decompiled_code:
__int64 __fastcall tloop_TREE_WRAP_AUX(_QWORD *a1, __int64 a2, int a3, int a4, __int64 a5)
{
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-20h] BYREF

*(_DWORD *)(a2 + 40) = 0;
v8 = a2;
*(_QWORD *)(a2 + 8) = &v8;
tloop_TREE_CALL(a1, a3, a4, a5);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
while ( 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), v5);
if ( ++v6 != 1000000000 )
break;
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
if ( v5 != 1 )
goto LABEL_5;
}
}
LABEL_5:
result = v8;
if ( a2 == v8 )
*(_QWORD *)(a2 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, __int64 a2, int a3, int a4, __int64 a5)
{
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-20h] BYREF

*(_DWORD *)(a2 + 40) = 0;
v8 = a2;
*(_QWORD *)(a2 + 8) = &v8;
func3(a1, a3, a4, a5);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
while ( 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), v5);
if ( ++v6 != 1000000000 )
break;
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
if ( v5 != 1 )
goto LABEL_5;
}
}
LABEL_5:
result = v8;
if ( a2 == v8 )
*(_QWORD *)(a2 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
return result;
}

original_code: Task* tloop_TREE_WRAP_AUX(Worker *__self, tloop_TREE_TD *t , int a1, int a2, int* a3){ tloop_TREE_TD *post_eval_task; tloop_TREE_TD *volatile v_t = t; t->info.size = 0; asm volatile( "" ); _wool_save_link( (Task**) &v_t ); tloop_TREE_CALL( __self , a1, a2, a3 ); post_eval_task = (tloop_TREE_TD*) _wool_swap_link( (Task *volatile *) &v_t, (Task *) t ); return (Task *) post_eval_task; }

canonical_original_code: struct _Task *tloop_TREE_WRAP_AUX(struct _Worker *__self, struct _tloop_TREE_TD *t, int a1, int a2, int *a3){ struct _tloop_TREE_TD *post_eval_task; struct _tloop_TREE_TD *v_t = t; t->info.size = 0; asm volatile( "" ); _wool_save_link( (struct _Task **) &v_t ); tloop_TREE_CALL( __self , a1, a2, a3 ); post_eval_task = (struct _tloop_TREE_TD *) _wool_swap_link( (struct _Task **) &v_t, (struct _Task *) t ); return (struct _Task *) post_eval_task; }

variable_types: struct _tloop_TREE_TD { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { ; } d; } *

variable_types: struct _tloop_TREE_TD { struct _wool_dict_t { struct _Task { struct _wool_dict_t *hdr; union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; } join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; } *(*f)(struct _Worker { struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; } info; } *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; } pr; char pad1[-1]; struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } work_available; void *(*fun)(void *); void *fun_arg; } pu; char pad2[-1]; } *, struct _Task *); int size; } *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { ; } d; } *

return_type: struct _Task { struct _wool_dict_t { struct _Task *(*f)(struct _Worker { struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; } join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; } info; } *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; } pr; char pad1[-1]; struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } work_available; void *(*fun)(void *); void *fun_arg; } pu; char pad2[-1]; } *, struct _Task *); int size; } *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; } *

user_defined_types: struct _wool_dict_t { struct _Task *(*f)(struct _Worker *, struct _Task *); int size; }


repo: kffaxen/wool

decompiled_code:
__int64 __fastcall tloop_TREE_WRAP(_QWORD *a1, __int64 a2)
{
return tloop_TREE_WRAP_AUX(a1, a2, *(_DWORD *)(a2 + 32), *(_DWORD *)(a2 + 36), *(_QWORD *)(a2 + 40));
}

original_code: Task* tloop_TREE_WRAP(Worker *__self, tloop_TREE_TD *t) { char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(int*), _wool_max( __alignof__(int), _wool_max( __alignof__(int), 1 ) ) ) ); return tloop_TREE_WRAP_AUX( __self, t , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int* *)( _wool_p + ((((((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int*) - 1) & ~( __alignof__(int*) - 1 )) ) );}

canonical_original_code: struct _Task *tloop_TREE_WRAP(struct _Worker *__self, struct _tloop_TREE_TD *t) { char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(int*), _wool_max( __alignof__(int), _wool_max( __alignof__(int), 1 ) ) ) ); return tloop_TREE_WRAP_AUX( __self, t , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int **)( _wool_p + ((((((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int *) - 1) & ~( __alignof__(int *) - 1 )) ) );}

user_defined_types: struct _tloop_TREE_TD { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { ; } d; }

user_defined_types: struct _Task { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; }

user_defined_types: struct _Worker { struct _Worker_private pr; char pad1[-1]; struct _Worker_public pu; char pad2[-1]; }

user_defined_types: struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; }

user_defined_types: struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t work_available; void *(*fun)(void *); void *fun_arg; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; }

user_defined_types: struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

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


original_code: Task *tloop_TREE_PUB(Worker *self, Task *top, Task *jfp ) { unsigned long ps = self->pr.public_size; int us; grab_res_t res = 0 ? 2 : 1; if( ( us = self->pr.unstolen_stealable, __builtin_expect( (unsigned long) jfp - (unsigned long) top < ps, 1 ) ) && __builtin_expect( ( us > 0 ), 1 ) && (res = _wool_grab_in_sync( self, (top)-1 ), ( self->pr.unstolen_stealable = us-1, __builtin_expect( res != 1, 1 ) ) ) ) { tloop_TREE_TD *t = (tloop_TREE_TD *) --top; char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(int*), _wool_max( __alignof__(int), _wool_max( __alignof__(int), 1 ) ) ) ); self->pr.pr_top = top; ; tloop_TREE_CALL( self , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int* *)( _wool_p + ((((((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int*) - 1) & ~( __alignof__(int*) - 1 )) ) ); return top; } else { top = _wool_slow_sync( self, top, res ); return top; } }

canonical_original_code: struct _Task *tloop_TREE_PUB(struct _Worker *self, struct _Task *top, struct _Task *jfp) { unsigned long ps = self->pr.public_size; int us; int res = 0 ? 2 : 1; if( ( us = self->pr.unstolen_stealable, __builtin_expect( (unsigned long) jfp - (unsigned long) top < ps, 1 ) ) && __builtin_expect( ( us > 0 ), 1 ) && (res = _wool_grab_in_sync( self, (top)-1 ), ( self->pr.unstolen_stealable = us-1, __builtin_expect( res != 1, 1 ) ) ) ) { struct _tloop_TREE_TD *t = (tloop_TREE_TD *) --top; char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(int*), _wool_max( __alignof__(int), _wool_max( __alignof__(int), 1 ) ) ) ); self->pr.pr_top = top; ; tloop_TREE_CALL( self , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int **)( _wool_p + ((((((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int *) - 1) & ~( __alignof__(int *) - 1 )) ) ); return top; } else { top = _wool_slow_sync( self, top, res ); return top; } }

variable_types:
self
struct _Worker *

variable_types:
top
struct _Task *

variable_types:
jfp
struct _Task *

variable_types:
ps
unsigned long

variable_types: us int

variable_types: res int


decompiled_code:
__int64 __fastcall main_CALL(_QWORD *a1, int a2, const char **a3)
{
int v4; // er13
__int64 v5; // r12
void *v6; // rax
void *v7; // rbp
int v8; // ebx
const char *v10; // [rsp+8h] [rbp-40h]

if ( a2 <= 3 )
{
fwrite("Usage: dynamic-loop <model> <reps> <trip> <params...>\n", 1uLL, 0x36uLL, stderr);
exit(1);
}
v10 = a3[1];
v4 = atoi(a3[2]);
v5 = atoi(a3[3]);
v6 = malloc(4 * v5);
v7 = v6;
if ( !strcmp(v10, "flute") )
flute(a2 - 5, a3 + 5, v5, (__int64)v6);
else
fprintf(stderr, "Unknown model: %s\n", v10);
v8 = 0;
if ( v4 > 0 )
{
do
{
tloop_TREE_CALL(a1, 0, v5, (__int64)v7);
++v8;
}
while ( v4 != v8 );
}
free(v7);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, int a2, const char **a3)
{
int v4; // er13
__int64 v5; // r12
void *v6; // rax
void *v7; // rbp
int v8; // ebx
const char *v10; // [rsp+8h] [rbp-40h]

if ( a2 <= 3 )
{
fwrite("Usage: dynamic-loop <model> <reps> <trip> <params...>\n", 1uLL, 0x36uLL, stderr);
exit(1);
}
v10 = a3[1];
v4 = atoi(a3[2]);
v5 = atoi(a3[3]);
v6 = malloc(4 * v5);
v7 = v6;
if ( !strcmp(v10, "flute") )
func2(a2 - 5, a3 + 5, v5, (__int64)v6);
else
fprintf(stderr, "Unknown model: %s\n", v10);
v8 = 0;
if ( v4 > 0 )
{
do
{
func3(a1, 0, v5, (__int64)v7);
++v8;
}
while ( v4 != v8 );
}
free(v7);
return 0LL;
}

original_code: int main_CALL(Worker *_wool_self , int a1, char ** a2) { return main_WRK( _wool_self, 1 , a1, a2 ); }

canonical_original_code: int main_CALL(struct _Worker *_wool_self, int a1, char **a2) { return main_WRK( _wool_self, 1 , a1, a2 ); }

variable_types: struct _Worker { struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task { struct _wool_dict_t { struct _Task *(*f)(struct _Worker *, struct _Task *); int size; } *hdr; union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; } join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; } *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; } info; } *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; } pr; char pad1[-1]; struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } work_available; void *(*fun)(void *); void *fun_arg; } pu; char pad2[-1]; } *

return_type: int


decompiled_code:
__int64 __fastcall main_WRAP_AUX(_QWORD *a1, __int64 a2, int a3, const char **a4)
{
int v4; // er13
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-30h] BYREF

*(_DWORD *)(a2 + 40) = 56;
v8 = a2;
*(_QWORD *)(a2 + 8) = &v8;
v4 = main_CALL(a1, a3, a4);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
while ( 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), v5);
if ( ++v6 != 1000000000 )
break;
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
if ( v5 != 1 )
goto LABEL_5;
}
}
LABEL_5:
result = v8;
if ( a2 == v8 )
*(_QWORD *)(a2 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
*(_DWORD *)(result + 48) = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int64 a2, int a3, const char **a4)
{
int v4; // er13
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-30h] BYREF

*(_DWORD *)(a2 + 40) = 56;
v8 = a2;
*(_QWORD *)(a2 + 8) = &v8;
v4 = func7(a1, a3, a4);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
while ( 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), v5);
if ( ++v6 != 1000000000 )
break;
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
if ( v5 != 1 )
goto LABEL_5;
}
}
LABEL_5:
result = v8;
if ( a2 == v8 )
*(_QWORD *)(a2 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
*(_DWORD *)(result + 48) = v4;
return result;
}

original_code: Task* main_WRAP_AUX(Worker *__self, main_TD *t , int a1, char ** a2){ main_TD *post_eval_task; main_TD *volatile v_t = t; int res; t->info.size = sizeof(main_TD); asm volatile( "" ); _wool_save_link( (Task**) &v_t ); res = main_CALL( __self , a1, a2 ); post_eval_task = (main_TD*) _wool_swap_link( (Task *volatile *) &v_t, (Task *) t ); post_eval_task->d.res = res; return (Task *) post_eval_task; }

