main

repo: csimmonds/boot-extract

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
int i; // er12
int v5; // eax
int v6; // eax
int v7; // er13
int v8; // er14
unsigned int v9; // ebp
unsigned int v10; // ebp
int v11; // ebp
size_t v12; // r14
void *v13; // rax
void *v14; // r12
int v15; // eax
int *v17; // rax
char *v18; // rax
int v19; // er12
size_t v20; // r15
void *v21; // rax
void *v22; // rbx
int v23; // eax
__int64 v24; // rdx
signed int v25; // ebx
int v26; // er12
size_t v27; // r15
void *v28; // rax
void *v29; // rbx
int v30; // eax
char v31[8]; // [rsp+0h] [rbp-298h] BYREF
size_t nbytes; // [rsp+8h] [rbp-290h]
size_t n; // [rsp+10h] [rbp-288h]
size_t size; // [rsp+18h] [rbp-280h]
unsigned int v35; // [rsp+20h] [rbp-278h]
__off_t offset; // [rsp+24h] [rbp-274h]
char v37[16]; // [rsp+30h] [rbp-268h] BYREF
char v38[600]; // [rsp+40h] [rbp-258h] BYREF

v3 = argv;
if ( argc == 1 )
goto LABEL_34;
for ( i = 0; ; i = 1 )
{
argv = v3;
v5 = getopt(argc, (char *const *)v3, "hi");
if ( v5 == -1 )
break;
if ( v5 == 104 )
goto LABEL_34;
if ( v5 != 105 )
exit(1);
}
argv = (const char **)(unsigned int)argc;
printf("argc %d optind %d\n", (unsigned int)argc, (unsigned int)_bss_start);
if ( _bss_start == argc )
LABEL_34:
usage(*v3, argv, envp);
v6 = open(v3[_bss_start], 0);
v7 = v6;
if ( v6 == -1 )
{
v17 = __errno_location();
v8 = 1;
v18 = strerror(*v17);
printf("Failed to open %s (%s)\n", v3[_bss_start], v18);
return v8;
}
if ( (unsigned int)read(v6, v31, 0x260uLL) <= 0x25F )
{
v8 = 1;
puts("read failed");
return v8;
}
v8 = strncmp(v31, "ANDROID!", 8uLL);
if ( v8 )
{
v8 = 1;
puts("Boot magic missing or corrupt: not a valid boot image");
return v8;
}
printf(
"Boot header\n"
" flash page size\t%d\n"
" kernel size\t\t0x%x\n"
" kernel load addr\t0x%x\n"
" ramdisk size\t\t0x%x\n"
" ramdisk load addr\t0x%x\n"
" second size\t\t0x%x\n"
" second load addr\t0x%x\n"
" tags addr\t\t0x%x\n"
" product name\t\t'%s'\n"
" kernel cmdline\t'%s'\n"
"\n",
(unsigned int)offset,
(unsigned int)nbytes,
HIDWORD(nbytes),
(unsigned int)n,
HIDWORD(n),
(unsigned int)size,
HIDWORD(size),
v35,
v37,
v38);
if ( !i )
{
v9 = offset;
if ( (_DWORD)nbytes )
{
lseek(v7, (unsigned int)offset, 0);
v19 = open("zImage", 577, 420LL);
if ( v19 < 0 )
{
v8 = 1;
puts("Failed to create kernel file");
return v8;
}
v20 = (unsigned int)nbytes;
v21 = malloc((unsigned int)nbytes);
v22 = v21;
if ( !v21 )
goto LABEL_36;
v23 = read(v7, v21, v20);
if ( (_DWORD)nbytes != v23 )
goto LABEL_24;
write(v19, v22, (unsigned int)nbytes);
free(v22);
close(v19);
puts("zImage extracted");
}
if ( (_DWORD)n )
{
v24 = v9 * ((v9 + (unsigned int)nbytes - 1) / v9 + 1);
v25 = v9 * ((v9 + (unsigned int)nbytes - 1) / v9 + 1);
printf("ramdisk offset %d (0x%x)\n", (unsigned int)v24, v24);
lseek(v7, v25, 0);
v26 = open("ramdisk.cpio.gz", 577, 420LL);
if ( v26 < 0 )
{
v8 = 1;
puts("Failed to create ramdisk file");
return v8;
}
v27 = (unsigned int)n;
v28 = malloc((unsigned int)n);
v29 = v28;
if ( !v28 )
goto LABEL_36;
v30 = read(v7, v28, v27);
if ( (_DWORD)n != v30 )
goto LABEL_24;
write(v26, v29, (unsigned int)n);
free(v29);
close(v26);
puts("ramdisk.cpio.gz extracted");
}
if ( (_DWORD)size )
{
v10 = ((v9 + (unsigned int)nbytes + (unsigned int)n - 1) / v9 + 1) * v9;
printf("Second binary at offset %d (0x%x)\n", v10, v10);
lseek(v7, (int)v10, 0);
v11 = open("second.dtb", 577, 420LL);
if ( v11 < 0 )
{
v8 = 1;
puts("Failed to create second (dtb) file");
return v8;
}
v12 = (unsigned int)size;
v13 = malloc((unsigned int)size);
v14 = v13;
if ( v13 )
{
v15 = read(v7, v13, v12);
if ( (_DWORD)size == v15 )
{
v8 = 0;
write(v11, v14, (unsigned int)size);
free(v14);
close(v11);
puts("second.dtb extracted");
return v8;
}
LABEL_24:
v8 = 1;
puts("Error in read");
return v8;
}
LABEL_36:
v8 = 1;
puts("malloc failed");
return v8;
}
}
return v8;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
int i; // er12
int v5; // eax
int v6; // eax
int v7; // er13
int v8; // er14
unsigned int v9; // ebp
unsigned int v10; // ebp
int v11; // ebp
size_t v12; // r14
void *v13; // rax
void *v14; // r12
int v15; // eax
int *v17; // rax
char *v18; // rax
int v19; // er12
size_t v20; // r15
void *v21; // rax
void *v22; // rbx
int v23; // eax
__int64 v24; // rdx
signed int v25; // ebx
int v26; // er12
size_t v27; // r15
void *v28; // rax
void *v29; // rbx
int v30; // eax
char v31[8]; // [rsp+0h] [rbp-298h] BYREF
size_t nbytes; // [rsp+8h] [rbp-290h]
size_t n; // [rsp+10h] [rbp-288h]
size_t size; // [rsp+18h] [rbp-280h]
unsigned int v35; // [rsp+20h] [rbp-278h]
__off_t offset; // [rsp+24h] [rbp-274h]
char v37[16]; // [rsp+30h] [rbp-268h] BYREF
char v38[600]; // [rsp+40h] [rbp-258h] BYREF

v3 = argv;
if ( argc == 1 )
goto LABEL_34;
for ( i = 0; ; i = 1 )
{
argv = v3;
v5 = getopt(argc, (char *const *)v3, "hi");
if ( v5 == -1 )
break;
if ( v5 == 104 )
goto LABEL_34;
if ( v5 != 105 )
exit(1);
}
argv = (const char **)(unsigned int)argc;
printf("argc %d optind %d\n", (unsigned int)argc, (unsigned int)_bss_start);
if ( _bss_start == argc )
LABEL_34:
func7(*v3, argv, envp);
v6 = open(v3[_bss_start], 0);
v7 = v6;
if ( v6 == -1 )
{
v17 = __errno_location();
v8 = 1;
v18 = strerror(*v17);
printf("Failed to open %s (%s)\n", v3[_bss_start], v18);
return v8;
}
if ( (unsigned int)read(v6, v31, 0x260uLL) <= 0x25F )
{
v8 = 1;
puts("read failed");
return v8;
}
v8 = strncmp(v31, "ANDROID!", 8uLL);
if ( v8 )
{
v8 = 1;
puts("Boot magic missing or corrupt: not a valid boot image");
return v8;
}
printf(
"Boot header\n"
" flash page size\t%d\n"
" kernel size\t\t0x%x\n"
" kernel load addr\t0x%x\n"
" ramdisk size\t\t0x%x\n"
" ramdisk load addr\t0x%x\n"
" second size\t\t0x%x\n"
" second load addr\t0x%x\n"
" tags addr\t\t0x%x\n"
" product name\t\t'%s'\n"
" kernel cmdline\t'%s'\n"
"\n",
(unsigned int)offset,
(unsigned int)nbytes,
HIDWORD(nbytes),
(unsigned int)n,
HIDWORD(n),
(unsigned int)size,
HIDWORD(size),
v35,
v37,
v38);
if ( !i )
{
v9 = offset;
if ( (_DWORD)nbytes )
{
lseek(v7, (unsigned int)offset, 0);
v19 = open("zImage", 577, 420LL);
if ( v19 < 0 )
{
v8 = 1;
puts("Failed to create kernel file");
return v8;
}
v20 = (unsigned int)nbytes;
v21 = malloc((unsigned int)nbytes);
v22 = v21;
if ( !v21 )
goto LABEL_36;
v23 = read(v7, v21, v20);
if ( (_DWORD)nbytes != v23 )
goto LABEL_24;
write(v19, v22, (unsigned int)nbytes);
free(v22);
close(v19);
puts("zImage extracted");
}
if ( (_DWORD)n )
{
v24 = v9 * ((v9 + (unsigned int)nbytes - 1) / v9 + 1);
v25 = v9 * ((v9 + (unsigned int)nbytes - 1) / v9 + 1);
printf("ramdisk offset %d (0x%x)\n", (unsigned int)v24, v24);
lseek(v7, v25, 0);
v26 = open("ramdisk.cpio.gz", 577, 420LL);
if ( v26 < 0 )
{
v8 = 1;
puts("Failed to create ramdisk file");
return v8;
}
v27 = (unsigned int)n;
v28 = malloc((unsigned int)n);
v29 = v28;
if ( !v28 )
goto LABEL_36;
v30 = read(v7, v28, v27);
if ( (_DWORD)n != v30 )
goto LABEL_24;
write(v26, v29, (unsigned int)n);
free(v29);
close(v26);
puts("ramdisk.cpio.gz extracted");
}
if ( (_DWORD)size )
{
v10 = ((v9 + (unsigned int)nbytes + (unsigned int)n - 1) / v9 + 1) * v9;
printf("Second binary at offset %d (0x%x)\n", v10, v10);
lseek(v7, (int)v10, 0);
v11 = open("second.dtb", 577, 420LL);
if ( v11 < 0 )
{
v8 = 1;
puts("Failed to create second (dtb) file");
return v8;
}
v12 = (unsigned int)size;
v13 = malloc((unsigned int)size);
v14 = v13;
if ( v13 )
{
v15 = read(v7, v13, v12);
if ( (_DWORD)size == v15 )
{
v8 = 0;
write(v11, v14, (unsigned int)size);
free(v14);
close(v11);
puts("second.dtb extracted");
return v8;
}
LABEL_24:
v8 = 1;
puts("Error in read");
return v8;
}
LABEL_36:
v8 = 1;
puts("malloc failed");
return v8;
}
}
return v8;
}

