readsect

original_code:
int readsect(dev_t dev, unsigned long lba, void *data, int sectsize)
{
 struct operation op;
 int ret;
 op.device = dev;
 op.type = 1;
 op.block = lba;
 op.blksize = sectsize;
 op.buffer = data;
 ret = devstrat(&op);
 return ret;
}

canonical_original_code:
int readsect(unsigned long dev, unsigned long lba, void *data, int sectsize)
{
 struct operation op;
 int ret;
 op.device = dev;
 op.type = 1;
 op.block = lba;
 op.blksize = sectsize;
 op.buffer = data;
 ret = devstrat(&op);
 return ret;
}

variable_types:
dev
unsigned long

variable_types:
lba
unsigned long

variable_types:
data
void *

variable_types: sectsize int

variable_types: struct operation { unsigned long device; int caller; int type; unsigned long block; unsigned int blksize; void *buffer; }


repo: mregmi/manrix

decompiled_code:
__int64 __fastcall read_mbr(__int64 a1, int a2, __int64 a3)
{
unsigned __int16 v4; // ax

if ( (int)readsect(a1, 0LL, a3, a2) < 0 )
return 0xFFFFFFFFLL;
v4 = *(_WORD *)(a3 + 542);
if ( v4 == 0xAA55 )
return 0LL;
printf(" Invalid Signature in MBR on disk %d %X \n", BYTE1(a1), v4);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, __int64 a3)
{
unsigned __int16 v4; // ax

if ( (int)func2(a1, 0LL, a3, a2) < 0 )
return 0xFFFFFFFFLL;
v4 = *(_WORD *)(a3 + 542);
if ( v4 == 0xAA55 )
return 0LL;
printf(" Invalid Signature in MBR on disk %d %X \n", BYTE1(a1), v4);
return 0xFFFFFFFFLL;
}

original_code:
int read_mbr(dev_t dev, int sectsize, MBR *mbr)
{
 int ret;
 ret = readsect(dev, 0, (void *)mbr, sectsize);
 if(ret < 0)
  return -1;
 if(mbr->signature != 0xAA55)
 {
  printf(" Invalid Signature in MBR on disk %d %X \n", (((dev & 0xFFFF) >> 8) & 0xff), mbr->signature);
  return -1;
 }
 return 0;
}

canonical_original_code:
int read_mbr(unsigned long dev, int sectsize, struct tagMBR *mbr)
{
 int ret;
 ret = readsect(dev, 0, (void *)mbr, sectsize);
 if(ret < 0)
  return -1;
 if(mbr->signature != 0xAA55)
 {
  printf(" Invalid Signature in MBR on disk %d %X \n", (((dev & 0xFFFF) >> 8) & 0xff), mbr->signature);
  return -1;
 }
 return 0;
}

variable_types: struct tagMBR { char res[446]; struct tagPARTITION { unsigned char bootIndicator; unsigned char startingHead; unsigned short start; unsigned char systemId; unsigned char endingHead; unsigned short end; unsigned long relativeSectors; unsigned long totalSectors; } part[4]; unsigned short signature; } *

variable_types: ret int

return_type: int

user_defined_types: struct tagMBR { char res[446]; struct tagPARTITION part[4]; unsigned short signature; }


original_code:
static inline int read_extended(dev_t dev, int sectsize, PARTITION *p, struct partition_info *pinfo)
{
 MBR ebr;
 PARTITION *p1, *p0;
 int ret, index = 5;
 uint32_t ebrBase, nextPart, ebr2 = 0;
 ebrBase = p->relativeSectors;
 ret = readsect(dev, ebrBase, &ebr, sectsize);
 if(ret < 0)
  return ret;
 do{
  p0 = &ebr.part[0];
  p1 = &ebr.part[1];
  pinfo[index].ptype = p0->systemId;
  pinfo[index].size = p0->totalSectors;
  pinfo[index].flag = p0->bootIndicator;
  pinfo[index].start = p0->relativeSectors + ebrBase + ebr2;
printf("Part %x,  size %d MB lba %d\n", p0->systemId, p0->totalSectors/(2 * 1024),p0->relativeSectors);
  ebr2 = p1->relativeSectors;
  nextPart = p1->relativeSectors + ebrBase;
  readsect(dev, nextPart, &ebr, sectsize);
  index++;
  if(index >= 255)
  {
   printf("Too many partitions. Cannot handle more than 256.\n");
   break;
  }
 }while (ebr.part[1].systemId != 0x00);
 pinfo[index].ptype = ebr.part[0].systemId;
 pinfo[index].size = ebr.part[0].totalSectors;
 pinfo[index].flag = p0->bootIndicator;
 pinfo[index].start = ebr.part[0].relativeSectors + ebrBase +ebr2;
 return (index + 1);
}

canonical_original_code:
static inline int read_extended(unsigned long dev, int sectsize, struct tagPARTITION *p, struct partition_info *pinfo)
{
 struct tagMBR ebr;
 struct tagPARTITION *p1; struct tagPARTITION *p0;
 int ret; int index = 5;
 unsigned long ebrBase; unsigned long nextPart; unsigned long ebr2 = 0;
 ebrBase = p->relativeSectors;
 ret = readsect(dev, ebrBase, &ebr, sectsize);
 if(ret < 0)
  return ret;
 do{
  p0 = &ebr.part[0];
  p1 = &ebr.part[1];
  pinfo[index].ptype = p0->systemId;
  pinfo[index].size = p0->totalSectors;
  pinfo[index].flag = p0->bootIndicator;
  pinfo[index].start = p0->relativeSectors + ebrBase + ebr2;
printf("Part %x,  size %d MB lba %d\n", p0->systemId, p0->totalSectors/(2 * 1024),p0->relativeSectors);
  ebr2 = p1->relativeSectors;
  nextPart = p1->relativeSectors + ebrBase;
  readsect(dev, nextPart, &ebr, sectsize);
  index++;
  if(index >= 255)
  {
   printf("Too many partitions. Cannot handle more than 256.\n");
   break;
  }
 }while (ebr.part[1].systemId != 0x00);
 pinfo[index].ptype = ebr.part[0].systemId;
 pinfo[index].size = ebr.part[0].totalSectors;
 pinfo[index].flag = p0->bootIndicator;
 pinfo[index].start = ebr.part[0].relativeSectors + ebrBase +ebr2;
 return (index + 1);
}

variable_types: struct tagPARTITION { unsigned char bootIndicator; unsigned char startingHead; unsigned short start; unsigned char systemId; unsigned char endingHead; unsigned short end; unsigned long relativeSectors; unsigned long totalSectors; } *

variable_types: struct partition_info { unsigned long start; unsigned long size; unsigned short ptype; unsigned short flag; } *

variable_types: struct tagMBR { char res[446]; struct tagPARTITION { unsigned char bootIndicator; unsigned char startingHead; unsigned short start; unsigned char systemId; unsigned char endingHead; unsigned short end; unsigned long relativeSectors; unsigned long totalSectors; } part[4]; unsigned short signature; }

variable_types: index int

variable_types:
ebrBase
unsigned long

variable_types:
nextPart
unsigned long


decompiled_code:
__int64 __fastcall read_partitions(__int64 a1, int a2, __int64 a3, __int64 a4)
{
int v6; // eax
unsigned int v7; // edx

v6 = read_primary(a3, a4);
v7 = 0;
if ( v6 != -1 )
v7 = read_extended(a1, a2, a3 + 24LL * v6 + 446, a4);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, __int64 a3, __int64 a4)
{
int v6; // eax
unsigned int v7; // edx

v6 = func1(a3, a4);
v7 = 0;
if ( v6 != -1 )
v7 = func4(a1, a2, a3 + 24LL * v6 + 446, a4);
return v7;
}

original_code:
int read_partitions(dev_t dev, int sectsize, MBR *mbr, struct partition_info *pinfo)
{
 PARTITION *ebr;
 int index, ret = 0;
 index = read_primary(mbr, pinfo);
 if(index == -1)
  return 0;
 ebr = &mbr->part[index];
 ret = read_extended(dev, sectsize, ebr, pinfo);
 return ret;
}

canonical_original_code:
int read_partitions(unsigned long dev, int sectsize, struct tagMBR *mbr, struct partition_info *pinfo)
{
 struct tagPARTITION *ebr;
 int index; int ret = 0;
 index = read_primary(mbr, pinfo);
 if(index == -1)
  return 0;
 ebr = &mbr->part[index];
 ret = read_extended(dev, sectsize, ebr, pinfo);
 return ret;
}

user_defined_types: struct partition_info { unsigned long start; unsigned long size; unsigned short ptype; unsigned short flag; }

user_defined_types: struct tagPARTITION { unsigned char bootIndicator; unsigned char startingHead; unsigned short start; unsigned char systemId; unsigned char endingHead; unsigned short end; unsigned long relativeSectors; unsigned long totalSectors; }


decompiled_code:
void *__fastcall initialize_partitions(__int64 a1, int a2, __int64 (__fastcall *a3)(_QWORD))
{
int v3; // edx
void *result; // rax
int *v5; // r12
int v6; // edx
_BYTE v7[568]; // [rsp+0h] [rbp-238h] BYREF

devstrat = a3;
v3 = read_mbr(a1, a2, (__int64)v7);
result = 0LL;
if ( v3 >= 0 )
{
v5 = (int *)malloc(0x1800uLL);
memset(v5, 0, 0x1800u);
v6 = read_partitions(a1, a2, (__int64)v7, (__int64)v5);
result = 0LL;
if ( v6 >= 0 )
result = realloc(v5, (unsigned int)(24 * v6));
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, int a2, __int64 (__fastcall *a3)(_QWORD))
{
int v3; // edx
void *result; // rax
int *v5; // r12
int v6; // edx
_BYTE v7[568]; // [rsp+0h] [rbp-238h] BYREF

devstrat = a3;
v3 = func3(a1, a2, (__int64)v7);
result = 0LL;
if ( v3 >= 0 )
{
v5 = (int *)malloc(0x1800uLL);
func0(v5, 0, 0x1800u);
v6 = func5(a1, a2, (__int64)v7, (__int64)v5);
result = 0LL;
if ( v6 >= 0 )
result = realloc(v5, (unsigned int)(24 * v6));
}
return result;
}

original_code:
struct partition_info *initialize_partitions(dev_t device, int sectorsize, int (* strategy)(struct operation *))
{
 MBR mbr;
 struct partition_info *pinfo;
 int ret;
 devstrat = strategy;
 ret = read_mbr(device, sectorsize, &mbr);
 if(ret < 0)
  return 0;
 pinfo = (struct partition_info *) malloc(sizeof(struct partition_info) * 256);
 memset(pinfo, 0, sizeof(struct partition_info) * 256);
 ret = read_partitions(device, sectorsize, &mbr, pinfo);
 if(ret < 0)
  return 0;
 pinfo = (struct partition_info *)realloc(pinfo, sizeof(struct partition_info) * ret);
 return pinfo;
}

canonical_original_code:
struct partition_info *initialize_partitions(unsigned long device, int sectorsize, int (*strategy)(struct operation *))
{
 struct tagMBR mbr;
 struct partition_info *pinfo;
 int ret;
 devstrat = strategy;
 ret = read_mbr(device, sectorsize, &mbr);
 if(ret < 0)
  return 0;
 pinfo = (struct partition_info *) malloc(sizeof(struct partition_info) * 256);
 memset(pinfo, 0, sizeof(struct partition_info) * 256);
 ret = read_partitions(device, sectorsize, &mbr, pinfo);
 if(ret < 0)
  return 0;
 pinfo = (struct partition_info *)realloc(pinfo, sizeof(struct partition_info) * ret);
 return pinfo;
}

variable_types:
device
unsigned long

variable_types: sectorsize int

variable_types: int (*)(struct operation { unsigned long device; int caller; int type; unsigned long block; unsigned int blksize; void *buffer; } *)

return_type: struct partition_info { unsigned long start; unsigned long size; unsigned short ptype; unsigned short flag; } *


original_code:
int console_init()
{
 struct winattr *wattr = &(ttys[termindex]).t_win;
 wattr->current_x = wattr->current_y = 8;
 vga = vga_init(vga, &wattr->max_x, &wattr->max_y, &wattr->attr);
 if(!vga)
  return -1;
 return 0;
}

variable_types: struct winattr { int current_x; int max_x; int attr; char scrbuf[-1]; } *


decompiled_code:
__int64 __fastcall scr_write(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
__int64 v2; // r12
unsigned __int8 v3; // di

v1 = a1;
v2 = ttys + 3168LL * termindex;
v3 = *a1;
if ( v3 )
{
do
{
put_char(v3, (_DWORD *)(v2 + 1144), 0);
v3 = *++v1;
}
while ( *v1 );
}
return update_cursor(*(_WORD *)(v2 + 1144) + 1, *(_DWORD *)(v2 + 1148));
}

original_code:
void scr_write(const char *string)
{
 struct terminal *term;
 struct winattr *wattr;
 term = &(ttys[termindex]);
 wattr = &term->t_win;
 while(*string != '\0')
 {
  put_char(*string, wattr, 0);
  string++;
 }
 update_cursor(wattr->current_x+1, wattr->current_y);
}

canonical_original_code:
void scr_write(char *string)
{
 struct terminal *term;
 struct winattr *wattr;
 term = &(ttys[termindex]);
 wattr = &term->t_win;
 while(*string != '\0')
 {
  put_char(*string, wattr, 0);
  string++;
 }
 update_cursor(wattr->current_x+1, wattr->current_y);
}

variable_types:
string
char *

variable_types: struct terminal { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned int c_cc[10]; } t_termios; struct termqueue { unsigned char queue[512]; unsigned char last_scancode; int end; unsigned long keyflag; int led; int flag; int thread; } t_input; struct termqueue t_output; struct winattr { int current_x; int max_x; int attr; char scrbuf[-1]; } t_win; int pgid; } *

return_type: void

user_defined_types: struct terminal { struct termios t_termios; struct termqueue t_input; struct termqueue t_output; struct winattr t_win; int pgid; }


decompiled_code:
__int64 __fastcall con_printf(char *format)
{
unsigned int v1; // ebx
char arg[8]; // [rsp+10h] [rbp-8h] BYREF

v1 = vsprintf(buf, format, arg);
scr_write((unsigned __int8 *)buf);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *format)
{
unsigned int v1; // ebx
char arg[8]; // [rsp+10h] [rbp-8h] BYREF

v1 = vsprintf(buf, format, arg);
func8((unsigned __int8 *)buf);
return v1;
}

original_code:
int con_printf(const char *format, ...)
{
 va_list ap;
 int ret;
 ((ap = (va_list)(&format)+sizeof(format)));
 ret = vsprintf(buf, format, ap);
 ((void)0);
 scr_write(buf);
 return ret;
}