canonical_original_code: struct _Task *main_WRAP_AUX(struct _Worker *__self, struct _main_TD *t, int a1, char **a2){ struct _main_TD *post_eval_task; struct _main_TD *v_t = t; int res; t->info.size = sizeof(main_TD); asm volatile( "" ); _wool_save_link( (struct _Task **) &v_t ); res = main_CALL( __self , a1, a2 ); post_eval_task = (struct _main_TD *) _wool_swap_link( (struct _Task **) &v_t, (struct _Task *) t ); post_eval_task->d.res = res; return (struct _Task *) post_eval_task; }

variable_types: struct _main_TD { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { int res; } d; } *

variable_types: struct _main_TD { struct _wool_dict_t { struct _Task { struct _wool_dict_t *hdr; union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; } join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; } *(*f)(struct _Worker { struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; } info; } *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; } pr; char pad1[-1]; struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } work_available; void *(*fun)(void *); void *fun_arg; } pu; char pad2[-1]; } *, struct _Task *); int size; } *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { int res; } d; } *


decompiled_code:
__int64 __fastcall main_WRAP(_QWORD *a1, __int64 a2)
{
return main_WRAP_AUX(a1, a2, *(_DWORD *)(a2 + 32), *(const char ***)(a2 + 40));
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, __int64 a2)
{
return func8(a1, a2, *(_DWORD *)(a2 + 32), *(const char ***)(a2 + 40));
}

original_code: Task* main_WRAP(Worker *__self, main_TD *t) { char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(char **), _wool_max( __alignof__(int), 1 ) ) ); return main_WRAP_AUX( __self, t , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(char ** *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(char **) - 1) & ~( __alignof__(char **) - 1 )) ) );}

canonical_original_code: struct _Task *main_WRAP(struct _Worker *__self, struct _main_TD *t) { char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(char **), _wool_max( __alignof__(int), 1 ) ) ); return main_WRAP_AUX( __self, t , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(char ***)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(char **) - 1) & ~( __alignof__(char **) - 1 )) ) );}

user_defined_types: struct _main_TD { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { int res; } d; }


original_code: Task *main_PUB(Worker *self, Task *top, Task *jfp ) { unsigned long ps = self->pr.public_size; int us; grab_res_t res = 0 ? 2 : 1; if( ( us = self->pr.unstolen_stealable, __builtin_expect( (unsigned long) jfp - (unsigned long) top < ps, 1 ) ) && __builtin_expect( ( us > 0 ), 1 ) && (res = _wool_grab_in_sync( self, (top)-1 ), ( self->pr.unstolen_stealable = us-1, __builtin_expect( res != 1, 1 ) ) ) ) { main_TD *t = (main_TD *) --top; char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(char **), _wool_max( __alignof__(int), 1 ) ) ); self->pr.pr_top = top; ; t->d.res = main_CALL( self , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(char ** *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(char **) - 1) & ~( __alignof__(char **) - 1 )) ) ); return top; } else { top = _wool_slow_sync( self, top, res ); return top; } }

canonical_original_code: struct _Task *main_PUB(struct _Worker *self, struct _Task *top, struct _Task *jfp) { unsigned long ps = self->pr.public_size; int us; int res = 0 ? 2 : 1; if( ( us = self->pr.unstolen_stealable, __builtin_expect( (unsigned long) jfp - (unsigned long) top < ps, 1 ) ) && __builtin_expect( ( us > 0 ), 1 ) && (res = _wool_grab_in_sync( self, (top)-1 ), ( self->pr.unstolen_stealable = us-1, __builtin_expect( res != 1, 1 ) ) ) ) { struct _main_TD *t = (main_TD *) --top; char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(char **), _wool_max( __alignof__(int), 1 ) ) ); self->pr.pr_top = top; ; t->d.res = main_CALL( self , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(char ***)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(char **) - 1) & ~( __alignof__(char **) - 1 )) ) ); return top; } else { top = _wool_slow_sync( self, top, res ); return top; } }


work

original_code:
static int work( int leaf_size, int width )
{
  long int *arr = malloc( sizeof(long int) * width );
  long int sum = 0;
  for( int i = 0; i < width; i++ ) {
    ( fanout_SPAWN_DSP( (Worker *) __self, _wool_in_task , leaf_size, arr+i ) );
    loop(1000);
  }
  for( int i = 0; i < width; i++ ) {
    ( fanout_SYNC_DSP( (Worker *) __self, _wool_in_task ) );
  }
  for( int i = 0; i < width; i++ ) {
    sum += arr[i];
  }
  free(arr);
  return sum;
}

canonical_original_code:
static int work(int leaf_size, int width)
{
  long *arr = malloc( sizeof(long int) * width );
  long sum = 0;
  for( int i = 0; i < width; i++ ) {
    ( fanout_SPAWN_DSP( (struct _Worker *) __self, _wool_in_task , leaf_size, arr+i ) );
    loop(1000);
  }
  for( int i = 0; i < width; i++ ) {
    ( fanout_SYNC_DSP( (struct _Worker *) __self, _wool_in_task ) );
  }
  for( int i = 0; i < width; i++ ) {
    sum += arr[i];
  }
  free(arr);
  return sum;
}

variable_types: width int

variable_types:
arr
long *

variable_types: sum long

variable_types: i int


decompiled_code:
__int64 __fastcall fanout_WRAP_AUX(__int64 a1, __int64 a2, unsigned int a3, _BOOL8 *a4)
{
__int32 v4; // ebx
__int64 v5; // rax
__int64 result; // rax
__int64 v7; // [rsp+8h] [rbp-20h] BYREF

*(_DWORD *)(a2 + 40) = 0;
v7 = a2;
*(_QWORD *)(a2 + 8) = &v7;
fanout_CALL(a1, a3, a4);
v4 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v5 = 1LL;
while ( v4 == 1 )
{
while ( 1 )
{
v4 = _InterlockedExchange((volatile __int32 *)(a2 + 28), v4);
if ( ++v5 != 1000000000 )
break;
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v5 = 0LL;
if ( v4 != 1 )
goto LABEL_5;
}
}
LABEL_5:
result = v7;
if ( a2 == v7 )
*(_QWORD *)(a2 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned int a3, _BOOL8 *a4)
{
__int32 v4; // ebx
__int64 v5; // rax
__int64 result; // rax
__int64 v7; // [rsp+8h] [rbp-20h] BYREF

*(_DWORD *)(a2 + 40) = 0;
v7 = a2;
*(_QWORD *)(a2 + 8) = &v7;
func3(a1, a3, a4);
v4 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v5 = 1LL;
while ( v4 == 1 )
{
while ( 1 )
{
v4 = _InterlockedExchange((volatile __int32 *)(a2 + 28), v4);
if ( ++v5 != 1000000000 )
break;
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v5 = 0LL;
if ( v4 != 1 )
goto LABEL_5;
}
}
LABEL_5:
result = v7;
if ( a2 == v7 )
*(_QWORD *)(a2 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
return result;
}

original_code: Task* fanout_WRAP_AUX(Worker *__self, fanout_TD *t , int a1, long int * a2){ fanout_TD *post_eval_task; fanout_TD *volatile v_t = t; t->info.size = 0; asm volatile( "" ); _wool_save_link( (Task**) &v_t ); fanout_CALL( __self , a1, a2 ); post_eval_task = (fanout_TD*) _wool_swap_link( (Task *volatile *) &v_t, (Task *) t ); return (Task *) post_eval_task; }

canonical_original_code: struct _Task *fanout_WRAP_AUX(struct _Worker *__self, struct _fanout_TD *t, int a1, long *a2){ struct _fanout_TD *post_eval_task; struct _fanout_TD *v_t = t; t->info.size = 0; asm volatile( "" ); _wool_save_link( (struct _Task **) &v_t ); fanout_CALL( __self , a1, a2 ); post_eval_task = (struct _fanout_TD *) _wool_swap_link( (struct _Task **) &v_t, (struct _Task *) t ); return (struct _Task *) post_eval_task; }

variable_types: struct _fanout_TD { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { ; } d; } *

variable_types: struct _fanout_TD { struct _wool_dict_t { struct _Task { struct _wool_dict_t *hdr; union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; } join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; } *(*f)(struct _Worker { struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; } info; } *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; } pr; char pad1[-1]; struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } work_available; void *(*fun)(void *); void *fun_arg; } pu; char pad2[-1]; } *, struct _Task *); int size; } *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { ; } d; } *


decompiled_code:
__int64 __fastcall fanout_WRAP(__int64 a1, __int64 a2)
{
return fanout_WRAP_AUX(a1, a2, *(_DWORD *)(a2 + 32), *(_BOOL8 **)(a2 + 40));
}

original_code: Task* fanout_WRAP(Worker *__self, fanout_TD *t) { char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(long int *), _wool_max( __alignof__(int), 1 ) ) ); return fanout_WRAP_AUX( __self, t , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(long int * *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(long int *) - 1) & ~( __alignof__(long int *) - 1 )) ) );}

canonical_original_code: struct _Task *fanout_WRAP(struct _Worker *__self, struct _fanout_TD *t) { char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(long int *), _wool_max( __alignof__(int), 1 ) ) ); return fanout_WRAP_AUX( __self, t , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(long **)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(long *) - 1) & ~( __alignof__(long *) - 1 )) ) );}

user_defined_types: struct _fanout_TD { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { ; } d; }


original_code: Task *fanout_PUB(Worker *self, Task *top, Task *jfp ) { unsigned long ps = self->pr.public_size; int us; grab_res_t res = 0 ? 2 : 1; if( ( us = self->pr.unstolen_stealable, __builtin_expect( (unsigned long) jfp - (unsigned long) top < ps, 1 ) ) && __builtin_expect( ( us > 0 ), 1 ) && (res = _wool_grab_in_sync( self, (top)-1 ), ( self->pr.unstolen_stealable = us-1, __builtin_expect( res != 1, 1 ) ) ) ) { fanout_TD *t = (fanout_TD *) --top; char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(long int *), _wool_max( __alignof__(int), 1 ) ) ); self->pr.pr_top = top; ; fanout_CALL( self , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(long int * *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(long int *) - 1) & ~( __alignof__(long int *) - 1 )) ) ); return top; } else { top = _wool_slow_sync( self, top, res ); return top; } }

canonical_original_code: struct _Task *fanout_PUB(struct _Worker *self, struct _Task *top, struct _Task *jfp) { unsigned long ps = self->pr.public_size; int us; int res = 0 ? 2 : 1; if( ( us = self->pr.unstolen_stealable, __builtin_expect( (unsigned long) jfp - (unsigned long) top < ps, 1 ) ) && __builtin_expect( ( us > 0 ), 1 ) && (res = _wool_grab_in_sync( self, (top)-1 ), ( self->pr.unstolen_stealable = us-1, __builtin_expect( res != 1, 1 ) ) ) ) { struct _fanout_TD *t = (fanout_TD *) --top; char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(long int *), _wool_max( __alignof__(int), 1 ) ) ); self->pr.pr_top = top; ; fanout_CALL( self , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(long **)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(long *) - 1) & ~( __alignof__(long *) - 1 )) ) ); return top; } else { top = _wool_slow_sync( self, top, res ); return top; } }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er14
int v5; // er12
int v6; // ebx
unsigned int v7; // ebp
int result; // eax

