decompiled_code:
__int64 test_case_02()
{
__int64 v0; // rbx
__int64 v1; // rax

v0 = sim_heap_start;
heap_start = 0LL;
sim_heap_end = sim_heap_start;
heap_end = 0LL;
v1 = my_malloc(18LL);
CU_assertImplementation(v1 != 0, 56LL, "NULL != p", "malloc-test.c", &unk_BB0, 0LL);
return CU_assertImplementation(
((v0 + 4127) & 0xFFFFFFFFFFFFF000LL) == sim_heap_end,
59LL,
"sim_heap_end == expected_heap_end",
"malloc-test.c",
&unk_BB0,
0LL);
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rbx
__int64 v1; // rax

v0 = sim_heap_start;
heap_start = 0LL;
sim_heap_end = sim_heap_start;
heap_end = 0LL;
v1 = my_malloc(18LL);
CU_assertImplementation(v1 != 0, 56LL, "NULL != p", "malloc-test.c", &unk_BB0, 0LL);
return CU_assertImplementation(
((v0 + 4127) & 0xFFFFFFFFFFFFF000LL) == sim_heap_end,
59LL,
"sim_heap_end == expected_heap_end",
"malloc-test.c",
&unk_BB0,
0LL);
}

original_code:
static void test_case_02(void) {
  unsigned long expected_heap_end = (((sim_heap_start + ((18 + 3) & 0xfffffffc) + 8 + 4) + (~(~((1UL<<12)-1)))) & (~((1UL<<12)-1)));
  void *p = ((void *)0);
  heap_end = heap_start = 0;
  sim_heap_end = sim_heap_start;
  p = my_malloc(18);
  { CU_assertImplementation((((void *)0) != p), 56, "NULL != p", "malloc-test.c", "", 0); };
  ("%s: expected_heap_end = 0x%x\n", __func__, (unsigned int)expected_heap_end);
  { CU_assertImplementation((sim_heap_end == expected_heap_end), 59, "sim_heap_end == expected_heap_end", "malloc-test.c", "", 0); };
}

canonical_original_code:
static void test_case_02() {
  unsigned long expected_heap_end = (((sim_heap_start + ((18 + 3) & 0xfffffffc) + 8 + 4) + (~(~((1UL<<12)-1)))) & (~((1UL<<12)-1)));
  void *p = ((void *)0);
  heap_end = heap_start = 0;
  sim_heap_end = sim_heap_start;
  p = my_malloc(18);
  { CU_assertImplementation((((void *)0) != p), 56, "NULL != p", "malloc-test.c", "", 0); };
  ("%s: expected_heap_end = 0x%x\n", __func__, (unsigned int)expected_heap_end);
  { CU_assertImplementation((sim_heap_end == expected_heap_end), 59, "sim_heap_end == expected_heap_end", "malloc-test.c", "", 0); };
}


decompiled_code:
__int64 test_case_01()
{
__int64 v0; // rbx
__int64 v1; // rax

v0 = sim_heap_start;
heap_start = 0LL;
sim_heap_end = sim_heap_start;
heap_end = 0LL;
v1 = my_malloc(1LL);
CU_assertImplementation(v1 != 0, 44LL, "NULL != p", "malloc-test.c", &unk_BB0, 0LL);
return CU_assertImplementation(
((v0 + 4111) & 0xFFFFFFFFFFFFF000LL) == sim_heap_end,
46LL,
"sim_heap_end == expected_heap_end",
"malloc-test.c",
&unk_BB0,
0LL);
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rbx
__int64 v1; // rax

v0 = sim_heap_start;
heap_start = 0LL;
sim_heap_end = sim_heap_start;
heap_end = 0LL;
v1 = my_malloc(1LL);
CU_assertImplementation(v1 != 0, 44LL, "NULL != p", "malloc-test.c", &unk_BB0, 0LL);
return CU_assertImplementation(
((v0 + 4111) & 0xFFFFFFFFFFFFF000LL) == sim_heap_end,
46LL,
"sim_heap_end == expected_heap_end",
"malloc-test.c",
&unk_BB0,
0LL);
}

original_code:
static void test_case_01(void) {
  unsigned long expected_heap_end = (((sim_heap_start + ((1 + 3) & 0xfffffffc) + 8 + 4) + (~(~((1UL<<12)-1)))) & (~((1UL<<12)-1)));
  void *p = ((void *)0);
  heap_end = heap_start = 0;
  sim_heap_end = sim_heap_start;
  p = my_malloc(1);
  { CU_assertImplementation((((void *)0) != p), 44, "NULL != p", "malloc-test.c", "", 0); };
  ("%s: expected_heap_end = 0x%x\n", __func__, (unsigned int)expected_heap_end);
  { CU_assertImplementation((sim_heap_end == expected_heap_end), 46, "sim_heap_end == expected_heap_end", "malloc-test.c", "", 0); };
}

canonical_original_code:
static void test_case_01() {
  unsigned long expected_heap_end = (((sim_heap_start + ((1 + 3) & 0xfffffffc) + 8 + 4) + (~(~((1UL<<12)-1)))) & (~((1UL<<12)-1)));
  void *p = ((void *)0);
  heap_end = heap_start = 0;
  sim_heap_end = sim_heap_start;
  p = my_malloc(1);
  { CU_assertImplementation((((void *)0) != p), 44, "NULL != p", "malloc-test.c", "", 0); };
  ("%s: expected_heap_end = 0x%x\n", __func__, (unsigned int)expected_heap_end);
  { CU_assertImplementation((sim_heap_end == expected_heap_end), 46, "sim_heap_end == expected_heap_end", "malloc-test.c", "", 0); };
}

variable_types:
p
void *

return_type: void


