decompiled_code:
void __fastcall sran32(int a1)
{
non_reentrant_state0 = 0;
non_reentrant_state1 = a1;
non_reentrant_seeded = 1;
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
non_reentrant_state0 = 0;
non_reentrant_state1 = a1;
non_reentrant_seeded = 1;
}

original_code:
void sran32(unsigned s)
{
 non_reentrant_state0 = 0;
 non_reentrant_state1 = s;
 non_reentrant_seeded = 1;
}

canonical_original_code:
void sran32(unsigned int s)
{
 non_reentrant_state0 = 0;
 non_reentrant_state1 = s;
 non_reentrant_seeded = 1;
}

variable_types:
s
unsigned int


repo: johnkerl/percolation

decompiled_code:
void __fastcall sran32b(int a1, int a2)
{
non_reentrant_state0 = a1;
non_reentrant_state1 = a2;
non_reentrant_seeded = 1;
}

canonical_decompiled_code:
void __fastcall func2(int a1, int a2)
{
non_reentrant_state0 = a1;
non_reentrant_state1 = a2;
non_reentrant_seeded = 1;
}

original_code:
void sran32b(unsigned s0, unsigned s1)
{
 non_reentrant_state0 = s0;
 non_reentrant_state1 = s1;
 non_reentrant_seeded = 1;
}

canonical_original_code:
void sran32b(unsigned int s0, unsigned int s1)
{
 non_reentrant_state0 = s0;
 non_reentrant_state1 = s1;
 non_reentrant_seeded = 1;
}

return_type: void


decompiled_code:
__int64 sran32_tod()
{
__pid_t v0; // eax
__int64 result; // rax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v2, 0LL);
v0 = getpid();
non_reentrant_seeded = 1;
non_reentrant_state0 = LODWORD(v2.tv_usec) ^ v0;
result = LODWORD(v2.tv_sec) ^ (unsigned int)(LODWORD(v2.tv_usec) * LODWORD(v2.tv_usec) + 1);
non_reentrant_state1 = LODWORD(v2.tv_sec) ^ (LODWORD(v2.tv_usec) * LODWORD(v2.tv_usec) + 1);
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__pid_t v0; // eax
__int64 result; // rax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v2, 0LL);
v0 = getpid();
non_reentrant_seeded = 1;
non_reentrant_state0 = LODWORD(v2.tv_usec) ^ v0;
result = LODWORD(v2.tv_sec) ^ (unsigned int)(LODWORD(v2.tv_usec) * LODWORD(v2.tv_usec) + 1);
non_reentrant_state1 = LODWORD(v2.tv_sec) ^ (LODWORD(v2.tv_usec) * LODWORD(v2.tv_usec) + 1);
return result;
}

original_code:
void sran32_tod(void)
{
 struct timeval tod;
 (void)gettimeofday(&tod, 0);
 non_reentrant_state0 = getpid() ^ tod.tv_usec;
 non_reentrant_state1 = tod.tv_sec ^ (tod.tv_usec * tod.tv_usec + 1);
 non_reentrant_seeded = 1;
}

canonical_original_code:
void sran32_tod()
{
 struct timeval tod;
 (void)gettimeofday(&tod, 0);
 non_reentrant_state0 = getpid() ^ tod.tv_usec;
 non_reentrant_state1 = tod.tv_sec ^ (tod.tv_usec * tod.tv_usec + 1);
 non_reentrant_seeded = 1;
}

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


decompiled_code:
__int64 __fastcall iran32_r(int *a1, int *a2)
{
int v4; // [rsp+8h] [rbp-18h] BYREF
unsigned int v5[5]; // [rsp+Ch] [rbp-14h] BYREF

v4 = *a1;
v5[0] = *a2;
psdes_hash_64(&v4, (int *)v5);
if ( (*a2)++ == -1 )
++*a1;
return v5[0];
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1, int *a2)
{
int v4; // [rsp+8h] [rbp-18h] BYREF
unsigned int v5[5]; // [rsp+Ch] [rbp-14h] BYREF

v4 = *a1;
v5[0] = *a2;
func0(&v4, (int *)v5);
if ( (*a2)++ == -1 )
++*a1;
return v5[0];
}

original_code:
unsigned iran32_r(unsigned * pstate0, unsigned * pstate1)
{
 unsigned word0 = *pstate0;
 unsigned word1 = *pstate1;
 psdes_hash_64(&word0, &word1);
 (*pstate1)++;
 if (*pstate1 == 0)
  (*pstate0)++;
 return word1;
}

canonical_original_code:
unsigned int iran32_r(unsigned int *pstate0, unsigned int *pstate1)
{
 unsigned int word0 = *pstate0;
 unsigned int word1 = *pstate1;
 psdes_hash_64(&word0, &word1);
 (*pstate1)++;
 if (*pstate1 == 0)
  (*pstate0)++;
 return word1;
}

return_type: unsigned int


decompiled_code:
__int64 iran32()
{
if ( !non_reentrant_seeded )
sran32_tod();
return iran32_r(&non_reentrant_state0, &non_reentrant_state1);
}

canonical_decompiled_code:
__int64 func5()
{
if ( !non_reentrant_seeded )
func3();
return func4(&non_reentrant_state0, &non_reentrant_state1);
}

original_code:
unsigned iran32(void)
{
 if (!non_reentrant_seeded)
  sran32_tod();
 return iran32_r(&non_reentrant_state0, &non_reentrant_state1);
}

canonical_original_code:
unsigned int iran32()
{
 if (!non_reentrant_seeded)
  sran32_tod();
 return iran32_r(&non_reentrant_state0, &non_reentrant_state1);
}


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

*a1 = *a3;
*a2 = *a4;
result = psdes_hash_64(a1, a2);
if ( (*a4)++ == -1 )
++*a3;
return result;
}

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

*a1 = *a3;
*a2 = *a4;
result = func0(a1, a2);
if ( (*a4)++ == -1 )
++*a3;
return result;
}

original_code:
void iran64_r(unsigned * pout0, unsigned * pout1,
 unsigned * pstate0, unsigned * pstate1)
{
 *pout0 = *pstate0;
 *pout1 = *pstate1;
 psdes_hash_64(pout0, pout1);
 (*pstate1)++;
 if (*pstate1 == 0)
  (*pstate0)++;
}

canonical_original_code:
void iran64_r(unsigned int *pout0, unsigned int *pout1, unsigned int *pstate0, unsigned int *pstate1)
{
 *pout0 = *pstate0;
 *pout1 = *pstate1;
 psdes_hash_64(pout0, pout1);
 (*pstate1)++;
 if (*pstate1 == 0)
  (*pstate0)++;
}


decompiled_code:
__int64 __fastcall iran64(int *a1, int *a2)
{
if ( !non_reentrant_seeded )
sran32_tod();
return iran64_r(a1, a2, &non_reentrant_state0, &non_reentrant_state1);
}

canonical_decompiled_code:
__int64 __fastcall func7(int *a1, int *a2)
{
if ( !non_reentrant_seeded )
func3();
return func6(a1, a2, &non_reentrant_state0, &non_reentrant_state1);
}

original_code:
void iran64(unsigned * pout0, unsigned * pout1)
{
 if (!non_reentrant_seeded)
  sran32_tod();
 return iran64_r(pout0, pout1,
  &non_reentrant_state0, &non_reentrant_state1);
}

canonical_original_code:
void iran64(unsigned int *pout0, unsigned int *pout1)
{
 if (!non_reentrant_seeded)
  sran32_tod();
 return iran64_r(pout0, pout1,
  &non_reentrant_state0, &non_reentrant_state1);
}


decompiled_code:
double __fastcall fran32_r(int *a1, int *a2)
{
return (double)(int)iran32_r(a1, a2) * 2.328306436538696e-10;
}

canonical_decompiled_code:
double __fastcall func8(int *a1, int *a2)
{
return (double)(int)func4(a1, a2) * 2.328306436538696e-10;
}

original_code:
double fran32_r(unsigned * pstate0, unsigned * pstate1)
{
 unsigned word = iran32_r(pstate0, pstate1);
 return (double)( (double)word / (double)4294967296.0 );
}

canonical_original_code:
double fran32_r(unsigned int *pstate0, unsigned int *pstate1)
{
 unsigned int word = iran32_r(pstate0, pstate1);
 return (double)( (double)word / (double)4294967296.0 );
}

variable_types:
word
unsigned int

return_type: double


decompiled_code:
double fran32()
{
if ( !non_reentrant_seeded )
sran32_tod();
return fran32_r(&non_reentrant_state0, &non_reentrant_state1);
}

canonical_decompiled_code:
double func9()
{
if ( !non_reentrant_seeded )
func3();
return func8(&non_reentrant_state0, &non_reentrant_state1);
}

original_code:
double fran32(void)
{
 if (!non_reentrant_seeded)
  sran32_tod();
 return fran32_r(&non_reentrant_state0, &non_reentrant_state1);
}

canonical_original_code:
double fran32()
{
 if (!non_reentrant_seeded)
  sran32_tod();
 return fran32_r(&non_reentrant_state0, &non_reentrant_state1);
}


decompiled_code:
__int64 __fastcall sran32_tod_r(int *a1, _DWORD *a2)
{
int v2; // edx
int v3; // eax
__int64 result; // rax
struct timeval v5; // [rsp+0h] [rbp-28h] BYREF

gettimeofday(&v5, 0LL);
v2 = LODWORD(v5.tv_usec) ^ getpid();
v3 = LODWORD(v5.tv_usec) * LODWORD(v5.tv_usec);
*a1 = v2;
result = LODWORD(v5.tv_sec) ^ (unsigned int)(v3 + 1);
*a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int *a1, _DWORD *a2)
{
int v2; // edx
int v3; // eax
__int64 result; // rax
struct timeval v5; // [rsp+0h] [rbp-28h] BYREF

gettimeofday(&v5, 0LL);
v2 = LODWORD(v5.tv_usec) ^ getpid();
v3 = LODWORD(v5.tv_usec) * LODWORD(v5.tv_usec);
*a1 = v2;
result = LODWORD(v5.tv_sec) ^ (unsigned int)(v3 + 1);
*a2 = result;
return result;
}

original_code:
void sran32_tod_r(unsigned * pstate0, unsigned * pstate1)
{
 struct timeval tod;
 (void)gettimeofday(&tod, 0);
 *pstate0 = getpid() ^ tod.tv_usec;
 *pstate1 = tod.tv_sec ^ (tod.tv_usec * tod.tv_usec + 1);
}

canonical_original_code:
void sran32_tod_r(unsigned int *pstate0, unsigned int *pstate1)
{
 struct timeval tod;
 (void)gettimeofday(&tod, 0);
 *pstate0 = getpid() ^ tod.tv_usec;
 *pstate1 = tod.tv_sec ^ (tod.tv_usec * tod.tv_usec + 1);
}

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


decompiled_code:
void *__fastcall malloc_or_die(unsigned int a1)
{
void *result; // rax

result = malloc((int)a1);
if ( !result )
{
fprintf(stderr, "malloc(%d) failed.\n", a1);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(unsigned int a1)
{
void *result; // rax

result = malloc((int)a1);
if ( !result )
{
fprintf(stderr, "malloc(%d) failed.\n", a1);
exit(1);
}
return result;
}

original_code:
void* malloc_or_die(int num_bytes)
{
 void* rv = malloc(num_bytes);
 if (rv == 0) {
  fprintf(stderr, "malloc(%d) failed.\n", num_bytes);
  exit(1);
 }
 return rv;
}

canonical_original_code:
void *malloc_or_die(int num_bytes)
{
 void *rv = malloc(num_bytes);
 if (rv == 0) {
  fprintf(stderr, "malloc(%d) failed.\n", num_bytes);
  exit(1);
 }
 return rv;
}

variable_types:
rv
void *

return_type: void *


decompiled_code:
char *get_sys_time_string()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) < 0 )
{
perror("gettimeofday");
exit(1);
}
return ctime(&v1.tv_sec);
}

canonical_decompiled_code:
char *func1()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) < 0 )
{
perror("gettimeofday");
exit(1);
}
return ctime(&v1.tv_sec);
}

original_code:
char* get_sys_time_string(void)
{
 struct timeval now;
 if (gettimeofday(&now, 0) < 0) {
  perror("gettimeofday");
  exit(1);
 }
 return ctime(&now.tv_sec);
}

canonical_original_code:
char *get_sys_time_string()
{
 struct timeval now;
 if (gettimeofday(&now, 0) < 0) {
  perror("gettimeofday");
  exit(1);
 }
 return ctime(&now.tv_sec);
}

return_type: char *


decompiled_code:
int check_stop()
{
int result; // eax
char *v1; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

result = stat("./__stop__", &v2);
if ( !result )
{
v1 = get_sys_time_string();
printf("Exiting due to __stop__ file. Time: %s", v1);
exit(1);
}
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax
char *v1; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

result = stat("./__stop__", &v2);
if ( !result )
{
v1 = func1();
printf("Exiting due to __stop__ file. Time: %s", v1);
exit(1);
}
return result;
}

original_code:
void check_stop(void)
{
 struct stat statbuf;
 if (stat("./__stop__", &statbuf) == 0) {
  printf("Exiting due to __stop__ file.  Time:  %s",
   get_sys_time_string());
  exit(1);
 }
}