if ( (int)wool_init(argc, argv, envp) <= 3 )
{
fwrite("Usage: fanout [<wool opts>] <grain> <width> <reps>\n", 1uLL, 0x33uLL, stderr);
result = 1;
}
else
{
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
v5 = atoi(argv[3]);
if ( v5 <= 0 )
{
v7 = 0;
}
else
{
v6 = 0;
v7 = 0;
do
{
++v6;
v7 += work(v3, v4);
}
while ( v5 != v6 );
}
printf("Number of leaves = %d\n", v7);
wool_fini();
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er14
int v5; // er12
int v6; // ebx
unsigned int v7; // ebp
int result; // eax

if ( (int)wool_init(argc, argv, envp) <= 3 )
{
fwrite("Usage: fanout [<wool opts>] <grain> <width> <reps>\n", 1uLL, 0x33uLL, stderr);
result = 1;
}
else
{
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
v5 = atoi(argv[3]);
if ( v5 <= 0 )
{
v7 = 0;
}
else
{
v6 = 0;
v7 = 0;
do
{
++v6;
v7 += func7(v3, v4);
}
while ( v5 != v6 );
}
printf("Number of leaves = %d\n", v7);
wool_fini();
result = 0;
}
return result;
}

original_code:
int main( int argc, char **argv )
{
  argc = wool_init( argc, argv );
  if( argc < 4 ) {
    fprintf( stderr, "Usage: fanout [<wool opts>] <grain> <width> <reps>\n" );
    return 1;
  }
  int n = atoi( argv[1] );
  int w = atoi( argv[2] );
  int m = atoi( argv[3] );
  int s = 0;
  for( int i=0; i<m; i++) {
    s += work( n, w );
  }
  printf( "Number of leaves = %d\n", s );
  wool_fini();
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  argc = wool_init( argc, argv );
  if( argc < 4 ) {
    fprintf( stderr, "Usage: fanout [<wool opts>] <grain> <width> <reps>\n" );
    return 1;
  }
  int n = atoi( argv[1] );
  int w = atoi( argv[2] );
  int m = atoi( argv[3] );
  int s = 0;
  for( int i = 0; i<m; i++) {
    s += work( n, w );
  }
  printf( "Number of leaves = %d\n", s );
  wool_fini();
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: n int

variable_types: w int

variable_types: m int

variable_types: s int


decompiled_code:
unsigned __int64 __fastcall work_TREE_CALL(_QWORD *a1, unsigned int a2, int a3, unsigned int a4)
{
unsigned __int64 result; // rax
unsigned int v6; // ebp
int v7; // ebx
unsigned __int64 v8; // rsi
unsigned int v9; // er14
__int64 v10; // rsi
unsigned __int64 v11; // r8

result = (int)(a3 - a2);
v6 = a2;
v7 = a3;
if ( result <= 1 )
{
LABEL_7:
if ( v7 > (int)v6 )
{
do
{
++v6;
result = work_LOOP_constprop_0(a4);
}
while ( v6 != v7 );
}
}
else
{
v8 = a1[62];
while ( 1 )
{
*(_DWORD *)(v8 + 36) = v7;
*(_DWORD *)(v8 + 40) = a4;
v9 = (int)(v6 + v7) / 2;
*(_DWORD *)(v8 + 32) = v9;
if ( v8 >= a1[54] )
{
v10 = wool_slow_spawn(a1, v8, &work_TREE_DICT);
}
else
{
*(_QWORD *)v8 = &work_TREE_DICT;
v10 = v8 + 128;
}
a1[62] = v10;
work_TREE_CALL(a1, v6, v9, a4);
v11 = a1[62];
if ( a1[53] >= v11 )
break;
v7 = *(_DWORD *)(v11 - 92);
v6 = *(_DWORD *)(v11 - 96);
v8 = v11 - 128;
a1[62] = v11 - 128;
a4 = *(_DWORD *)(v11 - 88);
result = (int)(v7 - v6);
if ( result <= 1 )
goto LABEL_7;
}
result = work_TREE_PUB(a1, a1[62]);
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(_QWORD *a1, unsigned int a2, int a3, unsigned int a4)
{
unsigned __int64 result; // rax
unsigned int v6; // ebp
int v7; // ebx
unsigned __int64 v8; // rsi
unsigned int v9; // er14
__int64 v10; // rsi
unsigned __int64 v11; // r8

result = (int)(a3 - a2);
v6 = a2;
v7 = a3;
if ( result <= 1 )
{
LABEL_7:
if ( v7 > (int)v6 )
{
do
{
++v6;
result = func1(a4);
}
while ( v6 != v7 );
}
}
else
{
v8 = a1[62];
while ( 1 )
{
*(_DWORD *)(v8 + 36) = v7;
*(_DWORD *)(v8 + 40) = a4;
v9 = (int)(v6 + v7) / 2;
*(_DWORD *)(v8 + 32) = v9;
if ( v8 >= a1[54] )
{
v10 = wool_slow_spawn(a1, v8, &work_TREE_DICT);
}
else
{
*(_QWORD *)v8 = &work_TREE_DICT;
v10 = v8 + 128;
}
a1[62] = v10;
func2(a1, v6, v9, a4);
v11 = a1[62];
if ( a1[53] >= v11 )
break;
v7 = *(_DWORD *)(v11 - 92);
v6 = *(_DWORD *)(v11 - 96);
v8 = v11 - 128;
a1[62] = v11 - 128;
a4 = *(_DWORD *)(v11 - 88);
result = (int)(v7 - v6);
if ( result <= 1 )
goto LABEL_7;
}
result = func5(a1, a1[62]);
}
return result;
}

original_code: void work_TREE_CALL(Worker *_wool_self , int a1, int a2, int a3){ return work_TREE_WRK( _wool_self, 1 , a1, a2, a3 ); }

canonical_original_code: void work_TREE_CALL(struct _Worker *_wool_self, int a1, int a2, int a3){ return work_TREE_WRK( _wool_self, 1 , a1, a2, a3 ); }

return_type: void


decompiled_code:
__int64 __fastcall work_TREE_WRAP_AUX(_QWORD *a1, __int64 a2, unsigned int a3, int a4, unsigned int a5)
{
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-20h] BYREF

*(_DWORD *)(a2 + 40) = 0;
v8 = a2;
*(_QWORD *)(a2 + 8) = &v8;
work_TREE_CALL(a1, a3, a4, a5);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
while ( 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), v5);
if ( ++v6 != 1000000000 )
break;
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
if ( v5 != 1 )
goto LABEL_5;
}
}
LABEL_5:
result = v8;
if ( a2 == v8 )
*(_QWORD *)(a2 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, __int64 a2, unsigned int a3, int a4, unsigned int a5)
{
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-20h] BYREF

*(_DWORD *)(a2 + 40) = 0;
v8 = a2;
*(_QWORD *)(a2 + 8) = &v8;
func2(a1, a3, a4, a5);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
while ( 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), v5);
if ( ++v6 != 1000000000 )
break;
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
if ( v5 != 1 )
goto LABEL_5;
}
}
LABEL_5:
result = v8;
if ( a2 == v8 )
*(_QWORD *)(a2 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
return result;
}

original_code: Task* work_TREE_WRAP_AUX(Worker *__self, work_TREE_TD *t , int a1, int a2, int a3){ work_TREE_TD *post_eval_task; work_TREE_TD *volatile v_t = t; t->info.size = 0; asm volatile( "" ); _wool_save_link( (Task**) &v_t ); work_TREE_CALL( __self , a1, a2, a3 ); post_eval_task = (work_TREE_TD*) _wool_swap_link( (Task *volatile *) &v_t, (Task *) t ); return (Task *) post_eval_task; }

canonical_original_code: struct _Task *work_TREE_WRAP_AUX(struct _Worker *__self, struct _work_TREE_TD *t, int a1, int a2, int a3){ struct _work_TREE_TD *post_eval_task; struct _work_TREE_TD *v_t = t; t->info.size = 0; asm volatile( "" ); _wool_save_link( (struct _Task **) &v_t ); work_TREE_CALL( __self , a1, a2, a3 ); post_eval_task = (struct _work_TREE_TD *) _wool_swap_link( (struct _Task **) &v_t, (struct _Task *) t ); return (struct _Task *) post_eval_task; }

variable_types: struct _work_TREE_TD { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { ; } d; } *

variable_types: struct _work_TREE_TD { struct _wool_dict_t { struct _Task { struct _wool_dict_t *hdr; union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; } join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; } *(*f)(struct _Worker { struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; } info; } *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; } pr; char pad1[-1]; struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } work_available; void *(*fun)(void *); void *fun_arg; } pu; char pad2[-1]; } *, struct _Task *); int size; } *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { ; } d; } *


decompiled_code:
__int64 __fastcall work_TREE_WRAP(_QWORD *a1, __int64 a2)
{
return work_TREE_WRAP_AUX(a1, a2, *(_DWORD *)(a2 + 32), *(_DWORD *)(a2 + 36), *(_DWORD *)(a2 + 40));
}

