main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__int64 v4; // rbx
int v5; // eax
__int64 v6; // r12
__int64 v7; // r13
__int64 v8; // rsi
__int64 v9; // rbp
size_t v10; // rdi
__int64 v11; // rbx
char *v12; // r12
__int64 v13; // rax
void *(*v14)(void *); // r13
__int64 v15; // rdx
__int64 v16; // rbx
int v17; // ebp
_DWORD *v18; // r14
void *v19; // rcx
pthread_t *v20; // rdi
__int64 v21; // r14
int v22; // eax
__time_t v23; // rax
__int64 v24; // rax
char *v26; // rax
int *v27; // rax
char *v28; // rax
int *v29; // rax
char *v30; // rax
int v31; // [rsp+4h] [rbp-884h]
__int64 v32; // [rsp+8h] [rbp-880h]
char *v33; // [rsp+10h] [rbp-878h]
__time_t v34; // [rsp+18h] [rbp-870h]
__int64 v35; // [rsp+20h] [rbp-868h]
__int64 (__fastcall *v36)(unsigned int); // [rsp+28h] [rbp-860h]
__int64 n; // [rsp+30h] [rbp-858h]
void *s; // [rsp+38h] [rbp-850h]
__int64 v39; // [rsp+40h] [rbp-848h]
unsigned int v40; // [rsp+48h] [rbp-840h]
void *(*start_routine[64])(void *); // [rsp+50h] [rbp-838h] BYREF
__int64 v42[64]; // [rsp+250h] [rbp-638h] BYREF
__int64 v43[64]; // [rsp+450h] [rbp-438h] BYREF
__int64 v44[71]; // [rsp+650h] [rbp-238h] BYREF

v3 = 11;
v4 = 4LL;
memset(start_routine, 0, sizeof(start_routine));
start_routine[0] = (void *(*)(void *))dumb_thread;
memset(v42, 0, sizeof(v42));
v42[1] = (__int64)mutex_init;
memset(v43, 0, sizeof(v43));
v43[0] = (__int64)dumb_fini;
memset(v44, 0, 0x200uLL);
start_routine[1] = (void *(*)(void *))mutex_thread;
v44[0] = (__int64)"pure increment test";
v44[1] = (__int64)"mutexed test";
v43[1] = (__int64)mutex_fini;
v44[2] = (__int64)"lock increment test";
v42[2] = (__int64)lock_init;
start_routine[2] = (void *(*)(void *))lock_thread;
v43[2] = (__int64)lock_fini;
v44[3] = (__int64)"lock compare&swap test";
v42[3] = (__int64)lock2_init;
start_routine[3] = (void *(*)(void *))lock2_thread;
v43[3] = (__int64)lock2_fini;
v44[4] = (__int64)"spinlock test";
v42[4] = (__int64)spin_init;
start_routine[4] = (void *(*)(void *))spin_thread;
v43[4] = (__int64)spin_fini;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "?hf:t:");
if ( v5 == -1 )
break;
if ( v5 == 104 )
goto LABEL_10;
if ( v5 > 104 )
{
if ( v5 == 116 )
v4 = (unsigned int)atoi(optarg);
}
else
{
if ( v5 == 63 )
{
LABEL_10:
usage((char *)*argv);
exit(0);
}
if ( v5 == 102 )
v3 = atoi(optarg);
}
}
printf("CPU ");
fflush(stdout);
system("cat /proc/cpuinfo |grep 'model name'|head -n1");
printf("Thread libs: ");
fflush(stdout);
system("getconf GNU_LIBPTHREAD_VERSION");
v6 = sysconf(84);
if ( v6 <= 0 )
{
v29 = _errno_location();
v30 = strerror(*v29);
fprintf(stdout, "Could not determine number of CPUs online:\n%s\n", v30);
exit(1);
}
v7 = sysconf(83);
if ( v7 <= 0 )
{
v27 = _errno_location();
v28 = strerror(*v27);
fprintf(stdout, "Could not determine number of CPUs configured:\n%s\n", v28);
}
printf("%ld of %ld cores online\n", v6, v7);
v31 = v6;
v32 = factor(v3);
printf("Additition threads: %d\n", (unsigned int)v4);
v8 = v3;
v9 = v6 + v4;
printf("Big number: %d! = 0x%lx\n", v8, v32);
v39 = v6 + v4;
n = 8 * (v6 + v4);
v10 = 24 * (v6 + v4);
v11 = 0LL;
v12 = (char *)malloc(n);
s = malloc(v10);
printf("Thrds:\t");
do
{
printf("%d\t", (unsigned int)(v11 + 1));
v13 = v11++;
}
while ( v9 >= v13 + 2 );
putchar(10);
v35 = 0LL;
v36 = dumb_init;
do
{
v14 = start_routine[v35];
v15 = (unsigned int)v35;
if ( !v14 )
break;
v16 = 1LL;
fprintf(stdout, "%s \n", (const char *)v44[v35]);
printf("*\t");
fflush(stdout);
do
{
v40 = v16;
memset(v12, 0, n);
memset(s, 0, n);
v36(v16);
v33 = v12;
v34 = epochmsec();
v17 = 0;
v18 = s;
do
{
v18[2] = v17;
v19 = v18;
v20 = (pthread_t *)v12;
v18[1] = v16;
++v17;
*v18 = v31;
v18 += 6;
v12 += 8;
*((_QWORD *)v18 - 1) = v32;
pthread_create(v20, 0LL, v14, v19);
}
while ( v17 != (_DWORD)v16 );
v12 = v33;
v21 = 0LL;
do
{
v22 = pthread_join(*(_QWORD *)&v33[8 * v21], 0LL);
if ( v22 )
{
v26 = strerror(v22);
fprintf(stdout, "Thread %d join error: %s\n", (unsigned int)v21, v26);
exit(1);
}
++v21;
}
while ( v21 != v16 );
v16 = v21 + 1;
((void (__fastcall *)(_QWORD))v43[v35])(v40);
v23 = epochmsec();
printf("%ld \t", v23 - v34);
fflush(stdout);
}
while ( v39 != v21 );
putchar(10);
v24 = v35;
v15 = (unsigned int)(v35 + 1);
if ( v35 == 63 )
{
v15 = 64LL;
break;
}
++v35;
v36 = (__int64 (__fastcall *)(unsigned int))v42[v24 + 1];
}
while ( v36 );
fprintf(stdout, "Done. %d tests at all.\n", v15);
free(v12);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__int64 v4; // rbx
int v5; // eax
__int64 v6; // r12
__int64 v7; // r13
__int64 v8; // rsi
__int64 v9; // rbp
size_t v10; // rdi
__int64 v11; // rbx
char *v12; // r12
__int64 v13; // rax
void *(*v14)(void *); // r13
__int64 v15; // rdx
__int64 v16; // rbx
int v17; // ebp
_DWORD *v18; // r14
void *v19; // rcx
pthread_t *v20; // rdi
__int64 v21; // r14
int v22; // eax
__time_t v23; // rax
__int64 v24; // rax
char *v26; // rax
int *v27; // rax
char *v28; // rax
int *v29; // rax
char *v30; // rax
int v31; // [rsp+4h] [rbp-884h]
__int64 v32; // [rsp+8h] [rbp-880h]
char *v33; // [rsp+10h] [rbp-878h]
__time_t v34; // [rsp+18h] [rbp-870h]
__int64 v35; // [rsp+20h] [rbp-868h]
__int64 (__fastcall *v36)(unsigned int); // [rsp+28h] [rbp-860h]
__int64 n; // [rsp+30h] [rbp-858h]
void *s; // [rsp+38h] [rbp-850h]
__int64 v39; // [rsp+40h] [rbp-848h]
unsigned int v40; // [rsp+48h] [rbp-840h]
void *(*start_routine[64])(void *); // [rsp+50h] [rbp-838h] BYREF
__int64 v42[64]; // [rsp+250h] [rbp-638h] BYREF
__int64 v43[64]; // [rsp+450h] [rbp-438h] BYREF
__int64 v44[71]; // [rsp+650h] [rbp-238h] BYREF

v3 = 11;
v4 = 4LL;
memset(start_routine, 0, sizeof(start_routine));
start_routine[0] = (void *(*)(void *))dumb_thread;
memset(v42, 0, sizeof(v42));
v42[1] = (__int64)mutex_init;
memset(v43, 0, sizeof(v43));
v43[0] = (__int64)dumb_fini;
memset(v44, 0, 0x200uLL);
start_routine[1] = (void *(*)(void *))mutex_thread;
v44[0] = (__int64)"pure increment test";
v44[1] = (__int64)"mutexed test";
v43[1] = (__int64)mutex_fini;
v44[2] = (__int64)"lock increment test";
v42[2] = (__int64)lock_init;
start_routine[2] = (void *(*)(void *))lock_thread;
v43[2] = (__int64)lock_fini;
v44[3] = (__int64)"lock compare&swap test";
v42[3] = (__int64)lock2_init;
start_routine[3] = (void *(*)(void *))lock2_thread;
v43[3] = (__int64)lock2_fini;
v44[4] = (__int64)"spinlock test";
v42[4] = (__int64)spin_init;
start_routine[4] = (void *(*)(void *))spin_thread;
v43[4] = (__int64)spin_fini;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "?hf:t:");
if ( v5 == -1 )
break;
if ( v5 == 104 )
goto LABEL_10;
if ( v5 > 104 )
{
if ( v5 == 116 )
v4 = (unsigned int)atoi(optarg);
}
else
{
if ( v5 == 63 )
{
LABEL_10:
func15((char *)*argv);
exit(0);
}
if ( v5 == 102 )
v3 = atoi(optarg);
}
}
printf("CPU ");
fflush(stdout);
system("cat /proc/cpuinfo |grep 'model name'|head -n1");
printf("Thread libs: ");
fflush(stdout);
system("getconf GNU_LIBPTHREAD_VERSION");
v6 = sysconf(84);
if ( v6 <= 0 )
{
v29 = _errno_location();
v30 = strerror(*v29);
fprintf(stdout, "Could not determine number of CPUs online:\n%s\n", v30);
exit(1);
}
v7 = sysconf(83);
if ( v7 <= 0 )
{
v27 = _errno_location();
v28 = strerror(*v27);
fprintf(stdout, "Could not determine number of CPUs configured:\n%s\n", v28);
}
printf("%ld of %ld cores online\n", v6, v7);
v31 = v6;
v32 = func16(v3);
printf("Additition threads: %d\n", (unsigned int)v4);
v8 = v3;
v9 = v6 + v4;
printf("Big number: %d! = 0x%lx\n", v8, v32);
v39 = v6 + v4;
n = 8 * (v6 + v4);
v10 = 24 * (v6 + v4);
v11 = 0LL;
v12 = (char *)malloc(n);
s = malloc(v10);
printf("Thrds:\t");
do
{
printf("%d\t", (unsigned int)(v11 + 1));
v13 = v11++;
}
while ( v9 >= v13 + 2 );
putchar(10);
v35 = 0LL;
v36 = dumb_init;
do
{
v14 = start_routine[v35];
v15 = (unsigned int)v35;
if ( !v14 )
break;
v16 = 1LL;
fprintf(stdout, "%s \n", (const char *)v44[v35]);
printf("*\t");
fflush(stdout);
do
{
v40 = v16;
memset(v12, 0, n);
memset(s, 0, n);
v36(v16);
v33 = v12;
v34 = func17();
v17 = 0;
v18 = s;
do
{
v18[2] = v17;
v19 = v18;
v20 = (pthread_t *)v12;
v18[1] = v16;
++v17;
*v18 = v31;
v18 += 6;
v12 += 8;
*((_QWORD *)v18 - 1) = v32;
pthread_create(v20, 0LL, v14, v19);
}
while ( v17 != (_DWORD)v16 );
v12 = v33;
v21 = 0LL;
do
{
v22 = pthread_join(*(_QWORD *)&v33[8 * v21], 0LL);
if ( v22 )
{
v26 = strerror(v22);
fprintf(stdout, "Thread %d join error: %s\n", (unsigned int)v21, v26);
exit(1);
}
++v21;
}
while ( v21 != v16 );
v16 = v21 + 1;
((void (__fastcall *)(_QWORD))v43[v35])(v40);
v23 = func17();
printf("%ld \t", v23 - v34);
fflush(stdout);
}
while ( v39 != v21 );
putchar(10);
v24 = v35;
v15 = (unsigned int)(v35 + 1);
if ( v35 == 63 )
{
v15 = 64LL;
break;
}
++v35;
v36 = (__int64 (__fastcall *)(unsigned int))v42[v24 + 1];
}
while ( v36 );
fprintf(stdout, "Done. %d tests at all.\n", v15);
free(v12);
return 0;
}

