decompiled_code:
void __fastcall fbs_open_file(unsigned __int16 a1, unsigned __int16 a2)
{
int v2; // eax
const char *v3; // r12
unsigned int v4; // eax
_DWORD *v5; // rdx
int v6; // er12
__int64 v7; // [rsp+0h] [rbp-258h] BYREF
__int64 v8; // [rsp+8h] [rbp-250h]
__m128i v9[3]; // [rsp+10h] [rbp-248h] BYREF
char ptr[14]; // [rsp+40h] [rbp-218h] BYREF
char v11; // [rsp+4Eh] [rbp-20Ah]
char v12; // [rsp+4Fh] [rbp-209h]
char v13; // [rsp+50h] [rbp-208h]
char v14; // [rsp+51h] [rbp-207h]
char v15; // [rsp+52h] [rbp-206h]
char v16; // [rsp+53h] [rbp-205h]
char v17[16]; // [rsp+54h] [rbp-204h] BYREF
char v18; // [rsp+64h] [rbp-1F4h]
char v19; // [rsp+65h] [rbp-1F3h]
char v20; // [rsp+66h] [rbp-1F2h]
char v21; // [rsp+67h] [rbp-1F1h]
__int128 v22[2]; // [rsp+68h] [rbp-1F0h] BYREF
int v23; // [rsp+88h] [rbp-1D0h]
char v24; // [rsp+8Ch] [rbp-1CCh]
char s[280]; // [rsp+140h] [rbp-118h] BYREF

strcpy((char *)v9, "RFB session archived by VNC Reflector");
v7 = 0x1000000LL;
v8 = 0LL;
if ( !s_fbs_prefix )
return;
fbs_close_file();
v2 = s_fbs_idx + 1;
if ( s_fbs_idx + 1 > 999 )
v2 = 0;
s_fbs_idx = v2;
v3 = s_fbs_prefix;
if ( (unsigned int)strlen(s_fbs_prefix) + 4 > 0xFF )
{
log_write(2LL, "FBS filename prefix too long");
s_fbs_prefix = 0LL;
return;
}
if ( s_join_sessions )
{
strcpy(s, v3);
}
else
{
sprintf(s, "%s.%03d", v3, (unsigned int)s_fbs_idx);
if ( !s_join_sessions )
goto LABEL_11;
}
if ( s_fbs_idx != 1 )
{
s_fbs_fp = fopen(s, "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", s);
if ( s_fbs_fb_width != a1 || s_fbs_fb_height != a2 )
{
LOBYTE(v8) = HIBYTE(a1);
BYTE1(v8) = a1;
BYTE2(v8) = HIBYTE(a2);
BYTE3(v8) = a2;
HIDWORD(v8) = 570425343;
fbs_write_data(&v7, 0x10uLL);
}
goto LABEL_27;
}
LABEL_11:
s_fbs_fp = fopen(s, "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", s);
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;
}
strcpy(ptr, "RFB 003.003\n");
ptr[13] = 0;
v11 = 0;
v12 = 1;
v13 = HIBYTE(a1);
v14 = a1;
v15 = HIBYTE(a2);
v16 = a2;
buf_put_pixfmt(v17, (unsigned int)((_DWORD)&g_screen_info + 4));
if ( s_join_sessions )
{
v18 = 0;
v19 = 0;
v20 = 0;
v21 = 37;
v22[0] = (__int128)_mm_loadu_si128(v9);
v22[1] = (__int128)_mm_loadu_si128(&v9[1]);
v23 = v9[2].m128i_i32[0];
v24 = v9[2].m128i_i8[4];
v4 = 37;
}
else
{
v4 = *((_DWORD *)&g_screen_info + 5);
if ( v4 > 0xC0 )
v4 = 192;
v18 = 0;
v19 = 0;
v20 = 0;
v21 = v4;
v5 = (_DWORD *)*((_QWORD *)&g_screen_info + 3);
if ( v4 >= 8 )
{
*(_QWORD *)&v17[v4 + 12] = *(_QWORD *)((char *)v5 + v4 - 8);
qmemcpy(v22, v5, 8LL * ((v4 - 1) >> 3));
}
else if ( (v4 & 4) != 0 )
{
LODWORD(v22[0]) = *v5;
*(_DWORD *)(&v18 + v4) = *(_DWORD *)((char *)v5 + v4 - 4);
}
else if ( v4 )
{
LOBYTE(v22[0]) = *(_BYTE *)v5;
if ( (v4 & 2) != 0 )
*(_WORD *)(&v20 + v4) = *(_WORD *)((char *)v5 + v4 - 2);
}
}
fbs_write_data(ptr, v4 + 40);
LABEL_27:
if ( s_fbs_fp )
{
v6 = ((a2 + 15) >> 4) * ((a1 + 15) >> 4) + 4 * a2 * a1 + 12;
s_fbs_buffer = malloc(v6);
if ( s_fbs_buffer )
{
log_write(5LL, "Allocated buffer to cache FBS data, %d bytes", (unsigned int)v6);
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 func5(unsigned __int16 a1, unsigned __int16 a2)
{
int v2; // eax
const char *v3; // r12
unsigned int v4; // eax
_DWORD *v5; // rdx
int v6; // er12
__int64 v7; // [rsp+0h] [rbp-258h] BYREF
__int64 v8; // [rsp+8h] [rbp-250h]
__m128i v9[3]; // [rsp+10h] [rbp-248h] BYREF
char ptr[14]; // [rsp+40h] [rbp-218h] BYREF
char v11; // [rsp+4Eh] [rbp-20Ah]
char v12; // [rsp+4Fh] [rbp-209h]
char v13; // [rsp+50h] [rbp-208h]
char v14; // [rsp+51h] [rbp-207h]
char v15; // [rsp+52h] [rbp-206h]
char v16; // [rsp+53h] [rbp-205h]
char v17[16]; // [rsp+54h] [rbp-204h] BYREF
char v18; // [rsp+64h] [rbp-1F4h]
char v19; // [rsp+65h] [rbp-1F3h]
char v20; // [rsp+66h] [rbp-1F2h]
char v21; // [rsp+67h] [rbp-1F1h]
__int128 v22[2]; // [rsp+68h] [rbp-1F0h] BYREF
int v23; // [rsp+88h] [rbp-1D0h]
char v24; // [rsp+8Ch] [rbp-1CCh]
char s[280]; // [rsp+140h] [rbp-118h] BYREF

strcpy((char *)v9, "RFB session archived by VNC Reflector");
v7 = 0x1000000LL;
v8 = 0LL;
if ( !s_fbs_prefix )
return;
func2();
v2 = s_fbs_idx + 1;
if ( s_fbs_idx + 1 > 999 )
v2 = 0;
s_fbs_idx = v2;
v3 = s_fbs_prefix;
if ( (unsigned int)strlen(s_fbs_prefix) + 4 > 0xFF )
{
log_write(2LL, "FBS filename prefix too long");
s_fbs_prefix = 0LL;
return;
}
if ( s_join_sessions )
{
strcpy(s, v3);
}
else
{
sprintf(s, "%s.%03d", v3, (unsigned int)s_fbs_idx);
if ( !s_join_sessions )
goto LABEL_11;
}
if ( s_fbs_idx != 1 )
{
s_fbs_fp = fopen(s, "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", s);
if ( s_fbs_fb_width != a1 || s_fbs_fb_height != a2 )
{
LOBYTE(v8) = HIBYTE(a1);
BYTE1(v8) = a1;
BYTE2(v8) = HIBYTE(a2);
BYTE3(v8) = a2;
HIDWORD(v8) = 570425343;
func3(&v7, 0x10uLL);
}
goto LABEL_27;
}
LABEL_11:
s_fbs_fp = fopen(s, "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", s);
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;
}
strcpy(ptr, "RFB 003.003\n");
ptr[13] = 0;
v11 = 0;
v12 = 1;
v13 = HIBYTE(a1);
v14 = a1;
v15 = HIBYTE(a2);
v16 = a2;
buf_put_pixfmt(v17, (unsigned int)((_DWORD)&g_screen_info + 4));
if ( s_join_sessions )
{
v18 = 0;
v19 = 0;
v20 = 0;
v21 = 37;
v22[0] = (__int128)_mm_loadu_si128(v9);
v22[1] = (__int128)_mm_loadu_si128(&v9[1]);
v23 = v9[2].m128i_i32[0];
v24 = v9[2].m128i_i8[4];
v4 = 37;
}
else
{
v4 = *((_DWORD *)&g_screen_info + 5);
if ( v4 > 0xC0 )
v4 = 192;
v18 = 0;
v19 = 0;
v20 = 0;
v21 = v4;
v5 = (_DWORD *)*((_QWORD *)&g_screen_info + 3);
if ( v4 >= 8 )
{
*(_QWORD *)&v17[v4 + 12] = *(_QWORD *)((char *)v5 + v4 - 8);
qmemcpy(v22, v5, 8LL * ((v4 - 1) >> 3));
}
else if ( (v4 & 4) != 0 )
{
LODWORD(v22[0]) = *v5;
*(_DWORD *)(&v18 + v4) = *(_DWORD *)((char *)v5 + v4 - 4);
}
else if ( v4 )
{
LOBYTE(v22[0]) = *(_BYTE *)v5;
if ( (v4 & 2) != 0 )
*(_WORD *)(&v20 + v4) = *(_WORD *)((char *)v5 + v4 - 2);
}
}
func3(ptr, v4 + 40);
LABEL_27:
if ( s_fbs_fp )
{
v6 = ((a2 + 15) >> 4) * ((a1 + 15) >> 4) + 4 * a2 * a1 + 12;
s_fbs_buffer = malloc(v6);
if ( s_fbs_buffer )
{
log_write(5LL, "Allocated buffer to cache FBS data, %d bytes", (unsigned int)v6);
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)
{
if ( !a1 )
_assert_fail("NULL!=pllBox", "ll.c", 0xDFu, "get_ll_total");
pthread_mutex_lock(*(pthread_mutex_t **)a1);
*a2 = *(_DWORD *)(a1 + 32);
return pthread_mutex_unlock(*(pthread_mutex_t **)a1);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, _DWORD *a2)
{
if ( !a1 )
_assert_fail("NULL!=pllBox", "ll.c", 0xDFu, "get_ll_total");
pthread_mutex_lock(*(pthread_mutex_t **)a1);
*a2 = *(_DWORD *)(a1 + 32);
return pthread_mutex_unlock(*(pthread_mutex_t **)a1);
}

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 *

return_type: void

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; // ebp
unsigned int v3; // er15
sem_t *v4; // rbp
unsigned int v5; // eax
pthread_mutex_t *v6; // r13
unsigned int v7; // eax
char *v8; // r12
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; // ebp
unsigned int v3; // er15
sem_t *v4; // rbp
unsigned int v5; // eax
pthread_mutex_t *v6; // r13
unsigned int v7; // eax
char *v8; // r12
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 v3; // rsi
unsigned int v4; // er12
unsigned int v5; // eax
_QWORD *v6; // rax
unsigned int v7; // ebp
unsigned int v9; // er12
unsigned int v10; // eax

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _QWORD *a2)
{
__int64 v3; // rsi
unsigned int v4; // er12
unsigned int v5; // eax
_QWORD *v6; // rax
unsigned int v7; // ebp
unsigned int v9; // er12
unsigned int v10; // eax

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

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

return_type: int

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)
{
_QWORD *v3; // rdi
__int64 v4; // rdx
int v5; // eax

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

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

if ( !a1 )
_assert_fail("NULL!=pllBox", "ll.c", 0xA9u, "rm_ll");
pthread_mutex_lock(*(pthread_mutex_t **)a1);
if ( *(int *)(a1 + 32) <= 0 )
_assert_fail("pllBox->total > 0", "ll.c", 0xACu, "rm_ll");
v3 = *(_QWORD **)(a1 + 8);
*a2 = v3[1];
v4 = **(_QWORD **)(a1 + 8);
*(_QWORD *)(a1 + 8) = v4;
v5 = *(_DWORD *)(a1 + 32) - 1;
*(_DWORD *)(a1 + 32) = v5;
if ( !v5 )
{
if ( v4 )
_assert_fail("NULL==pllBox->pHead", "ll.c", 0xB5u, "rm_ll");
*(_QWORD *)(a1 + 16) = 0LL;
}
*v3 = 0LL;
v3[1] = 0LL;
crop_free(v3, *(_QWORD *)(a1 + 48), 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 )
{
if ( !v3 )
LABEL_4:
_assert_fail("NULL!=pllTemp", "ll.c", 0xF7u, "print_ll");
while ( 1 )
{
printf("(%d):pllTemp->pv=%p\n", v4, v3[1]);
if ( a2 )
a2((__int64)v3[1]);
v3 = (__int64 **)*v3;
if ( !v4 )
break;
--v4;
if ( !v3 )
goto LABEL_4;
}
}
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 )
{
if ( !v3 )
LABEL_4:
_assert_fail("NULL!=pllTemp", "ll.c", 0xF7u, "print_ll");
while ( 1 )
{
printf("(%d):pllTemp->pv=%p\n", v4, v3[1]);
if ( a2 )
a2((__int64)v3[1]);
v3 = (__int64 **)*v3;
if ( !v4 )
break;
--v4;
if ( !v3 )
goto LABEL_4;
}
}
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; // rbx
pthread_mutex_t *v2; // r12
unsigned int v3; // er13
unsigned int v4; // ebp
int v5; // eax
char *v6; // rbp

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");
*v1 = 0LL;
crop_free(v1[6], "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; // rbx
pthread_mutex_t *v2; // r12
unsigned int v3; // er13
unsigned int v4; // ebp
int v5; // eax
char *v6; // rbp

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");
*v1 = 0LL;
crop_free(v1[6], "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 v5; // [rsp+8h] [rbp-20h] BYREF
pthread_t v6; // [rsp+10h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+18h] [rbp-10h] BYREF

pthread_create(newthread, 0LL, (void *(*)(void *))function1, 0LL);
pthread_create(&v6, 0LL, (void *(*)(void *))function2, 0LL);
pthread_create(&v5, 0LL, (void *(*)(void *))function3, 0LL);
pthread_create(&v4, 0LL, (void *(*)(void *))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 v1; // rbx

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

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

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

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)
{
unsigned int v2; // ebx
char v4[16]; // [rsp+0h] [rbp-38h] BYREF
unsigned int v5; // [rsp+10h] [rbp-28h]

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

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

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

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; // rbp
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; // rbp
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)
{
__int64 v3; // r12
__int64 v4; // rbx
float v6; // [rsp+0h] [rbp-50h]
float v7; // [rsp+28h] [rbp-28h]
float v8; // [rsp+2Ch] [rbp-24h]

if ( a3 <= 0 )
{
v6 = 0.0;
}
else
{
v3 = (unsigned int)a3;
v4 = 0LL;
v6 = 0.0;
do
{
v8 = *(float *)(a1 + 4 * v4);
v7 = *(float *)(a2 + 4 * v4);
if ( (float)(v8 - v7) > 0.1 )
fprintf(
stderr,
"%d, data0[%d] = %f data1[%d]= %f \n",
(unsigned int)v4,
(unsigned int)v4,
v8,
(unsigned int)v4,
v7);
v6 = v6 + (float)(v8 - v7);
++v4;
}
while ( v4 != v3 );
}
return fprintf(stderr, "diffall = %f\n", v6);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // r12
__int64 v4; // rbx
float v6; // [rsp+0h] [rbp-50h]
float v7; // [rsp+28h] [rbp-28h]
float v8; // [rsp+2Ch] [rbp-24h]

if ( a3 <= 0 )
{
v6 = 0.0;
}
else
{
v3 = (unsigned int)a3;
v4 = 0LL;
v6 = 0.0;
do
{
v8 = *(float *)(a1 + 4 * v4);
v7 = *(float *)(a2 + 4 * v4);
if ( (float)(v8 - v7) > 0.1 )
fprintf(
stderr,
"%d, data0[%d] = %f data1[%d]= %f \n",
(unsigned int)v4,
(unsigned int)v4,
v8,
(unsigned int)v4,
v7);
v6 = v6 + (float)(v8 - v7);
++v4;
}
while ( v4 != v3 );
}
return fprintf(stderr, "diffall = %f\n", v6);
}

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:");
v2 = getopt(argc, argv, shortopts);
if ( v2 == -1 )
return 0LL;
if ( v2 == 63 )
{
help();
result = 0xFFFFFFFFLL;
}
else
{
puts("Unknow option detection");
result = 0LL;
}
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:");
v2 = getopt(argc, argv, shortopts);
if ( v2 == -1 )
return 0LL;
if ( v2 == 63 )
{
func6();
result = 0xFFFFFFFFLL;
}
else
{
puts("Unknow option detection");
result = 0LL;
}
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


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
char v4[48]; // [rsp+0h] [rbp-D0h] BYREF
char v5[32]; // [rsp+30h] [rbp-A0h] BYREF
__int64 v6[4]; // [rsp+50h] [rbp-80h] BYREF
__int64 v7[4]; // [rsp+70h] [rbp-60h] BYREF
char v8[32]; // [rsp+90h] [rbp-40h] BYREF
char v9[32]; // [rsp+B0h] [rbp-20h] BYREF

result = configure(argc, (char **)argv);
if ( result != -1 )
{
fwrite("Using single point data-type\n", 1uLL, 0x1DuLL, stdout);
fprintf(stdout, "input image: %s\n", inputfilename);
fprintf(stdout, "output image: %s\n", outputfilename);
Array3D_malloc(v9, 128LL, 128LL, 128LL);
Array3D_malloc(v8, 128LL, 128LL, 128LL);
Array3D_malloc(v7, 128LL, 128LL, 128LL);
Array3D_initialize_value(v7[0], 128LL, 128LL, 128LL, 1.0);
Array3D_malloc(v6, 301LL, 257LL, 36LL);
Array3D_initialize_value(v6[0], 301LL, 257LL, 36LL, 1.0);
readImgArray3D(inputfilename, (__int64)v9);
util_start_papi((unsigned int)batch_id, v5);
CPU_Routine(v9, v8, v7, v6);
util_stop_papi((unsigned int)batch_id, v4);
util_print_papi((unsigned int)batch_id, v4, batch_id == 0);
writeImgArray3D(outputfilename, (__int64)v9);
Array3D_free(v9);
Array3D_free(v8);
Array3D_free(v7);
Array3D_free(v6);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
char v4[48]; // [rsp+0h] [rbp-D0h] BYREF
char v5[32]; // [rsp+30h] [rbp-A0h] BYREF
__int64 v6[4]; // [rsp+50h] [rbp-80h] BYREF
__int64 v7[4]; // [rsp+70h] [rbp-60h] BYREF
char v8[32]; // [rsp+90h] [rbp-40h] BYREF
char v9[32]; // [rsp+B0h] [rbp-20h] BYREF

result = func7(argc, (char **)argv);
if ( result != -1 )
{
fwrite("Using single point data-type\n", 1uLL, 0x1DuLL, stdout);
fprintf(stdout, "input image: %s\n", inputfilename);
fprintf(stdout, "output image: %s\n", outputfilename);
Array3D_malloc(v9, 128LL, 128LL, 128LL);
Array3D_malloc(v8, 128LL, 128LL, 128LL);
Array3D_malloc(v7, 128LL, 128LL, 128LL);
Array3D_initialize_value(v7[0], 128LL, 128LL, 128LL, 1.0);
Array3D_malloc(v6, 301LL, 257LL, 36LL);
Array3D_initialize_value(v6[0], 301LL, 257LL, 36LL, 1.0);
func2(inputfilename, (__int64)v9);
util_start_papi((unsigned int)batch_id, v5);
CPU_Routine(v9, v8, v7, v6);
util_stop_papi((unsigned int)batch_id, v4);
util_print_papi((unsigned int)batch_id, v4, batch_id == 0);
func3(outputfilename, (__int64)v9);
Array3D_free(v9);
Array3D_free(v8);
Array3D_free(v7);
Array3D_free(v6);
result = 0;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 int N_x = 128, N_y = 128, N_z = 128;
 float theta = 10.0;
 int q = 150;
 int qz = 128;
 Array3D cpu_image;
 Array3D cpu_sumA;
 Array3D cpu_image_denote;
 Array3D cpu_sino;
 if (configure(argc, argv) == -1)
  return -1;
 fprintf(stdout, "Using single point data-type\n");
 fprintf(stdout, "input image: %s\n", inputfilename);
 fprintf(stdout, "output image: %s\n", outputfilename);
 Array3D_malloc(&cpu_image, N_x, N_y, N_z);
 Array3D_malloc(&cpu_sumA, N_x, N_y, N_z);
 Array3D_malloc(&cpu_image_denote, N_x, N_y, N_z);
 Array3D_initialize_value((cpu_image_denote.dataPtr), 1.0, N_x, N_y,
     N_z);
 Array3D_malloc(&cpu_sino, 2 * q + 1, 2 * qz + 1,
         (int)floorf(359. / theta) + 1);
 Array3D_initialize_value((cpu_sino.dataPtr), 1.0, 2 * q + 1,
     2 * qz + 1, (int)floorf(359. / theta) + 1);
 readImgArray3D(inputfilename, &(cpu_image));
 int Events[5];
 unsigned long long papi_values[5];
 util_start_papi(batch_id, Events);
 CPU_Routine(&cpu_image, &cpu_sumA, &cpu_image_denote, &cpu_sino);
 util_stop_papi(batch_id, papi_values);
 util_print_papi(batch_id, papi_values, (batch_id == 0));
 writeImgArray3D(outputfilename, &cpu_image);
 Array3D_free(&cpu_image);
 Array3D_free(&cpu_sumA);
 Array3D_free(&cpu_image_denote);
 Array3D_free(&cpu_sino);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int N_x = 128; int N_y = 128; int N_z = 128;
 float theta = 10.0;
 int q = 150;
 int qz = 128;
 struct _Array3D cpu_image;
 struct _Array3D cpu_sumA;
 struct _Array3D cpu_image_denote;
 struct _Array3D cpu_sino;
 if (configure(argc, argv) == -1)
  return -1;
 fprintf(stdout, "Using single point data-type\n");
 fprintf(stdout, "input image: %s\n", inputfilename);
 fprintf(stdout, "output image: %s\n", outputfilename);
 Array3D_malloc(&cpu_image, N_x, N_y, N_z);
 Array3D_malloc(&cpu_sumA, N_x, N_y, N_z);
 Array3D_malloc(&cpu_image_denote, N_x, N_y, N_z);
 Array3D_initialize_value((cpu_image_denote.dataPtr), 1.0, N_x, N_y,
     N_z);
 Array3D_malloc(&cpu_sino, 2 * q + 1, 2 * qz + 1,
         (int)floorf(359. / theta) + 1);
 Array3D_initialize_value((cpu_sino.dataPtr), 1.0, 2 * q + 1,
     2 * qz + 1, (int)floorf(359. / theta) + 1);
 readImgArray3D(inputfilename, &(cpu_image));
 int Events[5];
 unsigned long long papi_values[5];
 util_start_papi(batch_id, Events);
 CPU_Routine(&cpu_image, &cpu_sumA, &cpu_image_denote, &cpu_sino);
 util_stop_papi(batch_id, papi_values);
 util_print_papi(batch_id, papi_values, (batch_id == 0));
 writeImgArray3D(outputfilename, &cpu_image);
 Array3D_free(&cpu_image);
 Array3D_free(&cpu_sumA);
 Array3D_free(&cpu_image_denote);
 Array3D_free(&cpu_sino);
 return 0;
}

variable_types:
argv
char **

variable_types: theta float

variable_types: q int

variable_types: qz int

variable_types: struct _Array3D { float *dataPtr; int index1Size; int index2Size; int index3Size; }

variable_types:
Events
int [5]


TVupdate

original_code:
void TVupdate(Array3D * image, Array3D * sumA, float alpha, int max_iter)
{
 int N_x = image->index1Size - 1;
 int N_y = image->index2Size - 1;
 int N_z = image->index3Size - 1;
 float c1, c2, c3, c4;
 float eps = (float) (1e-6);
 int i, j, k, l;
 for (i = 0; i < max_iter; i++) {
  for (j = 1; j < N_x; j++)
   for (k = 1; k < N_y; k++)
    for (l = 1; l < N_z; l++) {
     float data000;
     float data100, data010, data001;
     float datan100, datan110, datan101;
     float data1n10, data0n10, data0n11;
     float data10n1, data00n1, data01n1;
     float sum;
     float sub100, sub010, sub001;
     float sub000, subn110, subn101;
     float sub1n10, sub0002, sub0n11;
     float sub10n1, sub01n1, sub0003;
     float temp;
     data000 = (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size)));
     if (data000 > 1e-6) {
      data100 =
          (*(image->dataPtr + l + image->index3Size *(k + (j + 1) * image->index2Size)));
      data010 =
          (*(image->dataPtr + l + image->index3Size *((k + 1) + j * image->index2Size)));
      data001 =
          (*(image->dataPtr + (l + 1) + image->index3Size *(k + j * image->index2Size)));
      datan100 =
          (*(image->dataPtr + l + image->index3Size *(k + (j - 1) * image->index2Size)));
      datan110 =
          (*(image->dataPtr + l + image->index3Size *((k + 1) + (j - 1) * image->index2Size)));
      datan101 =
          (*(image->dataPtr + (l + 1) + image->index3Size *(k + (j - 1) * image->index2Size)));
      data1n10 =
          (*(image->dataPtr + l + image->index3Size *((k - 1) + (j + 1) * image->index2Size)));
      data0n10 =
          (*(image->dataPtr + l + image->index3Size *((k - 1) + j * image->index2Size)));
      data0n11 =
          (*(image->dataPtr + (l + 1) + image->index3Size *((k - 1) + j * image->index2Size)));
      data10n1 =
          (*(image->dataPtr + (l - 1) + image->index3Size *(k + (j + 1) * image->index2Size)));
      data00n1 =
          (*(image->dataPtr + (l - 1) + image->index3Size *(k + j * image->index2Size)));
      data01n1 =
          (*(image->dataPtr + (l - 1) + image->index3Size *((k + 1) + j * image->index2Size)));
      sum =
          (*(sumA->dataPtr + l + sumA->index3Size *(k + j * sumA->index2Size)));
      sub100 = data100 - data000;
      sub010 = data010 - data000;
      sub001 = data001 - data000;
      sub000 = data000 - datan100;
      subn110 = datan110 - datan100;
      subn101 = datan101 - datan100;
      sub1n10 = data1n10 - data0n10;
      sub0002 = data000 - data0n10;
      sub0n11 = data0n11 - data0n10;
      sub10n1 = data10n1 - data00n1;
      sub01n1 = data01n1 - data00n1;
      sub0003 = data000 - data00n1;
      c1 = data000 / sqrtf(eps +
            sub100 *
            sub100 +
            sub010 *
            sub010 +
            sub001 *
            sub001) /
          sum;
      c2 = data000 / sqrtf(eps +
            sub000 *
            sub000 +
            subn110 *
            subn110 +
            subn101 *
            subn101) /
          sum;
      c3 = data000 / sqrtf(eps +
            sub1n10 *
            sub1n10 +
            sub0002 *
            sub0002 +
            sub0n11 *
            sub0n11) /
          sum;
      c4 = data000 / sqrtf(eps +
            sub10n1 *
            sub10n1 +
            sub01n1 *
            sub01n1 +
            sub0003 *
            sub0003) /
          sum;
      temp =
          alpha * (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size)))
          +
          c1 *
          ((*(image->dataPtr + l + image->index3Size *(k + (j + 1) * image->index2Size))) + (*(image->dataPtr + l + image->index3Size *((k + 1) + j * image->index2Size))) +
           (*(image->dataPtr + (l + 1) + image->index3Size *(k + j * image->index2Size))))
          + c2 * (*(image->dataPtr + l + image->index3Size *(k + (j - 1) * image->index2Size)))
          + c3 * (*(image->dataPtr + l + image->index3Size *((k - 1) + j * image->index2Size)))
          + c4 * (*(image->dataPtr + (l - 1) + image->index3Size *(k + j * image->index2Size)));
      (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size))) =
          (float) (temp /
        (alpha +
         3.0 * c1 + c2 +
         c3 + c4));
     }
    };
  for (j = 1; j < N_x; j++)
   for (k = 1; k < N_y; k++) {
    (*(image->dataPtr + 0 + image->index3Size *(k + j * image->index2Size))) =
        (*(image->dataPtr + 1 + image->index3Size *(k + j * image->index2Size)));
    (*(image->dataPtr + N_z + image->index3Size *(k + j * image->index2Size))) =
        (*(image->dataPtr + (N_z - 1) + image->index3Size *(k + j * image->index2Size)));
   }
 }
}