original_code:
int main(int argc, char **argv)
{
 int opt;
 int info_only = 0;
 int f;
 int fk;
 int fr;
 int n;
 char *buf;
 unsigned int flash_page_size;
 struct boot_img_hdr hdr;
 if (argc == 1)
  usage(argv[0]);
 while ((opt = getopt(argc, argv, "hi")) != -1) {
  switch (opt) {
  case 'i':
   info_only = 1;
   break;
  case 'h':
   usage(argv[0]);
  default:
   exit(1);
  }
 }
 printf("argc %d optind %d\n", argc, optind);
 if (optind == argc)
  usage(argv[0]);
 f = open(argv[optind], 00);
 if (f == -1) {
  printf("Failed to open %s (%s)\n", argv[optind], strerror((*__errno_location ())));
  return 1;
 }
 n = read(f, &hdr, sizeof(hdr));
 if (n < sizeof(hdr)) {
  printf("read failed\n");
  return 1;
 }
 if (strncmp((const char *)hdr.magic, "ANDROID!", 8) != 0) {
  printf("Boot magic missing or corrupt: not a valid boot image\n");
  return 1;
 }
 printf("Boot header\n"
        "  flash page size\t%d\n"
        "  kernel size\t\t0x%x\n"
        "  kernel load addr\t0x%x\n"
        "  ramdisk size\t\t0x%x\n"
        "  ramdisk load addr\t0x%x\n"
        "  second size\t\t0x%x\n"
        "  second load addr\t0x%x\n"
        "  tags addr\t\t0x%x\n"
        "  product name\t\t'%s'\n"
        "  kernel cmdline\t'%s'\n\n",
        hdr.page_size,
        hdr.kernel_size, hdr.kernel_addr,
        hdr.ramdisk_size, hdr.ramdisk_addr,
        hdr.second_size, hdr.second_addr,
        hdr.tags_addr, hdr.name, hdr.cmdline);
 if (info_only)
  return 0;
 flash_page_size = hdr.page_size;
 if (hdr.kernel_size > 0) {
  lseek(f, flash_page_size, 0);
  fk = open("zImage", 01 | 0100 | 01000, 0644);
  if (fk < 0) {
   printf("Failed to create kernel file\n");
   return 1;
  }
  buf = malloc(hdr.kernel_size);
  if (buf == 0) {
   printf("malloc failed\n");
   return 1;
  }
  n = read(f, buf, hdr.kernel_size);
  if (n != hdr.kernel_size) {
   printf ("Error in read\n");
   return 1;
  }
  write(fk, buf, hdr.kernel_size);
  free(buf);
  close(fk);
  printf("zImage extracted\n");
 }
 if (hdr.ramdisk_size > 0) {
  int ramdisk_offset;
  ramdisk_offset =
      (((hdr.kernel_size + flash_page_size -
         1) / flash_page_size) + 1) * flash_page_size;
  printf("ramdisk offset %d (0x%x)\n", ramdisk_offset,
         ramdisk_offset);
  lseek(f, ramdisk_offset, 0);
  fr = open("ramdisk.cpio.gz", 01 | 0100 | 01000, 0644);
  if (fr < 0) {
   printf("Failed to create ramdisk file\n");
   return 1;
  }
  buf = malloc(hdr.ramdisk_size);
  if (buf == 0) {
   printf("malloc failed\n");
   return 1;
  }
  n = read(f, buf, hdr.ramdisk_size);
  if (n != hdr.ramdisk_size) {
   printf ("Error in read\n");
   return 1;
  }
  write(fr, buf, hdr.ramdisk_size);
  free(buf);
  close(fr);
  printf("ramdisk.cpio.gz extracted\n");
 }
 if (hdr.second_size > 0) {
  int second_offset;
  second_offset =
      (((hdr.kernel_size + hdr.ramdisk_size + flash_page_size -
         1) / flash_page_size) + 1) * flash_page_size;
  printf("Second binary at offset %d (0x%x)\n", second_offset,
         second_offset);
  lseek(f, second_offset, 0);
  fr = open("second.dtb", 01 | 0100 | 01000, 0644);
  if (fr < 0) {
   printf("Failed to create second (dtb) file\n");
   return 1;
  }
  buf = malloc(hdr.second_size);
  if (buf == 0) {
   printf("malloc failed\n");
   return 1;
  }
  n = read(f, buf, hdr.second_size);
  if (n != hdr.second_size) {
   printf ("Error in read\n");
   return 1;
  }
  write(fr, buf, hdr.second_size);
  free(buf);
  close(fr);
  printf("second.dtb extracted\n");
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int opt;
 int info_only = 0;
 int f;
 int fk;
 int fr;
 int n;
 char *buf;
 unsigned int flash_page_size;
 struct boot_img_hdr hdr;
 if (argc == 1)
  usage(argv[0]);
 while ((opt = getopt(argc, argv, "hi")) != -1) {
  switch (opt) {
  case 'i':
   info_only = 1;
   break;
  case 'h':
   usage(argv[0]);
  default:
   exit(1);
  }
 }
 printf("argc %d optind %d\n", argc, optind);
 if (optind == argc)
  usage(argv[0]);
 f = open(argv[optind], 00);
 if (f == -1) {
  printf("Failed to open %s (%s)\n", argv[optind], strerror((*__errno_location ())));
  return 1;
 }
 n = read(f, &hdr, sizeof(hdr));
 if (n < sizeof(hdr)) {
  printf("read failed\n");
  return 1;
 }
 if (strncmp((char *)hdr.magic, "ANDROID!", 8) != 0) {
  printf("Boot magic missing or corrupt: not a valid boot image\n");
  return 1;
 }
 printf("Boot header\n"
        "  flash page size\t%d\n"
        "  kernel size\t\t0x%x\n"
        "  kernel load addr\t0x%x\n"
        "  ramdisk size\t\t0x%x\n"
        "  ramdisk load addr\t0x%x\n"
        "  second size\t\t0x%x\n"
        "  second load addr\t0x%x\n"
        "  tags addr\t\t0x%x\n"
        "  product name\t\t'%s'\n"
        "  kernel cmdline\t'%s'\n\n",
        hdr.page_size,
        hdr.kernel_size, hdr.kernel_addr,
        hdr.ramdisk_size, hdr.ramdisk_addr,
        hdr.second_size, hdr.second_addr,
        hdr.tags_addr, hdr.name, hdr.cmdline);
 if (info_only)
  return 0;
 flash_page_size = hdr.page_size;
 if (hdr.kernel_size > 0) {
  lseek(f, flash_page_size, 0);
  fk = open("zImage", 01 | 0100 | 01000, 0644);
  if (fk < 0) {
   printf("Failed to create kernel file\n");
   return 1;
  }
  buf = malloc(hdr.kernel_size);
  if (buf == 0) {
   printf("malloc failed\n");
   return 1;
  }
  n = read(f, buf, hdr.kernel_size);
  if (n != hdr.kernel_size) {
   printf ("Error in read\n");
   return 1;
  }
  write(fk, buf, hdr.kernel_size);
  free(buf);
  close(fk);
  printf("zImage extracted\n");
 }
 if (hdr.ramdisk_size > 0) {
  int ramdisk_offset;
  ramdisk_offset =
      (((hdr.kernel_size + flash_page_size -
         1) / flash_page_size) + 1) * flash_page_size;
  printf("ramdisk offset %d (0x%x)\n", ramdisk_offset,
         ramdisk_offset);
  lseek(f, ramdisk_offset, 0);
  fr = open("ramdisk.cpio.gz", 01 | 0100 | 01000, 0644);
  if (fr < 0) {
   printf("Failed to create ramdisk file\n");
   return 1;
  }
  buf = malloc(hdr.ramdisk_size);
  if (buf == 0) {
   printf("malloc failed\n");
   return 1;
  }
  n = read(f, buf, hdr.ramdisk_size);
  if (n != hdr.ramdisk_size) {
   printf ("Error in read\n");
   return 1;
  }
  write(fr, buf, hdr.ramdisk_size);
  free(buf);
  close(fr);
  printf("ramdisk.cpio.gz extracted\n");
 }
 if (hdr.second_size > 0) {
  int second_offset;
  second_offset =
      (((hdr.kernel_size + hdr.ramdisk_size + flash_page_size -
         1) / flash_page_size) + 1) * flash_page_size;
  printf("Second binary at offset %d (0x%x)\n", second_offset,
         second_offset);
  lseek(f, second_offset, 0);
  fr = open("second.dtb", 01 | 0100 | 01000, 0644);
  if (fr < 0) {
   printf("Failed to create second (dtb) file\n");
   return 1;
  }
  buf = malloc(hdr.second_size);
  if (buf == 0) {
   printf("malloc failed\n");
   return 1;
  }
  n = read(f, buf, hdr.second_size);
  if (n != hdr.second_size) {
   printf ("Error in read\n");
   return 1;
  }
  write(fr, buf, hdr.second_size);
  free(buf);
  close(fr);
  printf("second.dtb extracted\n");
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opt int

variable_types: f int

variable_types: fk int

variable_types: fr int

variable_types: n int

variable_types:
buf
char *

variable_types: struct boot_img_hdr { unsigned char magic[8]; unsigned int kernel_size; unsigned int kernel_addr; unsigned int ramdisk_size; unsigned int ramdisk_addr; unsigned int second_size; unsigned int second_addr; unsigned int tags_addr; unsigned int page_size; unsigned int unused[2]; unsigned char name[16]; unsigned char cmdline[512]; unsigned int id[8]; }


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
printf(
"\n"
"Android boot image extraction tool v1.1\n"
"Copyright (C)2012,2016 Chris Simmonds\n"
"\n"
"Usage %s <-i> [boot or recovery image file]\n"
" -i information only: do not extract images\n",
a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
printf(
"\n"
"Android boot image extraction tool v1.1\n"
"Copyright (C)2012,2016 Chris Simmonds\n"
"\n"
"Usage %s <-i> [boot or recovery image file]\n"
" -i information only: do not extract images\n",
a1);
exit(1);
}

original_code:
static void usage(char *prog)
{
 printf("\nAndroid boot image extraction tool v1.1\n"
        "Copyright (C)2012,2016 Chris Simmonds\n\n"
        "Usage %s <-i> [boot or recovery image file]\n"
        "    -i   information only: do not extract images\n", prog);
 exit(1);
}

variable_types:
prog
char *

return_type: void


repo: csinitiative/fhce

decompiled_code:
void *__fastcall fh_mgr_run(void *a1)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
int v8; // [rsp+8h] [rbp-10h] BYREF
unsigned int v9[3]; // [rsp+Ch] [rbp-Ch] BYREF

v9[0] = 0;
if ( a1 )
{
v7 = fh_log_fmt("assertion '%s' failed at %s:%d", "arg == NULL", "fhmgr.c", 84LL);
fh_log("fhmgr.c", 84LL, 0LL, "ERR", v7);
exit(1);
}
fh_log_thread_start("FH_Mgr");
fh_mgmt_conn_init();
v8 = fh_adm_init();
if ( !v8 )
{
v8 = fh_tcp_server(0LL, 40000LL, v9);
if ( v8 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v2 = fh_log_fmt("failed to start the FH Manager on port:%d", 40000LL);
fh_log("fhmgr.c", 107LL, "MGMT", "ERR", v2);
}
}
else
{
v8 = fh_mgmt_conn_new(1LL, v9[0], 0LL, 40000LL);
if ( !v8 )
{
if ( mgmt_init_complete )
{
if ( (fh_log_lvl[12] & 4) != 0 )
{
v6 = fh_log_fmt("Plugin Management initialization complete");
fh_log("fhmgr.c", 126LL, "MGMT", "STATE", v6);
((void (__fastcall *)(int *))mgmt_init_complete)(&v8);
}
else
{
((void (__fastcall *)(int *))mgmt_init_complete)(&v8);
}
if ( v8 && (fh_log_lvl[12] & 2) != 0 )
{
v5 = fh_log_fmt("Plugin Management initialization complete failed");
fh_log("fhmgr.c", 129LL, "MGMT", "WARN", v5);
}
}
while ( 1 )
{
fh_mgmt_conn_loop(1000000LL);
fh_mgmt_sg_timers();
}
}
if ( (fh_log_lvl[12] & 2) != 0 )
{
v4 = fh_log_fmt("failed to create the FH Manager connection");
fh_log("fhmgr.c", 116LL, "MGMT", "WARN", v4);
}
}
return 0LL;
}
if ( (fh_log_lvl[12] & 1) == 0 )
return 0LL;
v3 = fh_log_fmt("failed to initialize admin message library");
fh_log("fhmgr.c", 98LL, "MGMT", "ERR", v3);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
int v8; // [rsp+8h] [rbp-10h] BYREF
unsigned int v9[3]; // [rsp+Ch] [rbp-Ch] BYREF

v9[0] = 0;
if ( a1 )
{
v7 = fh_log_fmt("assertion '%s' failed at %s:%d", "arg == NULL", "fhmgr.c", 84LL);
fh_log("fhmgr.c", 84LL, 0LL, "ERR", v7);
exit(1);
}
fh_log_thread_start("FH_Mgr");
fh_mgmt_conn_init();
v8 = fh_adm_init();
if ( !v8 )
{
v8 = fh_tcp_server(0LL, 40000LL, v9);
if ( v8 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v2 = fh_log_fmt("failed to start the FH Manager on port:%d", 40000LL);
fh_log("fhmgr.c", 107LL, "MGMT", "ERR", v2);
}
}
else
{
v8 = fh_mgmt_conn_new(1LL, v9[0], 0LL, 40000LL);
if ( !v8 )
{
if ( mgmt_init_complete )
{
if ( (fh_log_lvl[12] & 4) != 0 )
{
v6 = fh_log_fmt("Plugin Management initialization complete");
fh_log("fhmgr.c", 126LL, "MGMT", "STATE", v6);
((void (__fastcall *)(int *))mgmt_init_complete)(&v8);
}
else
{
((void (__fastcall *)(int *))mgmt_init_complete)(&v8);
}
if ( v8 && (fh_log_lvl[12] & 2) != 0 )
{
v5 = fh_log_fmt("Plugin Management initialization complete failed");
fh_log("fhmgr.c", 129LL, "MGMT", "WARN", v5);
}
}
while ( 1 )
{
fh_mgmt_conn_loop(1000000LL);
fh_mgmt_sg_timers();
}
}
if ( (fh_log_lvl[12] & 2) != 0 )
{
v4 = fh_log_fmt("failed to create the FH Manager connection");
fh_log("fhmgr.c", 116LL, "MGMT", "WARN", v4);
}
}
return 0LL;
}
if ( (fh_log_lvl[12] & 1) == 0 )
return 0LL;
v3 = fh_log_fmt("failed to initialize admin message library");
fh_log("fhmgr.c", 98LL, "MGMT", "ERR", v3);
return 0LL;
}

original_code:
static void *fh_mgr_run(void *arg)
{
    FH_STATUS rc;
    int srv_fd = 0;
    int ticks = 0;
    uint64_t timeout = (uint64_t)1000000;
    do { int nok = !(arg == ((void *)0)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "arg == NULL", "fhmgr.c", 84); fh_log("fhmgr.c", 84, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    fh_log_thread_start("FH_Mgr");
    fh_mgmt_conn_init();
    rc = fh_adm_init();
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to initialize admin message library"); fh_log("fhmgr.c", 98, "MGMT", "ERR", _msg); } } while (0);
        return ((void *)0);
    }
    rc = fh_tcp_server(((in_addr_t) 0x00000000), (40000), &srv_fd);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to start the FH Manager on port:%d", (40000)); fh_log("fhmgr.c", 107, "MGMT", "ERR", _msg); } } while (0);
        return ((void *)0);
    }
    rc = fh_mgmt_conn_new((1), srv_fd, ((in_addr_t) 0x00000000), (40000));
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("failed to create the FH Manager connection"); fh_log("fhmgr.c", 116, "MGMT", "WARN", _msg); } } while (0);
        return ((void *)0);
    }
    if (mgmt_init_complete) {
        do { if ((fh_log_lvl[(3)] & ((0x00000004)))) { char *_msg = fh_log_fmt ("Plugin Management initialization complete"); fh_log("fhmgr.c", 126, "MGMT", "STATE", _msg); } } while (0);
        mgmt_init_complete(&rc);
        if (rc != (0)) {
             do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("Plugin Management initialization complete failed"); fh_log("fhmgr.c", 129, "MGMT", "WARN", _msg); } } while (0);
        }
    }
    while (1) {
        ticks++;
        fh_mgmt_conn_loop(timeout);
        if ((ticks % (1)) == 0) {
            fh_mgmt_sg_timers();
        }
    }
    fh_log_thread_stop("FH_Mgr");
    return ((void *)0);
}

canonical_original_code:
static void *fh_mgr_run(void *arg)
{
    int rc;
    int srv_fd = 0;
    int ticks = 0;
    unsigned long timeout = (uint64_t)1000000;
    do { int nok = !(arg == ((void *)0)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "arg == NULL", "fhmgr.c", 84); fh_log("fhmgr.c", 84, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    fh_log_thread_start("FH_Mgr");
    fh_mgmt_conn_init();
    rc = fh_adm_init();
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to initialize admin message library"); fh_log("fhmgr.c", 98, "MGMT", "ERR", _msg); } } while (0);
        return ((void *)0);
    }
    rc = fh_tcp_server(((unsigned int) 0x00000000), (40000), &srv_fd);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to start the FH Manager on port:%d", (40000)); fh_log("fhmgr.c", 107, "MGMT", "ERR", _msg); } } while (0);
        return ((void *)0);
    }
    rc = fh_mgmt_conn_new((1), srv_fd, ((unsigned int) 0x00000000), (40000));
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("failed to create the FH Manager connection"); fh_log("fhmgr.c", 116, "MGMT", "WARN", _msg); } } while (0);
        return ((void *)0);
    }
    if (mgmt_init_complete) {
        do { if ((fh_log_lvl[(3)] & ((0x00000004)))) { char *_msg = fh_log_fmt ("Plugin Management initialization complete"); fh_log("fhmgr.c", 126, "MGMT", "STATE", _msg); } } while (0);
        mgmt_init_complete(&rc);
        if (rc != (0)) {
             do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("Plugin Management initialization complete failed"); fh_log("fhmgr.c", 129, "MGMT", "WARN", _msg); } } while (0);
        }
    }
    while (1) {
        ticks++;
        fh_mgmt_conn_loop(timeout);
        if ((ticks % (1)) == 0) {
            fh_mgmt_sg_timers();
        }
    }
    fh_log_thread_stop("FH_Mgr");
    return ((void *)0);
}