original_code: Task* work_TREE_WRAP(Worker *__self, work_TREE_TD *t) { char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(int), _wool_max( __alignof__(int), _wool_max( __alignof__(int), 1 ) ) ) ); return work_TREE_WRAP_AUX( __self, t , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + ((((((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ) );}

canonical_original_code: struct _Task *work_TREE_WRAP(struct _Worker *__self, struct _work_TREE_TD *t) { char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(int), _wool_max( __alignof__(int), _wool_max( __alignof__(int), 1 ) ) ) ); return work_TREE_WRAP_AUX( __self, t , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + ((((((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ) );}

user_defined_types: struct _work_TREE_TD { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { ; } d; }


original_code: Task *work_TREE_PUB(Worker *self, Task *top, Task *jfp ) { unsigned long ps = self->pr.public_size; int us; grab_res_t res = 0 ? 2 : 1; if( ( us = self->pr.unstolen_stealable, __builtin_expect( (unsigned long) jfp - (unsigned long) top < ps, 1 ) ) && __builtin_expect( ( us > 0 ), 1 ) && (res = _wool_grab_in_sync( self, (top)-1 ), ( self->pr.unstolen_stealable = us-1, __builtin_expect( res != 1, 1 ) ) ) ) { work_TREE_TD *t = (work_TREE_TD *) --top; char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(int), _wool_max( __alignof__(int), _wool_max( __alignof__(int), 1 ) ) ) ); self->pr.pr_top = top; ; work_TREE_CALL( self , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + ((((((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ) ); return top; } else { top = _wool_slow_sync( self, top, res ); return top; } }

canonical_original_code: struct _Task *work_TREE_PUB(struct _Worker *self, struct _Task *top, struct _Task *jfp) { unsigned long ps = self->pr.public_size; int us; int res = 0 ? 2 : 1; if( ( us = self->pr.unstolen_stealable, __builtin_expect( (unsigned long) jfp - (unsigned long) top < ps, 1 ) ) && __builtin_expect( ( us > 0 ), 1 ) && (res = _wool_grab_in_sync( self, (top)-1 ), ( self->pr.unstolen_stealable = us-1, __builtin_expect( res != 1, 1 ) ) ) ) { struct _work_TREE_TD *t = (work_TREE_TD *) --top; char *_wool_p = _wool_arg_ptr( (Task *) t, _wool_max( __alignof__(int), _wool_max( __alignof__(int), _wool_max( __alignof__(int), 1 ) ) ) ); self->pr.pr_top = top; ; work_TREE_CALL( self , *(int *)( _wool_p + ((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + (((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ), *(int *)( _wool_p + ((((((((0 + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) + sizeof(int)) + __alignof__(int) - 1) & ~( __alignof__(int) - 1 )) ) ); return top; } else { top = _wool_slow_sync( self, top, res ); return top; } }

variable_types:
self
struct _Worker *

variable_types:
top
struct _Task *

variable_types:
jfp
struct _Task *

variable_types:
ps
unsigned long

variable_types: us int

variable_types: res int

user_defined_types: struct _wool_dict_t { struct _Task *(*f)(struct _Worker *, struct _Task *); int size; }


decompiled_code:
__int64 __fastcall main_CALL(_QWORD *a1, __int64 a2, const char **a3)
{
unsigned int v4; // ebp
unsigned int v5; // er14
int v6; // er12
int i; // ebx

v4 = atoi(a3[1]);
v5 = atoi(a3[2]);
v6 = atoi(a3[3]);
if ( v6 > 0 )
{
for ( i = 0; i != v6; ++i )
work_TREE_CALL(a1, 0, v5, v4);
}
printf("%d %d %d\n", v4, v5, (unsigned int)v6);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 a2, const char **a3)
{
unsigned int v4; // ebp
unsigned int v5; // er14
int v6; // er12
int i; // ebx

v4 = atoi(a3[1]);
v5 = atoi(a3[2]);
v6 = atoi(a3[3]);
if ( v6 > 0 )
{
for ( i = 0; i != v6; ++i )
func2(a1, 0, v5, v4);
}
printf("%d %d %d\n", v4, v5, (unsigned int)v6);
return 0LL;
}

variable_types: struct _Worker { struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task { struct _wool_dict_t { struct _Task *(*f)(struct _Worker *, struct _Task *); int size; } *hdr; union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; } join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; } *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; } info; } *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; } pr; char pad1[-1]; struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } work_available; void *(*fun)(void *); void *fun_arg; } pu; char pad2[-1]; } *


decompiled_code:
__int64 __fastcall main_WRAP_AUX(_QWORD *a1, __int64 a2, unsigned int a3, const char **a4)
{
int v4; // er13
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-30h] BYREF

*(_DWORD *)(a2 + 40) = 56;
v8 = a2;
*(_QWORD *)(a2 + 8) = &v8;
v4 = main_CALL(a1, a3, a4);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
while ( 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), v5);
if ( ++v6 != 1000000000 )
break;
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
if ( v5 != 1 )
goto LABEL_5;
}
}
LABEL_5:
result = v8;
if ( a2 == v8 )
*(_QWORD *)(a2 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
*(_DWORD *)(result + 48) = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, __int64 a2, unsigned int a3, const char **a4)
{
int v4; // er13
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-30h] BYREF

*(_DWORD *)(a2 + 40) = 56;
v8 = a2;
*(_QWORD *)(a2 + 8) = &v8;
v4 = func6(a1, a3, a4);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
while ( 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), v5);
if ( ++v6 != 1000000000 )
break;
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
if ( v5 != 1 )
goto LABEL_5;
}
}
LABEL_5:
result = v8;
if ( a2 == v8 )
*(_QWORD *)(a2 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
*(_DWORD *)(result + 48) = v4;
return result;
}

variable_types: struct _main_TD { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { int res; } d; } *

variable_types: struct _main_TD { struct _wool_dict_t { struct _Task { struct _wool_dict_t *hdr; union _wool_join_data_t { struct _Task **back_link; unsigned long long task_index; } join_data; unsigned long ssn; int balarm; int join_lock; char p1[-1]; char d[-1]; char p2[-1]; } *(*f)(struct _Worker { struct _Worker_private { unsigned long long ctr[-1]; unsigned long long time; unsigned long long now; struct _Task *wait_for; struct _Task *join_first_private; struct _Task *spawn_high; struct _Task *join_stack_base; struct _wool__StolenTask { struct _wool_dict_t *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo { struct _wool__StolenTask *next; int size; } info; } *join_stack_top; struct _wool__StolenTask *join_stack_free; unsigned long join_stack_top_idx; unsigned long pool_base_idx; unsigned long public_size; unsigned long private_size; struct _Task *pr_top; struct _Task *dq_base; struct _Task *curr_block_base; struct _Task *block_base[128]; void *storage; void *logptr; unsigned long n_public; unsigned long curr_block_fidx; unsigned long highest_bot; int more_public_wanted; int t_idx; int unstolen_stealable; int idx; int decrement_deferred; int trlf_threshold; int clock; int thread_leader; int more_work; } pr; char pad1[-1]; struct _Worker_public { int is_thief; int flag; unsigned long dq_bot; unsigned long ssn; unsigned long pu_n_public; struct _Task *pu_block_base[128]; unsigned long long pool_base_idx; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *dq_lock; int is_running; int pad0; union pthread_mutex_t the_lock; union pthread_mutex_t work_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } work_available; void *(*fun)(void *); void *fun_arg; } pu; char pad2[-1]; } *, struct _Task *); int size; } *hdr; union _wool_join_data_t join_data; unsigned long ssn; int balarm; int join_lock; struct _wool_StolenTaskInfo info; union { int res; } d; } *


canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int64 a2)
{
return func7(a1, a2, *(_DWORD *)(a2 + 32), *(const char ***)(a2 + 40));
}


fib

original_code:
static long fib( long n )
{
   if( n < 2 ) {
      return n;
   } else {
      long k = fib( n-2 );
      long m = fib( n-1 );
      return m+k;
   }
}

canonical_original_code:
static long fib(long n)
{
   if( n < 2 ) {
      return n;
   } else {
      long k = fib( n-2 );
      long m = fib( n-1 );
      return m+k;
   }
}

variable_types: n long

variable_types: k long

variable_types: m long

return_type: long


main

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

if ( argc <= 1 )
{
fwrite("Usage: seqfib <arg>\n", 1uLL, 0x14uLL, stderr);
exit(2);
}
v3 = atol(argv[1]);
v4 = fib(v3);
printf("%ld\n", v4);
return 0;
}

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

if ( argc <= 1 )
{
fwrite("Usage: seqfib <arg>\n", 1uLL, 0x14uLL, stderr);
exit(2);
}
v3 = atol(argv[1]);
v4 = func7(v3);
printf("%ld\n", v4);
return 0;
}

original_code:
int main( int argc, char **argv )
{
   if( argc < 2 ) {
      fprintf( stderr, "Usage: seqfib <arg>\n" ),
      exit( 2 );
   }
   long n = atol( argv[ 1 ] );
   long m = fib( n );
   printf( "%ld\n", m );
   return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
   if( argc < 2 ) {
      fprintf( stderr, "Usage: seqfib <arg>\n" ),
      exit( 2 );
   }
   long n = atol( argv[ 1 ] );
   long m = fib( n );
   printf( "%ld\n", m );
   return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall main_CALL(_QWORD *a1, int a2, __int64 a3)
{
__int64 v3; // rax
__int64 v4; // rax

if ( a2 <= 1 )
{
fwrite("Usage: fib <woolopt>... <arg>\n", 1uLL, 0x1EuLL, stderr);
exit(2);
}
v3 = atol(*(const char **)(a3 + 8));
v4 = pfib_CALL(a1, v3);
printf("%ld\n", v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, int a2, __int64 a3)
{
__int64 v3; // rax
__int64 v4; // rax

if ( a2 <= 1 )
{
fwrite("Usage: fib <woolopt>... <arg>\n", 1uLL, 0x1EuLL, stderr);
exit(2);
}
v3 = atol(*(const char **)(a3 + 8));
v4 = func3(a1, v3);
printf("%ld\n", v4);
return 0LL;
}


decompiled_code:
__int64 __fastcall main_WRAP_AUX(_QWORD *a1, __int64 a2, int a3, __int64 a4)
{
int v4; // er13
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-30h] BYREF

*(_DWORD *)(a2 + 40) = 56;
v8 = a2;
*(_QWORD *)(a2 + 8) = &v8;
v4 = main_CALL(a1, a3, a4);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
while ( 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), v5);
if ( ++v6 != 1000000000 )
break;
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
if ( v5 != 1 )
goto LABEL_5;
}
}
LABEL_5:
result = v8;
if ( a2 == v8 )
*(_QWORD *)(a2 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
*(_DWORD *)(result + 48) = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, __int64 a2, int a3, __int64 a4)
{
int v4; // er13
__int32 v5; // ebx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-30h] BYREF

*(_DWORD *)(a2 + 40) = 56;
v8 = a2;
*(_QWORD *)(a2 + 8) = &v8;
v4 = func8(a1, a3, a4);
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), 1);
v6 = 1LL;
while ( v5 == 1 )
{
while ( 1 )
{
v5 = _InterlockedExchange((volatile __int32 *)(a2 + 28), v5);
if ( ++v6 != 1000000000 )
break;
fprintf(stderr, "Long wait at %s:%d\n", "../src/wool-common.h", 1063LL);
v6 = 0LL;
if ( v5 != 1 )
goto LABEL_5;
}
}
LABEL_5:
result = v8;
if ( a2 == v8 )
*(_QWORD *)(a2 + 8) = &wool_dummy_task_ptr;
*(_DWORD *)(a2 + 28) = 0;
*(_DWORD *)(result + 48) = v4;
return result;
}


decompiled_code:
__int64 __fastcall main_WRAP(_QWORD *a1, __int64 a2)
{
return main_WRAP_AUX(a1, a2, *(_DWORD *)(a2 + 32), *(_QWORD *)(a2 + 40));
}


repo: kfprimm/craftcore

decompiled_code:
__int64 __fastcall cc_render_2d(int a1, int a2)
{
glDisable(2929LL);
glMatrixMode(5889LL);
glLoadIdentity();
glOrtho(0.0, (double)a1, (double)a2, 0.0, 0.0, 1.0);
glMatrixMode(5888LL);
return glLoadIdentity();
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
glDisable(2929LL);
glMatrixMode(5889LL);
glLoadIdentity();
glOrtho(0.0, (double)a1, (double)a2, 0.0, 0.0, 1.0);
glMatrixMode(5888LL);
return glLoadIdentity();
}

original_code:
void cc_render_2d(int width, int height)
{
 glDisable(0x0B71);
 glMatrixMode(0x1701);
 glLoadIdentity();
 glOrtho(0, width, height, 0, 0, 1);
 glMatrixMode (0x1700);
 glLoadIdentity();
}

variable_types: width int

variable_types: height int


decompiled_code:
__int64 cc_render_3d()
{
glEnable(2929LL);
glEnable(2884LL);
glEnable(3089LL);
glEnableClientState(32884LL);
glEnableClientState(32888LL);
glEnableClientState(32886LL);
glClearDepth(1.0);
glDepthFunc(515LL);
glHint(3152LL, 4354LL);
return glAlphaFunc(518LL, 0.5);
}

canonical_decompiled_code:
__int64 func1()
{
glEnable(2929LL);
glEnable(2884LL);
glEnable(3089LL);
glEnableClientState(32884LL);
glEnableClientState(32888LL);
glEnableClientState(32886LL);
glClearDepth(1.0);
glDepthFunc(515LL);
glHint(3152LL, 4354LL);
return glAlphaFunc(518LL, 0.5);
}

original_code:
void cc_render_3d()
{
 glEnable(0x0B71);
 glEnable(0x0B44);
 glEnable(0x0C11);
 glEnableClientState(0x8074);
 glEnableClientState(0x8078);
 glEnableClientState(0x8076);
 glClearDepth(1.0);
 glDepthFunc(0x0203);
 glHint(0x0C50, 0x1102);
 glAlphaFunc(0x0206,0.5f);
}


decompiled_code:
// attributes: thunk
__int64 cc_startup_render()
{
return glewInit();
}

canonical_decompiled_code:
__int64 func2()
{
return glewInit();
}