canonical_original_code:
void TVupdate(struct _Array3D *image, struct _Array3D *sumA, float alpha, int max_iter)
{
 int N_x = image->index1Size - 1;
 int N_y = image->index2Size - 1;
 int N_z = image->index3Size - 1;
 float c1; float c2; float c3; float c4;
 float eps = (float) (1e-6);
 int i; int j; int k; int l;
 for (i = 0; i < max_iter; i++) {
  for (j = 1; j < N_x; j++)
   for (k = 1; k < N_y; k++)
    for (l = 1; l < N_z; l++) {
     float data000;
     float data100; float data010; float data001;
     float datan100; float datan110; float datan101;
     float data1n10; float data0n10; float data0n11;
     float data10n1; float data00n1; float data01n1;
     float sum;
     float sub100; float sub010; float sub001;
     float sub000; float subn110; float subn101;
     float sub1n10; float sub0002; float sub0n11;
     float sub10n1; float sub01n1; float sub0003;
     float temp;
     data000 = (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size)));
     if (data000 > 1e-6) {
      data100 =
          (*(image->dataPtr + l + image->index3Size *(k + (j + 1) * image->index2Size)));
      data010 =
          (*(image->dataPtr + l + image->index3Size *((k + 1) + j * image->index2Size)));
      data001 =
          (*(image->dataPtr + (l + 1) + image->index3Size *(k + j * image->index2Size)));
      datan100 =
          (*(image->dataPtr + l + image->index3Size *(k + (j - 1) * image->index2Size)));
      datan110 =
          (*(image->dataPtr + l + image->index3Size *((k + 1) + (j - 1) * image->index2Size)));
      datan101 =
          (*(image->dataPtr + (l + 1) + image->index3Size *(k + (j - 1) * image->index2Size)));
      data1n10 =
          (*(image->dataPtr + l + image->index3Size *((k - 1) + (j + 1) * image->index2Size)));
      data0n10 =
          (*(image->dataPtr + l + image->index3Size *((k - 1) + j * image->index2Size)));
      data0n11 =
          (*(image->dataPtr + (l + 1) + image->index3Size *((k - 1) + j * image->index2Size)));
      data10n1 =
          (*(image->dataPtr + (l - 1) + image->index3Size *(k + (j + 1) * image->index2Size)));
      data00n1 =
          (*(image->dataPtr + (l - 1) + image->index3Size *(k + j * image->index2Size)));
      data01n1 =
          (*(image->dataPtr + (l - 1) + image->index3Size *((k + 1) + j * image->index2Size)));
      sum =
          (*(sumA->dataPtr + l + sumA->index3Size *(k + j * sumA->index2Size)));
      sub100 = data100 - data000;
      sub010 = data010 - data000;
      sub001 = data001 - data000;
      sub000 = data000 - datan100;
      subn110 = datan110 - datan100;
      subn101 = datan101 - datan100;
      sub1n10 = data1n10 - data0n10;
      sub0002 = data000 - data0n10;
      sub0n11 = data0n11 - data0n10;
      sub10n1 = data10n1 - data00n1;
      sub01n1 = data01n1 - data00n1;
      sub0003 = data000 - data00n1;
      c1 = data000 / sqrtf(eps +
            sub100 *
            sub100 +
            sub010 *
            sub010 +
            sub001 *
            sub001) /
          sum;
      c2 = data000 / sqrtf(eps +
            sub000 *
            sub000 +
            subn110 *
            subn110 +
            subn101 *
            subn101) /
          sum;
      c3 = data000 / sqrtf(eps +
            sub1n10 *
            sub1n10 +
            sub0002 *
            sub0002 +
            sub0n11 *
            sub0n11) /
          sum;
      c4 = data000 / sqrtf(eps +
            sub10n1 *
            sub10n1 +
            sub01n1 *
            sub01n1 +
            sub0003 *
            sub0003) /
          sum;
      temp =
          alpha * (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size)))
          +
          c1 *
          ((*(image->dataPtr + l + image->index3Size *(k + (j + 1) * image->index2Size))) + (*(image->dataPtr + l + image->index3Size *((k + 1) + j * image->index2Size))) +
           (*(image->dataPtr + (l + 1) + image->index3Size *(k + j * image->index2Size))))
          + c2 * (*(image->dataPtr + l + image->index3Size *(k + (j - 1) * image->index2Size)))
          + c3 * (*(image->dataPtr + l + image->index3Size *((k - 1) + j * image->index2Size)))
          + c4 * (*(image->dataPtr + (l - 1) + image->index3Size *(k + j * image->index2Size)));
      (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size))) =
          (float) (temp /
        (alpha +
         3.0 * c1 + c2 +
         c3 + c4));
     }
    };
  for (j = 1; j < N_x; j++)
   for (k = 1; k < N_y; k++) {
    (*(image->dataPtr + 0 + image->index3Size *(k + j * image->index2Size))) =
        (*(image->dataPtr + 1 + image->index3Size *(k + j * image->index2Size)));
    (*(image->dataPtr + N_z + image->index3Size *(k + j * image->index2Size))) =
        (*(image->dataPtr + (N_z - 1) + image->index3Size *(k + j * image->index2Size)));
   }
 }
}