original_code:
int main(int argc, char** argv, char **env){
 void * (*per_thread[0x40])(void *) = {0};
 int (*init_test[0x40])(int) = {0};
 int (*fini_test[0x40])(int) = {0};
 char *titles[0x40] = {0};
 int tests = 0;
 titles[tests] = "pure increment test";
 init_test[tests] = &dumb_init;
 per_thread[tests] = &dumb_thread;
 fini_test[tests] = &dumb_fini;
 tests++;
 titles[tests] = "mutexed test";
 init_test[tests] = &mutex_init;
 per_thread[tests] = &mutex_thread;
 fini_test[tests] = &mutex_fini;
 tests++;
 titles[tests] = "lock increment test";
 init_test[tests] = &lock_init;
 per_thread[tests] = &lock_thread;
 fini_test[tests] = &lock_fini;
 tests++;
 titles[tests] = "lock compare&swap test";
 init_test[tests] = &lock2_init;
 per_thread[tests] = &lock2_thread;
 fini_test[tests] = &lock2_fini;
 tests++;
 titles[tests] = "spinlock test";
 init_test[tests] = &spin_init;
 per_thread[tests] = &spin_thread;
 fini_test[tests] = &spin_fini;
 tests++;
 unsigned int big_factor = 11;
 unsigned int additition_threads = 4;
 int opt = 0;
 while ((opt = getopt(argc, argv, "?hf:t:")) != -1) {
  switch (opt) {
   case '?':
   case 'h':
    usage(argv[0]);
    exit(0);
    break;
   case 't':
    additition_threads = atoi(optarg);
    break;
   case 'f':
    big_factor = atoi(optarg);
    break;
   default:
    break;
  }
 }
 printf("CPU ");
 fflush(stdout);
 int sys = system("cat /proc/cpuinfo |grep 'model name'|head -n1");
 printf("Thread libs: ");
 fflush(stdout);
 sys = system("getconf GNU_LIBPTHREAD_VERSION");
 long nprocs = -1, nprocs_max = -1;
 nprocs = sysconf(_SC_NPROCESSORS_ONLN);
 if (nprocs < 1)
 {
  fprintf(stdout, "Could not determine number of CPUs online:\n%s\n", strerror ((*__errno_location ())));
  exit (1);
 }
 nprocs_max = sysconf(_SC_NPROCESSORS_CONF);
 if (nprocs_max < 1)
 {
  fprintf(stdout, "Could not determine number of CPUs configured:\n%s\n", strerror ((*__errno_location ())));
 }
 printf ("%ld of %ld cores online\n",nprocs, nprocs_max);
 int test_number = 0;
 position *positions = ((void *)0);
 position next;
 next.nprocs = nprocs;
 next.my_number = 0;
 next.big_number = factor(big_factor);
 printf("Additition threads: %d\n",additition_threads);
 printf("Big number: %d! = 0x%lx\n", big_factor, next.big_number);
 nprocs += additition_threads;
 int thread_number = 0;
 int threads_number = 0;
 int ret = 0;
 int my_number = 0;
 pthread_t *threads = ((void *)0);
 unsigned long before = 0;
 unsigned long after = 0;
 threads = malloc(nprocs * sizeof(pthread_t));
 positions = malloc(nprocs * sizeof(position));
 printf("Thrds:\t");
 for(threads_number = 1; threads_number <= nprocs; threads_number++){
  printf("%d\t",threads_number);
 }
 printf("\n");
 while( 0x40 > test_number && ((void *)0) != init_test[test_number] && ((void *)0) != per_thread[test_number] ){
  fprintf(stdout,"%s \n",titles[test_number]);
  printf("*\t");
  fflush(stdout);
  for(threads_number = 1; threads_number <= nprocs; threads_number++){
   next.my_number = 0;
   next.threads = threads_number;
   my_number = 0;
   memset(threads, 0, nprocs*sizeof(pthread_t));
   memset(positions,0,nprocs*sizeof(positions));
   (*init_test[test_number])(threads_number);
   before = epochmsec();
   for(thread_number = 0; thread_number < threads_number; thread_number++){
    next.my_number = my_number;
    positions[thread_number] = next;
    pthread_create(threads+thread_number,((void *)0),per_thread[test_number],positions+thread_number);
    if(ret != 0){
     fprintf(stdout,"Thread %d create error: %s\n",thread_number, strerror(ret));
     exit (1);
    }
    my_number++;
   }
   for(thread_number = 0; thread_number < threads_number; thread_number++){
    ret = pthread_join(*(threads+thread_number),((void *)0));
    if(ret != 0){
     fprintf(stdout,"Thread %d join error: %s\n",thread_number, strerror(ret));
     exit (1);
    }
   }
   (*fini_test[test_number])(threads_number);
   after = epochmsec();
   printf("%ld \t", after - before);
   fflush(stdout);
  }
  printf("\n");
  test_number++;
 }
 fprintf(stdout, "Done. %d tests at all.\n", test_number);
 free(threads);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv, char **env){
 void *(*per_thread[64])(void *) = {0};
 int (*init_test[64])(int) = {0};
 int (*fini_test[64])(int) = {0};
 char *titles[64] = {0};
 int tests = 0;
 titles[tests] = "pure increment test";
 init_test[tests] = &dumb_init;
 per_thread[tests] = &dumb_thread;
 fini_test[tests] = &dumb_fini;
 tests++;
 titles[tests] = "mutexed test";
 init_test[tests] = &mutex_init;
 per_thread[tests] = &mutex_thread;
 fini_test[tests] = &mutex_fini;
 tests++;
 titles[tests] = "lock increment test";
 init_test[tests] = &lock_init;
 per_thread[tests] = &lock_thread;
 fini_test[tests] = &lock_fini;
 tests++;
 titles[tests] = "lock compare&swap test";
 init_test[tests] = &lock2_init;
 per_thread[tests] = &lock2_thread;
 fini_test[tests] = &lock2_fini;
 tests++;
 titles[tests] = "spinlock test";
 init_test[tests] = &spin_init;
 per_thread[tests] = &spin_thread;
 fini_test[tests] = &spin_fini;
 tests++;
 unsigned int big_factor = 11;
 unsigned int additition_threads = 4;
 int opt = 0;
 while ((opt = getopt(argc, argv, "?hf:t:")) != -1) {
  switch (opt) {
   case '?':
   case 'h':
    usage(argv[0]);
    exit(0);
    break;
   case 't':
    additition_threads = atoi(optarg);
    break;
   case 'f':
    big_factor = atoi(optarg);
    break;
   default:
    break;
  }
 }
 printf("CPU ");
 fflush(stdout);
 int sys = system("cat /proc/cpuinfo |grep 'model name'|head -n1");
 printf("Thread libs: ");
 fflush(stdout);
 sys = system("getconf GNU_LIBPTHREAD_VERSION");
 long nprocs = -1; long nprocs_max = -1;
 nprocs = sysconf(_SC_NPROCESSORS_ONLN);
 if (nprocs < 1)
 {
  fprintf(stdout, "Could not determine number of CPUs online:\n%s\n", strerror ((*__errno_location ())));
  exit (1);
 }
 nprocs_max = sysconf(_SC_NPROCESSORS_CONF);
 if (nprocs_max < 1)
 {
  fprintf(stdout, "Could not determine number of CPUs configured:\n%s\n", strerror ((*__errno_location ())));
 }
 printf ("%ld of %ld cores online\n",nprocs, nprocs_max);
 int test_number = 0;
 struct position *positions = ((void *)0);
 struct position next;
 next.nprocs = nprocs;
 next.my_number = 0;
 next.big_number = factor(big_factor);
 printf("Additition threads: %d\n",additition_threads);
 printf("Big number: %d! = 0x%lx\n", big_factor, next.big_number);
 nprocs += additition_threads;
 int thread_number = 0;
 int threads_number = 0;
 int ret = 0;
 int my_number = 0;
 unsigned long *threads = ((void *)0);
 unsigned long before = 0;
 unsigned long after = 0;
 threads = malloc(nprocs * sizeof(pthread_t));
 positions = malloc(nprocs * sizeof(position));
 printf("Thrds:\t");
 for(threads_number = 1; threads_number <= nprocs; threads_number++){
  printf("%d\t",threads_number);
 }
 printf("\n");
 while( 0x40 > test_number && ((void *)0) != init_test[test_number] && ((void *)0) != per_thread[test_number] ){
  fprintf(stdout,"%s \n",titles[test_number]);
  printf("*\t");
  fflush(stdout);
  for(threads_number = 1; threads_number <= nprocs; threads_number++){
   next.my_number = 0;
   next.threads = threads_number;
   my_number = 0;
   memset(threads, 0, nprocs*sizeof(pthread_t));
   memset(positions,0,nprocs*sizeof(positions));
   (*init_test[test_number])(threads_number);
   before = epochmsec();
   for(thread_number = 0; thread_number < threads_number; thread_number++){
    next.my_number = my_number;
    positions[thread_number] = next;
    pthread_create(threads+thread_number,((void *)0),per_thread[test_number],positions+thread_number);
    if(ret != 0){
     fprintf(stdout,"Thread %d create error: %s\n",thread_number, strerror(ret));
     exit (1);
    }
    my_number++;
   }
   for(thread_number = 0; thread_number < threads_number; thread_number++){
    ret = pthread_join(*(threads+thread_number),((void *)0));
    if(ret != 0){
     fprintf(stdout,"Thread %d join error: %s\n",thread_number, strerror(ret));
     exit (1);
    }
   }
   (*fini_test[test_number])(threads_number);
   after = epochmsec();
   printf("%ld \t", after - before);
   fflush(stdout);
  }
  printf("\n");
  test_number++;
 }
 fprintf(stdout, "Done. %d tests at all.\n", test_number);
 free(threads);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
env
char **

variable_types:
titles
char *[64]

variable_types: tests int

variable_types: opt int

variable_types: sys int

variable_types: nprocs long

variable_types: struct position { int nprocs; int threads; int my_number; unsigned long big_number; }

variable_types:
threads
unsigned long *

variable_types:
before
unsigned long

variable_types:
after
unsigned long


ComputerMove

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

result = a1 + 12LL * a3;
*(_DWORD *)(result + 4LL * a4) = *a2;
return result;
}

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

result = a1 + 12LL * a3;
*(_DWORD *)(result + 4LL * a4) = *a2;
return result;
}

original_code:
void ComputerMove(int gField[3][3], int *computerAnswer, int i, int j)
{
 gField[i][j] = *computerAnswer;
}

variable_types:
gField
int [3][3]

variable_types:
computerAnswer
int *

variable_types: i int

variable_types: j int

return_type: void


ChekingPlayerCanWin

original_code:
void ChekingPlayerCanWin(int gField[3][3], gboolean *gfoundDanger, int *playerAnswer, int *computerAnswer)
{
 *gfoundDanger = (0);
 int i;
 for (i = 0; i < 3; i++)
 {
  if (*gfoundDanger) break;
  int j;
  int free = -1;
  int filling = 0;
  for (j = 0; j < 3; j++)
  {
   if (*gfoundDanger) break;
   if (gField[i][j] == *playerAnswer)
    filling++;
   if (gField[i][j] == 0)
    free = j;
   if ((filling == 3 -1 )&&(free >= 0))
   {
    *gfoundDanger = (!(0));
    ComputerMove(gField, computerAnswer, i, free);
   }
  }
  free = -1;
  filling = 0;
  for (j = 0; j < 3; j++)
  {
   if (*gfoundDanger) break;
   if (gField[j][i] == *playerAnswer)
    filling++;
   if (gField[j][i] == 0)
    free = j;
   if ((filling == 3 - 1)&&(free >= 0))
   {
    *gfoundDanger = (!(0));
    ComputerMove(gField, computerAnswer, free, i);
   }
  }
  if (i == 0)
  {
   free = -1;
   filling = 0;
   for (j = 0; j < 3; j++)
   {
    if (*gfoundDanger) break;
    if (gField[j][j] == *playerAnswer)
     filling++;
    if (gField[j][j] == 0)
     free = j;
    if ((filling == 3 -1 )&&(free >= 0))
    {
     *gfoundDanger = (!(0));
     ComputerMove(gField, computerAnswer, free, free);
    }
   }
   free = -1;
   filling = 0;
   for (j = 0; j < 3; j++)
   {
    if (*gfoundDanger) break;
    if (gField[3 - j-1][j] == *playerAnswer)
     filling++;
    if (gField[3 - j-1][j] == 0)
     free = j;
    if ((filling == 3 -1 )&&(free >= 0))
    {
     *gfoundDanger = (!(0));
     ComputerMove(gField, computerAnswer, 3 - free - 1, free);
    }
   }
  }
 }
}

canonical_original_code:
void ChekingPlayerCanWin(int gField[3][3], int *gfoundDanger, int *playerAnswer, int *computerAnswer)
{
 *gfoundDanger = (0);
 int i;
 for (i = 0; i < 3; i++)
 {
  if (*gfoundDanger) break;
  int j;
  int free = -1;
  int filling = 0;
  for (j = 0; j < 3; j++)
  {
   if (*gfoundDanger) break;
   if (gField[i][j] == *playerAnswer)
    filling++;
   if (gField[i][j] == 0)
    free = j;
   if ((filling == 3 -1 )&&(free >= 0))
   {
    *gfoundDanger = (!(0));
    ComputerMove(gField, computerAnswer, i, free);
   }
  }
  free = -1;
  filling = 0;
  for (j = 0; j < 3; j++)
  {
   if (*gfoundDanger) break;
   if (gField[j][i] == *playerAnswer)
    filling++;
   if (gField[j][i] == 0)
    free = j;
   if ((filling == 3 - 1)&&(free >= 0))
   {
    *gfoundDanger = (!(0));
    ComputerMove(gField, computerAnswer, free, i);
   }
  }
  if (i == 0)
  {
   free = -1;
   filling = 0;
   for (j = 0; j < 3; j++)
   {
    if (*gfoundDanger) break;
    if (gField[j][j] == *playerAnswer)
     filling++;
    if (gField[j][j] == 0)
     free = j;
    if ((filling == 3 -1 )&&(free >= 0))
    {
     *gfoundDanger = (!(0));
     ComputerMove(gField, computerAnswer, free, free);
    }
   }
   free = -1;
   filling = 0;
   for (j = 0; j < 3; j++)
   {
    if (*gfoundDanger) break;
    if (gField[3 - j-1][j] == *playerAnswer)
     filling++;
    if (gField[3 - j-1][j] == 0)
     free = j;
    if ((filling == 3 -1 )&&(free >= 0))
    {
     *gfoundDanger = (!(0));
     ComputerMove(gField, computerAnswer, 3 - free - 1, free);
    }
   }
  }
 }
}

variable_types:
gfoundDanger
int *

variable_types:
playerAnswer
int *

variable_types: free int

variable_types: filling int


ChekingComputerWin

original_code:
void ChekingComputerWin(int gField[3][3], gboolean *gcomputerWin, int *playerAnswer, int *computerAnswer)
{
 *gcomputerWin = (0);
 int i;
 for (i = 0; i < 3; i++)
 {
  if (*gcomputerWin) break;
  int j;
  int free = -1;
  int filling = 0;
  for (j = 0; j < 3; j++)
  {
   if (*gcomputerWin) break;
   if (gField[i][j] == *computerAnswer)
    filling++;
   if (gField[i][j] == 0)
    free = j;
   if ((filling == 3 -1 )&&(free >= 0))
   {
    *gcomputerWin = (!(0));
    ComputerMove(gField, computerAnswer, i, free);
   }
  }
  free = -1;
  filling = 0;
  for (j = 0; j < 3; j++)
  {
   if (*gcomputerWin) break;
   if (gField[j][i] == *computerAnswer)
    filling++;
   if (gField[j][i] == 0)
    free = j;
   if ((filling == 3 - 1)&&(free >= 0))
   {
    (*gcomputerWin) = (!(0));
    ComputerMove(gField, computerAnswer, free, i);
   }
  }
  if (i == 0)
  {
   free = -1;
   filling = 0;
   for (j = 0; j < 3; j++)
   {
    if (*gcomputerWin) break;
    if (gField[j][j] == *computerAnswer)
     filling++;
    if (gField[j][j] == 0)
     free = j;
    if ((filling == 3 -1 )&&(free >= 0))
    {
     *gcomputerWin = (!(0));
     ComputerMove(gField, computerAnswer, free, free);
    }
   }
   free = -1;
   filling = 0;
   for (j = 0; j < 3; j++)
   {
    if (*gcomputerWin) break;
    if (gField[3 - j-1][j] == *computerAnswer)
     filling++;
    if (gField[3 - j-1][j] == 0)
     free = j;
    if ((filling == 3 -1 )&&(free >= 0))
    {
     *gcomputerWin = (!(0));
     ComputerMove(gField, computerAnswer, 3 - free - 1, free);
    }
   }
  }
 }
}