original_code:
void cc_startup_render()
{
 glewInit();
}


original_code:
static void normalize2(float v[2])
{
 float s;
 s = sqrt(v[0] * v[0] + v[1] * v[1]);
 v[0] = v[0] / s;
 v[1] = v[1] / s;
}

variable_types:
v
float [2]

variable_types: s float


decompiled_code:
double __fastcall noise1(double a1)
{
float v1; // xmm0_4
float v2; // xmm0_4
__int64 v3; // rax
float v4; // xmm4_4
float v5; // xmm0_4
float v6; // xmm4_4
float v7; // xmm1_4
float v8; // xmm0_4

v1 = a1;
if ( start )
{
start = 0;
init();
}
v2 = v1 + 4096.0;
v3 = p[(unsigned __int8)((int)v2 + 1)];
v4 = g1[p[(unsigned __int8)(int)v2]];
v5 = v2 - (float)(int)v2;
v6 = v4 * v5;
v7 = (float)((float)(v5 - 1.0) * g1[v3]) - v6;
v8 = (float)(v5 * v5) * (3.0 - (v5 + v5));
return (float)((float)(v8 * v7) + v6);
}

canonical_decompiled_code:
double __fastcall func3(double a1)
{
float v1; // xmm0_4
float v2; // xmm0_4
__int64 v3; // rax
float v4; // xmm4_4
float v5; // xmm0_4
float v6; // xmm4_4
float v7; // xmm1_4
float v8; // xmm0_4

v1 = a1;
if ( start )
{
start = 0;
func2();
}
v2 = v1 + 4096.0;
v3 = p[(unsigned __int8)((int)v2 + 1)];
v4 = g1[p[(unsigned __int8)(int)v2]];
v5 = v2 - (float)(int)v2;
v6 = v4 * v5;
v7 = (float)((float)(v5 - 1.0) * g1[v3]) - v6;
v8 = (float)(v5 * v5) * (3.0 - (v5 + v5));
return (float)((float)(v8 * v7) + v6);
}

original_code:
double noise1(double arg)
{
 int bx0, bx1;
 float rx0, rx1, sx, t, u, v, vec[1];
 vec[0] = arg;
 if (start) {
  start = 0;
  init();
 }
 t = vec[0] + 0x1000; bx0 = ((int)t) & 0xff; bx1 = (bx0+1) & 0xff; rx0 = t - (int)t; rx1 = rx0 - 1.;;
 sx = ( rx0 * rx0 * (3. - 2. * rx0) );
 u = rx0 * g1[ p[ bx0 ] ];
 v = rx1 * g1[ p[ bx1 ] ];
 return ( u + sx * (v - u) );
}

canonical_original_code:
double noise1(double arg)
{
 int bx0; int bx1;
 float rx0; float rx1; float sx; float t; float u; float v; float vec[1];
 vec[0] = arg;
 if (start) {
  start = 0;
  init();
 }
 t = vec[0] + 0x1000; bx0 = ((int)t) & 0xff; bx1 = (bx0+1) & 0xff; rx0 = t - (int)t; rx1 = rx0 - 1.;;
 sx = ( rx0 * rx0 * (3. - 2. * rx0) );
 u = rx0 * g1[ p[ bx0 ] ];
 v = rx1 * g1[ p[ bx1 ] ];
 return ( u + sx * (v - u) );
}

variable_types: arg double

variable_types: sx float

variable_types: t float

variable_types: u float

variable_types: v float

variable_types:
vec
float [1]

return_type: double


canonical_original_code:
float noise2(float vec[2])
{
 int bx0; int bx1; int by0; int by1; int b00; int b10; int b01; int b11;
 float rx0; float rx1; float ry0; float ry1; float *q; float sx; float sy; float a; float b; float t; float u; float v;
 register int i; register int j;
 if (start) {
  start = 0;
  init();
 }
 t = vec[0] + 0x1000; bx0 = ((int)t) & 0xff; bx1 = (bx0+1) & 0xff; rx0 = t - (int)t; rx1 = rx0 - 1.;;
 t = vec[1] + 0x1000; by0 = ((int)t) & 0xff; by1 = (by0+1) & 0xff; ry0 = t - (int)t; ry1 = ry0 - 1.;;
 i = p[ bx0 ];
 j = p[ bx1 ];
 b00 = p[ i + by0 ];
 b10 = p[ j + by0 ];
 b01 = p[ i + by1 ];
 b11 = p[ j + by1 ];
 sx = ( rx0 * rx0 * (3. - 2. * rx0) );
 sy = ( ry0 * ry0 * (3. - 2. * ry0) );
 q = g2[ b00 ] ; u = ( rx0 * q[0] + ry0 * q[1] );
 q = g2[ b10 ] ; v = ( rx1 * q[0] + ry0 * q[1] );
 a = ( u + sx * (v - u) );
 q = g2[ b01 ] ; u = ( rx0 * q[0] + ry1 * q[1] );
 q = g2[ b11 ] ; v = ( rx1 * q[0] + ry1 * q[1] );
 b = ( u + sx * (v - u) );
 return ( a + sy * (b - a) );
}

variable_types:
vec
float [2]

variable_types:
q
float *

variable_types: sy float

variable_types: a float

variable_types: b float

variable_types: i int

variable_types: j int

return_type: float


variable_types:
vec
float [3]

variable_types: sz float

variable_types: c float

variable_types: d float


SendFileData

decompiled_code:
__int64 __fastcall SendFileData(int fd)
{
int v1; // eax
int v2; // er13
int v3; // eax
int v4; // ebx
int v5; // er15
unsigned int v6; // eax
unsigned int v7; // er14
_BYTE v9[4152]; // [rsp+0h] [rbp-1038h] BYREF

v1 = open(compressedfilename, 0);
if ( v1 < 0 )
{
v7 = -1;
ErrorReport(1008LL);
}
else
{
v2 = v1;
do
{
LABEL_3:
memset(v9, 0, 0x1000uLL);
v3 = read(v2, v9, 0x1000uLL);
v4 = v3;
if ( !v3 )
{
v7 = 0;
close(v2);
return v7;
}
if ( v3 == -1 )
{
v7 = -1;
ErrorReport(1009LL);
close(v2);
return v7;
}
v5 = 0;
}
while ( v3 <= 0 );
while ( 1 )
{
v6 = send(fd, &v9[v5], v4 - v5, 0);
v7 = v6;
if ( v6 == -1 )
break;
v5 += v6;
if ( v5 >= v4 )
goto LABEL_3;
}
ErrorReport(1010LL);
close(v2);
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd)
{
int v1; // eax
int v2; // er13
int v3; // eax
int v4; // ebx
int v5; // er15
unsigned int v6; // eax
unsigned int v7; // er14
_BYTE v9[4152]; // [rsp+0h] [rbp-1038h] BYREF

v1 = open(compressedfilename, 0);
if ( v1 < 0 )
{
v7 = -1;
ErrorReport(1008LL);
}
else
{
v2 = v1;
do
{
LABEL_3:
memset(v9, 0, 0x1000uLL);
v3 = read(v2, v9, 0x1000uLL);
v4 = v3;
if ( !v3 )
{
v7 = 0;
close(v2);
return v7;
}
if ( v3 == -1 )
{
v7 = -1;
ErrorReport(1009LL);
close(v2);
return v7;
}
v5 = 0;
}
while ( v3 <= 0 );
while ( 1 )
{
v6 = send(fd, &v9[v5], v4 - v5, 0);
v7 = v6;
if ( v6 == -1 )
break;
v5 += v6;
if ( v5 >= v4 )
goto LABEL_3;
}
ErrorReport(1010LL);
close(v2);
}
return v7;
}

original_code:
int SendFileData(int socket)
{
 int fd;
 int sendlength = 0;
 int i;
 int filechunklength = 0;
 char buf[4096];
 fd = open(compressedfilename, 00);
 if(fd < 0)
 {
  ErrorReport(1008);
  return -1;
 }
 bzero(buf, 4096);
 filechunklength = read(fd, buf, 4096);
 while(filechunklength)
    {
        if(-1 == filechunklength)
        {
            ErrorReport(1009);
   close(fd);
   return -1;
        }
        for(i = 0; i < filechunklength; i += sendlength)
        {
            sendlength = send(socket, buf + i, filechunklength - i, 0);
         if(-1 == sendlength)
         {
             ErrorReport(1010);
    close(fd);
    return -1;
         }
        }
  bzero(buf, 4096);
     filechunklength = read(fd, buf, 4096);
    }
    close(fd);
   return 0;
}

variable_types: socket int

variable_types: fd int

variable_types: sendlength int

variable_types: filechunklength int

variable_types:
buf
char [4096]


FileCompress

decompiled_code:
__int64 FileCompress()
{
int v0; // er12
__int64 v1; // r13
unsigned int v2; // eax
__int64 v3; // rdx
unsigned int v4; // eax
unsigned int v5; // er14
_BYTE savedregs[4136]; // [rsp+0h] [rbp+0h] BYREF

v0 = open(originalfilename, 0);
v1 = gzopen(compressedfilename, &unk_7C0);
memset(savedregs, 0, 0x1000uLL);
v2 = read(v0, savedregs, 0x1000uLL);
if ( v2 )
{
if ( v2 == -1 )
{
LABEL_10:
v5 = -1;
ErrorReport(1009LL);
close(v0);
gzclose(v1);
}
else
{
v3 = v2;
while ( 1 )
{
v5 = gzwrite(v1, savedregs, v3);
if ( v5 == -1 )
break;
memset(savedregs, 0, 0x1000uLL);
v4 = read(v0, savedregs, 0x1000uLL);
v3 = v4;
if ( !v4 )
goto LABEL_9;
if ( v4 == -1 )
goto LABEL_10;
}
ErrorReport(1011LL);
close(v0);
gzclose(v1);
}
}
else
{
LABEL_9:
v5 = 0;
close(v0);
gzclose(v1);
}
return v5;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // er12
__int64 v1; // r13
unsigned int v2; // eax
__int64 v3; // rdx
unsigned int v4; // eax
unsigned int v5; // er14
_BYTE savedregs[4136]; // [rsp+0h] [rbp+0h] BYREF

v0 = open(originalfilename, 0);
v1 = gzopen(compressedfilename, &unk_7C0);
memset(savedregs, 0, 0x1000uLL);
v2 = read(v0, savedregs, 0x1000uLL);
if ( v2 )
{
if ( v2 == -1 )
{
LABEL_10:
v5 = -1;
ErrorReport(1009LL);
close(v0);
gzclose(v1);
}
else
{
v3 = v2;
while ( 1 )
{
v5 = gzwrite(v1, savedregs, v3);
if ( v5 == -1 )
break;
memset(savedregs, 0, 0x1000uLL);
v4 = read(v0, savedregs, 0x1000uLL);
v3 = v4;
if ( !v4 )
goto LABEL_9;
if ( v4 == -1 )
goto LABEL_10;
}
ErrorReport(1011LL);
close(v0);
gzclose(v1);
}
}
else
{
LABEL_9:
v5 = 0;
close(v0);
gzclose(v1);
}
return v5;
}

original_code:
int FileCompress(void)
{
 int fd;
 gzFile fc;
 char compressedbuf[4096];
 int compresslength;
 int writelength;
 fd = open(originalfilename, 00);
    fc = gzopen(compressedfilename, "wb");
 bzero(compressedbuf, 4096);
 compresslength = read(fd, compressedbuf, 4096);
 while(compresslength)
    {
        if(-1 == compresslength)
        {
            ErrorReport(1009);
   close(fd);
   gzclose(fc);
   return -1;
        }
        writelength = gzwrite(fc, compressedbuf, compresslength);
        if(-1 == writelength)
        {
            ErrorReport(1011);
   close(fd);
   gzclose(fc);
   return -1;
        }
  bzero(compressedbuf, 4096);
     compresslength = read(fd, compressedbuf, 4096);
    }
    close(fd);
 gzclose(fc);
 return 0;
}

canonical_original_code:
int FileCompress()
{
 int fd;
 struct gzFile_s *fc;
 char compressedbuf[4096];
 int compresslength;
 int writelength;
 fd = open(originalfilename, 00);
    fc = gzopen(compressedfilename, "wb");
 bzero(compressedbuf, 4096);
 compresslength = read(fd, compressedbuf, 4096);
 while(compresslength)
    {
        if(-1 == compresslength)
        {
            ErrorReport(1009);
   close(fd);
   gzclose(fc);
   return -1;
        }
        writelength = gzwrite(fc, compressedbuf, compresslength);
        if(-1 == writelength)
        {
            ErrorReport(1011);
   close(fd);
   gzclose(fc);
   return -1;
        }
  bzero(compressedbuf, 4096);
     compresslength = read(fd, compressedbuf, 4096);
    }
    close(fd);
 gzclose(fc);
 return 0;
}

variable_types: struct gzFile_s { unsigned int have; unsigned char *next; long pos; } *

variable_types:
compressedbuf
char [4096]

variable_types: compresslength int

variable_types: writelength int


GetFileSize

decompiled_code:
__int64 __fastcall GetFileSize(const char *a1)
{
bool v1; // zf
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3) == 0;
result = 0LL;
if ( v1 )
result = LODWORD(v3.st_size);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
bool v1; // zf
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3) == 0;
result = 0LL;
if ( v1 )
result = LODWORD(v3.st_size);
return result;
}