variable_types: struct _Array3D { float *dataPtr; int index1Size; int index2Size; int index3Size; } *

variable_types:
sumA
struct _Array3D *

variable_types: alpha float

variable_types: eps float

variable_types: i int

variable_types: j int

variable_types: k int

variable_types: l int

variable_types: sum float

variable_types: temp float


EMupdate

original_code:
void EMupdate(Array3D * sino,
       Array3D * image,
       Array3D * image_denote,
       Array3D * sumA,
       int max_iter,
       float D,
       int q,
       float ss, float d, float dtheta, float ssz, int qz)
{
 int M_x = sino->index1Size;
 int M_y = sino->index2Size;
 int M_z = sino->index3Size;
 int N_x = image->index1Size;
 int N_y = image->index2Size;
 int N_z = image->index3Size;
 int i, j, k, l;
 Array3D Af;
 Array3D gAf;
 Array3D AtAf;
 Array3D_malloc(&Af, M_x, M_y, M_z);
 Array3D_malloc(&gAf, M_x, M_y, M_z);
 Array3D_malloc(&AtAf, N_x, N_y, N_z);
 for (i = 0; i < max_iter; i++) {
  Forward_Projection(image, D, q, ss, d, dtheta, ssz, qz, &Af);
  for (j = 0; j < M_x; j++)
   for (k = 0; k < M_y; k++)
    for (l = 0; l < M_z; l++)
     if ((*((&Af)->dataPtr + l + (&Af)->index3Size *(k + j * (&Af)->index2Size))) > 1.e-6) {
      (*((&gAf)->dataPtr + l + (&gAf)->index3Size *(k + j * (&gAf)->index2Size))) =
          (*(sino->dataPtr + l + sino->index3Size *(k + j * sino->index2Size))) /
          (*((&Af)->dataPtr + l + (&Af)->index3Size *(k + j * (&Af)->index2Size)));
     }
  fprintf(stderr, "\n");
      Backward_Projection(&AtAf, image_denote, D, q, ss, d,
     dtheta, ssz, qz, &gAf);
  fprintf(stderr, "\n");
      for (j = 0; j < N_x; j++)
   for (k = 0; k < N_y; k++)
    for (l = 0; l < N_z; l++) {
     (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size))) =
         (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size))) *
         (*((&AtAf)->dataPtr + l + (&AtAf)->index3Size *(k + j * (&AtAf)->index2Size))) / (*(sumA->dataPtr + l + sumA->index3Size *(k + j * sumA->index2Size)));
    }
 }
 Array3D_free(&Af);
 Array3D_free(&gAf);
 Array3D_free(&AtAf);
}