decompiled_code:
__int64 __fastcall virtual_to_page(__int64 a1)
{
unsigned __int64 v1; // rax

v1 = (unsigned __int64)(a1 - test_page_offset) >> 12;
if ( (v1 & 0x80000000) != 0LL )
{
printk(1LL, 38LL, "invalid virtual address : %x\n", a1);
while ( 1 )
;
}
return pages_map + 48LL * (int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned __int64 v1; // rax

v1 = (unsigned __int64)(a1 - test_page_offset) >> 12;
if ( (v1 & 0x80000000) != 0LL )
{
printk(1LL, 38LL, "invalid virtual address : %x\n", a1);
while ( 1 )
;
}
return pages_map + 48LL * (int)v1;
}

original_code:
struct page* virtual_to_page(void * virtual) {
  int page_index = (int)((unsigned long)(virtual - test_page_offset)/(unsigned long)(1UL<<12));
  struct page* pg = pages_map + page_index;
  if(page_index < 0) {
 printk(0x01, 0x26, "invalid virtual address : %x\n", virtual);
 while(1);
 return 0;
  }
  return pg;
}

canonical_original_code:
struct page *virtual_to_page(void *virtual) {
  int page_index = (int)((unsigned long)(virtual - test_page_offset)/(unsigned long)(1UL<<12));
  struct page *pg = pages_map + page_index;
  if(page_index < 0) {
 printk(0x01, 0x26, "invalid virtual address : %x\n", virtual);
 while(1);
 return 0;
  }
  return pg;
}

variable_types:
virtual
void *

variable_types: struct page { unsigned long virtual; char allocated; char order; struct list_head { struct list_head *next; } manage; struct list_head list; } *

user_defined_types: struct page { unsigned long virtual; char allocated; char order; struct list_head manage; struct list_head list; }


decompiled_code:
__int64 __fastcall page_to_buddy(__int64 a1)
{
return a1 - 48 * ((__int64)(0xAAAAAAAAAAAAAAABLL * ((a1 - free_pages_head) >> 4)) % (1 << *(_BYTE *)(a1 + 9)));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return a1 - 48 * ((__int64)(0xAAAAAAAAAAAAAAABLL * ((a1 - free_pages_head) >> 4)) % (1 << *(_BYTE *)(a1 + 9)));
}

original_code:
struct page* page_to_buddy(struct page *pg) {
  int offset = (pg - free_pages_head)%(1 << pg->order);
  struct page* buddy = pg - offset;
  return buddy;
}

canonical_original_code:
struct page *page_to_buddy(struct page *pg) {
  int offset = (pg - free_pages_head)%(1 << pg->order);
  struct page *buddy = pg - offset;
  return buddy;
}

variable_types:
pg
struct page *

variable_types: offset int

return_type: struct page { unsigned long virtual; char allocated; char order; struct list_head { struct list_head *next; } manage; struct list_head list; } *


getResource

decompiled_code:
__int64 __fastcall getResource(int a1, int a2, _QWORD *a3)
{
__int64 result; // rax
int v5; // edx
__int64 v6; // rax
__int64 v7; // rdx
__int64 v8; // rdx

if ( a1 )
{
result = 0LL;
v5 = 51;
if ( a1 != 1 )
return result;
}
else
{
v5 = 66;
}
v6 = (__int64)*(&resources + a1);
v7 = v6 + 24LL * (unsigned int)(v5 - 1) + 24;
while ( *(_DWORD *)v6 != a2 )
{
v6 += 24LL;
if ( v6 == v7 )
return 0LL;
}
v8 = *(_QWORD *)(v6 + 16);
result = *(_QWORD *)(v6 + 8);
*a3 = v8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2, _QWORD *a3)
{
__int64 result; // rax
int v5; // edx
__int64 v6; // rax
__int64 v7; // rdx
__int64 v8; // rdx

if ( a1 )
{
result = 0LL;
v5 = 51;
if ( a1 != 1 )
return result;
}
else
{
v5 = 66;
}
v6 = (__int64)*(&resources + a1);
v7 = v6 + 24LL * (unsigned int)(v5 - 1) + 24;
while ( *(_DWORD *)v6 != a2 )
{
v6 += 24LL;
if ( v6 == v7 )
return 0LL;
}
v8 = *(_QWORD *)(v6 + 16);
result = *(_QWORD *)(v6 + 8);
*a3 = v8;
return result;
}

original_code:
unsigned char *getResource(int type, int id, unsigned long *len)
{
 int count;
 int found = 0;
 int i;
 if (type == 0) count = 66;
 else if (type == 1) count = 51;
 else return ((void *)0);
 for (i = 0; i < count; i++)
 {
  if (resources[type][i].r_id == id)
  {
   found = 1;
   break;
  }
 }
 if (!found) return ((void *)0);
 *len = resources[type][i].r_len;
 return resources[type][i].r_data;
}

variable_types: type int

variable_types: id int

variable_types:
len
unsigned long *

variable_types: count int

variable_types: found int

variable_types: i int

return_type: unsigned char *


repo: michaelcmartin/monocle

decompiled_code:
void mncl_stop_music()
{
Mix_ExpireChannel(0xFFFFFFFFLL, 0LL);
if ( current_bgm )
{
Mix_HaltMusic();
Mix_FreeMusic(current_bgm);
current_bgm = 0LL;
}
if ( current_bgm_name )
{
free(current_bgm_name);
current_bgm_name = 0LL;
}
if ( current_bgm_raw )
{
mncl_release_raw();
current_bgm_raw = 0LL;
}
}

canonical_decompiled_code:
void func0()
{
Mix_ExpireChannel(0xFFFFFFFFLL, 0LL);
if ( current_bgm )
{
Mix_HaltMusic();
Mix_FreeMusic(current_bgm);
current_bgm = 0LL;
}
if ( current_bgm_name )
{
free(current_bgm_name);
current_bgm_name = 0LL;
}
if ( current_bgm_raw )
{
mncl_release_raw();
current_bgm_raw = 0LL;
}
}

original_code:
void
mncl_stop_music(void)
{
    Mix_ExpireChannel(-1, 0);
    if (current_bgm) {
        Mix_HaltMusic();
        Mix_FreeMusic(current_bgm);
        current_bgm = ((void *)0);
    }
    if (current_bgm_name) {
        free(current_bgm_name);
        current_bgm_name = ((void *)0);
    }
    if (current_bgm_raw) {
        mncl_release_raw(current_bgm_raw);
        current_bgm_raw = ((void *)0);
    }
}

canonical_original_code:
void mncl_stop_music()
{
    Mix_ExpireChannel(-1, 0);
    if (current_bgm) {
        Mix_HaltMusic();
        Mix_FreeMusic(current_bgm);
        current_bgm = ((void *)0);
    }
    if (current_bgm_name) {
        free(current_bgm_name);
        current_bgm_name = ((void *)0);
    }
    if (current_bgm_raw) {
        mncl_release_raw(current_bgm_raw);
        current_bgm_raw = ((void *)0);
    }
}


decompiled_code:
// attributes: thunk
__int64 mncl_fade_out_music()
{
return Mix_FadeOutMusic();
}

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

original_code:
void
mncl_fade_out_music(int ms)
{
    Mix_FadeOutMusic(ms);
}

variable_types: ms int


decompiled_code:
// attributes: thunk
__int64 mncl_music_volume()
{
return Mix_VolumeMusic();
}

canonical_decompiled_code:
__int64 func3()
{
return Mix_VolumeMusic();
}

original_code:
void
mncl_music_volume(int volume)
{
    Mix_VolumeMusic(volume);
}

variable_types: volume int


decompiled_code:
// attributes: thunk
__int64 mncl_pause_music()
{
return Mix_PauseMusic();
}

canonical_decompiled_code:
__int64 func4()
{
return Mix_PauseMusic();
}

original_code:
void
mncl_pause_music(void)
{
    Mix_PauseMusic();
}

canonical_original_code:
void mncl_pause_music()
{
    Mix_PauseMusic();
}


decompiled_code:
// attributes: thunk
__int64 mncl_resume_music()
{
return Mix_ResumeMusic();
}

canonical_decompiled_code:
__int64 func5()
{
return Mix_ResumeMusic();
}

original_code:
void
mncl_resume_music(void)
{
    Mix_ResumeMusic();
}

canonical_original_code:
void mncl_resume_music()
{
    Mix_ResumeMusic();
}


decompiled_code:
void __fastcall mncl_free_sfx(void *ptr)
{
if ( ptr )
{
Mix_FreeChunk(*((_QWORD *)ptr + 1));
mncl_release_raw(*(_QWORD *)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
if ( ptr )
{
Mix_FreeChunk(*((_QWORD *)ptr + 1));
mncl_release_raw(*(_QWORD *)ptr);
free(ptr);
}
}

original_code:
void
mncl_free_sfx(MNCL_SFX *sfx)
{
    if (!sfx) {
        return;
    }
    Mix_FreeChunk(sfx->chunk);
    mncl_release_raw(sfx->raw);
    free(sfx);
}

canonical_original_code:
void mncl_free_sfx(struct struct_MNCL_SFX *sfx)
{
    if (!sfx) {
        return;
    }
    Mix_FreeChunk(sfx->chunk);
    mncl_release_raw(sfx->raw);
    free(sfx);
}

variable_types: struct struct_MNCL_SFX { struct struct_MNCL_RAW { unsigned char *data; unsigned int size; } *raw; struct Mix_Chunk { int allocated; unsigned char *abuf; unsigned int alen; unsigned char volume; } *chunk; } *

user_defined_types: struct struct_MNCL_SFX { struct struct_MNCL_RAW *raw; struct Mix_Chunk *chunk; }


decompiled_code:
void __fastcall mncl_play_sfx(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax

if ( a1 )
{
v2 = Mix_PlayChannelTimed(0xFFFFFFFFLL, *(_QWORD *)(a1 + 8), 0LL, 0xFFFFFFFFLL);
Mix_Volume(v2, a2);
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax

if ( a1 )
{
v2 = Mix_PlayChannelTimed(0xFFFFFFFFLL, *(_QWORD *)(a1 + 8), 0LL, 0xFFFFFFFFLL);
Mix_Volume(v2, a2);
}
}

original_code:
void
mncl_play_sfx(MNCL_SFX *sfx, int volume)
{
    int channel;
    if (!sfx) {
        return;
    }
    channel = Mix_PlayChannelTimed(-1,sfx->chunk,0,-1);
    Mix_Volume(channel, volume);
}

canonical_original_code:
void mncl_play_sfx(struct struct_MNCL_SFX *sfx, int volume)
{
    int channel;
    if (!sfx) {
        return;
    }
    channel = Mix_PlayChannelTimed(-1,sfx->chunk,0,-1);
    Mix_Volume(channel, volume);
}

variable_types: channel int

user_defined_types: struct struct_MNCL_RAW { unsigned char *data; unsigned int size; }

user_defined_types: struct Mix_Chunk { int allocated; unsigned char *abuf; unsigned int alen; unsigned char volume; }


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

if ( a1 )
{
v2 = a1;
do
{
a2(v2);
result = tree_preorder_aux(*(_QWORD *)(v2 + 8), a2);
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
}
return result;
}

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

if ( a1 )
{
v2 = a1;
do
{
a2(v2);
result = func0(*(_QWORD *)(v2 + 8), a2);
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
}
return result;
}

original_code:
static void
tree_preorder_aux(TREE_NODE *n, TREE_VISITOR visitor)
{
    if (!n) {
        return;
    }
    visitor(n);
    tree_preorder_aux(n->left, visitor);
    tree_preorder_aux(n->right, visitor);
}

canonical_original_code:
static void tree_preorder_aux(struct tree_node *n, void (*visitor)(struct tree_node *))
{
    if (!n) {
        return;
    }
    visitor(n);
    tree_preorder_aux(n->left, visitor);
    tree_preorder_aux(n->right, visitor);
}

variable_types: struct tree_node { struct tree_node *parent; char color; } *

variable_types:
visitor
void (*)(struct tree_node *)


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

if ( a1 )
{
tree_postorder_aux(*(_QWORD *)(a1 + 8));
tree_postorder_aux(*(_QWORD *)(a1 + 16));
result = a2(a1);
}
return result;
}

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

if ( a1 )
{
func1(*(_QWORD *)(a1 + 8));
func1(*(_QWORD *)(a1 + 16));
result = a2(a1);
}
return result;
}

original_code:
static void
tree_postorder_aux(TREE_NODE *n, TREE_VISITOR visitor)
{
    if (!n) {
        return;
    }
    tree_postorder_aux(n->left, visitor);
    tree_postorder_aux(n->right, visitor);
    visitor(n);
}

canonical_original_code:
static void tree_postorder_aux(struct tree_node *n, void (*visitor)(struct tree_node *))
{
    if (!n) {
        return;
    }
    tree_postorder_aux(n->left, visitor);
    tree_postorder_aux(n->right, visitor);
    visitor(n);
}

user_defined_types: struct tree_node { struct tree_node *parent; char color; }


decompiled_code:
int __fastcall key_value_node_cmp(__int64 a1, __int64 a2)
{
return strcmp(*(const char **)(a1 + 32), *(const char **)(a2 + 32));
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2)
{
return strcmp(*(const char **)(a1 + 32), *(const char **)(a2 + 32));
}

original_code:
int
key_value_node_cmp(TREE_NODE *a, TREE_NODE *b)
{
    return strcmp(((KEY_VALUE_NODE *)a)->key, ((KEY_VALUE_NODE *)b)->key);
}

canonical_original_code:
int key_value_node_cmp(struct tree_node *a, struct tree_node *b)
{
    return strcmp(((struct KEY_VALUE_NODE *)a)->key, ((struct KEY_VALUE_NODE *)b)->key);
}

variable_types:
b
struct tree_node *

return_type: int

user_defined_types: struct KEY_VALUE_NODE { struct tree_node header; char *key; void *value; char data[]; }


decompiled_code:
char *__fastcall key_value_node_alloc(char *src, __int64 a2)
{
size_t v2; // r13
char *v3; // rax
char *v4; // r12

v2 = (int)(strlen(src) + 1);
v3 = (char *)malloc(v2 + 48);
v4 = v3;
if ( v3 )
{
*((_QWORD *)v3 + 5) = a2;
*((_QWORD *)v3 + 4) = strncpy(v3 + 48, src, v2);
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func3(char *src, __int64 a2)
{
size_t v2; // r13
char *v3; // rax
char *v4; // r12

v2 = (int)(strlen(src) + 1);
v3 = (char *)malloc(v2 + 48);
v4 = v3;
if ( v3 )
{
*((_QWORD *)v3 + 5) = a2;
*((_QWORD *)v3 + 4) = strncpy(v3 + 48, src, v2);
}
return v4;
}

original_code:
KEY_VALUE_NODE *
key_value_node_alloc(const char *key, void *value)
{
    int size = strlen(key)+1;
    KEY_VALUE_NODE *result = (KEY_VALUE_NODE *)malloc(sizeof(KEY_VALUE_NODE) + size);
    if (!result) {
        return ((void *)0);
    }
    result->value = value;
    strncpy(result->data, key, size);
    result->key = &(result->data[0]);
    return result;
}

canonical_original_code:
struct KEY_VALUE_NODE *key_value_node_alloc(char *key, void *value)
{
    int size = strlen(key)+1;
    struct KEY_VALUE_NODE *result = (KEY_VALUE_NODE *)malloc(sizeof(KEY_VALUE_NODE) + size);
    if (!result) {
        return ((void *)0);
    }
    result->value = value;
    strncpy(result->data, key, size);
    result->key = &(result->data[0]);
    return result;
}

variable_types:
key
char *

variable_types:
value
void *

variable_types: size int

variable_types: struct KEY_VALUE_NODE { struct tree_node { struct tree_node *parent; char color; } header; char *key; void *value; char data[]; } *


decompiled_code:
__int64 __fastcall tree_minimum(__int64 *a1)
{
__int64 v1; // rax
__int64 v2; // r8

v1 = *a1;
if ( !*a1 )
return 0LL;
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
return v2;
}

original_code:
TREE_NODE *
tree_minimum(TREE *t)
{
    TREE_NODE *n = t->root;
    if (!n) {
        return ((void *)0);
    }
    while (n->left) {
        n = n->left;
    }
    return n;
}

canonical_original_code:
struct tree_node *tree_minimum(struct tree_core *t)
{
    struct tree_node *n = t->root;
    if (!n) {
        return ((void *)0);
    }
    while (n->left) {
        n = n->left;
    }
    return n;
}

variable_types: struct tree_core { struct tree_node *root; } *

return_type: struct tree_node { struct tree_node *parent; char color; } *


decompiled_code:
__int64 __fastcall tree_maximum(__int64 *a1)
{
__int64 v1; // rax
__int64 v2; // r8

v1 = *a1;
if ( !*a1 )
return 0LL;
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
return v2;
}

original_code:
TREE_NODE *
tree_maximum(TREE *t)
{
    TREE_NODE *n = t->root;
    if (!n) {
        return ((void *)0);
    }
    while (n->right) {
        n = n->right;
    }
    return n;
}

canonical_original_code:
struct tree_node *tree_maximum(struct tree_core *t)
{
    struct tree_node *n = t->root;
    if (!n) {
        return ((void *)0);
    }
    while (n->right) {
        n = n->right;
    }
    return n;
}

user_defined_types: struct tree_core { struct tree_node *root; }


decompiled_code:
void __fastcall mncl_kv_foreach(__int64 *a1, void (__fastcall *a2)(_QWORD, _QWORD, __int64), __int64 a3)
{
_QWORD *i; // rbp

if ( a1 )
{
for ( i = (_QWORD *)tree_minimum(a1); i; i = tree_next(i) )
a2(i[4], i[5], a3);
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 *a1, void (__fastcall *a2)(_QWORD, _QWORD, __int64), __int64 a3)
{
_QWORD *i; // rbp

if ( a1 )
{
for ( i = (_QWORD *)func4(a1); i; i = tree_next(i) )
a2(i[4], i[5], a3);
}
}

original_code:
void
mncl_kv_foreach(MNCL_KV *kv, MNCL_KV_VALUE_FN fn, void *user)
{
    TREE_NODE *node;
    if (!kv) {
        return;
    }
    node = tree_minimum(&kv->tree);
    while (node) {
        KEY_VALUE_NODE *kvn = (KEY_VALUE_NODE *)node;
        fn(kvn->key, kvn->value, user);
        node = tree_next(node);
    }
}

canonical_original_code:
void mncl_kv_foreach(struct struct_MNCL_KV *kv, void (*fn)(char *key, void *value, void *user), void *user)
{
    struct tree_node *node;
    if (!kv) {
        return;
    }
    node = tree_minimum(&kv->tree);
    while (node) {
        struct KEY_VALUE_NODE *kvn = (KEY_VALUE_NODE *)node;
        fn(kvn->key, kvn->value, user);
        node = tree_next(node);
    }
}

variable_types: struct struct_MNCL_KV { struct tree_core { struct tree_node { struct tree_node *parent; char color; } *root; } tree; void (*deleter)(void *value); } *

variable_types: void (*)(char *key, void *value, void *user)

variable_types:
user
void *

user_defined_types: struct struct_MNCL_KV { struct tree_core tree; void (*deleter)(void *value); }


original_code:
TREE_NODE *
tree_find(TREE *t, TREE_NODE *i, TREE_CMP cmp)
{
    TREE_NODE *n = t->root;
    while (n) {
        int c = cmp(i, n);
        if (c < 0) {
            n = n->left;
        } else if (c > 0) {
            n = n->right;
        } else {
            break;
        }
    }
    return n;
}

canonical_original_code:
struct tree_node *tree_find(struct tree_core *t, struct tree_node *i, int (*cmp)(struct tree_node *, struct tree_node *))
{
    struct tree_node *n = t->root;
    while (n) {
        int c = cmp(i, n);
        if (c < 0) {
            n = n->left;
        } else if (c > 0) {
            n = n->right;
        } else {
            break;
        }
    }
    return n;
}

variable_types:
i
struct tree_node *

variable_types: int (*)(struct tree_node *, struct tree_node *)

variable_types: c int


decompiled_code:
__int64 __fastcall mncl_kv_find(__int64 *a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax
_QWORD v4[7]; // [rsp-20h] [rbp-38h] BYREF

if ( !a1 )
return 0LL;
v4[4] = a2;
v2 = tree_find(a1, (__int64)v4, (__int64 (__fastcall *)(__int64, __int64))key_value_node_cmp);
if ( v2 )
result = *(_QWORD *)(v2 + 40);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax
_QWORD v4[7]; // [rsp-20h] [rbp-38h] BYREF

if ( !a1 )
return 0LL;
v4[4] = a2;
v2 = func7(a1, (__int64)v4, (__int64 (__fastcall *)(__int64, __int64))key_value_node_cmp);
if ( v2 )
result = *(_QWORD *)(v2 + 40);
else
result = 0LL;
return result;
}

original_code:
void *
mncl_kv_find(MNCL_KV *kv, const char *key)
{
    KEY_SEARCH_NODE seek;
    KEY_VALUE_NODE *result;
    if (!kv) {
        return ((void *)0);
    }
    seek.key = key;
    result = (KEY_VALUE_NODE *)tree_find(&kv->tree, (TREE_NODE *)&seek, key_value_node_cmp);
    if (result) {
        return result->value;
    }
    return ((void *)0);
}

canonical_original_code:
void *mncl_kv_find(struct struct_MNCL_KV *kv, char *key)
{
    struct KEY_SEARCH_NODE seek;
    struct KEY_VALUE_NODE *result;
    if (!kv) {
        return ((void *)0);
    }
    seek.key = key;
    result = (struct KEY_VALUE_NODE *)tree_find(&kv->tree, (struct tree_node *)&seek, key_value_node_cmp);
    if (result) {
        return result->value;
    }
    return ((void *)0);
}

variable_types: struct KEY_SEARCH_NODE { struct tree_node { struct tree_node *parent; char color; } header; char *key; }

return_type: void *

user_defined_types: struct KEY_SEARCH_NODE { struct tree_node header; char *key; }


original_code:
void
tree_delete_unbalanced(TREE *t, TREE_NODE *n)
{
    TREE_NODE *splice_out, *orphan;
    if (!t || !t->root || !n) {
        return;
    }
    splice_out = (n->left && n->right) ? tree_next(n) : n;
    orphan = splice_out->left ? splice_out->left : splice_out->right;
    if (orphan) {
        orphan->parent = splice_out->parent;
    }
    if (!splice_out->parent) {
        t->root = orphan;
    } else if (splice_out->parent->left == splice_out) {
        splice_out->parent->left = orphan;
    } else {
        splice_out->parent->right = orphan;
    }
    if (splice_out != n) {
        if (!n->parent) {
            t->root = splice_out;
        } else if (n->parent->left == n) {
            n->parent->left = splice_out;
        } else {
            n->parent->right = splice_out;
        }
        splice_out->parent = n->parent;
        splice_out->left = n->left;
        splice_out->right = n->right;
        if (n->left) {
            n->left->parent = splice_out;
        }
        if (n->right) {
            n->right->parent = splice_out;
        }
    }
}

canonical_original_code:
void tree_delete_unbalanced(struct tree_core *t, struct tree_node *n)
{
    struct tree_node *splice_out; struct tree_node *orphan;
    if (!t || !t->root || !n) {
        return;
    }
    splice_out = (n->left && n->right) ? tree_next(n) : n;
    orphan = splice_out->left ? splice_out->left : splice_out->right;
    if (orphan) {
        orphan->parent = splice_out->parent;
    }
    if (!splice_out->parent) {
        t->root = orphan;
    } else if (splice_out->parent->left == splice_out) {
        splice_out->parent->left = orphan;
    } else {
        splice_out->parent->right = orphan;
    }
    if (splice_out != n) {
        if (!n->parent) {
            t->root = splice_out;
        } else if (n->parent->left == n) {
            n->parent->left = splice_out;
        } else {
            n->parent->right = splice_out;
        }
        splice_out->parent = n->parent;
        splice_out->left = n->left;
        splice_out->right = n->right;
        if (n->left) {
            n->left->parent = splice_out;
        }
        if (n->right) {
            n->right->parent = splice_out;
        }
    }
}

variable_types: struct tree_core { struct tree_node { struct tree_node *parent; char color; } *root; } *

variable_types:
n
struct tree_node *


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

if ( a1 )
result = tree_preorder_aux(*a1, a2);
return result;
}

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

if ( a1 )
result = func0(*a1, a2);
return result;
}

original_code:
void
tree_preorder(TREE *t, TREE_VISITOR visitor)
{
    if (t) {
        tree_preorder_aux(t->root, visitor);
    }
}

canonical_original_code:
void tree_preorder(struct tree_core *t, void (*visitor)(struct tree_node *))
{
    if (t) {
        tree_preorder_aux(t->root, visitor);
    }
}


decompiled_code:
void __fastcall tree_inorder(_QWORD *a1, void (__fastcall *a2)(_QWORD *))
{
_QWORD *v2; // rax
_QWORD *v3; // rbp

if ( a1 )
{
v2 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
}
while ( v2 );
do
{
a2(v3);
v3 = tree_next(v3);
}
while ( v3 );
}
}
}

canonical_decompiled_code:
void __fastcall func11(_QWORD *a1, void (__fastcall *a2)(_QWORD *))
{
_QWORD *v2; // rax
_QWORD *v3; // rbp

if ( a1 )
{
v2 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
}
while ( v2 );
do
{
a2(v3);
v3 = tree_next(v3);
}
while ( v3 );
}
}
}

