decompiled_code:
__int64 rf_host_copyrect()
{
__int64 v0; // rbx
_WORD *v1; // rdx
unsigned __int16 v2; // cx
unsigned int v3; // er10
unsigned int v4; // er11
__int64 v5; // rdx
void *v6; // rsi
char *v7; // rdi
char *v8; // r12
char *v9; // rcx
__int64 v10; // rbx
int v11; // ebp
char *v12; // rax
char *v14; // r12
int v15; // ebp
__int64 v16; // rbx
char *v17; // rax

v0 = g_fb_width;
fbs_spool_data(*(_QWORD *)(cur_slot + 32LL), 4LL);
v1 = *(_WORD **)(cur_slot + 32LL);
word_EAC = __ROL2__(*v1, 8);
v2 = __ROL2__(v1[1], 8);
word_EAE = v2;
if ( g_fb_width <= (unsigned __int16)word_EAC )
{
v3 = (unsigned __int16)word_EA4;
v4 = (unsigned __int16)word_EA6;
LABEL_12:
log_write(1LL, "CopyRect from outside of the framebuffer: %dx%d from %d,%d", v3, v4, (unsigned __int16)word_EAC, v2);
return aio_close(0LL);
}
v3 = (unsigned __int16)word_EA4;
v4 = (unsigned __int16)word_EA6;
v5 = (unsigned __int16)word_EA4;
if ( (unsigned __int16)word_EA4 + (unsigned __int16)word_EAC > g_fb_width
|| g_fb_height <= v2
|| (unsigned __int16)word_EA6 + v2 > g_fb_height )
{
goto LABEL_12;
}
v6 = g_framebuffer;
if ( HIWORD(cur_rect) >= v2 )
{
v7 = (char *)(((unsigned __int16)word_EA6 + HIWORD(cur_rect) - 1) * (unsigned __int16)v0 + (unsigned __int16)cur_rect);
v14 = (char *)g_framebuffer
+ 4 * (unsigned __int16)v0 * ((unsigned __int16)word_EA6 + v2 - 1)
+ 4 * (unsigned __int16)word_EAC;
v9 = (char *)g_framebuffer + 4 * (_QWORD)v7;
if ( word_EA6 )
{
v15 = 0;
v16 = -4 * v0;
while ( 1 )
{
v6 = v14;
v7 = v9;
++v15;
v17 = (char *)memmove(v9, v14, 4 * v5);
v14 += v16;
v9 = &v17[v16];
if ( (unsigned __int16)word_EA6 <= v15 )
break;
v5 = (unsigned __int16)word_EA4;
}
}
}
else
{
v7 = (char *)(HIWORD(cur_rect) * (unsigned __int16)v0 + (unsigned __int16)cur_rect);
v8 = (char *)g_framebuffer + 4 * (unsigned __int16)word_EAC + 4 * (unsigned __int16)v0 * v2;
v9 = (char *)g_framebuffer + 4 * (_QWORD)v7;
if ( word_EA6 )
{
v10 = 4 * v0;
v11 = 0;
while ( 1 )
{
v6 = v8;
v7 = v9;
++v11;
v12 = (char *)memmove(v9, v8, 4 * v5);
v8 += v10;
v9 = &v12[v10];
if ( (unsigned __int16)word_EA6 <= v11 )
break;
v5 = (unsigned __int16)word_EA4;
}
}
}
return fbupdate_rect_done(v7, v6, v5, v9);
}

canonical_decompiled_code:
__int64 func17()
{
__int64 v0; // rbx
_WORD *v1; // rdx
unsigned __int16 v2; // cx
unsigned int v3; // er10
unsigned int v4; // er11
__int64 v5; // rdx
void *v6; // rsi
char *v7; // rdi
char *v8; // r12
char *v9; // rcx
__int64 v10; // rbx
int v11; // ebp
char *v12; // rax
char *v14; // r12
int v15; // ebp
__int64 v16; // rbx
char *v17; // rax

v0 = g_fb_width;
fbs_spool_data(*(_QWORD *)(cur_slot + 32LL), 4LL);
v1 = *(_WORD **)(cur_slot + 32LL);
word_EAC = __ROL2__(*v1, 8);
v2 = __ROL2__(v1[1], 8);
word_EAE = v2;
if ( g_fb_width <= (unsigned __int16)word_EAC )
{
v3 = (unsigned __int16)word_EA4;
v4 = (unsigned __int16)word_EA6;
LABEL_12:
log_write(1LL, "CopyRect from outside of the framebuffer: %dx%d from %d,%d", v3, v4, (unsigned __int16)word_EAC, v2);
return aio_close(0LL);
}
v3 = (unsigned __int16)word_EA4;
v4 = (unsigned __int16)word_EA6;
v5 = (unsigned __int16)word_EA4;
if ( (unsigned __int16)word_EA4 + (unsigned __int16)word_EAC > g_fb_width
|| g_fb_height <= v2
|| (unsigned __int16)word_EA6 + v2 > g_fb_height )
{
goto LABEL_12;
}
v6 = g_framebuffer;
if ( HIWORD(cur_rect) >= v2 )
{
v7 = (char *)(((unsigned __int16)word_EA6 + HIWORD(cur_rect) - 1) * (unsigned __int16)v0 + (unsigned __int16)cur_rect);
v14 = (char *)g_framebuffer
+ 4 * (unsigned __int16)v0 * ((unsigned __int16)word_EA6 + v2 - 1)
+ 4 * (unsigned __int16)word_EAC;
v9 = (char *)g_framebuffer + 4 * (_QWORD)v7;
if ( word_EA6 )
{
v15 = 0;
v16 = -4 * v0;
while ( 1 )
{
v6 = v14;
v7 = v9;
++v15;
v17 = (char *)memmove(v9, v14, 4 * v5);
v14 += v16;
v9 = &v17[v16];
if ( (unsigned __int16)word_EA6 <= v15 )
break;
v5 = (unsigned __int16)word_EA4;
}
}
}
else
{
v7 = (char *)(HIWORD(cur_rect) * (unsigned __int16)v0 + (unsigned __int16)cur_rect);
v8 = (char *)g_framebuffer + 4 * (unsigned __int16)word_EAC + 4 * (unsigned __int16)v0 * v2;
v9 = (char *)g_framebuffer + 4 * (_QWORD)v7;
if ( word_EA6 )
{
v10 = 4 * v0;
v11 = 0;
while ( 1 )
{
v6 = v8;
v7 = v9;
++v11;
v12 = (char *)memmove(v9, v8, 4 * v5);
v8 += v10;
v9 = &v12[v10];
if ( (unsigned __int16)word_EA6 <= v11 )
break;
v5 = (unsigned __int16)word_EA4;
}
}
}
return func15(v7, v6, v5, v9);
}

original_code:
static void rf_host_copyrect(void)
{
  u_int32_t *src_ptr;
  u_int32_t *dst_ptr;
  int width = (int)g_fb_width;
  int row;
  fbs_spool_data(cur_slot->readbuf, 4);
  cur_rect.src_x = ((u_int16_t)((u_int8_t *)cur_slot->readbuf)[0] << 8 | (u_int16_t)((u_int8_t *)cur_slot->readbuf)[1]);
  cur_rect.src_y = ((u_int16_t)((u_int8_t *)&cur_slot->readbuf[2])[0] << 8 | (u_int16_t)((u_int8_t *)&cur_slot->readbuf[2])[1]);
  if ( cur_rect.src_x >= g_fb_width ||
       cur_rect.src_x + cur_rect.w > g_fb_width ||
       cur_rect.src_y >= g_fb_height ||
       cur_rect.src_y + cur_rect.h > g_fb_height ) {
    log_write(1,
              "CopyRect from outside of the framebuffer: %dx%d from %d,%d",
              (int)cur_rect.w, (int)cur_rect.h,
              (int)cur_rect.src_x, (int)cur_rect.src_y);
    aio_close(0);
    return;
  }
  if (cur_rect.src_y > cur_rect.y) {
    src_ptr = &g_framebuffer[cur_rect.src_y * width + cur_rect.src_x];
    dst_ptr = &g_framebuffer[cur_rect.y * width + cur_rect.x];
    for (row = 0; row < cur_rect.h; row++) {
      memmove(dst_ptr, src_ptr, cur_rect.w * sizeof(u_int32_t));
      src_ptr += width;
      dst_ptr += width;
    }
  } else {
    src_ptr = &g_framebuffer[(cur_rect.src_y + cur_rect.h - 1) * width +
                             cur_rect.src_x];
    dst_ptr = &g_framebuffer[(cur_rect.y + cur_rect.h - 1) * width +
                             cur_rect.x];
    for (row = 0; row < cur_rect.h; row++) {
      memmove(dst_ptr, src_ptr, cur_rect.w * sizeof(u_int32_t));
      src_ptr -= width;
      dst_ptr -= width;
    }
  }
  fbupdate_rect_done();
}

canonical_original_code:
static void rf_host_copyrect()
{
  unsigned int *src_ptr;
  unsigned int *dst_ptr;
  int width = (int)g_fb_width;
  int row;
  fbs_spool_data(cur_slot->readbuf, 4);
  cur_rect.src_x = ((u_int16_t)((unsigned int *)cur_slot->readbuf)[0] << 8 | (u_int16_t)((unsigned int *)cur_slot->readbuf)[1]);
  cur_rect.src_y = ((u_int16_t)((unsigned int *)&cur_slot->readbuf[2])[0] << 8 | (u_int16_t)((unsigned int *)&cur_slot->readbuf[2])[1]);
  if ( cur_rect.src_x >= g_fb_width ||
       cur_rect.src_x + cur_rect.w > g_fb_width ||
       cur_rect.src_y >= g_fb_height ||
       cur_rect.src_y + cur_rect.h > g_fb_height ) {
    log_write(1,
              "CopyRect from outside of the framebuffer: %dx%d from %d,%d",
              (int)cur_rect.w, (int)cur_rect.h,
              (int)cur_rect.src_x, (int)cur_rect.src_y);
    aio_close(0);
    return;
  }
  if (cur_rect.src_y > cur_rect.y) {
    src_ptr = &g_framebuffer[cur_rect.src_y * width + cur_rect.src_x];
    dst_ptr = &g_framebuffer[cur_rect.y * width + cur_rect.x];
    for (row = 0; row < cur_rect.h; row++) {
      memmove(dst_ptr, src_ptr, cur_rect.w * sizeof(u_int32_t));
      src_ptr += width;
      dst_ptr += width;
    }
  } else {
    src_ptr = &g_framebuffer[(cur_rect.src_y + cur_rect.h - 1) * width +
                             cur_rect.src_x];
    dst_ptr = &g_framebuffer[(cur_rect.y + cur_rect.h - 1) * width +
                             cur_rect.x];
    for (row = 0; row < cur_rect.h; row++) {
      memmove(dst_ptr, src_ptr, cur_rect.w * sizeof(u_int32_t));
      src_ptr -= width;
      dst_ptr -= width;
    }
  }
  fbupdate_rect_done();
}

variable_types: width int


repo: inovex/vnc-reflector

decompiled_code:
__int64 rf_host_fbupdate_raw()
{
__int64 v0; // rdi
__int64 v1; // rsi
__int64 v2; // rdx
__int64 v3; // rcx
unsigned __int16 v4; // ax
__int64 result; // rax

v0 = *(_QWORD *)(cur_slot + 32LL);
v1 = 4LL * (unsigned __int16)word_EA4;
fbs_spool_data(v0, v1);
v4 = ++rect_cur_row;
if ( (unsigned __int16)rect_cur_row >= (unsigned __int16)word_EA6 )
result = fbupdate_rect_done(v0, v1, v2, v3);
else
result = aio_setread(
rf_host_fbupdate_raw,
(char *)g_framebuffer + 4 * (unsigned __int16)cur_rect + 4 * g_fb_width * (HIWORD(cur_rect) + v4),
4 * (unsigned int)(unsigned __int16)word_EA4);
return result;
}

canonical_decompiled_code:
__int64 func18()
{
__int64 v0; // rdi
__int64 v1; // rsi
__int64 v2; // rdx
__int64 v3; // rcx
unsigned __int16 v4; // ax
__int64 result; // rax

v0 = *(_QWORD *)(cur_slot + 32LL);
v1 = 4LL * (unsigned __int16)word_EA4;
fbs_spool_data(v0, v1);
v4 = ++rect_cur_row;
if ( (unsigned __int16)rect_cur_row >= (unsigned __int16)word_EA6 )
result = func15(v0, v1, v2, v3);
else
result = aio_setread(
rf_host_fbupdate_raw,
(char *)g_framebuffer + 4 * (unsigned __int16)cur_rect + 4 * g_fb_width * (HIWORD(cur_rect) + v4),
4 * (unsigned int)(unsigned __int16)word_EA4);
return result;
}

original_code:
static void rf_host_fbupdate_raw(void)
{
  int idx;
  fbs_spool_data(cur_slot->readbuf, cur_rect.w * sizeof(u_int32_t));
  if (++rect_cur_row < cur_rect.h) {
    idx = (cur_rect.y + rect_cur_row) * (int)g_fb_width + cur_rect.x;
    aio_setread(rf_host_fbupdate_raw, &g_framebuffer[idx],
                cur_rect.w * sizeof(u_int32_t));
  } else {
    fbupdate_rect_done();
  }
}

canonical_original_code:
static void rf_host_fbupdate_raw()
{
  int idx;
  fbs_spool_data(cur_slot->readbuf, cur_rect.w * sizeof(u_int32_t));
  if (++rect_cur_row < cur_rect.h) {
    idx = (cur_rect.y + rect_cur_row) * (int)g_fb_width + cur_rect.x;
    aio_setread(rf_host_fbupdate_raw, &g_framebuffer[idx],
                cur_rect.w * sizeof(u_int32_t));
  } else {
    fbupdate_rect_done();
  }
}

variable_types: idx int

return_type: void


decompiled_code:
int pass_msg_to_host()
{
int result; // eax
__int64 v1; // rbx

result = s_host_slot;
if ( s_host_slot )
{
v1 = cur_slot;
cur_slot = s_host_slot;
result = aio_write(0LL);
cur_slot = v1;
}
return result;
}

canonical_decompiled_code:
int func19()
{
int result; // eax
__int64 v1; // rbx

result = s_host_slot;
if ( s_host_slot )
{
v1 = cur_slot;
cur_slot = s_host_slot;
result = aio_write(0LL);
cur_slot = v1;
}
return result;
}

original_code:
void pass_msg_to_host(u_int8_t *msg, size_t len)
{
  AIO_SLOT *saved_slot = cur_slot;
  if (s_host_slot != ((void *)0)) {
    cur_slot = s_host_slot;
    aio_write(((void *)0), msg, len);
    cur_slot = saved_slot;
  }
}

canonical_original_code:
void pass_msg_to_host(unsigned int *msg, unsigned long len)
{
  struct _AIO_SLOT *saved_slot = cur_slot;
  if (s_host_slot != ((void *)0)) {
    cur_slot = s_host_slot;
    aio_write(((void *)0), msg, len);
    cur_slot = saved_slot;
  }
}