canonical_original_code:
void EMupdate(struct _Array3D *sino, struct _Array3D *image, struct _Array3D *image_denote, struct _Array3D *sumA, int max_iter, float D, int q, float ss, float d, float dtheta, float ssz, int qz)
{
 int M_x = sino->index1Size;
 int M_y = sino->index2Size;
 int M_z = sino->index3Size;
 int N_x = image->index1Size;
 int N_y = image->index2Size;
 int N_z = image->index3Size;
 int i; int j; int k; int l;
 struct _Array3D Af;
 struct _Array3D gAf;
 struct _Array3D AtAf;
 Array3D_malloc(&Af, M_x, M_y, M_z);
 Array3D_malloc(&gAf, M_x, M_y, M_z);
 Array3D_malloc(&AtAf, N_x, N_y, N_z);
 for (i = 0; i < max_iter; i++) {
  Forward_Projection(image, D, q, ss, d, dtheta, ssz, qz, &Af);
  for (j = 0; j < M_x; j++)
   for (k = 0; k < M_y; k++)
    for (l = 0; l < M_z; l++)
     if ((*((&Af)->dataPtr + l + (&Af)->index3Size *(k + j * (&Af)->index2Size))) > 1.e-6) {
      (*((&gAf)->dataPtr + l + (&gAf)->index3Size *(k + j * (&gAf)->index2Size))) =
          (*(sino->dataPtr + l + sino->index3Size *(k + j * sino->index2Size))) /
          (*((&Af)->dataPtr + l + (&Af)->index3Size *(k + j * (&Af)->index2Size)));
     }
  fprintf(stderr, "\n");
      Backward_Projection(&AtAf, image_denote, D, q, ss, d,
     dtheta, ssz, qz, &gAf);
  fprintf(stderr, "\n");
      for (j = 0; j < N_x; j++)
   for (k = 0; k < N_y; k++)
    for (l = 0; l < N_z; l++) {
     (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size))) =
         (*(image->dataPtr + l + image->index3Size *(k + j * image->index2Size))) *
         (*((&AtAf)->dataPtr + l + (&AtAf)->index3Size *(k + j * (&AtAf)->index2Size))) / (*(sumA->dataPtr + l + sumA->index3Size *(k + j * sumA->index2Size)));
    }
 }
 Array3D_free(&Af);
 Array3D_free(&gAf);
 Array3D_free(&AtAf);
}