original_code:
void
tree_inorder(TREE *t, TREE_VISITOR visitor)
{
    TREE_NODE *n;
    if (!t || !t->root) {
        return;
    }
    n = t->root;
    while (n->left) {
        n = n->left;
    }
    while (n) {
        visitor(n);
        n = tree_next(n);
    }
}

canonical_original_code:
void tree_inorder(struct tree_core *t, void (*visitor)(struct tree_node *))
{
    struct tree_node *n;
    if (!t || !t->root) {
        return;
    }
    n = t->root;
    while (n->left) {
        n = n->left;
    }
    while (n) {
        visitor(n);
        n = tree_next(n);
    }
}

variable_types: struct tree_node { struct tree_node *parent; char color; } *


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

if ( a1 )
result = tree_postorder_aux(*a1, a2);
return result;
}

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

if ( a1 )
result = func1(*a1, a2);
return result;
}

original_code:
void
tree_postorder(TREE *t, TREE_VISITOR visitor)
{
    if (t) {
        tree_postorder_aux(t->root, visitor);
    }
}

canonical_original_code:
void tree_postorder(struct tree_core *t, void (*visitor)(struct tree_node *))
{
    if (t) {
        tree_postorder_aux(t->root, visitor);
    }
}

variable_types:
visitor
void (*)(struct tree_node *)


decompiled_code:
void __fastcall mncl_free_kv(void *ptr)
{
void (__fastcall *v1)(_QWORD); // rdx
_QWORD *v2; // rbp

if ( ptr )
{
if ( *((_QWORD *)ptr + 1) )
{
v2 = (_QWORD *)tree_minimum((__int64 *)ptr);
if ( v2 )
{
while ( 1 )
{
v1(v2[5]);
v2 = tree_next(v2);
if ( !v2 )
break;
v1 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 1);
}
}
}
tree_postorder((__int64 *)ptr, (__int64 (__fastcall *)(__int64))&free);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func13(void *ptr)
{
void (__fastcall *v1)(_QWORD); // rdx
_QWORD *v2; // rbp

if ( ptr )
{
if ( *((_QWORD *)ptr + 1) )
{
v2 = (_QWORD *)func4((__int64 *)ptr);
if ( v2 )
{
while ( 1 )
{
v1(v2[5]);
v2 = tree_next(v2);
if ( !v2 )
break;
v1 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 1);
}
}
}
func12((__int64 *)ptr, (__int64 (__fastcall *)(__int64))&free);
free(ptr);
}
}

original_code:
void
mncl_free_kv(MNCL_KV *kv)
{
    if (!kv) {
        return;
    }
    if (kv->deleter) {
        TREE_NODE *node = tree_minimum(&kv->tree);
        while (node) {
            kv->deleter(((KEY_VALUE_NODE *)node)->value);
            node = tree_next(node);
        }
    }
    tree_postorder (&kv->tree, (TREE_VISITOR)free);
    free(kv);
}

canonical_original_code:
void mncl_free_kv(struct struct_MNCL_KV *kv)
{
    if (!kv) {
        return;
    }
    if (kv->deleter) {
        struct tree_node *node = tree_minimum(&kv->tree);
        while (node) {
            kv->deleter(((struct KEY_VALUE_NODE *)node)->value);
            node = tree_next(node);
        }
    }
    tree_postorder (&kv->tree, (void (*)(struct tree_node *))free);
    free(kv);
}