original_code:
int GetFileSize(const char *file_name)
{
       struct stat buf;
       if (stat(file_name, &buf) != 0 )
         return 0;
       return( buf.st_size );
}

canonical_original_code:
int GetFileSize(char *file_name)
{
       struct stat buf;
       if (stat(file_name, &buf) != 0 )
         return 0;
       return( buf.st_size );
}

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

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


ReceiveFileStatus

decompiled_code:
__int64 __fastcall ReceiveFileStatus(int a1)
{
int v1; // eax
unsigned __int64 v2; // rbx
int v3; // eax
int v4; // er12
size_t v5; // rax
int v6; // eax
int v7; // ebx
int v8; // er14
char *v9; // r15
int v10; // ebp
int v11; // eax
__int64 v12; // rax
bool v13; // cf
bool v14; // zf
int v15; // eax
unsigned int v16; // er9
__int64 v18; // rdi
int v19; // edx
unsigned __int64 v20; // rax
int v21; // edx
int v22; // eax
unsigned __int64 v23; // [rsp+8h] [rbp-2060h]
int v24; // [rsp+14h] [rbp-2054h]
int v25; // [rsp+18h] [rbp-2050h]
int v26; // [rsp+1Ch] [rbp-204Ch]
char v27[16]; // [rsp+20h] [rbp-2048h] BYREF
char s[4096]; // [rsp+30h] [rbp-2038h] BYREF
char buf[4152]; // [rsp+1030h] [rbp-1038h] BYREF

v1 = GetFileSize(originalfilename);
v23 = v1;
v2 = v1;
printf("File size = %llu\n", v1);
bitmaplength = (v2 >> 15) + 1;
bitmap_buf = calloc(bitmaplength, 1uLL);
v3 = open(originalfilename, 0);
if ( v3 < 0 )
{
ErrorReport(1008LL);
free(bitmap_buf);
v16 = -1;
}
else
{
v4 = v3;
memset(buf, 0, 0x1000uLL);
recv(a1, buf, 0x1000uLL, 0);
if ( !strcmp(buf, no_file) )
{
puts("Send the whole file...");
if ( (unsigned int)SendFileData(a1) == -1 )
{
free(bitmap_buf);
v16 = -1;
}
else
{
v16 = 1;
}
}
else
{
v25 = atoi(buf);
puts("Send file size....");
sprintf(s, "%llu", v23);
v5 = strlen(s);
if ( (unsigned int)send(a1, s, v5 + 1, 0) == -1 )
{
ErrorReport(1005LL);
free(bitmap_buf);
return (unsigned int)-1;
}
puts("Begin to receive MD5 data....");
memset(buf, 0, 0x1000uLL);
v6 = recv(a1, buf, 0x1000uLL, 0);
v24 = v6;
if ( !v6 )
{
v8 = 0;
v7 = 7;
LABEL_29:
v19 = v25 + 15;
v20 = v23 >> 12;
if ( v25 >= 0 )
v19 = v25;
v21 = (v19 >> 4) + 1;
if ( (int)v20 + 1 >= v21 )
{
v22 = v20 + 2;
do
{
*((_BYTE *)bitmap_buf + v8) |= 1 << v7;
v13 = v7-- == 0;
if ( v13 )
{
++v8;
v7 = 7;
}
++v21;
}
while ( v22 != v21 );
}
puts("Send bitmap information....");
if ( (unsigned int)send(a1, bitmap_buf, bitmaplength, 0) != -1 )
{
close(v4);
return 0;
}
v18 = 1005LL;
goto LABEL_25;
}
if ( v6 != -1 )
{
v7 = 7;
v8 = 0;
v26 = v25;
while ( 1 )
{
v9 = buf;
v10 = 0;
if ( v24 > 15 )
break;
LABEL_15:
v14 = v26 == v24;
v26 -= v24;
memset(buf, 0, 0x1000uLL);
if ( v14 )
{
puts("Receive enough MD5 Data");
goto LABEL_29;
}
v15 = recv(a1, buf, 0x1000uLL, 0);
v24 = v15;
if ( !v15 )
goto LABEL_29;
if ( v15 == -1 )
goto LABEL_18;
}
while ( 1 )
{
v11 = read(v4, s, 0x1000uLL);
if ( v11 == -1 )
break;
MD5(s, v11, v27);
v12 = 0LL;
while ( v27[v12] == v9[v12] )
{
if ( ++v12 == 16 )
goto LABEL_12;
}
*((_BYTE *)bitmap_buf + v8) |= 1 << v7;
LABEL_12:
v13 = v7-- == 0;
if ( v13 )
{
++v8;
v7 = 7;
}
++v10;
v9 += 16;
if ( v10 >= v24 / 16 )
goto LABEL_15;
}
v18 = 1009LL;
LABEL_25:
ErrorReport(v18);
close(v4);
free(bitmap_buf);
return (unsigned int)-1;
}
LABEL_18:
ErrorReport(1004LL);
close(v4);
free(bitmap_buf);
v16 = -1;
}
}
return v16;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // eax
unsigned __int64 v2; // rbx
int v3; // eax
int v4; // er12
size_t v5; // rax
int v6; // eax
int v7; // ebx
int v8; // er14
char *v9; // r15
int v10; // ebp
int v11; // eax
__int64 v12; // rax
bool v13; // cf
bool v14; // zf
int v15; // eax
unsigned int v16; // er9
__int64 v18; // rdi
int v19; // edx
unsigned __int64 v20; // rax
int v21; // edx
int v22; // eax
unsigned __int64 v23; // [rsp+8h] [rbp-2060h]
int v24; // [rsp+14h] [rbp-2054h]
int v25; // [rsp+18h] [rbp-2050h]
int v26; // [rsp+1Ch] [rbp-204Ch]
char v27[16]; // [rsp+20h] [rbp-2048h] BYREF
char s[4096]; // [rsp+30h] [rbp-2038h] BYREF
char buf[4152]; // [rsp+1030h] [rbp-1038h] BYREF

v1 = func2(originalfilename);
v23 = v1;
v2 = v1;
printf("File size = %llu\n", v1);
bitmaplength = (v2 >> 15) + 1;
bitmap_buf = calloc(bitmaplength, 1uLL);
v3 = open(originalfilename, 0);
if ( v3 < 0 )
{
ErrorReport(1008LL);
free(bitmap_buf);
v16 = -1;
}
else
{
v4 = v3;
memset(buf, 0, 0x1000uLL);
recv(a1, buf, 0x1000uLL, 0);
if ( !strcmp(buf, no_file) )
{
puts("Send the whole file...");
if ( (unsigned int)func0(a1) == -1 )
{
free(bitmap_buf);
v16 = -1;
}
else
{
v16 = 1;
}
}
else
{
v25 = atoi(buf);
puts("Send file size....");
sprintf(s, "%llu", v23);
v5 = strlen(s);
if ( (unsigned int)send(a1, s, v5 + 1, 0) == -1 )
{
ErrorReport(1005LL);
free(bitmap_buf);
return (unsigned int)-1;
}
puts("Begin to receive MD5 data....");
memset(buf, 0, 0x1000uLL);
v6 = recv(a1, buf, 0x1000uLL, 0);
v24 = v6;
if ( !v6 )
{
v8 = 0;
v7 = 7;
LABEL_29:
v19 = v25 + 15;
v20 = v23 >> 12;
if ( v25 >= 0 )
v19 = v25;
v21 = (v19 >> 4) + 1;
if ( (int)v20 + 1 >= v21 )
{
v22 = v20 + 2;
do
{
*((_BYTE *)bitmap_buf + v8) |= 1 << v7;
v13 = v7-- == 0;
if ( v13 )
{
++v8;
v7 = 7;
}
++v21;
}
while ( v22 != v21 );
}
puts("Send bitmap information....");
if ( (unsigned int)send(a1, bitmap_buf, bitmaplength, 0) != -1 )
{
close(v4);
return 0;
}
v18 = 1005LL;
goto LABEL_25;
}
if ( v6 != -1 )
{
v7 = 7;
v8 = 0;
v26 = v25;
while ( 1 )
{
v9 = buf;
v10 = 0;
if ( v24 > 15 )
break;
LABEL_15:
v14 = v26 == v24;
v26 -= v24;
memset(buf, 0, 0x1000uLL);
if ( v14 )
{
puts("Receive enough MD5 Data");
goto LABEL_29;
}
v15 = recv(a1, buf, 0x1000uLL, 0);
v24 = v15;
if ( !v15 )
goto LABEL_29;
if ( v15 == -1 )
goto LABEL_18;
}
while ( 1 )
{
v11 = read(v4, s, 0x1000uLL);
if ( v11 == -1 )
break;
MD5(s, v11, v27);
v12 = 0LL;
while ( v27[v12] == v9[v12] )
{
if ( ++v12 == 16 )
goto LABEL_12;
}
*((_BYTE *)bitmap_buf + v8) |= 1 << v7;
LABEL_12:
v13 = v7-- == 0;
if ( v13 )
{
++v8;
v7 = 7;
}
++v10;
v9 += 16;
if ( v10 >= v24 / 16 )
goto LABEL_15;
}
v18 = 1009LL;
LABEL_25:
ErrorReport(v18);
close(v4);
free(bitmap_buf);
return (unsigned int)-1;
}
LABEL_18:
ErrorReport(1004LL);
close(v4);
free(bitmap_buf);
v16 = -1;
}
}
return v16;
}

