clUtilErrorString

decompiled_code:
const char *__fastcall clUtilErrorString(int a1)
{
const char *result; // rax

switch ( a1 )
{
case -64:
result = "CL_INVALID_PROPERTY";
break;
case -63:
result = "CL_INVALID_GLOBAL_WORK_SIZE";
break;
case -61:
result = "CL_INVALID_BUFFER_SIZE";
break;
case -59:
result = "CL_INVALID_OPERATION";
break;
case -57:
result = "CL_INVALID_EVENT_WAIT_LIST";
break;
case -56:
result = "CL_INVALID_GLOBAL_OFFSET";
break;
case -55:
result = "CL_INVALID_WORK_ITEM_SIZE";
break;
case -54:
result = "CL_INVALID_WORK_GROUP_SIZE";
break;
case -53:
result = "CL_INVALID_WORK_DIMENSION";
break;
case -52:
result = "CL_INVALID_KERNEL_ARGS";
break;
case -51:
result = "CL_INVALID_ARG_SIZE";
break;
case -50:
result = "CL_INVALID_ARG_VALUE";
break;
case -49:
result = "CL_INVALID_ARG_INDEX";
break;
case -48:
result = "CL_INVALID_KERNEL";
break;
case -47:
result = "CL_INVALID_KERNEL_DEFINITION";
break;
case -46:
result = "CL_INVALID_KERNEL_NAME";
break;
case -45:
result = "CL_INVALID_PROGRAM_EXECUTABLE";
break;
case -44:
result = "CL_INVALID_PROGRAM";
break;
case -41:
result = "CL_INVALID_SAMPLER";
break;
case -40:
result = "CL_INVALID_IMAGE_SIZE";
break;
case -38:
result = "CL_INVALID_MEM_OBJECT";
break;
case -37:
result = "CL_INVALID_HOST_PTR";
break;
case -36:
result = "CL_INVALID_COMMAND_QUEUE";
break;
case -34:
result = "CL_INVALID_CONTEXT";
break;
case -33:
result = "CL_INVALID_DEVICE";
break;
case -32:
result = "CL_INVALID_PLATFORM";
break;
case -31:
result = "CL_INVALID_DEVICE_TYPE";
break;
case -30:
result = "CL_INVALID_VALUE";
break;
case -14:
result = "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";
break;
case -13:
result = "CL_MISALIGNED_SUB_BUFFER_OFFSET";
break;
case -6:
result = "CL_OUT_OF_HOST_MEMORY";
break;
case -5:
result = "CL_OUT_OF_RESOURCES";
break;
case -4:
result = "CL_MEM_OBJECT_ALLOCATION_FAILURE";
break;
case -2:
result = "CL_DEVICE_NOT_AVAILABLE";
break;
case -1:
result = "CL_DEVICE_NOT_FOUND";
break;
case 0:
result = "CL_SUCCESS";
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax

switch ( a1 )
{
case -64:
result = "CL_INVALID_PROPERTY";
break;
case -63:
result = "CL_INVALID_GLOBAL_WORK_SIZE";
break;
case -61:
result = "CL_INVALID_BUFFER_SIZE";
break;
case -59:
result = "CL_INVALID_OPERATION";
break;
case -57:
result = "CL_INVALID_EVENT_WAIT_LIST";
break;
case -56:
result = "CL_INVALID_GLOBAL_OFFSET";
break;
case -55:
result = "CL_INVALID_WORK_ITEM_SIZE";
break;
case -54:
result = "CL_INVALID_WORK_GROUP_SIZE";
break;
case -53:
result = "CL_INVALID_WORK_DIMENSION";
break;
case -52:
result = "CL_INVALID_KERNEL_ARGS";
break;
case -51:
result = "CL_INVALID_ARG_SIZE";
break;
case -50:
result = "CL_INVALID_ARG_VALUE";
break;
case -49:
result = "CL_INVALID_ARG_INDEX";
break;
case -48:
result = "CL_INVALID_KERNEL";
break;
case -47:
result = "CL_INVALID_KERNEL_DEFINITION";
break;
case -46:
result = "CL_INVALID_KERNEL_NAME";
break;
case -45:
result = "CL_INVALID_PROGRAM_EXECUTABLE";
break;
case -44:
result = "CL_INVALID_PROGRAM";
break;
case -41:
result = "CL_INVALID_SAMPLER";
break;
case -40:
result = "CL_INVALID_IMAGE_SIZE";
break;
case -38:
result = "CL_INVALID_MEM_OBJECT";
break;
case -37:
result = "CL_INVALID_HOST_PTR";
break;
case -36:
result = "CL_INVALID_COMMAND_QUEUE";
break;
case -34:
result = "CL_INVALID_CONTEXT";
break;
case -33:
result = "CL_INVALID_DEVICE";
break;
case -32:
result = "CL_INVALID_PLATFORM";
break;
case -31:
result = "CL_INVALID_DEVICE_TYPE";
break;
case -30:
result = "CL_INVALID_VALUE";
break;
case -14:
result = "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";
break;
case -13:
result = "CL_MISALIGNED_SUB_BUFFER_OFFSET";
break;
case -6:
result = "CL_OUT_OF_HOST_MEMORY";
break;
case -5:
result = "CL_OUT_OF_RESOURCES";
break;
case -4:
result = "CL_MEM_OBJECT_ALLOCATION_FAILURE";
break;
case -2:
result = "CL_DEVICE_NOT_AVAILABLE";
break;
case -1:
result = "CL_DEVICE_NOT_FOUND";
break;
case 0:
result = "CL_SUCCESS";
break;
default:
return result;
}
return result;
}

original_code:
const char * clUtilErrorString(cl_int error)
{
   switch(error) {
   case -2: return "CL_DEVICE_NOT_AVAILABLE";;
   case -1: return "CL_DEVICE_NOT_FOUND";;
   case -14: return "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";;
   case -49: return "CL_INVALID_ARG_INDEX";;
   case -51: return "CL_INVALID_ARG_SIZE";;
   case -50: return "CL_INVALID_ARG_VALUE";;
   case -61: return "CL_INVALID_BUFFER_SIZE";;
   case -36: return "CL_INVALID_COMMAND_QUEUE";;
   case -34: return "CL_INVALID_CONTEXT";;
   case -33: return "CL_INVALID_DEVICE";;
   case -31: return "CL_INVALID_DEVICE_TYPE";;
   case -57: return "CL_INVALID_EVENT_WAIT_LIST";;
   case -56: return "CL_INVALID_GLOBAL_OFFSET";;
   case -63: return "CL_INVALID_GLOBAL_WORK_SIZE";;
   case -37: return "CL_INVALID_HOST_PTR";;
   case -40: return "CL_INVALID_IMAGE_SIZE";;
   case -48: return "CL_INVALID_KERNEL";;
   case -52: return "CL_INVALID_KERNEL_ARGS";;
   case -47: return "CL_INVALID_KERNEL_DEFINITION";;
   case -46: return "CL_INVALID_KERNEL_NAME";;
   case -38: return "CL_INVALID_MEM_OBJECT";;
   case -59: return "CL_INVALID_OPERATION";;
   case -32: return "CL_INVALID_PLATFORM";;
   case -44: return "CL_INVALID_PROGRAM";;
   case -45: return "CL_INVALID_PROGRAM_EXECUTABLE";;
   case -64: return "CL_INVALID_PROPERTY";;
   case -41: return "CL_INVALID_SAMPLER";;
   case -30: return "CL_INVALID_VALUE";;
   case -53: return "CL_INVALID_WORK_DIMENSION";;
   case -54: return "CL_INVALID_WORK_GROUP_SIZE";;
   case -55: return "CL_INVALID_WORK_ITEM_SIZE";;
   case -4: return "CL_MEM_OBJECT_ALLOCATION_FAILURE";;
   case -13: return "CL_MISALIGNED_SUB_BUFFER_OFFSET";;
   case -6: return "CL_OUT_OF_HOST_MEMORY";;
   case -5: return "CL_OUT_OF_RESOURCES";;
   case 0: return "CL_SUCCESS";;
   }
}

canonical_original_code:
char *clUtilErrorString(int error)
{
   switch(error) {
   case -2: return "CL_DEVICE_NOT_AVAILABLE";;
   case -1: return "CL_DEVICE_NOT_FOUND";;
   case -14: return "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";;
   case -49: return "CL_INVALID_ARG_INDEX";;
   case -51: return "CL_INVALID_ARG_SIZE";;
   case -50: return "CL_INVALID_ARG_VALUE";;
   case -61: return "CL_INVALID_BUFFER_SIZE";;
   case -36: return "CL_INVALID_COMMAND_QUEUE";;
   case -34: return "CL_INVALID_CONTEXT";;
   case -33: return "CL_INVALID_DEVICE";;
   case -31: return "CL_INVALID_DEVICE_TYPE";;
   case -57: return "CL_INVALID_EVENT_WAIT_LIST";;
   case -56: return "CL_INVALID_GLOBAL_OFFSET";;
   case -63: return "CL_INVALID_GLOBAL_WORK_SIZE";;
   case -37: return "CL_INVALID_HOST_PTR";;
   case -40: return "CL_INVALID_IMAGE_SIZE";;
   case -48: return "CL_INVALID_KERNEL";;
   case -52: return "CL_INVALID_KERNEL_ARGS";;
   case -47: return "CL_INVALID_KERNEL_DEFINITION";;
   case -46: return "CL_INVALID_KERNEL_NAME";;
   case -38: return "CL_INVALID_MEM_OBJECT";;
   case -59: return "CL_INVALID_OPERATION";;
   case -32: return "CL_INVALID_PLATFORM";;
   case -44: return "CL_INVALID_PROGRAM";;
   case -45: return "CL_INVALID_PROGRAM_EXECUTABLE";;
   case -64: return "CL_INVALID_PROPERTY";;
   case -41: return "CL_INVALID_SAMPLER";;
   case -30: return "CL_INVALID_VALUE";;
   case -53: return "CL_INVALID_WORK_DIMENSION";;
   case -54: return "CL_INVALID_WORK_GROUP_SIZE";;
   case -55: return "CL_INVALID_WORK_ITEM_SIZE";;
   case -4: return "CL_MEM_OBJECT_ALLOCATION_FAILURE";;
   case -13: return "CL_MISALIGNED_SUB_BUFFER_OFFSET";;
   case -6: return "CL_OUT_OF_HOST_MEMORY";;
   case -5: return "CL_OUT_OF_RESOURCES";;
   case 0: return "CL_SUCCESS";;
   }
}

variable_types: error int


repo: NatTuck/cakemark

decompiled_code:
int __fastcall cl_perror(int a1)
{
const char *v1; // rax

v1 = cl_strerror(a1);
return fprintf(stderr, "OpenCL Error: %s\n", v1);
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
const char *v1; // rax

v1 = func0(a1);
return fprintf(stderr, "OpenCL Error: %s\n", v1);
}

original_code:
static void
cl_perror(int code)
{
    fprintf(stderr, "OpenCL Error: %s\n", cl_strerror(code));
}

variable_types: code int

return_type: void


decompiled_code:
__int64 __fastcall matrix_size(__int64 a1)
{
return *(_QWORD *)(a1 + 8) * *(_QWORD *)(a1 + 16);
}

original_code:
size_t
matrix_size(matrix * mm)
{
    return mm->rows * mm->cols;
}

canonical_original_code:
unsigned long matrix_size(struct matrix *mm)
{
    return mm->rows * mm->cols;
}

variable_types: struct matrix { float *data; unsigned long rows; unsigned long cols; } *

return_type: unsigned long


decompiled_code:
__int64 __fastcall matrix_bytes(__int64 a1)
{
return 4 * matrix_size(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return 4 * func3(a1);
}

original_code:
size_t
matrix_bytes(matrix * mm)
{
    return matrix_size(mm) * sizeof(float);
}

canonical_original_code:
unsigned long matrix_bytes(struct matrix *mm)
{
    return matrix_size(mm) * sizeof(float);
}

user_defined_types: struct matrix { float *data; unsigned long rows; unsigned long cols; }


decompiled_code:
void __fastcall destroy_matrix(void **a1)
{
free(*a1);
free(a1);
}

canonical_decompiled_code:
void __fastcall func5(void **a1)
{
free(*a1);
free(a1);
}

original_code:
void
destroy_matrix(matrix * mm)
{
    free(mm->data);
    free(mm);
}

canonical_original_code:
void destroy_matrix(struct matrix *mm)
{
    free(mm->data);
    free(mm);
}


decompiled_code:
float *__fastcall set_cell(_QWORD *a1, __int64 a2, __int64 a3, float a4)
{
float *result; // rax

result = (float *)(*a1 + 4 * (a2 * a1[2] + a3));
*result = a4;
return result;
}

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

result = (float *)(*a1 + 4 * (a2 * a1[2] + a3));
*result = a4;
return result;
}

original_code:
void
set_cell(matrix * mm, size_t ii, size_t jj, float value)
{
    mm->data[ii * mm->cols + jj] = value;
}

canonical_original_code:
void set_cell(struct matrix *mm, unsigned long ii, unsigned long jj, float value)
{
    mm->data[ii * mm->cols + jj] = value;
}

variable_types:
ii
unsigned long

variable_types:
jj
unsigned long

variable_types: value float


decompiled_code:
float __fastcall get_cell(_QWORD *a1, __int64 a2, __int64 a3)
{
return *(float *)(*a1 + 4 * (a2 * a1[2] + a3));
}

canonical_decompiled_code:
float __fastcall func7(_QWORD *a1, __int64 a2, __int64 a3)
{
return *(float *)(*a1 + 4 * (a2 * a1[2] + a3));
}

original_code:
float
get_cell(matrix * mm, size_t ii, size_t jj)
{
    return mm->data[ii * mm->cols + jj];
}

canonical_original_code:
float get_cell(struct matrix *mm, unsigned long ii, unsigned long jj)
{
    return mm->data[ii * mm->cols + jj];
}

return_type: float


decompiled_code:
int __fastcall check_result(_QWORD *a1, _QWORD *a2)
{
__m128i v2; // xmm0
__m128i v3; // xmm0
float v5; // [rsp+14h] [rbp-1Ch]
float v6; // [rsp+18h] [rbp-18h]
unsigned __int64 j; // [rsp+20h] [rbp-10h]
unsigned __int64 i; // [rsp+28h] [rbp-8h]

v2 = (__m128i)0x3A83126Fu;
for ( i = 0LL; i < a1[1]; ++i )
{
for ( j = 1LL; j < a1[2]; ++j )
{
*(float *)v2.m128i_i32 = get_cell(a2, i, j);
v6 = COERCE_FLOAT(_mm_cvtsi128_si32(v2));
*(float *)v2.m128i_i32 = get_cell(a1, i, j);
v5 = COERCE_FLOAT(_mm_cvtsi128_si32(v2));
v3 = (__m128i)LODWORD(v6);
*(float *)v3.m128i_i32 = v6 - v5;
v2 = _mm_cvtsi32_si128(_mm_cvtsi128_si32(v3));
std::abs(*(float *)v2.m128i_i32);
if ( COERCE_FLOAT(_mm_cvtsi128_si32(v2)) > 0.001 )
{
puts("ERROR - Incorrect result.");
return printf("At %ld, %ld got %f instead of %f\n", i, j, v5, v6);
}
}
}
puts("Result is correct.");
return puts("[cake: OK]");
}

canonical_decompiled_code:
int __fastcall func9(_QWORD *a1, _QWORD *a2)
{
__m128i v2; // xmm0
__m128i v3; // xmm0
float v5; // [rsp+14h] [rbp-1Ch]
float v6; // [rsp+18h] [rbp-18h]
unsigned __int64 j; // [rsp+20h] [rbp-10h]
unsigned __int64 i; // [rsp+28h] [rbp-8h]

v2 = (__m128i)0x3A83126Fu;
for ( i = 0LL; i < a1[1]; ++i )
{
for ( j = 1LL; j < a1[2]; ++j )
{
*(float *)v2.m128i_i32 = func7(a2, i, j);
v6 = COERCE_FLOAT(_mm_cvtsi128_si32(v2));
*(float *)v2.m128i_i32 = func7(a1, i, j);
v5 = COERCE_FLOAT(_mm_cvtsi128_si32(v2));
v3 = (__m128i)LODWORD(v6);
*(float *)v3.m128i_i32 = v6 - v5;
v2 = _mm_cvtsi32_si128(_mm_cvtsi128_si32(v3));
std::func11(*(float *)v2.m128i_i32);
if ( COERCE_FLOAT(_mm_cvtsi128_si32(v2)) > 0.001 )
{
puts("ERROR - Incorrect result.");
return printf("At %ld, %ld got %f instead of %f\n", i, j, v5, v6);
}
}
}
puts("Result is correct.");
return puts("[cake: OK]");
}

original_code:
void
check_result(matrix * cc, matrix * aa)
{
    const float EPS = 0.001;
    for (size_t ii = 0; ii < cc->rows; ++ii) {
        for (size_t jj = 1; jj < cc->cols; ++jj) {
            float xx = get_cell(aa, ii, jj);
            float yy = get_cell(cc, ii, jj);
            if (abs(1*xx - yy) > EPS) {
                printf("ERROR - Incorrect result.\n");
                printf("At %ld, %ld got %f instead of %f\n",
                       ii, jj, yy, xx);
                return;
            }
        }
    }
    printf("Result is correct.\n");
    printf("[cake: OK]\n");
}

canonical_original_code:
void check_result(struct matrix *cc, struct matrix *aa)
{
    float EPS = 0.001;
    for (unsigned long ii = 0; ii < cc->rows; ++ii) {
        for (unsigned long jj = 1; jj < cc->cols; ++jj) {
            float xx = get_cell(aa, ii, jj);
            float yy = get_cell(cc, ii, jj);
            if (abs(1*xx - yy) > EPS) {
                printf("ERROR - Incorrect result.\n");
                printf("At %ld, %ld got %f instead of %f\n",
                       ii, jj, yy, xx);
                return;
            }
        }
    }
    printf("Result is correct.\n");
    printf("[cake: OK]\n");
}

variable_types:
aa
struct matrix *

variable_types: EPS float

variable_types: xx float

variable_types: yy float


decompiled_code:
__int64 __fastcall matrix_size(__int64 a1)
{
return *(_QWORD *)(a1 + 16) * *(_QWORD *)(a1 + 8);
}


canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return 4 * func1(a1);
}


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

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


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