variable_types:
image
struct _Array3D *

variable_types: D float

variable_types: ss float

variable_types: d float

variable_types: dtheta float

variable_types: ssz float

user_defined_types: struct _Array3D { float *dataPtr; int index1Size; int index2Size; int index3Size; }


decompiled_code:
__int64 __fastcall CPU_Routine(_QWORD *a1, __int64 a2, _QWORD *a3, __int64 a4)
{
__int64 v6; // rbx
__int64 v7; // rax
__int64 v8; // rbx
__int64 v9; // rax
unsigned int i; // ebx
__int64 v11; // r12
__int64 v12; // rbx
__int64 v14; // [rsp+0h] [rbp-B0h]
__int64 v15; // [rsp+8h] [rbp-A8h]
char s[160]; // [rsp+10h] [rbp-A0h] BYREF

writeImgArray3D("../data/cpu_readinput.dat", a1);
v15 = emtv3d_timer_s();
fwrite("CPU Backward_Projection begins \n", 1uLL, 0x20uLL, stderr);
v6 = emtv3d_timer_us();
Backward_Projection(a2, a3, 150LL, 128LL, a4, 125.0, 0.5, 64.0, 10.0, 1.0);
v7 = emtv3d_timer_us();
fprintf(stderr, "\nCPU Backward_Projection uses %lld us\n", v7 - v6);
writeImgArray3D("../data/cpu_sumA.dat", a2);
fwrite("CPU Forward_Projection begins \n", 1uLL, 0x1FuLL, stderr);
v8 = emtv3d_timer_us();
Forward_Projection(a1, 150LL, 128LL, a4, 125.0, 0.5, 64.0, 10.0, 1.0);
v9 = emtv3d_timer_us();
fprintf(stderr, "\n CPU Forward_Projection uses %lld us\n", v9 - v8);
writeImgArray3D("../data/cpu_sino.dat", a4);
fwrite("CPU Initialization\n", 1uLL, 0x13uLL, stderr);
Initialization(a3, 150LL, 128LL, a4, 125.0, 0.5, 64.0, 10.0, 1.0);
Array3D_copy(*a1, *a3, 128LL, 128LL, 128LL);
writeImgArray3D("../data/cpu_initialization.dat", a1);
fputc(10, stderr);
v14 = emtv3d_timer_s();
for ( i = 0; i != 100; ++i )
{
fprintf(stderr, "CPU EMupdate %d \n", i);
EMupdate(a4, a1, a3, a2, 3LL, 150LL, 125.0, 0.5, 64.0, 10.0, 1.0, 128LL);
sprintf(s, "../data/cpu_EMupdate%d.dat", i);
writeImgArray3D(s, a1);
fprintf(stderr, "CPU TVupdate %d \n", i);
TVupdate(a1, a2, 10LL, 5.0);
sprintf(s, "../data/cpu_TVupdate%d.dat", i);
writeImgArray3D(s, a1);
}
v11 = emtv3d_timer_s();
v12 = emtv3d_timer_s();
fprintf(stderr, "CPU \nEMTV update uses %lld seconds\n", v11 - v14);
fprintf(stderr, "CPU total using %lld seconds\n", v12 - v15);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2, _QWORD *a3, __int64 a4)
{
__int64 v6; // rbx
__int64 v7; // rax
__int64 v8; // rbx
__int64 v9; // rax
unsigned int i; // ebx
__int64 v11; // r12
__int64 v12; // rbx
__int64 v14; // [rsp+0h] [rbp-B0h]
__int64 v15; // [rsp+8h] [rbp-A8h]
char s[160]; // [rsp+10h] [rbp-A0h] BYREF

writeImgArray3D("../data/cpu_readinput.dat", a1);
v15 = emtv3d_timer_s();
fwrite("CPU Backward_Projection begins \n", 1uLL, 0x20uLL, stderr);
v6 = emtv3d_timer_us();
Backward_Projection(a2, a3, 150LL, 128LL, a4, 125.0, 0.5, 64.0, 10.0, 1.0);
v7 = emtv3d_timer_us();
fprintf(stderr, "\nCPU Backward_Projection uses %lld us\n", v7 - v6);
writeImgArray3D("../data/cpu_sumA.dat", a2);
fwrite("CPU Forward_Projection begins \n", 1uLL, 0x1FuLL, stderr);
v8 = emtv3d_timer_us();
Forward_Projection(a1, 150LL, 128LL, a4, 125.0, 0.5, 64.0, 10.0, 1.0);
v9 = emtv3d_timer_us();
fprintf(stderr, "\n CPU Forward_Projection uses %lld us\n", v9 - v8);
writeImgArray3D("../data/cpu_sino.dat", a4);
fwrite("CPU Initialization\n", 1uLL, 0x13uLL, stderr);
Initialization(a3, 150LL, 128LL, a4, 125.0, 0.5, 64.0, 10.0, 1.0);
Array3D_copy(*a1, *a3, 128LL, 128LL, 128LL);
writeImgArray3D("../data/cpu_initialization.dat", a1);
fputc(10, stderr);
v14 = emtv3d_timer_s();
for ( i = 0; i != 100; ++i )
{
fprintf(stderr, "CPU EMupdate %d \n", i);
EMupdate(a4, a1, a3, a2, 3LL, 150LL, 125.0, 0.5, 64.0, 10.0, 1.0, 128LL);
sprintf(s, "../data/cpu_EMupdate%d.dat", i);
writeImgArray3D(s, a1);
fprintf(stderr, "CPU TVupdate %d \n", i);
TVupdate(a1, a2, 10LL, 5.0);
sprintf(s, "../data/cpu_TVupdate%d.dat", i);
writeImgArray3D(s, a1);
}
v11 = emtv3d_timer_s();
v12 = emtv3d_timer_s();
fprintf(stderr, "CPU \nEMTV update uses %lld seconds\n", v11 - v14);
fprintf(stderr, "CPU total using %lld seconds\n", v12 - v15);
return 0LL;
}