canonical_original_code:
int con_printf(char *format, ...)
{
 char *ap;
 int ret;
 ((ap = (va_list)(&format)+sizeof(format)));
 ret = vsprintf(buf, format, ap);
 ((void)0);
 scr_write(buf);
 return ret;
}

variable_types:
format
char *

variable_types:
ap
char *


readline

decompiled_code:
__int64 __fastcall readline(_WORD *a1, char *a2)
{
char v2; // al
char v3; // bl
char v4; // r12
char *v6; // rbx
int i; // ebx
char v8; // al
char nptr[4]; // [rsp+Bh] [rbp-2Dh] BYREF
char v10; // [rsp+Fh] [rbp-29h] BYREF

while ( 1 )
{
while ( 1 )
{
v2 = fgetc(in);
v3 = v2;
v4 = v2;
if ( v2 != 59 )
break;
fgets(a2, 80, in);
fgets(a2, 80, in);
}
if ( v2 == 86 || v2 == 68 )
break;
fgets(a2, 80, in);
if ( v3 == -1 )
return 0LL;
}
fgetc(in);
v6 = nptr;
do
*v6++ = fgetc(in);
while ( v6 != &v10 );
v10 = 0;
*a1 = strtol(nptr, 0LL, 16);
fgetc(in);
for ( i = 0; i <= 79; ++i )
{
v8 = fgetc(in);
if ( v8 == 10 )
break;
if ( v8 == 34 || v8 == 63 )
a2[i++] = 92;
a2[i] = v8;
}
a2[i] = 0;
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(_WORD *a1, char *a2)
{
char v2; // al
char v3; // bl
char v4; // r12
char *v6; // rbx
int i; // ebx
char v8; // al
char nptr[4]; // [rsp+Bh] [rbp-2Dh] BYREF
char v10; // [rsp+Fh] [rbp-29h] BYREF

while ( 1 )
{
while ( 1 )
{
v2 = fgetc(in);
v3 = v2;
v4 = v2;
if ( v2 != 59 )
break;
fgets(a2, 80, in);
fgets(a2, 80, in);
}
if ( v2 == 86 || v2 == 68 )
break;
fgets(a2, 80, in);
if ( v3 == -1 )
return 0LL;
}
fgetc(in);
v6 = nptr;
do
*v6++ = fgetc(in);
while ( v6 != &v10 );
v10 = 0;
*a1 = strtol(nptr, 0LL, 16);
fgetc(in);
for ( i = 0; i <= 79; ++i )
{
v8 = fgetc(in);
if ( v8 == 10 )
break;
if ( v8 == 34 || v8 == 63 )
a2[i++] = 92;
a2[i] = v8;
}
a2[i] = 0;
return (unsigned int)v4;
}

original_code:
static inline int readline(unsigned short *id, char *str)
{
 char etype, ch;
 char eid[5];
 int index, ret = 0, len;
 do{
  etype = fgetc(in);
  if(etype == ';')
   fgets(str, 80, in);
  if((etype == 'V') || (etype == 'D'))
  {
   fgetc(in);
   for(index = 0; index < 4; index++)
   {
    eid[index] = fgetc(in);
   }
   eid[4] = '\0';
   *id = (unsigned short)strtol(eid, (char **)((void *)0), 16);
   fgetc(in);
   for(index = 0; index < 80; index++)
   {
    ch = fgetc(in);
    if(ch == '\n')
     break;
    if((ch == '"')||(ch == '?'))
    {
     str[index++] = '\\';
    }
    str[index] = ch;
   }
   str[index] = '\0';
   ret = (int)etype;
   break;
  }
  else
  {
   fgets(str, 80, in);
  }
 }while(etype != (-1));
 return ret;
}

canonical_original_code:
static inline int readline(unsigned short *id, char *str)
{
 char etype; char ch;
 char eid[5];
 int index; int ret = 0; int len;
 do{
  etype = fgetc(in);
  if(etype == ';')
   fgets(str, 80, in);
  if((etype == 'V') || (etype == 'D'))
  {
   fgetc(in);
   for(index = 0; index < 4; index++)
   {
    eid[index] = fgetc(in);
   }
   eid[4] = '\0';
   *id = (unsigned short)strtol(eid, (char **)((void *)0), 16);
   fgetc(in);
   for(index = 0; index < 80; index++)
   {
    ch = fgetc(in);
    if(ch == '\n')
     break;
    if((ch == '"')||(ch == '?'))
    {
     str[index++] = '\\';
    }
    str[index] = ch;
   }
   str[index] = '\0';
   ret = (int)etype;
   break;
  }
  else
  {
   fgets(str, 80, in);
  }
 }while(etype != (-1));
 return ret;
}

variable_types:
id
unsigned short *

variable_types:
str
char *

variable_types: etype char

variable_types: ch char

variable_types:
eid
char [5]

variable_types: len int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rcx
int v4; // eax
char v6[94]; // [rsp+0h] [rbp-68h] BYREF
unsigned __int16 v7[5]; // [rsp+5Eh] [rbp-Ah] BYREF

in = fopen("pcidevs.txt", "r");
if ( !in )
{
perror("Error opening pcidevs.txt: ");
exit(1);
}
v3 = fopen("pciid.c", "w");
out = v3;
if ( !v3 )
{
perror("Error opening/creating pciid.c: ");
exit(1);
}
fwrite(
"/* \n"
" * BUS manager for ManRiX OS\n"
" * Copyright (C) 2004, 2005\tManish Regmi (regmi dot manish at gmail dot com)\n"
" *\t\t\t\tRajesh R.C (rajee5283 at hotmail dot com)\n"
" *\n"
" * This program is free software; you can redistribute it and/or modify\n"
" * it under the terms of the GNU General Public License as published by\n"
" * the Free Software Foundation; either version 2 of the License, or\n"
" * (at your option) any later version.\n"
" *\n"
" * This program is distributed in the hope that it will be useful,\n"
" * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
" * GNU General Public License for more details.\n"
" *\n"
" * You should have received a copy of the GNU General Public License\n"
" * along with this program; if not, write to the Free Software\n"
" * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"
" */\n"
"/*\n"
" * File: pciid.c\n"
" * \t\tPCI Device and Vendor's Id list based on Craig Hart's pcidevs.txt.\n"
" * \tAutomatically Generated By pciscan (pcidevs2c.c)\n"
" */\n"
"\n"
"#include \"pci.h\"\n"
"\n"
"struct pciid vendors[] = {\n",
1uLL,
0x431uLL,
v3);
while ( 1 )
{
v4 = readline(v7, v6);
if ( !v4 )
break;
fprintf(out, "\t{ '%c', 0x%X, \"%s\" },\n", (unsigned int)(char)v4, v7[0], v6);
}
fwrite("\t{ 'N', 0x0, NULL }\n};\n", 1uLL, 0x17uLL, out);
fclose(in);
fclose(out);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rcx
int v4; // eax
char v6[94]; // [rsp+0h] [rbp-68h] BYREF
unsigned __int16 v7[5]; // [rsp+5Eh] [rbp-Ah] BYREF

in = fopen("pcidevs.txt", "r");
if ( !in )
{
perror("Error opening pcidevs.txt: ");
exit(1);
}
v3 = fopen("pciid.c", "w");
out = v3;
if ( !v3 )
{
perror("Error opening/creating pciid.c: ");
exit(1);
}
fwrite(
"/* \n"
" * BUS manager for ManRiX OS\n"
" * Copyright (C) 2004, 2005\tManish Regmi (regmi dot manish at gmail dot com)\n"
" *\t\t\t\tRajesh R.C (rajee5283 at hotmail dot com)\n"
" *\n"
" * This program is free software; you can redistribute it and/or modify\n"
" * it under the terms of the GNU General Public License as published by\n"
" * the Free Software Foundation; either version 2 of the License, or\n"
" * (at your option) any later version.\n"
" *\n"
" * This program is distributed in the hope that it will be useful,\n"
" * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
" * GNU General Public License for more details.\n"
" *\n"
" * You should have received a copy of the GNU General Public License\n"
" * along with this program; if not, write to the Free Software\n"
" * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"
" */\n"
"/*\n"
" * File: pciid.c\n"
" * \t\tPCI Device and Vendor's Id list based on Craig Hart's pcidevs.txt.\n"
" * \tAutomatically Generated By pciscan (pcidevs2c.c)\n"
" */\n"
"\n"
"#include \"pci.h\"\n"
"\n"
"struct pciid vendors[] = {\n",
1uLL,
0x431uLL,
v3);
while ( 1 )
{
v4 = func7(v7, v6);
if ( !v4 )
break;
fprintf(out, "\t{ '%c', 0x%X, \"%s\" },\n", (unsigned int)(char)v4, v7[0], v6);
}
fwrite("\t{ 'N', 0x0, NULL }\n};\n", 1uLL, 0x17uLL, out);
fclose(in);
fclose(out);
return 0;
}

original_code:
int main()
{
 int length, type;
 unsigned short id;
 char str[80], entry[80];
 char *vendors = {
"/* \n"
" * BUS manager for ManRiX OS\n"
" * Copyright (C) 2004, 2005	Manish Regmi (regmi dot manish at gmail dot com)\n"
" *				Rajesh R.C (rajee5283 at hotmail dot com)\n"
" *\n"
" * This program is free software; you can redistribute it and/or modify\n"
" * it under the terms of the GNU General Public License as published by\n"
" * the Free Software Foundation; either version 2 of the License, or\n"
" * (at your option) any later version.\n"
" *\n"
" * This program is distributed in the hope that it will be useful,\n"
" * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
" * GNU General Public License for more details.\n"
" *\n"
" * You should have received a copy of the GNU General Public License\n"
" * along with this program; if not, write to the Free Software\n"
" * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n"
" */\n"
"/*\n"
" * File: pciid.c\n"
" * 		PCI Device and Vendor's Id list based on Craig Hart's pcidevs.txt.\n"
" * 	Automatically Generated By pciscan (pcidevs2c.c)\n"
" */\n"
"\n"
"#include \"pci.h\"\n\n"
"struct pciid vendors[] = {\n"};
 in = fopen("pcidevs.txt", "r");
 if(!in)
 {
  perror("Error opening pcidevs.txt: ");
  exit(1);
 }
 out = fopen("pciid.c","w");
 if(!out)
 {
  perror("Error opening/creating pciid.c: ");
  exit(1);
 }
 length = strlen(vendors);
 fwrite(vendors, 1, length, out);
 while((type = readline(&id, str)) != 0)
  fprintf(out, "\t{ '%c', 0x%X, \"%s\" },\n", (char)type, id, str);
 fprintf(out, "\t{ 'N', 0x0, NULL }\n};\n");
 fclose(in);
 fclose(out);
 return 0;
}

canonical_original_code:
int main()
{
 int length; int type;
 unsigned short id;
 char str[80]; char entry[80];
 char *vendors = {
"/* \n"
" * BUS manager for ManRiX OS\n"
" * Copyright (C) 2004, 2005	Manish Regmi (regmi dot manish at gmail dot com)\n"
" *				Rajesh R.C (rajee5283 at hotmail dot com)\n"
" *\n"
" * This program is free software; you can redistribute it and/or modify\n"
" * it under the terms of the GNU General Public License as published by\n"
" * the Free Software Foundation; either version 2 of the License, or\n"
" * (at your option) any later version.\n"
" *\n"
" * This program is distributed in the hope that it will be useful,\n"
" * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
" * GNU General Public License for more details.\n"
" *\n"
" * You should have received a copy of the GNU General Public License\n"
" * along with this program; if not, write to the Free Software\n"
" * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n"
" */\n"
"/*\n"
" * File: pciid.c\n"
" * 		PCI Device and Vendor's Id list based on Craig Hart's pcidevs.txt.\n"
" * 	Automatically Generated By pciscan (pcidevs2c.c)\n"
" */\n"
"\n"
"#include \"pci.h\"\n\n"
"struct pciid vendors[] = {\n"};
 in = fopen("pcidevs.txt", "r");
 if(!in)
 {
  perror("Error opening pcidevs.txt: ");
  exit(1);
 }
 out = fopen("pciid.c","w");
 if(!out)
 {
  perror("Error opening/creating pciid.c: ");
  exit(1);
 }
 length = strlen(vendors);
 fwrite(vendors, 1, length, out);
 while((type = readline(&id, str)) != 0)
  fprintf(out, "\t{ '%c', 0x%X, \"%s\" },\n", (char)type, id, str);
 fprintf(out, "\t{ 'N', 0x0, NULL }\n};\n");
 fclose(in);
 fclose(out);
 return 0;
}

variable_types: length int

variable_types: type int

variable_types:
id
unsigned short

variable_types:
str
char [80]

variable_types:
entry
char [80]

variable_types:
vendors
char *


decompiled_code:
__int64 __fastcall console_write(char *a1)
{
char *v1; // rbx
char v2; // di

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
put_char(v2);
v2 = *++v1;
}
while ( *v1 );
}
return update_cursor(current_x, current_y);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1)
{
char *v1; // rbx
char v2; // di

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
func4(v2);
v2 = *++v1;
}
while ( *v1 );
}
return func3(current_x, current_y);
}

original_code:
void console_write(char *string)
{
 while(*string != '\0')
 {
  put_char(*string);
  string++;
 }
 update_cursor(current_x, current_y);
}


scroll

decompiled_code:
__int64 scroll()
{
__int64 i; // rdi
__int64 result; // rax

memset((void *)0xB8000, 0, 0xA0u);
for ( i = 753664LL; i != 757664; i += 160LL )
memcpy((void *)i, (const void *)(i + 160), 0xA0u);
result = memset((void *)0xB8F00, 0, 0xA0u);
current_x = 0;
current_y = 24;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 i; // rdi
__int64 result; // rax

func0((void *)0xB8000, 0, 0xA0u);
for ( i = 753664LL; i != 757664; i += 160LL )
func1((void *)i, (const void *)(i + 160), 0xA0u);
result = func0((void *)0xB8F00, 0, 0xA0u);
current_x = 0;
current_y = 24;
return result;
}

canonical_original_code:
static void scroll()
{
 int i = 0;
 unsigned char *up = (u8 *) 0xB8000;
 unsigned char *down = (u8 *) (0xB8000 + 160);
 memset(up, 0, 160);
 while(i < 25)
 {
  memcpy(up, down, 160);
  up += 160;
  down += 160;
  i++;
 }
 memset((void *)(0xB8000 + (160 * 24)), 0, 160);
 current_x= 0;
 current_y = 24;
}

variable_types: i int

variable_types:
up
unsigned char *

variable_types:
down
unsigned char *