decompiled_code:
__int64 __fastcall mncl_kv_insert(__int64 *a1, char *a2, __int64 a3)
{
__int64 v4; // rbx
void (__fastcall *v5)(_QWORD); // rax
__int64 result; // rax
char *v7; // rsi
_QWORD v8[11]; // [rsp-20h] [rbp-58h] BYREF

if ( !a1 )
return 0LL;
v8[4] = a2;
v4 = tree_find(a1, (__int64)v8, (__int64 (__fastcall *)(__int64, __int64))key_value_node_cmp);
if ( v4 )
{
v5 = (void (__fastcall *)(_QWORD))a1[1];
if ( v5 )
v5(*(_QWORD *)(v4 + 40));
*(_QWORD *)(v4 + 40) = a3;
result = 1LL;
}
else
{
v7 = key_value_node_alloc(a2, a3);
result = 0LL;
if ( v7 )
{
tree_insert(a1, v7, (__int64 (__fastcall *)(_QWORD *, __int64))key_value_node_cmp);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 *a1, char *a2, __int64 a3)
{
__int64 v4; // rbx
void (__fastcall *v5)(_QWORD); // rax
__int64 result; // rax
char *v7; // rsi
_QWORD v8[11]; // [rsp-20h] [rbp-58h] BYREF

if ( !a1 )
return 0LL;
v8[4] = a2;
v4 = func7(a1, (__int64)v8, (__int64 (__fastcall *)(__int64, __int64))key_value_node_cmp);
if ( v4 )
{
v5 = (void (__fastcall *)(_QWORD))a1[1];
if ( v5 )
v5(*(_QWORD *)(v4 + 40));
*(_QWORD *)(v4 + 40) = a3;
result = 1LL;
}
else
{
v7 = func3(a2, a3);
result = 0LL;
if ( v7 )
{
tree_insert(a1, v7, (__int64 (__fastcall *)(_QWORD *, __int64))key_value_node_cmp);
result = 1LL;
}
}
return result;
}

original_code:
int
mncl_kv_insert(MNCL_KV *kv, const char *key, void *value)
{
    KEY_SEARCH_NODE seek;
    KEY_VALUE_NODE *result;
    if (!kv) {
        return 0;
    }
    seek.key=key;
    result = (KEY_VALUE_NODE *)tree_find(&kv->tree, (TREE_NODE *)&seek, key_value_node_cmp);
    if (result) {
        if (kv->deleter) {
            kv->deleter(result->value);
        }
        result->value = value;
    } else {
        result = key_value_node_alloc(key, value);
        if (!result) {
            return 0;
        } else {
            tree_insert(&kv->tree, (TREE_NODE *)result, key_value_node_cmp);
        }
    }
    return 1;
}

canonical_original_code:
int mncl_kv_insert(struct struct_MNCL_KV *kv, char *key, void *value)
{
    struct KEY_SEARCH_NODE seek;
    struct KEY_VALUE_NODE *result;
    if (!kv) {
        return 0;
    }
    seek.key=key;
    result = (struct KEY_VALUE_NODE *)tree_find(&kv->tree, (struct tree_node *)&seek, key_value_node_cmp);
    if (result) {
        if (kv->deleter) {
            kv->deleter(result->value);
        }
        result->value = value;
    } else {
        result = key_value_node_alloc(key, value);
        if (!result) {
            return 0;
        } else {
            tree_insert(&kv->tree, (struct tree_node *)result, key_value_node_cmp);
        }
    }
    return 1;
}


original_code:
void
tree_delete(TREE *t, TREE_NODE *n)
{
    TREE_NODE *splice_out, *orphan, *orphan_parent;
    int need_fixup = 0;
    if (!t || !t->root || !n) {
        return;
    }
    splice_out = (n->left && n->right) ? tree_next(n) : n;
    orphan = splice_out->left ? splice_out->left : splice_out->right;
    orphan_parent = splice_out->parent;
    if (orphan) {
        orphan->parent = orphan_parent;
    }
    if (!splice_out->parent) {
        t->root = orphan;
    } else if (splice_out->parent->left == splice_out) {
        splice_out->parent->left = orphan;
    } else {
        splice_out->parent->right = orphan;
    }
    if (splice_out->color == 1) {
        need_fixup = 1;
    }
    if (splice_out != n) {
        if (!n->parent) {
            t->root = splice_out;
        } else if (n->parent->left == n) {
            n->parent->left = splice_out;
        } else {
            n->parent->right = splice_out;
        }
        splice_out->parent = n->parent;
        splice_out->left = n->left;
        splice_out->right = n->right;
        splice_out->color = n->color;
        if (orphan_parent == n) {
            orphan_parent = splice_out;
        }
        if (n->left) {
            n->left->parent = splice_out;
        }
        if (n->right) {
            n->right->parent = splice_out;
        }
    }
    if (need_fixup) {
        TREE_NODE *x, *x_parent, *sibling;
        x = orphan;
        x_parent = orphan_parent;
        while (x_parent && (!x || x->color == 1)) {
            if (x == x_parent->left) {
                sibling = x_parent->right;
                if (sibling && sibling->color == 0) {
                    sibling->color = 1;
                    x_parent->color = 0;
                    left_rotate(t, x_parent);
                    sibling = x_parent->right;
                }
                if ((!sibling->left || sibling->left->color == 1) &&
                    (!sibling->right || sibling->right->color == 1)) {
                    sibling->color = 0;
                    x = x_parent;
                    x_parent = x ? x->parent : ((void *)0);
                } else {
                    if (!sibling->right || sibling->right->color == 1) {
                        sibling->left->color = 0;
                        right_rotate(t, sibling);
                        sibling = x_parent->right;
                    }
                    if (sibling) {
                        sibling->color = x_parent ? x_parent->color : 1;
                    }
                    if (x_parent) {
                        x_parent->color = 1;
                    }
                    if (sibling->right) {
                        sibling->right->color = 1;
                    }
                    left_rotate(t, x_parent);
                    x = t->root;
                    x_parent = ((void *)0);
                }
            } else {
                sibling = x_parent->left;
                if (sibling && sibling->color == 0) {
                    sibling->color = 1;
                    x_parent->color = 0;
                    right_rotate(t, x_parent);
                    sibling = x_parent->left;
                }
                if ((!sibling->left || sibling->left->color == 1) &&
                    (!sibling->right || sibling->right->color == 1)) {
                    sibling->color = 0;
                    x = x_parent;
                    x_parent = x ? x->parent : ((void *)0);
                } else {
                    if (!sibling->left || sibling->left->color == 1) {
                        sibling->right->color = 0;
                        left_rotate(t, sibling);
                        sibling = x_parent->left;
                    }
                    if (sibling) {
                        sibling->color = x_parent ? x_parent->color : 1;
                    }
                    if (x_parent) {
                        x_parent->color = 1;
                    }
                    if (sibling->left) {
                        sibling->left->color = 1;
                    }
                    right_rotate(t, x_parent);
                    x = t->root;
                    x_parent = ((void *)0);
                }
            }
        }
        if (x) {
            x->color = 1;
        }
    }
}

canonical_original_code:
void tree_delete(struct tree_core *t, struct tree_node *n)
{
    struct tree_node *splice_out; struct tree_node *orphan; struct tree_node *orphan_parent;
    int need_fixup = 0;
    if (!t || !t->root || !n) {
        return;
    }
    splice_out = (n->left && n->right) ? tree_next(n) : n;
    orphan = splice_out->left ? splice_out->left : splice_out->right;
    orphan_parent = splice_out->parent;
    if (orphan) {
        orphan->parent = orphan_parent;
    }
    if (!splice_out->parent) {
        t->root = orphan;
    } else if (splice_out->parent->left == splice_out) {
        splice_out->parent->left = orphan;
    } else {
        splice_out->parent->right = orphan;
    }
    if (splice_out->color == 1) {
        need_fixup = 1;
    }
    if (splice_out != n) {
        if (!n->parent) {
            t->root = splice_out;
        } else if (n->parent->left == n) {
            n->parent->left = splice_out;
        } else {
            n->parent->right = splice_out;
        }
        splice_out->parent = n->parent;
        splice_out->left = n->left;
        splice_out->right = n->right;
        splice_out->color = n->color;
        if (orphan_parent == n) {
            orphan_parent = splice_out;
        }
        if (n->left) {
            n->left->parent = splice_out;
        }
        if (n->right) {
            n->right->parent = splice_out;
        }
    }
    if (need_fixup) {
        struct tree_node *x; struct tree_node *x_parent; struct tree_node *sibling;
        x = orphan;
        x_parent = orphan_parent;
        while (x_parent && (!x || x->color == 1)) {
            if (x == x_parent->left) {
                sibling = x_parent->right;
                if (sibling && sibling->color == 0) {
                    sibling->color = 1;
                    x_parent->color = 0;
                    left_rotate(t, x_parent);
                    sibling = x_parent->right;
                }
                if ((!sibling->left || sibling->left->color == 1) &&
                    (!sibling->right || sibling->right->color == 1)) {
                    sibling->color = 0;
                    x = x_parent;
                    x_parent = x ? x->parent : ((void *)0);
                } else {
                    if (!sibling->right || sibling->right->color == 1) {
                        sibling->left->color = 0;
                        right_rotate(t, sibling);
                        sibling = x_parent->right;
                    }
                    if (sibling) {
                        sibling->color = x_parent ? x_parent->color : 1;
                    }
                    if (x_parent) {
                        x_parent->color = 1;
                    }
                    if (sibling->right) {
                        sibling->right->color = 1;
                    }
                    left_rotate(t, x_parent);
                    x = t->root;
                    x_parent = ((void *)0);
                }
            } else {
                sibling = x_parent->left;
                if (sibling && sibling->color == 0) {
                    sibling->color = 1;
                    x_parent->color = 0;
                    right_rotate(t, x_parent);
                    sibling = x_parent->left;
                }
                if ((!sibling->left || sibling->left->color == 1) &&
                    (!sibling->right || sibling->right->color == 1)) {
                    sibling->color = 0;
                    x = x_parent;
                    x_parent = x ? x->parent : ((void *)0);
                } else {
                    if (!sibling->left || sibling->left->color == 1) {
                        sibling->right->color = 0;
                        left_rotate(t, sibling);
                        sibling = x_parent->left;
                    }
                    if (sibling) {
                        sibling->color = x_parent ? x_parent->color : 1;
                    }
                    if (x_parent) {
                        x_parent->color = 1;
                    }
                    if (sibling->left) {
                        sibling->left->color = 1;
                    }
                    right_rotate(t, x_parent);
                    x = t->root;
                    x_parent = ((void *)0);
                }
            }
        }
        if (x) {
            x->color = 1;
        }
    }
}


decompiled_code:
void __fastcall mncl_kv_delete(__int64 *a1, __int64 a2)
{
_QWORD *v2; // r12
void (__fastcall *v3)(_QWORD); // rax
_QWORD v4[9]; // [rsp-20h] [rbp-48h] BYREF

if ( a1 )
{
v4[4] = a2;
v2 = (_QWORD *)tree_find(a1, (__int64)v4, (__int64 (__fastcall *)(__int64, __int64))key_value_node_cmp);
if ( v2 )
{
v3 = (void (__fastcall *)(_QWORD))a1[1];
if ( v3 )
v3(v2[5]);
tree_delete((__int64 **)a1, (__int64)v2);
free(v2);
}
}
}

original_code:
void
mncl_kv_delete(MNCL_KV *kv, const char *key)
{
    KEY_SEARCH_NODE seek;
    KEY_VALUE_NODE *result;
    if (!kv) {
        return;
    }
    seek.key = key;
    result = (KEY_VALUE_NODE *)tree_find(&kv->tree, (TREE_NODE *)&seek, key_value_node_cmp);
    if (result) {
        if (kv->deleter) {
            kv->deleter(result->value);
        }
        tree_delete(&kv->tree, (TREE_NODE *)result);
        free(result);
    }
}

canonical_original_code:
void mncl_kv_delete(struct struct_MNCL_KV *kv, char *key)
{
    struct KEY_SEARCH_NODE seek;
    struct KEY_VALUE_NODE *result;
    if (!kv) {
        return;
    }
    seek.key = key;
    result = (struct KEY_VALUE_NODE *)tree_find(&kv->tree, (struct tree_node *)&seek, key_value_node_cmp);
    if (result) {
        if (kv->deleter) {
            kv->deleter(result->value);
        }
        tree_delete(&kv->tree, (struct tree_node *)result);
        free(result);
    }
}


decompiled_code:
void mncl_post_quit()
{
current_global_event = 0;
}

canonical_decompiled_code:
void func8()
{
current_global_event = 0;
}

original_code:
void
mncl_post_quit(void)
{
    current_global_event.type = MNCL_EVENT_QUIT;
}

canonical_original_code:
void mncl_post_quit()
{
    current_global_event.type = MNCL_EVENT_QUIT;
}


decompiled_code:
__int64 mncl_init()
{
const char *v1; // rax
const char *v2; // rax

SDL_SetMainReady();
if ( (unsigned int)SDL_Init(49LL) )
{
v1 = (const char *)SDL_GetError();
printf("SDL_Init Failed! %s\n", v1);
}
Mix_Init(18LL);
if ( (unsigned int)Mix_OpenAudio(22050LL, 32784LL, 1LL, 1024LL) )
{
v2 = (const char *)SDL_GetError();
printf("Could not open audio: %s\n", v2);
}
Mix_AllocateChannels(4LL);
Mix_Volume(0xFFFFFFFFLL, 128LL);
return initialize_object_trees();
}

canonical_decompiled_code:
__int64 func0()
{
const char *v1; // rax
const char *v2; // rax

SDL_SetMainReady();
if ( (unsigned int)SDL_Init(49LL) )
{
v1 = (const char *)SDL_GetError();
printf("SDL_Init Failed! %s\n", v1);
}
Mix_Init(18LL);
if ( (unsigned int)Mix_OpenAudio(22050LL, 32784LL, 1LL, 1024LL) )
{
v2 = (const char *)SDL_GetError();
printf("Could not open audio: %s\n", v2);
}
Mix_AllocateChannels(4LL);
Mix_Volume(0xFFFFFFFFLL, 128LL);
return initialize_object_trees();
}

original_code:
void
mncl_init(void)
{
    SDL_SetMainReady();
    if (SDL_Init(0x00000020u | 0x00000010u | 0x00000001u)) {
        printf ("SDL_Init Failed! %s\n", SDL_GetError());
    }
    Mix_Init(MIX_INIT_MOD|MIX_INIT_OGG);
    if (Mix_OpenAudio(22050, 0x8010, 1, 1024)) {
        printf("Could not open audio: %s\n", SDL_GetError());
    }
    Mix_AllocateChannels(4);
    Mix_Volume(-1, 128);
    initialize_object_trees();
}

canonical_original_code:
void mncl_init()
{
    SDL_SetMainReady();
    if (SDL_Init(0x00000020u | 0x00000010u | 0x00000001u)) {
        printf ("SDL_Init Failed! %s\n", SDL_GetError());
    }
    Mix_Init(MIX_INIT_MOD|MIX_INIT_OGG);
    if (Mix_OpenAudio(22050, 0x8010, 1, 1024)) {
        printf("Could not open audio: %s\n", SDL_GetError());
    }
    Mix_AllocateChannels(4);
    Mix_Volume(-1, 128);
    initialize_object_trees();
}


decompiled_code:
__int64 mncl_uninit()
{
mncl_unload_all_resources();
Mix_CloseAudio();
Mix_Quit();
SDL_Quit();
return mncl_uninit_raw_system();
}

canonical_decompiled_code:
__int64 func1()
{
mncl_unload_all_resources();
Mix_CloseAudio();
Mix_Quit();
SDL_Quit();
return mncl_uninit_raw_system();
}

original_code:
void
mncl_uninit()
{
    mncl_unload_all_resources();
    Mix_CloseAudio();
    Mix_Quit();
    SDL_Quit();
    mncl_uninit_raw_system();
}


initCosts

repo: michaeldickens/Typing

decompiled_code:
void initCosts()
{
__int64 v0; // xmm0_8

detailedOutput = 1;
numThreads = 1;
keepZXCV = 0;
keepQWERTY = 0;
keepNumbers = 1;
keepBrackets = 1;
keepShiftPairs = 0;
keepTab = 1;
keepConsonantsRight = 0;
keepNumbersShifted = 0;
zCost = 10;
xCost = 6;
cCost = 12;
vCost = 14;
qwertyPosCost = 14;
qwertyFingerCost = 4;
qwertyHandCost = 20;
bracketsCost = 5000000;
numbersShiftedCost = -1000000;
if ( fullKeyboard == 2 )
{
fingerPercentMaxes[9] = LC0;
fingerPercentMaxes[0] = LC0;
fingerPercentMaxes[8] = LC1;
fingerPercentMaxes[1] = LC1;
v0 = LC2;
}
else
{
fingerPercentMaxes[9] = LC4;
fingerPercentMaxes[0] = LC4;
fingerPercentMaxes[8] = LC5;
fingerPercentMaxes[1] = LC5;
v0 = LC6;
}
fingerPercentMaxes[7] = v0;
fingerPercentMaxes[2] = v0;
fingerPercentMaxes[6] = v0;
fingerPercentMaxes[3] = v0;
fingerWorkCosts[9] = 40LL;
fingerWorkCosts[0] = 40LL;
fingerWorkCosts[8] = 30LL;
fingerWorkCosts[1] = 30LL;
fingerWorkCosts[7] = 20LL;
fingerWorkCosts[2] = 20LL;
fingerWorkCosts[6] = 20LL;
fingerWorkCosts[3] = 20LL;
fingerWorkCosts[5] = 20LL;
fingerWorkCosts[4] = 20LL;
distance = 1;
inRoll = -40;
outRoll = 5;
sameHand = 5;
sameFingerP = 150;
sameFingerR = 140;
sameFingerM = 110;
sameFingerI = 90;
sameFingerT = 100;
rowChangeDown = 10;
rowChangeUp = 15;
handWarp = 25;
handSmooth = -5;
homeJump = 100;
homeJumpIndex = -90;
fingerPercentMaxes[5] = LC3;
fingerPercentMaxes[4] = LC3;
doubleJump = 220;
ringJump = 40;
toCenter = 30;
toOutside = 30;
shiftCost = 100;
doubleShiftCost = 150;
}

canonical_decompiled_code:
void func0()
{
__int64 v0; // xmm0_8

detailedOutput = 1;
numThreads = 1;
keepZXCV = 0;
keepQWERTY = 0;
keepNumbers = 1;
keepBrackets = 1;
keepShiftPairs = 0;
keepTab = 1;
keepConsonantsRight = 0;
keepNumbersShifted = 0;
zCost = 10;
xCost = 6;
cCost = 12;
vCost = 14;
qwertyPosCost = 14;
qwertyFingerCost = 4;
qwertyHandCost = 20;
bracketsCost = 5000000;
numbersShiftedCost = -1000000;
if ( fullKeyboard == 2 )
{
fingerPercentMaxes[9] = LC0;
fingerPercentMaxes[0] = LC0;
fingerPercentMaxes[8] = LC1;
fingerPercentMaxes[1] = LC1;
v0 = LC2;
}
else
{
fingerPercentMaxes[9] = LC4;
fingerPercentMaxes[0] = LC4;
fingerPercentMaxes[8] = LC5;
fingerPercentMaxes[1] = LC5;
v0 = LC6;
}
fingerPercentMaxes[7] = v0;
fingerPercentMaxes[2] = v0;
fingerPercentMaxes[6] = v0;
fingerPercentMaxes[3] = v0;
fingerWorkCosts[9] = 40LL;
fingerWorkCosts[0] = 40LL;
fingerWorkCosts[8] = 30LL;
fingerWorkCosts[1] = 30LL;
fingerWorkCosts[7] = 20LL;
fingerWorkCosts[2] = 20LL;
fingerWorkCosts[6] = 20LL;
fingerWorkCosts[3] = 20LL;
fingerWorkCosts[5] = 20LL;
fingerWorkCosts[4] = 20LL;
distance = 1;
inRoll = -40;
outRoll = 5;
sameHand = 5;
sameFingerP = 150;
sameFingerR = 140;
sameFingerM = 110;
sameFingerI = 90;
sameFingerT = 100;
rowChangeDown = 10;
rowChangeUp = 15;
handWarp = 25;
handSmooth = -5;
homeJump = 100;
homeJumpIndex = -90;
fingerPercentMaxes[5] = LC3;
fingerPercentMaxes[4] = LC3;
doubleJump = 220;
ringJump = 40;
toCenter = 30;
toOutside = 30;
shiftCost = 100;
doubleShiftCost = 150;
}

original_code:
void initCosts()
{
 detailedOutput = 1;
 numThreads = 1;
 keepZXCV = 0;
 keepQWERTY = 0;
 keepNumbers = 1;
 keepBrackets = 1;
 keepShiftPairs = 0;
 keepTab = 1;
 keepConsonantsRight = 0;
 keepNumbersShifted = 0;
 zCost = 10;
 xCost = 6;
 cCost = 12;
 vCost = 14;
 qwertyPosCost = 14;
 qwertyFingerCost = 4;
 qwertyHandCost = 20;
 bracketsCost = 5000000;
 numbersShiftedCost = -1000000;
 if (fullKeyboard == 2) {
  fingerPercentMaxes[0] = fingerPercentMaxes[10 - 1] = 7.5;
  fingerPercentMaxes[1] = fingerPercentMaxes[10 - 2] = 10.0;
  fingerPercentMaxes[2] = fingerPercentMaxes[10 - 3] = 20.0;
  fingerPercentMaxes[3] = fingerPercentMaxes[10 - 4] = 20.0;
  fingerPercentMaxes[4] = fingerPercentMaxes[10 - 5] = 18.0;
 } else {
  fingerPercentMaxes[0] = fingerPercentMaxes[10 - 1] = 9.0;
  fingerPercentMaxes[1] = fingerPercentMaxes[10 - 2] = 11.5;
  fingerPercentMaxes[2] = fingerPercentMaxes[10 - 3] = 22.0;
  fingerPercentMaxes[3] = fingerPercentMaxes[10 - 4] = 22.0;
  fingerPercentMaxes[4] = fingerPercentMaxes[10 - 5] = 18.0;
 }
 fingerWorkCosts[0] = fingerWorkCosts[10 - 1] = 40;
 fingerWorkCosts[1] = fingerWorkCosts[10 - 2] = 30;
 fingerWorkCosts[2] = fingerWorkCosts[10 - 3] = 20;
 fingerWorkCosts[3] = fingerWorkCosts[10 - 4] = 20;
 fingerWorkCosts[4] = fingerWorkCosts[10 - 5] = 20;
 distance = 1;
 inRoll = -40;
 outRoll = 5;
 sameHand = 5;
 sameFingerP = 150;
 sameFingerR = 140;
 sameFingerM = 110;
 sameFingerI = 90;
 sameFingerT = 100;
 rowChangeDown = 10;
 rowChangeUp = 15;
 handWarp = 25;
 handSmooth = - 5;
 homeJump = 100;
 homeJumpIndex = -90;
 doubleJump = 220;
 ringJump = 40;
 toCenter = 30;
 toOutside = 30;
 shiftCost = 100;
 doubleShiftCost=150;
}


initValues

decompiled_code:
__int64 initValues()
{
__int64 v0; // rdx
unsigned __int64 v1; // rax
__int64 v2; // rcx
__int64 result; // rax
__int64 v4; // rdx
unsigned __int64 v5; // rax
__int64 v6; // rcx
__int64 v7; // rdx
unsigned __int64 v8; // rax
__int64 v9; // rcx
__int64 v10; // rdx
unsigned __int64 v11; // rax
__int64 v12; // rcx

initCosts();
if ( fullKeyboard )
{
if ( fullKeyboard == 1 )
{
if ( ksize > 0 )
{
v7 = 110LL;
v8 = 0LL;
v9 = 8LL * (unsigned int)(ksize - 1);
while ( 1 )
{
distanceCosts[v8 / 8] = v7;
if ( v8 == v9 )
break;
v7 = qword_1FC8[v8 / 8];
v8 += 8LL;
}
}
}
else if ( fullKeyboard == 2 )
{
if ( ksize > 0 )
{
v10 = 120LL;
v11 = 0LL;
v12 = 8LL * (unsigned int)(ksize - 1);
while ( 1 )
{
distanceCosts[v11 / 8] = v10;
if ( v11 == v12 )
break;
v10 = qword_1988[v11 / 8];
v11 += 8LL;
}
}
}
else if ( fullKeyboard == 3 && ksize > 0 )
{
v4 = 45LL;
v5 = 0LL;
v6 = 8LL * (unsigned int)(ksize - 1);
while ( 1 )
{
distanceCosts[v5 / 8] = v4;
if ( v5 == v6 )
break;
v4 = qword_1348[v5 / 8];
v5 += 8LL;
}
}
}
else if ( ksize > 0 )
{
v0 = 40LL;
v1 = 0LL;
v2 = 8LL * (unsigned int)(ksize - 1);
while ( 1 )
{
distanceCosts[v1 / 8] = v0;
if ( v2 == v1 )
break;
v0 = qword_2608[v1 / 8];
v1 += 8LL;
}
}
shortcutCosts[0] = 0LL;
result = 0LL;
shortcutCosts[1] = 0LL;
shortcutCosts[2] = 1LL;
shortcutCosts[3] = 3LL;
shortcutCosts[4] = 4LL;
shortcutCosts[5] = 8LL;
shortcutCosts[6] = 10LL;
shortcutCosts[7] = 10LL;
shortcutCosts[8] = 10LL;
shortcutCosts[9] = 10LL;
shortcutCosts[10] = 0LL;
shortcutCosts[11] = 0LL;
shortcutCosts[12] = 2LL;
shortcutCosts[13] = 3LL;
shortcutCosts[14] = 5LL;
shortcutCosts[15] = 8LL;
shortcutCosts[16] = 10LL;
shortcutCosts[17] = 10LL;
shortcutCosts[18] = 10LL;
shortcutCosts[19] = 10LL;
shortcutCosts[20] = 0LL;
shortcutCosts[21] = 0LL;
shortcutCosts[22] = 0LL;
shortcutCosts[23] = 2LL;
shortcutCosts[24] = 4LL;
shortcutCosts[25] = 8LL;
shortcutCosts[26] = 10LL;
shortcutCosts[27] = 10LL;
shortcutCosts[28] = 10LL;
shortcutCosts[29] = 10LL;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rdx
unsigned __int64 v1; // rax
__int64 v2; // rcx
__int64 result; // rax
__int64 v4; // rdx
unsigned __int64 v5; // rax
__int64 v6; // rcx
__int64 v7; // rdx
unsigned __int64 v8; // rax
__int64 v9; // rcx
__int64 v10; // rdx
unsigned __int64 v11; // rax
__int64 v12; // rcx

func0();
if ( fullKeyboard )
{
if ( fullKeyboard == 1 )
{
if ( ksize > 0 )
{
v7 = 110LL;
v8 = 0LL;
v9 = 8LL * (unsigned int)(ksize - 1);
while ( 1 )
{
distanceCosts[v8 / 8] = v7;
if ( v8 == v9 )
break;
v7 = qword_1FC8[v8 / 8];
v8 += 8LL;
}
}
}
else if ( fullKeyboard == 2 )
{
if ( ksize > 0 )
{
v10 = 120LL;
v11 = 0LL;
v12 = 8LL * (unsigned int)(ksize - 1);
while ( 1 )
{
distanceCosts[v11 / 8] = v10;
if ( v11 == v12 )
break;
v10 = qword_1988[v11 / 8];
v11 += 8LL;
}
}
}
else if ( fullKeyboard == 3 && ksize > 0 )
{
v4 = 45LL;
v5 = 0LL;
v6 = 8LL * (unsigned int)(ksize - 1);
while ( 1 )
{
distanceCosts[v5 / 8] = v4;
if ( v5 == v6 )
break;
v4 = qword_1348[v5 / 8];
v5 += 8LL;
}
}
}
else if ( ksize > 0 )
{
v0 = 40LL;
v1 = 0LL;
v2 = 8LL * (unsigned int)(ksize - 1);
while ( 1 )
{
distanceCosts[v1 / 8] = v0;
if ( v2 == v1 )
break;
v0 = qword_2608[v1 / 8];
v1 += 8LL;
}
}
shortcutCosts[0] = 0LL;
result = 0LL;
shortcutCosts[1] = 0LL;
shortcutCosts[2] = 1LL;
shortcutCosts[3] = 3LL;
shortcutCosts[4] = 4LL;
shortcutCosts[5] = 8LL;
shortcutCosts[6] = 10LL;
shortcutCosts[7] = 10LL;
shortcutCosts[8] = 10LL;
shortcutCosts[9] = 10LL;
shortcutCosts[10] = 0LL;
shortcutCosts[11] = 0LL;
shortcutCosts[12] = 2LL;
shortcutCosts[13] = 3LL;
shortcutCosts[14] = 5LL;
shortcutCosts[15] = 8LL;
shortcutCosts[16] = 10LL;
shortcutCosts[17] = 10LL;
shortcutCosts[18] = 10LL;
shortcutCosts[19] = 10LL;
shortcutCosts[20] = 0LL;
shortcutCosts[21] = 0LL;
shortcutCosts[22] = 0LL;
shortcutCosts[23] = 2LL;
shortcutCosts[24] = 4LL;
shortcutCosts[25] = 8LL;
shortcutCosts[26] = 10LL;
shortcutCosts[27] = 10LL;
shortcutCosts[28] = 10LL;
shortcutCosts[29] = 10LL;
return result;
}

variable_types: i int

variable_types:
costsCopy
long [200]


main

canonical_name: main

repo: michaelforney/supervisor-extras

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
int v4; // edx
int v5; // ecx
int v6; // er8
int v7; // er9
int v8; // edx
int v9; // ecx
int v10; // er8
int v11; // er9
sigset_t v12; // [rsp+0h] [rbp-128h] BYREF
struct sigaction v13; // [rsp+80h] [rbp-A8h] BYREF

v13.sa_handler = (__sighandler_t)finish;
memset(&v13.sa_mask, 0, 0x90uLL);
sigfillset(&v12);
sigdelset(&v12, 10);
sigdelset(&v12, 12);
sigprocmask(2, &v12, 0LL);
sigaction(10, &v13, 0LL);
sigaction(12, &v13, 0LL);
v3 = fork();
if ( v3 != -1 )
{
if ( !v3 )
{
sigemptyset(&v12);
sigprocmask(2, &v12, 0LL);
msg(stdout, v12.__val[0]);
execv("/etc/rc", &startup);
die((unsigned int)"execv() failed", (unsigned int)&startup, v8, v9, v10, v11, v12.__val[0]);
}
while ( 1 )
{
wait(0LL);
wait(0LL);
}
}
die((unsigned int)"fork() failed", (unsigned int)&v13, v4, v5, v6, v7, v12.__val[0]);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
int v4; // edx
int v5; // ecx
int v6; // er8
int v7; // er9
int v8; // edx
int v9; // ecx
int v10; // er8
int v11; // er9
sigset_t v12; // [rsp+0h] [rbp-128h] BYREF
struct sigaction v13; // [rsp+80h] [rbp-A8h] BYREF

v13.sa_handler = (__sighandler_t)finish;
memset(&v13.sa_mask, 0, 0x90uLL);
sigfillset(&v12);
sigdelset(&v12, 10);
sigdelset(&v12, 12);
sigprocmask(2, &v12, 0LL);
sigaction(10, &v13, 0LL);
sigaction(12, &v13, 0LL);
v3 = fork();
if ( v3 != -1 )
{
if ( !v3 )
{
sigemptyset(&v12);
sigprocmask(2, &v12, 0LL);
func8(stdout, v12.__val[0]);
execv("/etc/rc", &startup);
func9((unsigned int)"execv() failed", (unsigned int)&startup, v8, v9, v10, v11, v12.__val[0]);
}
while ( 1 )
{
wait(0LL);
wait(0LL);
}
}
func9((unsigned int)"fork() failed", (unsigned int)&v13, v4, v5, v6, v7, v12.__val[0]);
}

original_code:
int main()
{
    int ret;
    struct sigaction action = { .__sigaction_handler.sa_handler = &finish };
    sigset_t set;
    sigfillset(&set);
    sigdelset(&set, 10);
    sigdelset(&set, 12);
    sigprocmask(2, &set, 0);
    sigaction(10, &action, 0);
    sigaction(12, &action, 0);
    switch (fork())
    {
        case 0:
            sigemptyset(&set);
            sigprocmask(2, &set, 0);
            msg(stdout, 32 | (1 << 8), "Executing startup command `%s'", startup[0]);
            execv(startup[0], startup);
            die("execv() failed");
        case -1:
            die("fork() failed");
    }
    while (1)
        wait(0);
}

canonical_original_code:
int main()
{
    int ret;
    struct sigaction action = { .__sigaction_handler.sa_handler = &finish };
    struct __sigset_t set;
    sigfillset(&set);
    sigdelset(&set, 10);
    sigdelset(&set, 12);
    sigprocmask(2, &set, 0);
    sigaction(10, &action, 0);
    sigaction(12, &action, 0);
    switch (fork())
    {
        case 0:
            sigemptyset(&set);
            sigprocmask(2, &set, 0);
            msg(stdout, 32 | (1 << 8), "Executing startup command `%s'", startup[0]);
            execv(startup[0], startup);
            die("execv() failed");
        case -1:
            die("fork() failed");
    }
    while (1)
        wait(0);
}

variable_types: ret int

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

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

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


die

decompiled_code:
void __noreturn die(const char *a1, ...)
{
int v1; // edi
char *v2; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
vmsg(stderr, 287, a1, va);
v1 = *__errno_location();
if ( v1 )
{
v2 = strerror(v1);
fprintf(stderr, ": %s\n", v2);
}
msg(stderr, 31, "Executing recover command `%s'\n", "/bin/bash");
execv("/bin/bash", &recover);
exit(1);
}

canonical_decompiled_code:
void __noreturn func9(const char *a1, ...)
{
int v1; // edi
char *v2; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func7(stderr, 287, a1, va);
v1 = *__errno_location();
if ( v1 )
{
v2 = strerror(v1);
fprintf(stderr, ": %s\n", v2);
}
func8(stderr, 31, "Executing recover command `%s'\n", "/bin/bash");
execv("/bin/bash", &recover);
exit(1);
}

original_code:
void __attribute__((noreturn, format(printf, 1, 2)))
    die(const char * fmt, ...)
{
    va_list args;
    __builtin_va_start(args,fmt);
    vmsg(stderr, 31 | (1 << 8), fmt, args);
    __builtin_va_end(args);
    if ((*__errno_location ()) != 0)
        fprintf(stderr, ": %s\n", strerror((*__errno_location ())));
    msg(stderr, 31, "Executing recover command `%s'\n", recover[0]);
    execv(recover[0], recover);
    exit(1);
}

canonical_original_code:
void die(char *fmt, ...)
{
    __builtin_va_list args;
    __builtin_va_start(args,fmt);
    vmsg(stderr, 31 | (1 << 8), fmt, args);
    __builtin_va_end(args);
    if ((*__errno_location ()) != 0)
        fprintf(stderr, ": %s\n", strerror((*__errno_location ())));
    msg(stderr, 31, "Executing recover command `%s'\n", recover[0]);
    execv(recover[0], recover);
    exit(1);
}

variable_types:
fmt
char *


finish

original_code:
void finish(int signum)
{
    int cmd;
    switch (signum)
    {
        case 10:
            cmd = 0x01234567;
            break;
        case 12:
            cmd = 0x4321fedc;
            break;
        default:
            return;
    }
    kill(-1, 15);
    sleep(1);
    kill(-1, 9);
    sync();
    reboot(cmd);
    die("reboot() failed");
}

variable_types: signum int

variable_types: cmd int


repo: michich/lattop

decompiled_code:
void __fastcall delete_symbols(void *ptr)
{
if ( ptr )
{
delete_symbols(*((void **)ptr + 2));
delete_symbols(*((void **)ptr + 1));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
if ( ptr )
{
func2(*((void **)ptr + 2));
func2(*((void **)ptr + 1));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(ptr);
}
}

original_code:
static void delete_symbols(struct rb_node *n)
{
 struct symbol_translation *s;
 if (!n)
  return;
 delete_symbols(n->rb_left);
 delete_symbols(n->rb_right);
 s = (struct symbol_translation *)((char *)(n) - (char *) &((struct symbol_translation *)0)->rb_node);
 free(s->symbol);
 free(s->translation);
 free(s);
}

variable_types: struct rb_node { unsigned long rb_parent_color; struct rb_node *rb_right; struct rb_node *rb_left; } *

variable_types: struct symbol_translation { struct rb_node { unsigned long rb_parent_color; struct rb_node *rb_right; struct rb_node *rb_left; } rb_node; char *symbol; char *translation; int prio; } *

user_defined_types: struct symbol_translation { struct rb_node rb_node; char *symbol; char *translation; int prio; }


decompiled_code:
void *__fastcall lookup_symbol(char *s1)
{
void *i; // r12
int v2; // eax

for ( i = sym2trans; i; i = (void *)*((_QWORD *)i + 1) )
{
while ( 1 )
{
v2 = strcmp(s1, *((const char **)i + 3));
if ( v2 >= 0 )
break;
i = (void *)*((_QWORD *)i + 2);
if ( !i )
return i;
}
if ( !v2 )
break;
}
return i;
}

canonical_decompiled_code:
void *__fastcall func5(char *s1)
{
void *i; // r12
int v2; // eax

for ( i = sym2trans; i; i = (void *)*((_QWORD *)i + 1) )
{
while ( 1 )
{
v2 = strcmp(s1, *((const char **)i + 3));
if ( v2 >= 0 )
break;
i = (void *)*((_QWORD *)i + 2);
if ( !i )
return i;
}
if ( !v2 )
break;
}
return i;
}

original_code:
struct symbol_translation *lookup_symbol(const char *symbol)
{
 struct rb_node *n = sym2trans.rb_node;
 struct symbol_translation *st;
 int cmp;
 while (n) {
  st = (struct symbol_translation *)((char *)(n) - (char *) &((struct symbol_translation *)0)->rb_node);
  cmp = strcmp(symbol, st->symbol);
  if (cmp < 0)
   n = n->rb_left;
  else if (cmp > 0)
   n = n->rb_right;
  else
   return st;
 }
 return ((void *)0);
}

canonical_original_code:
struct symbol_translation *lookup_symbol(char *symbol)
{
 struct rb_node *n = sym2trans.rb_node;
 struct symbol_translation *st;
 int cmp;
 while (n) {
  st = (struct symbol_translation *)((char *)(n) - (char *) &((struct symbol_translation *)0)->rb_node);
  cmp = strcmp(symbol, st->symbol);
  if (cmp < 0)
   n = n->rb_left;
  else if (cmp > 0)
   n = n->rb_right;
  else
   return st;
 }
 return ((void *)0);
}

variable_types:
symbol
char *

variable_types: cmp int

return_type: struct symbol_translation { struct rb_node { unsigned long rb_parent_color; struct rb_node *rb_right; struct rb_node *rb_left; } rb_node; char *symbol; char *translation; int prio; } *


decompiled_code:
__int64 __fastcall lat_translator_lookup(char *a1, _QWORD *a2, _DWORD *a3)
{
_QWORD *v4; // rax
__int64 v5; // rdx
int v6; // eax

v4 = lookup_symbol(a1);
if ( !v4 )
return 4294967294LL;
v5 = v4[4];
v6 = *((_DWORD *)v4 + 10);
*a2 = v5;
*a3 = v6;
return 0LL;
}

original_code:
int lat_translator_lookup(const char *symbol, const char **translation, int *prio)
{
 struct symbol_translation *st = lookup_symbol(symbol);
 if (!st)
  return -2;
 *translation = st->translation;
 *prio = st->prio;
 return 0;
}

canonical_original_code:
int lat_translator_lookup(char *symbol, char **translation, int *prio)
{
 struct symbol_translation *st = lookup_symbol(symbol);
 if (!st)
  return -2;
 *translation = st->translation;
 *prio = st->prio;
 return 0;
}

variable_types:
translation
char **

variable_types:
prio
int *

user_defined_types: struct rb_node { unsigned long rb_parent_color; struct rb_node *rb_right; struct rb_node *rb_left; }


decompiled_code:
__int64 __fastcall lat_translator_translate_stack(char *s)
{
char *v1; // rbx
signed int v2; // er12
__int64 v3; // r13
char v4; // r14
size_t v5; // rax
char *v6; // rbp
int v8; // [rsp+4h] [rbp-34h] BYREF
__int64 v9[6]; // [rsp+8h] [rbp-30h] BYREF

if ( !*s )
return 0LL;
v1 = s;
v2 = 0x80000000;
v3 = 0LL;
do
{
v5 = strspn(v1, " ");
v6 = &v1[v5];
if ( !v1[v5] )
break;
v1 = &v6[strcspn(&v1[v5], " ")];
v4 = *v1;
*v1 = 0;
if ( !(unsigned int)lat_translator_lookup(v6, v9, &v8) && v8 > v2 )
{
v3 = v9[0];
v2 = v8;
}
*v1 = v4;
}
while ( v4 );
return v3;
}

original_code:
const char *lat_translator_translate_stack(char *symbolic_stack_trace)
{
 const char *translation, *best_translation = ((void *)0);
 char *p;
 size_t len;
 int prio, best_prio = (-0x7fffffff - 1);
 char tmp;
 p = symbolic_stack_trace;
 while (*p) {
  p += strspn(p, " ");
  if (*p == '\0')
   break;
  len = strcspn(p, " ");
  tmp = p[len];
  p[len] = '\0';
  if (lat_translator_lookup(p, &translation, &prio) == 0 &&
      prio > best_prio) {
   best_prio = prio;
   best_translation = translation;
  }
  p[len] = tmp;
  p += len;
 }
 return best_translation ?: ((void *)0);
}

canonical_original_code:
char *lat_translator_translate_stack(char *symbolic_stack_trace)
{
 char *translation; char *best_translation = ((void *)0);
 char *p;
 unsigned long len;
 int prio; int best_prio = (-0x7fffffff - 1);
 char tmp;
 p = symbolic_stack_trace;
 while (*p) {
  p += strspn(p, " ");
  if (*p == '\0')
   break;
  len = strcspn(p, " ");
  tmp = p[len];
  p[len] = '\0';
  if (lat_translator_lookup(p, &translation, &prio) == 0 &&
      prio > best_prio) {
   best_prio = prio;
   best_translation = translation;
  }
  p[len] = tmp;
  p += len;
 }
 return best_translation ?: ((void *)0);
}

variable_types:
translation
char *

variable_types:
p
char *

variable_types:
len
unsigned long

variable_types: prio int

variable_types: tmp char

return_type: char *


decompiled_code:
// attributes: thunk
__int64 lat_translator_init()
{
return parse_latencytop_trans();
}

canonical_decompiled_code:
__int64 func8()
{
return func4();
}

original_code:
int lat_translator_init(void)
{
 return parse_latencytop_trans();
}

canonical_original_code:
int lat_translator_init()
{
 return parse_latencytop_trans();
}


decompiled_code:
void lat_translator_fini()
{
delete_symbols(sym2trans);
}

canonical_decompiled_code:
void func9()
{
func2(sym2trans);
}

original_code:
void lat_translator_fini(void)
{
 delete_symbols(sym2trans.rb_node);
}

canonical_original_code:
void lat_translator_fini()
{
 delete_symbols(sym2trans.rb_node);
}


decompiled_code:
__int64 __fastcall stap_reader_get_fd(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

original_code:
static int stap_reader_get_fd(struct polled_reader *pr)
{
 struct stap_reader *sr = (struct stap_reader*) pr;
 return sr->pipe[0];
}

variable_types: struct polled_reader { struct polled_reader_ops { void (*fini)(struct polled_reader *pr); int (*start)(struct polled_reader *pr); int (*get_fd)(struct polled_reader *pr); int (*handle_ready_fd)(struct polled_reader *pr); } *ops; } *

variable_types: struct stap_reader { struct polled_reader { struct polled_reader_ops { void (*fini)(struct polled_reader *pr); int (*start)(struct polled_reader *pr); int (*get_fd)(struct polled_reader *pr); int (*handle_ready_fd)(struct polled_reader *pr); } *ops; } pr; int pipe[2]; int stap_pid; enum { STAP_STARTING=0, STAP_WANT_PROC_INFO=1, STAP_WANT_LATENCY=2 } state; char *line; unsigned long len; char buf[-1]; unsigned int start; char comm[16]; unsigned long delay; unsigned long pid; unsigned long tid; char sleep_or_block; } *

user_defined_types: struct polled_reader { struct polled_reader_ops *ops; }

user_defined_types: struct stap_reader { struct polled_reader pr; int pipe[2]; int stap_pid; enum { STAP_STARTING=0, STAP_WANT_PROC_INFO=1, STAP_WANT_LATENCY=2 } state; char *line; unsigned long len; char buf[-1]; unsigned int start; char comm[16]; unsigned long delay; unsigned long pid; unsigned long tid; char sleep_or_block; }


decompiled_code:
ssize_t __fastcall buf_refill(__int64 a1)
{
int v1; // eax
unsigned int v2; // edx
__int64 v3; // rsi
__int64 v5; // rax
int v6; // edi
ssize_t result; // rax
int v8; // edi
struct iovec v9; // [rsp+0h] [rbp-28h] BYREF
__int64 v10; // [rsp+10h] [rbp-18h]
__int64 v11; // [rsp+18h] [rbp-10h]

v1 = *(_DWORD *)(a1 + 65580);
v2 = 0x10000 - v1;
if ( v1 == 0x10000 )
return -28LL;
v3 = a1 + 40;
v5 = (unsigned __int16)(*(_WORD *)(a1 + 65576) + v1);
v9.iov_base = (void *)(a1 + 40 + v5);
if ( v2 <= (unsigned __int64)(0x10000 - v5) )
{
v8 = *(_DWORD *)(a1 + 8);
v9.iov_len = v2;
result = readv(v8, &v9, 1);
if ( result >= 0 )
goto LABEL_4;
}
else
{
v6 = *(_DWORD *)(a1 + 8);
v10 = v3;
v9.iov_len = 0x10000 - v5;
v11 = v5 + v2 - 0x10000;
result = readv(v6, &v9, 2);
if ( result >= 0 )
{
LABEL_4:
*(_DWORD *)(a1 + 65580) += result;
return result;
}
}
return -*_errno_location();
}

canonical_decompiled_code:
ssize_t __fastcall func1(__int64 a1)
{
int v1; // eax
unsigned int v2; // edx
__int64 v3; // rsi
__int64 v5; // rax
int v6; // edi
ssize_t result; // rax
int v8; // edi
struct iovec v9; // [rsp+0h] [rbp-28h] BYREF
__int64 v10; // [rsp+10h] [rbp-18h]
__int64 v11; // [rsp+18h] [rbp-10h]

v1 = *(_DWORD *)(a1 + 65580);
v2 = 0x10000 - v1;
if ( v1 == 0x10000 )
return -28LL;
v3 = a1 + 40;
v5 = (unsigned __int16)(*(_WORD *)(a1 + 65576) + v1);
v9.iov_base = (void *)(a1 + 40 + v5);
if ( v2 <= (unsigned __int64)(0x10000 - v5) )
{
v8 = *(_DWORD *)(a1 + 8);
v9.iov_len = v2;
result = readv(v8, &v9, 1);
if ( result >= 0 )
goto LABEL_4;
}
else
{
v6 = *(_DWORD *)(a1 + 8);
v10 = v3;
v9.iov_len = 0x10000 - v5;
v11 = v5 + v2 - 0x10000;
result = readv(v6, &v9, 2);
if ( result >= 0 )
{
LABEL_4:
*(_DWORD *)(a1 + 65580) += result;
return result;
}
}
return -*_errno_location();
}

original_code:
static ssize_t buf_refill(struct stap_reader *sr)
{
 struct iovec iovecs[2];
 int iovcnt;
 ssize_t nread;
 unsigned space = sizeof(sr->buf) - sr->fill_count;
 if (!space)
  return -28;
 unsigned first_empty_idx = (sr->start + sr->fill_count) % sizeof(sr->buf);
 char *first_empty = sr->buf + first_empty_idx;
 if (space <= sizeof(sr->buf) - first_empty_idx) {
  iovecs[0].iov_base = first_empty;
  iovecs[0].iov_len = space;
  iovcnt = 1;
 } else {
  iovecs[0].iov_base = first_empty;
  iovecs[0].iov_len = sizeof(sr->buf) - first_empty_idx;
  iovecs[1].iov_base = sr->buf;
  iovecs[1].iov_len = space - iovecs[0].iov_len;
  iovcnt = 2;
 }
 nread = readv(sr->pipe[0], iovecs, iovcnt);
 if (nread < 0)
  return -(*__errno_location ());
 sr->fill_count += nread;
 return nread;
}

canonical_original_code:
static long buf_refill(struct stap_reader *sr)
{
 struct iovec iovecs[2];
 int iovcnt;
 long nread;
 unsigned int space = sizeof(sr->buf) - sr->fill_count;
 if (!space)
  return -28;
 unsigned int first_empty_idx = (sr->start + sr->fill_count) % sizeof(sr->buf);
 char *first_empty = sr->buf + first_empty_idx;
 if (space <= sizeof(sr->buf) - first_empty_idx) {
  iovecs[0].iov_base = first_empty;
  iovecs[0].iov_len = space;
  iovcnt = 1;
 } else {
  iovecs[0].iov_base = first_empty;
  iovecs[0].iov_len = sizeof(sr->buf) - first_empty_idx;
  iovecs[1].iov_base = sr->buf;
  iovecs[1].iov_len = space - iovecs[0].iov_len;
  iovcnt = 2;
 }
 nread = readv(sr->pipe[0], iovecs, iovcnt);
 if (nread < 0)
  return -(*__errno_location ());
 sr->fill_count += nread;
 return nread;
}

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } [2]

variable_types: iovcnt int

variable_types: nread long

variable_types:
space
unsigned int

return_type: long

user_defined_types: struct polled_reader_ops { void (*fini)(struct polled_reader *pr); int (*start)(struct polled_reader *pr); int (*get_fd)(struct polled_reader *pr); int (*handle_ready_fd)(struct polled_reader *pr); }


decompiled_code:
__int64 __fastcall stap_reader_start(int *a1)
{
__pid_t v1; // eax
unsigned int v2; // eax
__int64 result; // rax
int v4; // er12
int v5; // er12
char *v6[3]; // [rsp+0h] [rbp-58h] BYREF
char *ptr; // [rsp+18h] [rbp-40h] BYREF
char *v8; // [rsp+20h] [rbp-38h] BYREF
char *v9[6]; // [rsp+28h] [rbp-30h] BYREF

if ( pipe2(a1 + 2, 0) < 0 )
{
v4 = *_errno_location();
perror("pipe");
result = (unsigned int)-v4;
}
else
{
v1 = fork();
if ( v1 < 0 )
{
v5 = *_errno_location();
perror("fork");
close(a1[2]);
close(a1[3]);
result = (unsigned int)-v5;
}
else
{
if ( !v1 )
{
close(a1[2]);
if ( dup2(a1[3], 1) >= 0 )
{
v6[0] = "stap";
v6[1] = "-g";
v6[2] = "lat.stp";
asprintf(&ptr, "%llu", arg_min_delay);
asprintf(&v8, "%llu", arg_max_interruptible_delay);
asprintf(v9, "%d", arg_pid_filter);
v9[1] = 0LL;
execvp("stap", v6);
perror("Failed to execute 'stap'");
exit(1);
}
perror("dup2");
exit(1);
}
a1[4] = v1;
close(a1[3]);
v2 = fcntl(a1[2], 3, 0LL);
BYTE1(v2) |= 8u;
fcntl(a1[2], 4, v2);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1)
{
__pid_t v1; // eax
unsigned int v2; // eax
__int64 result; // rax
int v4; // er12
int v5; // er12
char *v6[3]; // [rsp+0h] [rbp-58h] BYREF
char *ptr; // [rsp+18h] [rbp-40h] BYREF
char *v8; // [rsp+20h] [rbp-38h] BYREF
char *v9[6]; // [rsp+28h] [rbp-30h] BYREF

if ( pipe2(a1 + 2, 0) < 0 )
{
v4 = *_errno_location();
perror("pipe");
result = (unsigned int)-v4;
}
else
{
v1 = fork();
if ( v1 < 0 )
{
v5 = *_errno_location();
perror("fork");
close(a1[2]);
close(a1[3]);
result = (unsigned int)-v5;
}
else
{
if ( !v1 )
{
close(a1[2]);
if ( dup2(a1[3], 1) >= 0 )
{
v6[0] = "stap";
v6[1] = "-g";
v6[2] = "lat.stp";
asprintf(&ptr, "%llu", arg_min_delay);
asprintf(&v8, "%llu", arg_max_interruptible_delay);
asprintf(v9, "%d", arg_pid_filter);
v9[1] = 0LL;
execvp("stap", v6);
perror("Failed to execute 'stap'");
exit(1);
}
perror("dup2");
exit(1);
}
a1[4] = v1;
close(a1[3]);
v2 = fcntl(a1[2], 3, 0LL);
BYTE1(v2) |= 8u;
fcntl(a1[2], 4, v2);
result = 0LL;
}
}
return result;
}

original_code:
static int stap_reader_start(struct polled_reader *pr)
{
 struct stap_reader *sr = (struct stap_reader*) pr;
 pid_t pid;
 int r;
 r = pipe2(sr->pipe, 0);
 if (r < 0) {
  r = -(*__errno_location ());
  perror("pipe");
  goto out_pipe;
 }
 pid = fork();
 if (pid < 0) {
  r = -(*__errno_location ());
  perror("fork");
  goto out_fork;
 }
 if (pid == 0) {
  char *argv[7];
  unsigned n;
  close(sr->pipe[0]);
  r = dup2(sr->pipe[1], 1);
  if (r < 0) {
   perror("dup2");
   exit(1);
  }
  n = 0;
  argv[n++] = "stap";
  argv[n++] = "-g";
  argv[n++] = "lat.stp";
  asprintf(&argv[n++], "%llu", arg_min_delay);
  asprintf(&argv[n++], "%llu", arg_max_interruptible_delay);
  asprintf(&argv[n++], "%d", arg_pid_filter);
  argv[n++] = ((void *)0);
  execvp("stap", argv);
  perror("Failed to execute 'stap'");
  exit(1);
 }
 sr->stap_pid = pid;
 close(sr->pipe[1]);
 fcntl(sr->pipe[0], 4,
       fcntl(sr->pipe[0], 3, 0) | 04000);
 return 0;
out_fork:
 close(sr->pipe[0]);
 close(sr->pipe[1]);
out_pipe:
 return r;
}

canonical_original_code:
static int stap_reader_start(struct polled_reader *pr)
{
 struct stap_reader *sr = (struct stap_reader*) pr;
 int pid;
 int r;
 r = pipe2(sr->pipe, 0);
 if (r < 0) {
  r = -(*__errno_location ());
  perror("pipe");
  goto out_pipe;
 }
 pid = fork();
 if (pid < 0) {
  r = -(*__errno_location ());
  perror("fork");
  goto out_fork;
 }
 if (pid == 0) {
  char *argv[7];
  unsigned int n;
  close(sr->pipe[0]);
  r = dup2(sr->pipe[1], 1);
  if (r < 0) {
   perror("dup2");
   exit(1);
  }
  n = 0;
  argv[n++] = "stap";
  argv[n++] = "-g";
  argv[n++] = "lat.stp";
  asprintf(&argv[n++], "%llu", arg_min_delay);
  asprintf(&argv[n++], "%llu", arg_max_interruptible_delay);
  asprintf(&argv[n++], "%d", arg_pid_filter);
  argv[n++] = ((void *)0);
  execvp("stap", argv);
  perror("Failed to execute 'stap'");
  exit(1);
 }
 sr->stap_pid = pid;
 close(sr->pipe[1]);
 fcntl(sr->pipe[0], 4,
       fcntl(sr->pipe[0], 3, 0) | 04000);
 return 0;
out_fork:
 close(sr->pipe[0]);
 close(sr->pipe[1]);
out_pipe:
 return r;
}

variable_types: pid int

variable_types: r int

variable_types:
argv
char *[7]

variable_types:
n
unsigned int


decompiled_code:
void __fastcall stap_reader_fini(__int64 a1)
{
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( *(_DWORD *)(a1 + 16) )
{
close(*(_DWORD *)(a1 + 8));
kill(*(_DWORD *)(a1 + 16), 15);
kill(*(_DWORD *)(a1 + 16), 18);
while ( waitpid(*(_DWORD *)(a1 + 16), stat_loc, 0) >= 0 || *_errno_location() == 4 )
{
if ( (stat_loc[0] & 0x7F) == 0 || (char)((stat_loc[0] & 0x7F) + 1) > 1 )
goto LABEL_2;
}
perror("waitpid");
}
LABEL_2:
free(*(void **)(a1 + 24));
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( *(_DWORD *)(a1 + 16) )
{
close(*(_DWORD *)(a1 + 8));
kill(*(_DWORD *)(a1 + 16), 15);
kill(*(_DWORD *)(a1 + 16), 18);
while ( waitpid(*(_DWORD *)(a1 + 16), stat_loc, 0) >= 0 || *_errno_location() == 4 )
{
if ( (stat_loc[0] & 0x7F) == 0 || (char)((stat_loc[0] & 0x7F) + 1) > 1 )
goto LABEL_2;
}
perror("waitpid");
}
LABEL_2:
free(*(void **)(a1 + 24));
}

original_code:
static void stap_reader_fini(struct polled_reader *pr)
{
 struct stap_reader *sr = (struct stap_reader*) pr;
 if (sr->stap_pid) {
  int r, status;
  close(sr->pipe[0]);
  kill(sr->stap_pid, 15);
  kill(sr->stap_pid, 18);
  do {
   r = waitpid(sr->stap_pid, &status, 0);
   if (r < 0 && (*__errno_location ()) != 4) {
    perror("waitpid");
    break;
   }
  } while (!(((status) & 0x7f) == 0) && !(((signed char) (((status) & 0x7f) + 1) >> 1) > 0));
 }
 free(sr->line);
}

canonical_original_code:
static void stap_reader_fini(struct polled_reader *pr)
{
 struct stap_reader *sr = (struct stap_reader*) pr;
 if (sr->stap_pid) {
  int r; int status;
  close(sr->pipe[0]);
  kill(sr->stap_pid, 15);
  kill(sr->stap_pid, 18);
  do {
   r = waitpid(sr->stap_pid, &status, 0);
   if (r < 0 && (*__errno_location ()) != 4) {
    perror("waitpid");
    break;
   }
  } while (!(((status) & 0x7f) == 0) && !(((char) (((status) & 0x7f) + 1) >> 1) > 0));
 }
 free(sr->line);
}

variable_types: status int


original_code:
static ssize_t get_next_line(struct stap_reader *sr)
{
 char *start = sr->buf + sr->start;
 char *eol, *p;
 unsigned line_len;
 eol = bufchr(sr, '\n');
 if (!eol)
  return -2;
 line_len = eol - start + 1;
 if (eol < start)
  line_len += sizeof(sr->buf);
 if (sr->len <= line_len) {
  char *reallocd_line;
  reallocd_line = realloc(sr->line, line_len + 1);
  if (!reallocd_line)
   return -12;
  sr->line = reallocd_line;
  sr->len = line_len + 1;
 }
 if (eol >= start) {
  p = mempcpy(sr->line, start, line_len);
  *p = '\0';
 } else {
  unsigned first_part_len = sizeof(sr->buf) - sr->start;
  p = mempcpy(sr->line, start, first_part_len);
  p = mempcpy(p, sr->buf, line_len - first_part_len);
  *p = '\0';
 }
 sr->start = eol - sr->buf + 1;
 if (sr->start == sizeof(sr->buf))
  sr->start = 0;
 sr->fill_count -= line_len;
 return line_len;
}

canonical_original_code:
static long get_next_line(struct stap_reader *sr)
{
 char *start = sr->buf + sr->start;
 char *eol; char *p;
 unsigned int line_len;
 eol = bufchr(sr, '\n');
 if (!eol)
  return -2;
 line_len = eol - start + 1;
 if (eol < start)
  line_len += sizeof(sr->buf);
 if (sr->len <= line_len) {
  char *reallocd_line;
  reallocd_line = realloc(sr->line, line_len + 1);
  if (!reallocd_line)
   return -12;
  sr->line = reallocd_line;
  sr->len = line_len + 1;
 }
 if (eol >= start) {
  p = mempcpy(sr->line, start, line_len);
  *p = '\0';
 } else {
  unsigned int first_part_len = sizeof(sr->buf) - sr->start;
  p = mempcpy(sr->line, start, first_part_len);
  p = mempcpy(p, sr->buf, line_len - first_part_len);
  *p = '\0';
 }
 sr->start = eol - sr->buf + 1;
 if (sr->start == sizeof(sr->buf))
  sr->start = 0;
 sr->fill_count -= line_len;
 return line_len;
}

variable_types:
start
char *

variable_types:
eol
char *


original_code:
static int read_all_lines(struct stap_reader *sr)
{
 ssize_t n;
 char *str;
 struct back_trace bt;
 int depth;
 int nread;
 _Bool end_of_trace;
 for (;;) {
  n = get_next_line(sr);
  if (n < 0) {
   if (n == -2)
    return 0;
   return n;
  }
  switch (sr->state) {
  case STAP_STARTING:
   if (strcmp(sr->line, "lat begin\n"))
    return -22;
   lattop_reader_started(&sr->pr);
   sr->state = STAP_WANT_PROC_INFO;
   break;
  case STAP_WANT_PROC_INFO:
   if (sscanf(sr->line, "%c %lu %lu %lu %15[^\n]", &sr->sleep_or_block, &sr->delay, &sr->pid, &sr->tid, sr->comm) != 5) {
    fprintf(stderr, "Malformed input line.\n");
    return -22;
   }
   sr->state = STAP_WANT_LATENCY;
   break;
  case STAP_WANT_LATENCY:
   str = sr->line;
   end_of_trace = 0;
   for (depth = 0; depth < 12; depth++) {
    if (end_of_trace) {
     bt.trace[depth] = 0;
     continue;
    }
    if (sscanf(str, "%lx%n", &bt.trace[depth], &nread) == 1)
     str += nread;
    else {
     bt.trace[depth] = 0;
     end_of_trace = 1;
    }
   }
   pa_account_latency(sr->pid, sr->tid, sr->comm, sr->delay, &bt);
   sr->state = STAP_WANT_PROC_INFO;
   break;
  }
 }
}

canonical_original_code:
static int read_all_lines(struct stap_reader *sr)
{
 long n;
 char *str;
 struct back_trace bt;
 int depth;
 int nread;
 _Bool end_of_trace;
 for (;;) {
  n = get_next_line(sr);
  if (n < 0) {
   if (n == -2)
    return 0;
   return n;
  }
  switch (sr->state) {
  case STAP_STARTING:
   if (strcmp(sr->line, "lat begin\n"))
    return -22;
   lattop_reader_started(&sr->pr);
   sr->state = STAP_WANT_PROC_INFO;
   break;
  case STAP_WANT_PROC_INFO:
   if (sscanf(sr->line, "%c %lu %lu %lu %15[^\n]", &sr->sleep_or_block, &sr->delay, &sr->pid, &sr->tid, sr->comm) != 5) {
    fprintf(stderr, "Malformed input line.\n");
    return -22;
   }
   sr->state = STAP_WANT_LATENCY;
   break;
  case STAP_WANT_LATENCY:
   str = sr->line;
   end_of_trace = 0;
   for (depth = 0; depth < 12; depth++) {
    if (end_of_trace) {
     bt.trace[depth] = 0;
     continue;
    }
    if (sscanf(str, "%lx%n", &bt.trace[depth], &nread) == 1)
     str += nread;
    else {
     bt.trace[depth] = 0;
     end_of_trace = 1;
    }
   }
   pa_account_latency(sr->pid, sr->tid, sr->comm, sr->delay, &bt);
   sr->state = STAP_WANT_PROC_INFO;
   break;
  }
 }
}

variable_types: n long

variable_types:
str
char *

variable_types: struct back_trace { unsigned long trace[12]; }

variable_types: depth int

variable_types: nread int


decompiled_code:
__int64 __fastcall stap_reader_handle_ready_fd(__int64 a1)
{
int v1; // ebp
ssize_t v2; // rax
__int64 result; // rax

v1 = 100;
while ( 1 )
{
v2 = buf_refill(a1);
if ( v2 == -11 )
return 0LL;
if ( !v2 )
return 0xFFFFFFFFLL;
if ( v2 == -28 )
break;
result = read_all_lines(a1);
if ( (int)result < 0 )
return result;
if ( !--v1 )
return 0LL;
}
fwrite("No space in read buffer before refilling. Weird.\n", 1uLL, 0x31uLL, stderr);
result = 0LL;
*(_DWORD *)(a1 + 65580) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v1; // ebp
ssize_t v2; // rax
__int64 result; // rax

v1 = 100;
while ( 1 )
{
v2 = func1(a1);
if ( v2 == -11 )
return 0LL;
if ( !v2 )
return 0xFFFFFFFFLL;
if ( v2 == -28 )
break;
result = func6(a1);
if ( (int)result < 0 )
return result;
if ( !--v1 )
return 0LL;
}
fwrite("No space in read buffer before refilling. Weird.\n", 1uLL, 0x31uLL, stderr);
result = 0LL;
*(_DWORD *)(a1 + 65580) = 0;
return result;
}

original_code:
static int stap_reader_handle_ready_fd(struct polled_reader *pr)
{
 struct stap_reader *sr = (struct stap_reader*) pr;
 ssize_t refill_result;
 int r, i;
 for (i = 0; i < 100; i++) {
  refill_result = buf_refill(sr);
  switch (refill_result) {
  case 0:
   return -1;
  case -11:
   return 0;
  case -28:
   fprintf(stderr, "No space in read buffer before refilling. Weird.\n");
   sr->fill_count = 0;
   return 0;
  default:;
  }
  r = read_all_lines(sr);
  if (r < 0)
   return r;
 }
 return 0;
}

canonical_original_code:
static int stap_reader_handle_ready_fd(struct polled_reader *pr)
{
 struct stap_reader *sr = (struct stap_reader*) pr;
 long refill_result;
 int r; int i;
 for (i = 0; i < 100; i++) {
  refill_result = buf_refill(sr);
  switch (refill_result) {
  case 0:
   return -1;
  case -11:
   return 0;
  case -28:
   fprintf(stderr, "No space in read buffer before refilling. Weird.\n");
   sr->fill_count = 0;
   return 0;
  default:;
  }
  r = read_all_lines(sr);
  if (r < 0)
   return r;
 }
 return 0;
}

variable_types: struct polled_reader { struct polled_reader_ops { void (*fini)(struct polled_reader *pr); int (*start)(struct polled_reader *pr); int (*get_fd)(struct polled_reader *pr); int (*handle_ready_fd)(struct polled_reader *pr); } *ops; } *

variable_types: struct stap_reader { struct polled_reader { struct polled_reader_ops { void (*fini)(struct polled_reader *pr); int (*start)(struct polled_reader *pr); int (*get_fd)(struct polled_reader *pr); int (*handle_ready_fd)(struct polled_reader *pr); } *ops; } pr; int pipe[2]; int stap_pid; enum { STAP_STARTING=0, STAP_WANT_PROC_INFO=1, STAP_WANT_LATENCY=2 } state; char *line; unsigned long len; char buf[-1]; unsigned int start; char comm[16]; unsigned long delay; unsigned long pid; unsigned long tid; char sleep_or_block; } *

variable_types: i int


decompiled_code:
_QWORD *stap_reader_new()
{
_QWORD *result; // rax

result = calloc(1uLL, 0x10060uLL);
if ( result )
*result = stap_reader_ops;
return result;
}

canonical_decompiled_code:
_QWORD *func8()
{
_QWORD *result; // rax

result = calloc(1uLL, 0x10060uLL);
if ( result )
*result = stap_reader_ops;
return result;
}

original_code:
struct polled_reader *stap_reader_new(void)
{
 struct stap_reader *r;
 r = calloc(1, sizeof(struct stap_reader));
 if (r == ((void *)0))
  return ((void *)0);
 r->pr.ops = &stap_reader_ops;
 return &r->pr;
}

canonical_original_code:
struct polled_reader *stap_reader_new()
{
 struct stap_reader *r;
 r = calloc(1, sizeof(struct stap_reader));
 if (r == ((void *)0))
  return ((void *)0);
 r->pr.ops = &stap_reader_ops;
 return &r->pr;
}

return_type: struct polled_reader { struct polled_reader_ops { void (*fini)(struct polled_reader *pr); int (*start)(struct polled_reader *pr); int (*get_fd)(struct polled_reader *pr); int (*handle_ready_fd)(struct polled_reader *pr); } *ops; } *


decompiled_code:
unsigned __int64 __fastcall rb_set_color(unsigned __int64 *a1, int a2)
{
unsigned __int64 result; // rax

result = a2 | *a1 & 0xFFFFFFFFFFFFFFFELL;
*a1 = result;
return result;
}

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

result = a2 | *a1 & 0xFFFFFFFFFFFFFFFELL;
*a1 = result;
return result;
}

original_code:
static inline void rb_set_color(struct rb_node *rb, int color)
{
 rb->rb_parent_color = (rb->rb_parent_color & ~1) | color;
}

variable_types: struct rb_node { unsigned long rb_parent_color; struct rb_node *rb_right; struct rb_node *rb_left; } *

variable_types: color int


original_code:
struct rb_node *rb_first(const struct rb_root *root)
{
 struct rb_node *n;
 n = root->rb_node;
 if (!n)
  return ((void *)0);
 while (n->rb_left)
  n = n->rb_left;
 return n;
}

canonical_original_code:
struct rb_node *rb_first(struct rb_root *root)
{
 struct rb_node *n;
 n = root->rb_node;
 if (!n)
  return ((void *)0);
 while (n->rb_left)
  n = n->rb_left;
 return n;
}

variable_types: struct rb_root { struct rb_node *rb_node; } *

return_type: struct rb_node { unsigned long rb_parent_color; struct rb_node *rb_right; struct rb_node *rb_left; } *


original_code:
struct rb_node *rb_last(const struct rb_root *root)
{
 struct rb_node *n;
 n = root->rb_node;
 if (!n)
  return ((void *)0);
 while (n->rb_right)
  n = n->rb_right;
 return n;
}

canonical_original_code:
struct rb_node *rb_last(struct rb_root *root)
{
 struct rb_node *n;
 n = root->rb_node;
 if (!n)
  return ((void *)0);
 while (n->rb_right)
  n = n->rb_right;
 return n;
}

user_defined_types: struct rb_root { struct rb_node *rb_node; }


decompiled_code:
unsigned __int64 __fastcall rb_next(__int64 *a1)
{
__int64 v1; // rdx
unsigned __int64 v2; // rax
unsigned __int64 v3; // r8
__int64 *v5; // rax

v1 = *a1;
if ( a1 == (__int64 *)(*a1 & 0xFFFFFFFFFFFFFFFCLL) )
return 0LL;
v2 = a1[1];
if ( v2 )
{
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
return v3;
}
while ( 1 )
{
v5 = (__int64 *)(v1 & 0xFFFFFFFFFFFFFFFCLL);
v3 = v1 & 0xFFFFFFFFFFFFFFFCLL;
if ( (v1 & 0xFFFFFFFFFFFFFFFCLL) == 0 )
break;
if ( (__int64 *)v5[1] != a1 )
return v3;
v1 = *v5;
a1 = v5;
}
return 0LL;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 *a1)
{
__int64 v1; // rdx
unsigned __int64 v2; // rax
unsigned __int64 v3; // r8
__int64 *v5; // rax

v1 = *a1;
if ( a1 == (__int64 *)(*a1 & 0xFFFFFFFFFFFFFFFCLL) )
return 0LL;
v2 = a1[1];
if ( v2 )
{
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 );
return v3;
}
while ( 1 )
{
v5 = (__int64 *)(v1 & 0xFFFFFFFFFFFFFFFCLL);
v3 = v1 & 0xFFFFFFFFFFFFFFFCLL;
if ( (v1 & 0xFFFFFFFFFFFFFFFCLL) == 0 )
break;
if ( (__int64 *)v5[1] != a1 )
return v3;
v1 = *v5;
a1 = v5;
}
return 0LL;
}

original_code:
struct rb_node *rb_next(const struct rb_node *node)
{
 struct rb_node *parent;
 if (((struct rb_node *)((node)->rb_parent_color & ~3)) == node)
  return ((void *)0);
 if (node->rb_right) {
  node = node->rb_right;
  while (node->rb_left)
   node=node->rb_left;
  return (struct rb_node *)node;
 }
 while ((parent = ((struct rb_node *)((node)->rb_parent_color & ~3))) && node == parent->rb_right)
  node = parent;
 return parent;
}

canonical_original_code:
struct rb_node *rb_next(struct rb_node *node)
{
 struct rb_node *parent;
 if (((struct rb_node *)((node)->rb_parent_color & ~3)) == node)
  return ((void *)0);
 if (node->rb_right) {
  node = node->rb_right;
  while (node->rb_left)
   node=node->rb_left;
  return (struct rb_node *)node;
 }
 while ((parent = ((struct rb_node *)((node)->rb_parent_color & ~3))) && node == parent->rb_right)
  node = parent;
 return parent;
}

variable_types:
node
struct rb_node *


decompiled_code:
unsigned __int64 __fastcall rb_prev(__int64 *a1)
{
__int64 v1; // rdx
unsigned __int64 v2; // rax
unsigned __int64 v3; // r8
__int64 *v5; // rax

v1 = *a1;
if ( a1 == (__int64 *)(*a1 & 0xFFFFFFFFFFFFFFFCLL) )
return 0LL;
v2 = a1[2];
if ( v2 )
{
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
return v3;
}
while ( 1 )
{
v5 = (__int64 *)(v1 & 0xFFFFFFFFFFFFFFFCLL);
v3 = v1 & 0xFFFFFFFFFFFFFFFCLL;
if ( (v1 & 0xFFFFFFFFFFFFFFFCLL) == 0 )
break;
if ( (__int64 *)v5[2] != a1 )
return v3;
v1 = *v5;
a1 = v5;
}
return 0LL;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(__int64 *a1)
{
__int64 v1; // rdx
unsigned __int64 v2; // rax
unsigned __int64 v3; // r8
__int64 *v5; // rax

v1 = *a1;
if ( a1 == (__int64 *)(*a1 & 0xFFFFFFFFFFFFFFFCLL) )
return 0LL;
v2 = a1[2];
if ( v2 )
{
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
return v3;
}
while ( 1 )
{
v5 = (__int64 *)(v1 & 0xFFFFFFFFFFFFFFFCLL);
v3 = v1 & 0xFFFFFFFFFFFFFFFCLL;
if ( (v1 & 0xFFFFFFFFFFFFFFFCLL) == 0 )
break;
if ( (__int64 *)v5[2] != a1 )
return v3;
v1 = *v5;
a1 = v5;
}
return 0LL;
}

original_code:
struct rb_node *rb_prev(const struct rb_node *node)
{
 struct rb_node *parent;
 if (((struct rb_node *)((node)->rb_parent_color & ~3)) == node)
  return ((void *)0);
 if (node->rb_left) {
  node = node->rb_left;
  while (node->rb_right)
   node=node->rb_right;
  return (struct rb_node *)node;
 }
 while ((parent = ((struct rb_node *)((node)->rb_parent_color & ~3))) && node == parent->rb_left)
  node = parent;
 return parent;
}

canonical_original_code:
struct rb_node *rb_prev(struct rb_node *node)
{
 struct rb_node *parent;
 if (((struct rb_node *)((node)->rb_parent_color & ~3)) == node)
  return ((void *)0);
 if (node->rb_left) {
  node = node->rb_left;
  while (node->rb_right)
   node=node->rb_right;
  return (struct rb_node *)node;
 }
 while ((parent = ((struct rb_node *)((node)->rb_parent_color & ~3))) && node == parent->rb_left)
  node = parent;
 return parent;
}


original_code:
void rb_replace_node(struct rb_node *victim, struct rb_node *new,
       struct rb_root *root)
{
 struct rb_node *parent = ((struct rb_node *)((victim)->rb_parent_color & ~3));
 if (parent) {
  if (victim == parent->rb_left)
   parent->rb_left = new;
  else
   parent->rb_right = new;
 } else {
  root->rb_node = new;
 }
 if (victim->rb_left)
  rb_set_parent(victim->rb_left, new);
 if (victim->rb_right)
  rb_set_parent(victim->rb_right, new);
 *new = *victim;
}

variable_types:
new
struct rb_node *


decompiled_code:
_QWORD *new_slab()
{
_QWORD *result; // rax

result = mmap(0LL, 0x100000uLL, 3, 34, -1, 0LL);
if ( result == (_QWORD *)-1LL )
return 0LL;
result[1] = 0LL;
*result = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *result; // rax

result = mmap(0LL, 0x100000uLL, 3, 34, -1, 0LL);
if ( result == (_QWORD *)-1LL )
return 0LL;
result[1] = 0LL;
*result = 0LL;
return result;
}

original_code:
static struct symbol_slab *new_slab(void)
{
 struct symbol_slab *ss;
 ss = mmap(((void *)0), (1024*1024), 0x1|0x2, 0x02|0x20, -1, 0);
 if (ss == ((void *) -1))
  return ((void *)0);
 ss->fill_count = 0;
 ss->next = ((void *)0);
 return ss;
}

canonical_original_code:
static struct symbol_slab *new_slab()
{
 struct symbol_slab *ss;
 ss = mmap(((void *)0), (1024*1024), 0x1|0x2, 0x02|0x20, -1, 0);
 if (ss == ((void *) -1))
  return ((void *)0);
 ss->fill_count = 0;
 ss->next = ((void *)0);
 return ss;
}

variable_types: struct symbol_slab { struct symbol_slab *next; unsigned long fill_count; struct symbol { struct rb_node { unsigned long rb_parent_color; struct rb_node *rb_right; struct rb_node *rb_left; } rb_node; unsigned long addr; long name_offset; } symbols[]; } *

user_defined_types: struct symbol_slab { struct symbol_slab *next; unsigned long fill_count; struct symbol symbols[]; }

user_defined_types: struct symbol { struct rb_node rb_node; unsigned long addr; long name_offset; }


decompiled_code:
__int64 __fastcall new_symbol(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rax
__int64 v6; // r8
_QWORD *v7; // rbx
_QWORD *v9; // rax
__int64 v10; // rdx
_QWORD *v11; // rax

if ( !first_slab )
{
v11 = new_slab();
v2 = v11;
if ( v11 )
{
first_slab = v11;
v3 = v11[1];
current_slab = (__int64)v2;
goto LABEL_3;
}
return 0LL;
}
v2 = (_QWORD *)current_slab;
v3 = *(_QWORD *)(current_slab + 8);
if ( v3 == 26214 )
{
v9 = new_slab();
v10 = (__int64)v9;
if ( v9 )
{
*v2 = v9;
v3 = v9[1];
v2 = (_QWORD *)v10;
current_slab = v10;
goto LABEL_3;
}
return 0LL;
}
LABEL_3:
v4 = v3 + 1;
v5 = 5 * v3;
v2[1] = v4;
v6 = (__int64)&v2[v5 + 2];
v7 = &v2[v5];
v7[5] = a1;
v7[6] = a2;
return v6;
}

original_code:
static struct symbol *new_symbol(unsigned long addr, ptrdiff_t name_offset)
{
 struct symbol_slab *ss;
 struct symbol *s;
 if (!first_slab || current_slab->fill_count == (((1024*1024) - sizeof(struct symbol_slab)) / sizeof(struct symbol))) {
  ss = new_slab();
  if (!ss)
   return ((void *)0);
  if (!first_slab)
   current_slab = first_slab = ss;
  else {
   current_slab->next = ss;
   current_slab = ss;
  }
 }
 s = &current_slab->symbols[current_slab->fill_count++];
 s->addr = addr;
 s->name_offset = name_offset;
 return s;
}

canonical_original_code:
static struct symbol *new_symbol(unsigned long addr, long name_offset)
{
 struct symbol_slab *ss;
 struct symbol *s;
 if (!first_slab || current_slab->fill_count == (((1024*1024) - sizeof(struct symbol_slab)) / sizeof(struct symbol))) {
  ss = new_slab();
  if (!ss)
   return ((void *)0);
  if (!first_slab)
   current_slab = first_slab = ss;
  else {
   current_slab->next = ss;
   current_slab = ss;
  }
 }
 s = &current_slab->symbols[current_slab->fill_count++];
 s->addr = addr;
 s->name_offset = name_offset;
 return s;
}

variable_types:
addr
unsigned long

variable_types: struct symbol { struct rb_node { unsigned long rb_parent_color; struct rb_node *rb_right; struct rb_node *rb_left; } rb_node; unsigned long addr; long name_offset; } *


decompiled_code:
__int64 __fastcall undo_new_symbol(__int64 a1)
{
__int64 v1; // rdx
__int64 v2; // rax
__int64 v3; // rax
__int64 result; // rax

v1 = current_slab;
v2 = *(_QWORD *)(current_slab + 8);
if ( !v2 )
_assert_fail("current_slab->fill_count > 0", "sym_translator.c", 0x87u, "undo_new_symbol");
v3 = v2 - 1;
*(_QWORD *)(current_slab + 8) = v3;
result = v1 + 40 * v3 + 16;
if ( a1 != result )
_assert_fail("&current_slab->symbols[current_slab->fill_count] == s", "sym_translator.c", 0x89u, "undo_new_symbol");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rdx
__int64 v2; // rax
__int64 v3; // rax
__int64 result; // rax

v1 = current_slab;
v2 = *(_QWORD *)(current_slab + 8);
if ( !v2 )
_assert_fail("current_slab->fill_count > 0", "sym_translator.c", 0x87u, "undo_new_symbol");
v3 = v2 - 1;
*(_QWORD *)(current_slab + 8) = v3;
result = v1 + 40 * v3 + 16;
if ( a1 != result )
_assert_fail("&current_slab->symbols[current_slab->fill_count] == s", "sym_translator.c", 0x89u, "undo_new_symbol");
return result;
}

original_code:
static void undo_new_symbol(struct symbol *s)
{
 ((void) sizeof ((current_slab->fill_count > 0) ? 1 : 0), __extension__ ({ if (current_slab->fill_count > 0) ; else __assert_fail ("current_slab->fill_count > 0", "sym_translator.c", 135, __extension__ __PRETTY_FUNCTION__); }));
 current_slab->fill_count--;
 ((void) sizeof ((&current_slab->symbols[current_slab->fill_count] == s) ? 1 : 0), __extension__ ({ if (&current_slab->symbols[current_slab->fill_count] == s) ; else __assert_fail ("&current_slab->symbols[current_slab->fill_count] == s", "sym_translator.c", 137, __extension__ __PRETTY_FUNCTION__); }));
}