original_code:
int CPU_Routine(Array3D * image, Array3D * sumA, Array3D * image_denote,
  Array3D * sino)
{
 int N_x = 128, N_y = 128, N_z = 128;
 float D = 125, d = 64;
 float theta = 10.0;
 int q = 150;
 int qz = 128;
 float ss = 0.5;
 float ssz = 1.0;
 int max_iter_EM = 3;
 int max_iter_TV = 10;
 float alpha = 5;
 int iter;
 int64_t i_start_whole, i_end_whole;
 int64_t i_start, i_end;
 char filename[100];
 writeImgArray3D("../data/cpu_readinput.dat", image);
 i_start_whole = emtv3d_timer_s();
 fprintf(stderr, "CPU Backward_Projection begins \n");
 i_start = emtv3d_timer_us();
 Backward_Projection(sumA, image_denote, D, q, ss, d, theta, ssz, qz, sino);
 i_end = emtv3d_timer_us();
 fprintf(stderr, "\nCPU Backward_Projection uses %lld us\n",
  (i_end - i_start));
 writeImgArray3D("../data/cpu_sumA.dat", sumA);
 fprintf(stderr, "CPU Forward_Projection begins \n");
 i_start = emtv3d_timer_us();
 Forward_Projection(image, D, q, ss, d, theta, ssz, qz, sino);
 i_end = emtv3d_timer_us();
 fprintf(stderr, "\n CPU Forward_Projection uses %lld us\n",
  (i_end - i_start));
 writeImgArray3D("../data/cpu_sino.dat", sino);
 fprintf(stderr, "CPU Initialization\n");
 Initialization(image_denote, D, q, ss, d, theta, ssz, qz, sino);
 Array3D_copy(image->dataPtr, image_denote->dataPtr, N_x, N_y, N_z);
 writeImgArray3D("../data/cpu_initialization.dat", image);
 fprintf(stderr, "\n");
 i_start = emtv3d_timer_s();
 for (iter = 0; iter < 100; iter++) {
  fprintf(stderr, "CPU EMupdate %d \n", iter);
  EMupdate(sino, image, image_denote, sumA, max_iter_EM, D, q, ss, d, theta, ssz, qz);
  sprintf(filename, "../data/cpu_EMupdate%d.dat", iter);
  writeImgArray3D(filename, image);
  fprintf(stderr, "CPU TVupdate %d \n", iter);
  TVupdate(image, sumA, alpha, max_iter_TV);
  sprintf(filename, "../data/cpu_TVupdate%d.dat", iter);
  writeImgArray3D(filename, image);
 }
 i_end = emtv3d_timer_s();
 i_end_whole = emtv3d_timer_s();
 fprintf(stderr, "CPU \nEMTV update uses %lld seconds\n",
  (i_end - i_start));
 fprintf(stderr, "CPU total using %lld seconds\n",
  (i_end_whole - i_start_whole));
 return 0;
}