variable_types:
arg
void *

variable_types: rc int

variable_types: ticks int

variable_types:
timeout
unsigned long

variable_types: nok int

return_type: void *


decompiled_code:
void __noreturn fh_mgr_usage()
{
printf(
"Usage: %s ARGS\n\n -d Debug mode (doesn't daemonize)\n -h? Display this help message\n",
(const char *)pname);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
printf(
"Usage: %s ARGS\n\n -d Debug mode (doesn't daemonize)\n -h? Display this help message\n",
(const char *)pname);
exit(1);
}

original_code:
static void fh_mgr_usage()
{
  printf("Usage: %s ARGS\n\n"
         "   -d             Debug mode (doesn't daemonize)\n"
         "   -h?            Display this help message\n", pname);
  exit(1);
}


decompiled_code:
__int64 __fastcall fh_mgr_parse_args(int argc, char **argv)
{
int v2; // eax

while ( 1 )
{
v2 = getopt(argc, argv, "dh?");
if ( v2 == -1 )
return 0LL;
if ( v2 != 100 )
break;
debug = 1;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int argc, char **argv)
{
int v2; // eax

while ( 1 )
{
v2 = getopt(argc, argv, "dh?");
if ( v2 == -1 )
return 0LL;
if ( v2 != 100 )
break;
debug = 1;
}
return 0xFFFFFFFFLL;
}

original_code:
FH_STATUS fh_mgr_parse_args(int argc, char *argv[])
{
    extern int optind;
    extern char *optarg;
    int c;
    while ((c = getopt(argc, argv, "dh?")) != (-1)) {
        switch (c) {
        case 'd':
            debug = 1;
            break;
        case '?':
        case 'h':
        default:
            return (-1);
        }
    }
    return (0);
}

canonical_original_code:
int fh_mgr_parse_args(int argc, char *argv[])
{
    extern int optind;
    extern char *optarg;
    int c;
    while ((c = getopt(argc, argv, "dh?")) != (-1)) {
        switch (c) {
        case 'd':
            debug = 1;
            break;
        case '?':
        case 'h':
        default:
            return (-1);
        }
    }
    return (0);
}

variable_types:
argv
char *[]

variable_types: optind int

variable_types:
optarg
char *

variable_types: c int

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
char *v4; // rax
char *v5; // rdx
__int64 v6; // rbp
unsigned int v7; // eax
int v8; // er12
unsigned int v10; // eax
__int64 v11; // rax
void (__fastcall *v12)(unsigned int *); // rbx
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
unsigned int v17; // [rsp+4h] [rbp-24h] BYREF
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

v3 = *argv;
v4 = strrchr(*argv, 47);
if ( v4 )
v3 = v4 + 1;
pname = (__int64)v3;
if ( (unsigned int)fh_mgr_parse_args(argc, (char **)argv) )
fh_mgr_usage();
v5 = getenv("FH_HOME");
if ( !v5 )
v5 = "/opt/csi/fh";
fh_home = (__int64)v5;
sprintf(fhmgr_config_file, "%s/%s", v5, "mgmt/etc/fhmgr.conf");
sprintf(&fhmgr_plugins_dir, "%s/%s", (const char *)fh_home, "mgmt/plugins");
if ( fhmgr_plugins_dir )
fh_plugin_load(&fhmgr_plugins_dir);
v6 = fh_cfg_load(fhmgr_config_file);
if ( !v6 )
{
v8 = 1;
fprintf(stderr, "ERROR: Failed to load FH Manager configuration: %s", fhmgr_config_file);
return v8;
}
fh_log_open();
if ( debug )
{
fh_log_set_cfg(1LL);
fh_log_set_class(3LL, 26LL);
}
else
{
fh_daemonize();
}
fh_log_set_ident("FHMgr");
v7 = fh_log_cfg_load(v6);
v17 = v7;
if ( v7 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v8 = 1;
v14 = fh_log_fmt("failed to load logging configuration from file: %d", v7);
fh_log("fhmgr.c", 257LL, "MGMT", "ERR", v14);
return v8;
}
}
else
{
v10 = fh_mgmt_cfg_load(v6);
v17 = v10;
if ( v10 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v11 = fh_log_fmt("failed to load FH Manager configuration from file: %d", v10);
fh_log("fhmgr.c", 266LL, "MGMT", "ERR", v11);
}
}
else
{
v12 = (void (__fastcall *)(unsigned int *))fh_plugin_get_hook(16LL);
if ( !v12 )
goto LABEL_27;
if ( (fh_log_lvl[12] & 4) != 0 )
{
v15 = fh_log_fmt("Plugin Management initialization");
fh_log("fhmgr.c", 275LL, "MGMT", "STATE", v15);
}
v12(&v17);
if ( !v17 )
{
LABEL_27:
fh_mgmt_serv_post_init();
mgmt_init_complete = fh_plugin_get_hook(20LL);
if ( mgmt_init_complete && (fh_log_lvl[12] & 4) != 0 )
{
v16 = fh_log_fmt("Plugin Management initialization complete");
fh_log("fhmgr.c", 287LL, "MGMT", "STATE", v16);
}
v8 = pthread_create(newthread, 0LL, fh_mgr_run, 0LL);
if ( !v8 )
{
pthread_join(newthread[0], 0LL);
return v8;
}
if ( (fh_log_lvl[12] & 1) != 0 )
{
v8 = 1;
v13 = fh_log_fmt("failed to start FH Manager thread");
fh_log("fhmgr.c", 294LL, "MGMT", "ERR", v13);
return v8;
}
}
}
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
char *v4; // rax
char *v5; // rdx
__int64 v6; // rbp
unsigned int v7; // eax
int v8; // er12
unsigned int v10; // eax
__int64 v11; // rax
void (__fastcall *v12)(unsigned int *); // rbx
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
unsigned int v17; // [rsp+4h] [rbp-24h] BYREF
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

v3 = *argv;
v4 = strrchr(*argv, 47);
if ( v4 )
v3 = v4 + 1;
pname = (__int64)v3;
if ( (unsigned int)func2(argc, (char **)argv) )
func1();
v5 = getenv("FH_HOME");
if ( !v5 )
v5 = "/opt/csi/fh";
fh_home = (__int64)v5;
sprintf(fhmgr_config_file, "%s/%s", v5, "mgmt/etc/fhmgr.conf");
sprintf(&fhmgr_plugins_dir, "%s/%s", (const char *)fh_home, "mgmt/plugins");
if ( fhmgr_plugins_dir )
fh_plugin_load(&fhmgr_plugins_dir);
v6 = fh_cfg_load(fhmgr_config_file);
if ( !v6 )
{
v8 = 1;
fprintf(stderr, "ERROR: Failed to load FH Manager configuration: %s", fhmgr_config_file);
return v8;
}
fh_log_open();
if ( debug )
{
fh_log_set_cfg(1LL);
fh_log_set_class(3LL, 26LL);
}
else
{
fh_daemonize();
}
fh_log_set_ident("FHMgr");
v7 = fh_log_cfg_load(v6);
v17 = v7;
if ( v7 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v8 = 1;
v14 = fh_log_fmt("failed to load logging configuration from file: %d", v7);
fh_log("fhmgr.c", 257LL, "MGMT", "ERR", v14);
return v8;
}
}
else
{
v10 = fh_mgmt_cfg_load(v6);
v17 = v10;
if ( v10 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v11 = fh_log_fmt("failed to load FH Manager configuration from file: %d", v10);
fh_log("fhmgr.c", 266LL, "MGMT", "ERR", v11);
}
}
else
{
v12 = (void (__fastcall *)(unsigned int *))fh_plugin_get_hook(16LL);
if ( !v12 )
goto LABEL_27;
if ( (fh_log_lvl[12] & 4) != 0 )
{
v15 = fh_log_fmt("Plugin Management initialization");
fh_log("fhmgr.c", 275LL, "MGMT", "STATE", v15);
}
v12(&v17);
if ( !v17 )
{
LABEL_27:
fh_mgmt_serv_post_init();
mgmt_init_complete = fh_plugin_get_hook(20LL);
if ( mgmt_init_complete && (fh_log_lvl[12] & 4) != 0 )
{
v16 = fh_log_fmt("Plugin Management initialization complete");
fh_log("fhmgr.c", 287LL, "MGMT", "STATE", v16);
}
v8 = pthread_create(newthread, 0LL, fh_mgr_run, 0LL);
if ( !v8 )
{
pthread_join(newthread[0], 0LL);
return v8;
}
if ( (fh_log_lvl[12] & 1) != 0 )
{
v8 = 1;
v13 = fh_log_fmt("failed to start FH Manager thread");
fh_log("fhmgr.c", 294LL, "MGMT", "ERR", v13);
return v8;
}
}
}
}
return 1;
}

original_code:
int main(int argc, char *argv[])
{
    fh_cfg_node_t *config = ((void *)0);
    pthread_t tid;
    FH_STATUS rc;
    fh_plugin_hook_t mgmt_init = ((void *)0);
    do { char *ptr = strrchr(argv[0], '/'); pname = ptr ? ptr + 1 : argv[0]; } while (0);
    rc = fh_mgr_parse_args(argc, argv);
    if (rc != (0)) {
        fh_mgr_usage();
    }
    if ((fh_home = getenv("FH_HOME")) == ((void *)0)) {
        fh_home = "/opt/csi/fh";
    }
    sprintf(fhmgr_config_file, "%s/%s", fh_home, "mgmt/etc/fhmgr.conf");
    sprintf(fhmgr_plugins_dir, "%s/%s", fh_home, "mgmt/plugins");
    if (fhmgr_plugins_dir[0] != '\0') {
        fh_plugin_load(fhmgr_plugins_dir);
    }
    config = fh_cfg_load(fhmgr_config_file);
    if (!config) {
        fprintf(stderr, "ERROR: Failed to load FH Manager configuration: %s", fhmgr_config_file);
        return 1;
    }
    fh_log_open();
    if (debug) {
        fh_log_set_cfg((0x00000001));
        fh_log_set_class((3), (0x00000008)|(0x00000002)|(0x00000010));
    }
    else {
        fh_daemonize();
    }
    fh_log_set_ident("FHMgr");
    rc = fh_log_cfg_load(config);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to load logging configuration from file: %d", rc); fh_log("fhmgr.c", 257, "MGMT", "ERR", _msg); } } while (0);
        return 1;
    }
    rc = fh_mgmt_cfg_load(config);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to load FH Manager configuration from file: %d", rc); fh_log("fhmgr.c", 266, "MGMT", "ERR", _msg); } } while (0);
        return 1;
    }
    mgmt_init = fh_plugin_get_hook((16));
    if (mgmt_init) {
        do { if ((fh_log_lvl[(3)] & ((0x00000004)))) { char *_msg = fh_log_fmt ("Plugin Management initialization"); fh_log("fhmgr.c", 275, "MGMT", "STATE", _msg); } } while (0);
        mgmt_init(&rc);
        if (rc != (0)) {
            return 1;
        }
    }
    fh_mgmt_serv_post_init();
    mgmt_init_complete = fh_plugin_get_hook((20));
    if (mgmt_init_complete) {
        do { if ((fh_log_lvl[(3)] & ((0x00000004)))) { char *_msg = fh_log_fmt ("Plugin Management initialization complete"); fh_log("fhmgr.c", 287, "MGMT", "STATE", _msg); } } while (0);
    }
    if (pthread_create(&tid, ((void *)0), &fh_mgr_run, ((void *)0)) != 0) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to start FH Manager thread"); fh_log("fhmgr.c", 294, "MGMT", "ERR", _msg); } } while (0);
        return 1;
    }
    pthread_join(tid, ((void *)0));
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct fh_cfg_node *config = ((void *)0);
    unsigned long tid;
    int rc;
    void (*mgmt_init)(int *, ...) = ((void *)0);
    do { char *ptr = strrchr(argv[0], '/'); pname = ptr ? ptr + 1 : argv[0]; } while (0);
    rc = fh_mgr_parse_args(argc, argv);
    if (rc != (0)) {
        fh_mgr_usage();
    }
    if ((fh_home = getenv("FH_HOME")) == ((void *)0)) {
        fh_home = "/opt/csi/fh";
    }
    sprintf(fhmgr_config_file, "%s/%s", fh_home, "mgmt/etc/fhmgr.conf");
    sprintf(fhmgr_plugins_dir, "%s/%s", fh_home, "mgmt/plugins");
    if (fhmgr_plugins_dir[0] != '\0') {
        fh_plugin_load(fhmgr_plugins_dir);
    }
    config = fh_cfg_load(fhmgr_config_file);
    if (!config) {
        fprintf(stderr, "ERROR: Failed to load FH Manager configuration: %s", fhmgr_config_file);
        return 1;
    }
    fh_log_open();
    if (debug) {
        fh_log_set_cfg((0x00000001));
        fh_log_set_class((3), (0x00000008)|(0x00000002)|(0x00000010));
    }
    else {
        fh_daemonize();
    }
    fh_log_set_ident("FHMgr");
    rc = fh_log_cfg_load(config);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to load logging configuration from file: %d", rc); fh_log("fhmgr.c", 257, "MGMT", "ERR", _msg); } } while (0);
        return 1;
    }
    rc = fh_mgmt_cfg_load(config);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to load FH Manager configuration from file: %d", rc); fh_log("fhmgr.c", 266, "MGMT", "ERR", _msg); } } while (0);
        return 1;
    }
    mgmt_init = fh_plugin_get_hook((16));
    if (mgmt_init) {
        do { if ((fh_log_lvl[(3)] & ((0x00000004)))) { char *_msg = fh_log_fmt ("Plugin Management initialization"); fh_log("fhmgr.c", 275, "MGMT", "STATE", _msg); } } while (0);
        mgmt_init(&rc);
        if (rc != (0)) {
            return 1;
        }
    }
    fh_mgmt_serv_post_init();
    mgmt_init_complete = fh_plugin_get_hook((20));
    if (mgmt_init_complete) {
        do { if ((fh_log_lvl[(3)] & ((0x00000004)))) { char *_msg = fh_log_fmt ("Plugin Management initialization complete"); fh_log("fhmgr.c", 287, "MGMT", "STATE", _msg); } } while (0);
    }
    if (pthread_create(&tid, ((void *)0), &fh_mgr_run, ((void *)0)) != 0) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to start FH Manager thread"); fh_log("fhmgr.c", 294, "MGMT", "ERR", _msg); } } while (0);
        return 1;
    }
    pthread_join(tid, ((void *)0));
    return 0;
}