variable_types:
msg
unsigned int *

variable_types:
len
unsigned long

variable_types: struct _AIO_SLOT { int type; int fd; int idx; char *name; void (*readfunc)(); unsigned char *readbuf; unsigned long bytes_to_read; unsigned long bytes_ready; unsigned char buf256[256]; struct _AIO_BLOCK { struct _AIO_BLOCK *next; void (*func)(); unsigned long data_size; unsigned char data[1]; } *outqueue; struct _AIO_BLOCK *outqueue_last; unsigned long bytes_written; void (*closefunc)(); unsigned int listening_f; unsigned int alloc_f; unsigned int close_f; unsigned int fd_closed_f; unsigned int errio_f; unsigned int errread_f; unsigned int errwrite_f; int io_errno; struct _AIO_SLOT *next; struct _AIO_SLOT *prev; } *

user_defined_types: struct _AIO_SLOT { int type; int fd; int idx; char *name; void (*readfunc)(); unsigned char *readbuf; unsigned long bytes_to_read; unsigned long bytes_ready; unsigned char buf256[256]; struct _AIO_BLOCK *outqueue; struct _AIO_BLOCK *outqueue_last; unsigned long bytes_written; void (*closefunc)(); unsigned int listening_f; unsigned int alloc_f; unsigned int close_f; unsigned int fd_closed_f; unsigned int errio_f; unsigned int errread_f; unsigned int errwrite_f; int io_errno; struct _AIO_SLOT *next; struct _AIO_SLOT *prev; }


decompiled_code:
int pass_cuttext_to_host()
{
int result; // eax
__int64 v1; // r12

result = s_host_slot;
v1 = cur_slot;
if ( s_host_slot )
{
cur_slot = s_host_slot;
aio_write(0LL);
result = aio_write(0LL);
cur_slot = v1;
}
return result;
}

canonical_decompiled_code:
int func20()
{
int result; // eax
__int64 v1; // r12

result = s_host_slot;
v1 = cur_slot;
if ( s_host_slot )
{
cur_slot = s_host_slot;
aio_write(0LL);
result = aio_write(0LL);
cur_slot = v1;
}
return result;
}

original_code:
void pass_cuttext_to_host(u_int8_t *text, size_t len)
{
  AIO_SLOT *saved_slot = cur_slot;
  u_int8_t client_cuttext_hdr[8] = {
    6, 0, 0, 0, 0, 0, 0, 0
  };
  if (s_host_slot != ((void *)0)) {
    { ((u_int8_t *)&client_cuttext_hdr[4])[0] = (u_int8_t)((u_int32_t)len >> 24); ((u_int8_t *)&client_cuttext_hdr[4])[1] = (u_int8_t)((u_int32_t)len >> 16); ((u_int8_t *)&client_cuttext_hdr[4])[2] = (u_int8_t)((u_int32_t)len >> 8); ((u_int8_t *)&client_cuttext_hdr[4])[3] = (u_int8_t)(u_int32_t)len; };
    cur_slot = s_host_slot;
    aio_write(((void *)0), client_cuttext_hdr, sizeof(client_cuttext_hdr));
    aio_write(((void *)0), text, len);
    cur_slot = saved_slot;
  }
}

canonical_original_code:
void pass_cuttext_to_host(unsigned int *text, unsigned long len)
{
  struct _AIO_SLOT *saved_slot = cur_slot;
  unsigned int client_cuttext_hdr[8] = {
    6, 0, 0, 0, 0, 0, 0, 0
  };
  if (s_host_slot != ((void *)0)) {
    { ((unsigned int *)&client_cuttext_hdr[4])[0] = (u_int8_t)((unsigned int)len >> 24); ((unsigned int *)&client_cuttext_hdr[4])[1] = (u_int8_t)((unsigned int)len >> 16); ((unsigned int *)&client_cuttext_hdr[4])[2] = (u_int8_t)((unsigned int)len >> 8); ((unsigned int *)&client_cuttext_hdr[4])[3] = (unsigned int)(unsigned int)len; };
    cur_slot = s_host_slot;
    aio_write(((void *)0), client_cuttext_hdr, sizeof(client_cuttext_hdr));
    aio_write(((void *)0), text, len);
    cur_slot = saved_slot;
  }
}

variable_types:
text
unsigned int *

user_defined_types: struct _AIO_BLOCK { struct _AIO_BLOCK *next; void (*func)(); unsigned long data_size; unsigned char data[1]; }