canonical_original_code:
int CPU_Routine(struct _Array3D *image, struct _Array3D *sumA, struct _Array3D *image_denote, struct _Array3D *sino)
{
 int N_x = 128; int N_y = 128; int N_z = 128;
 float D = 125; float d = 64;
 float theta = 10.0;
 int q = 150;
 int qz = 128;
 float ss = 0.5;
 float ssz = 1.0;
 int max_iter_EM = 3;
 int max_iter_TV = 10;
 float alpha = 5;
 int iter;
 long i_start_whole; long i_end_whole;
 long i_start; long i_end;
 char filename[100];
 writeImgArray3D("../data/cpu_readinput.dat", image);
 i_start_whole = emtv3d_timer_s();
 fprintf(stderr, "CPU Backward_Projection begins \n");
 i_start = emtv3d_timer_us();
 Backward_Projection(sumA, image_denote, D, q, ss, d, theta, ssz, qz, sino);
 i_end = emtv3d_timer_us();
 fprintf(stderr, "\nCPU Backward_Projection uses %lld us\n",
  (i_end - i_start));
 writeImgArray3D("../data/cpu_sumA.dat", sumA);
 fprintf(stderr, "CPU Forward_Projection begins \n");
 i_start = emtv3d_timer_us();
 Forward_Projection(image, D, q, ss, d, theta, ssz, qz, sino);
 i_end = emtv3d_timer_us();
 fprintf(stderr, "\n CPU Forward_Projection uses %lld us\n",
  (i_end - i_start));
 writeImgArray3D("../data/cpu_sino.dat", sino);
 fprintf(stderr, "CPU Initialization\n");
 Initialization(image_denote, D, q, ss, d, theta, ssz, qz, sino);
 Array3D_copy(image->dataPtr, image_denote->dataPtr, N_x, N_y, N_z);
 writeImgArray3D("../data/cpu_initialization.dat", image);
 fprintf(stderr, "\n");
 i_start = emtv3d_timer_s();
 for (iter = 0; iter < 100; iter++) {
  fprintf(stderr, "CPU EMupdate %d \n", iter);
  EMupdate(sino, image, image_denote, sumA, max_iter_EM, D, q, ss, d, theta, ssz, qz);
  sprintf(filename, "../data/cpu_EMupdate%d.dat", iter);
  writeImgArray3D(filename, image);
  fprintf(stderr, "CPU TVupdate %d \n", iter);
  TVupdate(image, sumA, alpha, max_iter_TV);
  sprintf(filename, "../data/cpu_TVupdate%d.dat", iter);
  writeImgArray3D(filename, image);
 }
 i_end = emtv3d_timer_s();
 i_end_whole = emtv3d_timer_s();
 fprintf(stderr, "CPU \nEMTV update uses %lld seconds\n",
  (i_end - i_start));
 fprintf(stderr, "CPU total using %lld seconds\n",
  (i_end_whole - i_start_whole));
 return 0;
}