variable_types: argc int

variable_types: struct fh_cfg_node { char name[255]; struct fh_cfg_node **children; struct fh_cfg_node *parent; char **values; int num_children; int num_values; } *

variable_types:
tid
unsigned long

variable_types:
ptr
char *


decompiled_code:
void __fastcall fh_hist_free(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 4);
if ( v2 )
free(v2);
if ( *(_QWORD *)ptr )
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 4);
if ( v2 )
free(v2);
if ( *(_QWORD *)ptr )
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void fh_hist_free(fh_hist_t *hg)
{
    if (hg) {
        if (hg->hg_bins) {
            free(hg->hg_bins);
        }
        if (hg->hg_key) {
            free(hg->hg_key);
        }
        free(hg);
    }
}

canonical_original_code:
void fh_hist_free(struct fh_hist_t *hg)
{
    if (hg) {
        if (hg->hg_bins) {
            free(hg->hg_bins);
        }
        if (hg->hg_key) {
            free(hg->hg_key);
        }
        free(hg);
    }
}

variable_types: struct fh_hist_t { char *hg_key; unsigned long hg_start; unsigned long hg_stop; int hg_bincnt; int hg_binsize; unsigned long *hg_bins; unsigned long hg_total; long hg_min; long hg_max; long hg_sum; float hg_avg; } *