original_code:
int ReceiveFileStatus(int socket)
{
 int fd;
 int i,j;
 int readlength, recvlength, sendlength;
 char buf[4096];
 char recvbuf[4096];
 unsigned long long file_size;
 char md5buf[16];
 int bitmapindex = 0;
 int bitindex = 7;
 int result;
 int clientmd5length, restmd5length;
 int serverchunknum;
 file_size = GetFileSize(originalfilename);
 printf("File size = %llu\n", file_size);
 serverchunknum = (file_size / 4096) + 1;
 bitmaplength = ((file_size / 4096) / 8) + 1;
 bitmap_buf = malloc(bitmaplength);
 bzero(bitmap_buf, bitmaplength);
 fd = open(originalfilename, 00);
 if(fd < 0)
 {
  ErrorReport(1008);
  free(bitmap_buf);
  return -1;
 }
 bzero(recvbuf, 4096);
 recvlength = recv(socket, recvbuf, 4096, 0);
 if(0== (strcmp(recvbuf, no_file)))
 {
  printf("Send the whole file...\n");
  result = SendFileData(socket);
  if(-1 == result)
  {
   free(bitmap_buf);
   return -1;
  }
  return 1;
 }
 else
 {
  clientmd5length = atoi(recvbuf);
  restmd5length = clientmd5length;
  printf("Send file size....\n");
  sprintf(buf, "%llu", file_size);
  sendlength = send(socket, buf, strlen(buf) + 1, 0);
  if(-1 == sendlength)
  {
   ErrorReport(1005);
   free(bitmap_buf);
   return -1;
  }
  printf("Begin to receive MD5 data....\n");
  bzero(recvbuf, 4096);
  recvlength = recv(socket, recvbuf, 4096, 0);
  while(recvlength)
  {
   if(-1 == recvlength)
   {
    ErrorReport(1004);
    close(fd);
    free(bitmap_buf);
    return -1;
   }
   for( i = 0; i < (recvlength / 16); i++)
   {
    readlength = read(fd, buf, 4096);
    if(-1 == readlength)
    {
     ErrorReport(1009);
     close(fd);
     free(bitmap_buf);
     return -1;
    }
    MD5((unsigned char*)buf, readlength, (unsigned char*)md5buf);
    for(j = 0; j < 16; j++)
    {
     if(md5buf[j] != recvbuf[j + (i * 16)])
     {
      *(bitmap_buf + bitmapindex) |= (0x1<<bitindex);
      break;
     }
    }
    bitindex -= 1;
    if(-1 == bitindex)
    {
     bitindex = 7;
     bitmapindex++;
    }
   }
   bzero(recvbuf, 4096);
   restmd5length -= recvlength;
   if(restmd5length == 0)
   {
    printf("Receive enough MD5 Data\n");
    break;
   }
   recvlength = recv(socket, recvbuf, 4096, 0);
  }
  for(i = ((clientmd5length / 16) + 1); i <= serverchunknum; i++)
  {
   *(bitmap_buf + bitmapindex) |= (0x1<<bitindex);
   bitindex -= 1;
   if(-1 == bitindex)
   {
    bitindex = 7;
    bitmapindex++;
   }
  }
  printf("Send bitmap information....\n");
  sendlength = send(socket, bitmap_buf, bitmaplength, 0);
  if(-1 == sendlength)
  {
   ErrorReport(1005);
   close(fd);
   free(bitmap_buf);
   return -1;
  }
  close(fd);
  return 0;
 }
}

canonical_original_code:
int ReceiveFileStatus(int socket)
{
 int fd;
 int i; int j;
 int readlength; int recvlength; int sendlength;
 char buf[4096];
 char recvbuf[4096];
 unsigned long long file_size;
 char md5buf[16];
 int bitmapindex = 0;
 int bitindex = 7;
 int result;
 int clientmd5length; int restmd5length;
 int serverchunknum;
 file_size = GetFileSize(originalfilename);
 printf("File size = %llu\n", file_size);
 serverchunknum = (file_size / 4096) + 1;
 bitmaplength = ((file_size / 4096) / 8) + 1;
 bitmap_buf = malloc(bitmaplength);
 bzero(bitmap_buf, bitmaplength);
 fd = open(originalfilename, 00);
 if(fd < 0)
 {
  ErrorReport(1008);
  free(bitmap_buf);
  return -1;
 }
 bzero(recvbuf, 4096);
 recvlength = recv(socket, recvbuf, 4096, 0);
 if(0== (strcmp(recvbuf, no_file)))
 {
  printf("Send the whole file...\n");
  result = SendFileData(socket);
  if(-1 == result)
  {
   free(bitmap_buf);
   return -1;
  }
  return 1;
 }
 else
 {
  clientmd5length = atoi(recvbuf);
  restmd5length = clientmd5length;
  printf("Send file size....\n");
  sprintf(buf, "%llu", file_size);
  sendlength = send(socket, buf, strlen(buf) + 1, 0);
  if(-1 == sendlength)
  {
   ErrorReport(1005);
   free(bitmap_buf);
   return -1;
  }
  printf("Begin to receive MD5 data....\n");
  bzero(recvbuf, 4096);
  recvlength = recv(socket, recvbuf, 4096, 0);
  while(recvlength)
  {
   if(-1 == recvlength)
   {
    ErrorReport(1004);
    close(fd);
    free(bitmap_buf);
    return -1;
   }
   for( i = 0; i < (recvlength / 16); i++)
   {
    readlength = read(fd, buf, 4096);
    if(-1 == readlength)
    {
     ErrorReport(1009);
     close(fd);
     free(bitmap_buf);
     return -1;
    }
    MD5((unsigned char *)buf, readlength, (unsigned char *)md5buf);
    for(j = 0; j < 16; j++)
    {
     if(md5buf[j] != recvbuf[j + (i * 16)])
     {
      *(bitmap_buf + bitmapindex) |= (0x1<<bitindex);
      break;
     }
    }
    bitindex -= 1;
    if(-1 == bitindex)
    {
     bitindex = 7;
     bitmapindex++;
    }
   }
   bzero(recvbuf, 4096);
   restmd5length -= recvlength;
   if(restmd5length == 0)
   {
    printf("Receive enough MD5 Data\n");
    break;
   }
   recvlength = recv(socket, recvbuf, 4096, 0);
  }
  for(i = ((clientmd5length / 16) + 1); i <= serverchunknum; i++)
  {
   *(bitmap_buf + bitmapindex) |= (0x1<<bitindex);
   bitindex -= 1;
   if(-1 == bitindex)
   {
    bitindex = 7;
    bitmapindex++;
   }
  }
  printf("Send bitmap information....\n");
  sendlength = send(socket, bitmap_buf, bitmaplength, 0);
  if(-1 == sendlength)
  {
   ErrorReport(1005);
   close(fd);
   free(bitmap_buf);
   return -1;
  }
  close(fd);
  return 0;
 }
}

variable_types: readlength int

variable_types: recvlength int

variable_types:
recvbuf
char [4096]

variable_types: bitmapindex int

variable_types: bitindex int

variable_types: result int

variable_types: serverchunknum int


SendUpdateData

decompiled_code:
__int64 __fastcall SendUpdateData(int fd)
{
int v2; // eax
int v3; // ebp
unsigned __int8 *v4; // rdi
__int64 v5; // r14
unsigned int v6; // ebx
int v7; // er13
int v8; // eax
signed int v9; // eax
unsigned int v10; // er15
__int64 v11; // rdi
_BYTE v13[4152]; // [rsp+0h] [rbp-1038h] BYREF

v2 = open(originalfilename, 0);
if ( v2 < 0 )
{
v10 = -1;
ErrorReport(1008LL);
free(bitmap_buf);
return v10;
}
v3 = v2;
puts("Send update data....");
v4 = (unsigned __int8 *)bitmap_buf;
if ( bitmaplength <= 0 )
goto LABEL_11;
v5 = 0LL;
while ( 2 )
{
v6 = 7;
v7 = (_DWORD)v5 << 15;
do
{
while ( 1 )
{
v8 = v4[v5];
if ( _bittest(&v8, v6) )
break;
--v6;
v7 += 4096;
if ( v6 == -1 )
goto LABEL_10;
}
lseek(v3, v7, 0);
v9 = read(v3, v13, 0x1000uLL);
v10 = v9;
if ( v9 == -1 )
{
v11 = 1009LL;
LABEL_13:
ErrorReport(v11);
close(v3);
free(bitmap_buf);
return v10;
}
v10 = send(fd, v13, v9, 0);
if ( v10 == -1 )
{
v11 = 1005LL;
goto LABEL_13;
}
--v6;
v4 = (unsigned __int8 *)bitmap_buf;
v7 += 4096;
}
while ( v6 != -1 );
LABEL_10:
if ( bitmaplength > (int)++v5 )
continue;
break;
}
LABEL_11:
free(v4);
v10 = 0;
close(v3);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd)
{
int v2; // eax
int v3; // ebp
unsigned __int8 *v4; // rdi
__int64 v5; // r14
unsigned int v6; // ebx
int v7; // er13
int v8; // eax
signed int v9; // eax
unsigned int v10; // er15
__int64 v11; // rdi
_BYTE v13[4152]; // [rsp+0h] [rbp-1038h] BYREF

v2 = open(originalfilename, 0);
if ( v2 < 0 )
{
v10 = -1;
ErrorReport(1008LL);
free(bitmap_buf);
return v10;
}
v3 = v2;
puts("Send update data....");
v4 = (unsigned __int8 *)bitmap_buf;
if ( bitmaplength <= 0 )
goto LABEL_11;
v5 = 0LL;
while ( 2 )
{
v6 = 7;
v7 = (_DWORD)v5 << 15;
do
{
while ( 1 )
{
v8 = v4[v5];
if ( _bittest(&v8, v6) )
break;
--v6;
v7 += 4096;
if ( v6 == -1 )
goto LABEL_10;
}
lseek(v3, v7, 0);
v9 = read(v3, v13, 0x1000uLL);
v10 = v9;
if ( v9 == -1 )
{
v11 = 1009LL;
LABEL_13:
ErrorReport(v11);
close(v3);
free(bitmap_buf);
return v10;
}
v10 = send(fd, v13, v9, 0);
if ( v10 == -1 )
{
v11 = 1005LL;
goto LABEL_13;
}
--v6;
v4 = (unsigned __int8 *)bitmap_buf;
v7 += 4096;
}
while ( v6 != -1 );
LABEL_10:
if ( bitmaplength > (int)++v5 )
continue;
break;
}
LABEL_11:
free(v4);
v10 = 0;
close(v3);
return v10;
}

original_code:
int SendUpdateData(int socket)
{
 int fd;
 int i,j;
 int readlength, sendlength;
 char buf[4096];
 char updatestatus = 0;
 fd = open(originalfilename, 00);
 if(fd < 0)
 {
  ErrorReport(1008);
  free(bitmap_buf);
  return -1;
 }
 printf("Send update data....\n");
 for(i = 0; i < bitmaplength; i++)
 {
  for(j = 7; j >= 0; j--)
  {
   updatestatus = (*(bitmap_buf + i)>>j) & 0x1;
   if(updatestatus == 1)
   {
    lseek(fd, ((i * 8) + (7 - j))* 4096, 0);
    readlength = read(fd, buf, 4096);
    if(-1 == readlength)
    {
     ErrorReport(1009);
     close(fd);
     free(bitmap_buf);
     return -1;
    }
    sendlength = send(socket, buf, readlength, 0);
    if(-1 == sendlength)
    {
     ErrorReport(1005);
     close(fd);
     free(bitmap_buf);
     return -1;
    }
   }
  }
 }
 free(bitmap_buf);
 close(fd);
 return 0;
}