variable_types:
sino
struct _Array3D *

variable_types: theta float

variable_types: q int

variable_types: qz int

variable_types: iter int

variable_types:
filename
char [100]


compf

repo: intijk/triangulation

decompiled_code:
__int64 __fastcall compf(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
}

original_code:
int compf(const void *p1, const void *p2){
 return (*((int*)p1))-(*((int*)p2));
}

canonical_original_code:
int compf(void *p1, void *p2){
 return (*((int *)p1))-(*((int *)p2));
}


insertEdge

original_code:
void insertEdge(int a, int b){
 adjNode *np=(adjNode*)malloc(sizeof(adjNode)), *npt;
 np->n=b;
 np->next=((void *)0);
 if(adjList[a]==((void *)0)) adjList[a]=np;
 else{
  int existed=0;
  npt=adjList[a];
  while(1){
   if(npt->n==b){
      existed=1;
      break;
   }
   if(npt->next==((void *)0)){
    break;
   }
   npt=npt->next;
  }
  if(!existed){
   npt->next=np;
  }else{
   free(np);
  }
 }
}

canonical_original_code:
void insertEdge(int a, int b){
 struct adjNode *np = (adjNode*)malloc(sizeof(adjNode)); struct adjNode *npt;
 np->n=b;
 np->next=((void *)0);
 if(adjList[a]==((void *)0)) adjList[a]=np;
 else{
  int existed = 0;
  npt=adjList[a];
  while(1){
   if(npt->n==b){
      existed=1;
      break;
   }
   if(npt->next==((void *)0)){
    break;
   }
   npt=npt->next;
  }
  if(!existed){
   npt->next=np;
  }else{
   free(np);
  }
 }
}

variable_types: a int

variable_types: b int

variable_types: struct adjNode { int n; struct adjNode *next; } *

variable_types: existed int


recordEdge

decompiled_code:
void __fastcall recordEdge(int a1, int a2)
{
size_t v2; // r12

if ( a1 >= 0 && a1 != a2 && a2 >= 0 )
{
if ( !adjList )
{
v2 = 8LL * N;
adjList = (__int64)malloc(v2);
memset((void *)adjList, 0, v2);
}
insertEdge(a1, a2);
insertEdge(a2, a1);
}
}

canonical_decompiled_code:
void __fastcall func9(int a1, int a2)
{
size_t v2; // r12

if ( a1 >= 0 && a1 != a2 && a2 >= 0 )
{
if ( !adjList )
{
v2 = 8LL * N;
adjList = (__int64)malloc(v2);
memset((void *)adjList, 0, v2);
}
func8(a1, a2);
func8(a2, a1);
}
}

original_code:
void recordEdge(int a, int b){
 if(a<0 || b<0 || a==b) return;
 if(adjList==((void *)0)){
  adjList=(adjNode**)malloc(sizeof(adjNode*)*N);
  memset(adjList,0,sizeof(adjNode*)*N);
 }
 insertEdge(a,b);
 insertEdge(b,a);
}

canonical_original_code:
void recordEdge(int a, int b){
 if(a<0 || b<0 || a==b) return;
 if(adjList==((void *)0)){
  adjList=(struct adjNode **)malloc(sizeof(struct adjNode *)*N);
  memset(adjList,0,sizeof(struct adjNode *)*N);
 }
 insertEdge(a,b);
 insertEdge(b,a);
}

user_defined_types: struct adjNode { int n; struct adjNode *next; }