canonical_original_code:
void ChekingComputerWin(int gField[3][3], int *gcomputerWin, int *playerAnswer, int *computerAnswer)
{
 *gcomputerWin = (0);
 int i;
 for (i = 0; i < 3; i++)
 {
  if (*gcomputerWin) break;
  int j;
  int free = -1;
  int filling = 0;
  for (j = 0; j < 3; j++)
  {
   if (*gcomputerWin) break;
   if (gField[i][j] == *computerAnswer)
    filling++;
   if (gField[i][j] == 0)
    free = j;
   if ((filling == 3 -1 )&&(free >= 0))
   {
    *gcomputerWin = (!(0));
    ComputerMove(gField, computerAnswer, i, free);
   }
  }
  free = -1;
  filling = 0;
  for (j = 0; j < 3; j++)
  {
   if (*gcomputerWin) break;
   if (gField[j][i] == *computerAnswer)
    filling++;
   if (gField[j][i] == 0)
    free = j;
   if ((filling == 3 - 1)&&(free >= 0))
   {
    (*gcomputerWin) = (!(0));
    ComputerMove(gField, computerAnswer, free, i);
   }
  }
  if (i == 0)
  {
   free = -1;
   filling = 0;
   for (j = 0; j < 3; j++)
   {
    if (*gcomputerWin) break;
    if (gField[j][j] == *computerAnswer)
     filling++;
    if (gField[j][j] == 0)
     free = j;
    if ((filling == 3 -1 )&&(free >= 0))
    {
     *gcomputerWin = (!(0));
     ComputerMove(gField, computerAnswer, free, free);
    }
   }
   free = -1;
   filling = 0;
   for (j = 0; j < 3; j++)
   {
    if (*gcomputerWin) break;
    if (gField[3 - j-1][j] == *computerAnswer)
     filling++;
    if (gField[3 - j-1][j] == 0)
     free = j;
    if ((filling == 3 -1 )&&(free >= 0))
    {
     *gcomputerWin = (!(0));
     ComputerMove(gField, computerAnswer, 3 - free - 1, free);
    }
   }
  }
 }
}

variable_types:
gcomputerWin
int *


ClearField

decompiled_code:
void ClearField()
{
gField = 0LL;
*(&gField + 1) = 0LL;
*(&gField + 2) = 0LL;
*(&gField + 3) = 0LL;
*((_DWORD *)&gField + 8) = 0;
}

canonical_decompiled_code:
void func0()
{
gField = 0LL;
*(&gField + 1) = 0LL;
*(&gField + 2) = 0LL;
*(&gField + 3) = 0LL;
*((_DWORD *)&gField + 8) = 0;
}

original_code:
static void ClearField()
{
 int i,j;
 for(i = 0; i < 3; i++)
 {
  for(j = 0; j < 3; j++)
  {
   gField[i][j] = 0;
  }
 }
}

canonical_original_code:
static void ClearField()
{
 int i; int j;
 for(i = 0; i < 3; i++)
 {
  for(j = 0; j < 3; j++)
  {
   gField[i][j] = 0;
  }
 }
}


CellDenermination

decompiled_code:
__int64 __fastcall CellDenermination(int a1, int a2)
{
__int64 v2; // rdx
__int64 result; // rax

v2 = 3LL * (a1 / 100) + a2 / 100;
result = 0LL;
if ( !*((_DWORD *)&gField + v2) )
{
*((_DWORD *)&gField + v2) = playerAnswer;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
__int64 v2; // rdx
__int64 result; // rax

v2 = 3LL * (a1 / 100) + a2 / 100;
result = 0LL;
if ( !*((_DWORD *)&gField + v2) )
{
*((_DWORD *)&gField + v2) = playerAnswer;
result = 1LL;
}
return result;
}

original_code:
static gboolean CellDenermination(int x, int y)
{
 x /= 100;
 y /= 100;
 if (gField[x][y] == 0)
 {
  gField[x][y] = playerAnswer;
  return (!(0));
 }
 return (0);
}

canonical_original_code:
static int CellDenermination(int x, int y)
{
 x /= 100;
 y /= 100;
 if (gField[x][y] == 0)
 {
  gField[x][y] = playerAnswer;
  return (!(0));
 }
 return (0);
}

variable_types: x int

variable_types: y int

return_type: int


DeadHeat

original_code:
static void DeadHeat()
{
 int i,j;
 int filled = 0;
 for (i = 0; i < 3; i++)
 {
  for (j = 0; j < 3; j++)
  {
   if (gField[i][j] != 0)
    filled++;
  }
 }
 if (filled == (3*3))
  gdeadHeat = (!(0));
 else
  gdeadHeat = (0);
}

canonical_original_code:
static void DeadHeat()
{
 int i; int j;
 int filled = 0;
 for (i = 0; i < 3; i++)
 {
  for (j = 0; j < 3; j++)
  {
   if (gField[i][j] != 0)
    filled++;
  }
 }
 if (filled == (3*3))
  gdeadHeat = (!(0));
 else
  gdeadHeat = (0);
}

variable_types: filled int


ComputerStupidMove

decompiled_code:
__int64 ComputerStupidMove()
{
__int64 v0; // rbx
__int64 result; // rax

do
{
v0 = rand() % 3;
result = 3 * v0 + rand() % 3;
}
while ( *((_DWORD *)&gField + result) );
*((_DWORD *)&gField + result) = computerAnswer;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rbx
__int64 result; // rax

do
{
v0 = rand() % 3;
result = 3 * v0 + rand() % 3;
}
while ( *((_DWORD *)&gField + result) );
*((_DWORD *)&gField + result) = computerAnswer;
return result;
}

original_code:
static void ComputerStupidMove()
{
 int m,k;
 do
 {
  k = (rand()%3);
  m = (rand()%3);
 }
 while (gField[k][m] != 0);
 gField[k][m] = computerAnswer;
}

canonical_original_code:
static void ComputerStupidMove()
{
 int m; int k;
 do
 {
  k = (rand()%3);
  m = (rand()%3);
 }
 while (gField[k][m] != 0);
 gField[k][m] = computerAnswer;
}

variable_types: m int

variable_types: k int


usage

repo: kostelnik/jwmtools

decompiled_code:
void __noreturn usage()
{
fwrite("usage: slock [-v]\n", 1uLL, 0x12uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite("usage: slock [-v]\n", 1uLL, 0x12uLL, stderr);
exit(1);
}

original_code:
static void
usage(void) {
 fprintf(stderr, "usage: slock [-v]\n");
 exit(1);
}

canonical_original_code:
static void usage() {
 fprintf(stderr, "usage: slock [-v]\n");
 exit(1);
}


die

decompiled_code:
void __noreturn die(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stderr, format, arg);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stderr, format, arg);
exit(1);
}

original_code:
static void
die(const char *errstr, ...) {
 va_list ap;
 __builtin_va_start(ap,errstr);
 vfprintf(stderr, errstr, ap);
 __builtin_va_end(ap);
 exit(1);
}

canonical_original_code:
static void die(char *errstr, ...) {
 __builtin_va_list ap;
 __builtin_va_start(ap,errstr);
 vfprintf(stderr, errstr, ap);
 __builtin_va_end(ap);
 exit(1);
}

variable_types:
errstr
char *


getpw

decompiled_code:
char *getpw()
{
__uid_t v0; // eax
struct passwd *v1; // rax
struct passwd *v2; // rbx
char *v3; // rax
struct spwd *v4; // rbp
char *v5; // r12

v0 = getuid();
v1 = getpwuid(v0);
if ( !v1 )
die("slock: cannot retrieve password entry (make sure to suid or sgid slock)");
v2 = v1;
endpwent();
v3 = getenv("USER");
v4 = getspnam(v3);
if ( !v4 )
die("slock: cannot retrieve shadow entry (make sure to suid or sgid slock)\n");
endspent();
v5 = v4->sp_pwdp;
if ( setgid(v2->pw_gid) < 0 || setuid(v2->pw_uid) < 0 )
die("slock: cannot drop privileges");
return v5;
}

canonical_decompiled_code:
char *func2()
{
__uid_t v0; // eax
struct passwd *v1; // rax
struct passwd *v2; // rbx
char *v3; // rax
struct spwd *v4; // rbp
char *v5; // r12

v0 = getuid();
v1 = getpwuid(v0);
if ( !v1 )
func1("slock: cannot retrieve password entry (make sure to suid or sgid slock)");
v2 = v1;
endpwent();
v3 = getenv("USER");
v4 = getspnam(v3);
if ( !v4 )
func1("slock: cannot retrieve shadow entry (make sure to suid or sgid slock)\n");
endspent();
v5 = v4->sp_pwdp;
if ( setgid(v2->pw_gid) < 0 || setuid(v2->pw_uid) < 0 )
func1("slock: cannot drop privileges");
return v5;
}

original_code:
static const char *
getpw(void) {
 const char *rval;
 struct passwd *pw;
 pw = getpwuid(getuid());
 if(!pw)
  die("slock: cannot retrieve password entry (make sure to suid or sgid slock)");
 endpwent();
 rval = pw->pw_passwd;
 {
  struct spwd *sp;
  sp = getspnam(getenv("USER"));
  if(!sp)
   die("slock: cannot retrieve shadow entry (make sure to suid or sgid slock)\n");
  endspent();
  rval = sp->sp_pwdp;
 }
 if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0)
  die("slock: cannot drop privileges");
 return rval;
}

canonical_original_code:
static char *getpw() {
 char *rval;
 struct passwd *pw;
 pw = getpwuid(getuid());
 if(!pw)
  die("slock: cannot retrieve password entry (make sure to suid or sgid slock)");
 endpwent();
 rval = pw->pw_passwd;
 {
  struct spwd *sp;
  sp = getspnam(getenv("USER"));
  if(!sp)
   die("slock: cannot retrieve shadow entry (make sure to suid or sgid slock)\n");
  endspent();
  rval = sp->sp_pwdp;
 }
 if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0)
  die("slock: cannot drop privileges");
 return rval;
}

variable_types:
rval
char *

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types: struct spwd { char *sp_namp; char *sp_pwdp; long sp_lstchg; long sp_min; long sp_max; long sp_warn; long sp_inact; long sp_expire; unsigned long sp_flag; } *

return_type: char *