canonical_original_code:
void check_stop()
{
 struct stat statbuf;
 if (stat("./__stop__", &statbuf) == 0) {
  printf("Exiting due to __stop__ file.  Time:  %s",
   get_sys_time_string());
  exit(1);
 }
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 get_urandom()
{
int v0; // eax
__int64 v1; // rdx
int v2; // eax
unsigned int v3; // er8
unsigned int v5; // ebx

if ( fd_3 == -1 )
{
fd_3 = open("/dev/urandom", 0);
if ( fd_3 < 0 )
{
perror("open");
fprintf(stderr, "Couldn't open %s.\n", "/dev/urandom");
exit(1);
}
}
v0 = bufpos_1;
if ( !bufpos_1 )
{
v5 = read(fd_3, buf_0, 0x2000uLL);
if ( v5 != 0x2000 )
{
perror("read");
fprintf(stderr, "Couldn't read %s.\n", "/dev/urandom");
fprintf(stderr, "Expected %d byte(s); got %d.\n", 0x2000LL, v5);
exit(1);
}
v0 = bufpos_1;
}
v1 = v0;
v2 = v0 + 1;
v3 = buf_0[v1];
if ( v2 > 2047 )
v2 = 0;
bufpos_1 = v2;
return v3;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
__int64 v1; // rdx
int v2; // eax
unsigned int v3; // er8
unsigned int v5; // ebx

if ( fd_3 == -1 )
{
fd_3 = open("/dev/urandom", 0);
if ( fd_3 < 0 )
{
perror("open");
fprintf(stderr, "Couldn't open %s.\n", "/dev/urandom");
exit(1);
}
}
v0 = bufpos_1;
if ( !bufpos_1 )
{
v5 = read(fd_3, buf_0, 0x2000uLL);
if ( v5 != 0x2000 )
{
perror("read");
fprintf(stderr, "Couldn't read %s.\n", "/dev/urandom");
fprintf(stderr, "Expected %d byte(s); got %d.\n", 0x2000LL, v5);
exit(1);
}
v0 = bufpos_1;
}
v1 = v0;
v2 = v0 + 1;
v3 = buf_0[v1];
if ( v2 > 2047 )
v2 = 0;
bufpos_1 = v2;
return v3;
}

original_code:
int get_urandom(void)
{
 static int fd = -1;
 static int buf[2048];
 static int bufpos = 0;
 static char * dev_name = "/dev/urandom";
 int bytes_wanted;
 int bytes_read;
 int rv;
 if (fd == -1) {
  fd = open(dev_name, 00);
  if (fd < 0) {
   perror("open");
   fprintf(stderr, "Couldn't open %s.\n", dev_name);
   exit(1);
  }
 }
 if (bufpos == 0) {
  bytes_wanted = 2048 * sizeof(int);
  bytes_read = read(fd, buf, 2048 * sizeof(int));
  if (bytes_read != bytes_wanted) {
   perror("read");
   fprintf(stderr, "Couldn't read %s.\n", dev_name);
   fprintf(stderr, "Expected %d byte(s); got %d.\n",
    bytes_wanted, bytes_read);
   exit(1);
  }
 }
 rv = buf[bufpos];
 bufpos++;
 if (bufpos >= 2048)
  bufpos = 0;
 return rv;
}

canonical_original_code:
int get_urandom()
{
 static int fd = -1;
 static int buf[2048];
 static int bufpos = 0;
 static char *dev_name = "/dev/urandom";
 int bytes_wanted;
 int bytes_read;
 int rv;
 if (fd == -1) {
  fd = open(dev_name, 00);
  if (fd < 0) {
   perror("open");
   fprintf(stderr, "Couldn't open %s.\n", dev_name);
   exit(1);
  }
 }
 if (bufpos == 0) {
  bytes_wanted = 2048 * sizeof(int);
  bytes_read = read(fd, buf, 2048 * sizeof(int));
  if (bytes_read != bytes_wanted) {
   perror("read");
   fprintf(stderr, "Couldn't read %s.\n", dev_name);
   fprintf(stderr, "Expected %d byte(s); got %d.\n",
    bytes_wanted, bytes_read);
   exit(1);
  }
 }
 rv = buf[bufpos];
 bufpos++;
 if (bufpos >= 2048)
  bufpos = 0;
 return rv;
}

variable_types: fd int

variable_types:
buf
int [2048]

variable_types: bufpos int

variable_types: rv int

return_type: int


decompiled_code:
double get_urandomu()
{
return (double)(int)get_urandom() * 2.328306436538696e-10;
}

original_code:
double get_urandomu(void)
{
 unsigned u = get_urandom();
 double numer = (double)u;
 double denom = 4294967296.0;
 return (double)(numer/denom);
}

canonical_original_code:
double get_urandomu()
{
 unsigned int u = get_urandom();
 double numer = (double)u;
 double denom = 4294967296.0;
 return (double)(numer/denom);
}

variable_types:
u
unsigned int

variable_types: numer double

variable_types: denom double


decompiled_code:
int __fastcall print_lattice(_QWORD *a1, _QWORD *a2, _QWORD *a3, int a4, int a5, _DWORD *a6, _DWORD *a7)
{
int i; // ebx
int v11; // ebp
int v12; // ebx
int v13; // eax
int v14; // ebp
__int64 j; // rbx
__int64 v16; // rax
__int64 v17; // rbx
int v18; // ebx
__int64 v21; // [rsp+18h] [rbp-50h]

if ( a5 <= 0 )
{
puts("ooo");
printf("o ");
puts("o");
if ( a4 <= 0 )
return puts("ooo");
}
else
{
for ( i = 0; i != a5; ++i )
{
v11 = i;
printf("oooo");
}
v12 = 0;
puts("ooo");
printf("o ");
do
{
printf(" ");
v13 = v12++;
}
while ( v13 != v11 );
puts("o");
if ( a4 <= 0 )
{
LABEL_28:
v18 = 0;
do
{
++v18;
printf("oooo");
}
while ( a5 != v18 );
return puts("ooo");
}
}
v14 = 0;
v21 = (unsigned int)(a5 - 1);
do
{
printf("o ");
if ( a5 <= 0 )
{
puts("o");
printf("o ");
goto LABEL_26;
}
for ( j = 0LL; ; j = v16 )
{
if ( *a6 == v14 && a6[1] == (_DWORD)j )
{
putchar(65);
}
else if ( *a7 == v14 && a7[1] == (_DWORD)j )
{
putchar(66);
}
else
{
putchar(*(_DWORD *)(*a1 + 4 * j));
}
if ( !*(_DWORD *)(*a3 + 4 * j) )
break;
printf(" - ");
v16 = j + 1;
if ( j == v21 )
goto LABEL_18;
LABEL_11:
;
}
printf(" ");
v16 = j + 1;
if ( j != v21 )
goto LABEL_11;
LABEL_18:
v17 = 0LL;
puts("o");
printf("o ");
do
{
if ( *(_DWORD *)(*a2 + v17) )
putchar(124);
else
putchar(32);
v17 += 4LL;
printf(" ");
}
while ( 4 * v21 + 4 != v17 );
LABEL_26:
++v14;
++a2;
++a3;
puts("o");
++a1;
}
while ( a4 != v14 );
if ( a5 > 0 )
goto LABEL_28;
return puts("ooo");
}

canonical_decompiled_code:
int __fastcall func0(_QWORD *a1, _QWORD *a2, _QWORD *a3, int a4, int a5, _DWORD *a6, _DWORD *a7)
{
int i; // ebx
int v11; // ebp
int v12; // ebx
int v13; // eax
int v14; // ebp
__int64 j; // rbx
__int64 v16; // rax
__int64 v17; // rbx
int v18; // ebx
__int64 v21; // [rsp+18h] [rbp-50h]

if ( a5 <= 0 )
{
puts("ooo");
printf("o ");
puts("o");
if ( a4 <= 0 )
return puts("ooo");
}
else
{
for ( i = 0; i != a5; ++i )
{
v11 = i;
printf("oooo");
}
v12 = 0;
puts("ooo");
printf("o ");
do
{
printf(" ");
v13 = v12++;
}
while ( v13 != v11 );
puts("o");
if ( a4 <= 0 )
{
LABEL_28:
v18 = 0;
do
{
++v18;
printf("oooo");
}
while ( a5 != v18 );
return puts("ooo");
}
}
v14 = 0;
v21 = (unsigned int)(a5 - 1);
do
{
printf("o ");
if ( a5 <= 0 )
{
puts("o");
printf("o ");
goto LABEL_26;
}
for ( j = 0LL; ; j = v16 )
{
if ( *a6 == v14 && a6[1] == (_DWORD)j )
{
putchar(65);
}
else if ( *a7 == v14 && a7[1] == (_DWORD)j )
{
putchar(66);
}
else
{
putchar(*(_DWORD *)(*a1 + 4 * j));
}
if ( !*(_DWORD *)(*a3 + 4 * j) )
break;
printf(" - ");
v16 = j + 1;
if ( j == v21 )
goto LABEL_18;
LABEL_11:
;
}
printf(" ");
v16 = j + 1;
if ( j != v21 )
goto LABEL_11;
LABEL_18:
v17 = 0LL;
puts("o");
printf("o ");
do
{
if ( *(_DWORD *)(*a2 + v17) )
putchar(124);
else
putchar(32);
v17 += 4LL;
printf(" ");
}
while ( 4 * v21 + 4 != v17 );
LABEL_26:
++v14;
++a2;
++a3;
puts("o");
++a1;
}
while ( a4 != v14 );
if ( a5 > 0 )
goto LABEL_28;
return puts("ooo");
}

original_code:
void print_lattice(int** site_marks, int** vbonds, int** hbonds,
 int M, int N, int A1[2], int A2[2])
{
 int i, j;
 int ij[2];
 for (j = 0; j < N; j++)
  printf("oooo");
 printf("ooo\n");
 printf("o ");
 for (j = 0; j < N; j++)
  printf("    ");
 printf("o\n");
 for (i = 0; i < M; i++) {
  printf("o ");
  for (j = 0; j < N; j++) {
   ij[0] = i;
   ij[1] = j;
   if ((((ij)[0]==(A1)[0])&&((ij)[1]==(A1)[1])))
    printf("A");
   else if ((((ij)[0]==(A2)[0])&&((ij)[1]==(A2)[1])))
    printf("B");
   else
    printf("%c", site_marks[i][j]);
   if (j < N) {
    if (hbonds[i][j])
     printf(" - ");
    else
     printf("   ");
   }
  }
  printf("o\n");
  if (i < M) {
   printf("o ");
   for (j = 0; j < N; j++) {
    if (vbonds[i][j])
     printf("|");
    else
     printf(" ");
    if (j < N)
     printf("   ");
   }
   printf("o\n");
  }
 }
 for (j = 0; j < N; j++)
  printf("oooo");
 printf("ooo\n");
}

canonical_original_code:
void print_lattice(int **site_marks, int **vbonds, int **hbonds, int M, int N, int A1[2], int A2[2])
{
 int i; int j;
 int ij[2];
 for (j = 0; j < N; j++)
  printf("oooo");
 printf("ooo\n");
 printf("o ");
 for (j = 0; j < N; j++)
  printf("    ");
 printf("o\n");
 for (i = 0; i < M; i++) {
  printf("o ");
  for (j = 0; j < N; j++) {
   ij[0] = i;
   ij[1] = j;
   if ((((ij)[0]==(A1)[0])&&((ij)[1]==(A1)[1])))
    printf("A");
   else if ((((ij)[0]==(A2)[0])&&((ij)[1]==(A2)[1])))
    printf("B");
   else
    printf("%c", site_marks[i][j]);
   if (j < N) {
    if (hbonds[i][j])
     printf(" - ");
    else
     printf("   ");
   }
  }
  printf("o\n");
  if (i < M) {
   printf("o ");
   for (j = 0; j < N; j++) {
    if (vbonds[i][j])
     printf("|");
    else
     printf(" ");
    if (j < N)
     printf("   ");
   }
   printf("o\n");
  }
 }
 for (j = 0; j < N; j++)
  printf("oooo");
 printf("ooo\n");
}

variable_types:
vbonds
int **

variable_types:
hbonds
int **

variable_types: M int

variable_types: N int

variable_types: i int

variable_types: j int

variable_types:
ij
int [2]


original_code:
void print_lattice_and_cluster_numbers(int** site_marks,
 int** vbonds, int** hbonds, int M, int N)
{
 int i, j;
 int ij[2];
 for (j = 0; j < N; j++)
  printf("oooo");
 printf("ooo\n");
 printf("o ");
 for (j = 0; j < N; j++)
  printf("    ");
 printf("o\n");
 for (i = 0; i < M; i++) {
  printf("o ");
  for (j = 0; j < N; j++) {
   ij[0] = i;
   ij[1] = j;
   printf("%d", site_marks[i][j]);
   if (j < N) {
    if (hbonds[i][j])
     printf(" - ");
    else
     printf("   ");
   }
  }
  printf("o\n");
  if (i < M) {
   printf("o ");
   for (j = 0; j < N; j++) {
    if (vbonds[i][j])
     printf("|");
    else
     printf(" ");
    if (j < N)
     printf("   ");
   }
   printf("o\n");
  }
 }
 for (j = 0; j < N; j++)
  printf("oooo");
 printf("ooo\n");
}

canonical_original_code:
void print_lattice_and_cluster_numbers(int **site_marks, int **vbonds, int **hbonds, int M, int N)
{
 int i; int j;
 int ij[2];
 for (j = 0; j < N; j++)
  printf("oooo");
 printf("ooo\n");
 printf("o ");
 for (j = 0; j < N; j++)
  printf("    ");
 printf("o\n");
 for (i = 0; i < M; i++) {
  printf("o ");
  for (j = 0; j < N; j++) {
   ij[0] = i;
   ij[1] = j;
   printf("%d", site_marks[i][j]);
   if (j < N) {
    if (hbonds[i][j])
     printf(" - ");
    else
     printf("   ");
   }
  }
  printf("o\n");
  if (i < M) {
   printf("o ");
   for (j = 0; j < N; j++) {
    if (vbonds[i][j])
     printf("|");
    else
     printf(" ");
    if (j < N)
     printf("   ");
   }
   printf("o\n");
  }
 }
 for (j = 0; j < N; j++)
  printf("oooo");
 printf("ooo\n");
}


decompiled_code:
int show_usage()
{
return puts(
"\n"
"Usage: ascii-only [-r replacement] [-l log_file ] [-i input_file] [-o output_file]\n"
"\n"
" Missing input/output files default to stdin/stdout.\n"
" Replacement is one of the following: \n"
" character\n"
" hex constant ( i.e., 0x3F )\n"
" integer from 0 to 255 with decimal point ( i.e., 132. )\n");
}

canonical_decompiled_code:
int func7()
{
return puts(
"\n"
"Usage: ascii-only [-r replacement] [-l log_file ] [-i input_file] [-o output_file]\n"
"\n"
" Missing input/output files default to stdin/stdout.\n"
" Replacement is one of the following: \n"
" character\n"
" hex constant ( i.e., 0x3F )\n"
" integer from 0 to 255 with decimal point ( i.e., 132. )\n");
}

original_code:
void show_usage()
{
    printf("\nUsage: "
           "ascii-only [-r replacement] [-l log_file ] [-i input_file] [-o output_file]\n\n"
           "  Missing input/output files default to stdin/stdout.\n"
           "  Replacement is one of the following: \n"
           "   character\n"
           "   hex constant ( i.e., 0x3F )\n"
           "   integer from 0 to 255 with decimal point ( i.e., 132. )\n\n");
}


decompiled_code:
__int64 __fastcall determine_replacement(int a1, __int64 a2, __int64 a3)
{
const char **v3; // r12
const char *v4; // rdi
const char *v5; // rbx
unsigned int v6; // er12
int v8; // [rsp+8h] [rbp-20h]
unsigned int v9; // [rsp+Ch] [rbp-1Ch]

v3 = (const char **)(a3 + 8LL * a1);
v4 = *v3;
if ( *v3 )
{
if ( (v4[1] & 0xDF) == 88 )
{
if ( (unsigned int)__isoc99_sscanf() == 1 )
{
v5 = *v3;
if ( **v3 == 48 )
{
v6 = v9;
if ( v9 <= 0xFF && strlen(v5) <= 4 )
{
LABEL_7:
if ( !v5[v8] )
return v6;
return 0xFFFFFFFFLL;
}
}
}
}
else
{
if ( !v4[1] )
return (unsigned int)*v4;
if ( (unsigned int)__isoc99_sscanf() == 1 )
{
v5 = *v3;
if ( strlen(*v3) <= 4 )
{
v6 = v9;
if ( v9 <= 0xFF )
goto LABEL_7;
}
}
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, __int64 a2, __int64 a3)
{
const char **v3; // r12
const char *v4; // rdi
const char *v5; // rbx
unsigned int v6; // er12
int v8; // [rsp+8h] [rbp-20h]
unsigned int v9; // [rsp+Ch] [rbp-1Ch]

v3 = (const char **)(a3 + 8LL * a1);
v4 = *v3;
if ( *v3 )
{
if ( (v4[1] & 0xDF) == 88 )
{
if ( (unsigned int)__isoc99_sscanf() == 1 )
{
v5 = *v3;
if ( **v3 == 48 )
{
v6 = v9;
if ( v9 <= 0xFF && strlen(v5) <= 4 )
{
LABEL_7:
if ( !v5[v8] )
return v6;
return 0xFFFFFFFFLL;
}
}
}
}
else
{
if ( !v4[1] )
return (unsigned int)*v4;
if ( (unsigned int)__isoc99_sscanf() == 1 )
{
v5 = *v3;
if ( strlen(*v3) <= 4 )
{
v6 = v9;
if ( v9 <= 0xFF )
goto LABEL_7;
}
}
}
}
return 0xFFFFFFFFLL;
}

original_code:
int determine_replacement(int i, int argc, char **argv)
{
    int n, R, res;
    if (argv[i]) {
        switch(argv[i][1]) {
            case 'X':
            case 'x':
                res = sscanf(argv[i],"%x%n", &R,&n);
                if ((res != 1) || (argv[i][0] != '0') ||
                    (R < 0) || (R > 255) ||
                    (strlen(argv[i]) > 4) || (argv[i][n]))
                    break;
                 return R;
            case 0 :
                R = argv[i][0];
                return R;
            default :
                res = sscanf(argv[i],"%d.%n", &R,&n);
                if ((res != 1) || (strlen(argv[i]) > 4) ||
                    (R < 0) || (R > 255) || (argv[i][n]))
                    break;
                return R;
        }
    }
    return -1;
}

canonical_original_code:
int determine_replacement(int i, int argc, char **argv)
{
    int n; int R; int res;
    if (argv[i]) {
        switch(argv[i][1]) {
            case 'X':
            case 'x':
                res = sscanf(argv[i],"%x%n", &R,&n);
                if ((res != 1) || (argv[i][0] != '0') ||
                    (R < 0) || (R > 255) ||
                    (strlen(argv[i]) > 4) || (argv[i][n]))
                    break;
                 return R;
            case 0 :
                R = argv[i][0];
                return R;
            default :
                res = sscanf(argv[i],"%d.%n", &R,&n);
                if ((res != 1) || (strlen(argv[i]) > 4) ||
                    (R < 0) || (R > 255) || (argv[i][n]))
                    break;
                return R;
        }
    }
    return -1;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: n int

variable_types: R int

variable_types: res int


option

decompiled_code:
__int64 __fastcall option(char *s1, int a2, __int64 a3, int *a4)
{
__int64 v6; // rbx
__int64 v7; // r13
unsigned int v8; // er14

if ( a2 > 1 )
{
v6 = 2LL;
v7 = (unsigned int)(a2 + 1);
v8 = 0;
while ( 1 )
{
if ( strcmp(s1, *(const char **)(a3 + 8 * v6 - 8)) )
goto LABEL_4;
if ( v8 )
{
*a4 = a2;
LABEL_4:
if ( ++v6 == v7 )
return v8;
}
else
{
v8 = v6++;
*a4 += 2;
if ( v6 == v7 )
return v8;
}
}
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *s1, int a2, __int64 a3, int *a4)
{
__int64 v6; // rbx
__int64 v7; // r13
unsigned int v8; // er14

if ( a2 > 1 )
{
v6 = 2LL;
v7 = (unsigned int)(a2 + 1);
v8 = 0;
while ( 1 )
{
if ( strcmp(s1, *(const char **)(a3 + 8 * v6 - 8)) )
goto LABEL_4;
if ( v8 )
{
*a4 = a2;
LABEL_4:
if ( ++v6 == v7 )
return v8;
}
else
{
v8 = v6++;
*a4 += 2;
if ( v6 == v7 )
return v8;
}
}
}
return 0;
}

original_code:
int option(char *s, int argc, char **argv, int *flags)
{
    int i, j;
    for (i = 0, j = 1; j < argc; j++) {
        if (!strcmp(s, argv[j])) {
            if (i)
                *flags = argc;
            else {
                i = j+1;
                *flags += 2;
            }
        }
    }
    return i;
}

canonical_original_code:
int option(char *s, int argc, char **argv, int *flags)
{
    int i; int j;
    for (i = 0, j = 1; j < argc; j++) {
        if (!strcmp(s, argv[j])) {
            if (i)
                *flags = argc;
            else {
                i = j+1;
                *flags += 2;
            }
        }
    }
    return i;
}

variable_types:
s
char *

variable_types:
flags
int *


main

canonical_name: main

repo: johnpeck/boxcom

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("bignum is %u\r\n", 4233600LL);
return 0;
}

original_code:
int main(void) {
  uint32_t bignum = 4233600;
  printf("bignum is %u\r\n",bignum);
  return 0;
}

canonical_original_code:
int main() {
  unsigned int bignum = 4233600;
  printf("bignum is %u\r\n",bignum);
  return 0;
}

variable_types:
bignum
unsigned int


repo: johnpmayer/makerbardrumset

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

setbuf(_bss_start, 0LL);
while ( 1 )
{
read(0, buf, 1uLL);
playShit(buf[0]);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

setbuf(_bss_start, 0LL);
while ( 1 )
{
read(0, buf, 1uLL);
func8(buf[0]);
}
}

original_code:
int main() {
  setbuf(stdout, ((void *)0));
  while(1) {
    int c;
    read(0,&c,1);
    playShit(c);
  }
}

variable_types: c int


p

decompiled_code:
int __fastcall p(const char *a1)
{
puts(a1);
return fflush(_bss_start);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
puts(a1);
return fflush(_bss_start);
}

original_code:
void p(char* s) {
  printf("%s\n",s);
  fflush(stdout);
}

canonical_original_code:
void p(char *s) {
  printf("%s\n",s);
  fflush(stdout);
}


playShit

decompiled_code:
int __fastcall playShit(unsigned __int8 a1)
{
int *v1; // rax
int v2; // er12
int *v3; // rbp
__pid_t v4; // eax
int result; // eax
int v6; // er12
int v7; // ebp
const char *v8; // rbx
__pid_t v9; // ebx
int stat_loc; // [rsp+Ch] [rbp-6Ch] BYREF
char *argv[3]; // [rsp+10h] [rbp-68h] BYREF
__int128 v12; // [rsp+28h] [rbp-50h]
__int128 v13; // [rsp+38h] [rbp-40h]
__int128 v14; // [rsp+48h] [rbp-30h]
__int64 v15; // [rsp+58h] [rbp-20h]

v1 = __errno_location();
v2 = *v1;
v3 = v1;
while ( 1 )
{
v4 = waitpid(-1, &stat_loc, 1);
if ( v4 < 0 )
break;
if ( !v4 )
goto LABEL_6;
printf("Pid terminated %d\n", (unsigned int)v4);
fflush(_bss_start);
++finished;
}
perror("waitpid");
LABEL_6:
*v3 = v2;
if ( started - finished > 7 )
return puts("Too many");
result = a1 - 48;
switch ( a1 )
{
case '0':
result = shakeMode;
if ( shakeMode && shakePid > 0 )
{
v6 = 0;
v7 = 0;
v8 = "Samples/pickupneedle.mp3";
kill(shakePid, 9);
shakeMode = 0;
p("killed track");
shakePid = 0;
goto LABEL_11;
}
return result;
case '1':
if ( shakeMode != 1 )
{
if ( shakePid > 0 )
kill(shakePid, 9);
v6 = 0;
v7 = 1;
v8 = "Samples/shake1.mp3";
shakeMode = 1;
goto LABEL_11;
}
return result;
case '2':
if ( shakeMode != 2 )
{
if ( shakePid > 0 )
kill(shakePid, 9);
v6 = 0;
v7 = 1;
v8 = "Samples/shake2.mp3";
shakeMode = 2;
goto LABEL_11;
}
return result;
case 'F':
fp1 = 0;
return p("DS1 Foot Pedal up");
case 'T':
case 't':
v6 = 0;
v7 = 0;
v8 = "Samples/rimshot.mp3";
goto LABEL_11;
case 'X':
redButton = 0;
return result;
case 'Y':
greenButton = 0;
return result;
case 'Z':
blueButton = 0;
return result;
case 'a':
v6 = 0;
v7 = 0;
v8 = "Samples/chip snare.mp3";
goto LABEL_11;
case 'b':
v6 = 0;
v7 = 0;
v8 = "Samples/chip kick.mp3";
goto LABEL_11;
case 'c':
v6 = 0;
v7 = 0;
v8 = "Samples/chip boom.mp3";
goto LABEL_11;
case 'd':
v6 = 0;
v7 = 0;
v8 = "Samples/bleep.mp3";
goto LABEL_11;
case 'e':
v7 = fp1;
v6 = 0;
v8 = "Samples/TR8-808CX 46 OHH 2.mp3";
if ( fp1 )
{
v7 = 0;
v8 = "Samples/TR8-808CX 42 CHH 2.mp3";
}
goto LABEL_11;
case 'f':
fp1 = 1;
return result;
case 'g':
v6 = 0;
v7 = 0;
v8 = "Samples/808 wet snare.mp3";
goto LABEL_11;
case 'h':
v6 = 0;
v7 = 0;
v8 = "Samples/TR8-808CX 48 HTL 1.mp3";
goto LABEL_11;
case 'i':
v6 = 0;
v7 = 0;
v8 = "Samples/TR8-808CX 45 MTL 2.mp3";
goto LABEL_11;
case 'j':
v6 = 0;
v7 = 0;
v8 = "Samples/COWBELL.mp3";
goto LABEL_11;
case 'k':
v6 = 0;
v7 = 0;
v8 = "Samples/TR8-808CX 52 CYH 5.mp3";
goto LABEL_11;
case 'l':
v6 = 0;
v7 = 0;
v8 = "Samples/TR8-808CX 36 BD2 4.mp3";
goto LABEL_11;
case 'm':
v6 = 0;
v7 = 0;
v8 = "Samples/click.mp3";
goto LABEL_11;
case 'n':
v6 = 0;
v7 = 0;
v8 = "Samples/bongo.mp3";
goto LABEL_11;
case 'o':
v6 = 0;
v7 = 0;
v8 = "Samples/explosion.mp3";
goto LABEL_11;
case 'p':
v6 = 0;
v7 = 0;
v8 = "Samples/laser.mp3";
goto LABEL_11;
case 'q':
v6 = 0;
v7 = 0;
v8 = "Samples/clap.mp3";
goto LABEL_11;
case 'r':
v6 = 0;
v7 = 0;
v8 = "Samples/gong.mp3";
goto LABEL_11;
case 's':
v6 = 1;
v7 = 0;
v8 = "Samples/airhorn.mp3";
if ( airhornPid > 0 )
{
kill(airhornPid, 9);
airhornPid = 0;
}
goto LABEL_11;
case 'u':
v6 = 0;
v7 = 0;
v8 = "Samples/robot 1.mp3";
goto LABEL_11;
case 'w':
v6 = 0;
v7 = 0;
v8 = "Samples/robot 2.mp3";
LABEL_11:
printf("%s\r\n", v8);
fflush(_bss_start);
argv[2] = (char *)v8;
v15 = 0LL;
argv[0] = mpg;
argv[1] = "--quiet";
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v9 = fork();
if ( v9 )
{
printf("Children: %d\n", (unsigned int)(++started - finished));
result = fflush(_bss_start);
}
else
{
result = execv(mpg, argv);
}
if ( v7 == 1 )
shakePid = v9;
if ( v6 == 1 )
airhornPid = v9;
break;
case 'x':
redButton = 1;
break;
case 'y':
greenButton = 1;
break;
case 'z':
blueButton = 1;
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(unsigned __int8 a1)
{
int *v1; // rax
int v2; // er12
int *v3; // rbp
__pid_t v4; // eax
int result; // eax
int v6; // er12
int v7; // ebp
const char *v8; // rbx
__pid_t v9; // ebx
int stat_loc; // [rsp+Ch] [rbp-6Ch] BYREF
char *argv[3]; // [rsp+10h] [rbp-68h] BYREF
__int128 v12; // [rsp+28h] [rbp-50h]
__int128 v13; // [rsp+38h] [rbp-40h]
__int128 v14; // [rsp+48h] [rbp-30h]
__int64 v15; // [rsp+58h] [rbp-20h]

v1 = __errno_location();
v2 = *v1;
v3 = v1;
while ( 1 )
{
v4 = waitpid(-1, &stat_loc, 1);
if ( v4 < 0 )
break;
if ( !v4 )
goto LABEL_6;
printf("Pid terminated %d\n", (unsigned int)v4);
fflush(_bss_start);
++finished;
}
perror("waitpid");
LABEL_6:
*v3 = v2;
if ( started - finished > 7 )
return puts("Too many");
result = a1 - 48;
switch ( a1 )
{
case '0':
result = shakeMode;
if ( shakeMode && shakePid > 0 )
{
v6 = 0;
v7 = 0;
v8 = "Samples/pickupneedle.mp3";
kill(shakePid, 9);
shakeMode = 0;
func7("killed track");
shakePid = 0;
goto LABEL_11;
}
return result;
case '1':
if ( shakeMode != 1 )
{
if ( shakePid > 0 )
kill(shakePid, 9);
v6 = 0;
v7 = 1;
v8 = "Samples/shake1.mp3";
shakeMode = 1;
goto LABEL_11;
}
return result;
case '2':
if ( shakeMode != 2 )
{
if ( shakePid > 0 )
kill(shakePid, 9);
v6 = 0;
v7 = 1;
v8 = "Samples/shake2.mp3";
shakeMode = 2;
goto LABEL_11;
}
return result;
case 'F':
fp1 = 0;
return func7("DS1 Foot Pedal up");
case 'T':
case 't':
v6 = 0;
v7 = 0;
v8 = "Samples/rimshot.mp3";
goto LABEL_11;
case 'X':
redButton = 0;
return result;
case 'Y':
greenButton = 0;
return result;
case 'Z':
blueButton = 0;
return result;
case 'a':
v6 = 0;
v7 = 0;
v8 = "Samples/chip snare.mp3";
goto LABEL_11;
case 'b':
v6 = 0;
v7 = 0;
v8 = "Samples/chip kick.mp3";
goto LABEL_11;
case 'c':
v6 = 0;
v7 = 0;
v8 = "Samples/chip boom.mp3";
goto LABEL_11;
case 'd':
v6 = 0;
v7 = 0;
v8 = "Samples/bleep.mp3";
goto LABEL_11;
case 'e':
v7 = fp1;
v6 = 0;
v8 = "Samples/TR8-808CX 46 OHH 2.mp3";
if ( fp1 )
{
v7 = 0;
v8 = "Samples/TR8-808CX 42 CHH 2.mp3";
}
goto LABEL_11;
case 'f':
fp1 = 1;
return result;
case 'g':
v6 = 0;
v7 = 0;
v8 = "Samples/808 wet snare.mp3";
goto LABEL_11;
case 'h':
v6 = 0;
v7 = 0;
v8 = "Samples/TR8-808CX 48 HTL 1.mp3";
goto LABEL_11;
case 'i':
v6 = 0;
v7 = 0;
v8 = "Samples/TR8-808CX 45 MTL 2.mp3";
goto LABEL_11;
case 'j':
v6 = 0;
v7 = 0;
v8 = "Samples/COWBELL.mp3";
goto LABEL_11;
case 'k':
v6 = 0;
v7 = 0;
v8 = "Samples/TR8-808CX 52 CYH 5.mp3";
goto LABEL_11;
case 'l':
v6 = 0;
v7 = 0;
v8 = "Samples/TR8-808CX 36 BD2 4.mp3";
goto LABEL_11;
case 'm':
v6 = 0;
v7 = 0;
v8 = "Samples/click.mp3";
goto LABEL_11;
case 'n':
v6 = 0;
v7 = 0;
v8 = "Samples/bongo.mp3";
goto LABEL_11;
case 'o':
v6 = 0;
v7 = 0;
v8 = "Samples/explosion.mp3";
goto LABEL_11;
case 'p':
v6 = 0;
v7 = 0;
v8 = "Samples/laser.mp3";
goto LABEL_11;
case 'q':
v6 = 0;
v7 = 0;
v8 = "Samples/clap.mp3";
goto LABEL_11;
case 'r':
v6 = 0;
v7 = 0;
v8 = "Samples/gong.mp3";
goto LABEL_11;
case 's':
v6 = 1;
v7 = 0;
v8 = "Samples/airhorn.mp3";
if ( airhornPid > 0 )
{
kill(airhornPid, 9);
airhornPid = 0;
}
goto LABEL_11;
case 'u':
v6 = 0;
v7 = 0;
v8 = "Samples/robot 1.mp3";
goto LABEL_11;
case 'w':
v6 = 0;
v7 = 0;
v8 = "Samples/robot 2.mp3";
LABEL_11:
printf("%s\r\n", v8);
fflush(_bss_start);
argv[2] = (char *)v8;
v15 = 0LL;
argv[0] = mpg;
argv[1] = "--quiet";
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v9 = fork();
if ( v9 )
{
printf("Children: %d\n", (unsigned int)(++started - finished));
result = fflush(_bss_start);
}
else
{
result = execv(mpg, argv);
}
if ( v7 == 1 )
shakePid = v9;
if ( v6 == 1 )
airhornPid = v9;
break;
case 'x':
redButton = 1;
break;
case 'y':
greenButton = 1;
break;
case 'z':
blueButton = 1;
break;
default:
return result;
}
return result;
}

original_code:
void playShit(int keyCode) {
  int pid, status, serrno;
  serrno = (*__errno_location ());
  while (1)
  {
    pid = waitpid ((-1), &status, 1);
    if (pid < 0)
    {
      perror ("waitpid");
      break;
    }
    if (pid == 0)
      break;
    printf("Pid terminated %d\n",pid);
    fflush(stdout);
    finished++;
  }
  (*__errno_location ()) = serrno;
  if ((started - finished) >= 8) {
    printf("Too many\n");
    return;
  }
  char* fname = ((void *)0);
  int setShakePid = 0;
  int setAirhornPid = 0;
  switch((char)keyCode & 0xFF) {
    case 'a':
      fname = "Samples/chip snare.mp3";
      break;
    case 'b':
      fname = "Samples/chip kick.mp3";
      break;
    case 'c':
      fname = "Samples/chip boom.mp3";
      break;
    case 'd':
      fname = "Samples/bleep.mp3";
      break;
    case 'e':
      fname = fp1 ? "Samples/TR8-808CX 42 CHH 2.mp3"
        : "Samples/TR8-808CX 46 OHH 2.mp3";
      break;
    case 'f':
      fp1 = 1;
      break;
    case 'F':
      fp1 = 0;
      p("DS1 Foot Pedal up");
      return;
    case 'g':
      fname = "Samples/808 wet snare.mp3";
      break;
    case 'h':
      fname = "Samples/TR8-808CX 48 HTL 1.mp3";
      break;
    case 'i':
      fname = "Samples/TR8-808CX 45 MTL 2.mp3";
      break;
    case 'j':
      fname = "Samples/COWBELL.mp3";
      break;
    case 'k':
      fname = "Samples/TR8-808CX 52 CYH 5.mp3";
      break;
    case 'l':
      fname = "Samples/TR8-808CX 36 BD2 4.mp3";
      break;
    case 'm':
      fname = "Samples/click.mp3";
      break;
    case 'n':
      fname = "Samples/bongo.mp3";
      break;
    case 'o':
      fname = "Samples/explosion.mp3";
      break;
    case 'p':
      fname = "Samples/laser.mp3";
      break;
    case 'q':
      fname = "Samples/clap.mp3";
      break;
    case 'r':
      fname = "Samples/gong.mp3";
      break;
    case 's':
      if (airhornPid > 0) {
        kill(airhornPid, 9);
        airhornPid = 0;
      }
      fname = "Samples/airhorn.mp3";
      setAirhornPid = 1;
      break;
    case 't':
    case 'T':
      fname = "Samples/rimshot.mp3";
      break;
    case 'u':
      fname = "Samples/robot 1.mp3";
      break;
    case 'w':
      fname = "Samples/robot 2.mp3";
      break;
    case 'x':
      redButton = 1;
      break;
    case 'X':
      redButton = 0;
      break;
    case 'y':
      greenButton = 1;
      break;
    case 'Y':
      greenButton = 0;
      break;
    case 'z':
      blueButton = 1;
      break;
    case 'Z':
      blueButton = 0;
      break;
    case '0':
      if (shakeMode != 0 && shakePid > 0) {
        kill(shakePid, 9);
        shakeMode = 0;
        p("killed track");
        fname = "Samples/pickupneedle.mp3";
        shakePid = 0;
      }
      break;
    case '1':
      if (shakeMode != 1) {
        if (shakePid > 0) kill(shakePid, 9);
        fname = "Samples/shake1.mp3";
        setShakePid = 1;
        shakeMode = 1;
      }
      break;
    case '2':
      if (shakeMode != 2) {
        if (shakePid > 0) kill(shakePid, 9);
        fname = "Samples/shake2.mp3";
        setShakePid = 1;
        shakeMode = 2;
      }
      break;
  }
  if (fname != ((void *)0))
  {
    printf("%s\r\n", fname);
    fflush(stdout);
    char* const args[10] = { (char*)mpg, "--quiet", (char*)fname, ((void *)0) };
    int pid = fork();
    if (pid == 0) {
      execv(mpg, args);
    } else {
      started++;
      printf("Children: %d\n", (started - finished));
      fflush(stdout);
    }
    if (setShakePid == 1) {
      shakePid = pid;
    }
    if (setAirhornPid == 1) {
      airhornPid = pid;
    }
  }
}

canonical_original_code:
void playShit(int keyCode) {
  int pid; int status; int serrno;
  serrno = (*__errno_location ());
  while (1)
  {
    pid = waitpid ((-1), &status, 1);
    if (pid < 0)
    {
      perror ("waitpid");
      break;
    }
    if (pid == 0)
      break;
    printf("Pid terminated %d\n",pid);
    fflush(stdout);
    finished++;
  }
  (*__errno_location ()) = serrno;
  if ((started - finished) >= 8) {
    printf("Too many\n");
    return;
  }
  char *fname = ((void *)0);
  int setShakePid = 0;
  int setAirhornPid = 0;
  switch((char)keyCode & 0xFF) {
    case 'a':
      fname = "Samples/chip snare.mp3";
      break;
    case 'b':
      fname = "Samples/chip kick.mp3";
      break;
    case 'c':
      fname = "Samples/chip boom.mp3";
      break;
    case 'd':
      fname = "Samples/bleep.mp3";
      break;
    case 'e':
      fname = fp1 ? "Samples/TR8-808CX 42 CHH 2.mp3"
        : "Samples/TR8-808CX 46 OHH 2.mp3";
      break;
    case 'f':
      fp1 = 1;
      break;
    case 'F':
      fp1 = 0;
      p("DS1 Foot Pedal up");
      return;
    case 'g':
      fname = "Samples/808 wet snare.mp3";
      break;
    case 'h':
      fname = "Samples/TR8-808CX 48 HTL 1.mp3";
      break;
    case 'i':
      fname = "Samples/TR8-808CX 45 MTL 2.mp3";
      break;
    case 'j':
      fname = "Samples/COWBELL.mp3";
      break;
    case 'k':
      fname = "Samples/TR8-808CX 52 CYH 5.mp3";
      break;
    case 'l':
      fname = "Samples/TR8-808CX 36 BD2 4.mp3";
      break;
    case 'm':
      fname = "Samples/click.mp3";
      break;
    case 'n':
      fname = "Samples/bongo.mp3";
      break;
    case 'o':
      fname = "Samples/explosion.mp3";
      break;
    case 'p':
      fname = "Samples/laser.mp3";
      break;
    case 'q':
      fname = "Samples/clap.mp3";
      break;
    case 'r':
      fname = "Samples/gong.mp3";
      break;
    case 's':
      if (airhornPid > 0) {
        kill(airhornPid, 9);
        airhornPid = 0;
      }
      fname = "Samples/airhorn.mp3";
      setAirhornPid = 1;
      break;
    case 't':
    case 'T':
      fname = "Samples/rimshot.mp3";
      break;
    case 'u':
      fname = "Samples/robot 1.mp3";
      break;
    case 'w':
      fname = "Samples/robot 2.mp3";
      break;
    case 'x':
      redButton = 1;
      break;
    case 'X':
      redButton = 0;
      break;
    case 'y':
      greenButton = 1;
      break;
    case 'Y':
      greenButton = 0;
      break;
    case 'z':
      blueButton = 1;
      break;
    case 'Z':
      blueButton = 0;
      break;
    case '0':
      if (shakeMode != 0 && shakePid > 0) {
        kill(shakePid, 9);
        shakeMode = 0;
        p("killed track");
        fname = "Samples/pickupneedle.mp3";
        shakePid = 0;
      }
      break;
    case '1':
      if (shakeMode != 1) {
        if (shakePid > 0) kill(shakePid, 9);
        fname = "Samples/shake1.mp3";
        setShakePid = 1;
        shakeMode = 1;
      }
      break;
    case '2':
      if (shakeMode != 2) {
        if (shakePid > 0) kill(shakePid, 9);
        fname = "Samples/shake2.mp3";
        setShakePid = 1;
        shakeMode = 2;
      }
      break;
  }
  if (fname != ((void *)0))
  {
    printf("%s\r\n", fname);
    fflush(stdout);
    char *args[10] = { (char*)mpg, "--quiet", (char*)fname, ((void *)0) };
    int pid = fork();
    if (pid == 0) {
      execv(mpg, args);
    } else {
      started++;
      printf("Children: %d\n", (started - finished));
      fflush(stdout);
    }
    if (setShakePid == 1) {
      shakePid = pid;
    }
    if (setAirhornPid == 1) {
      airhornPid = pid;
    }
  }
}

variable_types: keyCode int

variable_types: pid int

variable_types: status int

variable_types: serrno int

variable_types:
fname
char *

variable_types: setShakePid int

variable_types: setAirhornPid int

variable_types:
args
char *[10]


decompiled_code:
__int64 timeout_cb()
{
(*(void (__fastcall **)(__int64, __int64))(ph + 40))(ph, timeout_hook);
minimized = 1;
return 3LL;
}

canonical_decompiled_code:
__int64 func1()
{
(*(void (__fastcall **)(__int64, __int64))(ph + 40))(ph, timeout_hook);
minimized = 1;
return 3LL;
}

original_code:
static int timeout_cb(void *user_data)
{
  (((ph))->xchat_unhook)(ph, timeout_hook);
  minimized = 1;
  return (1|2);
}


repo: jojje/command-wrapper

decompiled_code:
void *__fastcall malloc_string(size_t a1, int a2)
{
const char *v2; // rdx
void *v3; // r12

v3 = malloc(a1);
if ( !v3 )
error((int)"Failed to allocate memory\n", a2, v2);
return v3;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1, int a2)
{
const char *v2; // rdx
void *v3; // r12

v3 = malloc(a1);
if ( !v3 )
error((int)"Failed to allocate memory\n", a2, v2);
return v3;
}

original_code:
char* malloc_string(size_t size) {
  char* s = (char*) malloc(size);
  if(!s) {
    error("Failed to allocate memory\n");
  }
  return s;
}

canonical_original_code:
char *malloc_string(unsigned long size) {
  char *s = (char*) malloc(size);
  if(!s) {
    error("Failed to allocate memory\n");
  }
  return s;
}

variable_types:
size
unsigned long


decompiled_code:
int __fastcall join_path(char *a1, const char *a2, const char *a3)
{
return snprintf(a1, 0x7FFFuLL, "%s%s%s", a2, "//", a3);
}

canonical_decompiled_code:
int __fastcall func1(char *a1, const char *a2, const char *a3)
{
return snprintf(a1, 0x7FFFuLL, "%s%s%s", a2, "//", a3);
}

original_code:
void join_path(char* dst, const char* path1, const char* path2) {
  snprintf(dst, 32767, "%s%s%s", path1, "//", path2);
}

canonical_original_code:
void join_path(char *dst, char *path1, char *path2) {
  snprintf(dst, 32767, "%s%s%s", path1, "//", path2);
}

variable_types:
dst
char *


basename

decompiled_code:
size_t __fastcall basename(const char **a1)
{
const char *v2; // rbx
size_t result; // rax
__int64 v4; // rsi
__int64 v5; // rdi
__int64 v6; // rsi
char v7; // dl
int v8; // ecx

v2 = *a1;
result = strlen(*a1);
if ( (int)result > 0 )
{
v4 = (unsigned int)(result - 1);
v5 = 0LL;
result = 1LL;
v6 = v4 + 2;
do
{
while ( 1 )
{
v7 = v2[result - 1];
v8 = result;
if ( v7 == 47 || v7 == 92 )
break;
if ( v6 == ++result )
goto LABEL_7;
}
++result;
v5 = v8;
}
while ( v6 != result );
LABEL_7:
v2 += v5;
}
*a1 = v2;
return result;
}

canonical_decompiled_code:
size_t __fastcall func2(const char **a1)
{
const char *v2; // rbx
size_t result; // rax
__int64 v4; // rsi
__int64 v5; // rdi
__int64 v6; // rsi
char v7; // dl
int v8; // ecx

v2 = *a1;
result = strlen(*a1);
if ( (int)result > 0 )
{
v4 = (unsigned int)(result - 1);
v5 = 0LL;
result = 1LL;
v6 = v4 + 2;
do
{
while ( 1 )
{
v7 = v2[result - 1];
v8 = result;
if ( v7 == 47 || v7 == 92 )
break;
if ( v6 == ++result )
goto LABEL_7;
}
++result;
v5 = v8;
}
while ( v6 != result );
LABEL_7:
v2 += v5;
}
*a1 = v2;
return result;
}

original_code:
void basename(char** ppath) {
  char* path = *ppath;
  int i, last_sep, len=strlen(path);
  for(i=0, last_sep=0; i<len; i++) {
    if(path[i] == '/' || path[i] == '\\') {
      last_sep = i+1;
    }
  }
  path += last_sep;
  *ppath = path;
  len = strlen(path);
}

canonical_original_code:
void basename(char **ppath) {
  char *path = *ppath;
  int i; int last_sep; int len = strlen(path);
  for(i=0, last_sep=0; i<len; i++) {
    if(path[i] == '/' || path[i] == '\\') {
      last_sep = i+1;
    }
  }
  path += last_sep;
  *ppath = path;
  len = strlen(path);
}

variable_types:
ppath
char **

variable_types:
path
char *

variable_types: i int

variable_types: len int


decompiled_code:
__int64 __fastcall get_name_value(char *s, _QWORD *a2, _QWORD *a3)
{
size_t v4; // r14
size_t v5; // rbp
__int64 result; // rax
size_t v7; // rdx
const char *v8; // rbp
size_t v9; // rax

v4 = strlen(s);
v5 = strcspn(s, "=");
result = 0LL;
if ( v4 != v5 )
{
v7 = v5;
v8 = &s[v5 + 1];
strncpy_null(*a2, s, v7);
trim(a2);
v9 = strlen(v8);
strncpy_null(*a3, v8, v9);
trim(a3);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s, _QWORD *a2, _QWORD *a3)
{
size_t v4; // r14
size_t v5; // rbp
__int64 result; // rax
size_t v7; // rdx
const char *v8; // rbp
size_t v9; // rax

v4 = strlen(s);
v5 = strcspn(s, "=");
result = 0LL;
if ( v4 != v5 )
{
v7 = v5;
v8 = &s[v5 + 1];
strncpy_null(*a2, s, v7);
trim(a2);
v9 = strlen(v8);
strncpy_null(*a3, v8, v9);
trim(a3);
result = 1LL;
}
return result;
}

original_code:
int get_name_value(const char* line, char** pname, char** pvalue){
  size_t pos = 0, len = strlen(line);
  pos = strcspn(line, "=");
  if(pos == len)
    return 0;
  strncpy_null(*pname, line, pos);
  trim(pname);
  line += pos+1;
  strncpy_null(*pvalue, line, strlen(line));
  trim(pvalue);
  return 1;
}

canonical_original_code:
int get_name_value(char *line, char **pname, char **pvalue){
  unsigned long pos = 0; unsigned long len = strlen(line);
  pos = strcspn(line, "=");
  if(pos == len)
    return 0;
  strncpy_null(*pname, line, pos);
  trim(pname);
  line += pos+1;
  strncpy_null(*pvalue, line, strlen(line));
  trim(pvalue);
  return 1;
}

variable_types:
line
char *

variable_types:
pname
char **

variable_types:
pvalue
char **

variable_types:
pos
unsigned long

variable_types:
len
unsigned long


original_code:
int parse_env_vars(config_entry* entry, const char* line, char delim) {
  char* s = malloc_string(strlen(line)+1);
  size_t i, j, len = strlen(line);
  char* start;
  strcpy(s,line);
  for(i=0, j=0; i<len; i++) {
    if( s[i] == delim ) j++;
  }
  entry->c_envvars = j;
  entry->envvars = (char**) malloc(entry->c_envvars * sizeof(char**));
  if(!entry->envvars)
    error("Failed to allocate memory");
  s++;
  start = s;
  for(i=0; *s; s++) {
    if( *s == '|' ) {
      *s = 0;
      entry->envvars[i] = (char*) malloc(strlen(start) + 1);
      strcpy(entry->envvars[i], start);
      trim(&entry->envvars[i]);
      i++;
      start = s+1;
    }
  }
  if(strlen(start) > 3) {
    entry->envvars[i] = (char*) malloc(strlen(start) + 1);
    strcpy(entry->envvars[i], start);
    trim(&entry->envvars[i]);
  }
  return 1;
}

canonical_original_code:
int parse_env_vars(struct config_entry *entry, char *line, char delim) {
  char *s = malloc_string(strlen(line)+1);
  unsigned long i; unsigned long j; unsigned long len = strlen(line);
  char *start;
  strcpy(s,line);
  for(i=0, j=0; i<len; i++) {
    if( s[i] == delim ) j++;
  }
  entry->c_envvars = j;
  entry->envvars = (char **) malloc(entry->c_envvars * sizeof(char **));
  if(!entry->envvars)
    error("Failed to allocate memory");
  s++;
  start = s;
  for(i=0; *s; s++) {
    if( *s == '|' ) {
      *s = 0;
      entry->envvars[i] = (char *) malloc(strlen(start) + 1);
      strcpy(entry->envvars[i], start);
      trim(&entry->envvars[i]);
      i++;
      start = s+1;
    }
  }
  if(strlen(start) > 3) {
    entry->envvars[i] = (char *) malloc(strlen(start) + 1);
    strcpy(entry->envvars[i], start);
    trim(&entry->envvars[i]);
  }
  return 1;
}

variable_types: struct config_entry { char *cmd; char *abscmd; char **envvars; int c_envvars; } *

variable_types: delim char

variable_types:
s
char *

variable_types:
i
unsigned long

variable_types:
j
unsigned long

variable_types:
start
char *


decompiled_code:
__int64 __fastcall parse_config_entry(_QWORD *a1, char *a2)
{
unsigned int v2; // er13
size_t v3; // rbx
size_t v4; // rax
size_t v5; // rbx
size_t v6; // r12
void *v7; // rax
char *v8; // rsi
size_t v9; // rbx
void *v10; // rax
char *v11; // rsi
char *v12; // r12
char *s; // [rsp+8h] [rbp-30h] BYREF

v2 = 0;
s = a2;
v3 = strlen(a2);
v4 = strcspn(a2, "=");
if ( v3 == v4 )
return v2;
v5 = v4 + 1;
v6 = v4;
v2 = 1;
v7 = malloc_string(v4 + 1, (int)"=");
v8 = s;
*a1 = v7;
strncpy_null(v7, v8, v6);
trim(a1);
s += v5;
v9 = strcspn(s, "|");
v10 = malloc_string(v9 + 1, (int)"|");
v11 = s;
a1[1] = v10;
strncpy_null(v10, v11, v9);
trim(a1 + 1);
s += v9;
trim(&s);
v12 = s;
if ( strlen(s) <= 4 )
return v2;
parse_env_vars((__int64)a1, v12, 0x7Cu);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, char *a2)
{
unsigned int v2; // er13
size_t v3; // rbx
size_t v4; // rax
size_t v5; // rbx
size_t v6; // r12
void *v7; // rax
char *v8; // rsi
size_t v9; // rbx
void *v10; // rax
char *v11; // rsi
char *v12; // r12
char *s; // [rsp+8h] [rbp-30h] BYREF

v2 = 0;
s = a2;
v3 = strlen(a2);
v4 = strcspn(a2, "=");
if ( v3 == v4 )
return v2;
v5 = v4 + 1;
v6 = v4;
v2 = 1;
v7 = func0(v4 + 1, (int)"=");
v8 = s;
*a1 = v7;
strncpy_null(v7, v8, v6);
trim(a1);
s += v5;
v9 = strcspn(s, "|");
v10 = func0(v9 + 1, (int)"|");
v11 = s;
a1[1] = v10;
strncpy_null(v10, v11, v9);
trim(a1 + 1);
s += v9;
trim(&s);
v12 = s;
if ( strlen(s) <= 4 )
return v2;
func6((__int64)a1, v12, 0x7Cu);
return 1LL;
}

original_code:
int parse_config_entry(config_entry* entry, char* line){
  size_t pos = 0, len = strlen(line);
  pos = strcspn(line, "=");
  if(pos == len)
    return 0;
  entry->cmd = malloc_string( pos+1 );
  strncpy_null(entry->cmd, line, pos);
  trim(&entry->cmd);
  line += pos+1;
  pos = strcspn(line, "|");
  entry->abscmd = malloc_string( pos+1 );
  strncpy_null(entry->abscmd, line, pos);
  trim(&entry->abscmd);
  line += pos;
  trim(&line);
  len = strlen(line);
  if(len > 4) {
    parse_env_vars(entry, line, '|');
  }
  return 1;
}

canonical_original_code:
int parse_config_entry(struct config_entry *entry, char *line){
  unsigned long pos = 0; unsigned long len = strlen(line);
  pos = strcspn(line, "=");
  if(pos == len)
    return 0;
  entry->cmd = malloc_string( pos+1 );
  strncpy_null(entry->cmd, line, pos);
  trim(&entry->cmd);
  line += pos+1;
  pos = strcspn(line, "|");
  entry->abscmd = malloc_string( pos+1 );
  strncpy_null(entry->abscmd, line, pos);
  trim(&entry->abscmd);
  line += pos;
  trim(&line);
  len = strlen(line);
  if(len > 4) {
    parse_env_vars(entry, line, '|');
  }
  return 1;
}

user_defined_types: struct config_entry { char *cmd; char *abscmd; char **envvars; int c_envvars; }


decompiled_code:
__int64 __fastcall split_pair(const char **a1, const char *a2)
{
int v2; // eax
__int64 result; // rax

v2 = strcspn(a2, "=");
a2[v2] = 0;
result = (__int64)&a2[v2 + 1];
*a1 = a2;
a1[1] = (const char *)result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1, const char *a2)
{
int v2; // eax
__int64 result; // rax

v2 = strcspn(a2, "=");
a2[v2] = 0;
result = (__int64)&a2[v2 + 1];
*a1 = a2;
a1[1] = (const char *)result;
return result;
}

original_code:
void split_pair(pair* kv, char* s ) {
  int pos = strcspn(s, "=");
  *(s + pos) = 0;
  kv->key = s;
  s += pos+1;
  kv->value = s;
}

canonical_original_code:
void split_pair(struct pair *kv, char *s) {
  int pos = strcspn(s, "=");
  *(s + pos) = 0;
  kv->key = s;
  s += pos+1;
  kv->value = s;
}

variable_types: struct pair { char *key; char *value; } *

variable_types: pos int


setEnv

decompiled_code:
const char **__fastcall setEnv(char *s, char *a2, const char **a3)
{
const char **v3; // r14
const char *v6; // rbp
const char **v7; // r15
int i; // ebx
int v9; // eax
size_t v10; // rax
const char *v11; // rsi
size_t v12; // rbp
size_t v13; // rax
char *v14; // rax
size_t v16; // rdi
const char **v17; // rax
const char *v18; // rdx
const char **v19; // rbp
__int64 v20; // rax
__int64 v21; // rcx
char **v22; // r14
__int64 v23; // rbx
size_t v24; // r15
size_t v25; // rax
char *v26; // rax
const char *v27; // rsi
int v28; // [rsp+Ch] [rbp-803Ch]
char s2[32824]; // [rsp+10h] [rbp-8038h] BYREF

v3 = a3;
v6 = *a3;
if ( !*a3 )
{
v16 = 16LL;
goto LABEL_10;
}
v28 = 0;
v7 = a3;
for ( i = 0; ; i = v9 )
{
v10 = strcspn(v6, "=");
strncpy_null(s2, v6, v10);
if ( !strcmp(s, s2) )
break;
v6 = v7[1];
++v7;
v9 = i + 1;
if ( !v6 )
goto LABEL_7;
LABEL_4:
;
}
v11 = *v7++;
info("Replacing ENV: %s -> %s=%s\n", v11, s, a2);
v12 = strlen(s);
v13 = strlen(a2);
v14 = (char *)malloc(v13 * v12 + 2);
*(v7 - 1) = v14;
sprintf(v14, "%s=%s", s, a2);
v6 = *v7;
v28 = 1;
v9 = i + 1;
if ( *v7 )
goto LABEL_4;
LABEL_7:
if ( v28 )
return v3;
v16 = 8LL * (i + 3);
LABEL_10:
v17 = (const char **)malloc(v16);
v18 = *v3;
v19 = v17;
if ( *v3 )
{
v20 = 1LL;
do
{
v19[v20 - 1] = v18;
v21 = v20++;
v18 = v3[v20 - 1];
}
while ( v18 );
v22 = (char **)&v19[v21];
v23 = v20;
}
else
{
v22 = (char **)v17;
v23 = 1LL;
}
v24 = strlen(s);
v25 = strlen(a2);
v26 = (char *)malloc(v25 * v24 + 2);
*v22 = v26;
sprintf(v26, "%s=%s", s, a2);
v27 = *v22;
v3 = v19;
info("Adding ENV: %s\n", v27);
v19[v23] = 0LL;
return v3;
}

original_code:
char** setEnv(char* key, char* value, char* envp[]) {
  int i, found = 0;
  char** new_envp;
  char lkey[32767 +1];
  size_t pos;
  for(i=0; envp[i] != 0; i++) {
    pos = strcspn(envp[i], "=");
    strncpy_null(lkey, envp[i], pos);
    if( strcmp(key, lkey) == 0 ) {
      found = 1;
      info("Replacing ENV: %s -> %s=%s\n", envp[i], key, value);
      envp[i] = (char*) malloc( strlen(key) * strlen(value) + 2 );
      sprintf(envp[i], "%s=%s", key, value);
    }
  }
  if(!found) {
    new_envp = (char**) malloc( (i+2) * sizeof(char**) );
    for(i=0; envp[i] != 0; i++) {
      new_envp[i] = envp[i];
    }
    new_envp[i] = (char*) malloc( strlen(key) * strlen(value) + 2 );
    sprintf(new_envp[i], "%s=%s", key, value);
    info("Adding ENV: %s\n", new_envp[i]);
    new_envp[i+1] = 0;
    envp = new_envp;
  }
  return envp;
}

canonical_original_code:
char **setEnv(char *key, char *value, char *envp[]) {
  int i; int found = 0;
  char **new_envp;
  char lkey[-1];
  unsigned long pos;
  for(i=0; envp[i] != 0; i++) {
    pos = strcspn(envp[i], "=");
    strncpy_null(lkey, envp[i], pos);
    if( strcmp(key, lkey) == 0 ) {
      found = 1;
      info("Replacing ENV: %s -> %s=%s\n", envp[i], key, value);
      envp[i] = (char *) malloc( strlen(key) * strlen(value) + 2 );
      sprintf(envp[i], "%s=%s", key, value);
    }
  }
  if(!found) {
    new_envp = (char **) malloc( (i+2) * sizeof(char **) );
    for(i=0; envp[i] != 0; i++) {
      new_envp[i] = envp[i];
    }
    new_envp[i] = (char *) malloc( strlen(key) * strlen(value) + 2 );
    sprintf(new_envp[i], "%s=%s", key, value);
    info("Adding ENV: %s\n", new_envp[i]);
    new_envp[i+1] = 0;
    envp = new_envp;
  }
  return envp;
}

variable_types:
key
char *

variable_types:
value
char *

variable_types:
envp
char *[]

variable_types: found int

variable_types:
lkey
char [-1]

return_type: char **


launch

decompiled_code:
__int64 __fastcall launch(int a1, const char **a2, __int64 a3)
{
const char *v5; // rdx
__int64 v6; // r12
__int64 v8; // rbx
const char *v9; // rax
const char *v10; // r12
const char *i; // rsi
__int64 v12; // rbx
size_t v13; // rax
char *v14; // rax

if ( (unsigned int)file_exists(*a2) )
{
if ( !verbose )
goto LABEL_3;
}
else
{
error((int)"File command found: %s\n", (int)*a2, v5);
if ( !verbose )
goto LABEL_3;
}
v8 = a3 + 8;
v9 = (const char *)malloc(0x10000uLL);
*v9 = 0;
v10 = v9;
info("Launching using environment variables:");
for ( i = *(const char **)(v8 - 8); i; i = *(const char **)(v8 - 8) )
{
v8 += 8LL;
info(" %s", i);
}
info((const char *)&unk_557);
v12 = 0LL;
info("Command arguments: ");
if ( a1 > 0 )
{
do
{
v13 = strlen(v10);
v14 = stpcpy((char *)&v10[v13], a2[v12]);
if ( a1 - 1 > (int)v12 )
*(_WORD *)v14 = 32;
++v12;
}
while ( a1 != v12 );
}
info(" %s\n", v10);
LABEL_3:
v6 = (unsigned int)execv(*a2, (char *const *)a2);
info("Return code: %d", v6);
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, const char **a2, __int64 a3)
{
const char *v5; // rdx
__int64 v6; // r12
__int64 v8; // rbx
const char *v9; // rax
const char *v10; // r12
const char *i; // rsi
__int64 v12; // rbx
size_t v13; // rax
char *v14; // rax

if ( (unsigned int)file_exists(*a2) )
{
if ( !verbose )
goto LABEL_3;
}
else
{
error((int)"File command found: %s\n", (int)*a2, v5);
if ( !verbose )
goto LABEL_3;
}
v8 = a3 + 8;
v9 = (const char *)malloc(0x10000uLL);
*v9 = 0;
v10 = v9;
info("Launching using environment variables:");
for ( i = *(const char **)(v8 - 8); i; i = *(const char **)(v8 - 8) )
{
v8 += 8LL;
info(" %s", i);
}
info((const char *)&unk_557);
v12 = 0LL;
info("Command arguments: ");
if ( a1 > 0 )
{
do
{
v13 = strlen(v10);
v14 = stpcpy((char *)&v10[v13], a2[v12]);
if ( a1 - 1 > (int)v12 )
*(_WORD *)v14 = 32;
++v12;
}
while ( a1 != v12 );
}
info(" %s\n", v10);
LABEL_3:
v6 = (unsigned int)execv(*a2, (char *const *)a2);
info("Return code: %d", v6);
return (unsigned int)v6;
}

original_code:
int launch(int argc, char* argv[], char* envp[]) {
  int i, rc;
  char* infomsg;
  if(! file_exists(argv[0]) )
    error("File command found: %s\n",argv[0]);
  if(verbose) {
    infomsg = (char*) malloc(1<<16);
    infomsg[0] = 0;
    if(infomsg) {
      info("Launching using environment variables:");
      for(i=0; envp[i] != 0; i++) info("  %s", envp[i] );
      info("");
      info("Command arguments: ");
      for(i=0; i<argc ; i++) {
        strcat(infomsg, argv[i] );
        if(i<argc-1) strcat(infomsg, " ");
      }
      info("  %s\n", infomsg);
    }
  }
    rc = execv(argv[0],(char * const *)argv);
  info("Return code: %d", rc);
  return rc;
}

canonical_original_code:
int launch(int argc, char *argv[], char *envp[]) {
  int i; int rc;
  char *infomsg;
  if(! file_exists(argv[0]) )
    error("File command found: %s\n",argv[0]);
  if(verbose) {
    infomsg = (char *) malloc(1<<16);
    infomsg[0] = 0;
    if(infomsg) {
      info("Launching using environment variables:");
      for(i=0; envp[i] != 0; i++) info("  %s", envp[i] );
      info("");
      info("Command arguments: ");
      for(i=0; i<argc ; i++) {
        strcat(infomsg, argv[i] );
        if(i<argc-1) strcat(infomsg, " ");
      }
      info("  %s\n", infomsg);
    }
  }
    rc = execv(argv[0],(char **)argv);
  info("Return code: %d", rc);
  return rc;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

variable_types: rc int

variable_types:
infomsg
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v5; // rax
_QWORD *v6; // rbp
__int64 v7; // rbx
const char *v8; // rsi
int v10[3]; // [rsp+Ch] [rbp-4Ch] BYREF
char filename[8]; // [rsp+18h] [rbp-40h] BYREF
char *s[7]; // [rsp+20h] [rbp-38h] BYREF

v5 = *argv;
v10[0] = argc;
*(_QWORD *)filename = v5;
parse_verbose(v10, (__int64)argv);
basename(filename);
v6 = find_config(*(__int64 *)filename);
*argv = (const char *)v6[1];
if ( *((int *)v6 + 6) > 0 )
{
v7 = 0LL;
do
{
v8 = *(const char **)(v6[2] + 8 * v7++);
split_pair((const char **)s, v8);
envp = setEnv(s[0], s[1], envp);
}
while ( *((_DWORD *)v6 + 6) > (int)v7 );
}
free(v6);
return launch(v10[0], argv, (__int64)envp);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v5; // rax
_QWORD *v6; // rbp
__int64 v7; // rbx
const char *v8; // rsi
int v10[3]; // [rsp+Ch] [rbp-4Ch] BYREF
char filename[8]; // [rsp+18h] [rbp-40h] BYREF
char *s[7]; // [rsp+20h] [rbp-38h] BYREF

v5 = *argv;
v10[0] = argc;
*(_QWORD *)filename = v5;
func1(v10, (__int64)argv);
basename(filename);
v6 = find_config(*(__int64 *)filename);
*argv = (const char *)v6[1];
if ( *((int *)v6 + 6) > 0 )
{
v7 = 0LL;
do
{
v8 = *(const char **)(v6[2] + 8 * v7++);
func0((const char **)s, v8);
envp = func2(s[0], s[1], envp);
}
while ( *((_DWORD *)v6 + 6) > (int)v7 );
}
free(v6);
return func3(v10[0], argv, (__int64)envp);
}

original_code:
int main(int argc, char* argv[], char* envp[]) {
  int i;
  char* cmd = argv[0];
  config_entry* entry;
  pair kv;
  parse_verbose(&argc, argv);
  basename(&cmd);
  entry = find_config(cmd);
  argv[0] = entry->abscmd;
  for(i=0; i<entry->c_envvars; i++){
    split_pair(&kv, entry->envvars[i] );
    envp = setEnv(kv.key, kv.value, envp);
  }
  free(entry);
  return launch(argc, argv, envp);
}

canonical_original_code:
int main(int argc, char *argv[], char *envp[]) {
  int i;
  char *cmd = argv[0];
  struct config_entry *entry;
  struct pair kv;
  parse_verbose(&argc, argv);
  basename(&cmd);
  entry = find_config(cmd);
  argv[0] = entry->abscmd;
  for(i=0; i<entry->c_envvars; i++){
    split_pair(&kv, entry->envvars[i] );
    envp = setEnv(kv.key, kv.value, envp);
  }
  free(entry);
  return launch(argc, argv, envp);
}

variable_types:
cmd
char *

variable_types: struct config_entry { char *cmd; char *abscmd; char **envvars; int c_envvars; } *

variable_types:
kv
struct pair { char *key; char *value; }


error

decompiled_code:
void __noreturn error(char *src, ...)
{
char *v1; // rax
char *v2; // rbp
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v1 = (char *)malloc(0x10000uLL);
v2 = v1;
if ( v1 )
{
*(_DWORD *)v1 = 1330795077;
*((_WORD *)v1 + 2) = 8274;
*(_WORD *)stpcpy(v1 + 6, src) = 10;
va_start(arg, src);
vfprintf(stderr, v2, arg);
}
free(v2);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0(char *src, ...)
{
char *v1; // rax
char *v2; // rbp
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v1 = (char *)malloc(0x10000uLL);
v2 = v1;
if ( v1 )
{
*(_DWORD *)v1 = 1330795077;
*((_WORD *)v1 + 2) = 8274;
*(_WORD *)stpcpy(v1 + 6, src) = 10;
va_start(arg, src);
vfprintf(stderr, v2, arg);
}
free(v2);
exit(1);
}

original_code:
void error(const char* fmt, ...) {
  va_list args;
  int max = 1<<16;
  char* msg = (char*) malloc(max);
  if(msg) {
    strcpy(msg,"ERROR ");
    strcat(msg,fmt);
    strcat(msg,"\n");
    __builtin_va_start(args,fmt);
    vfprintf(stderr, msg, args);
    __builtin_va_end(args);
  }
  free(msg);
  exit(1);
}

canonical_original_code:
void error(char *fmt, ...) {
  __builtin_va_list args;
  int max = 1<<16;
  char *msg = (char*) malloc(max);
  if(msg) {
    strcpy(msg,"ERROR ");
    strcat(msg,fmt);
    strcat(msg,"\n");
    __builtin_va_start(args,fmt);
    vfprintf(stderr, msg, args);
    __builtin_va_end(args);
  }
  free(msg);
  exit(1);
}

variable_types:
fmt
char *

variable_types: max int

variable_types:
msg
char *


info

decompiled_code:
void info(char *src, ...)
{
char *v1; // rax
char *v2; // r12
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( verbose )
{
v1 = (char *)malloc(0x10000uLL);
v2 = v1;
if ( v1 )
{
*(_DWORD *)v1 = 1330007625;
v1[4] = 32;
*(_WORD *)stpcpy(v1 + 5, src) = 10;
va_start(arg, src);
vfprintf(stdout, v2, arg);
}
free(v2);
}
}

canonical_decompiled_code:
void func1(char *src, ...)
{
char *v1; // rax
char *v2; // r12
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( verbose )
{
v1 = (char *)malloc(0x10000uLL);
v2 = v1;
if ( v1 )
{
*(_DWORD *)v1 = 1330007625;
v1[4] = 32;
*(_WORD *)stpcpy(v1 + 5, src) = 10;
va_start(arg, src);
vfprintf(stdout, v2, arg);
}
free(v2);
}
}

original_code:
void info(const char* fmt, ...) {
  va_list args;
  char* msg;
  if(verbose) {
    msg = (char*) malloc(1<<16);
    if(msg) {
      strcpy(msg,"INFO ");
      strcat(msg,fmt);
      strcat(msg,"\n");
      __builtin_va_start(args,fmt);
      vfprintf(stdout, msg, args);
      __builtin_va_end(args);
    }
    free(msg);
  }
}

canonical_original_code:
void info(char *fmt, ...) {
  __builtin_va_list args;
  char *msg;
  if(verbose) {
    msg = (char *) malloc(1<<16);
    if(msg) {
      strcpy(msg,"INFO ");
      strcat(msg,fmt);
      strcat(msg,"\n");
      __builtin_va_start(args,fmt);
      vfprintf(stdout, msg, args);
      __builtin_va_end(args);
    }
    free(msg);
  }
}


trim

decompiled_code:
__int64 __fastcall trim(const char **a1)
{
const char *v1; // rbx
const char *v2; // rbp
const unsigned __int16 **v3; // rax
const unsigned __int16 **v4; // rcx
__int64 result; // rax

v1 = *a1;
v2 = &v1[strlen(*a1) - 1];
v3 = _ctype_b_loc();
v4 = v3;
while ( ((*v3)[*v2] & 0x2000) != 0 )
--v2;
*((_BYTE *)v2 + 1) = 0;
for ( result = *v1; ((*v4)[result] & 0x2000) != 0; ++v1 )
result = v1[1];
*a1 = v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1)
{
const char *v1; // rbx
const char *v2; // rbp
const unsigned __int16 **v3; // rax
const unsigned __int16 **v4; // rcx
__int64 result; // rax

v1 = *a1;
v2 = &v1[strlen(*a1) - 1];
v3 = _ctype_b_loc();
v4 = v3;
while ( ((*v3)[*v2] & 0x2000) != 0 )
--v2;
*((_BYTE *)v2 + 1) = 0;
for ( result = *v1; ((*v4)[result] & 0x2000) != 0; ++v1 )
result = v1[1];
*a1 = v1;
return result;
}

original_code:
void trim(char** sptr) {
  char* s = *sptr;
  char* ptr = s;
  ptr = s + strlen(s)-1;
  while(((*__ctype_b_loc ())[(int) (((int)*ptr))] & (unsigned short int) _ISspace)) ptr--;
  *(ptr+1) = '\0';
  ptr = s;
  while(((*__ctype_b_loc ())[(int) (((int)*ptr))] & (unsigned short int) _ISspace)) ptr++;
  *sptr = ptr;
}

canonical_original_code:
void trim(char **sptr) {
  char *s = *sptr;
  char *ptr = s;
  ptr = s + strlen(s)-1;
  while(((*__ctype_b_loc ())[(int) (((int)*ptr))] & (unsigned short) _ISspace)) ptr--;
  *(ptr+1) = '\0';
  ptr = s;
  while(((*__ctype_b_loc ())[(int) (((int)*ptr))] & (unsigned short) _ISspace)) ptr++;
  *sptr = ptr;
}

variable_types:
sptr
char **

variable_types:
s
char *

variable_types:
ptr
char *


decompiled_code:
char *__fastcall strncpy_null(char *a1, const char *a2, size_t a3)
{
char *result; // rax

result = strncpy(a1, a2, a3);
result[a3] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *a1, const char *a2, size_t a3)
{
char *result; // rax

result = strncpy(a1, a2, a3);
result[a3] = 0;
return result;
}

original_code:
char* strncpy_null(char* dst, const char* src, size_t num) {
  strncpy(dst, src, num);
  dst[num] = 0;
  return dst;
}

canonical_original_code:
char *strncpy_null(char *dst, char *src, unsigned long num) {
  strncpy(dst, src, num);
  dst[num] = 0;
  return dst;
}

variable_types:
dst
char *

variable_types:
src
char *

variable_types:
num
unsigned long


quote

decompiled_code:
int __fastcall quote(char *a1, const char *a2)
{
return sprintf(a1, "\"%s\"", a2);
}

canonical_decompiled_code:
int __fastcall func2(char *a1, const char *a2)
{
return sprintf(a1, "\"%s\"", a2);
}

original_code:
void quote(char* dst, const char* src) {
  sprintf(dst, "\"%s\"", src);
}

canonical_original_code:
void quote(char *dst, char *src) {
  sprintf(dst, "\"%s\"", src);
}


repo: jokkebk/JZipVIew

original_code:
JImage *make_letter(JImage *font, int x, int y, int w, int h, void ** mempool) {
    int i, j, offset = 0;
    JImage *image = (JImage *)(*mempool);
    *mempool += sizeof(JImage);
    image->w = w;
    image->h = h;
    image->data = (Uint32 *)(*mempool);
    *mempool += w*h * sizeof(Uint32);
    for(j=0; j<h; j++)
        for(i=0; i<w; i++)
            image->data[offset++] = ((font)->data[(y+j) * (font)->w + (x+i)]);
    return image;
}

canonical_original_code:
struct JImage *make_letter(struct JImage *font, int x, int y, int w, int h, void **mempool) {
    int i; int j; int offset = 0;
    struct JImage *image = (JImage *)(*mempool);
    *mempool += sizeof(JImage);
    image->w = w;
    image->h = h;
    image->data = (unsigned int *)(*mempool);
    *mempool += w*h * sizeof(Uint32);
    for(j=0; j<h; j++)
        for(i=0; i<w; i++)
            image->data[offset++] = ((font)->data[(y+j) * (font)->w + (x+i)]);
    return image;
}

variable_types:
font
struct JImage *

variable_types: x int

variable_types: y int

variable_types: w int

variable_types: h int

variable_types:
mempool
void **

variable_types: j int

variable_types: offset int

variable_types: struct JImage { unsigned int *data; int w; int h; } *


decompiled_code:
// attributes: thunk
void destroy_font(void *ptr)
{
free(ptr);
}

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

original_code:
void destroy_font(JFont *fontPtr) {
    free(fontPtr);
}

canonical_original_code:
void destroy_font(struct JFont *fontPtr) {
    free(fontPtr);
}

variable_types: struct JFont { struct JImage { unsigned int *data; int w; int h; } **letter; char convert[128]; int letter_spacing; int space_width; } *

user_defined_types: struct JFont { struct JImage **letter; char convert[128]; int letter_spacing; int space_width; }


original_code:
void write_font(JImage *image, JFont *font, Uint32 c, const char *message, int x, int y, int align, int spacing) {
    int total_width = 0, len = strlen(message), i, ch, n;
    for(i=0; i<len; i++) {
        if((ch = message[i]) == 32 || (n = font->convert[ch]) == -1)
            total_width += font->space_width;
        else
            total_width += font->letter[n]->w;
    }
    total_width += spacing * (len-1);
    if((align & 0x0F) == 0x01)
        y -= font->letter[0]->h / 2;
    else if((align & 0x0F) == 0x02)
        y -= font->letter[0]->h;
    if((align & 0xF0) == 0x10)
        x -= total_width / 2;
    else if((align & 0xF0) == 0x20)
        x -= total_width;
    for(i=0; i<len; i++) {
        if((ch = message[i]) == 32 || (n = font->convert[ch]) == -1) {
            x += font->space_width + spacing;
        } else {
            blit_font(image, font->letter[n], x, y, c);
            x += font->letter[n]->w + spacing;
        }
    }
}

canonical_original_code:
void write_font(struct JImage *image, struct JFont *font, unsigned int c, char *message, int x, int y, int align, int spacing) {
    int total_width = 0; int len = strlen(message); int i; int ch; int n;
    for(i=0; i<len; i++) {
        if((ch = message[i]) == 32 || (n = font->convert[ch]) == -1)
            total_width += font->space_width;
        else
            total_width += font->letter[n]->w;
    }
    total_width += spacing * (len-1);
    if((align & 0x0F) == 0x01)
        y -= font->letter[0]->h / 2;
    else if((align & 0x0F) == 0x02)
        y -= font->letter[0]->h;
    if((align & 0xF0) == 0x10)
        x -= total_width / 2;
    else if((align & 0xF0) == 0x20)
        x -= total_width;
    for(i=0; i<len; i++) {
        if((ch = message[i]) == 32 || (n = font->convert[ch]) == -1) {
            x += font->space_width + spacing;
        } else {
            blit_font(image, font->letter[n], x, y, c);
            x += font->letter[n]->w + spacing;
        }
    }
}

variable_types: struct JFont { struct JImage **letter; char convert[128]; int letter_spacing; int space_width; } *

variable_types:
c
unsigned int

variable_types:
message
char *

variable_types: align int

variable_types: spacing int

variable_types: len int

variable_types: i int

variable_types: ch int

variable_types: n int

user_defined_types: struct JImage { unsigned int *data; int w; int h; }


decompiled_code:
void __fastcall destroy_image(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void destroy_image(JImage *img) {
    free(img->data);
    free(img);
}

canonical_original_code:
void destroy_image(struct JImage *img) {
    free(img->data);
    free(img);
}


decompiled_code:
void *__fastcall copy_image(void **a1, __int64 a2)
{
void *result; // rax

result = *(void **)(a2 + 8);
if ( a1[1] == result )
result = memcpy(*a1, *(const void **)a2, 4LL * *(_DWORD *)(a2 + 12) * *(_DWORD *)(a2 + 8));
return result;
}

canonical_decompiled_code:
void *__fastcall func1(void **a1, __int64 a2)
{
void *result; // rax

result = *(void **)(a2 + 8);
if ( a1[1] == result )
result = memcpy(*a1, *(const void **)a2, 4LL * *(_DWORD *)(a2 + 12) * *(_DWORD *)(a2 + 8));
return result;
}

original_code:
void copy_image(JImage *dest, JImage *src) {
    if(dest->w != src->w || dest->h != src->h)
        return;
    memcpy(dest->data, src->data, src->w * src->h * sizeof(Uint32));
}

canonical_original_code:
void copy_image(struct JImage *dest, struct JImage *src) {
    if(dest->w != src->w || dest->h != src->h)
        return;
    memcpy(dest->data, src->data, src->w * src->h * sizeof(Uint32));
}

variable_types:
src
struct JImage *


decompiled_code:
unsigned __int64 __fastcall rotate_image(void **a1, __int64 a2, int a3)
{
int v3; // er8
int v4; // ecx
unsigned __int64 result; // rax
int v6; // er9
__int64 v7; // r11
_DWORD *v8; // r10
int v9; // er8
int v10; // ecx
int v11; // ebx
int v12; // eax
int v13; // edx
int i; // er8
__int64 v15; // r10
_DWORD *v16; // r9
int v17; // ecx
int v18; // er11
int v19; // eax
int v20; // er8
__int64 v21; // r10
_DWORD *v22; // r9
int v23; // ecx
int v24; // edx
int v25; // eax
int v26; // edx

v3 = *(_DWORD *)(a2 + 8);
v4 = *(_DWORD *)(a2 + 12);
result = (unsigned int)(*((_DWORD *)a1 + 3) * *((_DWORD *)a1 + 2));
if ( (_DWORD)result != v4 * v3 )
return result;
result = a3 & 0xFFFFFFFD;
if ( (_DWORD)result == 1 )
{
*((_DWORD *)a1 + 2) = v4;
result = *(unsigned int *)(a2 + 8);
*((_DWORD *)a1 + 3) = result;
if ( a3 != 2 )
goto LABEL_4;
}
else
{
*((_DWORD *)a1 + 3) = v4;
*((_DWORD *)a1 + 2) = v3;
if ( a3 != 2 )
{
LABEL_4:
if ( a3 == 3 )
{
if ( *(int *)(a2 + 12) > 0 )
{
result = *(unsigned int *)(a2 + 8);
v20 = 0;
do
{
if ( (int)result > 0 )
{
v21 = *(_QWORD *)a2;
v22 = *a1;
v23 = 0;
do
{
v24 = result;
v25 = *((_DWORD *)a1 + 2) * (result - 1 - v23);
v26 = v23 + v20 * v24;
++v23;
v22[v20 + v25] = *(_DWORD *)(v21 + 4LL * v26);
result = *(unsigned int *)(a2 + 8);
}
while ( (int)result > v23 );
}
++v20;
}
while ( *(_DWORD *)(a2 + 12) > v20 );
}
}
else if ( a3 == 1 )
{
v13 = *(_DWORD *)(a2 + 12);
if ( v13 > 0 )
{
result = *(unsigned int *)(a2 + 8);
for ( i = 0; i < v13; ++i )
{
if ( (int)result > 0 )
{
v15 = *(_QWORD *)a2;
v16 = *a1;
v17 = 0;
do
{
v18 = *(_DWORD *)(v15 + 4LL * (v17 + i * (int)result));
v19 = v17 * *((_DWORD *)a1 + 2);
++v17;
v16[v19 + v13 - 1 - i] = v18;
result = *(unsigned int *)(a2 + 8);
v13 = *(_DWORD *)(a2 + 12);
}
while ( (int)result > v17 );
}
}
}
}
else
{
result = (unsigned __int64)copy_image(a1, a2);
}
return result;
}
}
result = *(unsigned int *)(a2 + 12);
if ( (int)result > 0 )
{
result = *(unsigned int *)(a2 + 8);
v6 = 0;
while ( (int)result <= 0 )
{
if ( *(_DWORD *)(a2 + 12) <= ++v6 )
return result;
}
LABEL_11:
v7 = *(_QWORD *)a2;
v8 = *a1;
v9 = 0;
do
{
v10 = *((_DWORD *)a1 + 2);
v11 = *(_DWORD *)(v7 + 4LL * (v9 + v6 * (int)result));
v12 = v10 - 1 - v9++;
v8[v10 * (*((_DWORD *)a1 + 3) + ~v6) + v12] = v11;
result = *(unsigned int *)(a2 + 8);
}
while ( (int)result > v9 );
while ( *(_DWORD *)(a2 + 12) > ++v6 )
{
if ( (int)result > 0 )
goto LABEL_11;
}
}
return result;
}

original_code:
void rotate_image(JImage *dest, JImage *src, int angle) {
    int x, y;
    if(dest->w * dest->h != src->w * src->h)
        return;
    if(angle == 1 || angle == 3) {
        dest->w = src->h;
        dest->h = src->w;
    } else {
        dest->h = src->h;
        dest->w = src->w;
    }
    switch(angle) {
    case 1:
        for(y=0; y<src->h; y++)
        for(x=0; x<src->w; x++)
            { (dest)->data[(x) * (dest)->w + (src->h - 1 - y)] = (((src)->data[(y) * (src)->w + (x)])); };
        break;
    case 2:
        for(y=0; y<src->h; y++)
        for(x=0; x<src->w; x++)
            { (dest)->data[(dest->h - 1 - y) * (dest)->w + (dest->w - 1 - x)] = (((src)->data[(y) * (src)->w + (x)])); };
        break;
    case 3:
        for(y=0; y<src->h; y++)
        for(x=0; x<src->w; x++)
            { (dest)->data[(src->w - 1 - x) * (dest)->w + (y)] = (((src)->data[(y) * (src)->w + (x)])); };
        break;
    default:
        copy_image(dest, src);
        break;
    }
}

canonical_original_code:
void rotate_image(struct JImage *dest, struct JImage *src, int angle) {
    int x; int y;
    if(dest->w * dest->h != src->w * src->h)
        return;
    if(angle == 1 || angle == 3) {
        dest->w = src->h;
        dest->h = src->w;
    } else {
        dest->h = src->h;
        dest->w = src->w;
    }
    switch(angle) {
    case 1:
        for(y=0; y<src->h; y++)
        for(x=0; x<src->w; x++)
            { (dest)->data[(x) * (dest)->w + (src->h - 1 - y)] = (((src)->data[(y) * (src)->w + (x)])); };
        break;
    case 2:
        for(y=0; y<src->h; y++)
        for(x=0; x<src->w; x++)
            { (dest)->data[(dest->h - 1 - y) * (dest)->w + (dest->w - 1 - x)] = (((src)->data[(y) * (src)->w + (x)])); };
        break;
    case 3:
        for(y=0; y<src->h; y++)
        for(x=0; x<src->w; x++)
            { (dest)->data[(src->w - 1 - x) * (dest)->w + (y)] = (((src)->data[(y) * (src)->w + (x)])); };
        break;
    default:
        copy_image(dest, src);
        break;
    }
}

variable_types: angle int

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall greyscale_image(__int64 *a1)
{
__int64 result; // rax
int v2; // ecx
__int64 v3; // rsi
int v4; // edx
int v5; // eax

result = *((unsigned int *)a1 + 3);
if ( (int)result > 0 )
{
result = *((unsigned int *)a1 + 2);
v2 = 0;
while ( (int)result <= 0 )
{
if ( *((_DWORD *)a1 + 3) <= ++v2 )
return result;
}
while ( 1 )
{
v3 = *a1;
v4 = 0;
do
{
v5 = v4 + v2 * result;
++v4;
*(_DWORD *)(v3 + 4LL * v5) = 65793
* (((unsigned __int8)*(_DWORD *)(v3 + 4LL * v5)
+ (unsigned __int8)BYTE1(*(_DWORD *)(v3 + 4LL * v5))
+ (unsigned int)(unsigned __int8)BYTE2(*(_DWORD *)(v3 + 4LL * v5)))
/ 3);
result = *((unsigned int *)a1 + 2);
}
while ( (int)result > v4 );
if ( *((_DWORD *)a1 + 3) <= ++v2 )
break;
while ( (int)result <= 0 )
{
if ( *((_DWORD *)a1 + 3) <= ++v2 )
return result;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1)
{
__int64 result; // rax
int v2; // ecx
__int64 v3; // rsi
int v4; // edx
int v5; // eax

result = *((unsigned int *)a1 + 3);
if ( (int)result > 0 )
{
result = *((unsigned int *)a1 + 2);
v2 = 0;
while ( (int)result <= 0 )
{
if ( *((_DWORD *)a1 + 3) <= ++v2 )
return result;
}
while ( 1 )
{
v3 = *a1;
v4 = 0;
do
{
v5 = v4 + v2 * result;
++v4;
*(_DWORD *)(v3 + 4LL * v5) = 65793
* (((unsigned __int8)*(_DWORD *)(v3 + 4LL * v5)
+ (unsigned __int8)BYTE1(*(_DWORD *)(v3 + 4LL * v5))
+ (unsigned int)(unsigned __int8)BYTE2(*(_DWORD *)(v3 + 4LL * v5)))
/ 3);
result = *((unsigned int *)a1 + 2);
}
while ( (int)result > v4 );
if ( *((_DWORD *)a1 + 3) <= ++v2 )
break;
while ( (int)result <= 0 )
{
if ( *((_DWORD *)a1 + 3) <= ++v2 )
return result;
}
}
}
return result;
}

variable_types: avg int


decompiled_code:
__int64 __fastcall invert_image(__int64 *a1)
{
__int64 result; // rax
int v2; // esi
__int64 v3; // r8
int v4; // edx
int v5; // eax

result = *((unsigned int *)a1 + 3);
if ( (int)result > 0 )
{
result = *((unsigned int *)a1 + 2);
v2 = 0;
do
{
if ( (int)result > 0 )
{
v3 = *a1;
v4 = 0;
do
{
v5 = v4 + v2 * result;
++v4;
*(_DWORD *)(v3 + 4LL * v5) = 0xFFFFFF - *(_DWORD *)(v3 + 4LL * v5);
result = *((unsigned int *)a1 + 2);
}
while ( (int)result > v4 );
}
++v2;
}
while ( *((_DWORD *)a1 + 3) > v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1)
{
__int64 result; // rax
int v2; // esi
__int64 v3; // r8
int v4; // edx
int v5; // eax

result = *((unsigned int *)a1 + 3);
if ( (int)result > 0 )
{
result = *((unsigned int *)a1 + 2);
v2 = 0;
do
{
if ( (int)result > 0 )
{
v3 = *a1;
v4 = 0;
do
{
v5 = v4 + v2 * result;
++v4;
*(_DWORD *)(v3 + 4LL * v5) = 0xFFFFFF - *(_DWORD *)(v3 + 4LL * v5);
result = *((unsigned int *)a1 + 2);
}
while ( (int)result > v4 );
}
++v2;
}
while ( *((_DWORD *)a1 + 3) > v2 );
}
return result;
}

original_code:
void invert_image(JImage *img) {
    int x, y;
    for(y=0; y<img->h; y++) {
        for(x=0; x<img->w; x++) {
            { (img)->data[(y) * (img)->w + (x)] = (0xFFFFFF - ((img)->data[(y) * (img)->w + (x)])); };
        }
    }
}

canonical_original_code:
void invert_image(struct JImage *img) {
    int x; int y;
    for(y=0; y<img->h; y++) {
        for(x=0; x<img->w; x++) {
            { (img)->data[(y) * (img)->w + (x)] = (0xFFFFFF - ((img)->data[(y) * (img)->w + (x)])); };
        }
    }
}


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

result = (unsigned int)(*((_DWORD *)a1 + 3) * *((_DWORD *)a1 + 2));
if ( (int)result > 0 )
{
v3 = *a1;
result = 0LL;
do
*(_DWORD *)(v3 + 4 * result++) = a2;
while ( *((_DWORD *)a1 + 3) * *((_DWORD *)a1 + 2) > (int)result );
}
return result;
}

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

result = (unsigned int)(*((_DWORD *)a1 + 3) * *((_DWORD *)a1 + 2));
if ( (int)result > 0 )
{
v3 = *a1;
result = 0LL;
do
*(_DWORD *)(v3 + 4 * result++) = a2;
while ( *((_DWORD *)a1 + 3) * *((_DWORD *)a1 + 2) > (int)result );
}
return result;
}

original_code:
void fill_image(JImage *img, Uint32 c) {
    int i;
    for(i=0; i<img->w * img->h; i++)
        img->data[i] = c;
}

canonical_original_code:
void fill_image(struct JImage *img, unsigned int c) {
    int i;
    for(i=0; i<img->w * img->h; i++)
        img->data[i] = c;
}


original_code:
void blit_image(JImage *dest, int dx, int dy, JImage *src, int sx, int sy, int w, int h) {
    int x, y;
    if(dx < 0) {
        w += dx;
        sx += dx;
        dx = 0;
    }
    if(dy < 0) {
        h += dy;
        sy += dy;
        dy = 0;
    }
    if(sx < 0) {
        w += sx;
        dx += sx;
        sx = 0;
    }
    if(sy < 0) {
        h += sy;
        dy += sy;
        sy = 0;
    }
    if(dx + w > dest->w)
        w = dest->w - dx;
    if(dy + h > dest->h)
        h = dest->h - dy;
    if(sx + w > src->w)
        w = src->w - sx;
    if(sy + h > src->h)
        h = src->h - sy;
    if(dx >= dest->w || dy >= dest->h || w <= 0 || h <= 0)
        return;
    for(y=0; y<h; y++)
        for(x=0; x<w; x++)
            { (dest)->data[(dy+y) * (dest)->w + (dx+x)] = (((src)->data[(sy+y) * (src)->w + (sx+x)])); };
}

canonical_original_code:
void blit_image(struct JImage *dest, int dx, int dy, struct JImage *src, int sx, int sy, int w, int h) {
    int x; int y;
    if(dx < 0) {
        w += dx;
        sx += dx;
        dx = 0;
    }
    if(dy < 0) {
        h += dy;
        sy += dy;
        dy = 0;
    }
    if(sx < 0) {
        w += sx;
        dx += sx;
        sx = 0;
    }
    if(sy < 0) {
        h += sy;
        dy += sy;
        sy = 0;
    }
    if(dx + w > dest->w)
        w = dest->w - dx;
    if(dy + h > dest->h)
        h = dest->h - dy;
    if(sx + w > src->w)
        w = src->w - sx;
    if(sy + h > src->h)
        h = src->h - sy;
    if(dx >= dest->w || dy >= dest->h || w <= 0 || h <= 0)
        return;
    for(y=0; y<h; y++)
        for(x=0; x<w; x++)
            { (dest)->data[(dy+y) * (dest)->w + (dx+x)] = (((src)->data[(sy+y) * (src)->w + (sx+x)])); };
}

variable_types: dx int

variable_types: dy int

variable_types: sx int

variable_types: sy int

variable_types: w int

variable_types: h int


original_code:
void blit_sprite(JImage *dest, int dx, int dy, JImage *sprite) {
    blit_image(dest, dx, dy, sprite, 0, 0, sprite->w, sprite->h);
}

canonical_original_code:
void blit_sprite(struct JImage *dest, int dx, int dy, struct JImage *sprite) {
    blit_image(dest, dx, dy, sprite, 0, 0, sprite->w, sprite->h);
}

variable_types: struct JImage { unsigned int *data; int w; int h; } *

variable_types:
sprite
struct JImage *


repo: jon/libjs

decompiled_code:
void *js_alloc()
{
return calloc(0x908uLL, 1uLL);
}

canonical_decompiled_code:
void *func6()
{
return calloc(0x908uLL, 1uLL);
}

original_code:
static js_t *js_alloc() {
    js_t *js;
    js = (js_t *)malloc(sizeof(js_t));
    if (js == ((void *)0))
        return ((void *)0);
    memset(js, 0, sizeof(js_t));
    return js;
}

canonical_original_code:
static struct js *js_alloc() {
    struct js *js;
    js = (struct js *)malloc(sizeof(js_t));
    if (js == ((void *)0))
        return ((void *)0);
    memset(js, 0, sizeof(js_t));
    return js;
}

variable_types: struct js { int fd; struct js_state { unsigned char buttons[256]; double axes[256]; } state; } *

user_defined_types: struct js { int fd; struct js_state state; }


decompiled_code:
void *__fastcall js_poll_event(int *a1)
{
bool v1; // cc
void *result; // rax

if ( !a1 )
__assert_fail("js != NULL", "js.c", 0x56u, "js_poll_event");
v1 = (int)read(*a1, &event_1, 8uLL) <= 7;
result = &event_1;
if ( v1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
void *__fastcall func8(int *a1)
{
bool v1; // cc
void *result; // rax

if ( !a1 )
__assert_fail("js != NULL", "js.c", 0x56u, "js_poll_event");
v1 = (int)read(*a1, &event_1, 8uLL) <= 7;
result = &event_1;
if ( v1 )
result = 0LL;
return result;
}

original_code:
js_event_t *js_poll_event(js_t *js) {
    static js_event_t event;
    ((void) sizeof ((js != ((void *)0)) ? 1 : 0), __extension__ ({ if (js != ((void *)0)) ; else __assert_fail ("js != NULL", "js.c", 86, __extension__ __PRETTY_FUNCTION__); }));
    int len = read(js->fd, &event, sizeof(event));
    if (len < (int)sizeof(event))
        return ((void *)0);
    return &event;
}

canonical_original_code:
struct js_event *js_poll_event(struct js *js) {
    static struct js_event event;
    ((void) sizeof ((js != ((void *)0)) ? 1 : 0), __extension__ ({ if (js != ((void *)0)) ; else __assert_fail ("js != NULL", "js.c", 86, __extension__ __PRETTY_FUNCTION__); }));
    int len = read(js->fd, &event, sizeof(event));
    if (len < (int)sizeof(event))
        return ((void *)0);
    return &event;
}

variable_types: len int

return_type: struct js_event { unsigned int time; short value; unsigned char type; unsigned char number; } *

user_defined_types: struct js_state { unsigned char buttons[256]; double axes[256]; }


decompiled_code:
__int64 __fastcall js_poll_state(__int64 a1)
{
__int64 v1; // rax
char v2; // dl
unsigned int v3; // er8
__int64 result; // rax
__int64 v5; // rdx
double v6; // xmm0_8

v1 = js_poll_event();
if ( !v1 )
return (unsigned int)-1;
v2 = *(_BYTE *)(v1 + 6);
if ( v2 == 1 )
{
*(_BYTE *)(a1 + *(unsigned __int8 *)(v1 + 7) + 8) = *(_WORD *)(v1 + 4);
result = 0LL;
}
else
{
v3 = 0;
if ( v2 != 2 )
return v3;
v5 = *(unsigned __int8 *)(v1 + 7);
v6 = (double)*(__int16 *)(v1 + 4) * 0.000030517578125;
result = 0LL;
*(double *)(a1 + 8 * v5 + 264) = v6;
}
return result;
}

original_code:
int js_poll_state(js_t *js) {
    js_event_t *event = js_poll_event(js);
    if (event == ((void *)0))
        return -1;
    switch (event->type) {
        case 0x02:
            js->state.axes[event->number] = (double)event->value / 32768.0;
            break;
        case 0x01:
            js->state.buttons[event->number] = event->value;
            break;
        default:
            break;
    }
    return 0;
}

canonical_original_code:
int js_poll_state(struct js *js) {
    struct js_event *event = js_poll_event(js);
    if (event == ((void *)0))
        return -1;
    switch (event->type) {
        case 0x02:
            js->state.axes[event->number] = (double)event->value / 32768.0;
            break;
        case 0x01:
            js->state.buttons[event->number] = event->value;
            break;
        default:
            break;
    }
    return 0;
}

variable_types: struct js_event { unsigned int time; short value; unsigned char type; unsigned char number; } *


decompiled_code:
void __fastcall js_close(void *ptr)
{
if ( !ptr )
__assert_fail("js != NULL", "js.c", 0x75u, "js_close");
close(*(_DWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
if ( !ptr )
__assert_fail("js != NULL", "js.c", 0x75u, "js_close");
close(*(_DWORD *)ptr);
free(ptr);
}

original_code:
void js_close(js_t *js) {
    ((void) sizeof ((js != ((void *)0)) ? 1 : 0), __extension__ ({ if (js != ((void *)0)) ; else __assert_fail ("js != NULL", "js.c", 117, __extension__ __PRETTY_FUNCTION__); }));
    close(js->fd);
    free(js);
}

canonical_original_code:
void js_close(struct js *js) {
    ((void) sizeof ((js != ((void *)0)) ? 1 : 0), __extension__ ({ if (js != ((void *)0)) ; else __assert_fail ("js != NULL", "js.c", 117, __extension__ __PRETTY_FUNCTION__); }));
    close(js->fd);
    free(js);
}


decompiled_code:
void __fastcall ldap_free_friendlymap(void **a1)
{
void **v1; // rbp
void *v3; // rdi
void *v4; // rdi

v1 = (void **)*a1;
if ( *a1 )
{
v3 = *v1;
if ( *v1 )
{
do
{
free(v3);
v4 = v1[1];
v1 += 2;
free(v4);
v3 = *v1;
}
while ( *v1 );
v1 = (void **)*a1;
}
free(v1);
*a1 = 0LL;
}
}

original_code:
void
ldap_free_friendlymap( LDAPFriendlyMap **map )
{
 LDAPFriendlyMap* pF = *map;
 if ( pF == ((void *)0) )
  return;
 while ( pF->lf_unfriendly )
 {
  free( pF->lf_unfriendly );
  free( pF->lf_friendly );
  pF++;
 }
 free( *map );
 *map = ((void *)0);
}

canonical_original_code:
void ldap_free_friendlymap(struct ldap_friendly **map)
{
 struct ldap_friendly *pF = *map;
 if ( pF == ((void *)0) )
  return;
 while ( pF->lf_unfriendly )
 {
  free( pF->lf_unfriendly );
  free( pF->lf_friendly );
  pF++;
 }
 free( *map );
 *map = ((void *)0);
}

variable_types: struct ldap_friendly { char *lf_unfriendly; char *lf_friendly; } **


decompiled_code:
__int64 __fastcall break_into_words(__int64 a1, __int64 a2, _QWORD *a3)
{
void *v4; // rax
void *v5; // rbp
__int64 v6; // rbx
__int64 v7; // r15
unsigned int v8; // er14
char *v9; // rax
char v11[64]; // [rsp+8h] [rbp-40h] BYREF

v4 = calloc(1uLL, 8uLL);
if ( !v4 )
return (unsigned int)-1;
v5 = v4;
v6 = ldap_pvt_strtok(a1, a2, v11);
if ( v6 )
{
v7 = 0LL;
v8 = 0;
while ( 1 )
{
v9 = (char *)realloc(v5, v7 + 16);
v5 = v9;
if ( !v9 )
return (unsigned int)-1;
*(_QWORD *)&v9[v7] = v6;
v7 += 8LL;
*(_QWORD *)&v9[v7] = 0LL;
++v8;
v6 = ldap_pvt_strtok(0LL, a2, v11);
if ( !v6 )
goto LABEL_6;
}
}
v8 = 0;
LABEL_6:
*a3 = v5;
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, _QWORD *a3)
{
void *v4; // rax
void *v5; // rbp
__int64 v6; // rbx
__int64 v7; // r15
unsigned int v8; // er14
char *v9; // rax
char v11[64]; // [rsp+8h] [rbp-40h] BYREF

v4 = calloc(1uLL, 8uLL);
if ( !v4 )
return (unsigned int)-1;
v5 = v4;
v6 = ldap_pvt_strtok(a1, a2, v11);
if ( v6 )
{
v7 = 0LL;
v8 = 0;
while ( 1 )
{
v9 = (char *)realloc(v5, v7 + 16);
v5 = v9;
if ( !v9 )
return (unsigned int)-1;
*(_QWORD *)&v9[v7] = v6;
v7 += 8LL;
*(_QWORD *)&v9[v7] = 0LL;
++v8;
v6 = ldap_pvt_strtok(0LL, a2, v11);
if ( !v6 )
goto LABEL_6;
}
}
v8 = 0;
LABEL_6:
*a3 = v5;
return v8;
}

original_code:
static int
break_into_words( char *str, const char *delims, char ***wordsp )
{
    char *word, **words;
    int count;
    char *tok_r;
    if (( words = (char **)(calloc((1),(sizeof( char * ))))) == ((void *)0) ) {
 return( -1 );
    }
    count = 0;
    words[ count ] = ((void *)0);
    word = ldap_pvt_strtok( str, delims, &tok_r );
    while ( word != ((void *)0) ) {
 if (( words = (char **)(realloc((words),(( count + 2 ) * sizeof( char * ))))) == ((void *)0) ) {
     return( -1 );
 }
 words[ count ] = word;
 words[ ++count ] = ((void *)0);
 word = ldap_pvt_strtok( ((void *)0), delims, &tok_r );
    }
    *wordsp = words;
    return( count );
}

canonical_original_code:
static int break_into_words(char *str, char *delims, char ***wordsp)
{
    char *word; char **words;
    int count;
    char *tok_r;
    if (( words = (char **)(calloc((1),(sizeof( char * ))))) == ((void *)0) ) {
 return( -1 );
    }
    count = 0;
    words[ count ] = ((void *)0);
    word = ldap_pvt_strtok( str, delims, &tok_r );
    while ( word != ((void *)0) ) {
 if (( words = (char **)(realloc((words),(( count + 2 ) * sizeof( char * ))))) == ((void *)0) ) {
     return( -1 );
 }
 words[ count ] = word;
 words[ ++count ] = ((void *)0);
 word = ldap_pvt_strtok( ((void *)0), delims, &tok_r );
    }
    *wordsp = words;
    return( count );
}

variable_types:
str
char *

variable_types:
delims
char *

variable_types:
wordsp
char ***

variable_types:
word
char *

variable_types:
words
char **

variable_types: count int


decompiled_code:
void __fastcall ldap_setfilteraffixes(__int64 a1, const char *a2, char *a3)
{
char *v3; // r12
void *v6; // rdi
void *v7; // rdi

v3 = (char *)a2;
v6 = *(void **)(a1 + 1096);
if ( v6 )
free(v6);
if ( a2 )
v3 = strdup(a2);
v7 = *(void **)(a1 + 1104);
*(_QWORD *)(a1 + 1096) = v3;
if ( v7 )
free(v7);
if ( a3 )
a3 = strdup(a3);
*(_QWORD *)(a1 + 1104) = a3;
}

original_code:
void
ldap_setfilteraffixes( LDAPFiltDesc *lfdp, const char *prefix, const char *suffix )
{
    if ( lfdp->lfd_filtprefix != ((void *)0) ) {
 (free(lfdp->lfd_filtprefix));
    }
    lfdp->lfd_filtprefix = ( prefix == ((void *)0) ) ? ((void *)0) : (strdup(prefix));
    if ( lfdp->lfd_filtsuffix != ((void *)0) ) {
 (free(lfdp->lfd_filtsuffix));
    }
    lfdp->lfd_filtsuffix = ( suffix == ((void *)0) ) ? ((void *)0) : (strdup(suffix));
}

canonical_original_code:
void ldap_setfilteraffixes(struct ldap_filt_desc *lfdp, char *prefix, char *suffix)
{
    if ( lfdp->lfd_filtprefix != ((void *)0) ) {
 (free(lfdp->lfd_filtprefix));
    }
    lfdp->lfd_filtprefix = ( prefix == ((void *)0) ) ? ((void *)0) : (strdup(prefix));
    if ( lfdp->lfd_filtsuffix != ((void *)0) ) {
 (free(lfdp->lfd_filtsuffix));
    }
    lfdp->lfd_filtsuffix = ( suffix == ((void *)0) ) ? ((void *)0) : (strdup(suffix));
}

variable_types: struct ldap_filt_desc { struct ldap_filt_list { char *lfl_tag; char *lfl_pattern; char *lfl_delims; struct ldap_filt_info { char *lfi_filter; char *lfi_desc; int lfi_scope; int lfi_isexact; struct ldap_filt_info *lfi_next; } *lfl_ilist; struct ldap_filt_list *lfl_next; } *lfd_filtlist; struct ldap_filt_info *lfd_curfip; struct ldap_filt_info lfd_retfi; char lfd_filter[1024]; char *lfd_curval; char *lfd_curvalcopy; char **lfd_curvalwords; char *lfd_filtprefix; char *lfd_filtsuffix; } *

variable_types:
prefix
char *

variable_types:
suffix
char *

user_defined_types: struct ldap_filt_desc { struct ldap_filt_list *lfd_filtlist; struct ldap_filt_info *lfd_curfip; struct ldap_filt_info lfd_retfi; char lfd_filter[1024]; char *lfd_curval; char *lfd_curvalcopy; char **lfd_curvalwords; char *lfd_filtprefix; char *lfd_filtsuffix; }

user_defined_types: struct ldap_filt_list { char *lfl_tag; char *lfl_pattern; char *lfl_delims; struct ldap_filt_info *lfl_ilist; struct ldap_filt_list *lfl_next; }