canonical_original_code:
int SendUpdateData(int socket)
{
 int fd;
 int i; int j;
 int readlength; int sendlength;
 char buf[4096];
 char updatestatus = 0;
 fd = open(originalfilename, 00);
 if(fd < 0)
 {
  ErrorReport(1008);
  free(bitmap_buf);
  return -1;
 }
 printf("Send update data....\n");
 for(i = 0; i < bitmaplength; i++)
 {
  for(j = 7; j >= 0; j--)
  {
   updatestatus = (*(bitmap_buf + i)>>j) & 0x1;
   if(updatestatus == 1)
   {
    lseek(fd, ((i * 8) + (7 - j))* 4096, 0);
    readlength = read(fd, buf, 4096);
    if(-1 == readlength)
    {
     ErrorReport(1009);
     close(fd);
     free(bitmap_buf);
     return -1;
    }
    sendlength = send(socket, buf, readlength, 0);
    if(-1 == sendlength)
    {
     ErrorReport(1005);
     close(fd);
     free(bitmap_buf);
     return -1;
    }
   }
  }
 }
 free(bitmap_buf);
 close(fd);
 return 0;
}

variable_types: socket int

variable_types: i int

variable_types: j int

variable_types: updatestatus char


repo: kgabis/brainfuck-c

decompiled_code:
_BOOL8 execute_bf()
{
__int16 v0; // ax
unsigned int v1; // ebp
int v2; // ebx
__int64 v3; // rdx
_BOOL8 result; // rax
__int16 v5; // [rsp+0h] [rbp-20018h]
char s[131094]; // [rsp+2h] [rbp-20016h] BYREF

memset(s, 0, 0x1FFFCuLL);
v0 = PROGRAM[0];
if ( !PROGRAM[0] )
return 0LL;
v1 = 0;
v2 = 0;
v3 = 0LL;
while ( 2 )
{
switch ( v0 )
{
case 1:
++v1;
goto LABEL_9;
case 2:
--v1;
goto LABEL_9;
case 3:
++*(&v5 + v1);
goto LABEL_9;
case 4:
--*(&v5 + v1);
goto LABEL_9;
case 5:
putchar((unsigned __int16)*(&v5 + v1));
goto LABEL_9;
case 6:
*(&v5 + v1) = getchar();
goto LABEL_9;
case 7:
if ( !*(&v5 + v1) )
v2 = (unsigned __int16)word_4044C2[2 * v3];
goto LABEL_9;
case 8:
if ( *(&v5 + v1) )
v2 = (unsigned __int16)word_4044C2[2 * v3];
LABEL_9:
v3 = (unsigned __int16)++v2;
v0 = PROGRAM[2 * (unsigned __int16)v2];
if ( v1 <= 0xFFFE && v0 )
continue;
result = v1 == 0xFFFF;
break;
default:
return 1LL;
}
return result;
}
}

canonical_decompiled_code:
_BOOL8 func8()
{
__int16 v0; // ax
unsigned int v1; // ebp
int v2; // ebx
__int64 v3; // rdx
_BOOL8 result; // rax
__int16 v5; // [rsp+0h] [rbp-20018h]
char s[131094]; // [rsp+2h] [rbp-20016h] BYREF

memset(s, 0, 0x1FFFCuLL);
v0 = PROGRAM[0];
if ( !PROGRAM[0] )
return 0LL;
v1 = 0;
v2 = 0;
v3 = 0LL;
while ( 2 )
{
switch ( v0 )
{
case 1:
++v1;
goto LABEL_9;
case 2:
--v1;
goto LABEL_9;
case 3:
++*(&v5 + v1);
goto LABEL_9;
case 4:
--*(&v5 + v1);
goto LABEL_9;
case 5:
putchar((unsigned __int16)*(&v5 + v1));
goto LABEL_9;
case 6:
*(&v5 + v1) = getchar();
goto LABEL_9;
case 7:
if ( !*(&v5 + v1) )
v2 = (unsigned __int16)word_4044C2[2 * v3];
goto LABEL_9;
case 8:
if ( *(&v5 + v1) )
v2 = (unsigned __int16)word_4044C2[2 * v3];
LABEL_9:
v3 = (unsigned __int16)++v2;
v0 = PROGRAM[2 * (unsigned __int16)v2];
if ( v1 <= 0xFFFE && v0 )
continue;
result = v1 == 0xFFFF;
break;
default:
return 1LL;
}
return result;
}
}

original_code:
int execute_bf() {
    unsigned short data[65535], pc = 0;
    unsigned int ptr = 65535;
    while (--ptr) { data[ptr] = 0; }
    while (PROGRAM[pc].operator != 0 && ptr < 65535) {
        switch (PROGRAM[pc].operator) {
            case 1: ptr++; break;
            case 2: ptr--; break;
            case 3: data[ptr]++; break;
            case 4: data[ptr]--; break;
            case 5: putchar(data[ptr]); break;
            case 6: data[ptr] = (unsigned int)getchar(); break;
            case 7: if(!data[ptr]) { pc = PROGRAM[pc].operand; } break;
            case 8: if(data[ptr]) { pc = PROGRAM[pc].operand; } break;
            default: return 1;
        }
        pc++;
    }
    return ptr != 65535 ? 0 : 1;
}

canonical_original_code:
int execute_bf() {
    unsigned short data[65535]; unsigned short pc = 0;
    unsigned int ptr = 65535;
    while (--ptr) { data[ptr] = 0; }
    while (PROGRAM[pc].operator != 0 && ptr < 65535) {
        switch (PROGRAM[pc].operator) {
            case 1: ptr++; break;
            case 2: ptr--; break;
            case 3: data[ptr]++; break;
            case 4: data[ptr]--; break;
            case 5: putchar(data[ptr]); break;
            case 6: data[ptr] = (unsigned int)getchar(); break;
            case 7: if(!data[ptr]) { pc = PROGRAM[pc].operand; } break;
            case 8: if(data[ptr]) { pc = PROGRAM[pc].operand; } break;
            default: return 1;
        }
        pc++;
    }
    return ptr != 65535 ? 0 : 1;
}

variable_types:
data
unsigned short [65535]

variable_types:
pc
unsigned short

variable_types:
ptr
unsigned int


main

repo: kgamiel/dxf

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

if ( argc <= 1 )
{
fprintf(stderr, "Usage: %s <dxf_filename>\n", *argv);
exit(1);
}
v3 = argv + 1;
v4 = &argv[(unsigned int)(argc - 2) + 2];
do
{
while ( 1 )
{
v5 = dxf_load(v7, *v3, envp);
if ( !v5 )
break;
++v3;
dxf_print_error(v5, stderr);
if ( v3 == v4 )
return 0;
}
++v3;
dxf_print(v7[0], stdout);
dxf_unload(v7[0]);
}
while ( v3 != v4 );
return 0;
}

original_code:
int main(int argc, char **argv) {
    int i;
    if(argc < 2) {
        fprintf(stderr, "Usage: %s <dxf_filename>\n", argv[0]);
        exit(1);
    }
    for(i = 1;i < argc; i++) {
        dxf_handle_t dxf;
        dxf_error_t err;
        if((err = dxf_load(&dxf, argv[i])) != dxfErrorOk) {
            (void)dxf_print_error(err, stderr);
        } else {
            dxf_print(dxf, stdout);
            dxf_unload(dxf);
        }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    int i;
    if(argc < 2) {
        fprintf(stderr, "Usage: %s <dxf_filename>\n", argv[0]);
        exit(1);
    }
    for(i = 1;i < argc; i++) {
        unsigned int dxf;
        enum dxf_error_t err;
        if((err = dxf_load(&dxf, argv[i])) != dxfErrorOk) {
            (void)dxf_print_error(err, stderr);
        } else {
            dxf_print(dxf, stdout);
            dxf_unload(dxf);
        }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
dxf
unsigned int

variable_types: enum dxf_error_t { dxfErrorOk=0, dxfErrorBadFd=1, dxfErrorInvalidFormat=2, dxfErrorEOF=3, dxfErrorFgets=4, dxfErrorLineTooLong=5, dxfErrorNonASCII=6, dxfErrorDigitExpected=7, dxfErrorInvalidFile=8, dxfErrorOpenFailed=9, dxfErrorCloseFailed=10, dxfErrorSnprintfFailed=11, dxfErrorTooManyOpen=12, dxfErrorInvalidHandle=13, dxfErrorInvalidVariable=14 }


repo: kgamiel/seewaves

decompiled_code:
__int64 __fastcall cfg_open(char *s, char *format, __int64 a3)
{
unsigned __int64 v4; // rdi
__int64 result; // rax
struct stat v7; // [rsp+0h] [rbp-A8h] BYREF

v4 = (unsigned __int64)(s + 8);
*(_QWORD *)(v4 - 8) = 0LL;
*(_QWORD *)(v4 + 4088) = 0LL;
memset((void *)(v4 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * (((unsigned int)s - (v4 & 0xFFFFFFF8) + 4104) >> 3));
snprintf(s, 0x1000uLL, format, "%s");
if ( stat(s, &v7) )
{
perror(s);
result = 1LL;
}
else
{
*((_QWORD *)s + 512) = a3;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s, char *format, __int64 a3)
{
unsigned __int64 v4; // rdi
__int64 result; // rax
struct stat v7; // [rsp+0h] [rbp-A8h] BYREF

v4 = (unsigned __int64)(s + 8);
*(_QWORD *)(v4 - 8) = 0LL;
*(_QWORD *)(v4 + 4088) = 0LL;
memset((void *)(v4 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * (((unsigned int)s - (v4 & 0xFFFFFFF8) + 4104) >> 3));
snprintf(s, 0x1000uLL, format, "%s");
if ( stat(s, &v7) )
{
perror(s);
result = 1LL;
}
else
{
*((_QWORD *)s + 512) = a3;
result = 0LL;
}
return result;
}

original_code:
cfg_error_t cfg_open(cfg_t *cfg, const char *filename, cfg_option_t *options) {
 struct stat status;
 memset(cfg, 0, sizeof(cfg_t));
 snprintf(cfg->filename, 4096, filename, "%s");
 if(stat(cfg->filename, &status)) {
  perror(cfg->filename);
  return (CFG_ERROR);
 }
 cfg->options = options;
 return(CFG_OK);
}

canonical_original_code:
enum cfg_error_t cfg_open(struct cfg_t *cfg, char *filename, struct cfg_option_t *options) {
 struct stat status;
 memset(cfg, 0, sizeof(cfg_t));
 snprintf(cfg->filename, 4096, filename, "%s");
 if(stat(cfg->filename, &status)) {
  perror(cfg->filename);
  return (CFG_ERROR);
 }
 cfg->options = options;
 return(CFG_OK);
}

variable_types: struct cfg_t { char filename[4096]; struct cfg_option_t { char *name; char *description; enum cfg_option_which_t { STRING=0, INTEGER=1, FLOAT=2, FLOAT3=3 } which; union { char sval[512]; int ival; float fval; float f3val[3]; } u; union { char *sval; int ival; float fval; float f3val[3]; } d; } *options; } *

variable_types:
filename
char *

variable_types:
options
struct cfg_option_t *

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

return_type: enum cfg_error_t { CFG_OK=0, CFG_ERROR=1 }

user_defined_types: struct cfg_t { char filename[4096]; struct cfg_option_t *options; }

user_defined_types: struct cfg_option_t { char *name; char *description; enum cfg_option_which_t which; union { char sval[512]; int ival; float fval; float f3val[3]; } u; union { char *sval; int ival; float fval; float f3val[3]; } d; }