original_code:
void fh_hist_add(fh_hist_t *hg, int64_t val)
{
    int64_t bin;
    do { int nok = !(hg); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "hg", "fh_hist.c", 93); fh_log("fh_hist.c", 93, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    if (val >= 0) {
        if (val < hg->hg_min) {
            hg->hg_min = val;
        }
        if (val > hg->hg_max) {
            hg->hg_max = val;
        }
        bin = val / hg->hg_binsize;
        if (bin > hg->hg_bincnt) {
            bin = hg->hg_bincnt;
        }
        hg->hg_bins[bin]++;
        hg->hg_sum += val;
        hg->hg_total++;
    }
}

canonical_original_code:
void fh_hist_add(struct fh_hist_t *hg, long val)
{
    long bin;
    do { int nok = !(hg); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "hg", "fh_hist.c", 93); fh_log("fh_hist.c", 93, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    if (val >= 0) {
        if (val < hg->hg_min) {
            hg->hg_min = val;
        }
        if (val > hg->hg_max) {
            hg->hg_max = val;
        }
        bin = val / hg->hg_binsize;
        if (bin > hg->hg_bincnt) {
            bin = hg->hg_bincnt;
        }
        hg->hg_bins[bin]++;
        hg->hg_sum += val;
        hg->hg_total++;
    }
}

variable_types: val long

variable_types: bin long

user_defined_types: struct fh_hist_t { char *hg_key; unsigned long hg_start; unsigned long hg_stop; int hg_bincnt; int hg_binsize; unsigned long *hg_bins; unsigned long hg_total; long hg_min; long hg_max; long hg_sum; float hg_avg; }


original_code:
void fh_hist_reset(fh_hist_t *hg)
{
    do { int nok = !(hg); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "hg", "fh_hist.c", 124); fh_log("fh_hist.c", 124, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    hg->hg_total = 0;
    hg->hg_sum = 0;
    hg->hg_min = hg->hg_binsize * hg->hg_bincnt;
    hg->hg_max = 0;
    memset(hg->hg_bins, 0, (hg->hg_bincnt+1) * sizeof(int64_t));
}

canonical_original_code:
void fh_hist_reset(struct fh_hist_t *hg)
{
    do { int nok = !(hg); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "hg", "fh_hist.c", 124); fh_log("fh_hist.c", 124, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    hg->hg_total = 0;
    hg->hg_sum = 0;
    hg->hg_min = hg->hg_binsize * hg->hg_bincnt;
    hg->hg_max = 0;
    memset(hg->hg_bins, 0, (hg->hg_bincnt+1) * sizeof(long));
}


decompiled_code:
__int64 __fastcall fh_hist_start(__int64 a1)
{
__int64 v2; // rax

if ( !a1 )
{
v2 = fh_log_fmt("assertion '%s' failed at %s:%d", "hg", "fh_hist.c", 141LL);
fh_log("fh_hist.c", 141LL, 0LL, "ERR", v2);
exit(1);
}
return fh_time_get(a1 + 8);
}

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

if ( !a1 )
{
v2 = fh_log_fmt("assertion '%s' failed at %s:%d", "hg", "fh_hist.c", 141LL);
fh_log("fh_hist.c", 141LL, 0LL, "ERR", v2);
exit(1);
}
return fh_time_get(a1 + 8);
}

original_code:
void fh_hist_start(fh_hist_t *hg)
{
    do { int nok = !(hg); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "hg", "fh_hist.c", 141); fh_log("fh_hist.c", 141, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    fh_time_get(&hg->hg_start);
}

canonical_original_code:
void fh_hist_start(struct fh_hist_t *hg)
{
    do { int nok = !(hg); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "hg", "fh_hist.c", 141); fh_log("fh_hist.c", 141, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    fh_time_get(&hg->hg_start);
}


decompiled_code:
__int64 __fastcall fh_hist_stop(__int64 a1)
{
__int64 v2; // rax

if ( !a1 )
{
v2 = fh_log_fmt("assertion '%s' failed at %s:%d", "hg", "fh_hist.c", 153LL);
fh_log("fh_hist.c", 153LL, 0LL, "ERR", v2);
exit(1);
}
return fh_time_get(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v2; // rax

if ( !a1 )
{
v2 = fh_log_fmt("assertion '%s' failed at %s:%d", "hg", "fh_hist.c", 153LL);
fh_log("fh_hist.c", 153LL, 0LL, "ERR", v2);
exit(1);
}
return fh_time_get(a1 + 16);
}

original_code:
void fh_hist_stop(fh_hist_t *hg)
{
    do { int nok = !(hg); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "hg", "fh_hist.c", 153); fh_log("fh_hist.c", 153, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    fh_time_get(&hg->hg_stop);
}

canonical_original_code:
void fh_hist_stop(struct fh_hist_t *hg)
{
    do { int nok = !(hg); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "hg", "fh_hist.c", 153); fh_log("fh_hist.c", 153, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    fh_time_get(&hg->hg_stop);
}


original_code:
void fh_hist_copy(fh_hist_t *hg_from, fh_hist_t *hg_to)
{
    do { int nok = !(hg_from && hg_to); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "hg_from && hg_to", "fh_hist.c", 167); fh_log("fh_hist.c", 167, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    do { int nok = !(hg_from->hg_bincnt == hg_to->hg_bincnt); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "hg_from->hg_bincnt == hg_to->hg_bincnt", "fh_hist.c", 168); fh_log("fh_hist.c", 168, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    hg_to->hg_total = hg_from->hg_total;
    hg_to->hg_sum = hg_from->hg_sum;
    hg_to->hg_min = hg_from->hg_min;
    hg_to->hg_max = hg_from->hg_max;
    hg_to->hg_start = hg_from->hg_start;
    hg_to->hg_stop = hg_from->hg_stop;
    memcpy(hg_to->hg_bins, hg_from->hg_bins, (hg_from->hg_bincnt+1) * sizeof(int64_t));
}

canonical_original_code:
void fh_hist_copy(struct fh_hist_t *hg_from, struct fh_hist_t *hg_to)
{
    do { int nok = !(hg_from && hg_to); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "hg_from && hg_to", "fh_hist.c", 167); fh_log("fh_hist.c", 167, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    do { int nok = !(hg_from->hg_bincnt == hg_to->hg_bincnt); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "hg_from->hg_bincnt == hg_to->hg_bincnt", "fh_hist.c", 168); fh_log("fh_hist.c", 168, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    hg_to->hg_total = hg_from->hg_total;
    hg_to->hg_sum = hg_from->hg_sum;
    hg_to->hg_min = hg_from->hg_min;
    hg_to->hg_max = hg_from->hg_max;
    hg_to->hg_start = hg_from->hg_start;
    hg_to->hg_stop = hg_from->hg_stop;
    memcpy(hg_to->hg_bins, hg_from->hg_bins, (hg_from->hg_bincnt+1) * sizeof(long));
}


original_code:
void fh_hist_print(fh_hist_t *hg)
{
    int64_t total = 0;
    int i;
    do { int nok = !(hg); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "hg", "fh_hist.c", 194); fh_log("fh_hist.c", 194, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    if (hg->hg_total == 0) {
        return;
    }
    do { char *_msg = fh_log_fmt ("------------------------------------------------------"); fh_log("fh_hist.c", 200, ((void *)0), "STATS", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("Histogram for '%s':", hg->hg_key); fh_log("fh_hist.c", 201, ((void *)0), "STATS", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("------------------------------------------------------"); fh_log("fh_hist.c", 202, ((void *)0), "STATS", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("        Buckets         Counts   Dist(%%) Perc'ile(th)"); fh_log("fh_hist.c", 203, ((void *)0), "STATS", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("------------------------------------------------------"); fh_log("fh_hist.c", 204, ((void *)0), "STATS", _msg); } while (0);
    for (i=0; i<hg->hg_bincnt; i++) {
        total += hg->hg_bins[i];
        if ((((i+1) * hg->hg_binsize) >= hg->hg_min) &&
            ((i * hg->hg_binsize) <= hg->hg_max)) {
            do { char *_msg = fh_log_fmt (" > [ %5d - %5d ]: %8lld   %6.2f     %3d", i * hg->hg_binsize, ((i+1) * hg->hg_binsize) - 1, ((long long int)(hg->hg_bins[i])), ((float) 100*(float)(hg)->hg_bins[i]/(hg)->hg_total), (int) 100 * total / hg->hg_total); fh_log("fh_hist.c", 213, ((void *)0), "STATS", _msg); } while (0);
        }
    }
    total += hg->hg_bins[i];
    if ((i * hg->hg_binsize) <= hg->hg_max) {
        do { char *_msg = fh_log_fmt (" > [ %5d - ..... ]: %8lld   %6.2f     %3d", i * hg->hg_binsize, ((long long int)(hg->hg_bins[i])), ((float) 100*(float)(hg)->hg_bins[i]/(hg)->hg_total), (int) 100 * total / hg->hg_total); fh_log("fh_hist.c", 222, ((void *)0), "STATS", _msg); } while (0);
    }
    hg->hg_avg = (float) hg->hg_sum / hg->hg_total;
    do { char *_msg = fh_log_fmt (" > Total:             %8lld", ((long long int)(total))); fh_log("fh_hist.c", 230, ((void *)0), "STATS", _msg); } while (0);
    do { char *_msg = fh_log_fmt (" > min %lld max %lld avg %.2f", ((long long int)(hg->hg_min)), ((long long int)(hg->hg_max)), hg->hg_avg); fh_log("fh_hist.c", 231, ((void *)0), "STATS", _msg); } while (0);
    if (hg->hg_start && hg->hg_stop) {
        uint64_t elapsed;
        float rate;
        elapsed = hg->hg_stop - hg->hg_start;
        rate = (float) hg->hg_total/elapsed * 1000000;
        do { char *_msg = fh_log_fmt (" > total processed %lld (rate %.2f /sec)", ((long long int)(hg->hg_total)), rate); fh_log("fh_hist.c", 241, ((void *)0), "STATS", _msg); } while (0);
        do { char *_msg = fh_log_fmt (" > elapsed processing time %d.%d", (uint32_t) (elapsed/1000000), (uint32_t) (elapsed%1000000)); fh_log("fh_hist.c", 242, ((void *)0), "STATS", _msg); } while (0);
    }
}

canonical_original_code:
void fh_hist_print(struct fh_hist_t *hg)
{
    long total = 0;
    int i;
    do { int nok = !(hg); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "hg", "fh_hist.c", 194); fh_log("fh_hist.c", 194, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    if (hg->hg_total == 0) {
        return;
    }
    do { char *_msg = fh_log_fmt ("------------------------------------------------------"); fh_log("fh_hist.c", 200, ((void *)0), "STATS", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("Histogram for '%s':", hg->hg_key); fh_log("fh_hist.c", 201, ((void *)0), "STATS", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("------------------------------------------------------"); fh_log("fh_hist.c", 202, ((void *)0), "STATS", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("        Buckets         Counts   Dist(%%) Perc'ile(th)"); fh_log("fh_hist.c", 203, ((void *)0), "STATS", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("------------------------------------------------------"); fh_log("fh_hist.c", 204, ((void *)0), "STATS", _msg); } while (0);
    for (i=0; i<hg->hg_bincnt; i++) {
        total += hg->hg_bins[i];
        if ((((i+1) * hg->hg_binsize) >= hg->hg_min) &&
            ((i * hg->hg_binsize) <= hg->hg_max)) {
            do { char *_msg = fh_log_fmt (" > [ %5d - %5d ]: %8lld   %6.2f     %3d", i * hg->hg_binsize, ((i+1) * hg->hg_binsize) - 1, ((long long int)(hg->hg_bins[i])), ((float) 100*(float)(hg)->hg_bins[i]/(hg)->hg_total), (int) 100 * total / hg->hg_total); fh_log("fh_hist.c", 213, ((void *)0), "STATS", _msg); } while (0);
        }
    }
    total += hg->hg_bins[i];
    if ((i * hg->hg_binsize) <= hg->hg_max) {
        do { char *_msg = fh_log_fmt (" > [ %5d - ..... ]: %8lld   %6.2f     %3d", i * hg->hg_binsize, ((long long int)(hg->hg_bins[i])), ((float) 100*(float)(hg)->hg_bins[i]/(hg)->hg_total), (int) 100 * total / hg->hg_total); fh_log("fh_hist.c", 222, ((void *)0), "STATS", _msg); } while (0);
    }
    hg->hg_avg = (float) hg->hg_sum / hg->hg_total;
    do { char *_msg = fh_log_fmt (" > Total:             %8lld", ((long long int)(total))); fh_log("fh_hist.c", 230, ((void *)0), "STATS", _msg); } while (0);
    do { char *_msg = fh_log_fmt (" > min %lld max %lld avg %.2f", ((long long int)(hg->hg_min)), ((long long int)(hg->hg_max)), hg->hg_avg); fh_log("fh_hist.c", 231, ((void *)0), "STATS", _msg); } while (0);
    if (hg->hg_start && hg->hg_stop) {
        unsigned long elapsed;
        float rate;
        elapsed = hg->hg_stop - hg->hg_start;
        rate = (float) hg->hg_total/elapsed * 1000000;
        do { char *_msg = fh_log_fmt (" > total processed %lld (rate %.2f /sec)", ((long long int)(hg->hg_total)), rate); fh_log("fh_hist.c", 241, ((void *)0), "STATS", _msg); } while (0);
        do { char *_msg = fh_log_fmt (" > elapsed processing time %d.%d", (uint32_t) (elapsed/1000000), (uint32_t) (elapsed%1000000)); fh_log("fh_hist.c", 242, ((void *)0), "STATS", _msg); } while (0);
    }
}

variable_types: total long

variable_types: i int

variable_types:
elapsed
unsigned long

variable_types: rate float


decompiled_code:
char *__fastcall fh_net_ntoa(unsigned int a1)
{
int v1; // edx
char *v2; // r12

v1 = buf_index_3++;
v2 = (char *)&b_2 + 18 * (v1 % 10);
sprintf(v2, "%d.%d.%d.%d", (unsigned __int8)a1, BYTE1(a1), a1 << 8 >> 24, HIBYTE(a1));
return v2;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned int a1)
{
int v1; // edx
char *v2; // r12

v1 = buf_index_3++;
v2 = (char *)&b_2 + 18 * (v1 % 10);
sprintf(v2, "%d.%d.%d.%d", (unsigned __int8)a1, BYTE1(a1), a1 << 8 >> 24, HIBYTE(a1));
return v2;
}

original_code:
char *fh_net_ntoa(uint32_t ipaddr)
{
    static char b[18 * 10];
    static int buf_index = 0;
    register char *src, *dst;
    register int i = buf_index++ % 10;
    src = (char *) &ipaddr;
    dst = (char *) b + i * 18;
    sprintf(dst, "%d.%d.%d.%d",
        (((int)src[0])&0xff), (((int)src[1])&0xff), (((int)src[2])&0xff), (((int)src[3])&0xff));
    return dst;
}

canonical_original_code:
char *fh_net_ntoa(unsigned int ipaddr)
{
    static char b[-1];
    static int buf_index = 0;
    register char *src; register char *dst;
    register int i = buf_index++ % 10;
    src = (char *) &ipaddr;
    dst = (char *) b + i * 18;
    sprintf(dst, "%d.%d.%d.%d",
        (((int)src[0])&0xff), (((int)src[1])&0xff), (((int)src[2])&0xff), (((int)src[3])&0xff));
    return dst;
}

variable_types:
ipaddr
unsigned int

variable_types:
b
char [-1]

variable_types:
src
char *

variable_types:
dst
char *

return_type: char *


original_code:
char *fh_net_hwtoa(uint8_t *hwaddr)
{
    static char b[32 * 10];
    static int buf_index = 0;
    register char *src, *dst;
    register int i = buf_index++ % 10;
    src = (char *) hwaddr;
    dst = (char *) b + i * 32;
    sprintf(dst, "%02X:%02X:%02X:%02X:%02X:%02X",
        (((int)src[0])&0xff), (((int)src[1])&0xff), (((int)src[2])&0xff), (((int)src[3])&0xff), (((int)src[4])&0xff), (((int)src[5])&0xff));
    return dst;
}

canonical_original_code:
char *fh_net_hwtoa(unsigned char *hwaddr)
{
    static char b[-1];
    static int buf_index = 0;
    register char *src; register char *dst;
    register int i = buf_index++ % 10;
    src = (char *) hwaddr;
    dst = (char *) b + i * 32;
    sprintf(dst, "%02X:%02X:%02X:%02X:%02X:%02X",
        (((int)src[0])&0xff), (((int)src[1])&0xff), (((int)src[2])&0xff), (((int)src[3])&0xff), (((int)src[4])&0xff), (((int)src[5])&0xff));
    return dst;
}

variable_types:
hwaddr
unsigned char *


decompiled_code:
__int64 __fastcall fh_net_ifaddr(int fd, const char *a2)
{
char *v2; // rax
int v3; // er8
__int64 result; // rax
int *v5; // rax
__int64 v6; // rax
char v7; // [rsp-10h] [rbp-38h] BYREF
__int128 v8; // [rsp+0h] [rbp-28h]
__int64 v9; // [rsp+10h] [rbp-18h]

v8 = 0LL;
v9 = 0LL;
v2 = strncpy(&v7, a2, 0x10uLL);
v3 = ioctl(fd, 0x8915uLL, v2);
result = DWORD1(v8);
if ( v3 < 0 )
{
result = fh_log_lvl[1] & 1;
if ( (fh_log_lvl[1] & 1) != 0 )
{
v5 = _errno_location();
v6 = fh_log_fmt("NET> ioctl SIOCGIFADDR failed: %d", (unsigned int)*v5);
fh_log("fh_net.c", 93LL, "NET", "ERR", v6);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, const char *a2)
{
char *v2; // rax
int v3; // er8
__int64 result; // rax
int *v5; // rax
__int64 v6; // rax
char v7; // [rsp-10h] [rbp-38h] BYREF
__int128 v8; // [rsp+0h] [rbp-28h]
__int64 v9; // [rsp+10h] [rbp-18h]

v8 = 0LL;
v9 = 0LL;
v2 = strncpy(&v7, a2, 0x10uLL);
v3 = ioctl(fd, 0x8915uLL, v2);
result = DWORD1(v8);
if ( v3 < 0 )
{
result = fh_log_lvl[1] & 1;
if ( (fh_log_lvl[1] & 1) != 0 )
{
v5 = _errno_location();
v6 = fh_log_fmt("NET> ioctl SIOCGIFADDR failed: %d", (unsigned int)*v5);
fh_log("fh_net.c", 93LL, "NET", "ERR", v6);
result = 0LL;
}
}
return result;
}

original_code:
uint32_t fh_net_ifaddr(int s, char *ifname)
{
    struct ifreq ifr;
    memset(&ifr, 0, sizeof(ifr));
    strncpy(ifr.ifr_ifrn.ifrn_name, ifname, sizeof(ifr.ifr_ifrn.ifrn_name));
    if (ioctl(s, 0x8915, (caddr_t)&ifr) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> ioctl SIOCGIFADDR failed: %d", (*__errno_location ())); fh_log("fh_net.c", 93, "NET", "ERR", _msg); } } while (0);
        return 0;
    }
    return ((struct sockaddr_in *) &ifr.ifr_ifru.ifru_addr)->sin_addr.s_addr;
}

canonical_original_code:
unsigned int fh_net_ifaddr(int s, char *ifname)
{
    struct ifreq ifr;
    memset(&ifr, 0, sizeof(ifr));
    strncpy(ifr.ifr_ifrn.ifrn_name, ifname, sizeof(ifr.ifr_ifrn.ifrn_name));
    if (ioctl(s, 0x8915, (caddr_t)&ifr) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> ioctl SIOCGIFADDR failed: %d", (*__errno_location ())); fh_log("fh_net.c", 93, "NET", "ERR", _msg); } } while (0);
        return 0;
    }
    return ((struct sockaddr_in *) &ifr.ifr_ifru.ifru_addr)->sin_addr.s_addr;
}

variable_types: s int

variable_types:
ifname
char *

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

return_type: unsigned int

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

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


decompiled_code:
int fh_daemonize()
{
__pid_t v0; // eax
int v1; // ebx
int v3; // eax
int v4; // eax

signal(17, handler);
v0 = fork();
if ( v0 < 0 )
exit(1);
if ( v0 )
exit(0);
setsid();
v1 = getdtablesize();
if ( v1 >= 0 )
{
do
close(v1);
while ( v1-- != 0 );
}
v3 = open("/dev/null", 2);
v4 = dup(v3);
return dup(v4);
}

canonical_decompiled_code:
int func0()
{
__pid_t v0; // eax
int v1; // ebx
int v3; // eax
int v4; // eax

signal(17, handler);
v0 = fork();
if ( v0 < 0 )
exit(1);
if ( v0 )
exit(0);
setsid();
v1 = getdtablesize();
if ( v1 >= 0 )
{
do
close(v1);
while ( v1-- != 0 );
}
v3 = open("/dev/null", 2);
v4 = dup(v3);
return dup(v4);
}

original_code:
void fh_daemonize()
{
    int pid;
    int i;
    signal(17, ((__sighandler_t) 1));
    pid = fork();
    if (pid < 0) exit(1);
    if (pid > 0) exit(0);
    setsid();
    for (i = getdtablesize(); i >= 0; --i) close(i);
    i = open("/dev/null", 02);
    i = dup(i);
    i = dup(i);
}

canonical_original_code:
void fh_daemonize()
{
    int pid;
    int i;
    signal(17, ((void (*)(int)) 1));
    pid = fork();
    if (pid < 0) exit(1);
    if (pid > 0) exit(0);
    setsid();
    for (i = getdtablesize(); i >= 0; --i) close(i);
    i = open("/dev/null", 02);
    i = dup(i);
    i = dup(i);
}

variable_types: pid int


decompiled_code:
__int64 __fastcall fh_strsplit_sep(char *a1, const char *a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 v4; // r14
char *v7; // rax
char *save_ptr; // [rsp+8h] [rbp-30h] BYREF

v4 = 0LL;
save_ptr = 0LL;
do
{
v7 = strtok_r(a1, a2, &save_ptr);
*(_QWORD *)(a3 + 8 * v4) = v7;
if ( !v7 )
break;
++v4;
a1 = 0LL;
}
while ( v4 < a4 );
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, const char *a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 v4; // r14
char *v7; // rax
char *save_ptr; // [rsp+8h] [rbp-30h] BYREF

v4 = 0LL;
save_ptr = 0LL;
do
{
v7 = strtok_r(a1, a2, &save_ptr);
*(_QWORD *)(a3 + 8 * v4) = v7;
if ( !v7 )
break;
++v4;
a1 = 0LL;
}
while ( v4 < a4 );
return (unsigned int)v4;
}

original_code:
int fh_strsplit_sep(char *string, char *sep, char **fields, size_t size)
{
    size_t i;
    char *ptr;
    char *saveptr;
    i = 0;
    ptr = string;
    saveptr = ((void *)0);
    while ((fields[i] = strtok_r(ptr, sep, &saveptr)) != ((void *)0)) {
        ptr = ((void *)0);
        i++;
        if (i >= size) {
            break;
        }
    }
    return (i);
}

canonical_original_code:
int fh_strsplit_sep(char *string, char *sep, char **fields, unsigned long size)
{
    unsigned long i;
    char *ptr;
    char *saveptr;
    i = 0;
    ptr = string;
    saveptr = ((void *)0);
    while ((fields[i] = strtok_r(ptr, sep, &saveptr)) != ((void *)0)) {
        ptr = ((void *)0);
        i++;
        if (i >= size) {
            break;
        }
    }
    return (i);
}

variable_types:
string
char *

variable_types:
sep
char *

variable_types:
fields
char **

variable_types:
size
unsigned long

variable_types:
i
unsigned long

variable_types:
ptr
char *

variable_types:
saveptr
char *


decompiled_code:
__int64 __fastcall fh_strsplit(char *a1, __int64 a2, unsigned __int64 a3)
{
return fh_strsplit_sep(a1, " \t", a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, __int64 a2, unsigned __int64 a3)
{
return func1(a1, " \t", a2, a3);
}

original_code:
int fh_strsplit(char *string, char **fields, size_t size)
{
    return fh_strsplit_sep(string, " \t", fields, size);
}

canonical_original_code:
int fh_strsplit(char *string, char **fields, unsigned long size)
{
    return fh_strsplit_sep(string, " \t", fields, size);
}


decompiled_code:
char *__fastcall fh_str_downcase(char *a1)
{
__int64 v1; // rbx
const __int32_t **v2; // rcx
char *v3; // rax

v1 = *a1;
if ( (_BYTE)v1 )
{
v2 = _ctype_tolower_loc();
v3 = a1;
do
{
*v3++ = (*v2)[v1];
v1 = *v3;
}
while ( (_BYTE)v1 );
}
return a1;
}

canonical_decompiled_code:
char *__fastcall func3(char *a1)
{
__int64 v1; // rbx
const __int32_t **v2; // rcx
char *v3; // rax

v1 = *a1;
if ( (_BYTE)v1 )
{
v2 = _ctype_tolower_loc();
v3 = a1;
do
{
*v3++ = (*v2)[v1];
v1 = *v3;
}
while ( (_BYTE)v1 );
}
return a1;
}

original_code:
char *fh_str_downcase(char *str)
{
    int i;
    for (i = 0; str[i] != '\0'; i++) {
        str[i] = (__extension__ ({ int __res; if (sizeof (str[i]) > 1) { if (__builtin_constant_p (str[i])) { int __c = (str[i]); __res = __c < -128 || __c > 255 ? __c : (*__ctype_tolower_loc ())[__c]; } else __res = tolower (str[i]); } else __res = (*__ctype_tolower_loc ())[(int) (str[i])]; __res; }));
    }
    return str;
}

variable_types:
str
char *

variable_types: i int


decompiled_code:
char *__fastcall fh_util_thread_name(char *s, char *a2)
{
int v2; // er12
int v3; // eax
char *v4; // rax
char *v5; // r12
__int64 v7; // rax

v2 = strlen(a2);
v3 = strlen(s);
v4 = (char *)malloc(v2 + v3 + 2);
if ( !v4 )
{
v7 = fh_log_fmt("assertion '%s' failed at %s:%d", "thread_name != NULL", "fh_util.c", 144LL);
fh_log("fh_util.c", 144LL, 0LL, "ERR", v7);
exit(1);
}
v5 = v4;
sprintf(v4, "%s_%s", s, a2);
return v5;
}

canonical_decompiled_code:
char *__fastcall func4(char *s, char *a2)
{
int v2; // er12
int v3; // eax
char *v4; // rax
char *v5; // r12
__int64 v7; // rax

v2 = strlen(a2);
v3 = strlen(s);
v4 = (char *)malloc(v2 + v3 + 2);
if ( !v4 )
{
v7 = fh_log_fmt("assertion '%s' failed at %s:%d", "thread_name != NULL", "fh_util.c", 144LL);
fh_log("fh_util.c", 144LL, 0LL, "ERR", v7);
exit(1);
}
v5 = v4;
sprintf(v4, "%s_%s", s, a2);
return v5;
}

original_code:
char *fh_util_thread_name(const char *base, const char *proc)
{
    int string_chars;
    char *thread_name = ((void *)0);
    string_chars = strlen(proc) + strlen(base) + 1;
    thread_name = (char *)malloc((string_chars + 1) * sizeof(char));
    do { int nok = !(thread_name != ((void *)0)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "thread_name != NULL", "fh_util.c", 144); fh_log("fh_util.c", 144, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    sprintf(thread_name, "%s_%s", base, proc);
    return thread_name;
}

canonical_original_code:
char *fh_util_thread_name(char *base, char *proc)
{
    int string_chars;
    char *thread_name = ((void *)0);
    string_chars = strlen(proc) + strlen(base) + 1;
    thread_name = (char *)malloc((string_chars + 1) * sizeof(char));
    do { int nok = !(thread_name != ((void *)0)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "thread_name != NULL", "fh_util.c", 144); fh_log("fh_util.c", 144, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    sprintf(thread_name, "%s_%s", base, proc);
    return thread_name;
}

variable_types:
base
char *

variable_types:
proc
char *

variable_types: nok int


decompiled_code:
__int64 __fastcall ht_npower(int a1)
{
int v1; // ecx
__int64 result; // rax

v1 = 0;
while ( 1 )
{
result = (unsigned int)(1 << v1);
if ( (int)result >= a1 )
break;
if ( ++v1 == 32 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // ecx
__int64 result; // rax

v1 = 0;
while ( 1 )
{
result = (unsigned int)(1 << v1);
if ( (int)result >= a1 )
break;
if ( ++v1 == 32 )
return 0LL;
}
return result;
}

original_code:
static int ht_npower(int n)
{
    register int k = 3;
    for (k = 0; k < 32; k++) {
        int size = 1 << k;
        if (size >= n) {
            return size;
        }
    }
    return 0;
}

variable_types: n int

variable_types: k int

variable_types: size int


decompiled_code:
void __fastcall fh_ht_free(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
if ( *(_QWORD *)ptr )
fh_mpool_free();
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
if ( *(_QWORD *)ptr )
fh_mpool_free();
free(ptr);
}
}

original_code:
void fh_ht_free(fh_ht_t *ht)
{
    if (ht) {
        if (ht->ht_table) {
            free(ht->ht_table);
        }
        if (ht->ht_mpool) {
            fh_mpool_free(ht->ht_mpool);
        }
        free(ht);
    }
}

canonical_original_code:
void fh_ht_free(struct fh_ht_t *ht)
{
    if (ht) {
        if (ht->ht_table) {
            free(ht->ht_table);
        }
        if (ht->ht_mpool) {
            fh_mpool_free(ht->ht_mpool);
        }
        free(ht);
    }
}

variable_types: struct fh_ht_t { struct fh_mpool_t { char *mp_name; struct _mp_mblock { struct _mp_mblock *mb_next; } *mp_mblocks; struct _mp_mchunk { struct _mp_mchunk *mc_next; } *mp_mchunks; unsigned int mp_chunksize; unsigned int mp_nchunks; unsigned int mp_nblocks; unsigned int mp_flags; unsigned int mp_free; unsigned int mp_inuse; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mp_lock; } *ht_mpool; struct he_head_t { struct _fh_ht_elt { struct he_entry_t { struct _fh_ht_elt *tqe_next; struct _fh_ht_elt **tqe_prev; } he_next; struct he_head_t *he_chead; void *he_value; void *he_key; int he_klen; unsigned int he_hashval; } *tqh_first; struct _fh_ht_elt **tqh_last; } *ht_table; unsigned int ht_size; unsigned int ht_count; unsigned int ht_mask; unsigned int ht_flags; struct fh_ht_kops_t { unsigned int (*kops_khash)(void *key, int klen); char *(*kops_kdump)(void *key, int klen); int (*kops_kcmp)(void *key_a, void *key_b, int klen); } ht_kops; } *

user_defined_types: struct fh_ht_t { struct fh_mpool_t *ht_mpool; struct he_head_t *ht_table; unsigned int ht_size; unsigned int ht_count; unsigned int ht_mask; unsigned int ht_flags; struct fh_ht_kops_t ht_kops; }

user_defined_types: struct fh_mpool_t { char *mp_name; struct _mp_mblock *mp_mblocks; struct _mp_mchunk *mp_mchunks; unsigned int mp_chunksize; unsigned int mp_nchunks; unsigned int mp_nblocks; unsigned int mp_flags; unsigned int mp_free; unsigned int mp_inuse; union pthread_mutex_t mp_lock; }

user_defined_types: struct he_head_t { struct _fh_ht_elt *tqh_first; struct _fh_ht_elt **tqh_last; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct _fh_ht_elt { struct he_entry_t he_next; struct he_head_t *he_chead; void *he_value; void *he_key; int he_klen; unsigned int he_hashval; }


original_code:
FH_STATUS fh_ht_put(fh_ht_t *ht, void *key, int klen, void *value)
{
    register uint32_t hashval = 0;
    register int hops = 0;
    fh_ht_elt_t *he = ((void *)0);
    he_head_t *he_head;
    fh_ht_kops_t *kops;
    int index;
    fh_prof_init(&HT_PUT_prof_ctxt);
    fh_prof_beg(&HT_PUT_prof_ctxt);
    do { int nok = !(ht); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "ht", "fh_htable.c", 209); fh_log("fh_htable.c", 209, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    kops = &ht->ht_kops;
    hashval = kops->kops_khash(key, klen);
    index = ((hashval) & ht->ht_mask);
    he_head = &ht->ht_table[index];
    for ((he) = ((he_head)->tqh_first); (he); (he) = ((he)->he_next.tqe_next)) {
        if (he->he_hashval == hashval &&
            he->he_klen == klen &&
            kops->kops_kcmp(he->he_key, key, klen)) {
            do { if ((fh_log_lvl[(0)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Duplicate key '%s' hashval=%u", kops->kops_kdump(key, klen), hashval); fh_log("fh_htable.c", 230, "CSI", "DIAG", _msg); } } while (0);
            return (2);
        }
        hops++;
    }
    if (hops > 0) {
        do { if ((fh_log_lvl[(0)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Hash collisions - hops:%d key:%s", hops, kops->kops_kdump(key, klen)); fh_log("fh_htable.c", 243, "CSI", "DIAG", _msg); } } while (0);
    }
    he = (fh_ht_elt_t *)fh_mpool_get(ht->ht_mpool);
    if (!he) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Couldn't get another hash entry for key '%s'", kops->kops_kdump(key, klen)); fh_log("fh_htable.c", 252, "CSI", "ERR", _msg); } } while (0);
        return (-1);
    }
    ht->ht_count++;
    do { if ((fh_log_lvl[(0)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("Insert key '%s' hashval=%u", kops->kops_kdump(key, klen), hashval); fh_log("fh_htable.c", 259, "CSI", "INFO", _msg); } } while (0);
    if (ht->ht_flags & (0x00000001)) {
        if (5 * (uint32_t)ht->ht_count > 4 * ht->ht_size) {
            (void) ht_grow(ht);
            index = ((hashval) & ht->ht_mask);
            he_head = &ht->ht_table[index];
        }
    }
    he->he_key = key;
    he->he_klen = klen;
    he->he_hashval = hashval;
    do { if (((he)->he_next.tqe_next = (he_head)->tqh_first) != ((void *)0)) (he_head)->tqh_first->he_next.tqe_prev = &(he)->he_next.tqe_next; else (he_head)->tqh_last = &(he)->he_next.tqe_next; (he_head)->tqh_first = (he); (he)->he_next.tqe_prev = &(he_head)->tqh_first; } while ( 0);
    he->he_chead = he_head;
    he->he_value = value;
    fh_prof_end(&HT_PUT_prof_ctxt);
    fh_prof_print(&HT_PUT_prof_ctxt);
    return (0);
}

canonical_original_code:
int fh_ht_put(struct fh_ht_t *ht, void *key, int klen, void *value)
{
    register unsigned int hashval = 0;
    register int hops = 0;
    struct _fh_ht_elt *he = ((void *)0);
    struct he_head_t *he_head;
    struct fh_ht_kops_t *kops;
    int index;
    fh_prof_init(&HT_PUT_prof_ctxt);
    fh_prof_beg(&HT_PUT_prof_ctxt);
    do { int nok = !(ht); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "ht", "fh_htable.c", 209); fh_log("fh_htable.c", 209, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    kops = &ht->ht_kops;
    hashval = kops->kops_khash(key, klen);
    index = ((hashval) & ht->ht_mask);
    he_head = &ht->ht_table[index];
    for ((he) = ((he_head)->tqh_first); (he); (he) = ((he)->he_next.tqe_next)) {
        if (he->he_hashval == hashval &&
            he->he_klen == klen &&
            kops->kops_kcmp(he->he_key, key, klen)) {
            do { if ((fh_log_lvl[(0)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Duplicate key '%s' hashval=%u", kops->kops_kdump(key, klen), hashval); fh_log("fh_htable.c", 230, "CSI", "DIAG", _msg); } } while (0);
            return (2);
        }
        hops++;
    }
    if (hops > 0) {
        do { if ((fh_log_lvl[(0)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Hash collisions - hops:%d key:%s", hops, kops->kops_kdump(key, klen)); fh_log("fh_htable.c", 243, "CSI", "DIAG", _msg); } } while (0);
    }
    he = (struct _fh_ht_elt *)fh_mpool_get(ht->ht_mpool);
    if (!he) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Couldn't get another hash entry for key '%s'", kops->kops_kdump(key, klen)); fh_log("fh_htable.c", 252, "CSI", "ERR", _msg); } } while (0);
        return (-1);
    }
    ht->ht_count++;
    do { if ((fh_log_lvl[(0)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("Insert key '%s' hashval=%u", kops->kops_kdump(key, klen), hashval); fh_log("fh_htable.c", 259, "CSI", "INFO", _msg); } } while (0);
    if (ht->ht_flags & (0x00000001)) {
        if (5 * (unsigned int)ht->ht_count > 4 * ht->ht_size) {
            (void) ht_grow(ht);
            index = ((hashval) & ht->ht_mask);
            he_head = &ht->ht_table[index];
        }
    }
    he->he_key = key;
    he->he_klen = klen;
    he->he_hashval = hashval;
    do { if (((he)->he_next.tqe_next = (he_head)->tqh_first) != ((void *)0)) (he_head)->tqh_first->he_next.tqe_prev = &(he)->he_next.tqe_next; else (he_head)->tqh_last = &(he)->he_next.tqe_next; (he_head)->tqh_first = (he); (he)->he_next.tqe_prev = &(he_head)->tqh_first; } while ( 0);
    he->he_chead = he_head;
    he->he_value = value;
    fh_prof_end(&HT_PUT_prof_ctxt);
    fh_prof_print(&HT_PUT_prof_ctxt);
    return (0);
}

variable_types:
key
void *

variable_types: klen int

variable_types:
value
void *

variable_types:
hashval
unsigned int

variable_types: hops int

variable_types: struct _fh_ht_elt { struct he_entry_t { struct _fh_ht_elt *tqe_next; struct _fh_ht_elt **tqe_prev; } he_next; struct he_head_t { struct _fh_ht_elt *tqh_first; struct _fh_ht_elt **tqh_last; } *he_chead; void *he_value; void *he_key; int he_klen; unsigned int he_hashval; } *

variable_types: struct he_head_t { struct _fh_ht_elt { struct he_entry_t { struct _fh_ht_elt *tqe_next; struct _fh_ht_elt **tqe_prev; } he_next; struct he_head_t *he_chead; void *he_value; void *he_key; int he_klen; unsigned int he_hashval; } *tqh_first; struct _fh_ht_elt **tqh_last; } *

variable_types: struct fh_ht_kops_t { unsigned int (*kops_khash)(void *key, int klen); char *(*kops_kdump)(void *key, int klen); int (*kops_kcmp)(void *key_a, void *key_b, int klen); } *

variable_types: index int

user_defined_types: struct _mp_mblock { struct _mp_mblock *mb_next; }

user_defined_types: struct _mp_mchunk { struct _mp_mchunk *mc_next; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall fh_ht_get(__int64 a1, __int64 a2, unsigned int a3, _QWORD *a4)
{
__int64 *v5; // rax
__int64 v7; // rax

if ( !a1 )
{
v7 = fh_log_fmt("assertion '%s' failed at %s:%d", "ht", "fh_htable.c", 344LL);
fh_log("fh_htable.c", 344LL, 0LL, "ERR", v7);
exit(1);
}
*a4 = 0LL;
v5 = ht_lookup(a1, a2, a3);
if ( !v5 )
return 1LL;
*a4 = v5[3];
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, unsigned int a3, _QWORD *a4)
{
__int64 *v5; // rax
__int64 v7; // rax

if ( !a1 )
{
v7 = fh_log_fmt("assertion '%s' failed at %s:%d", "ht", "fh_htable.c", 344LL);
fh_log("fh_htable.c", 344LL, 0LL, "ERR", v7);
exit(1);
}
*a4 = 0LL;
v5 = ht_lookup(a1, a2, a3);
if ( !v5 )
return 1LL;
*a4 = v5[3];
return 0LL;
}

original_code:
FH_STATUS fh_ht_get(fh_ht_t *ht, void *key, int klen, void **value)
{
    fh_ht_elt_t *he;
    do { int nok = !(ht); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "ht", "fh_htable.c", 344); fh_log("fh_htable.c", 344, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    *value = ((void *)0);
    he = ht_lookup(ht, key, klen);
    if (!he) {
        return (1);
    }
    *value = he->he_value;
    return (0);
}

canonical_original_code:
int fh_ht_get(struct fh_ht_t *ht, void *key, int klen, void **value)
{
    struct _fh_ht_elt *he;
    do { int nok = !(ht); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "ht", "fh_htable.c", 344); fh_log("fh_htable.c", 344, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    *value = ((void *)0);
    he = ht_lookup(ht, key, klen);
    if (!he) {
        return (1);
    }
    *value = he->he_value;
    return (0);
}

variable_types:
value
void **

user_defined_types: struct fh_ht_kops_t { unsigned int (*kops_khash)(void *key, int klen); char *(*kops_kdump)(void *key, int klen); int (*kops_kcmp)(void *key_a, void *key_b, int klen); }

user_defined_types: struct he_entry_t { struct _fh_ht_elt *tqe_next; struct _fh_ht_elt **tqe_prev; }


original_code:
FH_STATUS fh_ht_delete(fh_ht_t *ht, void *key, int klen, void **val)
{
    fh_ht_elt_t *he;
    do { int nok = !(ht); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "ht", "fh_htable.c", 367); fh_log("fh_htable.c", 367, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    *val = ((void *)0);
    do { int nok = !(ht && ht->ht_size > 0); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "ht && ht->ht_size > 0", "fh_htable.c", 371); fh_log("fh_htable.c", 371, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    he = ht_lookup(ht, key, klen);
    if (!he) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Couldn't find key '%s'", ht->ht_kops.kops_kdump(key, klen)); fh_log("fh_htable.c", 375, "CSI", "ERR", _msg); } } while (0);
        return (1);
    }
    do { if (((he)->he_next.tqe_next) != ((void *)0)) (he)->he_next.tqe_next->he_next.tqe_prev = (he)->he_next.tqe_prev; else (he->he_chead)->tqh_last = (he)->he_next.tqe_prev; *(he)->he_next.tqe_prev = (he)->he_next.tqe_next; ; } while ( 0);
    *val = he->he_value;
    fh_mpool_put(ht->ht_mpool, he);
    do { int nok = !(ht->ht_count > 0); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "ht->ht_count > 0", "fh_htable.c", 385); fh_log("fh_htable.c", 385, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    ht->ht_count--;
    do { if ((fh_log_lvl[(0)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("Deleted key '%s' (remaining=%d)", ht->ht_kops.kops_kdump(key, klen), ht->ht_count); fh_log("fh_htable.c", 388, "CSI", "INFO", _msg); } } while (0);
    return (0);
}

canonical_original_code:
int fh_ht_delete(struct fh_ht_t *ht, void *key, int klen, void **val)
{
    struct _fh_ht_elt *he;
    do { int nok = !(ht); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "ht", "fh_htable.c", 367); fh_log("fh_htable.c", 367, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    *val = ((void *)0);
    do { int nok = !(ht && ht->ht_size > 0); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "ht && ht->ht_size > 0", "fh_htable.c", 371); fh_log("fh_htable.c", 371, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    he = ht_lookup(ht, key, klen);
    if (!he) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Couldn't find key '%s'", ht->ht_kops.kops_kdump(key, klen)); fh_log("fh_htable.c", 375, "CSI", "ERR", _msg); } } while (0);
        return (1);
    }
    do { if (((he)->he_next.tqe_next) != ((void *)0)) (he)->he_next.tqe_next->he_next.tqe_prev = (he)->he_next.tqe_prev; else (he->he_chead)->tqh_last = (he)->he_next.tqe_prev; *(he)->he_next.tqe_prev = (he)->he_next.tqe_next; ; } while ( 0);
    *val = he->he_value;
    fh_mpool_put(ht->ht_mpool, he);
    do { int nok = !(ht->ht_count > 0); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "ht->ht_count > 0", "fh_htable.c", 385); fh_log("fh_htable.c", 385, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    ht->ht_count--;
    do { if ((fh_log_lvl[(0)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("Deleted key '%s' (remaining=%d)", ht->ht_kops.kops_kdump(key, klen), ht->ht_count); fh_log("fh_htable.c", 388, "CSI", "INFO", _msg); } } while (0);
    return (0);
}

variable_types:
val
void **


decompiled_code:
__int64 __fastcall fh_ht_memuse(__int64 a1)
{
int v1; // ebx

v1 = 16 * *(_DWORD *)(a1 + 16);
return v1 + 56 + (unsigned int)fh_mpool_memuse(*(_QWORD *)a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
int v1; // ebx

v1 = 16 * *(_DWORD *)(a1 + 16);
return v1 + 56 + (unsigned int)fh_mpool_memuse(*(_QWORD *)a1);
}

original_code:
uint32_t fh_ht_memuse(fh_ht_t *ht)
{
    uint32_t mem = 0;
    mem += sizeof(fh_ht_t);
    mem += ht->ht_size * sizeof(he_head_t);
    mem += fh_mpool_memuse(ht->ht_mpool);
    return mem;
}

canonical_original_code:
unsigned int fh_ht_memuse(struct fh_ht_t *ht)
{
    unsigned int mem = 0;
    mem += sizeof(fh_ht_t);
    mem += ht->ht_size * sizeof(he_head_t);
    mem += fh_mpool_memuse(ht->ht_mpool);
    return mem;
}

variable_types:
mem
unsigned int


decompiled_code:
__int64 __fastcall adm_serv_resp_pack(char *src, char *dest, _DWORD *a3)
{
char *v4; // r13
int v5; // eax
unsigned int v6; // edi
int v7; // eax
unsigned int v8; // edi
char *v9; // rbp
__int64 v10; // rcx
unsigned int v11; // er14
unsigned int v12; // er12
unsigned int v13; // er13
const char *v14; // rax
__int64 v15; // rax

*a3 = *((_DWORD *)src + 4) * *((_DWORD *)src + 5) + 28;
if ( !dest )
return 0;
v4 = src + 28;
v5 = _bswap_32(*((_DWORD *)src + 6));
v6 = *((_DWORD *)src + 5);
*((_DWORD *)dest + 6) = v5;
v7 = _bswap_32(v6);
v8 = *((_DWORD *)src + 4);
*((_DWORD *)dest + 5) = v7;
v9 = dest + 28;
*((_DWORD *)dest + 4) = _bswap_32(v8);
strcpy(dest, src);
if ( !*((_DWORD *)src + 4) )
return 0;
v10 = *((unsigned int *)src + 5);
v11 = 0;
while ( 1 )
{
v12 = fh_adm_pack(*((unsigned int *)src + 6), v9, v4, v10);
if ( v12 )
break;
++v11;
v10 = *((unsigned int *)src + 5);
v9 += v10;
v4 += v10;
if ( *((_DWORD *)src + 4) <= v11 )
return 0;
}
if ( (fh_log_lvl[12] & 1) != 0 )
{
v13 = *((_DWORD *)src + 4);
v14 = (const char *)fh_adm_getname(*((unsigned int *)src + 6));
v15 = fh_log_fmt("Failed to pack cmd: %s resp: %d out of %d", v14, v11, v13);
fh_log("admin/fh_adm_serv_resp.c", 61LL, "MGMT", "ERR", v15);
return v12;
}
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src, char *dest, _DWORD *a3)
{
char *v4; // r13
int v5; // eax
unsigned int v6; // edi
int v7; // eax
unsigned int v8; // edi
char *v9; // rbp
__int64 v10; // rcx
unsigned int v11; // er14
unsigned int v12; // er12
unsigned int v13; // er13
const char *v14; // rax
__int64 v15; // rax

*a3 = *((_DWORD *)src + 4) * *((_DWORD *)src + 5) + 28;
if ( !dest )
return 0;
v4 = src + 28;
v5 = func0(*((_DWORD *)src + 6));
v6 = *((_DWORD *)src + 5);
*((_DWORD *)dest + 6) = v5;
v7 = func0(v6);
v8 = *((_DWORD *)src + 4);
*((_DWORD *)dest + 5) = v7;
v9 = dest + 28;
*((_DWORD *)dest + 4) = func0(v8);
strcpy(dest, src);
if ( !*((_DWORD *)src + 4) )
return 0;
v10 = *((unsigned int *)src + 5);
v11 = 0;
while ( 1 )
{
v12 = fh_adm_pack(*((unsigned int *)src + 6), v9, v4, v10);
if ( v12 )
break;
++v11;
v10 = *((unsigned int *)src + 5);
v9 += v10;
v4 += v10;
if ( *((_DWORD *)src + 4) <= v11 )
return 0;
}
if ( (fh_log_lvl[12] & 1) != 0 )
{
v13 = *((_DWORD *)src + 4);
v14 = (const char *)fh_adm_getname(*((unsigned int *)src + 6));
v15 = fh_log_fmt("Failed to pack cmd: %s resp: %d out of %d", v14, v11, v13);
fh_log("admin/fh_adm_serv_resp.c", 61LL, "MGMT", "ERR", v15);
return v12;
}
return v12;
}

original_code:
FH_STATUS adm_serv_resp_pack(void *msg, char *data, int *length)
{
    fh_adm_serv_resp_t *m_serv = (fh_adm_serv_resp_t *) msg;
    fh_adm_serv_resp_t *d_serv = (fh_adm_serv_resp_t *) data;
    register uint32_t i;
    *length = sizeof(fh_adm_serv_resp_t) +
              m_serv->serv_resp_size * m_serv->serv_resp_cnt;
    if (data == ((void *)0)) {
        return (0);
    }
    d_serv->serv_resp_cmd = __bswap_32 (m_serv->serv_resp_cmd);
    d_serv->serv_resp_size = __bswap_32 (m_serv->serv_resp_size);
    d_serv->serv_resp_cnt = __bswap_32 (m_serv->serv_resp_cnt);
    strcpy(d_serv->serv_name, m_serv->serv_name);
    data += sizeof(fh_adm_serv_resp_t);
    msg += sizeof(fh_adm_serv_resp_t);
    for (i=0; i<m_serv->serv_resp_cnt; i++) {
        FH_STATUS rc = fh_adm_pack(m_serv->serv_resp_cmd,
                                   data, msg, m_serv->serv_resp_size);
        if (rc != (0)) {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to pack cmd: %s resp: %d out of %d", (fh_adm_getname(m_serv->serv_resp_cmd)), i, m_serv->serv_resp_cnt); fh_log("admin/fh_adm_serv_resp.c", 61, "MGMT", "ERR", _msg); } } while (0);
            return rc;
        }
        data += m_serv->serv_resp_size;
        msg += m_serv->serv_resp_size;
    }
    return (0);
}

canonical_original_code:
int adm_serv_resp_pack(void *msg, char *data, int *length)
{
    struct fh_adm_serv_resp_t *m_serv = (fh_adm_serv_resp_t *) msg;
    struct fh_adm_serv_resp_t *d_serv = (fh_adm_serv_resp_t *) data;
    register unsigned int i;
    *length = sizeof(fh_adm_serv_resp_t) +
              m_serv->serv_resp_size * m_serv->serv_resp_cnt;
    if (data == ((void *)0)) {
        return (0);
    }
    d_serv->serv_resp_cmd = __bswap_32 (m_serv->serv_resp_cmd);
    d_serv->serv_resp_size = __bswap_32 (m_serv->serv_resp_size);
    d_serv->serv_resp_cnt = __bswap_32 (m_serv->serv_resp_cnt);
    strcpy(d_serv->serv_name, m_serv->serv_name);
    data += sizeof(fh_adm_serv_resp_t);
    msg += sizeof(fh_adm_serv_resp_t);
    for (i=0; i<m_serv->serv_resp_cnt; i++) {
        int rc = fh_adm_pack(m_serv->serv_resp_cmd,
                                   data, msg, m_serv->serv_resp_size);
        if (rc != (0)) {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to pack cmd: %s resp: %d out of %d", (fh_adm_getname(m_serv->serv_resp_cmd)), i, m_serv->serv_resp_cnt); fh_log("admin/fh_adm_serv_resp.c", 61, "MGMT", "ERR", _msg); } } while (0);
            return rc;
        }
        data += m_serv->serv_resp_size;
        msg += m_serv->serv_resp_size;
    }
    return (0);
}

variable_types:
msg
void *

variable_types:
data
char *

variable_types:
length
int *

variable_types: struct fh_adm_serv_resp_t { char serv_name[16]; unsigned int serv_resp_cnt; unsigned int serv_resp_size; unsigned int serv_resp_cmd; } *

variable_types:
i
unsigned int

variable_types: rc int


decompiled_code:
__int64 __fastcall adm_serv_resp_unpack(char *dest, __int64 a2, unsigned int a3)
{
int v5; // eax
unsigned int v6; // edi
int v7; // eax
unsigned int v8; // edi
__int64 v9; // r8
__int64 v10; // rdx
__int64 v11; // rbx
char *v12; // rbp
unsigned int v13; // er14
__int64 v14; // rcx
unsigned int v15; // er12
unsigned int v16; // er15
const char *v17; // rax
__int64 v18; // rax
__int64 v20; // rax

v5 = _bswap_32(*(_DWORD *)(a2 + 24));
v6 = *(_DWORD *)(a2 + 20);
*((_DWORD *)dest + 6) = v5;
v7 = _bswap_32(v6);
v8 = *(_DWORD *)(a2 + 16);
*((_DWORD *)dest + 5) = v7;
*((_DWORD *)dest + 4) = _bswap_32(v8);
strcpy(dest, (const char *)a2);
v9 = *((unsigned int *)dest + 4);
v10 = (unsigned int)(v9 * *((_DWORD *)dest + 5) + 28);
if ( (_DWORD)v10 == a3 )
{
v11 = a2 + 28;
v12 = dest + 28;
v13 = 0;
if ( (_DWORD)v9 )
{
while ( 1 )
{
v15 = fh_adm_unpack(*((unsigned int *)dest + 6), v11, v12);
if ( v15 )
break;
++v13;
v14 = *((unsigned int *)dest + 5);
v11 += v14;
v12 += v14;
if ( *((_DWORD *)dest + 4) <= v13 )
goto LABEL_8;
}
if ( (fh_log_lvl[12] & 1) != 0 )
{
v16 = *((_DWORD *)dest + 4);
v17 = (const char *)fh_adm_getname(*((unsigned int *)dest + 6));
v18 = fh_log_fmt("Failed to pack cmd: %s resp: %d out of %d", v17, v13, v16);
fh_log("admin/fh_adm_serv_resp.c", 114LL, "MGMT", "ERR", v18);
}
}
else
{
LABEL_8:
v15 = 0;
}
}
else
{
v15 = -1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v20 = fh_log_fmt(
"Invalid service response length: %d != %d (resp_size: %d resp_cnt: %d)",
a3,
v10,
*((unsigned int *)dest + 5),
v9);
fh_log("admin/fh_adm_serv_resp.c", 98LL, "MGMT", "ERR", v20);
}
}
return v15;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *dest, __int64 a2, unsigned int a3)
{
int v5; // eax
unsigned int v6; // edi
int v7; // eax
unsigned int v8; // edi
__int64 v9; // r8
__int64 v10; // rdx
__int64 v11; // rbx
char *v12; // rbp
unsigned int v13; // er14
__int64 v14; // rcx
unsigned int v15; // er12
unsigned int v16; // er15
const char *v17; // rax
__int64 v18; // rax
__int64 v20; // rax

v5 = func0(*(_DWORD *)(a2 + 24));
v6 = *(_DWORD *)(a2 + 20);
*((_DWORD *)dest + 6) = v5;
v7 = func0(v6);
v8 = *(_DWORD *)(a2 + 16);
*((_DWORD *)dest + 5) = v7;
*((_DWORD *)dest + 4) = func0(v8);
strcpy(dest, (const char *)a2);
v9 = *((unsigned int *)dest + 4);
v10 = (unsigned int)(v9 * *((_DWORD *)dest + 5) + 28);
if ( (_DWORD)v10 == a3 )
{
v11 = a2 + 28;
v12 = dest + 28;
v13 = 0;
if ( (_DWORD)v9 )
{
while ( 1 )
{
v15 = fh_adm_unpack(*((unsigned int *)dest + 6), v11, v12);
if ( v15 )
break;
++v13;
v14 = *((unsigned int *)dest + 5);
v11 += v14;
v12 += v14;
if ( *((_DWORD *)dest + 4) <= v13 )
goto LABEL_8;
}
if ( (fh_log_lvl[12] & 1) != 0 )
{
v16 = *((_DWORD *)dest + 4);
v17 = (const char *)fh_adm_getname(*((unsigned int *)dest + 6));
v18 = fh_log_fmt("Failed to pack cmd: %s resp: %d out of %d", v17, v13, v16);
fh_log("admin/fh_adm_serv_resp.c", 114LL, "MGMT", "ERR", v18);
}
}
else
{
LABEL_8:
v15 = 0;
}
}
else
{
v15 = -1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v20 = fh_log_fmt(
"Invalid service response length: %d != %d (resp_size: %d resp_cnt: %d)",
a3,
v10,
*((unsigned int *)dest + 5),
v9);
fh_log("admin/fh_adm_serv_resp.c", 98LL, "MGMT", "ERR", v20);
}
}
return v15;
}

original_code:
FH_STATUS adm_serv_resp_unpack(void *msg, char *data, int length)
{
    fh_adm_serv_resp_t *m_serv = (fh_adm_serv_resp_t *) msg;
    fh_adm_serv_resp_t *d_serv = (fh_adm_serv_resp_t *) data;
    register uint32_t i;
    int exp_len;
    m_serv->serv_resp_cmd = __bswap_32 (d_serv->serv_resp_cmd);
    m_serv->serv_resp_size = __bswap_32 (d_serv->serv_resp_size);
    m_serv->serv_resp_cnt = __bswap_32 (d_serv->serv_resp_cnt);
    strcpy(m_serv->serv_name, d_serv->serv_name);
    exp_len = sizeof(fh_adm_serv_resp_t) + m_serv->serv_resp_size *
        m_serv->serv_resp_cnt;
    if (length != exp_len) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Invalid service response length: %d != %d " "(resp_size: %d resp_cnt: %d)", length, exp_len, m_serv->serv_resp_size, m_serv->serv_resp_cnt); fh_log("admin/fh_adm_serv_resp.c", 98, "MGMT", "ERR", _msg); } } while (0);
        return (-1);
    }
    data += sizeof(fh_adm_serv_resp_t);
    msg += sizeof(fh_adm_serv_resp_t);
    for (i=0; i<m_serv->serv_resp_cnt; i++) {
        FH_STATUS rc = fh_adm_unpack(m_serv->serv_resp_cmd,
                                     data, msg, m_serv->serv_resp_size);
        if (rc != (0)) {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to pack cmd: %s resp: %d out of %d", (fh_adm_getname(m_serv->serv_resp_cmd)), i, m_serv->serv_resp_cnt); fh_log("admin/fh_adm_serv_resp.c", 114, "MGMT", "ERR", _msg); } } while (0);
            return rc;
        }
        data += m_serv->serv_resp_size;
        msg += m_serv->serv_resp_size;
    }
    return (0);
}

canonical_original_code:
int adm_serv_resp_unpack(void *msg, char *data, int length)
{
    struct fh_adm_serv_resp_t *m_serv = (fh_adm_serv_resp_t *) msg;
    struct fh_adm_serv_resp_t *d_serv = (fh_adm_serv_resp_t *) data;
    register unsigned int i;
    int exp_len;
    m_serv->serv_resp_cmd = __bswap_32 (d_serv->serv_resp_cmd);
    m_serv->serv_resp_size = __bswap_32 (d_serv->serv_resp_size);
    m_serv->serv_resp_cnt = __bswap_32 (d_serv->serv_resp_cnt);
    strcpy(m_serv->serv_name, d_serv->serv_name);
    exp_len = sizeof(fh_adm_serv_resp_t) + m_serv->serv_resp_size *
        m_serv->serv_resp_cnt;
    if (length != exp_len) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Invalid service response length: %d != %d " "(resp_size: %d resp_cnt: %d)", length, exp_len, m_serv->serv_resp_size, m_serv->serv_resp_cnt); fh_log("admin/fh_adm_serv_resp.c", 98, "MGMT", "ERR", _msg); } } while (0);
        return (-1);
    }
    data += sizeof(fh_adm_serv_resp_t);
    msg += sizeof(fh_adm_serv_resp_t);
    for (i=0; i<m_serv->serv_resp_cnt; i++) {
        int rc = fh_adm_unpack(m_serv->serv_resp_cmd,
                                     data, msg, m_serv->serv_resp_size);
        if (rc != (0)) {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to pack cmd: %s resp: %d out of %d", (fh_adm_getname(m_serv->serv_resp_cmd)), i, m_serv->serv_resp_cnt); fh_log("admin/fh_adm_serv_resp.c", 114, "MGMT", "ERR", _msg); } } while (0);
            return rc;
        }
        data += m_serv->serv_resp_size;
        msg += m_serv->serv_resp_size;
    }
    return (0);
}

variable_types: length int

user_defined_types: struct fh_adm_serv_resp_t { char serv_name[16]; unsigned int serv_resp_cnt; unsigned int serv_resp_size; unsigned int serv_resp_cmd; }


decompiled_code:
__int64 __fastcall adm_action_req_pack(unsigned int *a1, _DWORD *a2, _DWORD *a3)
{
*a3 = 4;
if ( a2 )
*a2 = _bswap_32(*a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1, _DWORD *a2, _DWORD *a3)
{
*a3 = 4;
if ( a2 )
*a2 = func0(*a1);
return 0LL;
}

original_code:
FH_STATUS adm_action_req_pack(void *msg, char *data, int *length)
{
    fh_adm_action_req_t *m_action = (fh_adm_action_req_t *) msg;
    fh_adm_action_req_t *d_action = (fh_adm_action_req_t *) data;
    *length = sizeof(fh_adm_action_req_t);
    if (data == ((void *)0)) {
        return (0);
    }
    d_action->action_type = __bswap_32 (m_action->action_type);
    return (0);
}

canonical_original_code:
int adm_action_req_pack(void *msg, char *data, int *length)
{
    struct fh_adm_action_req_t *m_action = (fh_adm_action_req_t *) msg;
    struct fh_adm_action_req_t *d_action = (fh_adm_action_req_t *) data;
    *length = sizeof(fh_adm_action_req_t);
    if (data == ((void *)0)) {
        return (0);
    }
    d_action->action_type = __bswap_32 (m_action->action_type);
    return (0);
}

variable_types: struct fh_adm_action_req_t { unsigned int action_type; } *


decompiled_code:
__int64 __fastcall adm_action_req_unpack(__int64 a1, unsigned int *a2, int a3)
{
int v3; // eax
_DWORD *v4; // rcx
__int64 v6; // rax

if ( a3 != 4 )
{
v6 = fh_log_fmt(
"assertion '%s' failed at %s:%d",
"length == sizeof(fh_adm_action_req_t)",
"admin/fh_adm_action_req.c",
56LL);
fh_log("admin/fh_adm_action_req.c", 56LL, 0LL, "ERR", v6);
exit(1);
}
v3 = _bswap_32(*a2);
*v4 = v3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int *a2, int a3)
{
int v3; // eax
_DWORD *v4; // rcx
__int64 v6; // rax

if ( a3 != 4 )
{
v6 = fh_log_fmt(
"assertion '%s' failed at %s:%d",
"length == sizeof(fh_adm_action_req_t)",
"admin/fh_adm_action_req.c",
56LL);
fh_log("admin/fh_adm_action_req.c", 56LL, 0LL, "ERR", v6);
exit(1);
}
v3 = func0(*a2);
*v4 = v3;
return 0LL;
}

original_code:
FH_STATUS adm_action_req_unpack(void *msg, char *data, int length)
{
    fh_adm_action_req_t *m_action = (fh_adm_action_req_t *) msg;
    fh_adm_action_req_t *d_action = (fh_adm_action_req_t *) data;
    do { int nok = !(length == sizeof(fh_adm_action_req_t)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "length == sizeof(fh_adm_action_req_t)", "admin/fh_adm_action_req.c", 56); fh_log("admin/fh_adm_action_req.c", 56, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    m_action->action_type = __bswap_32 (d_action->action_type);
    return (0);
}

canonical_original_code:
int adm_action_req_unpack(void *msg, char *data, int length)
{
    struct fh_adm_action_req_t *m_action = (fh_adm_action_req_t *) msg;
    struct fh_adm_action_req_t *d_action = (fh_adm_action_req_t *) data;
    do { int nok = !(length == sizeof(fh_adm_action_req_t)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "length == sizeof(fh_adm_action_req_t)", "admin/fh_adm_action_req.c", 56); fh_log("admin/fh_adm_action_req.c", 56, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    m_action->action_type = __bswap_32 (d_action->action_type);
    return (0);
}

variable_types: nok int

user_defined_types: struct fh_adm_action_req_t { unsigned int action_type; }


decompiled_code:
__int64 __fastcall fh_sock_setbuf(unsigned int a1, int a2, int a3)
{
unsigned int v3; // er13
int *v6; // rax
const char *v7; // rsi
__int64 v8; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = a3;
if ( !a3 || setsockopt(a1, 1, a2, optval, 4u) >= 0 )
return 0;
v3 = -1;
if ( (fh_log_lvl[4] & 2) != 0 )
{
v6 = _errno_location();
v7 = "SO_RCVBUF";
if ( a2 != 8 )
v7 = "SO_SNDBUF";
v8 = fh_log_fmt("NET> setsockopt %s failed on socket #%d: %d", v7, a1, (unsigned int)*v6);
fh_log("fh_sock.c", 42LL, "NET", "WARN", v8);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2, int a3)
{
unsigned int v3; // er13
int *v6; // rax
const char *v7; // rsi
__int64 v8; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = a3;
if ( !a3 || setsockopt(a1, 1, a2, optval, 4u) >= 0 )
return 0;
v3 = -1;
if ( (fh_log_lvl[4] & 2) != 0 )
{
v6 = _errno_location();
v7 = "SO_RCVBUF";
if ( a2 != 8 )
v7 = "SO_SNDBUF";
v8 = fh_log_fmt("NET> setsockopt %s failed on socket #%d: %d", v7, a1, (unsigned int)*v6);
fh_log("fh_sock.c", 42LL, "NET", "WARN", v8);
}
return v3;
}

original_code:
FH_STATUS fh_sock_setbuf(int s, int opt, int bufsz)
{
    if (bufsz == 0) {
        return (0);
    }
    if (setsockopt(s, 1, opt, (char *)&bufsz, sizeof(bufsz)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("NET> setsockopt %s failed on socket #%d: %d", opt == 8 ? "SO_RCVBUF" : "SO_SNDBUF", s, (*__errno_location ())); fh_log("fh_sock.c", 42, "NET", "WARN", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_sock_setbuf(int s, int opt, int bufsz)
{
    if (bufsz == 0) {
        return (0);
    }
    if (setsockopt(s, 1, opt, (char *)&bufsz, sizeof(bufsz)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("NET> setsockopt %s failed on socket #%d: %d", opt == 8 ? "SO_RCVBUF" : "SO_SNDBUF", s, (*__errno_location ())); fh_log("fh_sock.c", 42, "NET", "WARN", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

variable_types: s int

variable_types: opt int

variable_types: bufsz int


decompiled_code:
__int64 __fastcall fh_sock_getbuf(unsigned int a1, int a2, void *a3)
{
unsigned int v4; // er13
int *v6; // rax
const char *v7; // rsi
__int64 v8; // rax
socklen_t optlen[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optlen[0] = 4;
if ( getsockopt(a1, 1, a2, a3, optlen) >= 0 )
return 0;
v4 = -1;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v6 = _errno_location();
v7 = "SO_RCVBUF";
if ( a2 != 8 )
v7 = "SO_SNDBUF";
v8 = fh_log_fmt("NET> setsockopt %s failed on socket #%d: %d", v7, a1, (unsigned int)*v6);
fh_log("fh_sock.c", 60LL, "NET", "ERR", v8);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, int a2, void *a3)
{
unsigned int v4; // er13
int *v6; // rax
const char *v7; // rsi
__int64 v8; // rax
socklen_t optlen[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optlen[0] = 4;
if ( getsockopt(a1, 1, a2, a3, optlen) >= 0 )
return 0;
v4 = -1;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v6 = _errno_location();
v7 = "SO_RCVBUF";
if ( a2 != 8 )
v7 = "SO_SNDBUF";
v8 = fh_log_fmt("NET> setsockopt %s failed on socket #%d: %d", v7, a1, (unsigned int)*v6);
fh_log("fh_sock.c", 60LL, "NET", "ERR", v8);
}
return v4;
}

original_code:
FH_STATUS fh_sock_getbuf(int s, int opt, int *bufsz)
{
    int len = sizeof(int);
    if (getsockopt(s, 1, opt,(char *)bufsz,(socklen_t*)&len) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt %s failed on socket #%d: %d", opt == 8 ? "SO_RCVBUF" : "SO_SNDBUF", s, (*__errno_location ())); fh_log("fh_sock.c", 60, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_sock_getbuf(int s, int opt, int *bufsz)
{
    int len = sizeof(int);
    if (getsockopt(s, 1, opt,(char *)bufsz,(unsigned int *)&len) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt %s failed on socket #%d: %d", opt == 8 ? "SO_RCVBUF" : "SO_SNDBUF", s, (*__errno_location ())); fh_log("fh_sock.c", 60, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

variable_types:
bufsz
int *

variable_types: len int


decompiled_code:
__int64 __fastcall fh_sock_setrxbuf(unsigned int a1, int a2)
{
return fh_sock_setbuf(a1, 8, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, int a2)
{
return func1(a1, 8, a2);
}

original_code:
FH_STATUS fh_sock_setrxbuf(int s, int bufsz)
{
    return fh_sock_setbuf(s, 8, bufsz);
}

canonical_original_code:
int fh_sock_setrxbuf(int s, int bufsz)
{
    return fh_sock_setbuf(s, 8, bufsz);
}


decompiled_code:
__int64 __fastcall fh_sock_getrxbuf(unsigned int a1, void *a2)
{
return fh_sock_getbuf(a1, 8, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, void *a2)
{
return func2(a1, 8, a2);
}

original_code:
FH_STATUS fh_sock_getrxbuf(int s, int *bufsz)
{
    return fh_sock_getbuf(s, 8, bufsz);
}

canonical_original_code:
int fh_sock_getrxbuf(int s, int *bufsz)
{
    return fh_sock_getbuf(s, 8, bufsz);
}