decompiled_code:
__int64 __fastcall sysmonitor_meminfo_percent(int *a1, _DWORD *a2, _DWORD *a3)
{
int v5; // esi
int v6; // ecx
int v7; // eax
int v8; // ecx
__int64 result; // rax
int v10; // [rsp+Ch] [rbp-2Ch] BYREF
int v11; // [rsp+10h] [rbp-28h] BYREF
int v12; // [rsp+14h] [rbp-24h] BYREF
int v13; // [rsp+18h] [rbp-20h] BYREF
int v14[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

sysmonitor_meminfo(&v10, &v11, &v12, &v13, v14);
v5 = v10;
v6 = v12;
*a1 = 100 * (v10 - v11 - v12) / v10;
v7 = 100 * v6;
v8 = v13;
result = (unsigned int)(v7 / v5);
*a2 = result;
*a3 = 0;
if ( v8 )
{
result = (unsigned int)(100 * (v8 - v14[0]) / v8);
*a3 = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int *a1, _DWORD *a2, _DWORD *a3)
{
int v5; // esi
int v6; // ecx
int v7; // eax
int v8; // ecx
__int64 result; // rax
int v10; // [rsp+Ch] [rbp-2Ch] BYREF
int v11; // [rsp+10h] [rbp-28h] BYREF
int v12; // [rsp+14h] [rbp-24h] BYREF
int v13; // [rsp+18h] [rbp-20h] BYREF
int v14[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

func7(&v10, &v11, &v12, &v13, v14);
v5 = v10;
v6 = v12;
*a1 = 100 * (v10 - v11 - v12) / v10;
v7 = 100 * v6;
v8 = v13;
result = (unsigned int)(v7 / v5);
*a2 = result;
*a3 = 0;
if ( v8 )
{
result = (unsigned int)(100 * (v8 - v14[0]) / v8);
*a3 = result;
}
return result;
}

original_code:
void sysmonitor_meminfo_percent(int * memory, int * cache, int * swap) {
  int mt,mf,mc,st,sf;
  sysmonitor_meminfo(&mt,&mf,&mc,&st,&sf);
  *memory = (100*(mt-mf-mc))/mt;
  *cache = (100*mc)/mt;
  *swap = 0;
  if (st != 0)
    *swap = (100*(st-sf))/st;
}

canonical_original_code:
void sysmonitor_meminfo_percent(int *memory, int *cache, int *swap) {
  int mt; int mf; int mc; int st; int sf;
  sysmonitor_meminfo(&mt,&mf,&mc,&st,&sf);
  *memory = (100*(mt-mf-mc))/mt;
  *cache = (100*mc)/mt;
  *swap = 0;
  if (st != 0)
    *swap = (100*(st-sf))/st;
}

variable_types:
memory
int *

variable_types:
cache
int *

variable_types:
swap
int *

variable_types: mt int

variable_types: mf int

variable_types: mc int

variable_types: st int

variable_types: sf int


start

repo: kostja/snippets

decompiled_code:
// positive sp value has been detected, the output may be wrong!
void __fastcall __noreturn start(__int64 a1, __int64 a2, void (*a3)(void))
{
__int64 v3; // rax
int v4; // esi
__int64 v5; // [rsp-8h] [rbp-8h] BYREF
char *retaddr; // [rsp+0h] [rbp+0h] BYREF

v4 = v5;
v5 = v3;
_libc_start_main(
(int (__fastcall *)(int, char **, char **))main,
v4,
&retaddr,
_libc_csu_init,
_libc_csu_fini,
a3,
&v5);
__halt();
}

canonical_decompiled_code:
void __fastcall __noreturn func1(__int64 a1, __int64 a2, void (*a3)(void))
{
__int64 v3; // rax
int v4; // esi
__int64 v5; // [rsp-8h] [rbp-8h] BYREF
char *retaddr; // [rsp+0h] [rbp+0h] BYREF

v4 = v5;
v5 = v3;
_libc_start_main(
(int (__fastcall *)(int, char **, char **))main,
v4,
&retaddr,
_libc_csu_init,
_libc_csu_fini,
a3,
&v5);
__halt();
}

original_code:
void start()
{
 socklen_t len;
 struct sockaddr_in addr;
 int listen_fd = socket(2, SOCK_STREAM, 0);
 bzero((char *) &addr, sizeof(addr));
 addr.sin_family = 2;
 addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 addr.sin_port = htons(8080);
 int yes = 1;
 if (setsockopt(listen_fd, 1, 2, (void *) &yes,
         sizeof(int)) < 0)
  error("setsockopt");
 if (bind(listen_fd, (struct sockaddr *) &addr, sizeof(addr)) < 0)
  error("ERROR on binding");
 listen(listen_fd, 5);
 int addrlen;
 int fd = accept(listen_fd, ((void *)0), ((void *)0));
 if (setsockopt(fd, IPPROTO_TCP, 1, (void *) &yes,
         sizeof(int)) < 0)
  error("setsockopt2");
 http(fd);
 close(listen_fd);
}

canonical_original_code:
void start()
{
 unsigned int len;
 struct sockaddr_in addr;
 int listen_fd = socket(2, SOCK_STREAM, 0);
 bzero((char *) &addr, sizeof(addr));
 addr.sin_family = 2;
 addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 addr.sin_port = htons(8080);
 int yes = 1;
 if (setsockopt(listen_fd, 1, 2, (void *) &yes,
         sizeof(int)) < 0)
  error("setsockopt");
 if (bind(listen_fd, (struct sockaddr *) &addr, sizeof(addr)) < 0)
  error("ERROR on binding");
 listen(listen_fd, 5);
 int addrlen;
 int fd = accept(listen_fd, ((void *)0), ((void *)0));
 if (setsockopt(fd, IPPROTO_TCP, 1, (void *) &yes,
         sizeof(int)) < 0)
  error("setsockopt2");
 http(fd);
 close(listen_fd);
}

variable_types:
len
unsigned int

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

variable_types: yes int

variable_types: addrlen int

variable_types: fd int

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

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


error

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

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

original_code:
void error(const char *msg)
{
    perror(msg);
    exit(1);
}

canonical_original_code:
void error(char *msg)
{
    perror(msg);
    exit(1);
}

variable_types:
msg
char *


decompiled_code:
__int64 http_connect()
{
unsigned int v0; // er12
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

v0 = socket(2, 1, 0);
addr = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16_constprop_0("127.0.0.1");
*(_DWORD *)&addr.sa_data[2] = inet_addr("127.0.0.1");
if ( connect(v0, &addr, 0x10u) < 0 )
error("connect");
optval = 1;
if ( setsockopt(v0, 6, 1, &optval, 4u) < 0 )
error("setsockopt2");
return v0;
}

canonical_decompiled_code:
__int64 func11()
{
unsigned int v0; // er12
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

v0 = socket(2, 1, 0);
addr = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func7("127.0.0.1");
*(_DWORD *)&addr.sa_data[2] = inet_addr("127.0.0.1");
if ( connect(v0, &addr, 0x10u) < 0 )
func8("connect");
optval = 1;
if ( setsockopt(v0, 6, 1, &optval, 4u) < 0 )
func8("setsockopt2");
return v0;
}

original_code:
int http_connect()
{
 socklen_t len;
 struct sockaddr_in addr;
 int fd = socket(2, SOCK_STREAM, 0);
 bzero((char *) &addr, sizeof(addr));
 addr.sin_family = 2;
 addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 addr.sin_port = htons(8080);
 addr.sin_addr.s_addr = inet_addr("127.0.0.1");
 if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0)
  error("connect");
 int yes = 1;
 if (setsockopt(fd, IPPROTO_TCP, 1, (void *) &yes,
         sizeof(int)) < 0)
  error("setsockopt2");
 return fd;
}

canonical_original_code:
int http_connect()
{
 unsigned int len;
 struct sockaddr_in addr;
 int fd = socket(2, SOCK_STREAM, 0);
 bzero((char *) &addr, sizeof(addr));
 addr.sin_family = 2;
 addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 addr.sin_port = htons(8080);
 addr.sin_addr.s_addr = inet_addr("127.0.0.1");
 if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0)
  error("connect");
 int yes = 1;
 if (setsockopt(fd, IPPROTO_TCP, 1, (void *) &yes,
         sizeof(int)) < 0)
  error("setsockopt2");
 return fd;
}


main

canonical_name: main

repo: kotatsumikan/TiarraSocketWriter

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
size_t v4; // rax
_DWORD v6[29]; // [rsp+0h] [rbp-47Ch] BYREF
char s[16]; // [rsp+74h] [rbp-408h] BYREF
char v8[1008]; // [rsp+84h] [rbp-3F8h] BYREF

*(_OWORD *)s = 0LL;
memset(v8, 0, sizeof(v8));
v6[0] = 0;
setparm((unsigned int)argc, argv, envp);
v3 = socket(1, 1, 0);
perror("socket ");
LOWORD(v6[1]) = 1;
strcpy((char *)&v6[1] + 2, op_sock);
connect(v3, (const struct sockaddr *)&v6[1], 0x6Eu);
perror("connect ");
if ( op_notice == 1 )
strcpy((char *)v6, "yes");
else
strcpy((char *)v6, "no");
sprintf(
s,
"NOTIFY System::SendMessage TIARRACONTROL/1.0\r\n"
"Sender: \r\n"
"Notice: %s\r\n"
"Channel: %s\r\n"
"Charset: utf-8\r\n"
"Text: %s\r\n"
"\r\n",
(const char *)v6,
op_ch,
op_msg);
v4 = strlen(s);
write(v3, s, v4);
perror("write ");
close(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
size_t v4; // rax
_DWORD v6[29]; // [rsp+0h] [rbp-47Ch] BYREF
char s[16]; // [rsp+74h] [rbp-408h] BYREF
char v8[1008]; // [rsp+84h] [rbp-3F8h] BYREF

*(_OWORD *)s = 0LL;
memset(v8, 0, sizeof(v8));
v6[0] = 0;
func7((unsigned int)argc, argv, envp);
v3 = socket(1, 1, 0);
perror("socket ");
LOWORD(v6[1]) = 1;
strcpy((char *)&v6[1] + 2, op_sock);
connect(v3, (const struct sockaddr *)&v6[1], 0x6Eu);
perror("connect ");
if ( op_notice == 1 )
strcpy((char *)v6, "yes");
else
strcpy((char *)v6, "no");
sprintf(
s,
"NOTIFY System::SendMessage TIARRACONTROL/1.0\r\n"
"Sender: \r\n"
"Notice: %s\r\n"
"Channel: %s\r\n"
"Charset: utf-8\r\n"
"Text: %s\r\n"
"\r\n",
(const char *)v6,
op_ch,
op_msg);
v4 = strlen(s);
write(v3, s, v4);
perror("write ");
close(v3);
return 0;
}

original_code:
int main(int argc, char* args[]){
    int sd, len;
    int rtn = 0;
    char buf[1024]={0};
    struct sockaddr_un saddr;
    char is_notice[4] = {0};
    rtn = setparm(argc, args);
    sd = socket(1, SOCK_STREAM, 0);
    perror("socket ");
    saddr.sun_family = 1;
    strcpy(saddr.sun_path, op_sock);
    len = sizeof(saddr);
    rtn = connect(sd, (struct sockaddr*)&saddr, len);
    perror("connect ");
    if(op_notice == 1){
        strcpy(is_notice, "yes");
    }else{
        strcpy(is_notice, "no");
    }
    sprintf(buf, "NOTIFY System::SendMessage TIARRACONTROL/1.0\r\nSender: \r\nNotice: %s\r\nChannel: %s\r\nCharset: utf-8\r\nText: %s\r\n\r\n", is_notice, op_ch, op_msg);
    write(sd, buf, strlen(buf));
    perror("write ");
    close(sd);
}

canonical_original_code:
int main(int argc, char *args[]){
    int sd; int len;
    int rtn = 0;
    char buf[1024] = {0};
    struct sockaddr_un saddr;
    char is_notice[4] = {0};
    rtn = setparm(argc, args);
    sd = socket(1, SOCK_STREAM, 0);
    perror("socket ");
    saddr.sun_family = 1;
    strcpy(saddr.sun_path, op_sock);
    len = sizeof(saddr);
    rtn = connect(sd, (struct sockaddr *)&saddr, len);
    perror("connect ");
    if(op_notice == 1){
        strcpy(is_notice, "yes");
    }else{
        strcpy(is_notice, "no");
    }
    sprintf(buf, "NOTIFY System::SendMessage TIARRACONTROL/1.0\r\nSender: \r\nNotice: %s\r\nChannel: %s\r\nCharset: utf-8\r\nText: %s\r\n\r\n", is_notice, op_ch, op_msg);
    write(sd, buf, strlen(buf));
    perror("write ");
    close(sd);
}

variable_types: argc int

variable_types:
args
char *[]

variable_types: sd int

variable_types: len int

variable_types: rtn int

variable_types:
buf
char [1024]

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


setparm

decompiled_code:
__int64 __fastcall setparm(int a1, __int64 a2)
{
int v2; // eax
const char *v4; // rsi
int v5; // er13
__int64 v6; // r9
const char *v7; // rsi
const char *v9; // rsi
const char *v10; // rsi

if ( a1 > 0 )
{
v2 = 0;
while ( 1 )
{
v5 = v2 + 1;
v6 = 8LL * v2;
if ( !strcmp("-socket", *(const char **)(a2 + v6)) )
{
v4 = *(const char **)(a2 + v6 + 8);
if ( v4 )
strncpy(op_sock, v4, 0x6BuLL);
goto LABEL_5;
}
if ( strcmp("-sender", *(const char **)(a2 + 8LL * v2)) )
break;
v7 = *(const char **)(a2 + v6 + 8);
if ( v7 )
{
strncpy(op_sender, v7, 0x1FuLL);
v2 = v5 + 1;
if ( a1 <= v5 + 1 )
return 0LL;
}
else
{
LABEL_5:
v2 = v5 + 1;
if ( a1 <= v5 + 1 )
return 0LL;
}
}
if ( !strcmp("-notice", *(const char **)(a2 + 8LL * v2)) )
{
op_notice = 1;
v5 = v2;
}
else if ( !strcmp("-message", *(const char **)(a2 + 8LL * v2)) )
{
v9 = *(const char **)(a2 + v6 + 8);
if ( v9 )
strncpy(op_msg, v9, 0x1FFuLL);
}
else if ( !strcmp("-channel", *(const char **)(a2 + 8LL * v2)) )
{
v10 = *(const char **)(a2 + v6 + 8);
if ( v10 )
strncpy(op_ch, v10, 0x3FuLL);
}
else
{
v5 = v2;
}
goto LABEL_5;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, __int64 a2)
{
int v2; // eax
const char *v4; // rsi
int v5; // er13
__int64 v6; // r9
const char *v7; // rsi
const char *v9; // rsi
const char *v10; // rsi

if ( a1 > 0 )
{
v2 = 0;
while ( 1 )
{
v5 = v2 + 1;
v6 = 8LL * v2;
if ( !strcmp("-socket", *(const char **)(a2 + v6)) )
{
v4 = *(const char **)(a2 + v6 + 8);
if ( v4 )
strncpy(op_sock, v4, 0x6BuLL);
goto LABEL_5;
}
if ( strcmp("-sender", *(const char **)(a2 + 8LL * v2)) )
break;
v7 = *(const char **)(a2 + v6 + 8);
if ( v7 )
{
strncpy(op_sender, v7, 0x1FuLL);
v2 = v5 + 1;
if ( a1 <= v5 + 1 )
return 0LL;
}
else
{
LABEL_5:
v2 = v5 + 1;
if ( a1 <= v5 + 1 )
return 0LL;
}
}
if ( !strcmp("-notice", *(const char **)(a2 + 8LL * v2)) )
{
op_notice = 1;
v5 = v2;
}
else if ( !strcmp("-message", *(const char **)(a2 + 8LL * v2)) )
{
v9 = *(const char **)(a2 + v6 + 8);
if ( v9 )
strncpy(op_msg, v9, 0x1FFuLL);
}
else if ( !strcmp("-channel", *(const char **)(a2 + 8LL * v2)) )
{
v10 = *(const char **)(a2 + v6 + 8);
if ( v10 )
strncpy(op_ch, v10, 0x3FuLL);
}
else
{
v5 = v2;
}
goto LABEL_5;
}
return 0LL;
}

original_code:
int setparm(int argc, char **args){
    int i=0;
    int flag=0;
    for(i=0; i<argc; i++){
        if(strcmp("-socket", args[i]) == 0){
            i++;
            if(args[i] == ((void *)0))
                continue;
            strncpy(op_sock, args[i], (sizeof(op_sock)-1));
        }else if(strcmp("-sender", args[i]) == 0){
            i++;
            if(args[i] == ((void *)0))
                continue;
            strncpy(op_sender, args[i], (sizeof(op_sender)-1));
        }else if(strcmp("-notice", args[i]) == 0){
            op_notice = 1;
        }else if(strcmp("-message", args[i]) == 0){
            i++;
            if(args[i] == ((void *)0))
                continue;
            strncpy(op_msg, args[i], (sizeof(op_msg)-1));
        }else if(strcmp("-channel", args[i]) == 0){
            i++;
            if(args[i] == ((void *)0))
                continue;
            strncpy(op_ch, args[i], (sizeof(op_ch)-1));
        }
    }
    return 0;
}

canonical_original_code:
int setparm(int argc, char **args){
    int i = 0;
    int flag = 0;
    for(i=0; i<argc; i++){
        if(strcmp("-socket", args[i]) == 0){
            i++;
            if(args[i] == ((void *)0))
                continue;
            strncpy(op_sock, args[i], (sizeof(op_sock)-1));
        }else if(strcmp("-sender", args[i]) == 0){
            i++;
            if(args[i] == ((void *)0))
                continue;
            strncpy(op_sender, args[i], (sizeof(op_sender)-1));
        }else if(strcmp("-notice", args[i]) == 0){
            op_notice = 1;
        }else if(strcmp("-message", args[i]) == 0){
            i++;
            if(args[i] == ((void *)0))
                continue;
            strncpy(op_msg, args[i], (sizeof(op_msg)-1));
        }else if(strcmp("-channel", args[i]) == 0){
            i++;
            if(args[i] == ((void *)0))
                continue;
            strncpy(op_ch, args[i], (sizeof(op_ch)-1));
        }
    }
    return 0;
}

variable_types:
args
char **

variable_types: i int

variable_types: flag int


transpose

repo: koturn/C-study

original_code:
static void transpose(int *restrict *restrict dst, const int *const restrict *restrict src, uint row, uint col) {
  uint i;
  for (i = 0; i < row; i++) {
    uint j;
    for (j = 0; j < col; j++) {
      dst[j][i] = src[i][j];
    }
  }
}

canonical_original_code:
static void transpose(int **dst, int **src, unsigned int row, unsigned int col) {
  unsigned int i;
  for (i = 0; i < row; i++) {
    unsigned int j;
    for (j = 0; j < col; j++) {
      dst[j][i] = src[i][j];
    }
  }
}

variable_types:
dst
int **

variable_types:
src
int **

variable_types:
row
unsigned int

variable_types:
col
unsigned int

variable_types:
i
unsigned int

variable_types:
j
unsigned int


decompiled_code:
int __fastcall show_2d_array(_QWORD *a1, int a2, int a3)
{
_QWORD *v3; // r14
__int64 v4; // r13
__int64 v6; // rbp
__int64 v7; // rbx
__int64 v8; // rsi
int result; // eax

if ( a2 )
{
v3 = a1;
v4 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
v6 = 4LL * (unsigned int)(a3 - 1) + 4;
do
{
v7 = 0LL;
if ( a3 )
{
do
{
v8 = *(unsigned int *)(*v3 + v7);
v7 += 4LL;
printf("%4d ", v8);
}
while ( v6 != v7 );
}
++v3;
result = puts(&s);
}
while ( v3 != (_QWORD *)v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(_QWORD *a1, int a2, int a3)
{
_QWORD *v3; // r14
__int64 v4; // r13
__int64 v6; // rbp
__int64 v7; // rbx
__int64 v8; // rsi
int result; // eax

if ( a2 )
{
v3 = a1;
v4 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
v6 = 4LL * (unsigned int)(a3 - 1) + 4;
do
{
v7 = 0LL;
if ( a3 )
{
do
{
v8 = *(unsigned int *)(*v3 + v7);
v7 += 4LL;
printf("%4d ", v8);
}
while ( v6 != v7 );
}
++v3;
result = puts(&s);
}
while ( v3 != (_QWORD *)v4 );
}
return result;
}

original_code:
static void show_2d_array(const int *const restrict *restrict array, uint row, uint col) {
  uint i;
  for (i = 0; i < row; i++) {
    uint j;
    for (j = 0; j < col; j++) {
      printf("%4d ", array[i][j]);
    }
    puts("");
  }
}

canonical_original_code:
static void show_2d_array(int **array, unsigned int row, unsigned int col) {
  unsigned int i;
  for (i = 0; i < row; i++) {
    unsigned int j;
    for (j = 0; j < col; j++) {
      printf("%4d ", array[i][j]);
    }
    puts("");
  }
}

variable_types:
array
int **


decompiled_code:
void **__fastcall alloc_2d_array(size_t nmemb, unsigned int a2)
{
void **v2; // rax
void **v3; // r12
__int64 v4; // rbx
void *v5; // rax
void **v7; // rbx
void *v8; // rdi

v2 = (void **)calloc((unsigned int)nmemb, 8uLL);
if ( !v2 )
return 0LL;
v3 = v2;
if ( (_DWORD)nmemb )
{
v4 = 0LL;
while ( 1 )
{
v5 = calloc(a2, 4uLL);
v3[v4] = v5;
if ( !v5 )
break;
if ( ++v4 == (unsigned int)nmemb )
return v3;
}
v7 = &v3[v4];
while ( v3 != v7 )
{
v8 = *v3++;
free(v8);
*(v3 - 1) = 0LL;
}
return 0LL;
}
return v3;
}

canonical_decompiled_code:
void **__fastcall func2(size_t nmemb, unsigned int a2)
{
void **v2; // rax
void **v3; // r12
__int64 v4; // rbx
void *v5; // rax
void **v7; // rbx
void *v8; // rdi

v2 = (void **)calloc((unsigned int)nmemb, 8uLL);
if ( !v2 )
return 0LL;
v3 = v2;
if ( (_DWORD)nmemb )
{
v4 = 0LL;
while ( 1 )
{
v5 = calloc(a2, 4uLL);
v3[v4] = v5;
if ( !v5 )
break;
if ( ++v4 == (unsigned int)nmemb )
return v3;
}
v7 = &v3[v4];
while ( v3 != v7 )
{
v8 = *v3++;
free(v8);
*(v3 - 1) = 0LL;
}
return 0LL;
}
return v3;
}

original_code:
inline static int **alloc_2d_array(uint row, uint col) {
  uint i;
  int **array;
  if ((array = ((int * *)calloc((row), sizeof(int *)))) == ((void *)0)) {
    return ((void *)0);
  }
  for (i = 0; i < row; i++) {
    if ((array[i] = ((int *)calloc((col), sizeof(int)))) == ((void *)0)) {
      uint j;
      for (j = 0; j < i; j++) {
        (free(*(&array[j])), *(&array[j]) = ((void *)0));
      }
      return ((void *)0);
    }
  }
  return array;
}

canonical_original_code:
inline static int **alloc_2d_array(unsigned int row, unsigned int col) {
  unsigned int i;
  int **array;
  if ((array = ((int **)calloc((row), sizeof(int *)))) == ((void *)0)) {
    return ((void *)0);
  }
  for (i = 0; i < row; i++) {
    if ((array[i] = ((int *)calloc((col), sizeof(int)))) == ((void *)0)) {
      unsigned int j;
      for (j = 0; j < i; j++) {
        (free(*(&array[j])), *(&array[j]) = ((void *)0));
      }
      return ((void *)0);
    }
  }
  return array;
}

return_type: int **


decompiled_code:
void __fastcall free_2d_array(void *ptr, int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

v2 = ptr;
if ( a2 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v5 = *v3++;
free(v5);
*(v3 - 1) = 0LL;
}
while ( v3 != v4 );
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr, int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

v2 = ptr;
if ( a2 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v5 = *v3++;
free(v5);
*(v3 - 1) = 0LL;
}
while ( v3 != v4 );
}
free(v2);
}

original_code:
inline static void free_2d_array(int **array, uint row) {
  uint i;
  for (i = 0; i < row; i++) {
    (free(*(&array[i])), *(&array[i]) = ((void *)0));
  }
  (free(*(&array)), *(&array) = ((void *)0));
}

canonical_original_code:
inline static void free_2d_array(int **array, unsigned int row) {
  unsigned int i;
  for (i = 0; i < row; i++) {
    (free(*(&array[i])), *(&array[i]) = ((void *)0));
  }
  (free(*(&array)), *(&array) = ((void *)0));
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void **v3; // r12
void **v4; // rax
void **v5; // r13
unsigned int i; // ebp
unsigned int v7; // ebx
__int64 v8; // rdx
int result; // eax
size_t nmemb; // [rsp+4h] [rbp-34h] BYREF
int v11[11]; // [rsp+Ch] [rbp-2Ch] BYREF

printf("Number of ROW = ?\b");
_isoc99_scanf("%u", &nmemb);
printf("Number of COLUMN = ?\b");
_isoc99_scanf("%u", (char *)&nmemb + 4);
v3 = alloc_2d_array((unsigned int)nmemb, HIDWORD(nmemb));
v4 = alloc_2d_array(HIDWORD(nmemb), nmemb);
if ( v3 && (v5 = v4) != 0LL )
{
for ( i = 0; (unsigned int)nmemb > i; ++i )
{
if ( HIDWORD(nmemb) )
{
v7 = 0;
do
{
_isoc99_scanf("%d", v11);
v8 = v7++;
*((_DWORD *)v3[i] + v8) = v11[0];
}
while ( HIDWORD(nmemb) > v7 );
}
}
puts(&s);
puts("Matrix = ");
show_2d_array(v3, nmemb, SHIDWORD(nmemb));
puts("============================================================");
transpose((__int64)v5, (__int64)v3, nmemb, HIDWORD(nmemb));
puts("Transposed Matrix = ");
show_2d_array(v5, SHIDWORD(nmemb), nmemb);
free_2d_array(v3, nmemb);
free_2d_array(v5, nmemb);
result = 0;
}
else
{
fwrite("Memory allocation error!\n", 1uLL, 0x19uLL, stderr);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void **v3; // r12
void **v4; // rax
void **v5; // r13
unsigned int i; // ebp
unsigned int v7; // ebx
__int64 v8; // rdx
int result; // eax
size_t nmemb; // [rsp+4h] [rbp-34h] BYREF
int v11[11]; // [rsp+Ch] [rbp-2Ch] BYREF

printf("Number of ROW = ?\b");
_isoc99_scanf("%u", &nmemb);
printf("Number of COLUMN = ?\b");
_isoc99_scanf("%u", (char *)&nmemb + 4);
v3 = func2((unsigned int)nmemb, HIDWORD(nmemb));
v4 = func2(HIDWORD(nmemb), nmemb);
if ( v3 && (v5 = v4) != 0LL )
{
for ( i = 0; (unsigned int)nmemb > i; ++i )
{
if ( HIDWORD(nmemb) )
{
v7 = 0;
do
{
_isoc99_scanf("%d", v11);
v8 = v7++;
*((_DWORD *)v3[i] + v8) = v11[0];
}
while ( HIDWORD(nmemb) > v7 );
}
}
puts(&s);
puts("Matrix = ");
func1(v3, nmemb, SHIDWORD(nmemb));
puts("============================================================");
func0((__int64)v5, (__int64)v3, nmemb, HIDWORD(nmemb));
puts("Transposed Matrix = ");
func1(v5, SHIDWORD(nmemb), nmemb);
func3(v3, nmemb);
func3(v5, nmemb);
result = 0;
}
else
{
fwrite("Memory allocation error!\n", 1uLL, 0x19uLL, stderr);
result = 1;
}
return result;
}

original_code:
int main(void) {
  uint row, col;
  uint i;
  int **array, **t_array;
  printf("Number of ROW    = ?\b"); scanf("%u", &row);
  printf("Number of COLUMN = ?\b"); scanf("%u", &col);
  array = alloc_2d_array(row, col);
  t_array = alloc_2d_array(col, row);
  if (array == ((void *)0) || t_array == ((void *)0)) {
    fputs("Memory allocation error!\n", stderr);
    return 1;
  }
  for (i = 0; i < row; i++) {
    uint j;
    for (j = 0; j < col; j++) {
      int tmp;
      scanf("%d", &tmp);
      array[i][j] = tmp;
    }
  }
  puts("");
  puts("Matrix = ");
  show_2d_array((const int *const *)array, row, col);
  puts("============================================================");
  transpose(t_array, (const int *const *)array, row, col);
  puts("Transposed Matrix = ");
  show_2d_array((const int *const *)t_array, col, row);
  free_2d_array(array, row);
  free_2d_array(t_array, row);
  return 0;
}

canonical_original_code:
int main() {
  unsigned int row; unsigned int col;
  unsigned int i;
  int **array; int **t_array;
  printf("Number of ROW    = ?\b"); scanf("%u", &row);
  printf("Number of COLUMN = ?\b"); scanf("%u", &col);
  array = alloc_2d_array(row, col);
  t_array = alloc_2d_array(col, row);
  if (array == ((void *)0) || t_array == ((void *)0)) {
    fputs("Memory allocation error!\n", stderr);
    return 1;
  }
  for (i = 0; i < row; i++) {
    unsigned int j;
    for (j = 0; j < col; j++) {
      int tmp;
      scanf("%d", &tmp);
      array[i][j] = tmp;
    }
  }
  puts("");
  puts("Matrix = ");
  show_2d_array((int **)array, row, col);
  puts("============================================================");
  transpose(t_array, (int **)array, row, col);
  puts("Transposed Matrix = ");
  show_2d_array((int **)t_array, col, row);
  free_2d_array(array, row);
  free_2d_array(t_array, row);
  return 0;
}

variable_types: tmp int


decompiled_code:
__int64 __fastcall binary2decimal(_BYTE *a1)
{
int v1; // eax
unsigned int i; // er8

v1 = (char)*a1;
for ( i = 0; *a1; v1 = (char)*a1 )
{
++a1;
i = v1 + 2 * i - 48;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
int v1; // eax
unsigned int i; // er8

v1 = (char)*a1;
for ( i = 0; *a1; v1 = (char)*a1 )
{
++a1;
i = v1 + 2 * i - 48;
}
return i;
}

original_code:
inline static int binary2decimal(const char *restrict bstr) {
  int sum = 0;
  for (; *bstr != '\0'; bstr++) {
    sum <<= 1;
    sum += ((*bstr) - '0');
  }
  return sum;
}

canonical_original_code:
inline static int binary2decimal(char *bstr) {
  int sum = 0;
  for (; *bstr != '\0'; bstr++) {
    sum <<= 1;
    sum += ((*bstr) - '0');
  }
  return sum;
}

variable_types:
bstr
char *

variable_types: sum int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
const char *v4; // rdx

v3 = binary2decimal("1110");
printf("%d + 0b%s = %d\n", 124LL, v4, (unsigned int)(v3 + 124));
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
const char *v4; // rdx

v3 = func0("1110");
printf("%d + 0b%s = %d\n", 124LL, v4, (unsigned int)(v3 + 124));
return 0;
}

original_code:
int main(void) {
  static const int num = 124;
  static const char *bstr = "1110";
  printf("%d + 0b%s = %d\n", num, bstr, num + binary2decimal(bstr));
  return 0;
}

canonical_original_code:
int main() {
  static int num = 124;
  static char *bstr = "1110";
  printf("%d + 0b%s = %d\n", num, bstr, num + binary2decimal(bstr));
  return 0;
}

variable_types: num int


convert

decompiled_code:
double __fastcall convert(double result)
{
if ( result < 100.0 )
return result * 3.0;
if ( result >= 150.0 )
result = result * 0.5;
return result;
}

canonical_decompiled_code:
double __fastcall func0(double result)
{
if ( result < 100.0 )
return result * 3.0;
if ( result >= 150.0 )
result = result * 0.5;
return result;
}

original_code:
inline static double convert(double x) {
  return x < 100 ? x * 3
                 : x >= 150 ? x / 2
                            : x;
}

variable_types: x double

return_type: double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm4_8
double v4; // xmm0_8
__int64 v5; // rsi
__int128 i; // xmm2
__int128 v7; // xmm0
__int128 v8; // xmm1

v3 = *(double *)&LC5;
v4 = 0.0;
v5 = 0LL;
for ( i = (unsigned __int64)LC5; *(double *)&i < v4 - 0.00000001 || v4 + 0.00000001 < *(double *)&i; i = v8 )
{
*((_QWORD *)&v7 + 1) = *((_QWORD *)&i + 1);
v5 = (unsigned int)(v5 + 1);
*(double *)&v7 = convert(*(double *)&i);
v8 = v7;
v4 = *(double *)&i;
}
printf(format, v5, envp, v3, *(double *)&i);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm4_8
double v4; // xmm0_8
__int64 v5; // rsi
__int128 i; // xmm2
__int128 v7; // xmm0
__int128 v8; // xmm1

v3 = *(double *)&LC5;
v4 = 0.0;
v5 = 0LL;
for ( i = (unsigned __int64)LC5; *(double *)&i < v4 - 0.00000001 || v4 + 0.00000001 < *(double *)&i; i = v8 )
{
*((_QWORD *)&v7 + 1) = *((_QWORD *)&i + 1);
v5 = (unsigned int)(v5 + 1);
*(double *)&v7 = func0(*(double *)&i);
v8 = v7;
v4 = *(double *)&i;
}
printf(format, v5, envp, v3, *(double *)&i);
return 0;
}

original_code:
int main(void) {
  static const double x = 7.9;
  double y = x;
  uint cnt = 0;
  double prev_y = 0.0;
  while (!(((prev_y) - EPS) <= ((y)) && ((y)) <= ((prev_y) + EPS))) {
    cnt++;
    prev_y = y;
    y = convert(y);
  }
  printf("%fに関数を%u回用いると%fになります\n", x, cnt, y);
  return 0;
}

canonical_original_code:
int main() {
  static double x = 7.9;
  double y = x;
  unsigned int cnt = 0;
  double prev_y = 0.0;
  while (!(((prev_y) - EPS) <= ((y)) && ((y)) <= ((prev_y) + EPS))) {
    cnt++;
    prev_y = y;
    y = convert(y);
  }
  printf("%fに関数を%u回用いると%fになります\n", x, cnt, y);
  return 0;
}

variable_types: y double

variable_types:
cnt
unsigned int


repo: koturn/LessonOfUniversity

decompiled_code:
size_t __fastcall trim_dirname(const char *a1)
{
size_t result; // rax
const char *v2; // rbx

result = strlen(a1);
v2 = &a1[(unsigned int)(result - 1)];
if ( *v2 == 47 )
*v2 = 0;
return result;
}

canonical_decompiled_code:
size_t __fastcall func1(const char *a1)
{
size_t result; // rax
const char *v2; // rbx

result = strlen(a1);
v2 = &a1[(unsigned int)(result - 1)];
if ( *v2 == 47 )
*v2 = 0;
return result;
}

original_code:
static void trim_dirname(char *dirname) {
  uint idx = strlen(dirname) - 1;
  if (dirname[idx] == '/') {
    dirname[idx] = '\0';
  }
}

canonical_original_code:
static void trim_dirname(char *dirname) {
  unsigned int idx = strlen(dirname) - 1;
  if (dirname[idx] == '/') {
    dirname[idx] = '\0';
  }
}

variable_types:
dirname
char *

variable_types:
idx
unsigned int


cmpfunc

decompiled_code:
int __fastcall cmpfunc(const void *a1, const void *a2)
{
return strcmp((const char *)(*(_QWORD *)a1 + 19LL), (const char *)(*(_QWORD *)a2 + 19LL));
}

canonical_decompiled_code:
int __fastcall func2(const void *a1, const void *a2)
{
return strcmp((const char *)(*(_QWORD *)a1 + 19LL), (const char *)(*(_QWORD *)a2 + 19LL));
}

original_code:
static int cmpfunc(const void *direntp1, const void *direntp2) {
  return strcmp((*(struct dirent *const *)direntp1)->d_name,
      (*(struct dirent *const *)direntp2)->d_name);
}

canonical_original_code:
static int cmpfunc(void *direntp1, void *direntp2) {
  return strcmp((*(struct dirent **)direntp1)->d_name,
      (*(struct dirent **)direntp2)->d_name);
}

user_defined_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; }


variable_types: mode int

variable_types:
str
char []


decompiled_code:
char *__fastcall uid_to_name(__uid_t a1)
{
struct passwd *v1; // rax

v1 = getpwuid(a1);
if ( v1 )
return v1->pw_name;
sprintf(numstr_1, "%u", a1);
return numstr_1;
}

canonical_decompiled_code:
char *__fastcall func4(__uid_t a1)
{
struct passwd *v1; // rax

v1 = getpwuid(a1);
if ( v1 )
return v1->pw_name;
sprintf(numstr_1, "%u", a1);
return numstr_1;
}

original_code:
static char *uid_to_name(uid_t uid) {
  struct passwd *getpwuid(), *pw_ptr;
  static char numstr[10];
  if ((pw_ptr = getpwuid(uid)) == ((void *)0)) {
    sprintf(numstr, "%u", uid);
    return numstr;
  } else {
    return pw_ptr->pw_name;
  }
}

canonical_original_code:
static char *uid_to_name(unsigned int uid) {
  struct passwd *getpwuid(); struct passwd *pw_ptr;
  static char numstr[10];
  if ((pw_ptr = getpwuid(uid)) == ((void *)0)) {
    sprintf(numstr, "%u", uid);
    return numstr;
  } else {
    return pw_ptr->pw_name;
  }
}

variable_types:
uid
unsigned int

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *()

variable_types:
numstr
char [10]


decompiled_code:
char *__fastcall gid_to_name(__gid_t a1)
{
struct group *v1; // rax

v1 = getgrgid(a1);
if ( v1 )
return v1->gr_name;
sprintf(numstr_0, "%u", a1);
return numstr_0;
}

canonical_decompiled_code:
char *__fastcall func5(__gid_t a1)
{
struct group *v1; // rax

v1 = getgrgid(a1);
if ( v1 )
return v1->gr_name;
sprintf(numstr_0, "%u", a1);
return numstr_0;
}

original_code:
static char *gid_to_name(gid_t gid) {
  struct group *getgrgid(), *grp_ptr;
  static char numstr[10];
  if ((grp_ptr = getgrgid(gid)) == ((void *)0)) {
    sprintf(numstr, "%u", gid);
    return numstr;
  } else {
    return grp_ptr->gr_name;
  }
}

canonical_original_code:
static char *gid_to_name(unsigned int gid) {
  struct group *getgrgid(); struct group *grp_ptr;
  static char numstr[10];
  if ((grp_ptr = getgrgid(gid)) == ((void *)0)) {
    sprintf(numstr, "%u", gid);
    return numstr;
  } else {
    return grp_ptr->gr_name;
  }
}

variable_types:
gid
unsigned int

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *()


decompiled_code:
int __fastcall show_file_info(char *s, __int64 a2)
{
char *v2; // rax
char *v3; // rax
char *v4; // rax
char v6[35]; // [rsp+5h] [rbp-23h] BYREF

mode_to_letters(*(_DWORD *)(a2 + 24), v6);
printf("%s", v6);
printf("%4d ", *(unsigned int *)(a2 + 16));
v2 = uid_to_name(*(_DWORD *)(a2 + 28));
printf("%-8s ", v2);
v3 = gid_to_name(*(_DWORD *)(a2 + 32));
printf("%-8s ", v3);
printf("%8ld ", *(_QWORD *)(a2 + 48));
v4 = ctime((const time_t *)(a2 + 88));
printf("%.12s ", v4 + 4);
return puts(s);
}

original_code:
static void show_file_info(const char *filename, const struct stat *info_p) {
  char *uid_to_name(), *ctime(), *gid_to_name(), *filemode();
  void mode_to_letters();
  char modestr[11];
  mode_to_letters(info_p->st_mode, modestr);
  printf("%s" , modestr);
  printf("%4d " , (int)info_p->st_nlink);
  printf("%-8s " , uid_to_name(info_p->st_uid));
  printf("%-8s " , gid_to_name(info_p->st_gid));
  printf("%8ld " , (long)info_p->st_size);
  printf("%.12s ", 4 + ctime(&info_p->st_mtim.tv_sec));
  printf("%s\n" , filename);
}

canonical_original_code:
static void show_file_info(char *filename, struct stat *info_p) {
  char *uid_to_name(); char *ctime(); char *gid_to_name(); char *filemode();
  void mode_to_letters();
  char modestr[11];
  mode_to_letters(info_p->st_mode, modestr);
  printf("%s" , modestr);
  printf("%4d " , (int)info_p->st_nlink);
  printf("%-8s " , uid_to_name(info_p->st_uid));
  printf("%-8s " , gid_to_name(info_p->st_gid));
  printf("%8ld " , (long)info_p->st_size);
  printf("%.12s ", 4 + ctime(&info_p->st_mtim.tv_sec));
  printf("%s\n" , filename);
}

variable_types:
filename
char *

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

variable_types:
ctime
char *()

variable_types:
filemode
char *()

variable_types:
modestr
char [11]

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:
char *__fastcall make_relpath(char *a1, const char *a2, const char *a3)
{
char *v4; // rax

v4 = stpcpy(a1, a2);
*v4 = 47;
return strcpy(v4 + 1, a3);
}

canonical_decompiled_code:
char *__fastcall func7(char *a1, const char *a2, const char *a3)
{
char *v4; // rax

v4 = stpcpy(a1, a2);
*v4 = 47;
return strcpy(v4 + 1, a3);
}

original_code:
static void make_relpath(char *new_relpath, const char *relpath, const char *dirname) {
  strcpy(new_relpath, relpath);
  strcat(new_relpath, "/");
  strcat(new_relpath, dirname);
}

canonical_original_code:
static void make_relpath(char *new_relpath, char *relpath, char *dirname) {
  strcpy(new_relpath, relpath);
  strcat(new_relpath, "/");
  strcat(new_relpath, dirname);
}

variable_types:
relpath
char *


original_code:
static void show_list(struct dirent *const dirent_array[], const char relpath[], uint end_idx, int opt_flag) {
  uint i;
  char *filename;
  struct stat *infos = ((struct stat *)malloc(sizeof(struct stat) * (end_idx)));
  if (infos == ((void *)0)) {
    fputs("メモリ確保エラーです", stderr);
    exit(1);
  }
  for (i = 0; i < end_idx; i++) {
    char *filename = dirent_array[i]->d_name;
    if (stat(filename, &infos[i]) == -1) {
      perror(filename);
      return;
    }
  }
  if (opt_flag & INFO_FLAG) {
    for (i = 0; i < end_idx; i++) {
      filename = dirent_array[i]->d_name;
      if (filename[0] == '.' && !(opt_flag & ALL_FLAG)) continue;
      show_file_info(filename, &infos[i]);
    }
  } else {
    for (i = 0; i < end_idx; i++) {
      filename = dirent_array[i]->d_name;
      if (filename[0] == '.' && !(opt_flag & ALL_FLAG)) continue;
      puts(filename);
    }
  }
  if (opt_flag & RECCURSE_FLAG) {
    for (i = 0; i < end_idx; i++) {
      filename = dirent_array[i]->d_name;
      if (((((infos[i].st_mode)) & 0170000) == (0040000)) && strcmp(filename, ".") && strcmp(filename, "..")) {
        char curdir_name[1024];
        char new_relpath[1024];
        make_relpath(new_relpath, relpath, filename);
        printf("\n%s:\n", new_relpath);
        getcwd(curdir_name, sizeof(curdir_name));
        chdir(filename);
        do_ls(".", new_relpath, opt_flag);
        chdir(curdir_name);
      }
    }
  }
  free(infos);
}

canonical_original_code:
static void show_list(struct dirent *dirent_array[], char relpath[], unsigned int end_idx, int opt_flag) {
  unsigned int i;
  char *filename;
  struct stat *infos = ((struct stat *)malloc(sizeof(struct stat) * (end_idx)));
  if (infos == ((void *)0)) {
    fputs("メモリ確保エラーです", stderr);
    exit(1);
  }
  for (i = 0; i < end_idx; i++) {
    char *filename = dirent_array[i]->d_name;
    if (stat(filename, &infos[i]) == -1) {
      perror(filename);
      return;
    }
  }
  if (opt_flag & INFO_FLAG) {
    for (i = 0; i < end_idx; i++) {
      filename = dirent_array[i]->d_name;
      if (filename[0] == '.' && !(opt_flag & ALL_FLAG)) continue;
      show_file_info(filename, &infos[i]);
    }
  } else {
    for (i = 0; i < end_idx; i++) {
      filename = dirent_array[i]->d_name;
      if (filename[0] == '.' && !(opt_flag & ALL_FLAG)) continue;
      puts(filename);
    }
  }
  if (opt_flag & RECCURSE_FLAG) {
    for (i = 0; i < end_idx; i++) {
      filename = dirent_array[i]->d_name;
      if (((((infos[i].st_mode)) & 0170000) == (0040000)) && strcmp(filename, ".") && strcmp(filename, "..")) {
        char curdir_name[1024];
        char new_relpath[1024];
        make_relpath(new_relpath, relpath, filename);
        printf("\n%s:\n", new_relpath);
        getcwd(curdir_name, sizeof(curdir_name));
        chdir(filename);
        do_ls(".", new_relpath, opt_flag);
        chdir(curdir_name);
      }
    }
  }
  free(infos);
}

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } *[]

variable_types:
relpath
char []

variable_types:
i
unsigned int

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
__int64 __fastcall parse_args(int argc, char **argv, int *a3)
{
unsigned int v4; // er12
char v5; // al

v4 = 0;
while ( 1 )
{
v5 = getopt(argc, argv, "alR");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'a':
v4 |= 1u;
break;
case 'l':
v4 |= 2u;
break;
case 'R':
v4 |= 4u;
break;
}
}
*a3 = optind;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(int argc, char **argv, int *a3)
{
unsigned int v4; // er12
char v5; // al

v4 = 0;
while ( 1 )
{
v5 = getopt(argc, argv, "alR");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'a':
v4 |= 1u;
break;
case 'l':
v4 |= 2u;
break;
case 'R':
v4 |= 4u;
break;
}
}
*a3 = optind;
return v4;
}

original_code:
static int parse_args(int argc, char *argv[], uint *r_index) {
  int opt_flag = 0;
  char optch;
  while ((optch = getopt(argc, argv, "alR")) != -1) {
    switch (optch) {
      case 'a':
        opt_flag |= ALL_FLAG;
        break;
      case 'l':
        opt_flag |= INFO_FLAG;
        break;
      case 'R':
        opt_flag |= RECCURSE_FLAG;
        break;
    }
  }
  *r_index = optind;
  return opt_flag;
}

canonical_original_code:
static int parse_args(int argc, char *argv[], unsigned int *r_index) {
  int opt_flag = 0;
  char optch;
  while ((optch = getopt(argc, argv, "alR")) != -1) {
    switch (optch) {
      case 'a':
        opt_flag |= ALL_FLAG;
        break;
      case 'l':
        opt_flag |= INFO_FLAG;
        break;
      case 'R':
        opt_flag |= RECCURSE_FLAG;
        break;
    }
  }
  *r_index = optind;
  return opt_flag;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: optch char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
unsigned int v4; // eax
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = parse_args(argc, (char **)argv, (int *)v6);
v4 = v6[0];
if ( argc == v6[0] )
{
if ( (v3 & 4) != 0 )
puts(".:");
do_ls_constprop_0((__int64)".", v3);
}
else if ( argc - v6[0] == 1 )
{
trim_dirname(argv[v6[0]]);
if ( (v3 & 4) != 0 )
printf("%s:\n", argv[v6[0]]);
getcwd(curdir_name_2, 0x400uLL);
chdir(argv[v6[0]]);
do_ls_constprop_0((__int64)argv[v6[0]], v3);
chdir(curdir_name_2);
}
else
{
while ( argc > v4 )
{
trim_dirname(argv[v4]);
printf("%s:\n", argv[v6[0]]);
getcwd(curdir_name_2, 0x400uLL);
chdir(argv[v6[0]]);
do_ls_constprop_0((__int64)argv[v6[0]], v3);
chdir(curdir_name_2);
v4 = ++v6[0];
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
unsigned int v4; // eax
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = func0(argc, (char **)argv, (int *)v6);
v4 = v6[0];
if ( argc == v6[0] )
{
if ( (v3 & 4) != 0 )
puts(".:");
func8((__int64)".", v3);
}
else if ( argc - v6[0] == 1 )
{
func1(argv[v6[0]]);
if ( (v3 & 4) != 0 )
printf("%s:\n", argv[v6[0]]);
getcwd(curdir_name_2, 0x400uLL);
chdir(argv[v6[0]]);
func8((__int64)argv[v6[0]], v3);
chdir(curdir_name_2);
}
else
{
while ( argc > v4 )
{
func1(argv[v4]);
printf("%s:\n", argv[v6[0]]);
getcwd(curdir_name_2, 0x400uLL);
chdir(argv[v6[0]]);
func8((__int64)argv[v6[0]], v3);
chdir(curdir_name_2);
v4 = ++v6[0];
}
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
  static char curdir_name[1024];
  uint r_index;
  int opt_flag = parse_args(argc, argv, &r_index);
  switch (argc - r_index) {
    case 0:
      if (opt_flag & RECCURSE_FLAG) {
        puts(".:");
      }
      do_ls(".", ".", opt_flag);
      break;
    case 1:
      trim_dirname(argv[r_index]);
      if (opt_flag & RECCURSE_FLAG) {
        printf("%s:\n", argv[r_index]);
      }
      getcwd(curdir_name, sizeof(curdir_name));
      chdir(argv[r_index]);
      do_ls(".", argv[r_index], opt_flag);
      chdir(curdir_name);
      break;
    default:
      for (; r_index < (uint)argc; r_index++) {
        trim_dirname(argv[r_index]);
        printf("%s:\n", argv[r_index]);
        getcwd(curdir_name, sizeof(curdir_name));
        chdir(argv[r_index]);
        do_ls(".", argv[r_index], opt_flag);
        chdir(curdir_name);
      }
      break;
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  static char curdir_name[1024];
  unsigned int r_index;
  int opt_flag = parse_args(argc, argv, &r_index);
  switch (argc - r_index) {
    case 0:
      if (opt_flag & RECCURSE_FLAG) {
        puts(".:");
      }
      do_ls(".", ".", opt_flag);
      break;
    case 1:
      trim_dirname(argv[r_index]);
      if (opt_flag & RECCURSE_FLAG) {
        printf("%s:\n", argv[r_index]);
      }
      getcwd(curdir_name, sizeof(curdir_name));
      chdir(argv[r_index]);
      do_ls(".", argv[r_index], opt_flag);
      chdir(curdir_name);
      break;
    default:
      for (; r_index < (unsigned int)argc; r_index++) {
        trim_dirname(argv[r_index]);
        printf("%s:\n", argv[r_index]);
        getcwd(curdir_name, sizeof(curdir_name));
        chdir(argv[r_index]);
        do_ls(".", argv[r_index], opt_flag);
        chdir(curdir_name);
      }
      break;
  }
  return 0;
}


decompiled_code:
__int64 __fastcall check_end(int a1, int a2)
{
__int64 result; // rax

if ( a1 == 5 )
{
puts("You win!!!!");
result = 1LL;
}
else
{
result = 0LL;
if ( a2 == 5 )
{
puts("You lose!!!!");
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
__int64 result; // rax

if ( a1 == 5 )
{
puts("You win!!!!");
result = 1LL;
}
else
{
result = 0LL;
if ( a2 == 5 )
{
puts("You lose!!!!");
result = 1LL;
}
}
return result;
}

original_code:
static uchar check_end(uint my_cnt, uint enemy_cnt) {
  if (my_cnt == 5) {
    puts("You win!!!!");
    return 1;
  } else if (enemy_cnt == 5) {
    puts("You lose!!!!");
    return 1;
  }
  return 0;
}

canonical_original_code:
static unsigned char check_end(unsigned int my_cnt, unsigned int enemy_cnt) {
  if (my_cnt == 5) {
    puts("You win!!!!");
    return 1;
  } else if (enemy_cnt == 5) {
    puts("You lose!!!!");
    return 1;
  }
  return 0;
}

return_type: unsigned char


judge

decompiled_code:
int __fastcall judge(unsigned __int64 a1, unsigned __int64 a2, _DWORD *a3, unsigned int *a4)
{
__int64 v6; // rsi

if ( a1 < a2 )
{
puts("You get a point!");
v6 = (unsigned int)(*a3 + 1);
*a3 = v6;
}
else
{
if ( a1 > a2 )
{
puts("Enemy get a point!");
++*a4;
}
else
{
puts("Draw game!");
}
v6 = (unsigned int)*a3;
}
printf("\nYour point : %u\n", v6);
return printf("enemy's point : %u\n", *a4);
}

canonical_decompiled_code:
int __fastcall func1(unsigned __int64 a1, unsigned __int64 a2, _DWORD *a3, unsigned int *a4)
{
__int64 v6; // rsi

if ( a1 < a2 )
{
puts("You get a point!");
v6 = (unsigned int)(*a3 + 1);
*a3 = v6;
}
else
{
if ( a1 > a2 )
{
puts("Enemy get a point!");
++*a4;
}
else
{
puts("Draw game!");
}
v6 = (unsigned int)*a3;
}
printf("\nYour point : %u\n", v6);
return printf("enemy's point : %u\n", *a4);
}

original_code:
static void judge(ulong input_time, ulong enemy_time, uint *my_cnt, uint *enemy_cnt) {
  if (input_time < enemy_time) {
    puts("You get a point!");
    (*my_cnt)++;
  } else if (input_time > enemy_time) {
    puts("Enemy get a point!");
    (*enemy_cnt)++;
  } else {
    puts("Draw game!");
  }
  printf("\nYour point    : %u\n", *my_cnt);
  printf("enemy's point : %u\n", *enemy_cnt);
}

canonical_original_code:
static void judge(unsigned long input_time, unsigned long enemy_time, unsigned int *my_cnt, unsigned int *enemy_cnt) {
  if (input_time < enemy_time) {
    puts("You get a point!");
    (*my_cnt)++;
  } else if (input_time > enemy_time) {
    puts("Enemy get a point!");
    (*enemy_cnt)++;
  } else {
    puts("Draw game!");
  }
  printf("\nYour point    : %u\n", *my_cnt);
  printf("enemy's point : %u\n", *enemy_cnt);
}


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

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_sec + v1.tv_usec / 1000;
}

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

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_sec + v1.tv_usec / 1000;
}

original_code:
static ulong gettimeofday_sec(void) {
  struct timeval t;
  gettimeofday(&t, ((void *)0));
  return t.tv_sec * 1000 + t.tv_usec / 1000;
}

canonical_original_code:
static unsigned long gettimeofday_sec() {
  struct timeval t;
  gettimeofday(&t, ((void *)0));
  return t.tv_sec * 1000 + t.tv_usec / 1000;
}

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

return_type: unsigned long


decompiled_code:
__int64 __fastcall show_ring_buf(__int64 a1, unsigned int a2, unsigned int a3)
{
int v3; // er13
__int64 result; // rax
const char *v7; // rdi

if ( a2 )
{
v3 = 0;
do
{
result = a3;
v7 = *(const char **)(a1 + 8LL * a3);
if ( !v7 )
break;
++v3;
printf(v7);
result = (a3 + 1) / a2;
a3 = (a3 + 1) % a2;
}
while ( a2 != v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, unsigned int a3)
{
int v3; // er13
__int64 result; // rax
const char *v7; // rdi

if ( a2 )
{
v3 = 0;
do
{
result = a3;
v7 = *(const char **)(a1 + 8LL * a3);
if ( !v7 )
break;
++v3;
printf(v7);
result = (a3 + 1) / a2;
a3 = (a3 + 1) % a2;
}
while ( a2 != v3 );
}
return result;
}

original_code:
static void show_ring_buf(char *const *ring_buf, uint line_num, uint rb_idx) {
  uint i;
  for (i = 0; i < line_num && ring_buf[rb_idx] != ((void *)0); i++, rb_idx = (rb_idx + 1) % line_num) {
    1 ? (void) 0 : printf("%03d ", i + 1);
    printf(ring_buf[rb_idx]);
  }
}

canonical_original_code:
static void show_ring_buf(char **ring_buf, unsigned int line_num, unsigned int rb_idx) {
  unsigned int i;
  for (i = 0; i < line_num && ring_buf[rb_idx] != ((void *)0); i++, rb_idx = (rb_idx + 1) % line_num) {
    1 ? (void) 0 : printf("%03d ", i + 1);
    printf(ring_buf[rb_idx]);
  }
}


decompiled_code:
void __fastcall free_ring_buf(void *ptr, unsigned int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

v2 = ptr;
if ( a2 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * a2);
do
{
v5 = *v3++;
free(v5);
}
while ( v3 != v4 );
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr, unsigned int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

v2 = ptr;
if ( a2 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * a2);
do
{
v5 = *v3++;
free(v5);
}
while ( v3 != v4 );
}
free(v2);
}

original_code:
static void free_ring_buf(char **ring_buf, uint line_num) {
  uint i;
  char **array_top = ring_buf;
  for (i = 0; i < line_num; i++, ring_buf++) {
    free(*ring_buf);
  }
  free(array_top);
}

canonical_original_code:
static void free_ring_buf(char **ring_buf, unsigned int line_num) {
  unsigned int i;
  char **array_top = ring_buf;
  for (i = 0; i < line_num; i++, ring_buf++) {
    free(*ring_buf);
  }
  free(array_top);
}


decompiled_code:
int __fastcall show_usage(const char *a1)
{
puts(&s);
printf(" %s [-options] prog_name\n", a1);
puts(aOptions);
puts(&byte_7C5);
puts(asc_860);
return puts(aN);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
puts(&s);
printf(" %s [-options] prog_name\n", a1);
puts(aOptions);
puts(&byte_7C5);
puts(asc_860);
return puts(aN);
}

original_code:
static void show_usage(const char *prog_name) {
  puts ("使い方");
  printf("  %s [-options] prog_name" "\n", prog_name);
  puts ("    [-options]は省略可能で、一番最後の引数の名前のファイルを読み込みます\n");
  puts ("オプション");
  puts ("  -f : ログ監視モードでファイルをオープンします");
  puts ("  -n : 何行表示するかを決定します");
}

canonical_original_code:
static void show_usage(char *prog_name) {
  puts ("使い方");
  printf("  %s [-options] prog_name" "\n", prog_name);
  puts ("    [-options]は省略可能で、一番最後の引数の名前のファイルを読み込みます\n");
  puts ("オプション");
  puts ("  -f : ログ監視モードでファイルをオープンします");
  puts ("  -n : 何行表示するかを決定します");
}


decompiled_code:
__int64 __fastcall convert_str2int(const char *a1)
{
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

result = strtol(a1, &endptr, 10);
if ( *endptr )
{
fwrite(&unk_8D8, 1uLL, 0x2BuLL, stderr);
exit(1);
}
if ( (int)result <= 0 )
{
fwrite(&unk_908, 1uLL, 0x2FuLL, stderr);
exit(1);
}
if ( (_DWORD)result == 0x7FFFFFFF )
{
fwrite(&unk_7D5, 1uLL, 0x19uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

result = strtol(a1, &endptr, 10);
if ( *endptr )
{
fwrite(&unk_8D8, 1uLL, 0x2BuLL, stderr);
exit(1);
}
if ( (int)result <= 0 )
{
fwrite(&unk_908, 1uLL, 0x2FuLL, stderr);
exit(1);
}
if ( (_DWORD)result == 0x7FFFFFFF )
{
fwrite(&unk_7D5, 1uLL, 0x19uLL, stderr);
exit(1);
}
return result;
}

original_code:
static int convert_str2int(const char *str) {
  char *check;
  int num = strtol(str, &check, 10);
  if (*check != '\0') {
    fputs("文字列に数値以外がありました\n", stderr);
    exit(1);
  }
  if (num <= 0) {
    fputs("0以下の値を指定しないでください\n", stderr);
    exit(1);
  } else if (num == 0x7fffffff) {
    fputs("値が大きすぎます\n", stderr);
    exit(1);
  }
  return num;
}

canonical_original_code:
static int convert_str2int(char *str) {
  char *check;
  int num = strtol(str, &check, 10);
  if (*check != '\0') {
    fputs("文字列に数値以外がありました\n", stderr);
    exit(1);
  }
  if (num <= 0) {
    fputs("0以下の値を指定しないでください\n", stderr);
    exit(1);
  } else if (num == 0x7fffffff) {
    fputs("値が大きすぎます\n", stderr);
    exit(1);
  }
  return num;
}

variable_types:
str
char *

variable_types:
check
char *

variable_types: num int


decompiled_code:
void __fastcall free_2darray(void *ptr, int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

v2 = ptr;
if ( a2 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v5 = *v3++;
free(v5);
}
while ( v3 != v4 );
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr, int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

v2 = ptr;
if ( a2 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v5 = *v3++;
free(v5);
}
while ( v3 != v4 );
}
free(v2);
}

original_code:
static void free_2darray(char **array, uint row) {
  register uint i;
  for (i = 0; i < row; i++) {
    free(array[i]);
  }
  free(array);
}

canonical_original_code:
static void free_2darray(char **array, unsigned int row) {
  register unsigned int i;
  for (i = 0; i < row; i++) {
    free(array[i]);
  }
  free(array);
}

variable_types:
array
char **

variable_types:
row
unsigned int


decompiled_code:
int __fastcall show_usage(const char *a1)
{
puts(&s);
printf(" $ %s\n", a1);
puts(asc_277);
printf(aS, a1);
puts(asc_29F);
puts(asc_2D8);
puts(asc_277);
puts(" Ctrl-C");
return puts(asc_308);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
puts(&s);
printf(" $ %s\n", a1);
puts(asc_277);
printf(aS, a1);
puts(asc_29F);
puts(asc_2D8);
puts(asc_277);
puts(" Ctrl-C");
return puts(asc_308);
}

original_code:
static void show_usage(const char *prog_name) {
  puts ("使い方:");
  printf("    $ %s" "\n", prog_name);
  puts ("  または");
  printf("    $ %s [ポート番号]" "\n", prog_name);
  puts ("\n終了方法:");
  puts ("    ゲーム中に\"quit\"と入力する");
  puts ("  または");
  puts ("    Ctrl-C");
  puts ("  で終了することができます。");
}

canonical_original_code:
static void show_usage(char *prog_name) {
  puts ("使い方:");
  printf("    $ %s" "\n", prog_name);
  puts ("  または");
  printf("    $ %s [ポート番号]" "\n", prog_name);
  puts ("\n終了方法:");
  puts ("    ゲーム中に\"quit\"と入力する");
  puts ("  または");
  puts ("    Ctrl-C");
  puts ("  で終了することができます。");
}


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

if ( a1 == 1 )
goto LABEL_4;
if ( a1 != 2 )
{
fwrite(&unk_338, 1uLL, 0x26uLL, stderr);
show_usage(*(const char **)a2);
return 0xFFFFFFFFLL;
}
result = convert_str2port(*(_QWORD *)(a2 + 8));
*a3 = result;
if ( (_DWORD)result != -1 )
{
LABEL_4:
*a3 = 50000;
result = 0LL;
}
return result;
}

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

if ( a1 == 1 )
goto LABEL_4;
if ( a1 != 2 )
{
fwrite(&unk_338, 1uLL, 0x26uLL, stderr);
func0(*(const char **)a2);
return 0xFFFFFFFFLL;
}
result = convert_str2port(*(_QWORD *)(a2 + 8));
*a3 = result;
if ( (_DWORD)result != -1 )
{
LABEL_4:
*a3 = 50000;
result = 0LL;
}
return result;
}

original_code:
static int arg_parse(int argc, char *argv[], int *port_num) {
  switch (argc) {
    case 2:
      *port_num = convert_str2port(argv[1]);
      if (*port_num == -1) return -1;
    case 1:
      *port_num = 50000;
      break;
    default:
      fputs("引数は1つにしてください。" "\n", stderr);
      show_usage(argv[0]);
      return -1;
  }
  return 0;
}


decompiled_code:
__int64 __fastcall make_socket(unsigned __int16 a1)
{
int v1; // edx
int v2; // eax
int v3; // ebp
unsigned int v4; // er12
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

*(_DWORD *)&v6.sa_data[10] = 0;
v6.sa_family = 2;
*(_QWORD *)&v6.sa_data[2] = (unsigned int)_bswap_32_constprop_0(a1, 1LL, 0LL);
*(_WORD *)v6.sa_data = _bswap_16(a1);
v2 = socket(2, 1, v1);
if ( v2 < 0 )
{
v4 = -1;
perror("socket");
}
else
{
v3 = v2;
v4 = bind(v2, &v6, 0x10u);
if ( v4 == -1 )
{
perror("bind");
}
else
{
listen(v3, 1);
fwrite("successfully bound, now waiting.\n", 1uLL, 0x21uLL, stderr);
v4 = accept(v3, 0LL, 0LL);
close(v3);
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int16 a1)
{
int v1; // edx
int v2; // eax
int v3; // ebp
unsigned int v4; // er12
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

*(_DWORD *)&v6.sa_data[10] = 0;
v6.sa_family = 2;
*(_QWORD *)&v6.sa_data[2] = (unsigned int)func5(a1, 1LL, 0LL);
*(_WORD *)v6.sa_data = func2(a1);
v2 = socket(2, 1, v1);
if ( v2 < 0 )
{
v4 = -1;
perror("socket");
}
else
{
v3 = v2;
v4 = bind(v2, &v6, 0x10u);
if ( v4 == -1 )
{
perror("bind");
}
else
{
listen(v3, 1);
fwrite("successfully bound, now waiting.\n", 1uLL, 0x21uLL, stderr);
v4 = accept(v3, 0LL, 0LL);
close(v3);
}
}
return v4;
}

original_code:
static int make_socket(int port_num) {
  struct sockaddr_in me;
  int sock;
  int sock_new;
  memset((char *)&me, 0, sizeof(me));
  me.sin_family = 2;
  me.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
  me.sin_port = htons(port_num);
  if ((sock = socket(2, SOCK_STREAM, 0)) < 0 ) {
    perror("socket");
    return -1;
  }
  if (bind(sock, (struct sockaddr *)&me, sizeof(me)) == -1){
    perror("bind");
    return -1;
  }
  listen(sock, 1);
  fputs("successfully bound, now waiting." "\n", stderr);
  sock_new = accept(sock, ((void *)0), ((void *)0));
  close(sock);
  return sock_new;
}

canonical_original_code:
static int make_socket(int port_num) {
  struct sockaddr_in me;
  int sock;
  int sock_new;
  memset((char *)&me, 0, sizeof(me));
  me.sin_family = 2;
  me.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
  me.sin_port = htons(port_num);
  if ((sock = socket(2, SOCK_STREAM, 0)) < 0 ) {
    perror("socket");
    return -1;
  }
  if (bind(sock, (struct sockaddr *)&me, sizeof(me)) == -1){
    perror("bind");
    return -1;
  }
  listen(sock, 1);
  fputs("successfully bound, now waiting." "\n", stderr);
  sock_new = accept(sock, ((void *)0), ((void *)0));
  close(sock);
  return sock_new;
}

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

variable_types: sock int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
_QWORD *v4; // r13
__int64 v5; // rbx
int v6; // er12
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( (unsigned int)arg_parse(argc, (__int64)argv, v8) == -1 )
return 1;
v3 = make_socket(v8[0]);
if ( v3 == -1 )
return 1;
v4 = alloc_2darray_constprop_0();
v5 = (unsigned int)read_question("question.txt", v4, 256LL);
v6 = play_game_server(v3, v4, v5);
free_2darray(v4, v5 - 1);
return v6;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
_QWORD *v4; // r13
__int64 v5; // rbx
int v6; // er12
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( (unsigned int)func1(argc, (__int64)argv, v8) == -1 )
return 1;
v3 = func6(v8[0]);
if ( v3 == -1 )
return 1;
v4 = func4();
v5 = (unsigned int)read_question("question.txt", v4, 256LL);
v6 = play_game_server(v3, v4, v5);
func3(v4, v5 - 1);
return v6;
}

original_code:
int main(int argc, char *argv[]) {
  int sock_new;
  int port_num;
  uint qnum;
  char **questions;
  int ret;
  if (arg_parse(argc, argv, &port_num) == -1) {
    return 1;
  }
  if ((sock_new = make_socket(port_num)) == -1) {
    return 1;
  }
  questions = alloc_2darray(256, 256);
  qnum = read_question(("question.txt"), questions, 256);
  ret = play_game_server(sock_new, questions, qnum);
  free_2darray(questions, qnum - 1);
  return ret;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int sock_new;
  int port_num;
  unsigned int qnum;
  char **questions;
  int ret;
  if (arg_parse(argc, argv, &port_num) == -1) {
    return 1;
  }
  if ((sock_new = make_socket(port_num)) == -1) {
    return 1;
  }
  questions = alloc_2darray(256, 256);
  qnum = read_question(("question.txt"), questions, 256);
  ret = play_game_server(sock_new, questions, qnum);
  free_2darray(questions, qnum - 1);
  return ret;
}

variable_types:
qnum
unsigned int

variable_types:
questions
char **

variable_types: ret int


decompiled_code:
__int64 __fastcall convert_str2port(const char *a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
char *endptr; // [rsp+8h] [rbp-10h] BYREF

v1 = strtol(a1, &endptr, 10);
if ( *endptr )
{
v2 = -1;
fwrite(&unk_100, 1uLL, 0x34uLL, stderr);
return v2;
}
if ( v1 > 0xFFFF )
goto LABEL_8;
if ( v1 <= 0x3FF )
{
fwrite(&unk_178, 1uLL, 0x40uLL, stderr);
LABEL_8:
v2 = -1;
fprintf(stderr, &byte_138, 49152LL, 0xFFFFLL);
return v2;
}
v2 = v1;
if ( v1 - 1024 > 0xBBFF )
return v2;
fwrite(&unk_1C0, 1uLL, 0x42uLL, stderr);
fprintf(stderr, format, 49152LL, 0xFFFFLL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
char *endptr; // [rsp+8h] [rbp-10h] BYREF

v1 = strtol(a1, &endptr, 10);
if ( *endptr )
{
v2 = -1;
fwrite(&unk_100, 1uLL, 0x34uLL, stderr);
return v2;
}
if ( v1 > 0xFFFF )
goto LABEL_8;
if ( v1 <= 0x3FF )
{
fwrite(&unk_178, 1uLL, 0x40uLL, stderr);
LABEL_8:
v2 = -1;
fprintf(stderr, &byte_138, 49152LL, 0xFFFFLL);
return v2;
}
v2 = v1;
if ( v1 - 1024 > 0xBBFF )
return v2;
fwrite(&unk_1C0, 1uLL, 0x42uLL, stderr);
fprintf(stderr, format, 49152LL, 0xFFFFLL);
return v2;
}

original_code:
int convert_str2port(const char *str) {
  char *check;
  int num = strtol(str, &check, 10);
  if (*check != '\0') {
    fputs("ポート番号は数値で指定してください" "\n", stderr);
    return -1;
  }
  if (num < 0 || 65535 < num) {
    fprintf((stderr), "ポート番号は %d~%d の範囲で指定してください" "\n", 49152, 65535);
    return -1;
  }
  if (0 <= num && num <= 1023) {
    fputs("ウェルノウンポートを指定しないでください。" "\n", stderr);
    fprintf((stderr), "ポート番号は %d~%d の範囲で指定してください" "\n", 49152, 65535);
    return -1;
  }
  if (1024 <= num && num <= 49151) {
    fputs("注意: 登録済みポート番号が指定されています。" "\n", stderr);
    fprintf((stderr), "      ポート番号を %d~%d の範囲で指定することを推奨します" "\n", 49152, 65535);
  }
  return num;
}

canonical_original_code:
int convert_str2port(char *str) {
  char *check;
  int num = strtol(str, &check, 10);
  if (*check != '\0') {
    fputs("ポート番号は数値で指定してください" "\n", stderr);
    return -1;
  }
  if (num < 0 || 65535 < num) {
    fprintf((stderr), "ポート番号は %d~%d の範囲で指定してください" "\n", 49152, 65535);
    return -1;
  }
  if (0 <= num && num <= 1023) {
    fputs("ウェルノウンポートを指定しないでください。" "\n", stderr);
    fprintf((stderr), "ポート番号は %d~%d の範囲で指定してください" "\n", 49152, 65535);
    return -1;
  }
  if (1024 <= num && num <= 49151) {
    fputs("注意: 登録済みポート番号が指定されています。" "\n", stderr);
    fprintf((stderr), "      ポート番号を %d~%d の範囲で指定することを推奨します" "\n", 49152, 65535);
  }
  return num;
}


decompiled_code:
int __fastcall print_fileinfo(char *s, char a2, unsigned int *a3)
{
if ( (a2 & 2) == 0 )
{
if ( (a2 & 4) == 0 )
goto LABEL_3;
LABEL_6:
printf("%u ", a3[2]);
if ( (a2 & 1) == 0 )
return puts(s);
goto LABEL_7;
}
printf("%u ", a3[1]);
if ( (a2 & 4) != 0 )
goto LABEL_6;
LABEL_3:
if ( (a2 & 1) == 0 )
return puts(s);
LABEL_7:
printf("%u ", *a3);
return puts(s);
}

canonical_decompiled_code:
int __fastcall func2(char *s, char a2, unsigned int *a3)
{
if ( (a2 & 2) == 0 )
{
if ( (a2 & 4) == 0 )
goto LABEL_3;
LABEL_6:
printf("%u ", a3[2]);
if ( (a2 & 1) == 0 )
return puts(s);
goto LABEL_7;
}
printf("%u ", a3[1]);
if ( (a2 & 4) != 0 )
goto LABEL_6;
LABEL_3:
if ( (a2 & 1) == 0 )
return puts(s);
LABEL_7:
printf("%u ", *a3);
return puts(s);
}

original_code:
static void print_fileinfo(const char *filename, int opt_flag, const wc_info *wi) {
  if (opt_flag & LINE_FLAG) printf("%u  ", wi->n_line);
  if (opt_flag & WORD_FLAG) printf("%u  ", wi->n_word);
  if (opt_flag & BYTE_FLAG) printf("%u  ", wi->n_byte);
  puts(filename);
}

canonical_original_code:
static void print_fileinfo(char *filename, int opt_flag, struct wc_info *wi) {
  if (opt_flag & LINE_FLAG) printf("%u  ", wi->n_line);
  if (opt_flag & WORD_FLAG) printf("%u  ", wi->n_word);
  if (opt_flag & BYTE_FLAG) printf("%u  ", wi->n_byte);
  puts(filename);
}

variable_types:
filename
char *

variable_types: struct wc_info { unsigned int n_byte; unsigned int n_line; unsigned int n_word; } *


decompiled_code:
__int64 __fastcall parse_args(int argc, char **argv, int *a3)
{
unsigned int v4; // er12
char v5; // al

v4 = 0;
while ( 1 )
{
v5 = getopt(argc, argv, "clw");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'l':
v4 |= 2u;
break;
case 'w':
v4 |= 4u;
break;
case 'c':
v4 |= 1u;
break;
}
}
*a3 = optind;
if ( !v4 )
v4 = 7;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(int argc, char **argv, int *a3)
{
unsigned int v4; // er12
char v5; // al

v4 = 0;
while ( 1 )
{
v5 = getopt(argc, argv, "clw");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'l':
v4 |= 2u;
break;
case 'w':
v4 |= 4u;
break;
case 'c':
v4 |= 1u;
break;
}
}
*a3 = optind;
if ( !v4 )
v4 = 7;
return v4;
}

original_code:
static int parse_args(int argc, char *argv[], uint *r_index) {
  int opt_flag = 0;
  char optch;
  while ((optch = getopt(argc, argv, "clw")) != -1) {
    switch (optch) {
      case 'c':
        opt_flag |= BYTE_FLAG;
        break;
      case 'l':
        opt_flag |= LINE_FLAG;
        break;
      case 'w':
        opt_flag |= WORD_FLAG;
        break;
    }
  }
  *r_index = optind;
  return opt_flag == 0x00 ? (BYTE_FLAG | LINE_FLAG | WORD_FLAG) : opt_flag;
}

canonical_original_code:
static int parse_args(int argc, char *argv[], unsigned int *r_index) {
  int opt_flag = 0;
  char optch;
  while ((optch = getopt(argc, argv, "clw")) != -1) {
    switch (optch) {
      case 'c':
        opt_flag |= BYTE_FLAG;
        break;
      case 'l':
        opt_flag |= LINE_FLAG;
        break;
      case 'w':
        opt_flag |= WORD_FLAG;
        break;
    }
  }
  *r_index = optind;
  return opt_flag == 0x00 ? (BYTE_FLAG | LINE_FLAG | WORD_FLAG) : opt_flag;
}


repo: koturn/WaveAnalyzer

decompiled_code:
__int64 __fastcall str2int(const char *a1)
{
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

result = strtol(a1, &endptr, 10);
if ( *endptr )
{
fwrite(&unk_A0, 1uLL, 0x2BuLL, stderr);
exit(1);
}
if ( (int)result <= 0 )
{
fwrite(&unk_D0, 1uLL, 0x2FuLL, stderr);
exit(1);
}
if ( (_DWORD)result == 0x7FFFFFFF )
{
fwrite(&unk_188, 1uLL, 0x19uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

result = strtol(a1, &endptr, 10);
if ( *endptr )
{
fwrite(&unk_A0, 1uLL, 0x2BuLL, stderr);
exit(1);
}
if ( (int)result <= 0 )
{
fwrite(&unk_D0, 1uLL, 0x2FuLL, stderr);
exit(1);
}
if ( (_DWORD)result == 0x7FFFFFFF )
{
fwrite(&unk_188, 1uLL, 0x19uLL, stderr);
exit(1);
}
return result;
}

original_code:
static unsigned int str2int(const char *restrict nstr) {
  char *check;
  int num = strtol(nstr, &check, 10);
  if (*check != '\0') {
    fputs("文字列に数値以外がありました\n", stderr);
    exit(1);
  }
  if (num <= 0) {
    fputs("0以下の値を指定しないでください\n", stderr);
    exit(1);
  } else if (num == 0x7fffffff) {
    fputs("値が大きすぎます\n", stderr);
    exit(1);
  }
  return (unsigned int)num;
}

canonical_original_code:
static unsigned int str2int(char *nstr) {
  char *check;
  int num = strtol(nstr, &check, 10);
  if (*check != '\0') {
    fputs("文字列に数値以外がありました\n", stderr);
    exit(1);
  }
  if (num <= 0) {
    fputs("0以下の値を指定しないでください\n", stderr);
    exit(1);
  } else if (num == 0x7fffffff) {
    fputs("値が大きすぎます\n", stderr);
    exit(1);
  }
  return (unsigned int)num;
}

variable_types:
nstr
char *

return_type: unsigned int