result = *a1;
*(float *)(*a1 + 4 * (a3 + a1[2] * a2)) = a4;
return result;
}

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

result = *a1;
*(float *)(*a1 + 4 * (a3 + a1[2] * a2)) = a4;
return result;
}


decompiled_code:
float __fastcall get_cell(_QWORD *a1, __int64 a2, __int64 a3)
{
return *(float *)(*a1 + 4 * (a3 + a1[2] * a2));
}

canonical_decompiled_code:
float __fastcall func5(_QWORD *a1, __int64 a2, __int64 a3)
{
return *(float *)(*a1 + 4 * (a3 + a1[2] * a2));
}


decompiled_code:
int __fastcall check_result(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // r15
unsigned __int64 v3; // r14
__int64 v4; // rbp
__int64 v5; // rbx
int result; // eax
float v7; // [rsp+8h] [rbp-40h]
float v8; // [rsp+Ch] [rbp-3Ch]

v2 = a1[1];
if ( v2 )
{
v3 = a1[2];
v4 = 0LL;
while ( 1 )
{
v5 = 1LL;
if ( v3 > 1 )
break;
LABEL_6:
if ( ++v4 == v2 )
goto LABEL_7;
}
while ( 1 )
{
v7 = get_cell(a2, v4, v5);
v8 = get_cell(a1, v4, v5);
if ( (float)(int)abs32((int)(float)(v7 - v8)) > 0.001 )
break;
if ( ++v5 == v3 )
goto LABEL_6;
}
puts("ERROR - Incorrect result.");
result = printf("At %ld, %ld got %f instead of %f\n", v4, v5, v8, v7);
}
else
{
LABEL_7:
puts("Result is correct.");
result = puts("[cake: OK]");
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // r15
unsigned __int64 v3; // r14
__int64 v4; // rbp
__int64 v5; // rbx
int result; // eax
float v7; // [rsp+8h] [rbp-40h]
float v8; // [rsp+Ch] [rbp-3Ch]

v2 = a1[1];
if ( v2 )
{
v3 = a1[2];
v4 = 0LL;
while ( 1 )
{
v5 = 1LL;
if ( v3 > 1 )
break;
LABEL_6:
if ( ++v4 == v2 )
goto LABEL_7;
}
while ( 1 )
{
v7 = func5(a2, v4, v5);
v8 = func5(a1, v4, v5);
if ( (float)(int)abs32((int)(float)(v7 - v8)) > 0.001 )
break;
if ( ++v5 == v3 )
goto LABEL_6;
}
puts("ERROR - Incorrect result.");
result = printf("At %ld, %ld got %f instead of %f\n", v4, v5, v8, v7);
}
else
{
LABEL_7:
puts("Result is correct.");
result = puts("[cake: OK]");
}
return result;
}


decompiled_code:
int __fastcall timer_reset(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

original_code:
void
timer_reset(timer* tt)
{
    struct timeval* tv = (struct timeval*)tt;
    gettimeofday(tv, 0);
}

canonical_original_code:
void timer_reset(struct timeval *tt)
{
    struct timeval *tv = (struct timeval*)tt;
    gettimeofday(tv, 0);
}

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


decompiled_code:
struct timeval *timer_alloc()
{
struct timeval *v0; // rbx

v0 = (struct timeval *)malloc(0x10uLL);
timer_reset(v0);
return v0;
}

canonical_decompiled_code:
struct timeval *func1()
{
struct timeval *v0; // rbx

v0 = (struct timeval *)malloc(0x10uLL);
func0(v0);
return v0;
}

original_code:
timer*
timer_alloc()
{
    timer* tt = (timer*) malloc(sizeof(timer));
    timer_reset(tt);
    return tt;
}

canonical_original_code:
struct timeval *timer_alloc()
{
    struct timeval *tt = (timer*) malloc(sizeof(timer));
    timer_reset(tt);
    return tt;
}

return_type: struct timeval { long tv_sec; long tv_usec; } *


decompiled_code:
double __fastcall timer_read(_QWORD *a1)
{
struct timeval v2; // [rsp+0h] [rbp-30h] BYREF

gettimeofday(&v2, 0LL);
return (double)SLODWORD(v2.tv_usec) / 1000000.0
+ (double)SLODWORD(v2.tv_sec)
- ((double)(int)a1[1] / 1000000.0
+ (double)(int)*a1);
}

canonical_decompiled_code:
double __fastcall func2(_QWORD *a1)
{
struct timeval v2; // [rsp+0h] [rbp-30h] BYREF

gettimeofday(&v2, 0LL);
return (double)SLODWORD(v2.tv_usec) / 1000000.0
+ (double)SLODWORD(v2.tv_sec)
- ((double)(int)a1[1] / 1000000.0
+ (double)(int)*a1);
}

original_code:
double
timer_read(timer* tt)
{
    const double MM = 1000000.0;
    struct timeval* tv0 = (struct timeval*)tt;
    struct timeval* tv1 = (struct timeval*)__builtin_alloca (sizeof(struct timeval));
    gettimeofday(tv1, 0);
    double s0 = tv0->tv_sec + ((double)tv0->tv_usec) / MM;
    double s1 = tv1->tv_sec + ((double)tv1->tv_usec) / MM;
    return s1 - s0;
}

canonical_original_code:
double timer_read(struct timeval *tt)
{
    double MM = 1000000.0;
    struct timeval *tv0 = (struct timeval*)tt;
    struct timeval *tv1 = (struct timeval*)__builtin_alloca (sizeof(struct timeval));
    gettimeofday(tv1, 0);
    double s0 = tv0->tv_sec + ((double)tv0->tv_usec) / MM;
    double s1 = tv1->tv_sec + ((double)tv1->tv_usec) / MM;
    return s1 - s0;
}

variable_types: MM double

return_type: double

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


decompiled_code:
void __fastcall timer_free(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
free(a1);
}

original_code:
void
timer_free(timer* tt)
{
    free(tt);
}

canonical_original_code:
void timer_free(struct timeval *tt)
{
    free(tt);
}


decompiled_code:
timeval *timer_alloc(void)
{
timeval *v1; // [rsp+8h] [rbp-8h]

v1 = (timeval *)malloc(0x10uLL);
timer_reset(v1);
return v1;
}

canonical_decompiled_code:
timeval *func0(void)
{
timeval *v1; // [rsp+8h] [rbp-8h]

v1 = (timeval *)malloc(0x10uLL);
func1(v1);
return v1;
}


decompiled_code:
int __fastcall timer_reset(timeval *a1)
{
return gettimeofday(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func1(timeval *a1)
{
return gettimeofday(a1, 0LL);
}


decompiled_code:
double __fastcall timer_read(timeval *a1)
{
void *v1; // rsp
__int64 v3; // [rsp+8h] [rbp-38h] BYREF
double v4; // [rsp+20h] [rbp-20h]
struct timeval *tv; // [rsp+28h] [rbp-18h]
timeval *v6; // [rsp+30h] [rbp-10h]
__int64 v7; // [rsp+38h] [rbp-8h]

HIBYTE(v3) = HIBYTE(a1);
v7 = 0x412E848000000000LL;
v6 = a1;
v1 = alloca(32LL);
tv = (struct timeval *)(16 * (((unsigned __int64)&v3 + 7) >> 4));
gettimeofday(tv, 0LL);
v4 = (double)(int)v6->tv_usec / 1000000.0 + (double)(int)v6->tv_sec;
return (double)(int)tv->tv_usec / 1000000.0 + (double)(int)tv->tv_sec - v4;
}

canonical_decompiled_code:
double __fastcall func2(timeval *a1)
{
void *v1; // rsp
__int64 v3; // [rsp+8h] [rbp-38h] BYREF
double v4; // [rsp+20h] [rbp-20h]
struct timeval *tv; // [rsp+28h] [rbp-18h]
timeval *v6; // [rsp+30h] [rbp-10h]
__int64 v7; // [rsp+38h] [rbp-8h]

HIBYTE(v3) = HIBYTE(a1);
v7 = 0x412E848000000000LL;
v6 = a1;
v1 = alloca(32LL);
tv = (struct timeval *)(16 * (((unsigned __int64)&v3 + 7) >> 4));
gettimeofday(tv, 0LL);
v4 = (double)(int)v6->tv_usec / 1000000.0 + (double)(int)v6->tv_sec;
return (double)(int)tv->tv_usec / 1000000.0 + (double)(int)tv->tv_sec - v4;
}


decompiled_code:
void __fastcall timer_free(timeval *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func3(timeval *a1)
{
free(a1);
}


streq

decompiled_code:
_BOOL8 __fastcall streq(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

original_code:
int
streq(const char* aa, const char* bb)
{
    return strcmp(aa, bb) == 0;
}

canonical_original_code:
int streq(char *aa, char *bb)
{
    return strcmp(aa, bb) == 0;
}

variable_types:
aa
char *

variable_types:
bb
char *

return_type: int


carp

decompiled_code:
void __fastcall __noreturn carp(const char *a1)
{
fprintf(stderr, "FATAL: %s\n", a1);
fflush(stderr);
abort();
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
fprintf(stderr, "FATAL: %s\n", a1);
fflush(stderr);
abort();
}

original_code:
void
carp(const char* msg)
{
    fprintf(stderr, "FATAL: %s\n", msg);
    fflush(stderr);
    abort();
}

canonical_original_code:
void carp(char *msg)
{
    fprintf(stderr, "FATAL: %s\n", msg);
    fflush(stderr);
    abort();
}

variable_types:
msg
char *


decompiled_code:
void __fastcall free_image(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void
free_image(image* im)
{
    free(im->data);
    free(im);
}

canonical_original_code:
void free_image(struct image *im)
{
    free(im->data);
    free(im);
}

variable_types: struct image { unsigned long width; unsigned long height; unsigned char *data; } *


main

canonical_name: main

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

v3 = pclu_create_context(argc, argv, envp);
v4 = (const char *)pclu_context_info(v3);
printf("\n%s\n", v4);
v5 = read_image(INPUT);
cl_gaussian_blur(v3, v5, 20);
write_image(OUTPUT, v5);
free_image(v5);
pclu_destroy_context(v3);
return 0;
}

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

v3 = pclu_create_context(argc, argv, envp);
v4 = (const char *)pclu_context_info(v3);
printf("\n%s\n", v4);
v5 = read_image(INPUT);
func6(v3, v5, 20);
func3(OUTPUT, v5);
func2(v5);
pclu_destroy_context(v3);
return 0;
}

original_code:
int
main(int argc, char* argv[])
{
    image* im = read_image(INPUT);
    gaussian_blur(im, SIGMA);
    write_image(OUTPUT, im);
    free_image(im);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct image *im = read_image(INPUT);
    gaussian_blur(im, SIGMA);
    write_image(OUTPUT, im);
    free_image(im);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

user_defined_types: struct image { unsigned long width; unsigned long height; unsigned char *data; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
const char *v4; // rax
char *v5; // rbx
_BYTE v7[256]; // [rsp+0h] [rbp-118h] BYREF
char v8; // [rsp+100h] [rbp-18h] BYREF

v3 = pclu_create_context(argc, argv, envp);
v4 = (const char *)pclu_context_info(v3);
printf("\n%s\n", v4);
cl_get_ids(v3, (__int64)v7);
v5 = v7;
do
{
printf("%d ", *(unsigned int *)v5);
v5 += 4;
}
while ( v5 != &v8 );
putchar(10);
pclu_destroy_context(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
const char *v4; // rax
char *v5; // rbx
_BYTE v7[256]; // [rsp+0h] [rbp-118h] BYREF
char v8; // [rsp+100h] [rbp-18h] BYREF

v3 = pclu_create_context(argc, argv, envp);
v4 = (const char *)pclu_context_info(v3);
printf("\n%s\n", v4);
func2(v3, (__int64)v7);
v5 = v7;
do
{
printf("%d ", *(unsigned int *)v5);
v5 += 4;
}
while ( v5 != &v8 );
putchar(10);
pclu_destroy_context(v3);
return 0;
}


decompiled_code:
int __fastcall cl_perror(int a1)
{
__int64 v1; // rdi
const char *v2; // rdx

v1 = (unsigned int)(a1 + 72);
v2 = "UNKNOWN_ERROR";
if ( (unsigned int)v1 <= 0x49 )
v2 = CSWTCH_130[v1];
return fprintf(stderr, "OpenCL Error: %s\n", v2);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
__int64 v1; // rdi
const char *v2; // rdx

v1 = (unsigned int)(a1 + 72);
v2 = "UNKNOWN_ERROR";
if ( (unsigned int)v1 <= 0x49 )
v2 = CSWTCH_130[v1];
return fprintf(stderr, "OpenCL Error: %s\n", v2);
}

canonical_original_code:
static void cl_perror(int code)
{
    fprintf(stderr, "OpenCL Error: %s\n", cl_strerror(code));
}

variable_types: code int


exists

repo: NatTuck/libdrip

decompiled_code:
_BOOL8 __fastcall exists(const char *a1)
{
int v1; // edx
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v3);
result = 1LL;
if ( v1 == -1 )
result = *_errno_location() != 2;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1)
{
int v1; // edx
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v3);
result = 1LL;
if ( v1 == -1 )
result = *_errno_location() != 2;
return result;
}

original_code:
static
int
exists(const char* filename)
{
    struct stat info;
    int rv = lstat(filename, &info);
    if (rv == -1 && (*__errno_location ()) == 2)
        return 0;
    else
        return 1;
}

canonical_original_code:
static int exists(char *filename)
{
    struct stat info;
    int rv = lstat(filename, &info);
    if (rv == -1 && (*__errno_location ()) == 2)
        return 0;
    else
        return 1;
}

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: rv int

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


lslurp

decompiled_code:
__int64 __fastcall lslurp(char *a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

return lslurpb(a1, &v2);
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

return func2(a1, &v2);
}

original_code:
char*
lslurp(const char* filename)
{
    size_t ignored;
    return (char*) lslurpb(filename, &ignored);
}

canonical_original_code:
char *lslurp(char *filename)
{
    unsigned long ignored;
    return (char *) lslurpb(filename, &ignored);
}

variable_types:
ignored
unsigned long

return_type: char *


ldump

decompiled_code:
int __fastcall ldump(const char *a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
return ldumpb(a1, a2, v2);
}

canonical_decompiled_code:
int __fastcall func5(const char *a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
return func4(a1, a2, v2);
}

original_code:
void
ldump(const char* filename, const char* text)
{
    ldumpb(filename, (void*) text, strlen(text));
}

canonical_original_code:
void ldump(char *filename, char *text)
{
    ldumpb(filename, (void *) text, strlen(text));
}

variable_types:
text
char *


ltempname

decompiled_code:
const char *__fastcall ltempname(__int64 a1)
{
__int64 v1; // r13
const char *v2; // r12

v1 = getpid();
do
{
v1 = (17 * v1 + 5) % 0x10000;
v2 = (const char *)lsprintf("/tmp/%s-%04lx", a1);
}
while ( exists(v2) );
return v2;
}

canonical_decompiled_code:
const char *__fastcall func6(__int64 a1)
{
__int64 v1; // r13
const char *v2; // r12

v1 = getpid();
do
{
v1 = (17 * v1 + 5) % 0x10000;
v2 = (const char *)lsprintf("/tmp/%s-%04lx", a1);
}
while ( func0(v2) );
return v2;
}

original_code:
char*
ltempname(const char* prefix)
{
    struct stat info;
    char* name;
    long nn = (long) getpid();
    do {
        nn = (nn * 17 + 5) % 0x10000;
        name = lsprintf("/tmp/%s-%04lx", prefix, nn);
    } while(exists(name));
    return name;
}

canonical_original_code:
char *ltempname(char *prefix)
{
    struct stat info;
    char *name;
    long nn = (long) getpid();
    do {
        nn = (nn * 17 + 5) % 0x10000;
        name = lsprintf("/tmp/%s-%04lx", prefix, nn);
    } while(exists(name));
    return name;
}

variable_types:
prefix
char *

variable_types:
name
char *

variable_types: nn long

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


lshell

decompiled_code:
__int64 __fastcall lshell(const char *a1)
{
char *v1; // rbx
const char *v2; // rax
int v3; // eax
__int64 v4; // rbp

v1 = (char *)ltempname((__int64)"lshell");
v2 = (const char *)lsprintf("(%s) > %s", a1);
v3 = system(v2);
if ( BYTE1(v3) )
{
fprintf(stderr, "lshell(%s) exited with status %d", a1, BYTE1(v3));
fflush(stderr);
abort();
}
v4 = lslurp(v1);
unlink(v1);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
char *v1; // rbx
const char *v2; // rax
int v3; // eax
__int64 v4; // rbp

v1 = (char *)func6((__int64)"lshell");
v2 = (const char *)lsprintf("(%s) > %s", a1);
v3 = system(v2);
if ( BYTE1(v3) )
{
fprintf(stderr, "lshell(%s) exited with status %d", a1, BYTE1(v3));
fflush(stderr);
abort();
}
v4 = func3(v1);
unlink(v1);
return v4;
}

original_code:
char*
lshell(const char* cmd)
{
    char* filename = ltempname("lshell");
    char* full_cmd = lsprintf("(%s) > %s", cmd, filename);
    int rv = system(full_cmd);
    if ((((rv) & 0xff00) >> 8) != 0) {
        fprintf(stderr, "lshell(%s) exited with status %d", cmd, (((rv) & 0xff00) >> 8));
        fflush(stderr);
        abort();
    }
    char* output = lslurp(filename);
    unlink(filename);
    return output;
}

canonical_original_code:
char *lshell(char *cmd)
{
    char *filename = ltempname("lshell");
    char *full_cmd = lsprintf("(%s) > %s", cmd, filename);
    int rv = system(full_cmd);
    if ((((rv) & 0xff00) >> 8) != 0) {
        fprintf(stderr, "lshell(%s) exited with status %d", cmd, (((rv) & 0xff00) >> 8));
        fflush(stderr);
        abort();
    }
    char *output = lslurp(filename);
    unlink(filename);
    return output;
}

variable_types:
cmd
char *

variable_types:
output
char *


streq

variable_types:
aa
char *


lstrdup

decompiled_code:
__int64 __fastcall lstrdup(const char *a1)
{
size_t v1; // r12
__int64 v2; // rbx

v1 = strlen(a1) + 1;
v2 = GC_malloc_atomic(v1);
strlcpy(v2, a1, v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
size_t v1; // r12
__int64 v2; // rbx

v1 = strlen(a1) + 1;
v2 = GC_malloc_atomic(v1);
strlcpy(v2, a1, v1);
return v2;
}

original_code:
char*
lstrdup(const char* aa)
{
    size_t size = strlen(aa) + 1;
    char* bb = (char*) GC_malloc_atomic(size);
    strlcpy(bb, aa, size);
    return bb;
}

canonical_original_code:
char *lstrdup(char *aa)
{
    unsigned long size = strlen(aa) + 1;
    char *bb = (char*) GC_malloc_atomic(size);
    strlcpy(bb, aa, size);
    return bb;
}

variable_types:
size
unsigned long

variable_types:
bb
char *


lsprintf

decompiled_code:
char *lsprintf(char *format, ...)
{
size_t v1; // rbx
char *v2; // rbp
__m128i v4; // [rsp+0h] [rbp-108h] BYREF
void *v5; // [rsp+10h] [rbp-F8h]
gcc_va_list arg; // [rsp+18h] [rbp-F0h] BYREF

va_start(arg, format);
v4 = _mm_loadu_si128((const __m128i *)arg);
v5 = arg[0].reg_save_area;
v1 = vsnprintf(0LL, 0LL, format, arg) + 1;
v2 = (char *)GC_malloc_atomic(v1);
vsnprintf(v2, v1, format, &v4);
return v2;
}

canonical_decompiled_code:
char *func3(char *format, ...)
{
size_t v1; // rbx
char *v2; // rbp
__m128i v4; // [rsp+0h] [rbp-108h] BYREF
void *v5; // [rsp+10h] [rbp-F8h]
gcc_va_list arg; // [rsp+18h] [rbp-F0h] BYREF

va_start(arg, format);
v4 = _mm_loadu_si128((const __m128i *)arg);
v5 = arg[0].reg_save_area;
v1 = vsnprintf(0LL, 0LL, format, arg) + 1;
v2 = (char *)GC_malloc_atomic(v1);
vsnprintf(v2, v1, format, &v4);
return v2;
}

original_code:
char*
lsprintf(const char* fmt, ...)
{
    va_list ap1;
    va_list ap2;
    __builtin_va_start(ap1,fmt);
    __builtin_va_copy(ap2,ap1);
    int size = 1 + vsnprintf(0, 0, fmt, ap1);
    char* outp = (char*) GC_malloc_atomic(size);
    vsnprintf(outp, size, fmt, ap2);
    __builtin_va_end(ap1);
    __builtin_va_end(ap2);
    return outp;
}

canonical_original_code:
char *lsprintf(char *fmt, ...)
{
    __builtin_va_list ap1;
    __builtin_va_list ap2;
    __builtin_va_start(ap1,fmt);
    __builtin_va_copy(ap2,ap1);
    int size = 1 + vsnprintf(0, 0, fmt, ap1);
    char *outp = (char*) GC_malloc_atomic(size);
    vsnprintf(outp, size, fmt, ap2);
    __builtin_va_end(ap1);
    __builtin_va_end(ap2);
    return outp;
}

variable_types:
fmt
char *

variable_types: size int

variable_types:
outp
char *


lchomp

decompiled_code:
const char *__fastcall lchomp(const char *a1)
{
const char *v1; // rbx
__int64 v2; // rax
const char *v3; // rdx
__int64 v4; // rax

v1 = (const char *)lstrdup(a1);
v2 = (int)(strlen(v1) - 1);
v3 = &v1[v2];
if ( v1[v2] == 10 )
{
v4 = (__int64)&v1[v2 - 1];
do
{
*v3 = 0;
v3 = (const char *)v4--;
}
while ( *(_BYTE *)(v4 + 1) == 10 );
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func5(const char *a1)
{
const char *v1; // rbx
__int64 v2; // rax
const char *v3; // rdx
__int64 v4; // rax

v1 = (const char *)func2(a1);
v2 = (int)(strlen(v1) - 1);
v3 = &v1[v2];
if ( v1[v2] == 10 )
{
v4 = (__int64)&v1[v2 - 1];
do
{
*v3 = 0;
v3 = (const char *)v4--;
}
while ( *(_BYTE *)(v4 + 1) == 10 );
}
return v1;
}

original_code:
char*
lchomp(const char* ss)
{
    char* yy = lstrdup(ss);
    int nn = strlen(yy);
    int ii = nn - 1;
    while (yy[ii] == '\n') {
        yy[ii] = '\0';
        ii -= 1;
    }
    return yy;
}

canonical_original_code:
char *lchomp(char *ss)
{
    char *yy = lstrdup(ss);
    int nn = strlen(yy);
    int ii = nn - 1;
    while (yy[ii] == '\n') {
        yy[ii] = '\0';
        ii -= 1;
    }
    return yy;
}

variable_types:
ss
char *

variable_types:
yy
char *

variable_types: nn int

variable_types: ii int


lstripc

decompiled_code:
__int64 __fastcall lstripc(char a1, const char *a2)
{
void *v2; // rsp
size_t v3; // rbx
int v4; // er13
char v5; // al
char v7[15]; // [rsp+0h] [rbp-30h] BYREF

v2 = alloca(strlen(a2) + 10);
v3 = 0LL;
v4 = 0;
while ( strlen(a2) > v3 )
{
v5 = a2[v3];
if ( v5 != a1 )
v7[v4++] = v5;
++v3;
}
v7[v4] = 0;
return lstrdup(v7);
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1, const char *a2)
{
void *v2; // rsp
size_t v3; // rbx
int v4; // er13
char v5; // al
char v7[15]; // [rsp+0h] [rbp-30h] BYREF

v2 = alloca(strlen(a2) + 10);
v3 = 0LL;
v4 = 0;
while ( strlen(a2) > v3 )
{
v5 = a2[v3];
if ( v5 != a1 )
v7[v4++] = v5;
++v3;
}
v7[v4] = 0;
return func2(v7);
}

original_code:
char*
lstripc(const char cc, const char* ss)
{
    char* yy = __builtin_alloca (strlen(ss) + 2);
    int jj = 0;
    for (int ii = 0; ii < strlen(ss); ++ii) {
        if (ss[ii] != cc) {
            yy[jj] = ss[ii];
            jj += 1;
        }
    }
    yy[jj] = 0;
    return lstrdup(yy);
}

canonical_original_code:
char *lstripc(char cc, char *ss)
{
    char *yy = __builtin_alloca (strlen(ss) + 2);
    int jj = 0;
    for (int ii = 0; ii < strlen(ss); ++ii) {
        if (ss[ii] != cc) {
            yy[jj] = ss[ii];
            jj += 1;
        }
    }
    yy[jj] = 0;
    return lstrdup(yy);
}

variable_types: cc char

variable_types: jj int


lmemcpy

decompiled_code:
void *__fastcall lmemcpy(void *src, size_t n)
{
void *v2; // rax

v2 = (void *)GC_malloc(n);
return memcpy(v2, src, n);
}

canonical_decompiled_code:
void *__fastcall func7(void *src, size_t n)
{
void *v2; // rax

v2 = (void *)GC_malloc(n);
return memcpy(v2, src, n);
}

original_code:
void*
lmemcpy(const void* src, size_t n)
{
    void* dest = GC_malloc(n);
    memcpy(dest, src, n);
    return dest;
}

canonical_original_code:
void *lmemcpy(void *src, unsigned long n)
{
    void *dest = GC_malloc(n);
    memcpy(dest, src, n);
    return dest;
}

variable_types:
src
void *

variable_types:
n
unsigned long

variable_types:
dest
void *

return_type: void *


decompiled_code:
__int64 __fastcall lstrvec_alloc(int a1)
{
__int64 v1; // rbp

v1 = GC_malloc(16LL);
*(_DWORD *)v1 = a1;
if ( a1 )
*(_QWORD *)(v1 + 8) = GC_malloc(8LL * a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
__int64 v1; // rbp

v1 = GC_malloc(16LL);
*(_DWORD *)v1 = a1;
if ( a1 )
*(_QWORD *)(v1 + 8) = GC_malloc(8LL * a1);
return v1;
}

original_code:
lstrvec*
lstrvec_alloc(int size)
{
    lstrvec* vec = GC_malloc(sizeof(lstrvec));
    vec->size = size;
    if (size != 0)
        vec->xs = GC_malloc(size * sizeof(char*));
    return vec;
}

canonical_original_code:
struct lstrvec *lstrvec_alloc(int size)
{
    struct lstrvec *vec = GC_malloc(sizeof(lstrvec));
    vec->size = size;
    if (size != 0)
        vec->xs = GC_malloc(size * sizeof(char *));
    return vec;
}

variable_types: struct lstrvec { int size; char **xs; } *


decompiled_code:
__int64 __fastcall lstrvec_size(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1)
{
return *a1;
}

original_code:
int
lstrvec_size(lstrvec* vec)
{
    return vec->size;
}

canonical_original_code:
int lstrvec_size(struct lstrvec *vec)
{
    return vec->size;
}


decompiled_code:
__int64 __fastcall lstrvec_get(unsigned int *a1, int a2)
{
if ( a2 < 0 || (int)*a1 <= a2 )
{
fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n", (unsigned int)a2, *a1);
abort();
}
return lstrdup(*(const char **)(*((_QWORD *)a1 + 1) + 8LL * a2));
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1, int a2)
{
if ( a2 < 0 || (int)*a1 <= a2 )
{
fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n", (unsigned int)a2, *a1);
abort();
}
return func2(*(const char **)(*((_QWORD *)a1 + 1) + 8LL * a2));
}

original_code:
char*
lstrvec_get(lstrvec* vec, int ii)
{
    if (ii < 0 || ii > vec->size - 1) {
        fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n",
                ii, vec->size);
        abort();
    }
    return lstrdup(vec->xs[ii]);
}

canonical_original_code:
char *lstrvec_get(struct lstrvec *vec, int ii)
{
    if (ii < 0 || ii > vec->size - 1) {
        fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n",
                ii, vec->size);
        abort();
    }
    return lstrdup(vec->xs[ii]);
}


decompiled_code:
__int64 __fastcall lstrvec_set(unsigned int *a1, int a2, const char *a3)
{
__int64 *v3; // rbx
__int64 result; // rax

if ( a2 < 0 || (int)*a1 <= a2 )
{
fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n", (unsigned int)a2, *a1);
abort();
}
v3 = (__int64 *)(*((_QWORD *)a1 + 1) + 8LL * a2);
result = lstrdup(a3);
*v3 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int *a1, int a2, const char *a3)
{
__int64 *v3; // rbx
__int64 result; // rax

if ( a2 < 0 || (int)*a1 <= a2 )
{
fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n", (unsigned int)a2, *a1);
abort();
}
v3 = (__int64 *)(*((_QWORD *)a1 + 1) + 8LL * a2);
result = func2(a3);
*v3 = result;
return result;
}

original_code:
void
lstrvec_set(lstrvec* vec, int ii, char* vv)
{
    if (ii < 0 || ii > vec->size - 1) {
        fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n",
                ii, vec->size);
        abort();
    }
    vec->xs[ii] = lstrdup(vv);
}

canonical_original_code:
void lstrvec_set(struct lstrvec *vec, int ii, char *vv)
{
    if (ii < 0 || ii > vec->size - 1) {
        fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n",
                ii, vec->size);
        abort();
    }
    vec->xs[ii] = lstrdup(vv);
}

variable_types:
vv
char *


decompiled_code:
_BOOL8 __fastcall lstrvec_contains(__int64 a1, const char *a2)
{
__int64 v2; // rbx
_BOOL8 result; // rax

if ( *(int *)a1 <= 0 )
return 0LL;
v2 = 0LL;
while ( 1 )
{
result = streq(a2, *(const char **)(*(_QWORD *)(a1 + 8) + 8 * v2));
if ( result )
break;
if ( *(_DWORD *)a1 <= (int)++v2 )
return result;
}
return 1LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(__int64 a1, const char *a2)
{
__int64 v2; // rbx
_BOOL8 result; // rax

if ( *(int *)a1 <= 0 )
return 0LL;
v2 = 0LL;
while ( 1 )
{
result = func0(a2, *(const char **)(*(_QWORD *)(a1 + 8) + 8 * v2));
if ( result )
break;
if ( *(_DWORD *)a1 <= (int)++v2 )
return result;
}
return 1LL;
}

original_code:
int
lstrvec_contains(lstrvec* vec, const char* ss)
{
    int ii;
    for (ii = 0; ii < vec->size; ++ii) {
        if (streq(ss, vec->xs[ii]))
            return 1;
    }
    return 0;
}

canonical_original_code:
int lstrvec_contains(struct lstrvec *vec, char *ss)
{
    int ii;
    for (ii = 0; ii < vec->size; ++ii) {
        if (streq(ss, vec->xs[ii]))
            return 1;
    }
    return 0;
}


lwords

decompiled_code:
unsigned int *__fastcall lwords(const char *a1)
{
const char *v1; // rbx
int v2; // eax
int v3; // er8
int v4; // er12
int j; // edx
const char *v6; // rcx
const char *v7; // rsi
__int64 v8; // rax
int v9; // edi
unsigned int *v10; // r13
int i; // ebp
const char *v12; // rax

v1 = (const char *)lstrdup(a1);
v2 = strlen(v1);
if ( v2 <= 0 )
{
v10 = (unsigned int *)lstrvec_alloc(1);
v4 = 0;
LABEL_10:
for ( i = 0; i <= v4; ++i )
{
v12 = (const char *)lstrdup(v1);
lstrvec_set(v10, i, v12);
for ( v1 += strlen(v1); !*v1; ++v1 )
;
}
return v10;
}
v3 = v2;
v4 = 0;
for ( j = 0; j < v3; ++j )
{
v6 = &v1[j];
if ( *v6 == 32 )
{
*v6 = 0;
++v4;
v7 = &v1[j + 1];
if ( *v7 == 32 )
{
v8 = 0LL;
v9 = j + 1;
do
{
j = v9 + v8;
v7[v8++] = 0;
}
while ( v6[v8 + 1] == 32 );
}
}
}
v10 = (unsigned int *)lstrvec_alloc(v4 + 1);
if ( v4 >= 0 )
goto LABEL_10;
return v10;
}

canonical_decompiled_code:
unsigned int *__fastcall func13(const char *a1)
{
const char *v1; // rbx
int v2; // eax
int v3; // er8
int v4; // er12
int j; // edx
const char *v6; // rcx
const char *v7; // rsi
__int64 v8; // rax
int v9; // edi
unsigned int *v10; // r13
int i; // ebp
const char *v12; // rax

v1 = (const char *)func2(a1);
v2 = strlen(v1);
if ( v2 <= 0 )
{
v10 = (unsigned int *)func8(1);
v4 = 0;
LABEL_10:
for ( i = 0; i <= v4; ++i )
{
v12 = (const char *)func2(v1);
func11(v10, i, v12);
for ( v1 += strlen(v1); !*v1; ++v1 )
;
}
return v10;
}
v3 = v2;
v4 = 0;
for ( j = 0; j < v3; ++j )
{
v6 = &v1[j];
if ( *v6 == 32 )
{
*v6 = 0;
++v4;
v7 = &v1[j + 1];
if ( *v7 == 32 )
{
v8 = 0LL;
v9 = j + 1;
do
{
j = v9 + v8;
v7[v8++] = 0;
}
while ( v6[v8 + 1] == 32 );
}
}
}
v10 = (unsigned int *)func8(v4 + 1);
if ( v4 >= 0 )
goto LABEL_10;
return v10;
}

original_code:
lstrvec*
lwords(const char* ss)
{
    char* aa = lstrdup(ss);
    int ii, jj;
    int nn = strlen(aa);
    int spaces = 0;
    lstrvec* xs;
    for (ii = 0; ii < nn; ++ii) {
        if (aa[ii] == ' ') {
            aa[ii] = '\0';
            spaces += 1;
            while (aa[ii + 1] == ' ') {
                ii += 1;
                aa[ii] = '\0';
            }
        }
    }
    xs = lstrvec_alloc(spaces + 1);
    for (ii = 0; ii < spaces + 1; ++ii) {
        lstrvec_set(xs, ii, lstrdup(aa));
        aa += strlen(aa);
        while(aa[0] == '\0')
            aa += 1;
    }
    return xs;
}

canonical_original_code:
struct lstrvec *lwords(char *ss)
{
    char *aa = lstrdup(ss);
    int ii; int jj;
    int nn = strlen(aa);
    int spaces = 0;
    struct lstrvec *xs;
    for (ii = 0; ii < nn; ++ii) {
        if (aa[ii] == ' ') {
            aa[ii] = '\0';
            spaces += 1;
            while (aa[ii + 1] == ' ') {
                ii += 1;
                aa[ii] = '\0';
            }
        }
    }
    xs = lstrvec_alloc(spaces + 1);
    for (ii = 0; ii < spaces + 1; ++ii) {
        lstrvec_set(xs, ii, lstrdup(aa));
        aa += strlen(aa);
        while(aa[0] == '\0')
            aa += 1;
    }
    return xs;
}

variable_types:
aa
char *

variable_types: spaces int

return_type: struct lstrvec { int size; char **xs; } *


lsplitc

decompiled_code:
unsigned int *__fastcall lsplitc(char a1, const char *a2)
{
const char *v2; // rbx
int v3; // eax
int v4; // edx
const char *v5; // rax
__int64 v6; // rdx
int v7; // er12
unsigned int *v8; // r13
int i; // ebp
const char *v10; // rax

v2 = (const char *)lstrdup(a2);
v3 = strlen(v2);
if ( v3 <= 0 )
{
v8 = (unsigned int *)lstrvec_alloc(1);
v7 = 1;
LABEL_7:
for ( i = 0; i < v7; ++i )
{
v10 = (const char *)lstrdup(v2);
lstrvec_set(v8, i, v10);
for ( v2 += strlen(v2); !*v2; ++v2 )
;
}
return v8;
}
v4 = v3;
v5 = v2;
v6 = (__int64)&v2[v4 - 1 + 1];
v7 = 1;
do
{
if ( *v5 == a1 )
{
*v5 = 0;
++v7;
}
++v5;
}
while ( v5 != (const char *)v6 );
v8 = (unsigned int *)lstrvec_alloc(v7);
if ( v7 > 0 )
goto LABEL_7;
return v8;
}

canonical_decompiled_code:
unsigned int *__fastcall func14(char a1, const char *a2)
{
const char *v2; // rbx
int v3; // eax
int v4; // edx
const char *v5; // rax
__int64 v6; // rdx
int v7; // er12
unsigned int *v8; // r13
int i; // ebp
const char *v10; // rax

v2 = (const char *)func2(a2);
v3 = strlen(v2);
if ( v3 <= 0 )
{
v8 = (unsigned int *)func8(1);
v7 = 1;
LABEL_7:
for ( i = 0; i < v7; ++i )
{
v10 = (const char *)func2(v2);
func11(v8, i, v10);
for ( v2 += strlen(v2); !*v2; ++v2 )
;
}
return v8;
}
v4 = v3;
v5 = v2;
v6 = (__int64)&v2[v4 - 1 + 1];
v7 = 1;
do
{
if ( *v5 == a1 )
{
*v5 = 0;
++v7;
}
++v5;
}
while ( v5 != (const char *)v6 );
v8 = (unsigned int *)func8(v7);
if ( v7 > 0 )
goto LABEL_7;
return v8;
}

original_code:
lstrvec*
lsplitc(const char cc, const char* ss)
{
    char* aa = lstrdup(ss);
    int ii, jj;
    int nn = strlen(aa);
    int slots = 1;
    lstrvec* xs;
    for (ii = 0; ii < nn; ++ii) {
        if (aa[ii] == cc) {
            aa[ii] = '\0';
            slots += 1;
        }
    }
    xs = lstrvec_alloc(slots);
    for (ii = 0; ii < slots; ++ii) {
        lstrvec_set(xs, ii, lstrdup(aa));
        aa += strlen(aa);
        while(aa[0] == '\0')
            aa += 1;
    }
    return xs;
}

canonical_original_code:
struct lstrvec *lsplitc(char cc, char *ss)
{
    char *aa = lstrdup(ss);
    int ii; int jj;
    int nn = strlen(aa);
    int slots = 1;
    struct lstrvec *xs;
    for (ii = 0; ii < nn; ++ii) {
        if (aa[ii] == cc) {
            aa[ii] = '\0';
            slots += 1;
        }
    }
    xs = lstrvec_alloc(slots);
    for (ii = 0; ii < slots; ++ii) {
        lstrvec_set(xs, ii, lstrdup(aa));
        aa += strlen(aa);
        while(aa[0] == '\0')
            aa += 1;
    }
    return xs;
}

variable_types: slots int


decompiled_code:
void __fastcall __noreturn drip_carp_real(const char *a1, unsigned int a2, const char *a3)
{
fprintf(stderr, "Fatal error at %s:%d\n\t%s\n", a1, a2, a3);
fflush(stderr);
abort();
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1, unsigned int a2, const char *a3)
{
fprintf(stderr, "Fatal error at %s:%d\n\t%s\n", a1, a2, a3);
fflush(stderr);
abort();
}

original_code:
void
drip_carp_real(const char* filename, const int line, const char* message)
{
    fprintf(stderr, "Fatal error at %s:%d\n\t%s\n", filename, line, message);
    fflush(stderr);
    abort();
}

canonical_original_code:
void drip_carp_real(char *filename, int line, char *message)
{
    fprintf(stderr, "Fatal error at %s:%d\n\t%s\n", filename, line, message);
    fflush(stderr);
    abort();
}

variable_types:
filename
char *

variable_types: line int

variable_types:
message
char *


repo: NatTuck/pancake

decompiled_code:
float rand48()
{
if ( !seeded_1 )
{
seed_0[2] = getpid();
seeded_1 = 1;
}
return erand48(seed_0);
}

canonical_decompiled_code:
float func0()
{
if ( !seeded_1 )
{
seed_0[2] = getpid();
seeded_1 = 1;
}
return erand48(seed_0);
}

original_code:
float
rand48()
{
    static unsigned short seed[3] = { 50, 461, 0 };
    static int seeded = 0;
    if (seeded == 0) {
        seed[2] = (short)getpid();
        seeded = 1;
    }
    return (float) erand48(seed);
}

variable_types:
seed
unsigned short [3]

variable_types: seeded int


decompiled_code:
__int64 __fastcall matrix_size(__int64 a1)
{
return *(_QWORD *)(a1 + 16) * *(_QWORD *)(a1 + 8);
}

original_code:
size_t
matrix_size(matrix * mm)
{
    return mm->rows * mm->cols;
}

canonical_original_code:
unsigned long matrix_size(struct matrix *mm)
{
    return mm->rows * mm->cols;
}

variable_types: struct matrix { float *data; unsigned long rows; unsigned long cols; } *


decompiled_code:
__int64 __fastcall matrix_bytes(__int64 a1)
{
return 4 * matrix_size(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return 4 * func1(a1);
}

original_code:
size_t
matrix_bytes(matrix * mm)
{
    return matrix_size(mm) * sizeof(float);
}

canonical_original_code:
unsigned long matrix_bytes(struct matrix *mm)
{
    return matrix_size(mm) * sizeof(float);
}


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

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

original_code:
void
destroy_matrix(matrix * mm)
{
    free(mm->data);
    free(mm);
}

canonical_original_code:
void destroy_matrix(struct matrix *mm)
{
    free(mm->data);
    free(mm);
}


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

result = *a1;
*(float *)(*a1 + 4 * (a3 + a1[2] * a2)) = a4;
return result;
}

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

result = *a1;
*(float *)(*a1 + 4 * (a3 + a1[2] * a2)) = a4;
return result;
}

original_code:
void
set_cell(matrix * mm, size_t ii, size_t jj, float value)
{
    mm->data[ii * mm->cols + jj] = value;
}

canonical_original_code:
void set_cell(struct matrix *mm, unsigned long ii, unsigned long jj, float value)
{
    mm->data[ii * mm->cols + jj] = value;
}

variable_types:
ii
unsigned long

variable_types:
jj
unsigned long

variable_types: value float


decompiled_code:
float __fastcall get_cell(_QWORD *a1, __int64 a2, __int64 a3)
{
return *(float *)(*a1 + 4 * (a3 + a1[2] * a2));
}

canonical_decompiled_code:
float __fastcall func5(_QWORD *a1, __int64 a2, __int64 a3)
{
return *(float *)(*a1 + 4 * (a3 + a1[2] * a2));
}

original_code:
float
get_cell(matrix * mm, size_t ii, size_t jj)
{
    return mm->data[ii * mm->cols + jj];
}

canonical_original_code:
float get_cell(struct matrix *mm, unsigned long ii, unsigned long jj)
{
    return mm->data[ii * mm->cols + jj];
}


decompiled_code:
int __fastcall print_matrix(_QWORD *a1)
{
unsigned __int64 i; // r12
float v2; // xmm0_4
unsigned __int64 j; // rbx
int result; // eax

for ( i = 0LL; a1[1] > i; ++i )
{
for ( j = 0LL; a1[2] > j; ++j )
{
v2 = get_cell(a1, i, j);
printf("%.02f", v2);
putchar(32);
}
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(_QWORD *a1)
{
unsigned __int64 i; // r12
float v2; // xmm0_4
unsigned __int64 j; // rbx
int result; // eax

for ( i = 0LL; a1[1] > i; ++i )
{
for ( j = 0LL; a1[2] > j; ++j )
{
v2 = func5(a1, i, j);
printf("%.02f", v2);
putchar(32);
}
result = putchar(10);
}
return result;
}

original_code:
void
print_matrix(matrix * mm)
{
    for (size_t ii = 0; ii < mm->rows; ++ii) {
        for (size_t jj = 0; jj < mm->cols; ++jj) {
            float xx = get_cell(mm, ii, jj);
            printf("%.02f", xx);
            printf(" ");
        }
        printf("\n");
    }
}

canonical_original_code:
void print_matrix(struct matrix *mm)
{
    for (unsigned long ii = 0; ii < mm->rows; ++ii) {
        for (unsigned long jj = 0; jj < mm->cols; ++jj) {
            float xx = get_cell(mm, ii, jj);
            printf("%.02f", xx);
            printf(" ");
        }
        printf("\n");
    }
}

variable_types: xx float


decompiled_code:
int __fastcall check_result(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // r15
unsigned __int64 v3; // r14
__int64 v4; // rbp
__int64 v5; // rbx
float v7; // [rsp+8h] [rbp-40h]
float v8; // [rsp+Ch] [rbp-3Ch]

v2 = a1[1];
if ( !v2 )
return puts("Result is correct.");
v3 = a1[2];
v4 = 0LL;
while ( 1 )
{
v5 = 1LL;
if ( v3 > 1 )
break;
LABEL_6:
if ( ++v4 == v2 )
return puts("Result is correct.");
}
while ( 1 )
{
v7 = get_cell(a2, v4, v5);
v8 = get_cell(a1, v4, v5);
if ( (float)(int)abs32((int)(float)(v7 - v8)) > 0.001 )
break;
if ( ++v5 == v3 )
goto LABEL_6;
}
puts("ERROR - Incorrect result.");
return printf("At %ld, %ld got %f instead of %f\n", v4, v5, v8, v7);
}

canonical_decompiled_code:
int __fastcall func7(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // r15
unsigned __int64 v3; // r14
__int64 v4; // rbp
__int64 v5; // rbx
float v7; // [rsp+8h] [rbp-40h]
float v8; // [rsp+Ch] [rbp-3Ch]

v2 = a1[1];
if ( !v2 )
return puts("Result is correct.");
v3 = a1[2];
v4 = 0LL;
while ( 1 )
{
v5 = 1LL;
if ( v3 > 1 )
break;
LABEL_6:
if ( ++v4 == v2 )
return puts("Result is correct.");
}
while ( 1 )
{
v7 = func5(a2, v4, v5);
v8 = func5(a1, v4, v5);
if ( (float)(int)abs32((int)(float)(v7 - v8)) > 0.001 )
break;
if ( ++v5 == v3 )
goto LABEL_6;
}
puts("ERROR - Incorrect result.");
return printf("At %ld, %ld got %f instead of %f\n", v4, v5, v8, v7);
}

original_code:
void
check_result(matrix * cc, matrix * aa)
{
    const float EPS = 0.001;
    for (size_t ii = 0; ii < cc->rows; ++ii) {
        for (size_t jj = 1; jj < cc->cols; ++jj) {
            float xx = get_cell(aa, ii, jj);
            float yy = get_cell(cc, ii, jj);
            if (abs(1*xx - yy) > EPS) {
                printf("ERROR - Incorrect result.\n");
                printf("At %ld, %ld got %f instead of %f\n",
                       ii, jj, yy, xx);
                return;
            }
        }
    }
    printf("Result is correct.\n");
}

canonical_original_code:
void check_result(struct matrix *cc, struct matrix *aa)
{
    float EPS = 0.001;
    for (unsigned long ii = 0; ii < cc->rows; ++ii) {
        for (unsigned long jj = 1; jj < cc->cols; ++jj) {
            float xx = get_cell(aa, ii, jj);
            float yy = get_cell(cc, ii, jj);
            if (abs(1*xx - yy) > EPS) {
                printf("ERROR - Incorrect result.\n");
                printf("At %ld, %ld got %f instead of %f\n",
                       ii, jj, yy, xx);
                return;
            }
        }
    }
    printf("Result is correct.\n");
}

variable_types:
aa
struct matrix *

variable_types: EPS float

variable_types: yy float


decompiled_code:
int __fastcall timer_reset(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

original_code:
void
timer_reset(timer* tt)
{
    struct timeval* tv = (struct timeval*)tt;
    gettimeofday(tv, 0);
}

canonical_original_code:
void timer_reset(struct timeval *tt)
{
    struct timeval *tv = (struct timeval*)tt;
    gettimeofday(tv, 0);
}

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


decompiled_code:
struct timeval *timer_alloc()
{
struct timeval *v0; // rbx

v0 = (struct timeval *)malloc(0x10uLL);
timer_reset(v0);
return v0;
}

canonical_decompiled_code:
struct timeval *func1()
{
struct timeval *v0; // rbx

v0 = (struct timeval *)malloc(0x10uLL);
func0(v0);
return v0;
}

original_code:
timer*
timer_alloc()
{
    timer* tt = (timer*) malloc(sizeof(timer));
    timer_reset(tt);
    return tt;
}

canonical_original_code:
struct timeval *timer_alloc()
{
    struct timeval *tt = (timer*) malloc(sizeof(timer));
    timer_reset(tt);
    return tt;
}


decompiled_code:
double __fastcall timer_read(_QWORD *a1)
{
struct timeval v2; // [rsp+0h] [rbp-30h] BYREF

gettimeofday(&v2, 0LL);
return (double)SLODWORD(v2.tv_usec) / 1000000.0
+ (double)SLODWORD(v2.tv_sec)
- ((double)(int)a1[1] / 1000000.0
+ (double)(int)*a1);
}

canonical_decompiled_code:
double __fastcall func2(_QWORD *a1)
{
struct timeval v2; // [rsp+0h] [rbp-30h] BYREF

gettimeofday(&v2, 0LL);
return (double)SLODWORD(v2.tv_usec) / 1000000.0
+ (double)SLODWORD(v2.tv_sec)
- ((double)(int)a1[1] / 1000000.0
+ (double)(int)*a1);
}

original_code:
double
timer_read(timer* tt)
{
    const double MM = 1000000.0;
    struct timeval* tv0 = (struct timeval*)tt;
    struct timeval* tv1 = (struct timeval*)__builtin_alloca (sizeof(struct timeval));
    gettimeofday(tv1, 0);
    double s0 = tv0->tv_sec + ((double)tv0->tv_usec) / MM;
    double s1 = tv1->tv_sec + ((double)tv1->tv_usec) / MM;
    return s1 - s0;
}

canonical_original_code:
double timer_read(struct timeval *tt)
{
    double MM = 1000000.0;
    struct timeval *tv0 = (struct timeval*)tt;
    struct timeval *tv1 = (struct timeval*)__builtin_alloca (sizeof(struct timeval));
    gettimeofday(tv1, 0);
    double s0 = tv0->tv_sec + ((double)tv0->tv_usec) / MM;
    double s1 = tv1->tv_sec + ((double)tv1->tv_usec) / MM;
    return s1 - s0;
}

variable_types: MM double


decompiled_code:
void __fastcall timer_free(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
free(a1);
}

original_code:
void
timer_free(timer* tt)
{
    free(tt);
}

canonical_original_code:
void timer_free(struct timeval *tt)
{
    free(tt);
}


decompiled_code:
int __fastcall pclu_perror(int a1)
{
char *v1; // rax

v1 = pclu_strerror(a1);
return fprintf(stderr, "OpenCL Error: %s\n", v1);
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
char *v1; // rax

v1 = func0(a1);
return fprintf(stderr, "OpenCL Error: %s\n", v1);
}

original_code:
void
pclu_perror(int code)
{
    fprintf(stderr, "OpenCL Error: %s\n", pclu_strerror(code));
}

variable_types: code int


decompiled_code:
__int64 __fastcall get_concurrency(char *nptr)
{
int *v1; // rbx
__int64 result; // rax

v1 = __errno_location();
*v1 = 0;
result = strtol(nptr, 0LL, 10);
if ( *v1 )
{
perror("Error converting string to integer");
exit(1);
}
if ( (unsigned int)(result - 1) > 0x31 )
{
puts("Error: Concurrency level (-c) is not in valid range (1 to 50).");
exit(0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *nptr)
{
int *v1; // rbx
__int64 result; // rax

v1 = __errno_location();
*v1 = 0;
result = strtol(nptr, 0LL, 10);
if ( *v1 )
{
perror("Error converting string to integer");
exit(1);
}
if ( (unsigned int)(result - 1) > 0x31 )
{
puts("Error: Concurrency level (-c) is not in valid range (1 to 50).");
exit(0);
}
return result;
}

original_code:
int get_concurrency(char * concr_str) {
    int concr;
    (*__errno_location ()) = 0;
    concr = (int) strtol(concr_str, ((void *)0), 10);
    if((*__errno_location ()) != 0) {
        perror("Error converting string to integer");
        exit(1);
    }
    if((concr < 1) || (concr > 50)) {
        printf("Error: Concurrency level (-c) is not in valid range (1 to 50).\n");
        exit(0);
    }
    return concr;
}

canonical_original_code:
int get_concurrency(char *concr_str) {
    int concr;
    (*__errno_location ()) = 0;
    concr = (int) strtol(concr_str, ((void *)0), 10);
    if((*__errno_location ()) != 0) {
        perror("Error converting string to integer");
        exit(1);
    }
    if((concr < 1) || (concr > 50)) {
        printf("Error: Concurrency level (-c) is not in valid range (1 to 50).\n");
        exit(0);
    }
    return concr;
}

variable_types: concr int


decompiled_code:
__int64 __fastcall get_max_prime(char *nptr)
{
int *v1; // rbx
__int64 result; // rax

v1 = __errno_location();
*v1 = 0;
result = strtol(nptr, 0LL, 10);
if ( *v1 )
{
perror("Error converting string to integer");
exit(1);
}
if ( (unsigned __int64)(result - 2) > 0xFFFFFFFD )
{
printf("Error: Max prime (-m) is not in valid range (2 to %u).\n", 0xFFFFFFFFLL);
exit(0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *nptr)
{
int *v1; // rbx
__int64 result; // rax

v1 = __errno_location();
*v1 = 0;
result = strtol(nptr, 0LL, 10);
if ( *v1 )
{
perror("Error converting string to integer");
exit(1);
}
if ( (unsigned __int64)(result - 2) > 0xFFFFFFFD )
{
printf("Error: Max prime (-m) is not in valid range (2 to %u).\n", 0xFFFFFFFFLL);
exit(0);
}
return result;
}

original_code:
unsigned int get_max_prime(char * max_str) {
    long max;
    (*__errno_location ()) = 0;
    max = strtol(max_str, ((void *)0), 10);
    if((*__errno_location ()) != 0) {
        perror("Error converting string to integer");
        exit(1);
    }
    if((max < 2) || (max > (0x7fffffff * 2U + 1U))) {
        printf("Error: Max prime (-m) is not in valid range (2 to %u).\n", (0x7fffffff * 2U + 1U));
        exit(0);
    }
    return (unsigned int) max;
}

canonical_original_code:
unsigned int get_max_prime(char *max_str) {
    long max;
    (*__errno_location ()) = 0;
    max = strtol(max_str, ((void *)0), 10);
    if((*__errno_location ()) != 0) {
        perror("Error converting string to integer");
        exit(1);
    }
    if((max < 2) || (max > (0x7fffffff * 2U + 1U))) {
        printf("Error: Max prime (-m) is not in valid range (2 to %u).\n", (0x7fffffff * 2U + 1U));
        exit(0);
    }
    return (unsigned int) max;
}

variable_types: max long

return_type: unsigned int


decompiled_code:
int __fastcall get_options(int argc, char **argv, _DWORD *a3)
{
int result; // eax

*a3 = -1;
a3[1] = 1;
a3[2] = 0;
while ( 1 )
{
result = getopt(argc, argv, "qc:m:");
if ( (_BYTE)result == 0xFF )
break;
switch ( (_BYTE)result )
{
case 'm':
*a3 = get_max_prime(_bss_start);
break;
case 'q':
a3[2] = 1;
break;
case 'c':
a3[1] = get_concurrency(_bss_start);
break;
default:
printf("Usage: %s [-q (quiet mode)] [-c concurrency] [-m max prime]\n", *argv);
exit(0);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(int argc, char **argv, _DWORD *a3)
{
int result; // eax

*a3 = -1;
a3[1] = 1;
a3[2] = 0;
while ( 1 )
{
result = getopt(argc, argv, "qc:m:");
if ( (_BYTE)result == 0xFF )
break;
switch ( (_BYTE)result )
{
case 'm':
*a3 = func10(_bss_start);
break;
case 'q':
a3[2] = 1;
break;
case 'c':
a3[1] = func9(_bss_start);
break;
default:
printf("Usage: %s [-q (quiet mode)] [-c concurrency] [-m max prime]\n", *argv);
exit(0);
}
}
return result;
}

original_code:
void get_options(int argc, char ** argv, struct options * opts) {
    char opt;
    opts->max = (0x7fffffff * 2U + 1U);
    opts->concurrency = 1;
    opts->q_set = 0;
    while((opt = getopt(argc, argv, "qc:m:")) != -1) {
        switch (opt) {
            case 'q':
                opts->q_set = 1;
                break;
            case 'c':
                opts->concurrency = get_concurrency(optarg);
                break;
            case 'm':
                opts->max = get_max_prime(optarg);
                break;
            default:
                printf("Usage: %s [-q (quiet mode)] [-c concurrency] [-m max prime]\n", argv[0]);
                exit(0);
                break;
        }
    }
}

canonical_original_code:
void get_options(int argc, char **argv, struct options *opts) {
    char opt;
    opts->max = (0x7fffffff * 2U + 1U);
    opts->concurrency = 1;
    opts->q_set = 0;
    while((opt = getopt(argc, argv, "qc:m:")) != -1) {
        switch (opt) {
            case 'q':
                opts->q_set = 1;
                break;
            case 'c':
                opts->concurrency = get_concurrency(optarg);
                break;
            case 'm':
                opts->max = get_max_prime(optarg);
                break;
            default:
                printf("Usage: %s [-q (quiet mode)] [-c concurrency] [-m max prime]\n", argv[0]);
                exit(0);
                break;
        }
    }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct options { unsigned int max; int concurrency; int q_set; } *

variable_types: opt char


decompiled_code:
__int64 __fastcall get_sqrt(int a1)
{
double v1; // xmm0_8
__int64 result; // rax

v1 = (double)a1;
if ( (double)a1 < 0.0 )
result = (unsigned int)(int)sqrt(v1);
else
result = (unsigned int)(int)sqrt(v1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
double v1; // xmm0_8
__int64 result; // rax

v1 = (double)a1;
if ( (double)a1 < 0.0 )
result = (unsigned int)(int)sqrt(v1);
else
result = (unsigned int)(int)sqrt(v1);
return result;
}

original_code:
unsigned int get_sqrt(unsigned int max) {
    return (unsigned int)(sqrt((double)max));
}

variable_types:
max
unsigned int


decompiled_code:
__int64 __fastcall get_sqrt32(int a1)
{
__int64 result; // rax

result = get_sqrt(a1);
if ( (result & 0x1F) != 0 )
result = ((unsigned int)result & 0xFFFFFFE0) + 32;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
__int64 result; // rax

result = func12(a1);
if ( (result & 0x1F) != 0 )
result = ((unsigned int)result & 0xFFFFFFE0) + 32;
return result;
}

original_code:
unsigned int get_sqrt32(unsigned int max) {
    unsigned int sqr;
    sqr = get_sqrt(max);
    if((sqr % 32) == 0) {
        return sqr;
    }
    else {
        return ((sqr/32) + 1) * 32;
    }
}

variable_types:
sqr
unsigned int


decompiled_code:
__int64 __fastcall get_interval(unsigned int a1, int a2)
{
return (((a2 - (unsigned int)get_sqrt32(a2)) / a1) & 0xFFFFFFE0) + 32;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1, int a2)
{
return (((a2 - (unsigned int)func13(a2)) / a1) & 0xFFFFFFE0) + 32;
}

original_code:
unsigned int get_interval(int num_threads, unsigned int max) {
    unsigned int intvl;
    intvl = ((max - get_sqrt32(max))/num_threads);
    intvl = (intvl/32 + 1) * 32;
    return intvl;
}

variable_types:
intvl
unsigned int


decompiled_code:
__int64 __fastcall get_first_multiple_gt(unsigned int a1, unsigned int a2)
{
return a1 * (a2 / a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int a1, unsigned int a2)
{
return a1 * (a2 / a1 + 1);
}

original_code:
unsigned int get_first_multiple_gt(unsigned int factor, unsigned int low) {
    unsigned int i = (low/factor) + 1;
    return i*factor;
}

variable_types:
factor
unsigned int

variable_types:
low
unsigned int

variable_types:
i
unsigned int


decompiled_code:
unsigned __int64 __fastcall get_min(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax

result = a2;
if ( a1 <= a2 )
result = a1;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func16(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax

result = a2;
if ( a1 <= a2 )
result = a1;
return result;
}

original_code:
unsigned long get_min(unsigned long a, unsigned long b) {
    if(a<b)
        return a;
    else
        return b;
}

variable_types:
a
unsigned long

variable_types:
b
unsigned long


decompiled_code:
__int64 __fastcall get_low(unsigned int a1, unsigned int a2, int a3)
{
unsigned int v5; // ebp
unsigned int v6; // eax

if ( !a3 )
return get_sqrt(a2);
v5 = get_sqrt32(a2);
v6 = get_interval(a1, a2);
return get_min(v5 + v6 * (__int64)a3, a2);
}

canonical_decompiled_code:
__int64 __fastcall func17(unsigned int a1, unsigned int a2, int a3)
{
unsigned int v5; // ebp
unsigned int v6; // eax

if ( !a3 )
return func12(a2);
v5 = func13(a2);
v6 = func14(a1, a2);
return func16(v5 + v6 * (__int64)a3, a2);
}

original_code:
unsigned int get_low(int num_threads, unsigned int max, int thread_num) {
    unsigned long intvl, sqr;
    if(thread_num == 0) {
        sqr = get_sqrt(max);
        return sqr;
    }
    else {
        sqr = get_sqrt32(max);
        intvl = get_interval(num_threads, max);
        return get_min((sqr + (thread_num * intvl)), max);
    }
}

canonical_original_code:
unsigned int get_low(int num_threads, unsigned int max, int thread_num) {
    unsigned long intvl; unsigned long sqr;
    if(thread_num == 0) {
        sqr = get_sqrt(max);
        return sqr;
    }
    else {
        sqr = get_sqrt32(max);
        intvl = get_interval(num_threads, max);
        return get_min((sqr + (thread_num * intvl)), max);
    }
}

variable_types:
intvl
unsigned long

variable_types:
sqr
unsigned long


decompiled_code:
unsigned __int64 __fastcall get_high(unsigned int a1, unsigned int a2, int a3)
{
unsigned int v4; // er12
unsigned int v5; // eax

v4 = get_interval(a1, a2);
v5 = get_sqrt32(a2);
return get_min(v5 + v4 * (__int64)(a3 + 1), a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func18(unsigned int a1, unsigned int a2, int a3)
{
unsigned int v4; // er12
unsigned int v5; // eax

v4 = func14(a1, a2);
v5 = func13(a2);
return func16(v5 + v4 * (__int64)(a3 + 1), a2);
}

original_code:
unsigned int get_high(int num_threads, unsigned int max, int thread_num) {
    unsigned long intvl, sqr;
    intvl = get_interval(num_threads, max);
    sqr = get_sqrt32(max);
    return get_min(sqr + ((thread_num+1) * intvl), max);
}

canonical_original_code:
unsigned int get_high(int num_threads, unsigned int max, int thread_num) {
    unsigned long intvl; unsigned long sqr;
    intvl = get_interval(num_threads, max);
    sqr = get_sqrt32(max);
    return get_min(sqr + ((thread_num+1) * intvl), max);
}


decompiled_code:
__int64 __fastcall sieve_multiples(__int64 a1, int a2, unsigned int a3)
{
unsigned int i; // ebx
__int64 result; // rax

for ( i = 2 * a2; a3 >= i; i += a2 )
result = set_bit(a1, i);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, int a2, unsigned int a3)
{
unsigned int i; // ebx
__int64 result; // rax

for ( i = 2 * a2; a3 >= i; i += a2 )
result = func19(a1, i);
return result;
}

original_code:
void sieve_multiples(int * psbl_primes, unsigned int factor, unsigned int max) {
    unsigned int i;
    for(i = (2*factor); i <= max; i += factor) {
        set_bit(psbl_primes, i);
    }
}

canonical_original_code:
void sieve_multiples(int *psbl_primes, unsigned int factor, unsigned int max) {
    unsigned int i;
    for(i = (2*factor); i <= max; i += factor) {
        set_bit(psbl_primes, i);
    }
}


decompiled_code:
__int64 __fastcall sieve_multiples_in_range(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 result; // rax
unsigned __int64 i; // rbx

result = get_first_multiple_gt(a2, a3);
for ( i = (unsigned int)result; i <= a4; i += a2 )
result = set_bit(a1, i);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 result; // rax
unsigned __int64 i; // rbx

result = func15(a2, a3);
for ( i = (unsigned int)result; i <= a4; i += a2 )
result = func19(a1, i);
return result;
}

original_code:
void sieve_multiples_in_range(int * psbl_primes, unsigned int factor, unsigned int low, unsigned int high) {
    unsigned long i;
    for(i = get_first_multiple_gt(factor, low); i <= high; i += factor) {
        set_bit(psbl_primes, i);
    }
}

canonical_original_code:
void sieve_multiples_in_range(int *psbl_primes, unsigned int factor, unsigned int low, unsigned int high) {
    unsigned long i;
    for(i = get_first_multiple_gt(factor, low); i <= high; i += factor) {
        set_bit(psbl_primes, i);
    }
}

variable_types:
high
unsigned int

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall check_bit(__int64 a1, unsigned int a2)
{
return (*(int *)(a1 + 4LL * (a2 >> 5)) >> a2) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, unsigned int a2)
{
return (*(int *)(a1 + 4LL * (a2 >> 5)) >> a2) & 1;
}

original_code:
int check_bit(int * array, unsigned int pos) {
    return ((array[pos/32] & (1 << (pos%32))) != 0);
}

canonical_original_code:
int check_bit(int *array, unsigned int pos) {
    return ((array[pos/32] & (1 << (pos%32))) != 0);
}

variable_types:
array
int *

variable_types:
pos
unsigned int


decompiled_code:
int __fastcall print_primes(__int64 a1, unsigned int a2)
{
unsigned int v2; // er12
unsigned int i; // ebx

if ( a2 )
{
v2 = 0;
for ( i = 1; i <= a2; ++i )
{
if ( !(unsigned int)check_bit(a1, i) )
{
++v2;
printf("%10u", i);
if ( v2 == 10 * (v2 / 0xA) )
putchar(10);
}
}
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func24(__int64 a1, unsigned int a2)
{
unsigned int v2; // er12
unsigned int i; // ebx

if ( a2 )
{
v2 = 0;
for ( i = 1; i <= a2; ++i )
{
if ( !(unsigned int)func23(a1, i) )
{
++v2;
printf("%10u", i);
if ( v2 == 10 * (v2 / 0xA) )
putchar(10);
}
}
}
return putchar(10);
}

original_code:
void print_primes(int * primes, int max) {
    unsigned int i;
    unsigned int cnt = 0;
    for(i=1; i<=max; i++) {
        if(!check_bit(primes, i)) {
            cnt++;
            printf("%10u", i);
            if(cnt % 10 == 0) {
                printf("\n");
            }
        }
    }
    printf("\n");
}

canonical_original_code:
void print_primes(int *primes, int max) {
    unsigned int i;
    unsigned int cnt = 0;
    for(i=1; i<=max; i++) {
        if(!check_bit(primes, i)) {
            cnt++;
            printf("%10u", i);
            if(cnt % 10 == 0) {
                printf("\n");
            }
        }
    }
    printf("\n");
}

variable_types:
primes
int *

variable_types: max int

variable_types:
cnt
unsigned int


decompiled_code:
__int64 __fastcall pre_sieve(__int64 a1, int a2)
{
signed int v2; // er13
double v3; // xmm0_8
double v4; // xmm0_8
unsigned int v5; // ebx
__int64 result; // rax

v2 = get_sqrt(a2);
v3 = (float)v2;
if ( v3 < 0.0 )
v4 = sqrt(v3);
else
v4 = sqrt(v3);
v5 = 0;
do
{
result = check_bit(a1, v5);
if ( !(_DWORD)result )
result = sieve_multiples(a1, v5, v2);
++v5;
}
while ( (int)v4 >= v5 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func25(__int64 a1, int a2)
{
signed int v2; // er13
double v3; // xmm0_8
double v4; // xmm0_8
unsigned int v5; // ebx
__int64 result; // rax

v2 = func12(a2);
v3 = (float)v2;
if ( v3 < 0.0 )
v4 = sqrt(v3);
else
v4 = sqrt(v3);
v5 = 0;
do
{
result = func23(a1, v5);
if ( !(_DWORD)result )
result = func20(a1, v5, v2);
++v5;
}
while ( (int)v4 >= v5 );
return result;
}

original_code:
void pre_sieve(int * psbl_primes, unsigned int max) {
    unsigned int i, sqr, sqr2;
    sqr = get_sqrt(max);
    sqr2 = (unsigned int)(sqrt((float) sqr));
    for(i=0; i<=sqr2; i++) {
        if(!check_bit(psbl_primes, i)) {
            sieve_multiples(psbl_primes, i, sqr);
        }
    }
}

canonical_original_code:
void pre_sieve(int *psbl_primes, unsigned int max) {
    unsigned int i; unsigned int sqr; unsigned int sqr2;
    sqr = get_sqrt(max);
    sqr2 = (unsigned int)(sqrt((float) sqr));
    for(i=0; i<=sqr2; i++) {
        if(!check_bit(psbl_primes, i)) {
            sieve_multiples(psbl_primes, i, sqr);
        }
    }
}

variable_types:
max
unsigned int


decompiled_code:
void __fastcall thread_sieve(void *a1)
{
unsigned int v1; // er13
unsigned int v2; // ebx
__int64 v3; // rbp

v1 = get_sqrt(*((_DWORD *)a1 + 2));
v2 = 0;
do
{
v3 = *(_QWORD *)a1;
if ( !(unsigned int)check_bit(*(_QWORD *)a1, v2) )
sieve_multiples_in_range(v3, v2, *((_DWORD *)a1 + 3), *((_DWORD *)a1 + 4));
++v2;
}
while ( v1 >= v2 );
free(a1);
}

canonical_decompiled_code:
void __fastcall func26(void *a1)
{
unsigned int v1; // er13
unsigned int v2; // ebx
__int64 v3; // rbp

v1 = func12(*((_DWORD *)a1 + 2));
v2 = 0;
do
{
v3 = *(_QWORD *)a1;
if ( !(unsigned int)func23(*(_QWORD *)a1, v2) )
func21(v3, v2, *((_DWORD *)a1 + 3), *((_DWORD *)a1 + 4));
++v2;
}
while ( v1 >= v2 );
free(a1);
}

original_code:
void thread_sieve(struct sieve_args * sa) {
    unsigned int i, sqr;
    sqr = get_sqrt(sa->max);
    for(i=0; i<=sqr; i++) {
        if(!check_bit(sa->psbl_primes, i)) {
            sieve_multiples_in_range(sa->psbl_primes, i, sa->low, sa->high);
        }
    }
    free(sa);
}

canonical_original_code:
void thread_sieve(struct sieve_args *sa) {
    unsigned int i; unsigned int sqr;
    sqr = get_sqrt(sa->max);
    for(i=0; i<=sqr; i++) {
        if(!check_bit(sa->psbl_primes, i)) {
            sieve_multiples_in_range(sa->psbl_primes, i, sa->low, sa->high);
        }
    }
    free(sa);
}

variable_types: struct sieve_args { int *psbl_primes; unsigned int max; unsigned int low; unsigned int high; } *

variable_types:
sqr
unsigned int


original_code:
long nano_diff(struct timespec * begin, struct timespec * end) {
    return (1000000000L * (end->tv_sec - begin->tv_sec) + (end->tv_nsec - begin->tv_nsec));
}

canonical_original_code:
long nano_diff(struct timespec *begin, struct timespec *end) {
    return (1000000000L * (end->tv_sec - begin->tv_sec) + (end->tv_nsec - begin->tv_nsec));
}

variable_types: struct timespec { long tv_sec; long tv_nsec; } *

variable_types:
end
struct timespec *

return_type: long


decompiled_code:
int create_prime_shm()
{
int result; // eax

result = shm_open("prime_shm", 194, 0x180u);
if ( result == -1 )
{
perror("Error creating shared memory object");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax

result = shm_open("prime_shm", 194, 0x180u);
if ( result == -1 )
{
perror("Error creating shared memory object");
exit(1);
}
return result;
}

original_code:
int create_prime_shm(void) {
    int shm_fd;
    if((shm_fd = shm_open("prime_shm", 0100 | 0200 | 02, 0400 | 0200)) == -1) {
        perror("Error creating shared memory object");
        exit(1);
    }
    return shm_fd;
}

canonical_original_code:
int create_prime_shm() {
    int shm_fd;
    if((shm_fd = shm_open("prime_shm", 0100 | 0200 | 02, 0400 | 0200)) == -1) {
        perror("Error creating shared memory object");
        exit(1);
    }
    return shm_fd;
}


decompiled_code:
int open_prime_shm()
{
int result; // eax

result = shm_open("prime_shm", 2, 0x180u);
if ( result == -1 )
{
perror("Error opening shared memory object");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax

result = shm_open("prime_shm", 2, 0x180u);
if ( result == -1 )
{
perror("Error opening shared memory object");
exit(1);
}
return result;
}

original_code:
int open_prime_shm(unsigned int max) {
    int shm_fd;
    if((shm_fd = shm_open("prime_shm", 02, 0400 | 0200)) == -1) {
        perror("Error opening shared memory object");
        exit(1);
    }
    return shm_fd;;
}


decompiled_code:
void *__fastcall map_prime_shm(int fd, unsigned int a2)
{
int v2; // ebx
void *result; // rax

v2 = (a2 >> 3) + 1;
if ( ftruncate(fd, v2) == -1 )
{
perror("Error truncating shared memory object");
exit(1);
}
result = mmap(0LL, v2, 3, 1, fd, 0LL);
if ( result == (void *)-1LL )
{
perror("Error mapping shared memory object");
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(int fd, unsigned int a2)
{
int v2; // ebx
void *result; // rax

v2 = (a2 >> 3) + 1;
if ( ftruncate(fd, v2) == -1 )
{
perror("Error truncating shared memory object");
exit(1);
}
result = mmap(0LL, v2, 3, 1, fd, 0LL);
if ( result == (void *)-1LL )
{
perror("Error mapping shared memory object");
exit(1);
}
return result;
}

original_code:
int * map_prime_shm(int shm_fd, unsigned int max) {
    int size;
    int * addr;
    size = (max/8) + 1;
    if(ftruncate(shm_fd, size) == -1) {
        perror("Error truncating shared memory object");
        exit(1);
    }
    if((addr = mmap(((void *)0), size, 0x1 | 0x2, 0x01, shm_fd, 0)) == ((void *) -1)) {
        perror("Error mapping shared memory object");
        exit(1);
    }
    return addr;
}

canonical_original_code:
int *map_prime_shm(int shm_fd, unsigned int max) {
    int size;
    int *addr;
    size = (max/8) + 1;
    if(ftruncate(shm_fd, size) == -1) {
        perror("Error truncating shared memory object");
        exit(1);
    }
    if((addr = mmap(((void *)0), size, 0x1 | 0x2, 0x01, shm_fd, 0)) == ((void *) -1)) {
        perror("Error mapping shared memory object");
        exit(1);
    }
    return addr;
}

variable_types: size int

variable_types:
addr
int *

return_type: int *


decompiled_code:
int __fastcall unmap_prime_shm(void *a1, unsigned int a2)
{
int result; // eax

result = munmap(a1, (int)((a2 >> 3) + 1));
if ( result == -1 )
{
perror("Error unmapping shared memory region");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(void *a1, unsigned int a2)
{
int result; // eax

result = munmap(a1, (int)((a2 >> 3) + 1));
if ( result == -1 )
{
perror("Error unmapping shared memory region");
exit(1);
}
return result;
}

original_code:
void unmap_prime_shm(void * addr, unsigned int max) {
    int size;
    size = (max/8) + 1;
    if(munmap(addr, size) == -1) {
        perror("Error unmapping shared memory region");
        exit(1);
    }
}

canonical_original_code:
void unmap_prime_shm(void *addr, unsigned int max) {
    int size;
    size = (max/8) + 1;
    if(munmap(addr, size) == -1) {
        perror("Error unmapping shared memory region");
        exit(1);
    }
}

variable_types:
addr
void *


decompiled_code:
int unlink_prime_shm()
{
int result; // eax

result = shm_unlink("prime_shm");
if ( result == -1 )
{
perror("Error unlinking shared memory object");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func5()
{
int result; // eax

result = shm_unlink("prime_shm");
if ( result == -1 )
{
perror("Error unlinking shared memory object");
exit(1);
}
return result;
}

original_code:
void unlink_prime_shm(void) {
    if(shm_unlink("prime_shm") == -1) {
        perror("Error unlinking shared memory object");
        exit(1);
    }
}

canonical_original_code:
void unlink_prime_shm() {
    if(shm_unlink("prime_shm") == -1) {
        perror("Error unlinking shared memory object");
        exit(1);
    }
}


decompiled_code:
void __noreturn sigint_handler()
{
unlink_prime_shm();
exit(0);
}

canonical_decompiled_code:
void __noreturn func6()
{
func5();
exit(0);
}

original_code:
void sigint_handler(int sig) {
    unlink_prime_shm();
    exit(0);
}

variable_types: sig int


decompiled_code:
__pid_t __fastcall create_child(int a1, int a2, unsigned int a3)
{
__pid_t result; // eax
_DWORD *v5; // rbp
int v6; // eax

result = fork();
if ( result == -1 )
{
perror("Error forking child process");
exit(1);
}
if ( !result )
{
v5 = malloc(0x18uLL);
v6 = open_prime_shm();
*(_QWORD *)v5 = map_prime_shm(v6, a3);
v5[3] = a1;
v5[4] = a2;
v5[2] = a3;
thread_sieve(v5);
exit(0);
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func7(int a1, int a2, unsigned int a3)
{
__pid_t result; // eax
_DWORD *v5; // rbp
int v6; // eax

result = fork();
if ( result == -1 )
{
perror("Error forking child process");
exit(1);
}
if ( !result )
{
v5 = malloc(0x18uLL);
v6 = func2();
*(_QWORD *)v5 = func3(v6, a3);
v5[3] = a1;
v5[4] = a2;
v5[2] = a3;
thread_sieve(v5);
exit(0);
}
return result;
}

original_code:
pid_t create_child(int low, int high, unsigned int max) {
    int shm_fd;
    pid_t pid;
    struct sieve_args * sa;
    switch (pid = fork()) {
        case -1:
            perror("Error forking child process");
            exit(1);
        case 0:
            sa = malloc(sizeof(struct sieve_args));
            shm_fd = open_prime_shm(max);
            sa->psbl_primes = map_prime_shm(shm_fd, max);
            sa->low = low;
            sa->high = high;
            sa->max = max;
            thread_sieve(sa);
            exit(0);
        default:
            return pid;
    }
}

canonical_original_code:
int create_child(int low, int high, unsigned int max) {
    int shm_fd;
    int pid;
    struct sieve_args *sa;
    switch (pid = fork()) {
        case -1:
            perror("Error forking child process");
            exit(1);
        case 0:
            sa = malloc(sizeof(struct sieve_args));
            shm_fd = open_prime_shm(max);
            sa->psbl_primes = map_prime_shm(shm_fd, max);
            sa->low = low;
            sa->high = high;
            sa->max = max;
            thread_sieve(sa);
            exit(0);
        default:
            return pid;
    }
}

variable_types: low int

variable_types: high int

variable_types: pid int

user_defined_types: struct sieve_args { int *psbl_primes; unsigned int max; unsigned int low; unsigned int high; }


decompiled_code:
void __fastcall wait_on_children(int a1, __pid_t *a2)
{
__pid_t *v2; // rbx

if ( a1 > 0 )
{
v2 = a2;
do
{
if ( waitpid(*v2, 0LL, 0) == -1 )
{
perror("Error waiting for child process");
exit(1);
}
++v2;
}
while ( v2 != &a2[a1 - 1 + 1] );
}
free(a2);
}

canonical_decompiled_code:
void __fastcall func8(int a1, __pid_t *a2)
{
__pid_t *v2; // rbx

if ( a1 > 0 )
{
v2 = a2;
do
{
if ( waitpid(*v2, 0LL, 0) == -1 )
{
perror("Error waiting for child process");
exit(1);
}
++v2;
}
while ( v2 != &a2[a1 - 1 + 1] );
}
free(a2);
}

original_code:
void wait_on_children(int num_procs, pid_t * pids) {
    int i;
    for(i=0; i<num_procs; i++) {
        if(waitpid(pids[i], ((void *)0), 0) == -1) {
            perror("Error waiting for child process");
            exit(1);
        }
    }
    free(pids);
}

canonical_original_code:
void wait_on_children(int num_procs, int *pids) {
    int i;
    for(i=0; i<num_procs; i++) {
        if(waitpid(pids[i], ((void *)0), 0) == -1) {
            perror("Error waiting for child process");
            exit(1);
        }
    }
    free(pids);
}

variable_types:
pids
int *

variable_types: i int


decompiled_code:
int install_sigint_handler()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)sigint_handler;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
return sigaction(2, &v1, 0LL);
}

canonical_decompiled_code:
int func9()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)sigint_handler;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
return sigaction(2, &v1, 0LL);
}

original_code:
void install_sigint_handler(void) {
    struct sigaction sigint;
    sigint.__sigaction_handler.sa_handler = sigint_handler;
    sigemptyset(&sigint.sa_mask);
    sigint.sa_flags = 0;
    sigaction(2, &sigint, ((void *)0));
}

canonical_original_code:
void install_sigint_handler() {
    struct sigaction sigint;
    sigint.__sigaction_handler.sa_handler = sigint_handler;
    sigemptyset(&sigint.sa_mask);
    sigint.sa_flags = 0;
    sigaction(2, &sigint, ((void *)0));
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


repo: NathanJCochran/ftp

decompiled_code:
ssize_t __fastcall send_message(int fd, void *buf)
{
size_t v2; // rbx
ssize_t result; // rax

v2 = (int)strlen((const char *)buf);
result = write(fd, buf, v2);
if ( result != v2 )
{
perror("Error writing message");
close(fd);
exit(1);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(int fd, void *buf)
{
size_t v2; // rbx
ssize_t result; // rax

v2 = (int)strlen((const char *)buf);
result = write(fd, buf, v2);
if ( result != v2 )
{
perror("Error writing message");
close(fd);
exit(1);
}
return result;
}

original_code:
void send_message(int socket_fd, char * message) {
    int length = strlen(message);
    if(write(socket_fd, message, length) != length) {
        perror("Error writing message");
        close(socket_fd);
        exit(1);
    }
}

canonical_original_code:
void send_message(int socket_fd, char *message) {
    int length = strlen(message);
    if(write(socket_fd, message, length) != length) {
        perror("Error writing message");
        close(socket_fd);
        exit(1);
    }
}

variable_types:
message
char *

variable_types: length int


decompiled_code:
int create_socket()
{
int result; // eax

result = socket(2, 1, 0);
if ( result == -1 )
{
perror("Error creating socket");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax

result = socket(2, 1, 0);
if ( result == -1 )
{
perror("Error creating socket");
exit(1);
}
return result;
}

original_code:
int create_socket(void) {
    int socket_fd;
    if((socket_fd = socket(2, SOCK_STREAM, 0)) == -1) {
        perror("Error creating socket");
        exit(1);
    }
    return socket_fd;
}

canonical_original_code:
int create_socket() {
    int socket_fd;
    if((socket_fd = socket(2, SOCK_STREAM, 0)) == -1) {
        perror("Error creating socket");
        exit(1);
    }
    return socket_fd;
}


decompiled_code:
int __fastcall bind_socket(int fd, __int16 a2)
{
int result; // eax
struct sockaddr v3; // [rsp+0h] [rbp-18h] BYREF

v3.sa_family = 2;
*(_DWORD *)&v3.sa_data[2] = 0;
*(_WORD *)v3.sa_data = _bswap_16(a2);
result = bind(fd, &v3, 0x10u);
if ( result == -1 )
{
perror("Error binding socket to address");
close(fd);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(int fd, __int16 a2)
{
int result; // eax
struct sockaddr v3; // [rsp+0h] [rbp-18h] BYREF

v3.sa_family = 2;
*(_DWORD *)&v3.sa_data[2] = 0;
*(_WORD *)v3.sa_data = func0(a2);
result = bind(fd, &v3, 0x10u);
if ( result == -1 )
{
perror("Error binding socket to address");
close(fd);
exit(1);
}
return result;
}

original_code:
void bind_socket(int socket_fd, unsigned short port) {
    struct sockaddr_in address;
    address.sin_family = 2;
    address.sin_addr.s_addr = ((in_addr_t) 0x00000000);
    address.sin_port = htons(port);
    if(bind(socket_fd, (struct sockaddr *) &address, sizeof(address)) == -1) {
        perror("Error binding socket to address");
        close(socket_fd);
        exit(1);
    }
}

canonical_original_code:
void bind_socket(int socket_fd, unsigned short port) {
    struct sockaddr_in address;
    address.sin_family = 2;
    address.sin_addr.s_addr = ((unsigned int) 0x00000000);
    address.sin_port = htons(port);
    if(bind(socket_fd, (struct sockaddr *) &address, sizeof(address)) == -1) {
        perror("Error binding socket to address");
        close(socket_fd);
        exit(1);
    }
}

variable_types:
port
unsigned short

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

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


decompiled_code:
int __fastcall listen_socket(int fd)
{
int result; // eax

result = listen(fd, 5);
if ( result == -1 )
{
perror("Error listening for incoming connections");
close(fd);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(int fd)
{
int result; // eax

result = listen(fd, 5);
if ( result == -1 )
{
perror("Error listening for incoming connections");
close(fd);
exit(1);
}
return result;
}

original_code:
void listen_socket(int socket_fd) {
    if(listen(socket_fd, 5) == -1) {
        perror("Error listening for incoming connections");
        close(socket_fd);
        exit(1);
    }
}


original_code:
int parse_command(char * buffer, char * arg) {
    int command = -1;
    while(*buffer == ' ' || *buffer == '\t') {
        buffer++;
    }
    if(strncmp(buffer, "list ", 5) == 0 ||
        strncmp(buffer, "list\t", 5) == 0 ||
        strncmp(buffer, "list\n", 5) == 0) {
        buffer = buffer + 4;
        command = 1;
    }
    else if(strncmp(buffer, "get ", 4) == 0 ||
            strncmp(buffer, "get\t", 4) == 0 ||
            strncmp(buffer, "get\n", 4) == 0) {
        buffer = buffer + 3;
        command = 2;
    }
    else if(strncmp(buffer, "cd ", 3) == 0 ||
            strncmp(buffer, "cd\t", 3) == 0 ||
            strncmp(buffer, "cd\n", 3) == 0) {
        buffer = buffer + 2;
        command = 3;
    }
    else if(strncmp(buffer, "pwd ", 4) == 0 ||
            strncmp(buffer, "pwd\t", 4) == 0 ||
            strncmp(buffer, "pwd\n", 4) == 0) {
        buffer = buffer + 3;
        command = 4;
    }
    else if(strncmp(buffer, "exit ", 5) == 0 ||
            strncmp(buffer, "exit\t", 5) == 0 ||
            strncmp(buffer, "exit\n", 5) == 0) {
        buffer = buffer + 4;
        command = 0;
    }
    if(arg != ((void *)0)) {
        while(*buffer == ' ' || *buffer == '\t') {
            buffer++;
        }
        while((*buffer != ' ') && (*buffer != '\n') && (*buffer != '\r') && (*buffer != '\0')) {
            *arg = *buffer;
            arg++;
            buffer++;
        }
        *arg = '\0';
    }
    return command;
}

canonical_original_code:
int parse_command(char *buffer, char *arg) {
    int command = -1;
    while(*buffer == ' ' || *buffer == '\t') {
        buffer++;
    }
    if(strncmp(buffer, "list ", 5) == 0 ||
        strncmp(buffer, "list\t", 5) == 0 ||
        strncmp(buffer, "list\n", 5) == 0) {
        buffer = buffer + 4;
        command = 1;
    }
    else if(strncmp(buffer, "get ", 4) == 0 ||
            strncmp(buffer, "get\t", 4) == 0 ||
            strncmp(buffer, "get\n", 4) == 0) {
        buffer = buffer + 3;
        command = 2;
    }
    else if(strncmp(buffer, "cd ", 3) == 0 ||
            strncmp(buffer, "cd\t", 3) == 0 ||
            strncmp(buffer, "cd\n", 3) == 0) {
        buffer = buffer + 2;
        command = 3;
    }
    else if(strncmp(buffer, "pwd ", 4) == 0 ||
            strncmp(buffer, "pwd\t", 4) == 0 ||
            strncmp(buffer, "pwd\n", 4) == 0) {
        buffer = buffer + 3;
        command = 4;
    }
    else if(strncmp(buffer, "exit ", 5) == 0 ||
            strncmp(buffer, "exit\t", 5) == 0 ||
            strncmp(buffer, "exit\n", 5) == 0) {
        buffer = buffer + 4;
        command = 0;
    }
    if(arg != ((void *)0)) {
        while(*buffer == ' ' || *buffer == '\t') {
            buffer++;
        }
        while((*buffer != ' ') && (*buffer != '\n') && (*buffer != '\r') && (*buffer != '\0')) {
            *arg = *buffer;
            arg++;
            buffer++;
        }
        *arg = '\0';
    }
    return command;
}

variable_types:
buffer
char *

variable_types:
arg
char *

variable_types: command int


decompiled_code:
_BOOL8 __fastcall input_yn(const char *a1)
{
bool v2; // zf
_BOOL8 result; // rax
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

printf("%s", a1);
while ( 1 )
{
fgets(v4, 256, stdin);
if ( !memcmp(v4, "yes\n", 4uLL) )
return 1LL;
if ( !memcmp(v4, "yes ", 4uLL) )
return 1LL;
if ( !memcmp(v4, "y\n", 2uLL) )
return 1LL;
if ( !memcmp(v4, "y ", 2uLL) )
break;
v2 = memcmp(v4, "no\n", 3uLL) == 0;
result = !v2;
if ( v2 )
return result;
v2 = memcmp(v4, "no ", 3uLL) == 0;
result = !v2;
if ( v2 )
return result;
v2 = memcmp(v4, "n\n", 2uLL) == 0;
result = !v2;
if ( v2 )
return result;
v2 = memcmp(v4, "n ", 2uLL) == 0;
result = !v2;
if ( v2 )
return result;
puts("Invalid input. Please try again.");
printf("%s", a1);
}
return 1LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(const char *a1)
{
bool v2; // zf
_BOOL8 result; // rax
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

printf("%s", a1);
while ( 1 )
{
fgets(v4, 256, stdin);
if ( !memcmp(v4, "yes\n", 4uLL) )
return 1LL;
if ( !memcmp(v4, "yes ", 4uLL) )
return 1LL;
if ( !memcmp(v4, "y\n", 2uLL) )
return 1LL;
if ( !memcmp(v4, "y ", 2uLL) )
break;
v2 = memcmp(v4, "no\n", 3uLL) == 0;
result = !v2;
if ( v2 )
return result;
v2 = memcmp(v4, "no ", 3uLL) == 0;
result = !v2;
if ( v2 )
return result;
v2 = memcmp(v4, "n\n", 2uLL) == 0;
result = !v2;
if ( v2 )
return result;
v2 = memcmp(v4, "n ", 2uLL) == 0;
result = !v2;
if ( v2 )
return result;
puts("Invalid input. Please try again.");
printf("%s", a1);
}
return 1LL;
}

original_code:
int input_yn(char * prompt) {
    char buf[256];
    printf("%s", prompt);
    while(1) {
        fgets(buf, 256, stdin);
        if(strncmp(buf, "yes\n", 4) == 0 ||
            strncmp(buf, "yes ", 4) == 0 ||
            strncmp(buf, "y\n", 2) == 0 ||
            strncmp(buf, "y ", 2) == 0) {
            return 1;
        }
        if(strncmp(buf, "no\n", 3) == 0 ||
            strncmp(buf, "no ", 3) == 0 ||
             strncmp(buf, "n\n", 2) == 0 ||
             strncmp(buf, "n ", 2) == 0) {
            return 0;
        }
        printf("Invalid input.  Please try again.\n");
        printf("%s", prompt);
    }
    return -1;
}

canonical_original_code:
int input_yn(char *prompt) {
    char buf[256];
    printf("%s", prompt);
    while(1) {
        fgets(buf, 256, stdin);
        if(strncmp(buf, "yes\n", 4) == 0 ||
            strncmp(buf, "yes ", 4) == 0 ||
            strncmp(buf, "y\n", 2) == 0 ||
            strncmp(buf, "y ", 2) == 0) {
            return 1;
        }
        if(strncmp(buf, "no\n", 3) == 0 ||
            strncmp(buf, "no ", 3) == 0 ||
             strncmp(buf, "n\n", 2) == 0 ||
             strncmp(buf, "n ", 2) == 0) {
            return 0;
        }
        printf("Invalid input.  Please try again.\n");
        printf("%s", prompt);
    }
    return -1;
}

variable_types:
prompt
char *

variable_types:
buf
char [256]