decompiled_code:
__int64 __fastcall set_active_file(void *src)
{
size_t v1; // r12

if ( !src )
return 0LL;
v1 = strlen((const char *)src) + 1;
active_file = (char *)malloc(v1);
if ( !active_file )
return 0LL;
memcpy(active_file, src, v1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *src)
{
size_t v1; // r12

if ( !src )
return 0LL;
v1 = strlen((const char *)src) + 1;
active_file = (char *)malloc(v1);
if ( !active_file )
return 0LL;
memcpy(active_file, src, v1);
return 1LL;
}

original_code:
int set_active_file(char *file_path)
{
  if (file_path == ((void *)0))
    return 0;
  active_file = malloc(strlen(file_path) + 1);
  if (active_file == ((void *)0))
    return 0;
  strcpy(active_file, file_path);
  return 1;
}

return_type: int


decompiled_code:
__int64 remove_active_file()
{
const char *v0; // r12

v0 = active_file;
if ( !active_file )
return 1LL;
if ( !unlink(active_file) )
{
log_write(6LL, "Removed active file marker", v0);
return 1LL;
}
log_write(2LL, "Error removing active file marker: %s", v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
const char *v0; // r12

v0 = active_file;
if ( !active_file )
return 1LL;
if ( !unlink(active_file) )
{
log_write(6LL, "Removed active file marker", v0);
return 1LL;
}
log_write(2LL, "Error removing active file marker: %s", v0);
return 0LL;
}

original_code:
int remove_active_file(void)
{
  if (active_file != ((void *)0)) {
    if (unlink(active_file) != 0) {
      log_write(2, "Error removing active file marker: %s", active_file);
      return 0;
    }
    log_write(6, "Removed active file marker", active_file);
  }
  return 1;
}

canonical_original_code:
int remove_active_file()
{
  if (active_file != ((void *)0)) {
    if (unlink(active_file) != 0) {
      log_write(2, "Error removing active file marker: %s", active_file);
      return 0;
    }
    log_write(6, "Removed active file marker", active_file);
  }
  return 1;
}


decompiled_code:
__int64 __fastcall set_actions_file(void *src)
{
size_t v1; // r12

if ( !src )
return 0LL;
v1 = strlen((const char *)src) + 1;
actions_file = (char *)malloc(v1);
if ( !actions_file )
return 0LL;
memcpy(actions_file, src, v1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *src)
{
size_t v1; // r12

if ( !src )
return 0LL;
v1 = strlen((const char *)src) + 1;
actions_file = (char *)malloc(v1);
if ( !actions_file )
return 0LL;
memcpy(actions_file, src, v1);
return 1LL;
}

original_code:
int set_actions_file(char *file_path)
{
  if (file_path == ((void *)0))
    return 0;
  actions_file = malloc(strlen(file_path) + 1);
  if (actions_file == ((void *)0))
    return 0;
  strcpy(actions_file, file_path);
  return 1;
}


decompiled_code:
__int64 __fastcall perform_action(char *a1)
{
unsigned int v1; // er12
int v2; // eax
__int64 result; // rax
char v4[1048]; // [rsp+0h] [rbp-418h] BYREF

v1 = 1;
if ( !actions_file )
return v1;
if ( (unsigned int)read_action_constprop_0(a1, v4) )
{
if ( v4[0] )
{
v2 = system(v4);
if ( v2 == -1 || v2 == 32512 )
{
v1 = 0;
log_write(2LL, "Failed to execute action command");
return v1;
}
if ( !BYTE1(v2) )
{
v1 = 1;
log_write(5LL, "Action command done", 0LL);
return v1;
}
log_write(4LL, "Action command exited with status %d", BYTE1(v2));
result = 1LL;
}
else
{
log_write(5LL, "Missing action for `%s'", a1);
result = 0LL;
}
}
else
{
log_write(2LL, "Failed to read actions file: %s", actions_file);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
unsigned int v1; // er12
int v2; // eax
__int64 result; // rax
char v4[1048]; // [rsp+0h] [rbp-418h] BYREF

v1 = 1;
if ( !actions_file )
return v1;
if ( (unsigned int)func0(a1, v4) )
{
if ( v4[0] )
{
v2 = system(v4);
if ( v2 == -1 || v2 == 32512 )
{
v1 = 0;
log_write(2LL, "Failed to execute action command");
return v1;
}
if ( !BYTE1(v2) )
{
v1 = 1;
log_write(5LL, "Action command done", 0LL);
return v1;
}
log_write(4LL, "Action command exited with status %d", BYTE1(v2));
result = 1LL;
}
else
{
log_write(5LL, "Missing action for `%s'", a1);
result = 0LL;
}
}
else
{
log_write(2LL, "Failed to read actions file: %s", actions_file);
result = 0LL;
}
return result;
}

original_code:
int perform_action(char *action_str)
{
  char cmd[1024];
  int status;
  if (actions_file == ((void *)0))
    return 1;
  if (!read_action(action_str, cmd, 1024)) {
    log_write(2, "Failed to read actions file: %s", actions_file);
    return 0;
  }
  if (cmd[0] == '\0') {
    log_write(5, "Missing action for `%s'", action_str);
    return 0;
  }
  status = system(cmd);
  if (status == -1 || status == 0x7F00) {
    log_write(2, "Failed to execute action command");
    return 0;
  }
  status = status >> 8 & 0xFF;
  if (status == 0) {
    log_write(5, "Action command done");
  } else {
    log_write(4, "Action command exited with status %d", status);
  }
  return 1;
}

variable_types:
cmd
char [1024]

variable_types: status int


original_code:
void buf_get_pixfmt(void *buf, RFB_PIXEL_FORMAT *format)
{
  u_int8_t *bbuf = buf;
  memcpy(format, buf, 16);
  format->r_max = ((u_int16_t)((u_int8_t *)&bbuf[4])[0] << 8 | (u_int16_t)((u_int8_t *)&bbuf[4])[1]);
  format->g_max = ((u_int16_t)((u_int8_t *)&bbuf[6])[0] << 8 | (u_int16_t)((u_int8_t *)&bbuf[6])[1]);
  format->b_max = ((u_int16_t)((u_int8_t *)&bbuf[8])[0] << 8 | (u_int16_t)((u_int8_t *)&bbuf[8])[1]);
}

canonical_original_code:
void buf_get_pixfmt(void *buf, struct _RFB_PIXEL_FORMAT *format)
{
  unsigned int *bbuf = buf;
  memcpy(format, buf, 16);
  format->r_max = ((u_int16_t)((unsigned int *)&bbuf[4])[0] << 8 | (u_int16_t)((unsigned int *)&bbuf[4])[1]);
  format->g_max = ((u_int16_t)((unsigned int *)&bbuf[6])[0] << 8 | (u_int16_t)((unsigned int *)&bbuf[6])[1]);
  format->b_max = ((u_int16_t)((unsigned int *)&bbuf[8])[0] << 8 | (u_int16_t)((unsigned int *)&bbuf[8])[1]);
}

variable_types:
buf
void *

variable_types: struct _RFB_PIXEL_FORMAT { unsigned int bits_pixel; unsigned int color_depth; unsigned int big_endian; unsigned int true_color; unsigned int r_max; unsigned int g_max; unsigned int b_max; unsigned int r_shift; unsigned int g_shift; unsigned int b_shift; unsigned int unused[3]; } *

variable_types:
bbuf
unsigned int *


original_code:
void buf_put_pixfmt(void *buf, RFB_PIXEL_FORMAT *format)
{
  u_int8_t *bbuf = buf;
  memcpy(buf, format, 16);
  { ((u_int8_t *)&bbuf[4])[0] = (u_int8_t)(format->r_max >> 8); ((u_int8_t *)&bbuf[4])[1] = (u_int8_t)format->r_max; };
  { ((u_int8_t *)&bbuf[6])[0] = (u_int8_t)(format->g_max >> 8); ((u_int8_t *)&bbuf[6])[1] = (u_int8_t)format->g_max; };
  { ((u_int8_t *)&bbuf[8])[0] = (u_int8_t)(format->b_max >> 8); ((u_int8_t *)&bbuf[8])[1] = (u_int8_t)format->b_max; };
}

canonical_original_code:
void buf_put_pixfmt(void *buf, struct _RFB_PIXEL_FORMAT *format)
{
  unsigned int *bbuf = buf;
  memcpy(buf, format, 16);
  { ((unsigned int *)&bbuf[4])[0] = (u_int8_t)(format->r_max >> 8); ((unsigned int *)&bbuf[4])[1] = (unsigned int)format->r_max; };
  { ((unsigned int *)&bbuf[6])[0] = (u_int8_t)(format->g_max >> 8); ((unsigned int *)&bbuf[6])[1] = (unsigned int)format->g_max; };
  { ((unsigned int *)&bbuf[8])[0] = (u_int8_t)(format->b_max >> 8); ((unsigned int *)&bbuf[8])[1] = (unsigned int)format->b_max; };
}

user_defined_types: struct _RFB_PIXEL_FORMAT { unsigned int bits_pixel; unsigned int color_depth; unsigned int big_endian; unsigned int true_color; unsigned int r_max; unsigned int g_max; unsigned int b_max; unsigned int r_shift; unsigned int g_shift; unsigned int b_shift; unsigned int unused[3]; }


decompiled_code:
__int64 __fastcall rfb_gen_challenge(_BYTE *a1)
{
_BYTE *v1; // rbx
unsigned int v2; // eax
__int64 result; // rax

v1 = a1;
v2 = time(0LL);
srandom(v2);
do
{
result = random();
*v1++ = result;
}
while ( a1 + 16 != v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1)
{
_BYTE *v1; // rbx
unsigned int v2; // eax
__int64 result; // rax

v1 = a1;
v2 = time(0LL);
srandom(v2);
do
{
result = random();
*v1++ = result;
}
while ( a1 + 16 != v1 );
return result;
}

original_code:
void rfb_gen_challenge(u_int8_t *buf)
{
  int i;
  srandom((unsigned int)time(((void *)0)));
  for (i = 0; i < 16; i++)
    *buf++ = (unsigned char)random();
}

canonical_original_code:
void rfb_gen_challenge(unsigned int *buf)
{
  int i;
  srandom((unsigned int)time(((void *)0)));
  for (i = 0; i < 16; i++)
    *buf++ = (unsigned char)random();
}

variable_types:
buf
unsigned int *

variable_types: i int


decompiled_code:
__int64 __fastcall rfb_crypt(__int64 a1, __int64 a2, const char *a3)
{
char dest[32]; // [rsp+8h] [rbp-20h] BYREF

strncpy(dest, a3, 8uLL);
deskey(dest, 0LL);
des(a2, a1);
return des(a2 + 8, a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, const char *a3)
{
char dest[32]; // [rsp+8h] [rbp-20h] BYREF

strncpy(dest, a3, 8uLL);
deskey(dest, 0LL);
des(a2, a1);
return des(a2 + 8, a1 + 8);
}

original_code:
void rfb_crypt(u_int8_t *dst_buf, u_int8_t *src_buf, unsigned char *password)
{
  unsigned char key[8];
  memset(key, 0, 8);
  strncpy((char *)key, (char *)password, 8);
  deskey(key, 0);
  des(src_buf, dst_buf);
  des(src_buf + 8, dst_buf + 8);
}

canonical_original_code:
void rfb_crypt(unsigned int *dst_buf, unsigned int *src_buf, unsigned char *password)
{
  unsigned char key[8];
  memset(key, 0, 8);
  strncpy((char *)key, (char *)password, 8);
  deskey(key, 0);
  des(src_buf, dst_buf);
  des(src_buf + 8, dst_buf + 8);
}

variable_types:
password
unsigned char *

variable_types:
key
unsigned char [8]


decompiled_code:
void __fastcall fbs_set_prefix(char *a1, int a2)
{
s_fbs_prefix = a1;
s_join_sessions = a2;
s_fbs_idx = 0;
}

canonical_decompiled_code:
void __fastcall func0(char *a1, int a2)
{
s_fbs_prefix = a1;
s_join_sessions = a2;
s_fbs_idx = 0;
}

original_code:
void fbs_set_prefix(char *fbs_prefix, int join_sessions)
{
  s_fbs_prefix = fbs_prefix;
  s_join_sessions = join_sessions;
  s_fbs_idx = 0;
}


decompiled_code:
void fbs_close_file()
{
if ( s_fbs_fp )
{
if ( fclose(s_fbs_fp) )
log_write(2LL, "Could not close FBS file");
s_fbs_fp = 0LL;
free(s_fbs_buffer);
}
}

canonical_decompiled_code:
void func3()
{
if ( s_fbs_fp )
{
if ( fclose(s_fbs_fp) )
log_write(2LL, "Could not close FBS file");
s_fbs_fp = 0LL;
free(s_fbs_buffer);
}
}

original_code:
void fbs_close_file(void)
{
  if (s_fbs_fp != ((void *)0)) {
    if (fclose(s_fbs_fp) != 0)
      log_write(2, "Could not close FBS file");
    s_fbs_fp = ((void *)0);
    free(s_fbs_buffer);
  }
}

canonical_original_code:
void fbs_close_file()
{
  if (s_fbs_fp != ((void *)0)) {
    if (fclose(s_fbs_fp) != 0)
      log_write(2, "Could not close FBS file");
    s_fbs_fp = ((void *)0);
    free(s_fbs_buffer);
  }
}


decompiled_code:
void *fbs_flush_data()
{
void *result; // rax

if ( s_fbs_fp )
{
fbs_write_data(s_fbs_buffer, (_BYTE *)s_fbs_buffer_ptr - (_BYTE *)s_fbs_buffer);
result = s_fbs_buffer;
s_fbs_buffer_ptr = s_fbs_buffer;
}
return result;
}

canonical_decompiled_code:
void *func5()
{
void *result; // rax

if ( s_fbs_fp )
{
func4(s_fbs_buffer, (_BYTE *)s_fbs_buffer_ptr - (_BYTE *)s_fbs_buffer);
result = s_fbs_buffer;
s_fbs_buffer_ptr = s_fbs_buffer;
}
return result;
}

original_code:
void fbs_flush_data(void)
{
  if (s_fbs_fp != ((void *)0)) {
    fbs_write_data(s_fbs_buffer, s_fbs_buffer_ptr - s_fbs_buffer);
    s_fbs_buffer_ptr = s_fbs_buffer;
  }
}

canonical_original_code:
void fbs_flush_data()
{
  if (s_fbs_fp != ((void *)0)) {
    fbs_write_data(s_fbs_buffer, s_fbs_buffer_ptr - s_fbs_buffer);
    s_fbs_buffer_ptr = s_fbs_buffer;
  }
}


decompiled_code:
void __fastcall fbs_open_file(unsigned __int16 a1, unsigned __int16 a2)
{
unsigned int v3; // er12
char *v4; // r14
size_t v5; // rax
unsigned int v6; // eax
_DWORD *v7; // rsi
size_t v8; // rsi
int v9; // er12
__m128i v10; // xmm1
__m128i v11; // xmm2
__int64 v12; // [rsp+0h] [rbp-268h] BYREF
__int64 v13; // [rsp+8h] [rbp-260h]
__m128i v14; // [rsp+10h] [rbp-258h] BYREF
__m128i v15; // [rsp+20h] [rbp-248h] BYREF
_DWORD v16[2]; // [rsp+30h] [rbp-238h] BYREF
char dest[256]; // [rsp+40h] [rbp-228h] BYREF
__int64 ptr; // [rsp+140h] [rbp-128h] BYREF
int v19; // [rsp+148h] [rbp-120h]
int v20; // [rsp+14Ch] [rbp-11Ch]
__int16 v21; // [rsp+150h] [rbp-118h]
__int16 v22; // [rsp+152h] [rbp-116h]
char v23[16]; // [rsp+154h] [rbp-114h] BYREF
int v24; // [rsp+164h] [rbp-104h]
__int128 v25[2]; // [rsp+168h] [rbp-100h] BYREF
int v26; // [rsp+188h] [rbp-E0h]
char v27; // [rsp+18Ch] [rbp-DCh]

strcpy((char *)v16, "ector");
v14 = _mm_load_si128((const __m128i *)&LC14);
v12 = 0x1000000LL;
v13 = 0LL;
v15 = _mm_load_si128((const __m128i *)&LC15);
if ( !s_fbs_prefix )
return;
v3 = 0;
fbs_close_file();
v4 = s_fbs_prefix;
if ( s_fbs_idx + 1 <= 999 )
v3 = s_fbs_idx + 1;
s_fbs_idx = v3;
v5 = strlen(s_fbs_prefix);
if ( (unsigned int)(v5 + 4) > 0xFF )
{
log_write(2LL, "FBS filename prefix too long");
s_fbs_prefix = 0LL;
return;
}
if ( s_join_sessions )
{
memcpy(dest, v4, v5 + 1);
}
else
{
sprintf(dest, "%s.%03d", v4, v3);
if ( !s_join_sessions )
goto LABEL_8;
}
if ( s_fbs_idx != 1 )
{
s_fbs_fp = fopen(dest, "a");
if ( !s_fbs_fp )
{
log_write(2LL, "Could not re-open FBS file for writing");
s_fbs_prefix = 0LL;
return;
}
log_write(3LL, "Re-opened FBS file for writing: %s", dest);
if ( s_fbs_fb_width != a1 || s_fbs_fb_height != a2 )
{
HIDWORD(v13) = 570425343;
LOWORD(v13) = __ROL2__(a1, 8);
WORD1(v13) = __ROL2__(a2, 8);
fbs_write_data(&v12, 0x10uLL);
}
goto LABEL_23;
}
LABEL_8:
s_fbs_fp = fopen(dest, "w");
if ( !s_fbs_fp )
{
log_write(2LL, "Could not open FBS file for writing");
s_fbs_prefix = 0LL;
return;
}
log_write(3LL, "Opened FBS file for writing: %s", dest);
gettimeofday(&s_fbs_start_time, &s_fbs_timezone);
if ( fwrite("FBS 001.000\n", 1uLL, 0xCuLL, s_fbs_fp) != 12 )
{
log_write(2LL, "Could not write FBS file header");
fclose(s_fbs_fp);
s_fbs_fp = 0LL;
return;
}
v19 = 171126832;
ptr = 0x2E33303020424652LL;
v20 = 0x1000000;
v21 = __ROL2__(a1, 8);
v22 = __ROL2__(a2, 8);
buf_put_pixfmt(v23, (unsigned int)((_DWORD)&g_screen_info + 4));
if ( s_join_sessions )
{
v8 = 77LL;
v10 = _mm_loadu_si128(&v14);
v24 = 620756992;
v11 = _mm_loadu_si128(&v15);
v26 = v16[0];
v25[0] = (__int128)v10;
v27 = v16[1];
v25[1] = (__int128)v11;
}
else
{
v6 = *((_DWORD *)&g_screen_info + 5);
BYTE2(v24) = 0;
v7 = (_DWORD *)*((_QWORD *)&g_screen_info + 3);
if ( v6 > 0xC0 )
v6 = 192;
LOWORD(v24) = 0;
HIBYTE(v24) = v6;
if ( v6 >= 8 )
{
*(_QWORD *)((char *)v25 + v6 - 8) = *(_QWORD *)((char *)v7 + v6 - 8);
qmemcpy(v25, v7, 8LL * ((v6 - 1) >> 3));
}
else if ( (v6 & 4) != 0 )
{
LODWORD(v25[0]) = *v7;
*(int *)((char *)&v24 + v6) = *(_DWORD *)((char *)v7 + v6 - 4);
}
else if ( v6 )
{
LOBYTE(v25[0]) = *(_BYTE *)v7;
if ( (v6 & 2) != 0 )
*(_WORD *)((char *)v25 + v6 - 2) = *(_WORD *)((char *)v7 + v6 - 2);
}
v8 = v6 + 40;
}
fbs_write_data(&ptr, v8);
LABEL_23:
if ( s_fbs_fp )
{
v9 = ((a2 + 15) >> 4) * ((a1 + 15) >> 4) + 4 * a2 * a1 + 12;
s_fbs_buffer = malloc(v9);
if ( s_fbs_buffer )
{
log_write(5LL, "Allocated buffer to cache FBS data, %d bytes", (unsigned int)v9);
s_fbs_buffer_ptr = s_fbs_buffer;
if ( s_fbs_fp )
{
s_fbs_fb_width = a1;
s_fbs_fb_height = a2;
}
}
else
{
log_write(2LL, "Memory allocation error, closing FBS file");
fclose(s_fbs_fp);
s_fbs_fp = 0LL;
}
}
}

canonical_decompiled_code:
void __fastcall func6(unsigned __int16 a1, unsigned __int16 a2)
{
unsigned int v3; // er12
char *v4; // r14
size_t v5; // rax
unsigned int v6; // eax
_DWORD *v7; // rsi
size_t v8; // rsi
int v9; // er12
__m128i v10; // xmm1
__m128i v11; // xmm2
__int64 v12; // [rsp+0h] [rbp-268h] BYREF
__int64 v13; // [rsp+8h] [rbp-260h]
__m128i v14; // [rsp+10h] [rbp-258h] BYREF
__m128i v15; // [rsp+20h] [rbp-248h] BYREF
_DWORD v16[2]; // [rsp+30h] [rbp-238h] BYREF
char dest[256]; // [rsp+40h] [rbp-228h] BYREF
__int64 ptr; // [rsp+140h] [rbp-128h] BYREF
int v19; // [rsp+148h] [rbp-120h]
int v20; // [rsp+14Ch] [rbp-11Ch]
__int16 v21; // [rsp+150h] [rbp-118h]
__int16 v22; // [rsp+152h] [rbp-116h]
char v23[16]; // [rsp+154h] [rbp-114h] BYREF
int v24; // [rsp+164h] [rbp-104h]
__int128 v25[2]; // [rsp+168h] [rbp-100h] BYREF
int v26; // [rsp+188h] [rbp-E0h]
char v27; // [rsp+18Ch] [rbp-DCh]

strcpy((char *)v16, "ector");
v14 = _mm_load_si128((const __m128i *)&LC14);
v12 = 0x1000000LL;
v13 = 0LL;
v15 = _mm_load_si128((const __m128i *)&LC15);
if ( !s_fbs_prefix )
return;
v3 = 0;
func3();
v4 = s_fbs_prefix;
if ( s_fbs_idx + 1 <= 999 )
v3 = s_fbs_idx + 1;
s_fbs_idx = v3;
v5 = strlen(s_fbs_prefix);
if ( (unsigned int)(v5 + 4) > 0xFF )
{
log_write(2LL, "FBS filename prefix too long");
s_fbs_prefix = 0LL;
return;
}
if ( s_join_sessions )
{
memcpy(dest, v4, v5 + 1);
}
else
{
sprintf(dest, "%s.%03d", v4, v3);
if ( !s_join_sessions )
goto LABEL_8;
}
if ( s_fbs_idx != 1 )
{
s_fbs_fp = fopen(dest, "a");
if ( !s_fbs_fp )
{
log_write(2LL, "Could not re-open FBS file for writing");
s_fbs_prefix = 0LL;
return;
}
log_write(3LL, "Re-opened FBS file for writing: %s", dest);
if ( s_fbs_fb_width != a1 || s_fbs_fb_height != a2 )
{
HIDWORD(v13) = 570425343;
LOWORD(v13) = __ROL2__(a1, 8);
WORD1(v13) = __ROL2__(a2, 8);
func4(&v12, 0x10uLL);
}
goto LABEL_23;
}
LABEL_8:
s_fbs_fp = fopen(dest, "w");
if ( !s_fbs_fp )
{
log_write(2LL, "Could not open FBS file for writing");
s_fbs_prefix = 0LL;
return;
}
log_write(3LL, "Opened FBS file for writing: %s", dest);
gettimeofday(&s_fbs_start_time, &s_fbs_timezone);
if ( fwrite("FBS 001.000\n", 1uLL, 0xCuLL, s_fbs_fp) != 12 )
{
log_write(2LL, "Could not write FBS file header");
fclose(s_fbs_fp);
s_fbs_fp = 0LL;
return;
}
v19 = 171126832;
ptr = 0x2E33303020424652LL;
v20 = 0x1000000;
v21 = __ROL2__(a1, 8);
v22 = __ROL2__(a2, 8);
buf_put_pixfmt(v23, (unsigned int)((_DWORD)&g_screen_info + 4));
if ( s_join_sessions )
{
v8 = 77LL;
v10 = _mm_loadu_si128(&v14);
v24 = 620756992;
v11 = _mm_loadu_si128(&v15);
v26 = v16[0];
v25[0] = (__int128)v10;
v27 = v16[1];
v25[1] = (__int128)v11;
}
else
{
v6 = *((_DWORD *)&g_screen_info + 5);
BYTE2(v24) = 0;
v7 = (_DWORD *)*((_QWORD *)&g_screen_info + 3);
if ( v6 > 0xC0 )
v6 = 192;
LOWORD(v24) = 0;
HIBYTE(v24) = v6;
if ( v6 >= 8 )
{
*(_QWORD *)((char *)v25 + v6 - 8) = *(_QWORD *)((char *)v7 + v6 - 8);
qmemcpy(v25, v7, 8LL * ((v6 - 1) >> 3));
}
else if ( (v6 & 4) != 0 )
{
LODWORD(v25[0]) = *v7;
*(int *)((char *)&v24 + v6) = *(_DWORD *)((char *)v7 + v6 - 4);
}
else if ( v6 )
{
LOBYTE(v25[0]) = *(_BYTE *)v7;
if ( (v6 & 2) != 0 )
*(_WORD *)((char *)v25 + v6 - 2) = *(_WORD *)((char *)v7 + v6 - 2);
}
v8 = v6 + 40;
}
func4(&ptr, v8);
LABEL_23:
if ( s_fbs_fp )
{
v9 = ((a2 + 15) >> 4) * ((a1 + 15) >> 4) + 4 * a2 * a1 + 12;
s_fbs_buffer = malloc(v9);
if ( s_fbs_buffer )
{
log_write(5LL, "Allocated buffer to cache FBS data, %d bytes", (unsigned int)v9);
s_fbs_buffer_ptr = s_fbs_buffer;
if ( s_fbs_fp )
{
s_fbs_fb_width = a1;
s_fbs_fb_height = a2;
}
}
else
{
log_write(2LL, "Memory allocation error, closing FBS file");
fclose(s_fbs_fp);
s_fbs_fp = 0LL;
}
}
}

original_code:
void fbs_open_file(u_int16_t fb_width, u_int16_t fb_height)
{
  int max_rect_size, w, h;
  u_int32_t len;
  char fname[256];
  char fbs_header[256];
  char fbs_desktop_name[] = "RFB session archived by VNC Reflector";
  u_int8_t fbs_newfbsize_msg[16] = {
    0, 0, 0, 1,
    0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0
  };
  if (s_fbs_prefix == ((void *)0))
    return;
  fbs_close_file();
  s_fbs_idx++;
  if (s_fbs_idx > 999)
    s_fbs_idx = 0;
  len = strlen(s_fbs_prefix);
  if (len + 4 > 255) {
    log_write(2, "FBS filename prefix too long");
    s_fbs_prefix = ((void *)0);
    return;
  }
  if (!s_join_sessions) {
    sprintf(fname, "%s.%03d", s_fbs_prefix, s_fbs_idx);
  } else {
    strcpy(fname, s_fbs_prefix);
  }
  if (!s_join_sessions || s_fbs_idx == 1) {
    s_fbs_fp = fopen(fname, "w");
    if (s_fbs_fp == ((void *)0)) {
      log_write(2, "Could not open FBS file for writing");
      s_fbs_prefix = ((void *)0);
      return;
    }
    log_write(3, "Opened FBS file for writing: %s", fname);
    gettimeofday(&s_fbs_start_time, &s_fbs_timezone);
    if (fwrite("FBS 001.000\n", 1, 12, s_fbs_fp) != 12) {
      log_write(2, "Could not write FBS file header");
      fclose(s_fbs_fp);
      s_fbs_fp = ((void *)0);
      return;
    }
    memcpy(fbs_header, "RFB 003.003\n", 12);
    { ((u_int8_t *)&fbs_header[12])[0] = (u_int8_t)(1 >> 24); ((u_int8_t *)&fbs_header[12])[1] = (u_int8_t)(1 >> 16); ((u_int8_t *)&fbs_header[12])[2] = (u_int8_t)(1 >> 8); ((u_int8_t *)&fbs_header[12])[3] = (u_int8_t)1; };
    { ((u_int8_t *)&fbs_header[16])[0] = (u_int8_t)(fb_width >> 8); ((u_int8_t *)&fbs_header[16])[1] = (u_int8_t)fb_width; };
    { ((u_int8_t *)&fbs_header[18])[0] = (u_int8_t)(fb_height >> 8); ((u_int8_t *)&fbs_header[18])[1] = (u_int8_t)fb_height; };
    buf_put_pixfmt(&fbs_header[20], &g_screen_info.pixformat);
    if (!s_join_sessions) {
      len = g_screen_info.name_length;
      if (len > 192)
        len = 192;
      { ((u_int8_t *)&fbs_header[36])[0] = (u_int8_t)(len >> 24); ((u_int8_t *)&fbs_header[36])[1] = (u_int8_t)(len >> 16); ((u_int8_t *)&fbs_header[36])[2] = (u_int8_t)(len >> 8); ((u_int8_t *)&fbs_header[36])[3] = (u_int8_t)len; };
      memcpy(&fbs_header[40], g_screen_info.name, len);
    } else {
      len = sizeof(fbs_desktop_name) - 1;
      { ((u_int8_t *)&fbs_header[36])[0] = (u_int8_t)(len >> 24); ((u_int8_t *)&fbs_header[36])[1] = (u_int8_t)(len >> 16); ((u_int8_t *)&fbs_header[36])[2] = (u_int8_t)(len >> 8); ((u_int8_t *)&fbs_header[36])[3] = (u_int8_t)len; };
      memcpy(&fbs_header[40], fbs_desktop_name, len);
    }
    fbs_write_data(fbs_header, 40 + len);
  } else {
    s_fbs_fp = fopen(fname, "a");
    if (s_fbs_fp == ((void *)0)) {
      log_write(2, "Could not re-open FBS file for writing");
      s_fbs_prefix = ((void *)0);
      return;
    }
    log_write(3, "Re-opened FBS file for writing: %s", fname);
    if (s_fbs_fb_width != fb_width || s_fbs_fb_height != fb_height) {
      { ((u_int8_t *)&fbs_newfbsize_msg[8])[0] = (u_int8_t)(fb_width >> 8); ((u_int8_t *)&fbs_newfbsize_msg[8])[1] = (u_int8_t)fb_width; };
      { ((u_int8_t *)&fbs_newfbsize_msg[10])[0] = (u_int8_t)(fb_height >> 8); ((u_int8_t *)&fbs_newfbsize_msg[10])[1] = (u_int8_t)fb_height; };
      { ((u_int8_t *)&fbs_newfbsize_msg[12])[0] = (u_int8_t)(0xFFFFFF21 >> 24); ((u_int8_t *)&fbs_newfbsize_msg[12])[1] = (u_int8_t)(0xFFFFFF21 >> 16); ((u_int8_t *)&fbs_newfbsize_msg[12])[2] = (u_int8_t)(0xFFFFFF21 >> 8); ((u_int8_t *)&fbs_newfbsize_msg[12])[3] = (u_int8_t)0xFFFFFF21; };
      fbs_write_data(fbs_newfbsize_msg, sizeof(fbs_newfbsize_msg));
    }
  }
  if (s_fbs_fp != ((void *)0)) {
    w = (int)fb_width;
    h = (int)fb_height;
    max_rect_size = 12 + (w * h * 4) + ((w + 15) / 16) * ((h + 15) / 16);
    s_fbs_buffer = malloc(max_rect_size);
    if (s_fbs_buffer == ((void *)0)) {
      log_write(2, "Memory allocation error, closing FBS file");
      fclose(s_fbs_fp);
      s_fbs_fp = ((void *)0);
    } else {
      log_write(5, "Allocated buffer to cache FBS data, %d bytes",
                max_rect_size);
      s_fbs_buffer_ptr = s_fbs_buffer;
    }
  }
  if (s_fbs_fp != ((void *)0)) {
    s_fbs_fb_width = fb_width;
    s_fbs_fb_height = fb_height;
  }
}

canonical_original_code:
void fbs_open_file(unsigned int fb_width, unsigned int fb_height)
{
  int max_rect_size; int w; int h;
  unsigned int len;
  char fname[256];
  char fbs_header[256];
  char fbs_desktop_name[] = "RFB session archived by VNC Reflector";
  unsigned int fbs_newfbsize_msg[16] = {
    0, 0, 0, 1,
    0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0
  };
  if (s_fbs_prefix == ((void *)0))
    return;
  fbs_close_file();
  s_fbs_idx++;
  if (s_fbs_idx > 999)
    s_fbs_idx = 0;
  len = strlen(s_fbs_prefix);
  if (len + 4 > 255) {
    log_write(2, "FBS filename prefix too long");
    s_fbs_prefix = ((void *)0);
    return;
  }
  if (!s_join_sessions) {
    sprintf(fname, "%s.%03d", s_fbs_prefix, s_fbs_idx);
  } else {
    strcpy(fname, s_fbs_prefix);
  }
  if (!s_join_sessions || s_fbs_idx == 1) {
    s_fbs_fp = fopen(fname, "w");
    if (s_fbs_fp == ((void *)0)) {
      log_write(2, "Could not open FBS file for writing");
      s_fbs_prefix = ((void *)0);
      return;
    }
    log_write(3, "Opened FBS file for writing: %s", fname);
    gettimeofday(&s_fbs_start_time, &s_fbs_timezone);
    if (fwrite("FBS 001.000\n", 1, 12, s_fbs_fp) != 12) {
      log_write(2, "Could not write FBS file header");
      fclose(s_fbs_fp);
      s_fbs_fp = ((void *)0);
      return;
    }
    memcpy(fbs_header, "RFB 003.003\n", 12);
    { ((unsigned int *)&fbs_header[12])[0] = (u_int8_t)(1 >> 24); ((unsigned int *)&fbs_header[12])[1] = (u_int8_t)(1 >> 16); ((unsigned int *)&fbs_header[12])[2] = (u_int8_t)(1 >> 8); ((unsigned int *)&fbs_header[12])[3] = (unsigned int)1; };
    { ((unsigned int *)&fbs_header[16])[0] = (u_int8_t)(fb_width >> 8); ((unsigned int *)&fbs_header[16])[1] = (unsigned int)fb_width; };
    { ((unsigned int *)&fbs_header[18])[0] = (u_int8_t)(fb_height >> 8); ((unsigned int *)&fbs_header[18])[1] = (unsigned int)fb_height; };
    buf_put_pixfmt(&fbs_header[20], &g_screen_info.pixformat);
    if (!s_join_sessions) {
      len = g_screen_info.name_length;
      if (len > 192)
        len = 192;
      { ((unsigned int *)&fbs_header[36])[0] = (u_int8_t)(len >> 24); ((unsigned int *)&fbs_header[36])[1] = (u_int8_t)(len >> 16); ((unsigned int *)&fbs_header[36])[2] = (u_int8_t)(len >> 8); ((unsigned int *)&fbs_header[36])[3] = (unsigned int)len; };
      memcpy(&fbs_header[40], g_screen_info.name, len);
    } else {
      len = sizeof(fbs_desktop_name) - 1;
      { ((unsigned int *)&fbs_header[36])[0] = (u_int8_t)(len >> 24); ((unsigned int *)&fbs_header[36])[1] = (u_int8_t)(len >> 16); ((unsigned int *)&fbs_header[36])[2] = (u_int8_t)(len >> 8); ((unsigned int *)&fbs_header[36])[3] = (unsigned int)len; };
      memcpy(&fbs_header[40], fbs_desktop_name, len);
    }
    fbs_write_data(fbs_header, 40 + len);
  } else {
    s_fbs_fp = fopen(fname, "a");
    if (s_fbs_fp == ((void *)0)) {
      log_write(2, "Could not re-open FBS file for writing");
      s_fbs_prefix = ((void *)0);
      return;
    }
    log_write(3, "Re-opened FBS file for writing: %s", fname);
    if (s_fbs_fb_width != fb_width || s_fbs_fb_height != fb_height) {
      { ((unsigned int *)&fbs_newfbsize_msg[8])[0] = (u_int8_t)(fb_width >> 8); ((unsigned int *)&fbs_newfbsize_msg[8])[1] = (unsigned int)fb_width; };
      { ((unsigned int *)&fbs_newfbsize_msg[10])[0] = (u_int8_t)(fb_height >> 8); ((unsigned int *)&fbs_newfbsize_msg[10])[1] = (unsigned int)fb_height; };
      { ((unsigned int *)&fbs_newfbsize_msg[12])[0] = (u_int8_t)(0xFFFFFF21 >> 24); ((unsigned int *)&fbs_newfbsize_msg[12])[1] = (u_int8_t)(0xFFFFFF21 >> 16); ((unsigned int *)&fbs_newfbsize_msg[12])[2] = (u_int8_t)(0xFFFFFF21 >> 8); ((unsigned int *)&fbs_newfbsize_msg[12])[3] = (unsigned int)0xFFFFFF21; };
      fbs_write_data(fbs_newfbsize_msg, sizeof(fbs_newfbsize_msg));
    }
  }
  if (s_fbs_fp != ((void *)0)) {
    w = (int)fb_width;
    h = (int)fb_height;
    max_rect_size = 12 + (w * h * 4) + ((w + 15) / 16) * ((h + 15) / 16);
    s_fbs_buffer = malloc(max_rect_size);
    if (s_fbs_buffer == ((void *)0)) {
      log_write(2, "Memory allocation error, closing FBS file");
      fclose(s_fbs_fp);
      s_fbs_fp = ((void *)0);
    } else {
      log_write(5, "Allocated buffer to cache FBS data, %d bytes",
                max_rect_size);
      s_fbs_buffer_ptr = s_fbs_buffer;
    }
  }
  if (s_fbs_fp != ((void *)0)) {
    s_fbs_fb_width = fb_width;
    s_fbs_fb_height = fb_height;
  }
}

variable_types: w int

variable_types: h int

variable_types:
len
unsigned int

variable_types:
fname
char [256]


repo: insidepower/cpptest

decompiled_code:
int __fastcall get_ll_total(__int64 a1, _DWORD *a2)
{
pthread_mutex_t *v3; // rdi

if ( !a1 )
_assert_fail("NULL!=pllBox", "ll.c", 0xDFu, "get_ll_total");
pthread_mutex_lock(*(pthread_mutex_t **)a1);
v3 = *(pthread_mutex_t **)a1;
*a2 = *(_DWORD *)(a1 + 32);
return pthread_mutex_unlock(v3);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, _DWORD *a2)
{
pthread_mutex_t *v3; // rdi

if ( !a1 )
_assert_fail("NULL!=pllBox", "ll.c", 0xDFu, "get_ll_total");
pthread_mutex_lock(*(pthread_mutex_t **)a1);
v3 = *(pthread_mutex_t **)a1;
*a2 = *(_DWORD *)(a1 + 32);
return pthread_mutex_unlock(v3);
}

original_code:
void get_ll_total(const llBox * pllBox, int * pTotal)
{
 ((void) sizeof ((((void *)0)!=pllBox) ? 1 : 0), __extension__ ({ if (((void *)0)!=pllBox) ; else __assert_fail ("NULL!=pllBox", "ll.c", 223, __extension__ __PRETTY_FUNCTION__); }));
 pthread_mutex_lock(pllBox->pMutex);
 *pTotal=pllBox->total;
 pthread_mutex_unlock(pllBox->pMutex);
}

canonical_original_code:
void get_ll_total(struct llBox_tag *pllBox, int *pTotal)
{
 ((void) sizeof ((((void *)0)!=pllBox) ? 1 : 0), __extension__ ({ if (((void *)0)!=pllBox) ; else __assert_fail ("NULL!=pllBox", "ll.c", 223, __extension__ __PRETTY_FUNCTION__); }));
 pthread_mutex_lock(pllBox->pMutex);
 *pTotal=pllBox->total;
 pthread_mutex_unlock(pllBox->pMutex);
}

variable_types: struct llBox_tag { 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; } *pMutex; struct ll_tag { struct ll_tag *pNext; void *pv; } *pHead; struct ll_tag *pTail; union sem_t { char __size[32]; long __align; } *pSem; int total; char *llBoxNm; char *llBoxNodeNm; } *

variable_types:
pTotal
int *

user_defined_types: struct llBox_tag { union pthread_mutex_t *pMutex; struct ll_tag *pHead; struct ll_tag *pTail; union sem_t *pSem; int total; char *llBoxNm; char *llBoxNodeNm; }

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; }


decompiled_code:
int __fastcall init_ll(__int64 *a1, const char *a2)
{
unsigned int v2; // er12
unsigned int v3; // ebp
sem_t *v4; // r12
unsigned int v5; // eax
pthread_mutex_t *v6; // r15
unsigned int v7; // eax
char *v8; // r13
size_t v9; // rax
unsigned int v10; // eax
__int64 v11; // rax

pthread_mutex_lock(&gpMutex);
if ( (int)(20 - strlen(a2)) <= 0 )
_assert_fail("strLenChk>0", "ll.c", 0x3Bu, "init_ll");
v2 = getpid();
v3 = pthread_self();
v4 = (sem_t *)crop_malloc(32LL, "pSem_llBox", 63LL, "ll.c", v3, v2);
if ( sem_init(v4, 0, 0) == -1 )
{
printf("[%10s:%-4d] Err! %s", "ll.c", 68LL, "semaphore init failed\n");
perror("Err! semaphore init failed");
}
else
{
v5 = getpid();
v6 = (pthread_mutex_t *)crop_malloc(40LL, "llMutex", 75LL, "ll.c", v3, v5);
pthread_mutex_init(v6, 0LL);
v7 = getpid();
v8 = (char *)crop_malloc(20LL, "nodeName", 82LL, "ll.c", v3, v7);
sprintf(v8, "%s_node", a2);
v9 = strlen(v8);
if ( v9 == 20 )
_assert_fail("(MAX_FILE_NM_LEN-strlen(strNodeNm)) > 0", "ll.c", 0x54u, "init_ll");
if ( 20 - (int)v9 <= 0 )
_assert_fail("strLenChk>0", "ll.c", 0x55u, "init_ll");
v10 = getpid();
v11 = crop_malloc(56LL, a2, 87LL, "ll.c", v3, v10);
*(_QWORD *)v11 = v6;
*(_QWORD *)(v11 + 8) = 0LL;
*(_QWORD *)(v11 + 16) = 0LL;
*(_QWORD *)(v11 + 24) = v4;
*(_DWORD *)(v11 + 32) = 0;
*(_QWORD *)(v11 + 40) = a2;
*(_QWORD *)(v11 + 48) = v8;
*a1 = v11;
}
return pthread_mutex_unlock(&gpMutex);
}

canonical_decompiled_code:
int __fastcall func0(__int64 *a1, const char *a2)
{
unsigned int v2; // er12
unsigned int v3; // ebp
sem_t *v4; // r12
unsigned int v5; // eax
pthread_mutex_t *v6; // r15
unsigned int v7; // eax
char *v8; // r13
size_t v9; // rax
unsigned int v10; // eax
__int64 v11; // rax

pthread_mutex_lock(&gpMutex);
if ( (int)(20 - strlen(a2)) <= 0 )
_assert_fail("strLenChk>0", "ll.c", 0x3Bu, "init_ll");
v2 = getpid();
v3 = pthread_self();
v4 = (sem_t *)crop_malloc(32LL, "pSem_llBox", 63LL, "ll.c", v3, v2);
if ( sem_init(v4, 0, 0) == -1 )
{
printf("[%10s:%-4d] Err! %s", "ll.c", 68LL, "semaphore init failed\n");
perror("Err! semaphore init failed");
}
else
{
v5 = getpid();
v6 = (pthread_mutex_t *)crop_malloc(40LL, "llMutex", 75LL, "ll.c", v3, v5);
pthread_mutex_init(v6, 0LL);
v7 = getpid();
v8 = (char *)crop_malloc(20LL, "nodeName", 82LL, "ll.c", v3, v7);
sprintf(v8, "%s_node", a2);
v9 = strlen(v8);
if ( v9 == 20 )
_assert_fail("(MAX_FILE_NM_LEN-strlen(strNodeNm)) > 0", "ll.c", 0x54u, "init_ll");
if ( 20 - (int)v9 <= 0 )
_assert_fail("strLenChk>0", "ll.c", 0x55u, "init_ll");
v10 = getpid();
v11 = crop_malloc(56LL, a2, 87LL, "ll.c", v3, v10);
*(_QWORD *)v11 = v6;
*(_QWORD *)(v11 + 8) = 0LL;
*(_QWORD *)(v11 + 16) = 0LL;
*(_QWORD *)(v11 + 24) = v4;
*(_DWORD *)(v11 + 32) = 0;
*(_QWORD *)(v11 + 40) = a2;
*(_QWORD *)(v11 + 48) = v8;
*a1 = v11;
}
return pthread_mutex_unlock(&gpMutex);
}

original_code:
void init_ll(llBox ** p_pllBox, const char * strllBoxNm)
{
 pthread_mutex_lock(&gpMutex);
 { int strLenChk=(20)-strlen(strllBoxNm); ((void) sizeof ((strLenChk>0) ? 1 : 0), __extension__ ({ if (strLenChk>0) ; else __assert_fail ("strLenChk>0", "ll.c", 59, __extension__ __PRETTY_FUNCTION__); }));};
 sem_t * pSem_llBox = (sem_t *) crop_malloc(sizeof(sem_t), "pSem_llBox", 63, "ll.c", pthread_self(),getpid());
 if(-1==sem_init(pSem_llBox, 0, 0)){
  p_pllBox=((void *)0);
  printf("[%10s:%-4d] Err! %s", "ll.c", 68, "semaphore init failed\n");
  perror("Err! semaphore init failed");
  goto exit_init_ll;
 }
 pthread_mutex_t * pMutex=((void *)0);
 pMutex = (pthread_mutex_t *) crop_malloc(sizeof(pthread_mutex_t), "llMutex", 75, "ll.c", pthread_self(),getpid());
 pthread_mutex_init(pMutex, ((void *)0));
 char * strNodeNm = (char *) crop_malloc((20), "nodeName", 82, "ll.c", pthread_self(),getpid());
 sprintf(strNodeNm, "%s_node", strllBoxNm);
 ((void) sizeof ((((20)-strlen(strNodeNm)) > 0) ? 1 : 0), __extension__ ({ if (((20)-strlen(strNodeNm)) > 0) ; else __assert_fail ("(MAX_FILE_NM_LEN-strlen(strNodeNm)) > 0", "ll.c", 84, __extension__ __PRETTY_FUNCTION__); }));
 { int strLenChk=(20)-strlen(strNodeNm); ((void) sizeof ((strLenChk>0) ? 1 : 0), __extension__ ({ if (strLenChk>0) ; else __assert_fail ("strLenChk>0", "ll.c", 85, __extension__ __PRETTY_FUNCTION__); }));};
 llBox * pllBox = (llBox *) crop_malloc(sizeof(llBox), strllBoxNm, 87, "ll.c", pthread_self(),getpid());
 pllBox->pMutex = pMutex;
 pllBox->pHead = ((void *)0);
 pllBox->pTail = pllBox->pHead;
 pllBox->pSem = pSem_llBox;
 pllBox->total = 0;
 pllBox->llBoxNm=strllBoxNm;
 pllBox->llBoxNodeNm=strNodeNm;
 *p_pllBox = pllBox;
exit_init_ll:
 pthread_mutex_unlock(&gpMutex);
}

canonical_original_code:
void init_ll(struct llBox_tag **p_pllBox, char *strllBoxNm)
{
 pthread_mutex_lock(&gpMutex);
 { int strLenChk = (20)-strlen(strllBoxNm); ((void) sizeof ((strLenChk>0) ? 1 : 0), __extension__ ({ if (strLenChk>0) ; else __assert_fail ("strLenChk>0", "ll.c", 59, __extension__ __PRETTY_FUNCTION__); }));};
 union sem_t *pSem_llBox = (sem_t *) crop_malloc(sizeof(sem_t), "pSem_llBox", 63, "ll.c", pthread_self(),getpid());
 if(-1==sem_init(pSem_llBox, 0, 0)){
  p_pllBox=((void *)0);
  printf("[%10s:%-4d] Err! %s", "ll.c", 68, "semaphore init failed\n");
  perror("Err! semaphore init failed");
  goto exit_init_ll;
 }
 union pthread_mutex_t *pMutex = ((void *)0);
 pMutex = (union pthread_mutex_t *) crop_malloc(sizeof(pthread_mutex_t), "llMutex", 75, "ll.c", pthread_self(),getpid());
 pthread_mutex_init(pMutex, ((void *)0));
 char *strNodeNm = (char *) crop_malloc((20), "nodeName", 82, "ll.c", pthread_self(),getpid());
 sprintf(strNodeNm, "%s_node", strllBoxNm);
 ((void) sizeof ((((20)-strlen(strNodeNm)) > 0) ? 1 : 0), __extension__ ({ if (((20)-strlen(strNodeNm)) > 0) ; else __assert_fail ("(MAX_FILE_NM_LEN-strlen(strNodeNm)) > 0", "ll.c", 84, __extension__ __PRETTY_FUNCTION__); }));
 { int strLenChk = (20)-strlen(strNodeNm); ((void) sizeof ((strLenChk>0) ? 1 : 0), __extension__ ({ if (strLenChk>0) ; else __assert_fail ("strLenChk>0", "ll.c", 85, __extension__ __PRETTY_FUNCTION__); }));};
 struct llBox_tag *pllBox = (llBox *) crop_malloc(sizeof(llBox), strllBoxNm, 87, "ll.c", pthread_self(),getpid());
 pllBox->pMutex = pMutex;
 pllBox->pHead = ((void *)0);
 pllBox->pTail = pllBox->pHead;
 pllBox->pSem = pSem_llBox;
 pllBox->total = 0;
 pllBox->llBoxNm=strllBoxNm;
 pllBox->llBoxNodeNm=strNodeNm;
 *p_pllBox = pllBox;
exit_init_ll:
 pthread_mutex_unlock(&gpMutex);
}

variable_types: struct llBox_tag { 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; } *pMutex; struct ll_tag { struct ll_tag *pNext; void *pv; } *pHead; struct ll_tag *pTail; union sem_t { char __size[32]; long __align; } *pSem; int total; char *llBoxNm; char *llBoxNodeNm; } **

variable_types:
strllBoxNm
char *

variable_types: strLenChk int

variable_types:
strNodeNm
char *


decompiled_code:
__int64 __fastcall add_ll(__int64 a1, _QWORD *a2)
{
__int64 v4; // rsi
unsigned int v5; // er12
unsigned int v6; // eax
_QWORD *v7; // rax
unsigned int v8; // er12
sem_t *v9; // rdi
unsigned int v11; // er12
unsigned int v12; // eax

if ( !a1 )
_assert_fail("NULL!=pllBox", "ll.c", 0x74u, "add_ll");
pthread_mutex_lock(*(pthread_mutex_t **)a1);
v4 = *(unsigned int *)(a1 + 32);
if ( (int)v4 > 19 )
{
v8 = -1;
printf("pllBox->total(%d)>MAX_TOTAL_LL_NODE, discarded\n", v4);
}
else
{
if ( (_DWORD)v4 )
{
v11 = getpid();
v12 = pthread_self();
v7 = (_QWORD *)crop_malloc(16LL, *(_QWORD *)(a1 + 48), 133LL, "ll.c", v12, v11);
**(_QWORD **)(a1 + 16) = v7;
*(_QWORD *)(a1 + 16) = v7;
}
else
{
if ( *(_QWORD *)(a1 + 8) )
_assert_fail("NULL==pllBox->pHead", "ll.c", 0x7Fu, "add_ll");
if ( *(_QWORD *)(a1 + 16) )
_assert_fail("NULL==pllBox->pTail", "ll.c", 0x80u, "add_ll");
v5 = getpid();
v6 = pthread_self();
v7 = (_QWORD *)crop_malloc(16LL, *(_QWORD *)(a1 + 48), 129LL, "ll.c", v6, v5);
*(_QWORD *)(a1 + 8) = v7;
*(_QWORD *)(a1 + 16) = v7;
}
*v7 = 0LL;
v8 = 0;
v7[1] = *a2;
*a2 = 0LL;
v9 = *(sem_t **)(a1 + 24);
++*(_DWORD *)(a1 + 32);
sem_post(v9);
}
pthread_mutex_unlock(*(pthread_mutex_t **)a1);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _QWORD *a2)
{
__int64 v4; // rsi
unsigned int v5; // er12
unsigned int v6; // eax
_QWORD *v7; // rax
unsigned int v8; // er12
sem_t *v9; // rdi
unsigned int v11; // er12
unsigned int v12; // eax

if ( !a1 )
_assert_fail("NULL!=pllBox", "ll.c", 0x74u, "add_ll");
pthread_mutex_lock(*(pthread_mutex_t **)a1);
v4 = *(unsigned int *)(a1 + 32);
if ( (int)v4 > 19 )
{
v8 = -1;
printf("pllBox->total(%d)>MAX_TOTAL_LL_NODE, discarded\n", v4);
}
else
{
if ( (_DWORD)v4 )
{
v11 = getpid();
v12 = pthread_self();
v7 = (_QWORD *)crop_malloc(16LL, *(_QWORD *)(a1 + 48), 133LL, "ll.c", v12, v11);
**(_QWORD **)(a1 + 16) = v7;
*(_QWORD *)(a1 + 16) = v7;
}
else
{
if ( *(_QWORD *)(a1 + 8) )
_assert_fail("NULL==pllBox->pHead", "ll.c", 0x7Fu, "add_ll");
if ( *(_QWORD *)(a1 + 16) )
_assert_fail("NULL==pllBox->pTail", "ll.c", 0x80u, "add_ll");
v5 = getpid();
v6 = pthread_self();
v7 = (_QWORD *)crop_malloc(16LL, *(_QWORD *)(a1 + 48), 129LL, "ll.c", v6, v5);
*(_QWORD *)(a1 + 8) = v7;
*(_QWORD *)(a1 + 16) = v7;
}
*v7 = 0LL;
v8 = 0;
v7[1] = *a2;
*a2 = 0LL;
v9 = *(sem_t **)(a1 + 24);
++*(_DWORD *)(a1 + 32);
sem_post(v9);
}
pthread_mutex_unlock(*(pthread_mutex_t **)a1);
return v8;
}

original_code:
int add_ll( llBox * pllBox, void **ppv)
{
 ((void) sizeof ((((void *)0)!=pllBox) ? 1 : 0), __extension__ ({ if (((void *)0)!=pllBox) ; else __assert_fail ("NULL!=pllBox", "ll.c", 116, __extension__ __PRETTY_FUNCTION__); }));
 pthread_mutex_lock(pllBox->pMutex);
 int status = (0);
 if(pllBox->total < (20)){
  ll * pllnew = ((void *)0);
  if(0==pllBox->total){
   ((void) sizeof ((((void *)0)==pllBox->pHead) ? 1 : 0), __extension__ ({ if (((void *)0)==pllBox->pHead) ; else __assert_fail ("NULL==pllBox->pHead", "ll.c", 127, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((((void *)0)==pllBox->pTail) ? 1 : 0), __extension__ ({ if (((void *)0)==pllBox->pTail) ; else __assert_fail ("NULL==pllBox->pTail", "ll.c", 128, __extension__ __PRETTY_FUNCTION__); }));
   pllnew = (ll *)crop_malloc(sizeof(ll), pllBox->llBoxNodeNm, 129, "ll.c", pthread_self(),getpid());
   pllBox->pHead = pllnew;
   pllBox->pTail = pllBox->pHead;
  }else{
   pllnew = (ll *) crop_malloc(sizeof(ll), pllBox->llBoxNodeNm, 133, "ll.c", pthread_self(),getpid());
   pllBox->pTail->pNext = pllnew;
   pllBox->pTail=pllnew;
  }
  pllnew->pNext=((void *)0);
  pllnew->pv=*ppv;
  *ppv=((void *)0);
  ++pllBox->total;
  sem_post(pllBox->pSem);
 }else{
  printf("pllBox->total(%d)>MAX_TOTAL_LL_NODE, discarded\n",pllBox->total);
  status = (-1);
 }
 pthread_mutex_unlock(pllBox->pMutex);
 return status;
}

canonical_original_code:
int add_ll(struct llBox_tag *pllBox, void **ppv)
{
 ((void) sizeof ((((void *)0)!=pllBox) ? 1 : 0), __extension__ ({ if (((void *)0)!=pllBox) ; else __assert_fail ("NULL!=pllBox", "ll.c", 116, __extension__ __PRETTY_FUNCTION__); }));
 pthread_mutex_lock(pllBox->pMutex);
 int status = (0);
 if(pllBox->total < (20)){
  struct ll_tag *pllnew = ((void *)0);
  if(0==pllBox->total){
   ((void) sizeof ((((void *)0)==pllBox->pHead) ? 1 : 0), __extension__ ({ if (((void *)0)==pllBox->pHead) ; else __assert_fail ("NULL==pllBox->pHead", "ll.c", 127, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((((void *)0)==pllBox->pTail) ? 1 : 0), __extension__ ({ if (((void *)0)==pllBox->pTail) ; else __assert_fail ("NULL==pllBox->pTail", "ll.c", 128, __extension__ __PRETTY_FUNCTION__); }));
   pllnew = (struct ll_tag *)crop_malloc(sizeof(ll), pllBox->llBoxNodeNm, 129, "ll.c", pthread_self(),getpid());
   pllBox->pHead = pllnew;
   pllBox->pTail = pllBox->pHead;
  }else{
   pllnew = (struct ll_tag *) crop_malloc(sizeof(ll), pllBox->llBoxNodeNm, 133, "ll.c", pthread_self(),getpid());
   pllBox->pTail->pNext = pllnew;
   pllBox->pTail=pllnew;
  }
  pllnew->pNext=((void *)0);
  pllnew->pv=*ppv;
  *ppv=((void *)0);
  ++pllBox->total;
  sem_post(pllBox->pSem);
 }else{
  printf("pllBox->total(%d)>MAX_TOTAL_LL_NODE, discarded\n",pllBox->total);
  status = (-1);
 }
 pthread_mutex_unlock(pllBox->pMutex);
 return status;
}

variable_types:
ppv
void **

variable_types: status int

variable_types: struct ll_tag { struct ll_tag *pNext; void *pv; } *

user_defined_types: union sem_t { char __size[32]; long __align; }

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


decompiled_code:
int __fastcall rm_ll(__int64 a1, _QWORD *a2)
{
int v3; // eax
_QWORD *v4; // rdi
int v5; // eax
__int64 v6; // rdx
__int64 v7; // rsi

if ( !a1 )
_assert_fail("NULL!=pllBox", "ll.c", 0xA9u, "rm_ll");
pthread_mutex_lock(*(pthread_mutex_t **)a1);
v3 = *(_DWORD *)(a1 + 32);
if ( v3 <= 0 )
_assert_fail("pllBox->total > 0", "ll.c", 0xACu, "rm_ll");
v4 = *(_QWORD **)(a1 + 8);
v5 = v3 - 1;
*a2 = v4[1];
v6 = **(_QWORD **)(a1 + 8);
*(_DWORD *)(a1 + 32) = v5;
*(_QWORD *)(a1 + 8) = v6;
if ( !v5 )
{
if ( v6 )
_assert_fail("NULL==pllBox->pHead", "ll.c", 0xB5u, "rm_ll");
*(_QWORD *)(a1 + 16) = 0LL;
}
*v4 = 0LL;
v7 = *(_QWORD *)(a1 + 48);
v4[1] = 0LL;
crop_free(v4, v7, 188LL, "ll.c");
return pthread_mutex_unlock(*(pthread_mutex_t **)a1);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, _QWORD *a2)
{
int v3; // eax
_QWORD *v4; // rdi
int v5; // eax
__int64 v6; // rdx
__int64 v7; // rsi

if ( !a1 )
_assert_fail("NULL!=pllBox", "ll.c", 0xA9u, "rm_ll");
pthread_mutex_lock(*(pthread_mutex_t **)a1);
v3 = *(_DWORD *)(a1 + 32);
if ( v3 <= 0 )
_assert_fail("pllBox->total > 0", "ll.c", 0xACu, "rm_ll");
v4 = *(_QWORD **)(a1 + 8);
v5 = v3 - 1;
*a2 = v4[1];
v6 = **(_QWORD **)(a1 + 8);
*(_DWORD *)(a1 + 32) = v5;
*(_QWORD *)(a1 + 8) = v6;
if ( !v5 )
{
if ( v6 )
_assert_fail("NULL==pllBox->pHead", "ll.c", 0xB5u, "rm_ll");
*(_QWORD *)(a1 + 16) = 0LL;
}
*v4 = 0LL;
v7 = *(_QWORD *)(a1 + 48);
v4[1] = 0LL;
crop_free(v4, v7, 188LL, "ll.c");
return pthread_mutex_unlock(*(pthread_mutex_t **)a1);
}

original_code:
void rm_ll( llBox * pllBox, void **pv)
{
 ((void) sizeof ((((void *)0)!=pllBox) ? 1 : 0), __extension__ ({ if (((void *)0)!=pllBox) ; else __assert_fail ("NULL!=pllBox", "ll.c", 169, __extension__ __PRETTY_FUNCTION__); }));
 pthread_mutex_lock((pllBox)->pMutex);
 ((void) sizeof ((pllBox->total > 0) ? 1 : 0), __extension__ ({ if (pllBox->total > 0) ; else __assert_fail ("pllBox->total > 0", "ll.c", 172, __extension__ __PRETTY_FUNCTION__); }));
 ll * pllToBeDel = pllBox->pHead;
 *pv = pllToBeDel->pv;
 pllBox->pHead = pllBox->pHead->pNext;
 --pllBox->total;
 if(0==pllBox->total){
  ((void) sizeof ((((void *)0)==pllBox->pHead) ? 1 : 0), __extension__ ({ if (((void *)0)==pllBox->pHead) ; else __assert_fail ("NULL==pllBox->pHead", "ll.c", 181, __extension__ __PRETTY_FUNCTION__); }));
  pllBox->pTail=((void *)0);
 }
 pllToBeDel->pNext=((void *)0);
 pllToBeDel->pv=((void *)0);
 crop_free(pllToBeDel, pllBox->llBoxNodeNm, 188, "ll.c");
 pthread_mutex_unlock(pllBox->pMutex);
}

canonical_original_code:
void rm_ll(struct llBox_tag *pllBox, void **pv)
{
 ((void) sizeof ((((void *)0)!=pllBox) ? 1 : 0), __extension__ ({ if (((void *)0)!=pllBox) ; else __assert_fail ("NULL!=pllBox", "ll.c", 169, __extension__ __PRETTY_FUNCTION__); }));
 pthread_mutex_lock((pllBox)->pMutex);
 ((void) sizeof ((pllBox->total > 0) ? 1 : 0), __extension__ ({ if (pllBox->total > 0) ; else __assert_fail ("pllBox->total > 0", "ll.c", 172, __extension__ __PRETTY_FUNCTION__); }));
 struct ll_tag *pllToBeDel = pllBox->pHead;
 *pv = pllToBeDel->pv;
 pllBox->pHead = pllBox->pHead->pNext;
 --pllBox->total;
 if(0==pllBox->total){
  ((void) sizeof ((((void *)0)==pllBox->pHead) ? 1 : 0), __extension__ ({ if (((void *)0)==pllBox->pHead) ; else __assert_fail ("NULL==pllBox->pHead", "ll.c", 181, __extension__ __PRETTY_FUNCTION__); }));
  pllBox->pTail=((void *)0);
 }
 pllToBeDel->pNext=((void *)0);
 pllToBeDel->pv=((void *)0);
 crop_free(pllToBeDel, pllBox->llBoxNodeNm, 188, "ll.c");
 pthread_mutex_unlock(pllBox->pMutex);
}

variable_types:
pv
void **

user_defined_types: struct ll_tag { struct ll_tag *pNext; void *pv; }


decompiled_code:
int __fastcall get_ll(__int64 a1, _QWORD *a2)
{
sem_wait(*(sem_t **)(a1 + 24));
return rm_ll(a1, a2);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, _QWORD *a2)
{
sem_wait(*(sem_t **)(a1 + 24));
return func2(a1, a2);
}

original_code:
void get_ll( llBox * pllBox, void **pv)
{
 sem_wait(pllBox->pSem);
 rm_ll(pllBox, pv);
}

canonical_original_code:
void get_ll(struct llBox_tag *pllBox, void **pv)
{
 sem_wait(pllBox->pSem);
 rm_ll(pllBox, pv);
}


decompiled_code:
int __fastcall print_ll(__int64 a1, void (__fastcall *a2)(__int64))
{
int v2; // eax
__int64 **v3; // rbx
unsigned int v4; // ebp

if ( !a1 )
_assert_fail("NULL!=pllBox", "ll.c", 0xF1u, "print_ll");
pthread_mutex_lock(*(pthread_mutex_t **)a1);
v2 = *(_DWORD *)(a1 + 32);
v3 = *(__int64 ***)(a1 + 8);
v4 = v2 - 1;
if ( v2 )
{
while ( 1 )
{
if ( !v3 )
_assert_fail("NULL!=pllTemp", "ll.c", 0xF7u, "print_ll");
printf("(%d):pllTemp->pv=%p\n", v4, v3[1]);
if ( a2 )
a2((__int64)v3[1]);
v3 = (__int64 **)*v3;
if ( !v4 )
break;
--v4;
}
}
if ( v3 )
_assert_fail("NULL==pllTemp", "ll.c", 0xFEu, "print_ll");
return pthread_mutex_unlock(*(pthread_mutex_t **)a1);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, void (__fastcall *a2)(__int64))
{
int v2; // eax
__int64 **v3; // rbx
unsigned int v4; // ebp

if ( !a1 )
_assert_fail("NULL!=pllBox", "ll.c", 0xF1u, "print_ll");
pthread_mutex_lock(*(pthread_mutex_t **)a1);
v2 = *(_DWORD *)(a1 + 32);
v3 = *(__int64 ***)(a1 + 8);
v4 = v2 - 1;
if ( v2 )
{
while ( 1 )
{
if ( !v3 )
_assert_fail("NULL!=pllTemp", "ll.c", 0xF7u, "print_ll");
printf("(%d):pllTemp->pv=%p\n", v4, v3[1]);
if ( a2 )
a2((__int64)v3[1]);
v3 = (__int64 **)*v3;
if ( !v4 )
break;
--v4;
}
}
if ( v3 )
_assert_fail("NULL==pllTemp", "ll.c", 0xFEu, "print_ll");
return pthread_mutex_unlock(*(pthread_mutex_t **)a1);
}

original_code:
void print_ll(const llBox * pllBox, void (*pvPrint)(void * pv))
{
 ((void) sizeof ((((void *)0)!=pllBox) ? 1 : 0), __extension__ ({ if (((void *)0)!=pllBox) ; else __assert_fail ("NULL!=pllBox", "ll.c", 241, __extension__ __PRETTY_FUNCTION__); }));
 pthread_mutex_lock(pllBox->pMutex);
 int count=pllBox->total;
 ll * pllTemp = pllBox->pHead;
 while(count--){
  ((void) sizeof ((((void *)0)!=pllTemp) ? 1 : 0), __extension__ ({ if (((void *)0)!=pllTemp) ; else __assert_fail ("NULL!=pllTemp", "ll.c", 247, __extension__ __PRETTY_FUNCTION__); }));
  printf("(%d):pllTemp->pv=%p\n", count, pllTemp->pv);
  if(((void *)0)!=pvPrint){
   pvPrint(pllTemp->pv);
  }
  pllTemp=pllTemp->pNext;
 }
 ((void) sizeof ((((void *)0)==pllTemp) ? 1 : 0), __extension__ ({ if (((void *)0)==pllTemp) ; else __assert_fail ("NULL==pllTemp", "ll.c", 254, __extension__ __PRETTY_FUNCTION__); }));
 pthread_mutex_unlock(pllBox->pMutex);
}

canonical_original_code:
void print_ll(struct llBox_tag *pllBox, void (*pvPrint)(void *pv))
{
 ((void) sizeof ((((void *)0)!=pllBox) ? 1 : 0), __extension__ ({ if (((void *)0)!=pllBox) ; else __assert_fail ("NULL!=pllBox", "ll.c", 241, __extension__ __PRETTY_FUNCTION__); }));
 pthread_mutex_lock(pllBox->pMutex);
 int count = pllBox->total;
 struct ll_tag *pllTemp = pllBox->pHead;
 while(count--){
  ((void) sizeof ((((void *)0)!=pllTemp) ? 1 : 0), __extension__ ({ if (((void *)0)!=pllTemp) ; else __assert_fail ("NULL!=pllTemp", "ll.c", 247, __extension__ __PRETTY_FUNCTION__); }));
  printf("(%d):pllTemp->pv=%p\n", count, pllTemp->pv);
  if(((void *)0)!=pvPrint){
   pvPrint(pllTemp->pv);
  }
  pllTemp=pllTemp->pNext;
 }
 ((void) sizeof ((((void *)0)==pllTemp) ? 1 : 0), __extension__ ({ if (((void *)0)==pllTemp) ; else __assert_fail ("NULL==pllTemp", "ll.c", 254, __extension__ __PRETTY_FUNCTION__); }));
 pthread_mutex_unlock(pllBox->pMutex);
}

variable_types:
pvPrint
void (*)(void *pv)

variable_types: count int


decompiled_code:
__int64 __fastcall end_ll(pthread_mutex_t ***a1)
{
pthread_mutex_t **v1; // rbp
pthread_mutex_t *v2; // r13
unsigned int v3; // ebx
unsigned int v4; // er12
int v5; // eax
char *v6; // r12
pthread_mutex_t *v7; // rdi

pthread_mutex_lock(**a1);
v1 = *a1;
v2 = **a1;
v3 = getpid();
v4 = pthread_self();
v5 = strlen((const char *)v1[5]);
v6 = (char *)crop_malloc((unsigned int)(v5 + 1), "boxToBeDelName", 274LL, "ll.c", v4, v3);
strcpy(v6, (const char *)v1[5]);
sem_destroy((sem_t *)v1[3]);
crop_free(v1[3], "pSem_llBox", 281LL, "ll.c");
v7 = v1[6];
*v1 = 0LL;
crop_free(v7, "nodeName", 286LL, "ll.c");
v1[5] = 0LL;
crop_free(v1, v6, 288LL, "ll.c");
crop_free(v6, "boxToBeDelName", 291LL, "ll.c");
pthread_mutex_unlock(v2);
pthread_mutex_destroy(v2);
return crop_free(v2, "llMutex", 298LL, "ll.c");
}

canonical_decompiled_code:
__int64 __fastcall func6(pthread_mutex_t ***a1)
{
pthread_mutex_t **v1; // rbp
pthread_mutex_t *v2; // r13
unsigned int v3; // ebx
unsigned int v4; // er12
int v5; // eax
char *v6; // r12
pthread_mutex_t *v7; // rdi

pthread_mutex_lock(**a1);
v1 = *a1;
v2 = **a1;
v3 = getpid();
v4 = pthread_self();
v5 = strlen((const char *)v1[5]);
v6 = (char *)crop_malloc((unsigned int)(v5 + 1), "boxToBeDelName", 274LL, "ll.c", v4, v3);
strcpy(v6, (const char *)v1[5]);
sem_destroy((sem_t *)v1[3]);
crop_free(v1[3], "pSem_llBox", 281LL, "ll.c");
v7 = v1[6];
*v1 = 0LL;
crop_free(v7, "nodeName", 286LL, "ll.c");
v1[5] = 0LL;
crop_free(v1, v6, 288LL, "ll.c");
crop_free(v6, "boxToBeDelName", 291LL, "ll.c");
pthread_mutex_unlock(v2);
pthread_mutex_destroy(v2);
return crop_free(v2, "llMutex", 298LL, "ll.c");
}

original_code:
void end_ll( llBox ** p_pllBox)
{
 pthread_mutex_lock((*p_pllBox)->pMutex);
 llBox * pllBox=*p_pllBox;
 char * str_name = ((void *)0);
 pthread_mutex_t * pMutexTemp = pllBox->pMutex;
 str_name = (char *) crop_malloc(strlen(pllBox->llBoxNm)+1, "boxToBeDelName", 274, "ll.c", pthread_self(),getpid());
 strcpy(str_name, pllBox->llBoxNm);
 sem_destroy(pllBox->pSem);
 crop_free(pllBox->pSem, "pSem_llBox", 281, "ll.c");
 pllBox->pMutex=((void *)0);
 crop_free(pllBox->llBoxNodeNm, "nodeName", 286, "ll.c");
 pllBox->llBoxNm=((void *)0);
 crop_free(pllBox, str_name, 288, "ll.c");
 pllBox=((void *)0);
 crop_free(str_name, "boxToBeDelName", 291, "ll.c");
 str_name=((void *)0);
 pthread_mutex_unlock(pMutexTemp);
 pthread_mutex_destroy(pMutexTemp);
 crop_free(pMutexTemp, "llMutex", 298, "ll.c");
 pMutexTemp=((void *)0);
}

canonical_original_code:
void end_ll(struct llBox_tag **p_pllBox)
{
 pthread_mutex_lock((*p_pllBox)->pMutex);
 struct llBox_tag *pllBox = *p_pllBox;
 char *str_name = ((void *)0);
 union pthread_mutex_t *pMutexTemp = pllBox->pMutex;
 str_name = (char *) crop_malloc(strlen(pllBox->llBoxNm)+1, "boxToBeDelName", 274, "ll.c", pthread_self(),getpid());
 strcpy(str_name, pllBox->llBoxNm);
 sem_destroy(pllBox->pSem);
 crop_free(pllBox->pSem, "pSem_llBox", 281, "ll.c");
 pllBox->pMutex=((void *)0);
 crop_free(pllBox->llBoxNodeNm, "nodeName", 286, "ll.c");
 pllBox->llBoxNm=((void *)0);
 crop_free(pllBox, str_name, 288, "ll.c");
 pllBox=((void *)0);
 crop_free(str_name, "boxToBeDelName", 291, "ll.c");
 str_name=((void *)0);
 pthread_mutex_unlock(pMutexTemp);
 pthread_mutex_destroy(pMutexTemp);
 crop_free(pMutexTemp, "llMutex", 298, "ll.c");
 pMutexTemp=((void *)0);
}

variable_types: 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; } *


decompiled_code:
void __fastcall __noreturn function1(void *a1)
{
while ( 1 )
{
puts("f1 try to get lock");
printf("f1 b4: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
pthread_mutex_lock(&mutex);
printf("f1 start: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
printf("Count is %d\n", (unsigned int)++count);
sleep(0xAu);
printf("f1 end: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
pthread_mutex_unlock(&mutex);
printf("f1 af: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
sleep(1u);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
while ( 1 )
{
puts("f1 try to get lock");
printf("f1 b4: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
pthread_mutex_lock(&mutex);
printf("f1 start: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
printf("Count is %d\n", (unsigned int)++count);
sleep(0xAu);
printf("f1 end: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
pthread_mutex_unlock(&mutex);
printf("f1 af: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
sleep(1u);
}
}

original_code:
void* function1( void* arg )
{
    int tmp = 0;
    while( 1 ) {
        printf("f1 try to get lock\n");
        printf("f1 b4: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        pthread_mutex_lock( &mutex );
        printf("f1 start: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        tmp = ++count;
        printf( "Count is %d\n", tmp );
 sleep(10);
        printf("f1 end: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        pthread_mutex_unlock( &mutex );
        printf("f1 af: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
 sleep(1);
    }
    return 0;
}

canonical_original_code:
void *function1(void *arg)
{
    int tmp = 0;
    while( 1 ) {
        printf("f1 try to get lock\n");
        printf("f1 b4: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        pthread_mutex_lock( &mutex );
        printf("f1 start: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        tmp = ++count;
        printf( "Count is %d\n", tmp );
 sleep(10);
        printf("f1 end: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        pthread_mutex_unlock( &mutex );
        printf("f1 af: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
 sleep(1);
    }
    return 0;
}

variable_types:
arg
void *

variable_types: tmp int

return_type: void *


decompiled_code:
void __fastcall __noreturn function2(void *a1)
{
while ( 1 )
{
sleep(1u);
puts("f2 try to get lock");
printf("f2 b4: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
pthread_mutex_lock(&mutex);
printf("f2 start: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
printf("** Count is %d\n", (unsigned int)--count);
printf("f2 end: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
pthread_mutex_unlock(&mutex);
printf("f2 af: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
sleep(1u);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *a1)
{
while ( 1 )
{
sleep(1u);
puts("f2 try to get lock");
printf("f2 b4: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
pthread_mutex_lock(&mutex);
printf("f2 start: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
printf("** Count is %d\n", (unsigned int)--count);
printf("f2 end: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
pthread_mutex_unlock(&mutex);
printf("f2 af: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
sleep(1u);
}
}

original_code:
void* function2( void* arg )
{
    int tmp = 0;
    while( 1 ) {
    sleep(1);
        printf("f2 try to get lock\n");
 printf("f2 b4: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        pthread_mutex_lock( &mutex );
        printf("f2 start: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        tmp = --count;
        printf( "** Count is %d\n", tmp );
        printf("f2 end: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        pthread_mutex_unlock( &mutex );
        printf("f2 af: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
 sleep(1);
    }
    return 0;
}

canonical_original_code:
void *function2(void *arg)
{
    int tmp = 0;
    while( 1 ) {
    sleep(1);
        printf("f2 try to get lock\n");
 printf("f2 b4: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        pthread_mutex_lock( &mutex );
        printf("f2 start: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        tmp = --count;
        printf( "** Count is %d\n", tmp );
        printf("f2 end: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        pthread_mutex_unlock( &mutex );
        printf("f2 af: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
 sleep(1);
    }
    return 0;
}


decompiled_code:
void __fastcall __noreturn function3(void *a1)
{
while ( 1 )
{
sleep(3u);
puts("f3 try to get lock");
printf("f3 b4: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
pthread_mutex_lock(&mutex);
printf("f3 start: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
printf("** Count is %d\n", (unsigned int)--count);
printf("f3 end: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
pthread_mutex_unlock(&mutex);
printf("f3 af: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
sleep(1u);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func9(void *a1)
{
while ( 1 )
{
sleep(3u);
puts("f3 try to get lock");
printf("f3 b4: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
pthread_mutex_lock(&mutex);
printf("f3 start: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
printf("** Count is %d\n", (unsigned int)--count);
printf("f3 end: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
pthread_mutex_unlock(&mutex);
printf("f3 af: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
sleep(1u);
}
}

original_code:
void* function3( void* arg )
{
    int tmp = 0;
    while( 1 ) {
    sleep(3);
        printf("f3 try to get lock\n");
 printf("f3 b4: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        pthread_mutex_lock( &mutex );
        printf("f3 start: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        tmp = --count;
        printf( "** Count is %d\n", tmp );
        printf("f3 end: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        pthread_mutex_unlock( &mutex );
        printf("f3 af: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
 sleep(1);
    }
    return 0;
}

canonical_original_code:
void *function3(void *arg)
{
    int tmp = 0;
    while( 1 ) {
    sleep(3);
        printf("f3 try to get lock\n");
 printf("f3 b4: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        pthread_mutex_lock( &mutex );
        printf("f3 start: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        tmp = --count;
        printf( "** Count is %d\n", tmp );
        printf("f3 end: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        pthread_mutex_unlock( &mutex );
        printf("f3 af: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
 sleep(1);
    }
    return 0;
}


decompiled_code:
void __fastcall __noreturn function4(void *a1)
{
while ( 1 )
{
sleep(4u);
puts("f4 try to get lock");
printf("f4 b4: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
pthread_mutex_lock(&mutex);
printf("f4 start: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
printf("** Count is %d\n", (unsigned int)--count);
printf("f4 end: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
pthread_mutex_unlock(&mutex);
printf("f4 af: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
sleep(1u);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func10(void *a1)
{
while ( 1 )
{
sleep(4u);
puts("f4 try to get lock");
printf("f4 b4: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
pthread_mutex_lock(&mutex);
printf("f4 start: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
printf("** Count is %d\n", (unsigned int)--count);
printf("f4 end: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
pthread_mutex_unlock(&mutex);
printf("f4 af: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__count, (unsigned int)mutex.__lock);
sleep(1u);
}
}

original_code:
void* function4( void* arg )
{
    int tmp = 0;
    while( 1 ) {
    sleep(4);
        printf("f4 try to get lock\n");
 printf("f4 b4: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        pthread_mutex_lock( &mutex );
        printf("f4 start: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        tmp = --count;
        printf( "** Count is %d\n", tmp );
        printf("f4 end: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        pthread_mutex_unlock( &mutex );
        printf("f4 af: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
 sleep(1);
    }
    return 0;
}

canonical_original_code:
void *function4(void *arg)
{
    int tmp = 0;
    while( 1 ) {
    sleep(4);
        printf("f4 try to get lock\n");
 printf("f4 b4: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        pthread_mutex_lock( &mutex );
        printf("f4 start: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        tmp = --count;
        printf( "** Count is %d\n", tmp );
        printf("f4 end: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
        pthread_mutex_unlock( &mutex );
        printf("f4 af: mutex.__count(%d), mutex.__lock(%d)\n", mutex.__data.__count, mutex.__data.__lock);
 sleep(1);
    }
    return 0;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t v4; // [rsp+0h] [rbp-28h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-20h] BYREF
pthread_t v6; // [rsp+10h] [rbp-18h] BYREF
pthread_t v7[2]; // [rsp+18h] [rbp-10h] BYREF

pthread_create(&v4, 0LL, function1, 0LL);
pthread_create(&newthread, 0LL, function2, 0LL);
pthread_create(&v6, 0LL, function3, 0LL);
pthread_create(v7, 0LL, function4, 0LL);
sleep(0x3Cu);
return 0;
}

original_code:
int main( void )
{
   pthread_t thread1, thread2, thread3, thread4;
    pthread_create( &thread1, ((void *)0), &function1, ((void *)0) );
    pthread_create( &thread2, ((void *)0), &function2, ((void *)0) );
    pthread_create( &thread3, ((void *)0), &function3, ((void *)0) );
    pthread_create( &thread4, ((void *)0), &function4, ((void *)0) );
    sleep( 60 );
    return 0;
}

canonical_original_code:
int main()
{
   unsigned long thread1; unsigned long thread2; unsigned long thread3; unsigned long thread4;
    pthread_create( &thread1, ((void *)0), &function1, ((void *)0) );
    pthread_create( &thread2, ((void *)0), &function2, ((void *)0) );
    pthread_create( &thread3, ((void *)0), &function3, ((void *)0) );
    pthread_create( &thread4, ((void *)0), &function4, ((void *)0) );
    sleep( 60 );
    return 0;
}


decompiled_code:
int __fastcall print_userData(__int64 a1)
{
return printf("name=%s, seq=%d\n", (const char *)a1, *(unsigned int *)(a1 + 12));
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
return printf("name=%s, seq=%d\n", (const char *)a1, *(unsigned int *)(a1 + 12));
}

original_code:
void print_userData(void * pv)
{
 tdUserData * ptd = (tdUserData *) pv;
 printf("name=%s, seq=%d\n", ptd->name, ptd->seq);
}

canonical_original_code:
void print_userData(void *pv)
{
 struct userData *ptd = (tdUserData *) pv;
 printf("name=%s, seq=%d\n", ptd->name, ptd->seq);
}

variable_types:
pv
void *

variable_types: struct userData { char name[10]; int seq; } *


initGppMac

decompiled_code:
__int64 initGppMac()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 0LL;
}

original_code:
int initGppMac(void)
{
 return 0;
}

canonical_original_code:
int initGppMac()
{
 return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
gui_reset = 0;
puts("Application terminated");
return 0;
}

original_code:
int main(void)
{
 if((-100)==initGppMac())
 {
 }
 do {
  gui_reset=0;
 }while(gui_reset);
 printf("Application terminated\n");
 return 0;
}

canonical_original_code:
int main()
{
 if((-100)==initGppMac())
 {
 }
 do {
  gui_reset=0;
 }while(gui_reset);
 printf("Application terminated\n");
 return 0;
}


loglvresolv

repo: inste/qaoed

decompiled_code:
__int64 __fastcall loglvresolv(char *s1)
{
__int64 v1; // rbx

v1 = 0LL;
while ( strcasecmp(s1, (&loglevel)[2 * v1]) )
{
if ( ++v1 == 5 )
{
printf("Unknown loglevel: %s\n", s1);
return 0xFFFFFFFFLL;
}
}
return LODWORD((&loglevel)[2 * (int)v1 + 1]);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
__int64 v1; // rbx

v1 = 0LL;
while ( strcasecmp(s1, (&loglevel)[2 * v1]) )
{
if ( ++v1 == 5 )
{
printf("Unknown loglevel: %s\n", s1);
return 0xFFFFFFFFLL;
}
}
return LODWORD((&loglevel)[2 * (int)v1 + 1]);
}

original_code:
int loglvresolv(char *str)
{
  int i;
  for( i = 0; i < (sizeof(loglevel)/sizeof(struct level)); i++)
    if(strcasecmp(str,loglevel[i].str) == 0)
      return(loglevel[i].lvl);
   printf("Unknown loglevel: %s\n",str);
   return(-1);
}

variable_types:
str
char *

variable_types: i int


syslgresolv

decompiled_code:
__int64 __fastcall syslgresolv(char *s1)
{
__int64 i; // rbx

for ( i = 0LL; i != 19; ++i )
{
if ( !strcasecmp(s1, (&sysloglevel)[2 * i]) )
return LODWORD((&sysloglevel)[2 * (int)i + 1]);
}
printf("Unknown syslog-level: %s\n", s1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
__int64 i; // rbx

for ( i = 0LL; i != 19; ++i )
{
if ( !strcasecmp(s1, (&sysloglevel)[2 * i]) )
return LODWORD((&sysloglevel)[2 * (int)i + 1]);
}
printf("Unknown syslog-level: %s\n", s1);
return 0xFFFFFFFFLL;
}

original_code:
int syslgresolv(char *str)
{
  int i;
  for( i = 0; i < (sizeof(sysloglevel)/sizeof(struct level)); i++)
    if(strcasecmp(str,sysloglevel[i].str) == 0)
      return(sysloglevel[i].lvl);
  printf("Unknown syslog-level: %s\n",str);
  return(-1);
}


getifindex

decompiled_code:
__int64 __fastcall getifindex(int fd, const char *a2)
{
char dest[16]; // [rsp+10h] [rbp-38h] BYREF
unsigned int v4; // [rsp+20h] [rbp-28h]

strcpy(dest, a2);
if ( ioctl(fd, 0x8933uLL, dest) != -1 )
return v4;
perror("getifindex");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, const char *a2)
{
char dest[16]; // [rsp+10h] [rbp-38h] BYREF
unsigned int v4; // [rsp+20h] [rbp-28h]

strcpy(dest, a2);
if ( ioctl(fd, 0x8933uLL, dest) != -1 )
return v4;
perror("getifindex");
return 0xFFFFFFFFLL;
}

original_code:
int getifindex(int sock,char *ifname)
{
   struct ifreq ifr;
   strcpy(ifr.ifr_ifrn.ifrn_name,ifname);
   if(ioctl(sock,0x8933,&ifr) == -1)
     {
 perror("getifindex");
 return(-1);
     }
   else
 return(ifr.ifr_ifru.ifru_ivalue);
}

canonical_original_code:
int getifindex(int sock, char *ifname)
{
   struct ifreq ifr;
   strcpy(ifr.ifr_ifrn.ifrn_name,ifname);
   if(ioctl(sock,0x8933,&ifr) == -1)
     {
 perror("getifindex");
 return(-1);
     }
   else
 return(ifr.ifr_ifru.ifru_ivalue);
}

variable_types: sock 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; }

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; }


decompiled_code:
int __fastcall arch_getsize(int a1, __int64 a2)
{
return ioctl(a1, 0x1260uLL, a2);
}

canonical_decompiled_code:
int __fastcall func0(int a1, __int64 a2)
{
return ioctl(a1, 0x1260uLL, a2);
}

variable_types: fd int

variable_types:
mediasize
void *

variable_types: error int


decompiled_code:
__int64 __fastcall qaoed_pktdestroy(void *ptr)
{
pthread_mutex_t *v1; // r12
int v2; // eax
__int64 result; // rax

v1 = (pthread_mutex_t *)((char *)ptr + 16);
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 16));
v2 = *((_DWORD *)ptr + 2) - 1;
*((_DWORD *)ptr + 2) = v2;
if ( v2 > 0 )
{
pthread_mutex_unlock(v1);
result = 1LL;
}
else
{
if ( *(_QWORD *)ptr )
free(*(void **)ptr);
pthread_mutex_unlock(v1);
pthread_mutex_destroy(v1);
free(ptr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
pthread_mutex_t *v1; // r12
int v2; // eax
__int64 result; // rax

v1 = (pthread_mutex_t *)((char *)ptr + 16);
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 16));
v2 = *((_DWORD *)ptr + 2) - 1;
*((_DWORD *)ptr + 2) = v2;
if ( v2 > 0 )
{
pthread_mutex_unlock(v1);
result = 1LL;
}
else
{
if ( *(_QWORD *)ptr )
free(*(void **)ptr);
pthread_mutex_unlock(v1);
pthread_mutex_destroy(v1);
free(ptr);
result = 0LL;
}
return result;
}

original_code:
int qaoed_pktdestroy(struct pkt *packet)
{
  pthread_mutex_lock(&packet->pktlock);
  packet->refcount--;
   if(packet->refcount < 1)
     {
 if(packet->raw != ((void *)0))
   free(packet->raw);
 pthread_mutex_unlock(&packet->pktlock);
 pthread_mutex_destroy(&packet->pktlock);
 free(packet);
 return(0);
     }
   else
     {
       pthread_mutex_unlock(&packet->pktlock);
       return(1);
     }
}

variable_types: struct pkt { void *raw; int refcount; 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; } pktlock; } *

user_defined_types: struct pkt { void *raw; int refcount; union pthread_mutex_t pktlock; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax

v3 = cpu_count(argc, argv, envp);
printf("%ld processors present\n", v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax

v3 = func7(argc, argv, envp);
printf("%ld processors present\n", v3);
return 0;
}

original_code:
int main()
{
        long numb_cores = -1;
        numb_cores = cpu_count();
        printf("%ld processors present\n",numb_cores);
}


decompiled_code:
__int64 cpu_count()
{
__int64 result; // rax
int *v1; // rax
char *v2; // rax

result = sysconf(84);
if ( result <= 0 )
{
v1 = __errno_location();
v2 = strerror(*v1);
fprintf(stderr, "Could not determine number of CPUs online:\n%s\n", v2);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax
int *v1; // rax
char *v2; // rax

result = sysconf(84);
if ( result <= 0 )
{
v1 = __errno_location();
v2 = strerror(*v1);
fprintf(stderr, "Could not determine number of CPUs online:\n%s\n", v2);
exit(1);
}
return result;
}

original_code:
long cpu_count() {
        long nprocs = -1;
        long nprocs_max = -1;
        nprocs = sysconf(_SC_NPROCESSORS_ONLN);
        if (nprocs < 1)
          {
            fprintf(stderr, "Could not determine number of CPUs online:\n%s\n", strerror ((*__errno_location ())));
            exit (1);
          }
        return (nprocs);
}

variable_types: nprocs long

return_type: long


die

repo: interfector/llmne

decompiled_code:
void __fastcall __noreturn die(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void
die(char* d)
{
 perror( d );
 exit(1);
}

canonical_original_code:
void die(char *d)
{
 perror( d );
 exit(1);
}

variable_types:
d
char *


decompiled_code:
__suseconds_t emtv3d_timer_us()
{
struct timeval tv; // [rsp+0h] [rbp-10h] BYREF

gettimeofday(&tv, 0LL);
return tv.tv_usec + 1000000 * tv.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func0()
{
struct timeval tv; // [rsp+0h] [rbp-10h] BYREF

gettimeofday(&tv, 0LL);
return tv.tv_usec + 1000000 * tv.tv_sec;
}

original_code:
int64_t emtv3d_timer_us(void)
{
 struct timeval tv_date;
 gettimeofday(&tv_date, ((void *)0));
 return ((int64_t) tv_date.tv_sec * 1000000 + (int64_t) tv_date.tv_usec);
}

canonical_original_code:
long emtv3d_timer_us()
{
 struct timeval tv_date;
 gettimeofday(&tv_date, ((void *)0));
 return ((long) tv_date.tv_sec * 1000000 + (long) tv_date.tv_usec);
}

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


decompiled_code:
__time_t emtv3d_timer_s()
{
struct timeval tv; // [rsp+0h] [rbp-10h] BYREF

gettimeofday(&tv, 0LL);
return tv.tv_sec;
}

canonical_decompiled_code:
__time_t func1()
{
struct timeval tv; // [rsp+0h] [rbp-10h] BYREF

gettimeofday(&tv, 0LL);
return tv.tv_sec;
}

original_code:
int64_t emtv3d_timer_s(void)
{
 struct timeval tv_date;
 gettimeofday(&tv_date, ((void *)0));
 return ((int64_t) tv_date.tv_sec);
}

canonical_original_code:
long emtv3d_timer_s()
{
 struct timeval tv_date;
 gettimeofday(&tv_date, ((void *)0));
 return ((long) tv_date.tv_sec);
}

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


CompareVector

decompiled_code:
int __fastcall CompareVector(__int64 a1, __int64 a2, int a3)
{
double v3; // xmm2_8
__int64 v4; // r12
__int64 i; // rbx
float v7; // [rsp+0h] [rbp-50h]
float v8; // [rsp+4h] [rbp-4Ch]
float v9; // [rsp+Ch] [rbp-44h]
double v10; // [rsp+28h] [rbp-28h]

if ( a3 <= 0 )
{
v10 = 0.0;
}
else
{
v9 = 0.0;
v3 = *(double *)&LC9;
v4 = a3;
for ( i = 0LL; i != v4; ++i )
{
v7 = *(float *)(a1 + 4 * i);
v8 = *(float *)(a2 + 4 * i);
if ( (float)(v7 - v8) > v3 )
{
fprintf(
stderr,
"%d, data0[%d] = %f data1[%d]= %f \n",
(unsigned int)i,
(unsigned int)i,
v7,
(unsigned int)i,
v8);
v3 = *(double *)&LC9;
}
v9 = v9 + (float)(v7 - v8);
}
v10 = v9;
}
return fprintf(stderr, "diffall = %f\n", v10);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2, int a3)
{
double v3; // xmm2_8
__int64 v4; // r12
__int64 i; // rbx
float v7; // [rsp+0h] [rbp-50h]
float v8; // [rsp+4h] [rbp-4Ch]
float v9; // [rsp+Ch] [rbp-44h]
double v10; // [rsp+28h] [rbp-28h]

if ( a3 <= 0 )
{
v10 = 0.0;
}
else
{
v9 = 0.0;
v3 = *(double *)&LC9;
v4 = a3;
for ( i = 0LL; i != v4; ++i )
{
v7 = *(float *)(a1 + 4 * i);
v8 = *(float *)(a2 + 4 * i);
if ( (float)(v7 - v8) > v3 )
{
fprintf(
stderr,
"%d, data0[%d] = %f data1[%d]= %f \n",
(unsigned int)i,
(unsigned int)i,
v7,
(unsigned int)i,
v8);
v3 = *(double *)&LC9;
}
v9 = v9 + (float)(v7 - v8);
}
v10 = v9;
}
return fprintf(stderr, "diffall = %f\n", v10);
}

original_code:
void CompareVector(float * data0, float * data1, int size)
{
 int i;
 float diff = 0.0;
 float diffall = 0.0;
 for (i = 0; i < size; i++) {
  diff = data0[i] - data1[i];
  if (diff > 0.1)
   fprintf(stderr, "%d, data0[%d] = %f data1[%d]= %f \n",
    i, i, data0[i], i, data1[i]);
  diffall += diff;
 }
 fprintf(stderr, "diffall = %f\n", diffall);
}

canonical_original_code:
void CompareVector(float *data0, float *data1, int size)
{
 int i;
 float diff = 0.0;
 float diffall = 0.0;
 for (i = 0; i < size; i++) {
  diff = data0[i] - data1[i];
  if (diff > 0.1)
   fprintf(stderr, "%d, data0[%d] = %f data1[%d]= %f \n",
    i, i, data0[i], i, data1[i]);
  diffall += diff;
 }
 fprintf(stderr, "diffall = %f\n", diffall);
}

variable_types: size int

variable_types: diff float

variable_types: diffall float


help

decompiled_code:
__int64 help()
{
puts("./emtv3d -i inputfilename -o outputfilename");
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
puts("./emtv3d -i inputfilename -o outputfilename");
return 0LL;
}

original_code:
int help()
{
 printf("./emtv3d -i inputfilename -o outputfilename\n");
 return 0;
}


configure

decompiled_code:
__int64 __fastcall configure(int argc, char **argv)
{
int v2; // eax
__int64 result; // rax
char shortopts[27]; // [rsp+5h] [rbp-1Bh] BYREF

strcpy(shortopts, "?vh:i:o:b:");
while ( 2 )
{
v2 = getopt(argc, argv, shortopts);
if ( v2 == -1 )
return 0LL;
if ( v2 == 63 )
{
LABEL_6:
help();
result = 0xFFFFFFFFLL;
}
else
{
switch ( v2 )
{
case 'b':
batch_id = atoi(optarg);
printf("papi batch id is : %d \n", (unsigned int)batch_id);
continue;
case 'h':
case 'v':
goto LABEL_6;
case 'i':
strcpy(inputfilename, optarg);
printf("input filename : %s \n", inputfilename);
continue;
case 'o':
strcpy(outputfilename, optarg);
printf("output filename : %s \n", outputfilename);
continue;
default:
puts("Unknow option detection");
result = 0LL;
break;
}
}
return result;
}
}

canonical_decompiled_code:
__int64 __fastcall func7(int argc, char **argv)
{
int v2; // eax
__int64 result; // rax
char shortopts[27]; // [rsp+5h] [rbp-1Bh] BYREF

strcpy(shortopts, "?vh:i:o:b:");
while ( 2 )
{
v2 = getopt(argc, argv, shortopts);
if ( v2 == -1 )
return 0LL;
if ( v2 == 63 )
{
LABEL_6:
func6();
result = 0xFFFFFFFFLL;
}
else
{
switch ( v2 )
{
case 'b':
batch_id = atoi(optarg);
printf("papi batch id is : %d \n", (unsigned int)batch_id);
continue;
case 'h':
case 'v':
goto LABEL_6;
case 'i':
strcpy(inputfilename, optarg);
printf("input filename : %s \n", inputfilename);
continue;
case 'o':
strcpy(outputfilename, optarg);
printf("output filename : %s \n", outputfilename);
continue;
default:
puts("Unknow option detection");
result = 0LL;
break;
}
}
return result;
}
}

original_code:
int configure(int argc, char *argv[])
{
 char option_def[] = "?vh:i:o:b:";
 int ch;
 for (;;) {
  ch = getopt(argc, argv, option_def);
  if (ch == -1)
   break;
  switch (ch) {
  case '?':
  case 'v':
  case 'h':
   help();
   return -1;
  case 'i':
   strcpy(inputfilename, optarg);
   printf("input filename : %s \n", inputfilename);
   break;
  case 'o':
   strcpy(outputfilename, optarg);
   printf("output filename : %s \n", outputfilename);
   break;
  case 'b':
   batch_id = atoi(optarg);
   printf("papi batch id is : %d \n", batch_id);
   break;
  default:
   printf("Unknow option detection\n");
   return 0;
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ch int