decompiled_code:
__int64 __fastcall update_cursor(int a1, int a2)
{
unsigned int v2; // edi
__int64 result; // rax

v2 = 80 * a2 + a1;
__outbyte(0x3D4u, 0xEu);
__outbyte(0x3D5u, BYTE1(v2));
__outbyte(0x3D4u, 0xFu);
result = v2;
__outbyte(0x3D5u, v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
unsigned int v2; // edi
__int64 result; // rax

v2 = 80 * a2 + a1;
__outbyte(0x3D4u, 0xEu);
__outbyte(0x3D5u, BYTE1(v2));
__outbyte(0x3D4u, 0xFu);
result = v2;
__outbyte(0x3D5u, v2);
return result;
}

original_code:
static void update_cursor(int x, int y)
{
 u16 position = (y * 80) + x;
 __asm__ volatile("outb %%al,%%dx"::"a" (0x0E),"d" (0x3D4));
 __asm__ volatile("outb %%al,%%dx"::"a" ((u8)((position >> 8) & 0xFF)),"d" (0x3D5));
 __asm__ volatile("outb %%al,%%dx"::"a" (0x0F),"d" (0x3D4));
 __asm__ volatile("outb %%al,%%dx"::"a" ((u8)(position & 0xFF)),"d" (0x3D5));
}

canonical_original_code:
static void update_cursor(int x, int y)
{
 unsigned short position = (y * 80) + x;
 __asm__ volatile("outb %%al,%%dx"::"a" (0x0E),"d" (0x3D4));
 __asm__ volatile("outb %%al,%%dx"::"a" ((u8)((position >> 8) & 0xFF)),"d" (0x3D5));
 __asm__ volatile("outb %%al,%%dx"::"a" (0x0F),"d" (0x3D4));
 __asm__ volatile("outb %%al,%%dx"::"a" ((u8)(position & 0xFF)),"d" (0x3D5));
}

variable_types: x int

variable_types: y int

variable_types:
position
unsigned short


decompiled_code:
__int64 __fastcall put_char(char a1)
{
__int64 result; // rax

if ( a1 == 11 )
{
current_y += 5;
return result;
}
if ( a1 > 11 )
{
if ( a1 == 13 )
{
current_x = 0;
return result;
}
}
else
{
if ( a1 == 9 )
{
current_x += 5;
return result;
}
if ( a1 == 10 )
{
++current_y;
current_x = 0;
return result;
}
}
if ( current_x > 79 )
{
current_x = 0;
++current_y;
}
if ( current_y > 24 )
scroll();
*(_BYTE *)(VGA + 2 * (current_x + 80 * current_y)) = a1;
result = 160 * current_y + 2 * current_x + 1;
*(_BYTE *)(VGA + result) = attr;
++current_x;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1)
{
__int64 result; // rax

if ( a1 == 11 )
{
current_y += 5;
return result;
}
if ( a1 > 11 )
{
if ( a1 == 13 )
{
current_x = 0;
return result;
}
}
else
{
if ( a1 == 9 )
{
current_x += 5;
return result;
}
if ( a1 == 10 )
{
++current_y;
current_x = 0;
return result;
}
}
if ( current_x > 79 )
{
current_x = 0;
++current_y;
}
if ( current_y > 24 )
func2();
*(_BYTE *)(VGA + 2 * (current_x + 80 * current_y)) = a1;
result = 160 * current_y + 2 * current_x + 1;
*(_BYTE *)(VGA + result) = attr;
++current_x;
return result;
}

original_code:
static void put_char(char ch)
{
 switch(ch)
 {
  case 0xb: current_y += 5; goto end;
  case 0x9: current_x += 5;goto end;
  case 0xa: current_y += 1;current_x = 0;goto end;
  case 0xd: current_x = 0;goto end;
 }
 if(current_x > 79)
 {
  current_x = 0;
  current_y += 1;
 }
 if(current_y > 24)
  scroll();
 VGA[(current_y * 160) + (current_x * 2)] = ch;
 VGA[(current_y * 160) + (current_x * 2 + 1)] = attr;
 current_x++;
end: ;
}


tcgetattr

decompiled_code:
__int64 __fastcall tcgetattr(unsigned __int16 a1)
{
_QWORD v2[7]; // [rsp+0h] [rbp-48h] BYREF
__int16 v3; // [rsp+3Ah] [rbp-Eh]

v3 = 8;
v2[2] = 56LL;
v2[6] = 5LL;
v2[1] = a1;
send_message(1LL, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 a1)
{
_QWORD v2[7]; // [rsp+0h] [rbp-48h] BYREF
__int16 v3; // [rsp+3Ah] [rbp-Eh]

v3 = 8;
v2[2] = 56LL;
v2[6] = 5LL;
v2[1] = a1;
send_message(1LL, v2);
return 0LL;
}

original_code:
int tcgetattr(int fildes, struct termios *termios_p)
{
 struct message msg;
 msg.flags = 8;
 msg.m2.rcv_ptr = termios_p;
 msg.m3.rcv_bufsize = sizeof(struct termios);
 msg.w1 = 5;
 msg.m2.w4 = (fildes & 0xFFFF);
 send_message(1, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 return 0;
}

variable_types: fildes int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned int c_cc[10]; } *

variable_types: struct message { union { unsigned long w3; unsigned long snd_bufsize; } m1; union { unsigned long w4; void *rcv_ptr; } m2; union { unsigned long w5; unsigned long rcv_bufsize; } m3; unsigned long dummy1; int tid; union { unsigned long w2; void *snd_ptr; } m4; unsigned long w1; unsigned short dummy; }


tcsetattr

decompiled_code:
__int64 __fastcall tcsetattr(unsigned __int16 a1, __int64 a2, __int64 a3)
{
__int64 v4[7]; // [rsp+0h] [rbp-48h] BYREF
__int16 v5; // [rsp+3Ah] [rbp-Eh]

v5 = 2;
v4[5] = a3;
v4[0] = 56LL;
v4[6] = 6LL;
v4[1] = a1;
send_message(1LL, v4);
return 0LL;
}

original_code:
int tcsetattr(int fildes, int optional_actions,
       const struct termios *termios_p)
{
 struct message msg;
 msg.flags = 2;
 msg.m4.snd_ptr = (void *)termios_p;
 msg.m1.snd_bufsize = sizeof(struct termios);
 msg.w1 = 6;
 msg.m2.w4 = (fildes & 0xFFFF);
 send_message(1, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 return 0;
}

canonical_original_code:
int tcsetattr(int fildes, int optional_actions, struct termios *termios_p)
{
 struct message msg;
 msg.flags = 2;
 msg.m4.snd_ptr = (void *)termios_p;
 msg.m1.snd_bufsize = sizeof(struct termios);
 msg.w1 = 6;
 msg.m2.w4 = (fildes & 0xFFFF);
 send_message(1, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 return 0;
}

user_defined_types: struct message { union { unsigned long w3; unsigned long snd_bufsize; } m1; union { unsigned long w4; void *rcv_ptr; } m2; union { unsigned long w5; unsigned long rcv_bufsize; } m3; unsigned long dummy1; int tid; union { unsigned long w2; void *snd_ptr; } m4; unsigned long w1; unsigned short dummy; }

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned int c_cc[10]; }


tcgetsid

decompiled_code:
__int64 __fastcall tcgetsid(unsigned __int16 a1)
{
_QWORD v2[6]; // [rsp+0h] [rbp-48h] BYREF
__int64 v3; // [rsp+30h] [rbp-18h]
__int16 v4; // [rsp+3Ah] [rbp-Eh]

v4 = 1;
v3 = 7LL;
v2[1] = a1;
send_message(1LL, v2);
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 a1)
{
_QWORD v2[6]; // [rsp+0h] [rbp-48h] BYREF
__int64 v3; // [rsp+30h] [rbp-18h]
__int16 v4; // [rsp+3Ah] [rbp-Eh]

v4 = 1;
v3 = 7LL;
v2[1] = a1;
send_message(1LL, v2);
return (unsigned int)v3;
}

original_code:
pid_t tcgetsid(int fildes)
{
 struct message msg;
 msg.flags = 1;
 msg.w1 = 7;
 msg.m2.w4 = (fildes & 0xFFFF);
 send_message(1, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 return msg.w1;
}

canonical_original_code:
int tcgetsid(int fildes)
{
 struct message msg;
 msg.flags = 1;
 msg.w1 = 7;
 msg.m2.w4 = (fildes & 0xFFFF);
 send_message(1, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 return msg.w1;
}


tcflush

decompiled_code:
__int64 __fastcall tcflush(unsigned __int16 a1, int a2)
{
_QWORD v3[7]; // [rsp+0h] [rbp-48h] BYREF
__int16 v4; // [rsp+3Ah] [rbp-Eh]

v4 = 1;
v3[6] = 8LL;
v3[1] = a1;
v3[5] = a2;
send_message(1LL, v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int16 a1, int a2)
{
_QWORD v3[7]; // [rsp+0h] [rbp-48h] BYREF
__int16 v4; // [rsp+3Ah] [rbp-Eh]

v4 = 1;
v3[6] = 8LL;
v3[1] = a1;
v3[5] = a2;
send_message(1LL, v3);
return 0LL;
}

original_code:
int tcflush(int fildes, int queue_selector)
{
 struct message msg;
 msg.flags = 1;
 msg.w1 = 8;
 msg.m2.w4 = (fildes & 0xFFFF);
 msg.m4.w2 = queue_selector;
 send_message(1, &msg);
 if(msg.w1 < 0)
 {
  errno = -msg.w1;
  return -1;
 }
 return 0;
}


decompiled_code:
__int64 vm_object_init()
{
__int64 result; // rax

result = kmem_cache_create("vm_object_cache", 104LL, 4LL, 0LL, 0LL);
vm_object_cache = result;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax

result = kmem_cache_create("vm_object_cache", 104LL, 4LL, 0LL, 0LL);
vm_object_cache = result;
return result;
}

original_code:
void vm_object_init()
{
 vm_object_cache = kmem_cache_create("vm_object_cache", sizeof(struct vm_object), 4, ((void *)0), ((void *)0));
}

user_defined_types: struct vm_object { struct linked_list page; struct atomic_t ref_count; struct atomic_t npages; unsigned int size; struct vm_object *shadow; int attribute; struct vn_object vn; struct spinlock lock; }

user_defined_types: struct vn_object { int fd; int blk_size; unsigned int page_size; unsigned int va; unsigned long offset; int map_type; int protection; unsigned int size; int pager_id; unsigned int noload_start; }


decompiled_code:
__int64 __fastcall vm_object_create(int a1)
{
__int64 v1; // rbx

v1 = kmem_cache_alloc(vm_object_cache, 0LL);
*(_DWORD *)(v1 + 24) = a1;
*(_DWORD *)(v1 + 16) = 1;
list_init((_QWORD *)v1);
*(_DWORD *)(v1 + 96) = 1;
*(_QWORD *)(v1 + 32) = 0LL;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
__int64 v1; // rbx

v1 = kmem_cache_alloc(vm_object_cache, 0LL);
*(_DWORD *)(v1 + 24) = a1;
*(_DWORD *)(v1 + 16) = 1;
func0((_QWORD *)v1);
*(_DWORD *)(v1 + 96) = 1;
*(_QWORD *)(v1 + 32) = 0LL;
return v1;
}

original_code:
vm_object_t vm_object_create(vm_size_t size)
{
 vm_object_t new_vm_object;
 new_vm_object = (vm_object_t) kmem_cache_alloc(vm_object_cache, 0);
 new_vm_object->size = size;
 ((&new_vm_object->ref_count)->value = 1);
 list_init(&new_vm_object->page);
 ((&new_vm_object->lock)->lock = 1);
 new_vm_object->shadow = ((void *)0);
 return new_vm_object;
}

canonical_original_code:
struct vm_object *vm_object_create(unsigned int size)
{
 struct vm_object *new_vm_object;
 new_vm_object = (struct vm_object *) kmem_cache_alloc(vm_object_cache, 0);
 new_vm_object->size = size;
 ((&new_vm_object->ref_count)->value = 1);
 list_init(&new_vm_object->page);
 ((&new_vm_object->lock)->lock = 1);
 new_vm_object->shadow = ((void *)0);
 return new_vm_object;
}

variable_types:
size
unsigned int

variable_types: struct vm_object { struct linked_list { void *next; } page; struct atomic_t { int value; } ref_count; struct atomic_t npages; unsigned int size; struct vm_object *shadow; int attribute; struct vn_object { int fd; int blk_size; unsigned int page_size; unsigned int va; unsigned long offset; int map_type; int protection; unsigned int size; int pager_id; unsigned int noload_start; } vn; struct spinlock { int lock; } lock; } *


decompiled_code:
__int64 __fastcall delete_object(__int64 a1)
{
__int64 result; // rax

result = atomic_dec((volatile signed __int32 *)(a1 + 16));
if ( (_DWORD)result )
{
free_pages(a1);
result = kmem_cache_free(vm_object_cache, a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax

result = func1((volatile signed __int32 *)(a1 + 16));
if ( (_DWORD)result )
{
free_pages(a1);
result = kmem_cache_free(vm_object_cache, a1);
}
return result;
}

original_code:
void delete_object(vm_object_t object)
{
 if(!atomic_dec(&object->ref_count))
  return;
 free_pages(object);
 kmem_cache_free(vm_object_cache, object);
}

canonical_original_code:
void delete_object(struct vm_object *object)
{
 if(!atomic_dec(&object->ref_count))
  return;
 free_pages(object);
 kmem_cache_free(vm_object_cache, object);
}


decompiled_code:
const char *__fastcall get_file_type(__int16 a1)
{
int v1; // edi
const char *result; // rax

v1 = a1 & 0xF000;
result = "directory";
if ( v1 != 0x4000 )
{
switch ( v1 )
{
case 32768:
result = "regular file";
break;
case 40960:
result = "symbolic link";
break;
case 24576:
result = "block special file";
break;
case 8192:
result = "character special file";
break;
case 49152:
result = "socket special file";
break;
default:
result = "FIFO special file";
if ( v1 != 4096 )
result = "unknown";
break;
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(__int16 a1)
{
int v1; // edi
const char *result; // rax

v1 = a1 & 0xF000;
result = "directory";
if ( v1 != 0x4000 )
{
switch ( v1 )
{
case 32768:
result = "regular file";
break;
case 40960:
result = "symbolic link";
break;
case 24576:
result = "block special file";
break;
case 8192:
result = "character special file";
break;
case 49152:
result = "socket special file";
break;
default:
result = "FIFO special file";
if ( v1 != 4096 )
result = "unknown";
break;
}
}
return result;
}

original_code:
static char *get_file_type(mode_t mode)
{
  char *type;
  if(((mode & 0xF000) == 0x4000))
   type = "directory";
  else if(((mode & 0xF000) == 0x8000))
   type = "regular file";
  else if(((mode & 0xF000) == 0xA000))
   type = "symbolic link";
  else if(((mode & 0xF000) == 0x6000))
   type = "block special file";
  else if(((mode & 0xF000) == 0x2000))
   type = "character special file";
  else if(((mode & 0xF000) == 0xC000))
   type = "socket special file";
  else if(((mode & 0xF000) == 0x1000))
   type = "FIFO special file";
  else
   type = "unknown";
  return type;
}

canonical_original_code:
static char *get_file_type(int mode)
{
  char *type;
  if(((mode & 0xF000) == 0x4000))
   type = "directory";
  else if(((mode & 0xF000) == 0x8000))
   type = "regular file";
  else if(((mode & 0xF000) == 0xA000))
   type = "symbolic link";
  else if(((mode & 0xF000) == 0x6000))
   type = "block special file";
  else if(((mode & 0xF000) == 0x2000))
   type = "character special file";
  else if(((mode & 0xF000) == 0xC000))
   type = "socket special file";
  else if(((mode & 0xF000) == 0x1000))
   type = "FIFO special file";
  else
   type = "unknown";
  return type;
}

variable_types: mode int

variable_types:
type
char *

return_type: char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+0h] [rbp-68h] BYREF
unsigned int v5; // [rsp+8h] [rbp-60h]
int v6; // [rsp+Ch] [rbp-5Ch]
unsigned int v7; // [rsp+10h] [rbp-58h]
__int64 v8; // [rsp+28h] [rbp-40h]
unsigned int v9; // [rsp+48h] [rbp-20h]
__int64 v10; // [rsp+50h] [rbp-18h]

if ( stat("/bin/stat", (struct stat *)&v4) < 0 )
{
fprintf((FILE *)"Could not stat file \"%s\"", "/bin/stat");
}
else
{
printf("\n File: '%s'", "/bin/stat");
get_file_type(v6);
printf("\n Size: %-15d Blocks: %-15d IO Block: %-8d", v8, v10, v9);
printf("\nDevice: %-15d Inode: %-15d Links: %-8d", v4, v5, v7);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+0h] [rbp-68h] BYREF
unsigned int v5; // [rsp+8h] [rbp-60h]
int v6; // [rsp+Ch] [rbp-5Ch]
unsigned int v7; // [rsp+10h] [rbp-58h]
__int64 v8; // [rsp+28h] [rbp-40h]
unsigned int v9; // [rsp+48h] [rbp-20h]
__int64 v10; // [rsp+50h] [rbp-18h]

if ( stat("/bin/stat", (struct stat *)&v4) < 0 )
{
fprintf((FILE *)"Could not stat file \"%s\"", "/bin/stat");
}
else
{
printf("\n File: '%s'", "/bin/stat");
func0(v6);
printf("\n Size: %-15d Blocks: %-15d IO Block: %-8d", v8, v10, v9);
printf("\nDevice: %-15d Inode: %-15d Links: %-8d", v4, v5, v7);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  int ret;
  struct stat st;
  char *path = "/bin/stat";
  ret = stat(path, &st);
  if(ret < 0)
  {
   fprintf("Could not stat file \"%s\"", path);
 return 0;
  }
  printf("\n  File: '%s'", path);
  printf("\n  Size: %-15d Blocks: %-15d IO Block: %-8d" , st.st_size, st.st_blocks, st.st_blksize, get_file_type(st.st_mode));
  printf("\nDevice: %-15d Inode: %-15d Links: %-8d", st.st_dev, st.st_ino, st.st_nlink);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ret int

variable_types: struct stat { unsigned long st_dev; int st_ino; int st_mode; int st_nlink; int st_uid; int st_gid; unsigned long st_rdev; unsigned long st_size; long st_atime; long st_mtime; long st_ctime; int st_blksize; unsigned long st_blocks; }

variable_types:
path
char *


original_code:
void qb_initialize(struct QueueBuffer **qbuf) {
 if (!qbuf)
  return;
 *qbuf = malloc(sizeof(struct QueueBuffer));
 (*qbuf)->head = malloc(sizeof(struct QueueBufferNode));
 (*qbuf)->tail = (*qbuf)->head;
 (*qbuf)->head->front =
 (*qbuf)->head->back = (*qbuf)->head->buffer;
 (*qbuf)->head->next = ((void *)0);
}

variable_types: struct QueueBuffer { struct QueueBufferNode { char buffer[4096]; char *front; struct QueueBufferNode *next; } *head; } **

user_defined_types: struct QueueBuffer { struct QueueBufferNode *head; }


original_code:
void qb_push(struct QueueBuffer *qbuf, const void *buffer, size_t len) {
 if (!qbuf)
  return;
 const char *cbuffer = (const char*)buffer;
 int i = 0,
     delta;
 while (i < len) {
  if (qbuf->tail->back - qbuf->tail->buffer >= 4096) {
   qbuf->tail->next = malloc(sizeof(struct QueueBufferNode));
   qbuf->tail = qbuf->tail->next;
   qbuf->tail->front =
   qbuf->tail->back = qbuf->tail->buffer;
   qbuf->tail->next = ((void *)0);
  }
  if (len - i > 4096 - (qbuf->tail->back - qbuf->tail->buffer))
   delta = 4096 - (qbuf->tail->back - qbuf->tail->buffer);
  else
   delta = len - i;
  memcpy(qbuf->tail->back, cbuffer + i, delta);
  qbuf->tail->back += delta;
  i += delta;
 }
}

canonical_original_code:
void qb_push(struct QueueBuffer *qbuf, void *buffer, unsigned long len) {
 if (!qbuf)
  return;
 char *cbuffer = (const char*)buffer;
 int i = 0; int delta;
 while (i < len) {
  if (qbuf->tail->back - qbuf->tail->buffer >= 4096) {
   qbuf->tail->next = malloc(sizeof(struct QueueBufferNode));
   qbuf->tail = qbuf->tail->next;
   qbuf->tail->front =
   qbuf->tail->back = qbuf->tail->buffer;
   qbuf->tail->next = ((void *)0);
  }
  if (len - i > 4096 - (qbuf->tail->back - qbuf->tail->buffer))
   delta = 4096 - (qbuf->tail->back - qbuf->tail->buffer);
  else
   delta = len - i;
  memcpy(qbuf->tail->back, cbuffer + i, delta);
  qbuf->tail->back += delta;
  i += delta;
 }
}

variable_types: struct QueueBuffer { struct QueueBufferNode { char buffer[4096]; char *front; struct QueueBufferNode *next; } *head; } *

variable_types:
buffer
void *

variable_types:
len
unsigned long

variable_types:
cbuffer
char *

variable_types: i int

variable_types: delta int


original_code:
int qb_pop(struct QueueBuffer *qbuf, void *buffer, size_t numbytes) {
 if (!qbuf)
  return 0;
 struct QueueBufferNode *current = qbuf->head;
 char *cbuffer = (char *)buffer;
 int i = 0,
     delta;
 while (i < numbytes) {
  if (qbuf->head->front == qbuf->head->back) {
   if (qbuf->head->next == ((void *)0)) {
    return i;
   } else {
    struct QueueBufferNode *temp = qbuf->head->next;
    free(qbuf->head);
    qbuf->head = temp;
   }
  }
  delta = qbuf->head->back - qbuf->head->front;
  if (numbytes - i < delta)
   delta = numbytes - i;
  memcpy(cbuffer + i, qbuf->head->front, delta);
  qbuf->head->front += delta;
  i += delta;
 }
 return i;
}

canonical_original_code:
int qb_pop(struct QueueBuffer *qbuf, void *buffer, unsigned long numbytes) {
 if (!qbuf)
  return 0;
 struct QueueBufferNode *current = qbuf->head;
 char *cbuffer = (char *)buffer;
 int i = 0; int delta;
 while (i < numbytes) {
  if (qbuf->head->front == qbuf->head->back) {
   if (qbuf->head->next == ((void *)0)) {
    return i;
   } else {
    struct QueueBufferNode *temp = qbuf->head->next;
    free(qbuf->head);
    qbuf->head = temp;
   }
  }
  delta = qbuf->head->back - qbuf->head->front;
  if (numbytes - i < delta)
   delta = numbytes - i;
  memcpy(cbuffer + i, qbuf->head->front, delta);
  qbuf->head->front += delta;
  i += delta;
 }
 return i;
}

variable_types:
numbytes
unsigned long

variable_types: struct QueueBufferNode { char buffer[4096]; char *front; struct QueueBufferNode *next; } *


original_code:
int qb_getSize(struct QueueBuffer *qbuf) {
 if (!qbuf)
  return 0;
 int size = 0;
 struct QueueBufferNode *current = qbuf->head;
 while (current != ((void *)0)) {
  size += current->back - current->front;
  current = current->next;
 }
 return size;
}

variable_types: size int

user_defined_types: struct QueueBufferNode { char buffer[4096]; char *front; struct QueueBufferNode *next; }


dolog

repo: quadstor/ietbsd

decompiled_code:
void __fastcall dolog(int a1, const char *a2, void *a3)
{
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

if ( log_daemon )
{
vsyslog(a1, a2, a3);
}
else
{
gettimeofday(&v4, 0LL);
fprintf(stderr, "%ld.%06ld: ", v4.tv_sec, v4.tv_usec);
vfprintf(stderr, a2, a3);
fputc(10, stderr);
fflush(stderr);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1, const char *a2, void *a3)
{
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

if ( log_daemon )
{
vsyslog(a1, a2, a3);
}
else
{
gettimeofday(&v4, 0LL);
fprintf(stderr, "%ld.%06ld: ", v4.tv_sec, v4.tv_usec);
vfprintf(stderr, a2, a3);
fputc(10, stderr);
fflush(stderr);
}
}

original_code:
static void dolog(int prio, const char *fmt, va_list ap)
{
 if (log_daemon)
  vsyslog(prio, fmt, ap);
 else {
  struct timeval time;
  gettimeofday(&time, ((void *)0));
  fprintf(stderr, "%ld.%06ld: ", time.tv_sec, time.tv_usec);
  vfprintf(stderr, fmt, ap);
  fprintf(stderr, "\n");
  fflush(stderr);
 }
}

canonical_original_code:
static void dolog(int prio, char *fmt, __builtin_va_list ap)
{
 if (log_daemon)
  vsyslog(prio, fmt, ap);
 else {
  struct timeval time;
  gettimeofday(&time, ((void *)0));
  fprintf(stderr, "%ld.%06ld: ", time.tv_sec, time.tv_usec);
  vfprintf(stderr, fmt, ap);
  fprintf(stderr, "\n");
  fflush(stderr);
 }
}

variable_types: prio int

variable_types:
fmt
char *

variable_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
void log_init()
{
if ( log_daemon )
openlog("ietd", 0, 24);
}

canonical_decompiled_code:
void func1()
{
if ( log_daemon )
openlog("ietd", 0, 24);
}

original_code:
void log_init(void)
{
 if (log_daemon)
  openlog("ietd", 0, (3<<3));
}

canonical_original_code:
void log_init()
{
 if (log_daemon)
  openlog("ietd", 0, (3<<3));
}


decompiled_code:
void log_warning(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
dolog(4, a1, va);
}

canonical_decompiled_code:
void func2(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func0(4, a1, va);
}

original_code:
void log_warning(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 dolog(4, fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void log_warning(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 dolog(4, fmt, ap);
 __builtin_va_end(ap);
}


decompiled_code:
void log_error(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
dolog(3, a1, va);
}

canonical_decompiled_code:
void func3(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func0(3, a1, va);
}

original_code:
void log_error(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 dolog(3, fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void log_error(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 dolog(3, fmt, ap);
 __builtin_va_end(ap);
}


decompiled_code:
void log_debug(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

if ( log_level >= a1 )
{
va_start(va, a2);
dolog(7, a2, va);
}
}

canonical_decompiled_code:
void func4(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

if ( log_level >= a1 )
{
va_start(va, a2);
func0(7, a2, va);
}
}

original_code:
void log_debug(int level, const char *fmt, ...)
{
 if (log_level >= level) {
  va_list ap;
  __builtin_va_start(ap,fmt);
  dolog(7, fmt, ap);
  __builtin_va_end(ap);
 }
}

canonical_original_code:
void log_debug(int level, char *fmt, ...)
{
 if (log_level >= level) {
  __builtin_va_list ap;
  __builtin_va_start(ap,fmt);
  dolog(7, fmt, ap);
  __builtin_va_end(ap);
 }
}

variable_types: level int


original_code:
void log_pdu(int level, struct PDU *pdu)
{
 unsigned char char_buf[16];
 int char_cnt = 0;
 unsigned char *buf;
 int i;
 if (log_level < level)
  return;
 buf = (void *)&pdu->bhs;
 log_debug(level, "BHS: (%p)", buf);
 for (i = 0; i < 48; i++)
  __dump_char(level, char_buf, &char_cnt, *buf++);
 __dump_line(level, char_buf, &char_cnt);
 buf = (void *)pdu->ahs;
 log_debug(level, "AHS: (%p)", buf);
 for (i = 0; i < pdu->ahssize; i++)
  __dump_char(level, char_buf, &char_cnt, *buf++);
 __dump_line(level, char_buf, &char_cnt);
 buf = (void *)pdu->data;
 log_debug(level, "Data: (%p)", buf);
 for (i = 0; i < pdu->datasize; i++)
  __dump_char(level, char_buf, &char_cnt, *buf++);
 __dump_line(level, char_buf, &char_cnt);
}

variable_types: struct PDU { struct iscsi_hdr { unsigned int opcode; unsigned int flags; unsigned int spec1[2]; unsigned int ahslength; unsigned int datalength[3]; unsigned int lun[4]; unsigned int itt; unsigned int ttt; unsigned int sn; unsigned int exp_sn; unsigned int max_sn; unsigned int spec3[3]; } bhs; void *ahs; unsigned int ahssize; void *data; unsigned int datasize; } *

variable_types:
buf
unsigned char *

user_defined_types: struct PDU { struct iscsi_hdr bhs; void *ahs; unsigned int ahssize; void *data; unsigned int datasize; }


decompiled_code:
__int64 __fastcall or_set_val(__int64 a1, int a2, _DWORD *a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = a1 + 8LL * a2;
result = (unsigned int)(*(_DWORD *)(v3 + 4) | *a3);
*a3 = result;
*(_DWORD *)(v3 + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, _DWORD *a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = a1 + 8LL * a2;
result = (unsigned int)(*(_DWORD *)(v3 + 4) | *a3);
*a3 = result;
*(_DWORD *)(v3 + 4) = result;
return result;
}

original_code:
static void or_set_val(struct iscsi_param *param, int idx, unsigned int *val)
{
 *val |= param[idx].val;
 param[idx].val = *val;
}

variable_types: struct iscsi_param { int state; unsigned int val; } *

variable_types: idx int

variable_types:
val
unsigned int *


decompiled_code:
__int64 __fastcall and_set_val(__int64 a1, int a2, _DWORD *a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = a1 + 8LL * a2;
result = (unsigned int)(*(_DWORD *)(v3 + 4) & *a3);
*a3 = result;
*(_DWORD *)(v3 + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, _DWORD *a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = a1 + 8LL * a2;
result = (unsigned int)(*(_DWORD *)(v3 + 4) & *a3);
*a3 = result;
*(_DWORD *)(v3 + 4) = result;
return result;
}

original_code:
static void and_set_val(struct iscsi_param *param, int idx, unsigned int *val)
{
 *val &= param[idx].val;
 param[idx].val = *val;
}

user_defined_types: struct iscsi_param { int state; unsigned int val; }


decompiled_code:
__int64 __fastcall minimum_check_val(__int64 a1, unsigned int *a2)
{
unsigned int v2; // eax

v2 = *(_DWORD *)(a1 + 12);
if ( *a2 < v2 || *a2 > *(_DWORD *)(a1 + 16) )
*a2 = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int *a2)
{
unsigned int v2; // eax

v2 = *(_DWORD *)(a1 + 12);
if ( *a2 < v2 || *a2 > *(_DWORD *)(a1 + 16) )
*a2 = v2;
return 0LL;
}

original_code:
static int minimum_check_val(struct iscsi_key *key, unsigned int *val)
{
 int err = 0;
 if (*val < key->min || key->max < *val) {
  *val = key->min;
  err = -22;
 }
 return 0;
}

variable_types: struct iscsi_key { char *name; unsigned int def; unsigned int min; unsigned int max; struct iscsi_key_ops { int (*val_to_str)(unsigned int, char *); int (*str_to_val)(char *, unsigned int *); int (*check_val)(struct iscsi_key *, unsigned int *); void (*set_val)(struct iscsi_param { int state; unsigned int val; } *, int, unsigned int *); } *ops; } *

variable_types: err int

user_defined_types: struct iscsi_key { char *name; unsigned int def; unsigned int min; unsigned int max; struct iscsi_key_ops *ops; }

user_defined_types: struct iscsi_key_ops { int (*val_to_str)(unsigned int, char *); int (*str_to_val)(char *, unsigned int *); int (*check_val)(struct iscsi_key *, unsigned int *); void (*set_val)(struct iscsi_param *, int, unsigned int *); }


original_code:
static int maximum_check_val(struct iscsi_key *key, unsigned int *val)
{
 int err = 0;
 if (*val < key->min || key->max < *val) {
  *val = key->max;
  err = -22;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall minimum_set_val(__int64 a1, int a2, unsigned int *a3)
{
__int64 result; // rax
unsigned int v4; // esi

result = a1 + 8LL * a2;
v4 = *(_DWORD *)(result + 4);
if ( *a3 <= v4 )
*(_DWORD *)(result + 4) = *a3;
else
*a3 = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, unsigned int *a3)
{
__int64 result; // rax
unsigned int v4; // esi

result = a1 + 8LL * a2;
v4 = *(_DWORD *)(result + 4);
if ( *a3 <= v4 )
*(_DWORD *)(result + 4) = *a3;
else
*a3 = v4;
return result;
}

original_code:
static void minimum_set_val(struct iscsi_param *param, int idx, unsigned int *val)
{
 if (*val > param[idx].val)
  *val = param[idx].val;
 else
  param[idx].val = *val;
}


decompiled_code:
__int64 __fastcall maximum_set_val(__int64 a1, int a2, unsigned int *a3)
{
__int64 result; // rax
unsigned int v4; // esi

result = a1 + 8LL * a2;
v4 = *(_DWORD *)(result + 4);
if ( v4 <= *a3 )
*(_DWORD *)(result + 4) = *a3;
else
*a3 = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, unsigned int *a3)
{
__int64 result; // rax
unsigned int v4; // esi

result = a1 + 8LL * a2;
v4 = *(_DWORD *)(result + 4);
if ( v4 <= *a3 )
*(_DWORD *)(result + 4) = *a3;
else
*a3 = v4;
return result;
}

original_code:
static void maximum_set_val(struct iscsi_param *param, int idx, unsigned int *val)
{
 if (param[idx].val > *val)
  *val = param[idx].val;
 else
  param[idx].val = *val;
}


decompiled_code:
__int64 __fastcall digest_set_val(__int64 a1, int a2, _BYTE *a3)
{
__int64 result; // rax

result = 1LL;
if ( (*a3 & 2) != 0 )
result = (unsigned int)((*(_BYTE *)(a1 + 8LL * a2 + 4) & 2) != 0) + 1;
*(_DWORD *)a3 = result;
*(_DWORD *)(a1 + 8LL * a2 + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, _BYTE *a3)
{
__int64 result; // rax

result = 1LL;
if ( (*a3 & 2) != 0 )
result = (unsigned int)((*(_BYTE *)(a1 + 8LL * a2 + 4) & 2) != 0) + 1;
*(_DWORD *)a3 = result;
*(_DWORD *)(a1 + 8LL * a2 + 4) = result;
return result;
}

original_code:
static void digest_set_val(struct iscsi_param *param, int idx, unsigned int *val)
{
 if (*val & (1 << 1) && param[idx].val & (1 << 1))
  *val = (1 << 1);
 else
  *val = (1 << 0);
 param[idx].val = *val;
}


decompiled_code:
_BOOL8 __fastcall marker_set_val(__int64 a1, int a2, _DWORD *a3)
{
_BOOL8 result; // rax

if ( a2 == 17 )
{
result = *(_DWORD *)(a1 + 120) != 2;
}
else
{
result = 1LL;
if ( a2 == 18 )
result = *(_DWORD *)(a1 + 128) != 2;
}
*a3 = result;
*(_DWORD *)(a1 + 8LL * a2 + 4) = result;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1, int a2, _DWORD *a3)
{
_BOOL8 result; // rax

if ( a2 == 17 )
{
result = *(_DWORD *)(a1 + 120) != 2;
}
else
{
result = 1LL;
if ( a2 == 18 )
result = *(_DWORD *)(a1 + 128) != 2;
}
*a3 = result;
*(_DWORD *)(a1 + 8LL * a2 + 4) = result;
return result;
}

original_code:
static void marker_set_val(struct iscsi_param *param, int idx, unsigned int *val)
{
 if ((idx == key_ofmarkint && param[key_ofmarker].state == 2) ||
     (idx == key_ifmarkint && param[key_ifmarker].state == 2))
  *val = 0;
 else
  *val = 1;
 param[idx].val = *val;
}


decompiled_code:
__int64 __fastcall range_str_to_val(const char *a1, _DWORD *a2)
{
*a2 = strtol(a1, 0LL, 0);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, _DWORD *a2)
{
*a2 = strtol(a1, 0LL, 0);
return 0LL;
}

original_code:
static int range_str_to_val(char *str, unsigned int *val)
{
 *val = strtol(str, ((void *)0), 0);
 return 0;
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall range_val_to_str(unsigned int a1, char *a2)
{
sprintf(a2, "%u", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, char *a2)
{
sprintf(a2, "%u", a1);
return 0LL;
}

original_code:
static int range_val_to_str(unsigned int val, char *str)
{
 sprintf(str, "%u", val);
 return 0;
}

variable_types:
val
unsigned int


decompiled_code:
__int64 __fastcall marker_val_to_str(int a1, char *a2)
{
if ( a1 )
strcpy(a2, "Reject");
else
strcpy(a2, "Irrelevant");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, char *a2)
{
if ( a1 )
strcpy(a2, "Reject");
else
strcpy(a2, "Irrelevant");
return 0LL;
}

original_code:
static int marker_val_to_str(unsigned int val, char *str)
{
 if (val == 0)
  strcpy(str, "Irrelevant");
 else
  strcpy(str, "Reject");
 return 0;
}


decompiled_code:
__int64 __fastcall bool_val_to_str(int a1, char *a2)
{
__int64 result; // rax

if ( a1 )
{
if ( a1 == 1 )
{
*(_DWORD *)a2 = 7562585;
result = 0LL;
}
else
{
result = 4294967274LL;
}
}
else
{
strcpy(a2, "No");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, char *a2)
{
__int64 result; // rax

if ( a1 )
{
if ( a1 == 1 )
{
*(_DWORD *)a2 = 7562585;
result = 0LL;
}
else
{
result = 4294967274LL;
}
}
else
{
strcpy(a2, "No");
result = 0LL;
}
return result;
}

original_code:
static int bool_val_to_str(unsigned int val, char *str)
{
 int err = 0;
 switch (val) {
 case 0:
  strcpy(str, "No");
  break;
 case 1:
  strcpy(str, "Yes");
  break;
 default:
  err = -22;
 }
 return err;
}


decompiled_code:
__int64 __fastcall digest_str_to_val(char *a1, _DWORD *a2)
{
char *v2; // rax
char *stringp; // [rsp+8h] [rbp-10h] BYREF

stringp = a1;
*a2 = 0;
while ( 1 )
{
v2 = strsep(&stringp, ",");
if ( strcmp(v2, "None") )
break;
*a2 |= 1u;
LABEL_3:
if ( !stringp )
return 0LL;
}
if ( !strcmp(v2, "CRC32C") )
{
*a2 |= 2u;
goto LABEL_3;
}
return 4294967274LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *a1, _DWORD *a2)
{
char *v2; // rax
char *stringp; // [rsp+8h] [rbp-10h] BYREF

stringp = a1;
*a2 = 0;
while ( 1 )
{
v2 = strsep(&stringp, ",");
if ( strcmp(v2, "None") )
break;
*a2 |= 1u;
LABEL_3:
if ( !stringp )
return 0LL;
}
if ( !strcmp(v2, "CRC32C") )
{
*a2 |= 2u;
goto LABEL_3;
}
return 4294967274LL;
}

original_code:
static int digest_str_to_val(char *str, unsigned int *val)
{
 int err = 0;
 char *p, *q;
 p = str;
 *val = 0;
 do {
  q = strsep(&p, ",");
  if (!strcmp(q, "None"))
   *val |= (1 << 0);
  else if (!strcmp(q, "CRC32C"))
   *val |= (1 << 1);
  else {
   err = -22;
   break;
  }
 } while (p);
 return err;
}

canonical_original_code:
static int digest_str_to_val(char *str, unsigned int *val)
{
 int err = 0;
 char *p; char *q;
 p = str;
 *val = 0;
 do {
  q = strsep(&p, ",");
  if (!strcmp(q, "None"))
   *val |= (1 << 0);
  else if (!strcmp(q, "CRC32C"))
   *val |= (1 << 1);
  else {
   err = -22;
   break;
  }
 } while (p);
 return err;
}

variable_types:
p
char *

variable_types:
q
char *


decompiled_code:
__int64 __fastcall bool_str_to_val(const char *a1, _DWORD *a2)
{
bool v2; // zf
__int64 result; // rax

v2 = strcmp(a1, "Yes") == 0;
result = !v2;
if ( v2 )
{
*a2 = 1;
}
else
{
v2 = strcmp(a1, "No") == 0;
result = !v2;
if ( v2 )
*a2 = 0;
else
result = 4294967274LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(const char *a1, _DWORD *a2)
{
bool v2; // zf
__int64 result; // rax

v2 = strcmp(a1, "Yes") == 0;
result = !v2;
if ( v2 )
{
*a2 = 1;
}
else
{
v2 = strcmp(a1, "No") == 0;
result = !v2;
if ( v2 )
*a2 = 0;
else
result = 4294967274LL;
}
return result;
}

original_code:
static int bool_str_to_val(char *str, unsigned int *val)
{
 int err = 0;
 if (!strcmp(str, "Yes"))
  *val = 1;
 else if (!strcmp(str, "No"))
  *val = 0;
 else
  err = -22;
 return err;
}


decompiled_code:
__int64 __fastcall digest_val_to_str(char a1, char *a2)
{
if ( (a1 & 1) != 0 )
strcpy(a2, "None");
if ( (a1 & 2) != 0 )
{
if ( *a2 )
*(_QWORD *)&a2[strlen(a2)] = 0x4332334352432CLL;
else
strcpy(a2, "CRC32C");
}
return *a2 == 0 ? 0xFFFFFFEA : 0;
}

original_code:
static int digest_val_to_str(unsigned int val, char *str)
{
 int err = 0;
 if (val & (1 << 0))
  strcpy(str, "None");
 if (val & (1 << 1)) {
  if (strlen(str))
   strcat(str, ",CRC32C");
  else
   strcpy(str, "CRC32C");
 }
 if (!strlen(str))
  err = -22;
 return err;
}


decompiled_code:
__int64 __fastcall param_index_by_name(char *s2, const char **a2)
{
const char *v3; // rdi
const char **v4; // rbx
unsigned int v5; // ebp

v3 = *a2;
if ( !*a2 )
return (unsigned int)-2;
v4 = a2 + 4;
v5 = 0;
while ( strcasecmp(v3, s2) )
{
++v5;
v4 += 4;
v3 = *(v4 - 4);
if ( !v3 )
return (unsigned int)-2;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func15(char *s2, const char **a2)
{
const char *v3; // rdi
const char **v4; // rbx
unsigned int v5; // ebp

v3 = *a2;
if ( !*a2 )
return (unsigned int)-2;
v4 = a2 + 4;
v5 = 0;
while ( strcasecmp(v3, s2) )
{
++v5;
v4 += 4;
v3 = *(v4 - 4);
if ( !v3 )
return (unsigned int)-2;
}
return v5;
}

original_code:
int param_index_by_name(char *name, struct iscsi_key *keys)
{
 int i, err = -2;
 for (i = 0; keys[i].name; i++) {
  if (!strcasecmp(keys[i].name, name)) {
   err = i;
   break;
  }
 }
 return err;
}

canonical_original_code:
int param_index_by_name(char *name, struct iscsi_key *keys)
{
 int i; int err = -2;
 for (i = 0; keys[i].name; i++) {
  if (!strcasecmp(keys[i].name, name)) {
   err = i;
   break;
  }
 }
 return err;
}

variable_types:
name
char *

variable_types: i int


decompiled_code:
void __fastcall param_set_defaults(__int64 a1, _QWORD *a2)
{
__int64 v2; // rax

if ( *a2 )
{
v2 = 0LL;
do
{
*(_DWORD *)(a1 + v2 * 2 + 4) = a2[v2 + 1];
v2 += 4LL;
}
while ( a2[v2] );
}
}

original_code:
void param_set_defaults(struct iscsi_param *params, struct iscsi_key *keys)
{
 int i;
 for (i = 0; keys[i].name; i++)
  params[i].val = keys[i].def;
}

variable_types: struct iscsi_key { char *name; unsigned int def; unsigned int min; unsigned int max; struct iscsi_key_ops { int (*val_to_str)(unsigned int, char *); int (*str_to_val)(char *, unsigned int *); int (*check_val)(struct iscsi_key *, unsigned int *); void (*set_val)(struct iscsi_param *, int, unsigned int *); } *ops; } *


decompiled_code:
__int64 __fastcall param_val_to_str(__int64 a1, int a2, unsigned int a3, __int64 a4)
{
__int64 v5; // rdi
__int64 (__fastcall *v6)(__int64, __int64); // rdx
__int64 result; // rax

v5 = a3;
v6 = **(__int64 (__fastcall ***)(__int64, __int64))(32LL * a2 + a1 + 24);
result = 0LL;
if ( v6 )
result = v6(v5, a4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, int a2, unsigned int a3, __int64 a4)
{
__int64 v5; // rdi
__int64 (__fastcall *v6)(__int64, __int64); // rdx
__int64 result; // rax

v5 = a3;
v6 = **(__int64 (__fastcall ***)(__int64, __int64))(32LL * a2 + a1 + 24);
result = 0LL;
if ( v6 )
result = v6(v5, a4);
return result;
}

original_code:
int param_val_to_str(struct iscsi_key *keys, int idx, unsigned int val, char *str)
{
 if (keys[idx].ops->val_to_str)
  return keys[idx].ops->val_to_str(val, str);
 else
  return 0;
}


decompiled_code:
__int64 __fastcall param_str_to_val(__int64 a1, int a2, __int64 a3, __int64 a4)
{
__int64 (__fastcall *v6)(__int64, __int64); // rdx
__int64 result; // rax

v6 = *(__int64 (__fastcall **)(__int64, __int64))(*(_QWORD *)(32LL * a2 + a1 + 24) + 8LL);
result = 0LL;
if ( v6 )
result = v6(a3, a4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, int a2, __int64 a3, __int64 a4)
{
__int64 (__fastcall *v6)(__int64, __int64); // rdx
__int64 result; // rax

v6 = *(__int64 (__fastcall **)(__int64, __int64))(*(_QWORD *)(32LL * a2 + a1 + 24) + 8LL);
result = 0LL;
if ( v6 )
result = v6(a3, a4);
return result;
}

original_code:
int param_str_to_val(struct iscsi_key *keys, int idx, char *str, unsigned int *val)
{
 if (keys[idx].ops->str_to_val)
  return keys[idx].ops->str_to_val(str, val);
 else
  return 0;
}


decompiled_code:
__int64 __fastcall param_check_val(__int64 a1, int a2, __int64 a3)
{
__int64 v3; // rdi
__int64 (__fastcall *v4)(__int64, __int64); // rcx
__int64 result; // rax

v3 = 32LL * a2 + a1;
v4 = *(__int64 (__fastcall **)(__int64, __int64))(*(_QWORD *)(v3 + 24) + 16LL);
result = 0LL;
if ( v4 )
result = v4(v3, a3);
return result;
}

original_code:
int param_check_val(struct iscsi_key *keys, int idx, unsigned int *val)
{
 if (keys[idx].ops->check_val)
  return keys[idx].ops->check_val(&keys[idx], val);
 else
  return 0;
}


decompiled_code:
_BOOL8 __fastcall list_empty(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

original_code:
static inline int list_empty(const struct __qelem *head)
{
 return head->q_forw == head;
}

canonical_original_code:
static inline int list_empty(struct __qelem *head)
{
 return head->q_forw == head;
}

variable_types: struct __qelem { struct __qelem *q_forw; struct __qelem *q_back; } *


decompiled_code:
__int64 __fastcall is_addr_unspecified(char *cp)
{
int v1; // edx
__int64 result; // rax
int v3[7]; // [rsp+0h] [rbp-28h] BYREF
int buf[3]; // [rsp+1Ch] [rbp-Ch] BYREF

if ( inet_pton(2, cp, buf) == 1 )
return buf[0] == 0;
v1 = inet_pton(10, cp, v3);
result = 0LL;
if ( v1 == 1 )
result = (v3[3] | v3[2] | v3[1] | v3[0]) == 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *cp)
{
int v1; // edx
__int64 result; // rax
int v3[7]; // [rsp+0h] [rbp-28h] BYREF
int buf[3]; // [rsp+1Ch] [rbp-Ch] BYREF

if ( inet_pton(2, cp, buf) == 1 )
return buf[0] == 0;
v1 = inet_pton(10, cp, v3);
result = 0LL;
if ( v1 == 1 )
result = (v3[3] | v3[2] | v3[1] | v3[0]) == 0;
return result;
}

original_code:
static int is_addr_unspecified(char *addr)
{
 struct in_addr ia;
 struct in6_addr ia6;
 if (inet_pton(2, addr, &ia) == 1)
  return (ia.s_addr == 0);
 if (inet_pton(10, addr, &ia6) == 1)
  return (__extension__ ({ const struct in6_addr *__a = (const struct in6_addr *) (&ia6); __a->__in6_u.__u6_addr32[0] == 0 && __a->__in6_u.__u6_addr32[1] == 0 && __a->__in6_u.__u6_addr32[2] == 0 && __a->__in6_u.__u6_addr32[3] == 0; }));
 return 0;
}

canonical_original_code:
static int is_addr_unspecified(char *addr)
{
 struct in_addr ia;
 struct in6_addr ia6;
 if (inet_pton(2, addr, &ia) == 1)
  return (ia.s_addr == 0);
 if (inet_pton(10, addr, &ia6) == 1)
  return (__extension__ ({ struct in6_addr *__a = (const struct in6_addr *) (&ia6); __a->__in6_u.__u6_addr32[0] == 0 && __a->__in6_u.__u6_addr32[1] == 0 && __a->__in6_u.__u6_addr32[2] == 0 && __a->__in6_u.__u6_addr32[3] == 0; }));
 return 0;
}

variable_types:
addr
char *

variable_types:
ia
struct in_addr { unsigned int s_addr; }

variable_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } *


decompiled_code:
__int64 __fastcall is_addr_loopback(char *cp)
{
int v1; // edx
__int64 result; // rax
int v3[7]; // [rsp+0h] [rbp-28h] BYREF
char buf[12]; // [rsp+1Ch] [rbp-Ch] BYREF

if ( inet_pton(2, cp, buf) == 1 )
return memcmp(cp, "127.", 4uLL) == 0;
v1 = inet_pton(10, cp, v3);
result = 0LL;
if ( v1 == 1 && !(v3[2] | v3[1] | v3[0]) )
result = v3[3] == (unsigned int)_bswap_32(1u);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *cp)
{
int v1; // edx
__int64 result; // rax
int v3[7]; // [rsp+0h] [rbp-28h] BYREF
char buf[12]; // [rsp+1Ch] [rbp-Ch] BYREF

if ( inet_pton(2, cp, buf) == 1 )
return memcmp(cp, "127.", 4uLL) == 0;
v1 = inet_pton(10, cp, v3);
result = 0LL;
if ( v1 == 1 && !(v3[2] | v3[1] | v3[0]) )
result = v3[3] == (unsigned int)func2(1u);
return result;
}

original_code:
static int is_addr_loopback(char *addr)
{
 struct in_addr ia;
 struct in6_addr ia6;
 if (inet_pton(2, addr, &ia) == 1)
  return !strncmp(addr, "127.", 4);
 if (inet_pton(10, addr, &ia6) == 1)
  return (__extension__ ({ const struct in6_addr *__a = (const struct in6_addr *) (&ia6); __a->__in6_u.__u6_addr32[0] == 0 && __a->__in6_u.__u6_addr32[1] == 0 && __a->__in6_u.__u6_addr32[2] == 0 && __a->__in6_u.__u6_addr32[3] == htonl (1); }));
 return 0;
}

canonical_original_code:
static int is_addr_loopback(char *addr)
{
 struct in_addr ia;
 struct in6_addr ia6;
 if (inet_pton(2, addr, &ia) == 1)
  return !strncmp(addr, "127.", 4);
 if (inet_pton(10, addr, &ia6) == 1)
  return (__extension__ ({ struct in6_addr *__a = (const struct in6_addr *) (&ia6); __a->__in6_u.__u6_addr32[0] == 0 && __a->__in6_u.__u6_addr32[1] == 0 && __a->__in6_u.__u6_addr32[2] == 0 && __a->__in6_u.__u6_addr32[3] == htonl (1); }));
 return 0;
}

variable_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


decompiled_code:
__int64 __fastcall target_print_addr(__int64 a1, char *a2, int a3)
{
char *v4; // rcx
const char *v5; // rdx
char *stringp; // [rsp+8h] [rbp-450h] BYREF
char s[1096]; // [rsp+10h] [rbp-448h] BYREF

stringp = a2;
v4 = strsep(&stringp, "%");
stringp = v4;
v5 = "%s:%d,1";
if ( a3 != 2 )
v5 = "[%s]:%d,1";
snprintf(s, 0x426uLL, v5, v4, server_port);
return text_key_add(a1, "TargetAddress", s);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char *a2, int a3)
{
char *v4; // rcx
const char *v5; // rdx
char *stringp; // [rsp+8h] [rbp-450h] BYREF
char s[1096]; // [rsp+10h] [rbp-448h] BYREF

stringp = a2;
v4 = strsep(&stringp, "%");
stringp = v4;
v5 = "%s:%d,1";
if ( a3 != 2 )
v5 = "[%s]:%d,1";
snprintf(s, 0x426uLL, v5, v4, server_port);
return text_key_add(a1, "TargetAddress", s);
}

original_code:
static void target_print_addr(struct connection *conn, char *addr, int family)
{
 char taddr[1025 + 32 + 5];
 addr = strsep(&addr, "%");
 snprintf(taddr, sizeof(taddr),
  (family == 2) ? "%s:%d,1" : "[%s]:%d,1",
       addr, server_port);
 text_key_add(conn, "TargetAddress", taddr);
}

canonical_original_code:
static void target_print_addr(struct connection *conn, char *addr, int family)
{
 char taddr[-1];
 addr = strsep(&addr, "%");
 snprintf(taddr, sizeof(taddr),
  (family == 2) ? "%s:%d,1" : "[%s]:%d,1",
       addr, server_port);
 text_key_add(conn, "TargetAddress", taddr);
}

variable_types: struct connection { int state; int iostate; int fd; struct session { struct __qelem { struct __qelem *q_forw; struct __qelem *q_back; } slist; char *initiator; struct target { struct __qelem tlist; struct __qelem sessions_list; unsigned int tid; char name[256]; char *alias; struct redirect_addr { char addr[-1]; char port[-1]; unsigned int type; } redirect; int max_nr_sessions; int nr_sessions; struct __qelem isns_head; } *target; union iscsi_sid { struct { unsigned int isid[6]; unsigned int tsih; } id; unsigned int id64; } sid; int conn_cnt; } *session; unsigned int tid; struct iscsi_param { int state; unsigned int val; } session_param[-1]; char *initiator; union iscsi_sid sid; unsigned int cid; int session_type; int auth_method; unsigned int stat_sn; unsigned int exp_stat_sn; unsigned int cmd_sn; unsigned int exp_cmd_sn; unsigned int max_cmd_sn; unsigned int ttt; struct PDU { struct iscsi_hdr { unsigned int opcode; unsigned int flags; unsigned int spec1[2]; unsigned int ahslength; unsigned int datalength[3]; unsigned int lun[4]; unsigned int itt; unsigned int ttt; unsigned int sn; unsigned int exp_sn; unsigned int max_sn; unsigned int spec3[3]; } bhs; void *ahs; unsigned int ahssize; void *data; unsigned int datasize; } req; void *req_buffer; struct PDU rsp; struct __qelem rsp_buf_list; unsigned char *buffer; int rwsize; int auth_state; union { struct { int digest_alg; int id; int challenge_size; unsigned char *challenge; } chap; } auth; } *

variable_types: family int

variable_types:
taddr
char [-1]

user_defined_types: struct connection { int state; int iostate; int fd; struct session *session; unsigned int tid; struct iscsi_param session_param[-1]; char *initiator; union iscsi_sid sid; unsigned int cid; int session_type; int auth_method; unsigned int stat_sn; unsigned int exp_stat_sn; unsigned int cmd_sn; unsigned int exp_cmd_sn; unsigned int max_cmd_sn; unsigned int ttt; struct PDU req; void *req_buffer; struct PDU rsp; struct __qelem rsp_buf_list; unsigned char *buffer; int rwsize; int auth_state; union { struct { int digest_alg; int id; int challenge_size; unsigned char *challenge; } chap; } auth; }

user_defined_types: struct session { struct __qelem slist; char *initiator; struct target *target; union iscsi_sid sid; int conn_cnt; }

user_defined_types: struct target { struct __qelem tlist; struct __qelem sessions_list; unsigned int tid; char name[256]; char *alias; struct redirect_addr redirect; int max_nr_sessions; int nr_sessions; struct __qelem isns_head; }


decompiled_code:
__int64 __fastcall all_accounts_del(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
__int64 v3; // [rsp+0h] [rbp-218h] BYREF
char v4[280]; // [rsp+100h] [rbp-118h] BYREF

memset(v4, 0, 0x100uLL);
while ( 1 )
{
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, char *, __int64 *))(cops + 80LL))(a1, a2, v4, &v3);
if ( (_DWORD)result == -2 )
break;
(*(void (__fastcall **)(_QWORD, _QWORD, char *))(cops + 72LL))(a1, a2, v4);
memset(v4, 0, 0x100uLL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
__int64 v3; // [rsp+0h] [rbp-218h] BYREF
char v4[280]; // [rsp+100h] [rbp-118h] BYREF

memset(v4, 0, 0x100uLL);
while ( 1 )
{
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, char *, __int64 *))(cops + 80LL))(a1, a2, v4, &v3);
if ( (_DWORD)result == -2 )
break;
(*(void (__fastcall **)(_QWORD, _QWORD, char *))(cops + 72LL))(a1, a2, v4);
memset(v4, 0, 0x100uLL);
}
return result;
}

original_code:
static void all_accounts_del(u32 tid, int dir)
{
 char name[256], pass[256];
 memset(name, 0, sizeof(name));
 for (;cops->account_query(tid, dir, name, pass) != -2;
  memset(name, 0, sizeof(name))) {
  cops->account_del(tid, dir, name);
 }
}

canonical_original_code:
static void all_accounts_del(unsigned int tid, int dir)
{
 char name[256]; char pass[256];
 memset(name, 0, sizeof(name));
 for (;cops->account_query(tid, dir, name, pass) != -2;
  memset(name, 0, sizeof(name))) {
  cops->account_del(tid, dir, name);
 }
}

variable_types:
tid
unsigned int

variable_types: dir int

variable_types:
name
char [256]

variable_types:
pass
char [256]


decompiled_code:
void __fastcall target_list_build_ifaddrs(__int64 a1, unsigned int a2, const char *a3, int a4)
{
struct ifaddrs *v7; // rbx
socklen_t v8; // er12
const struct sockaddr *v9; // rdi
char host[1032]; // [rsp+0h] [rbp-448h] BYREF
struct ifaddrs *ifap; // [rsp+408h] [rbp-40h] BYREF

getifaddrs(&ifap);
v7 = ifap;
if ( ifap )
{
v8 = 16;
if ( a4 != 2 )
v8 = 28;
do
{
v9 = v7->ifa_addr;
if ( v9
&& v9->sa_family == a4
&& !getnameinfo(v9, v8, host, 0x401u, 0LL, 0, 1)
&& strcmp(a3, host)
&& !(unsigned int)is_addr_loopback(host)
&& (*(unsigned int (__fastcall **)(_QWORD, struct sockaddr *))(cops + 104LL))(a2, v7->ifa_addr) )
{
target_print_addr(a1, host, a4);
}
v7 = v7->ifa_next;
}
while ( v7 );
}
freeifaddrs(ifap);
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, unsigned int a2, const char *a3, int a4)
{
struct ifaddrs *v7; // rbx
socklen_t v8; // er12
const struct sockaddr *v9; // rdi
char host[1032]; // [rsp+0h] [rbp-448h] BYREF
struct ifaddrs *ifap; // [rsp+408h] [rbp-40h] BYREF

getifaddrs(&ifap);
v7 = ifap;
if ( ifap )
{
v8 = 16;
if ( a4 != 2 )
v8 = 28;
do
{
v9 = v7->ifa_addr;
if ( v9
&& v9->sa_family == a4
&& !getnameinfo(v9, v8, host, 0x401u, 0LL, 0, 1)
&& strcmp(a3, host)
&& !(unsigned int)func3(host)
&& (*(unsigned int (__fastcall **)(_QWORD, struct sockaddr *))(cops + 104LL))(a2, v7->ifa_addr) )
{
func4(a1, host, a4);
}
v7 = v7->ifa_next;
}
while ( v7 );
}
freeifaddrs(ifap);
}

original_code:
void target_list_build_ifaddrs(struct connection *conn, u32 tid, char *addr,
        int family)
{
 struct ifaddrs *ifaddr, *ifa;
 char if_addr[1025];
 getifaddrs(&ifaddr);
 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
  if (!ifa->ifa_addr)
   continue;
  int sa_family = ifa->ifa_addr->sa_family;
  if (sa_family == family) {
   if (getnameinfo(ifa->ifa_addr, (family == 2) ?
      sizeof(struct sockaddr_in) :
      sizeof(struct sockaddr_in6),
      if_addr, sizeof(if_addr),
      ((void *)0), 0, 1))
    continue;
   if (strcmp(addr, if_addr) && !is_addr_loopback(if_addr)
    && cops->target_allow(tid, ifa->ifa_addr))
    target_print_addr(conn, if_addr, family);
  }
 }
 freeifaddrs(ifaddr);
}

canonical_original_code:
void target_list_build_ifaddrs(struct connection *conn, unsigned int tid, char *addr, int family)
{
 struct ifaddrs *ifaddr; struct ifaddrs *ifa;
 char if_addr[1025];
 getifaddrs(&ifaddr);
 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
  if (!ifa->ifa_addr)
   continue;
  int sa_family = ifa->ifa_addr->sa_family;
  if (sa_family == family) {
   if (getnameinfo(ifa->ifa_addr, (family == 2) ?
      sizeof(struct sockaddr_in) :
      sizeof(struct sockaddr_in6),
      if_addr, sizeof(if_addr),
      ((void *)0), 0, 1))
    continue;
   if (strcmp(addr, if_addr) && !is_addr_loopback(if_addr)
    && cops->target_allow(tid, ifa->ifa_addr))
    target_print_addr(conn, if_addr, family);
  }
 }
 freeifaddrs(ifaddr);
}

variable_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; } *

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; }

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }

user_defined_types: struct iscsi_hdr { unsigned int opcode; unsigned int flags; unsigned int spec1[2]; unsigned int ahslength; unsigned int datalength[3]; unsigned int lun[4]; unsigned int itt; unsigned int ttt; unsigned int sn; unsigned int exp_sn; unsigned int max_sn; unsigned int spec3[3]; }

user_defined_types: struct __qelem { struct __qelem *q_forw; struct __qelem *q_back; }

user_defined_types: union iscsi_sid { struct { unsigned int isid[6]; unsigned int tsih; } id; unsigned int id64; }

user_defined_types: struct redirect_addr { char addr[-1]; char port[-1]; unsigned int type; }


decompiled_code:
__int64 __fastcall target_del(unsigned int a1)
{
void **v1; // rax
void **v2; // rbx
int v3; // ebp
int *v5; // rax

v1 = target_find_by_id(a1);
if ( v1 )
{
v2 = v1;
if ( list_empty(v1 + 2) )
{
v3 = (*(__int64 (__fastcall **)(_QWORD))(ki + 56LL))(a1);
if ( v3 < 0 )
{
v5 = _errno_location();
log_error("unable to delete target %u: %d", a1, (unsigned int)*v5);
}
else
{
remque(v2);
all_accounts_del(a1, 0);
all_accounts_del(a1, 1u);
isns_target_deregister((char *)v2 + 36);
free(v2);
v3 = 0;
}
}
else
{
log_warning("%s: target %u still has sessions\n", "target_del", a1);
v3 = -16;
}
}
else
{
v3 = -2;
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
void **v1; // rax
void **v2; // rbx
int v3; // ebp
int *v5; // rax

v1 = func9(a1);
if ( v1 )
{
v2 = v1;
if ( func0(v1 + 2) )
{
v3 = (*(__int64 (__fastcall **)(_QWORD))(ki + 56LL))(a1);
if ( v3 < 0 )
{
v5 = _errno_location();
log_error("unable to delete target %u: %d", a1, (unsigned int)*v5);
}
else
{
remque(v2);
func5(a1, 0);
func5(a1, 1u);
isns_target_deregister((char *)v2 + 36);
free(v2);
v3 = 0;
}
}
else
{
log_warning("%s: target %u still has sessions\n", "target_del", a1);
v3 = -16;
}
}
else
{
v3 = -2;
}
return (unsigned int)v3;
}

original_code:
int target_del(u32 tid)
{
 struct target *target = target_find_by_id(tid);
 int err;
 if (!target)
  return -2;
 if (!list_empty(&target->sessions_list)) {
  log_warning("%s: target %u still has sessions\n", __FUNCTION__,
     tid);
  return -16;
 }
 err = ki->target_destroy(tid);
 if (err < 0) {
  log_error("unable to delete target %u: %d", tid, (*__errno_location ()));
  return err;
 }
 remque(&target->tlist);
 all_accounts_del(tid, 0);
 all_accounts_del(tid, 1);
 isns_target_deregister(target->name);
 free(target);
 return 0;
}

canonical_original_code:
int target_del(unsigned int tid)
{
 struct target *target = target_find_by_id(tid);
 int err;
 if (!target)
  return -2;
 if (!list_empty(&target->sessions_list)) {
  log_warning("%s: target %u still has sessions\n", __FUNCTION__,
     tid);
  return -16;
 }
 err = ki->target_destroy(tid);
 if (err < 0) {
  log_error("unable to delete target %u: %d", tid, (*__errno_location ()));
  return err;
 }
 remque(&target->tlist);
 all_accounts_del(tid, 0);
 all_accounts_del(tid, 1);
 isns_target_deregister(target->name);
 free(target);
 return 0;
}

variable_types: struct target { struct __qelem { struct __qelem *q_forw; struct __qelem *q_back; } tlist; struct __qelem sessions_list; unsigned int tid; char name[256]; char *alias; struct redirect_addr { char addr[-1]; char port[-1]; unsigned int type; } redirect; int max_nr_sessions; int nr_sessions; struct __qelem isns_head; } *

variable_types: err int


decompiled_code:
__int64 __fastcall target_add(unsigned int *a1, __int64 a2)
{
_QWORD *v2; // rbx
int v3; // er13
int *v5; // rax

if ( a2 )
{
v2 = malloc(0x570uLL);
if ( v2 )
{
memset(v2, 0, 0x570uLL);
*(_QWORD *)((char *)v2 + 36) = *(_QWORD *)a2;
*(_QWORD *)((char *)v2 + 283) = *(_QWORD *)(a2 + 247);
qmemcpy(
(void *)(((unsigned __int64)v2 + 44) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(a2 - (_QWORD)((char *)v2 - (((unsigned __int64)v2 + 44) & 0xFFFFFFFFFFFFFFF8LL) + 36)),
8LL * (((_DWORD)v2 + 36 - (((_DWORD)v2 + 44) & 0xFFFFFFF8) + 255) >> 3));
v3 = (*(__int64 (__fastcall **)(unsigned int *, __int64))(ki + 48LL))(a1, a2);
if ( v3 < 0 )
{
v5 = _errno_location();
log_warning("unable create target %u: %d\n", *a1, (unsigned int)*v5);
free(v2);
}
else
{
*v2 = v2;
v2[1] = v2;
v2[2] = v2 + 2;
v2[3] = v2 + 2;
v2[172] = v2 + 172;
v2[173] = v2 + 172;
*((_DWORD *)v2 + 8) = *a1;
insque(v2, &targets_list);
isns_target_register(a2);
log_debug(1LL, "created target %s", (const char *)a2);
v3 = 0;
}
}
else
{
v3 = -12;
}
}
else
{
v3 = -22;
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int *a1, __int64 a2)
{
_QWORD *v2; // rbx
int v3; // er13
int *v5; // rax

if ( a2 )
{
v2 = malloc(0x570uLL);
if ( v2 )
{
memset(v2, 0, 0x570uLL);
*(_QWORD *)((char *)v2 + 36) = *(_QWORD *)a2;
*(_QWORD *)((char *)v2 + 283) = *(_QWORD *)(a2 + 247);
qmemcpy(
(void *)(((unsigned __int64)v2 + 44) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(a2 - (_QWORD)((char *)v2 - (((unsigned __int64)v2 + 44) & 0xFFFFFFFFFFFFFFF8LL) + 36)),
8LL * (((_DWORD)v2 + 36 - (((_DWORD)v2 + 44) & 0xFFFFFFF8) + 255) >> 3));
v3 = (*(__int64 (__fastcall **)(unsigned int *, __int64))(ki + 48LL))(a1, a2);
if ( v3 < 0 )
{
v5 = _errno_location();
log_warning("unable create target %u: %d\n", *a1, (unsigned int)*v5);
free(v2);
}
else
{
*v2 = v2;
v2[1] = v2;
v2[2] = v2 + 2;
v2[3] = v2 + 2;
v2[172] = v2 + 172;
v2[173] = v2 + 172;
*((_DWORD *)v2 + 8) = *a1;
insque(v2, &targets_list);
isns_target_register(a2);
log_debug(1LL, "created target %s", (const char *)a2);
v3 = 0;
}
}
else
{
v3 = -12;
}
}
else
{
v3 = -22;
}
return (unsigned int)v3;
}

original_code:
int target_add(u32 *tid, char *name)
{
 struct target *target;
 int err;
 if (!name)
  return -22;
 if (!(target = malloc(sizeof(*target))))
  return -12;
 memset(target, 0, sizeof(*target));
 memcpy(target->name, name, sizeof(target->name) - 1);
 err = ki->target_create(tid, name);
 if (err < 0) {
  log_warning("unable create target %u: %d\n", *tid, (*__errno_location ()));
  goto out;
 }
 do { (&target->tlist)->q_forw = (&target->tlist); (&target->tlist)->q_back = (&target->tlist); } while (0);
 do { (&target->sessions_list)->q_forw = (&target->sessions_list); (&target->sessions_list)->q_back = (&target->sessions_list); } while (0);
 do { (&target->isns_head)->q_forw = (&target->isns_head); (&target->isns_head)->q_back = (&target->isns_head); } while (0);
 target->tid = *tid;
 insque(&target->tlist, &targets_list);
 isns_target_register(name);
 log_debug(1, "created target %s", name);
 return 0;
out:
 free(target);
 return err;
}

canonical_original_code:
int target_add(unsigned int *tid, char *name)
{
 struct target *target;
 int err;
 if (!name)
  return -22;
 if (!(target = malloc(sizeof(*target))))
  return -12;
 memset(target, 0, sizeof(*target));
 memcpy(target->name, name, sizeof(target->name) - 1);
 err = ki->target_create(tid, name);
 if (err < 0) {
  log_warning("unable create target %u: %d\n", *tid, (*__errno_location ()));
  goto out;
 }
 do { (&target->tlist)->q_forw = (&target->tlist); (&target->tlist)->q_back = (&target->tlist); } while (0);
 do { (&target->sessions_list)->q_forw = (&target->sessions_list); (&target->sessions_list)->q_back = (&target->sessions_list); } while (0);
 do { (&target->isns_head)->q_forw = (&target->isns_head); (&target->isns_head)->q_back = (&target->isns_head); } while (0);
 target->tid = *tid;
 insque(&target->tlist, &targets_list);
 isns_target_register(name);
 log_debug(1, "created target %s", name);
 return 0;
out:
 free(target);
 return err;
}

variable_types:
tid
unsigned int *

variable_types:
name
char *


decompiled_code:
int __fastcall target_redirected(__int64 a1, __int64 a2, const struct sockaddr *a3)
{
int result; // eax
socklen_t v6; // esi
int v7; // edx
char *v8; // rax
const char *v9; // r8
char v10[1072]; // [rsp-430h] [rbp-C68h] BYREF
char s[1040]; // [rsp+0h] [rbp-838h] BYREF
char host[1064]; // [rsp+410h] [rbp-428h] BYREF

result = 0;
if ( *(_BYTE *)(a1 + 304) )
{
v6 = 16;
if ( a3->sa_family != 2 )
v6 = 28;
v7 = getnameinfo(a3, v6, host, 0x402u, 0LL, 0, 1);
result = 0;
if ( !v7 )
{
v8 = strrchr(host, 37);
if ( v8 )
*v8 = 0;
if ( a3->sa_family == 10 )
snprintf(s, 0x404uLL, "[%s]", host);
else
snprintf(s, 0x404uLL, "%s", host);
v9 = "3260";
if ( *(_BYTE *)(a1 + 1330) )
v9 = (const char *)(a1 + 1330);
snprintf(v10, 0x425uLL, "%s:%s", (const char *)(a1 + 304), v9);
result = strcmp((const char *)(a1 + 304), s);
if ( result )
{
text_key_add(a2, "TargetAddress", v10);
result = 1;
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1, __int64 a2, const struct sockaddr *a3)
{
int result; // eax
socklen_t v6; // esi
int v7; // edx
char *v8; // rax
const char *v9; // r8
char v10[1072]; // [rsp-430h] [rbp-C68h] BYREF
char s[1040]; // [rsp+0h] [rbp-838h] BYREF
char host[1064]; // [rsp+410h] [rbp-428h] BYREF

result = 0;
if ( *(_BYTE *)(a1 + 304) )
{
v6 = 16;
if ( a3->sa_family != 2 )
v6 = 28;
v7 = getnameinfo(a3, v6, host, 0x402u, 0LL, 0, 1);
result = 0;
if ( !v7 )
{
v8 = strrchr(host, 37);
if ( v8 )
*v8 = 0;
if ( a3->sa_family == 10 )
snprintf(s, 0x404uLL, "[%s]", host);
else
snprintf(s, 0x404uLL, "%s", host);
v9 = "3260";
if ( *(_BYTE *)(a1 + 1330) )
v9 = (const char *)(a1 + 1330);
snprintf(v10, 0x425uLL, "%s:%s", (const char *)(a1 + 304), v9);
result = strcmp((const char *)(a1 + 304), s);
if ( result )
{
text_key_add(a2, "TargetAddress", v10);
result = 1;
}
}
}
return result;
}

original_code:
int target_redirected(struct target *target, struct connection *conn, struct sockaddr *sa)
{
 char tmp[1025 + 1];
 char addr[1025 + 3];
 char redirect[1025 + 32 + 4];
 char *p;
 if (!strlen(target->redirect.addr))
  return 0;
 if (getnameinfo(sa, (sa->sa_family == 2) ?
     sizeof(struct sockaddr_in) :
     sizeof(struct sockaddr_in6),
     tmp, sizeof(tmp), ((void *)0), 0,
     1))
  return 0;
 if ((p = strrchr(tmp, '%')))
  *p = '\0';
 if (sa->sa_family == 10)
  snprintf(addr, sizeof(addr), "[%s]", tmp);
 else
  snprintf(addr, sizeof(addr), "%s", tmp);
 snprintf(redirect, sizeof(redirect), "%s:%s", target->redirect.addr,
  strlen(target->redirect.port) ? target->redirect.port : "3260");
 if (strcmp(target->redirect.addr, addr)) {
  text_key_add(conn, "TargetAddress", redirect);
  return 1;
 }
 return 0;
}

canonical_original_code:
int target_redirected(struct target *target, struct connection *conn, struct sockaddr *sa)
{
 char tmp[-1];
 char addr[-1];
 char redirect[-1];
 char *p;
 if (!strlen(target->redirect.addr))
  return 0;
 if (getnameinfo(sa, (sa->sa_family == 2) ?
     sizeof(struct sockaddr_in) :
     sizeof(struct sockaddr_in6),
     tmp, sizeof(tmp), ((void *)0), 0,
     1))
  return 0;
 if ((p = strrchr(tmp, '%')))
  *p = '\0';
 if (sa->sa_family == 10)
  snprintf(addr, sizeof(addr), "[%s]", tmp);
 else
  snprintf(addr, sizeof(addr), "%s", tmp);
 snprintf(redirect, sizeof(redirect), "%s:%s", target->redirect.addr,
  strlen(target->redirect.port) ? target->redirect.port : "3260");
 if (strcmp(target->redirect.addr, addr)) {
  text_key_add(conn, "TargetAddress", redirect);
  return 1;
 }
 return 0;
}

variable_types: struct connection { int state; int iostate; int fd; struct session { struct __qelem slist; char *initiator; struct target *target; union iscsi_sid { struct { unsigned int isid[6]; unsigned int tsih; } id; unsigned int id64; } sid; int conn_cnt; } *session; unsigned int tid; struct iscsi_param { int state; unsigned int val; } session_param[-1]; char *initiator; union iscsi_sid sid; unsigned int cid; int session_type; int auth_method; unsigned int stat_sn; unsigned int exp_stat_sn; unsigned int cmd_sn; unsigned int exp_cmd_sn; unsigned int max_cmd_sn; unsigned int ttt; struct PDU { struct iscsi_hdr { unsigned int opcode; unsigned int flags; unsigned int spec1[2]; unsigned int ahslength; unsigned int datalength[3]; unsigned int lun[4]; unsigned int itt; unsigned int ttt; unsigned int sn; unsigned int exp_sn; unsigned int max_sn; unsigned int spec3[3]; } bhs; void *ahs; unsigned int ahssize; void *data; unsigned int datasize; } req; void *req_buffer; struct PDU rsp; struct __qelem rsp_buf_list; unsigned char *buffer; int rwsize; int auth_state; union { struct { int digest_alg; int id; int challenge_size; unsigned char *challenge; } chap; } auth; } *

variable_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; } *

variable_types:
tmp
char [-1]

variable_types:
addr
char [-1]

variable_types:
redirect
char [-1]

variable_types:
p
char *


decompiled_code:
char *conn_alloc()
{
char *v0; // rbx

v0 = (char *)malloc(0x1D0uLL);
if ( v0 )
{
memset(v0, 0, 0x1D0uLL);
param_set_defaults(v0 + 28, &session_keys);
*((_QWORD *)v0 + 51) = v0 + 408;
*((_QWORD *)v0 + 52) = v0 + 408;
}
return v0;
}

canonical_decompiled_code:
char *func0()
{
char *v0; // rbx

v0 = (char *)malloc(0x1D0uLL);
if ( v0 )
{
memset(v0, 0, 0x1D0uLL);
param_set_defaults(v0 + 28, &session_keys);
*((_QWORD *)v0 + 51) = v0 + 408;
*((_QWORD *)v0 + 52) = v0 + 408;
}
return v0;
}

original_code:
struct connection *conn_alloc(void)
{
 struct connection *conn;
 if (!(conn = malloc(sizeof(*conn))))
  return ((void *)0);
 memset(conn, 0, sizeof(*conn));
 conn->state = 0;
 param_set_defaults(conn->session_param, session_keys);
 do { (&conn->rsp_buf_list)->q_forw = (&conn->rsp_buf_list); (&conn->rsp_buf_list)->q_back = (&conn->rsp_buf_list); } while (0);
 return conn;
}

canonical_original_code:
struct connection *conn_alloc()
{
 struct connection *conn;
 if (!(conn = malloc(sizeof(*conn))))
  return ((void *)0);
 memset(conn, 0, sizeof(*conn));
 conn->state = 0;
 param_set_defaults(conn->session_param, session_keys);
 do { (&conn->rsp_buf_list)->q_forw = (&conn->rsp_buf_list); (&conn->rsp_buf_list)->q_back = (&conn->rsp_buf_list); } while (0);
 return conn;
}

variable_types: struct connection { int state; int iostate; int fd; struct session { struct __qelem { struct __qelem *q_forw; struct __qelem *q_back; } slist; char *initiator; struct target { struct __qelem tlist; struct __qelem sessions_list; unsigned int tid; char name[256]; char *alias; struct redirect_addr { char addr[-1]; char port[-1]; unsigned int type; } redirect; int max_nr_sessions; int nr_sessions; struct __qelem isns_head; } *target; union iscsi_sid { struct { unsigned int isid[6]; unsigned int tsih; } id; unsigned int id64; } sid; int conn_cnt; } *session; unsigned int tid; struct iscsi_param { int state; unsigned int val; } session_param[-1]; char *initiator; union iscsi_sid sid; unsigned int cid; int session_type; int auth_method; unsigned int stat_sn; unsigned int exp_stat_sn; unsigned int cmd_sn; unsigned int exp_cmd_sn; unsigned int max_cmd_sn; unsigned int ttt; struct PDU { struct iscsi_hdr { unsigned int opcode; unsigned int flags; unsigned int spec1[2]; unsigned int ahslength; unsigned int datalength[3]; unsigned int lun[4]; unsigned int itt; unsigned int ttt; unsigned int sn; unsigned int exp_sn; unsigned int max_sn; unsigned int spec3[3]; } bhs; void *ahs; unsigned int ahssize; void *data; unsigned int datasize; } req; void *req_buffer; struct PDU rsp; struct __qelem rsp_buf_list; unsigned char *buffer; int rwsize; int auth_state; union { struct { int digest_alg; int id; int challenge_size; unsigned char *challenge; } chap; } auth; } *


decompiled_code:
void __fastcall conn_free(void *ptr)
{
free(*((void **)ptr + 23));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
free(*((void **)ptr + 23));
free(ptr);
}

original_code:
void conn_free(struct connection *conn)
{
 free(conn->initiator);
 free(conn);
}


decompiled_code:
__int64 __fastcall conn_take_fd(__int64 a1, unsigned int a2)
{
__int64 result; // rax
int *v3; // rax

log_debug(
1LL,
"conn_take_fd: %d %u %u %u %lx",
a2,
*(unsigned __int16 *)(a1 + 200),
*(unsigned int *)(a1 + 212),
*(unsigned int *)(a1 + 216),
*(_QWORD *)(a1 + 192));
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD))(ki + 88LL))(
*(unsigned int *)(a1 + 24),
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 32LL),
*(unsigned __int16 *)(a1 + 200),
*(unsigned int *)(a1 + 212),
*(unsigned int *)(a1 + 216),
a2,
*(unsigned int *)(a1 + 136),
*(unsigned int *)(a1 + 144));
if ( (_DWORD)result )
{
--*(_DWORD *)(*(_QWORD *)(a1 + 16) + 40LL);
v3 = _errno_location();
result = log_error(
"unable to create connection %u for session %#lx in target %u: %d",
*(unsigned __int16 *)(a1 + 200),
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 32LL),
*(unsigned int *)(a1 + 24),
(unsigned int)*v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
__int64 result; // rax
int *v3; // rax

log_debug(
1LL,
"conn_take_fd: %d %u %u %u %lx",
a2,
*(unsigned __int16 *)(a1 + 200),
*(unsigned int *)(a1 + 212),
*(unsigned int *)(a1 + 216),
*(_QWORD *)(a1 + 192));
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD))(ki + 88LL))(
*(unsigned int *)(a1 + 24),
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 32LL),
*(unsigned __int16 *)(a1 + 200),
*(unsigned int *)(a1 + 212),
*(unsigned int *)(a1 + 216),
a2,
*(unsigned int *)(a1 + 136),
*(unsigned int *)(a1 + 144));
if ( (_DWORD)result )
{
--*(_DWORD *)(*(_QWORD *)(a1 + 16) + 40LL);
v3 = _errno_location();
result = log_error(
"unable to create connection %u for session %#lx in target %u: %d",
*(unsigned __int16 *)(a1 + 200),
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 32LL),
*(unsigned int *)(a1 + 24),
(unsigned int)*v3);
}
return result;
}

original_code:
void conn_take_fd(struct connection *conn, int fd)
{
 int err;
 log_debug(1, "conn_take_fd: %d %u %u %u %" "l" "x",
    fd, conn->cid, conn->stat_sn, conn->exp_stat_sn, conn->sid.id64);
 err = ki->conn_create(conn->tid, conn->session->sid.id64, conn->cid,
         conn->stat_sn, conn->exp_stat_sn, fd,
         conn->session_param[key_header_digest].val,
         conn->session_param[key_data_digest].val);
 if (err) {
  conn->session->conn_cnt--;
  log_error("unable to create connection %u for session %#" "l" "x" " in target %u: %d",
   conn->cid, conn->session->sid.id64, conn->tid, (*__errno_location ()));
 }
 return;
}

variable_types: fd int


original_code:
void conn_read_pdu(struct connection *conn)
{
 conn->iostate = 1;
 conn->buffer = (void *)&conn->req.bhs;
 conn->rwsize = 48;
}


original_code:
void conn_write_pdu(struct connection *conn)
{
 conn->iostate = 3;
 memset(&conn->rsp, 0, sizeof(conn->rsp));
 conn->buffer = (void *)&conn->rsp.bhs;
 conn->rwsize = 48;
}


decompiled_code:
__int64 __fastcall sha1_transform(int *a1, __int64 a2)
{
int v3[80]; // [rsp+0h] [rbp-140h] BYREF

return _sha1_transform(a1, a2, v3);
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, __int64 a2)
{
int v3[80]; // [rsp+0h] [rbp-140h] BYREF

return func2(a1, a2, v3);
}

original_code:
static inline void sha1_transform(u32 digest[5],
       const u32 block[16])
{
 u32 workspace[80];
 __sha1_transform(digest, block, workspace);
}

canonical_original_code:
static inline void sha1_transform(unsigned int digest[5], unsigned int block[16])
{
 unsigned int workspace[80];
 __sha1_transform(digest, block, workspace);
}

variable_types:
digest
unsigned int [5]

variable_types:
block
unsigned int [16]

variable_types:
workspace
unsigned int [80]


original_code:
void sha1_init(struct sha1_ctx *ctx)
{
 ctx->digest[0] = 0x67452301UL;
 ctx->digest[1] = 0xEFCDAB89UL;
 ctx->digest[2] = 0x98BADCFEUL;
 ctx->digest[3] = 0x10325476UL;
 ctx->digest[4] = 0xC3D2E1F0UL;
 ctx->count = 0;
}

variable_types: struct sha1_ctx { unsigned int digest[5]; unsigned int block[16]; unsigned int count; } *


original_code:
void sha1_update(struct sha1_ctx *ctx, const void *data_in, size_t len)
{
 const size_t offset = ctx->count & 0x3f;
 const size_t avail = (16 * 4) - offset;
 const u8 *data = data_in;
 ctx->count += len;
 if (avail > len) {
  memcpy((u8 *)ctx->block + offset, data, len);
  return;
 }
 memcpy((u8 *)ctx->block + offset, data, avail);
 sha1_transform(ctx->digest, ctx->block);
 data += avail;
 len -= avail;
 while (len >= (16 * 4)) {
  memcpy(ctx->block, data, (16 * 4));
  sha1_transform(ctx->digest, ctx->block);
  data += (16 * 4);
  len -= (16 * 4);
 }
 if (len)
  memcpy(ctx->block, data, len);
}

canonical_original_code:
void sha1_update(struct sha1_ctx *ctx, void *data_in, unsigned long len)
{
 unsigned long offset = ctx->count & 0x3f;
 unsigned long avail = (16 * 4) - offset;
 unsigned int *data = data_in;
 ctx->count += len;
 if (avail > len) {
  memcpy((unsigned int *)ctx->block + offset, data, len);
  return;
 }
 memcpy((unsigned int *)ctx->block + offset, data, avail);
 sha1_transform(ctx->digest, ctx->block);
 data += avail;
 len -= avail;
 while (len >= (16 * 4)) {
  memcpy(ctx->block, data, (16 * 4));
  sha1_transform(ctx->digest, ctx->block);
  data += (16 * 4);
  len -= (16 * 4);
 }
 if (len)
  memcpy(ctx->block, data, len);
}

variable_types:
len
unsigned long

variable_types:
offset
unsigned long

variable_types:
avail
unsigned long

variable_types:
data
unsigned int *

user_defined_types: struct sha1_ctx { unsigned int digest[5]; unsigned int block[16]; unsigned int count; }