repo: notfed/trybloop

decompiled_code:
__int64 __fastcall beep_head_callback(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, _DWORD *a6)
{
__int64 i; // rbp

if ( !a3 )
return 0LL;
for ( i = 0LL; i != a3; ++i )
{
*(float *)(a2 + 4 * i) = (*(float (__fastcall **)(_DWORD *))(*(_QWORD *)a6 + 16LL))(a6);
++a6[2];
}
return 0LL;
}

original_code:
static int beep_head_callback(
 const void *inputBuffer,
 void *outputBuffer,
 unsigned long framesPerBuffer,
 const PaStreamCallbackTimeInfo* timeInfo,
 PaStreamCallbackFlags statusFlags,
 void *data)
{
       beep_head* head = (beep_head*)(data);
       float *buffer = (float*)outputBuffer;
       for(int frame = 0; frame < framesPerBuffer; frame++)
       {
           buffer[frame] = head->note->waveform(head);
           head->frame++;
       }
       return paContinue;
}

canonical_original_code:
static int beep_head_callback(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, struct PaStreamCallbackTimeInfo *timeInfo, unsigned long statusFlags, void *data)
{
       struct beep_head *head = (beep_head*)(data);
       float *buffer = (float*)outputBuffer;
       for(int frame = 0; frame < framesPerBuffer; frame++)
       {
           buffer[frame] = head->note->waveform(head);
           head->frame++;
       }
       return paContinue;
}

variable_types:
inputBuffer
void *

variable_types:
outputBuffer
void *

variable_types:
framesPerBuffer
unsigned long

variable_types: struct PaStreamCallbackTimeInfo { double inputBufferAdcTime; double currentTime; double outputBufferDacTime; } *

variable_types:
statusFlags
unsigned long

variable_types:
data
void *

variable_types: struct beep_head { struct beep_note { float frequency; float amplitude; float duration; float (*waveform)(struct beep_head *); } *note; int frame; } *

variable_types:
buffer
float *

variable_types: frame int

user_defined_types: struct beep_head { struct beep_note *note; int frame; }


original_code:
static float beep_waveform_sine(beep_head *head)
{
   beep_note *note = head->note;
   return note->amplitude * sin(2 * 3.14159265358979323846 * note->frequency * head->frame / 44100);
}

canonical_original_code:
static float beep_waveform_sine(struct beep_head *head)
{
   struct beep_note *note = head->note;
   return note->amplitude * sin(2 * 3.14159265358979323846 * note->frequency * head->frame / 44100);
}

variable_types: struct beep_note { float frequency; float amplitude; float duration; float (*waveform)(struct beep_head { struct beep_note *note; int frame; } *); } *

return_type: float

user_defined_types: struct beep_note { float frequency; float amplitude; float duration; float (*waveform)(struct beep_head *); }


decompiled_code:
__int64 portaudio_init()
{
return Pa_Initialize();
}

canonical_decompiled_code:
__int64 func9()
{
return Pa_Initialize();
}

original_code:
static void portaudio_init() {
    Pa_Initialize();
}

return_type: void


decompiled_code:
__int64 portaudio_teardown()
{
return Pa_Terminate();
}

canonical_decompiled_code:
__int64 func11()
{
return Pa_Terminate();
}

original_code:
static void portaudio_teardown() {
    Pa_Terminate();
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
int result; // eax
int v5[4]; // [rsp+0h] [rbp-28h] BYREF
float (__fastcall *v6)(__int64); // [rsp+10h] [rbp-18h]
int v7; // [rsp+1Ch] [rbp-Ch]

v7 = 0;
if ( argc == 2 && (v3 = argv[1], (int)__isoc99_sscanf() >= 0) )
{
portaudio_init(v3, &unk_402004);
v5[0] = v7;
v5[1] = 1065353216;
v5[2] = 1148846080;
v6 = beep_waveform_sine;
beep_note_play(v5);
portaudio_teardown();
result = 0;
}
else
{
puts("beep: error: usage: beep freq");
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
int result; // eax
int v5[4]; // [rsp+0h] [rbp-28h] BYREF
float (__fastcall *v6)(__int64); // [rsp+10h] [rbp-18h]
int v7; // [rsp+1Ch] [rbp-Ch]

v7 = 0;
if ( argc == 2 && (v3 = argv[1], (int)__isoc99_sscanf() >= 0) )
{
func9(v3, &unk_402004);
v5[0] = v7;
v5[1] = 1065353216;
v5[2] = 1148846080;
v6 = beep_waveform_sine;
func10(v5);
func11();
result = 0;
}
else
{
puts("beep: error: usage: beep freq");
result = 1;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
    float freq = 0;
    if(argc != 2 || sscanf(argv[1],"%f",&freq)<0)
    {
       printf("beep: error: usage: beep freq\n");
       return 1;
    }
    portaudio_init();
    beep_note note = {
       .frequency = freq,
       .amplitude = 1.0,
       .duration = 1000,
       .waveform = beep_waveform_sine
    };
    beep_note_play(&note);
    portaudio_teardown();
}

canonical_original_code:
int main(int argc, char *argv[])
{
    float freq = 0;
    if(argc != 2 || sscanf(argv[1],"%f",&freq)<0)
    {
       printf("beep: error: usage: beep freq\n");
       return 1;
    }
    portaudio_init();
    struct beep_note note = {
       .frequency = freq,
       .amplitude = 1.0,
       .duration = 1000,
       .waveform = beep_waveform_sine
    };
    beep_note_play(&note);
    portaudio_teardown();
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: freq float

variable_types: struct beep_note { float frequency; float amplitude; float duration; float (*waveform)(struct beep_head { struct beep_note *note; int frame; } *); }

return_type: int


repo: novalis/cexpr

decompiled_code:
__int64 __fastcall dump_tree(char *s)
{
__int64 v1; // rax
_QWORD *v2; // rbx
size_t v4; // rax
const char *v5; // rbp

v1 = parse(s, 0LL);
v2 = (_QWORD *)v1;
if ( *(_DWORD *)v1 )
{
printf("Error: %s\n", *(const char **)(v1 + 8));
}
else
{
v4 = strlen(s);
v5 = (const char *)malloc(3 * v4 + 1);
write_tree_to_string(v2[1], v5);
puts(v5);
}
return *(unsigned int *)v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s)
{
__int64 v1; // rax
_QWORD *v2; // rbx
size_t v4; // rax
const char *v5; // rbp

v1 = parse(s, 0LL);
v2 = (_QWORD *)v1;
if ( *(_DWORD *)v1 )
{
printf("Error: %s\n", *(const char **)(v1 + 8));
}
else
{
v4 = strlen(s);
v5 = (const char *)malloc(3 * v4 + 1);
write_tree_to_string(v2[1], v5);
puts(v5);
}
return *(unsigned int *)v2;
}

original_code:
static int dump_tree(const char* expr) {
    struct parse_result* result = parse(expr, 0);
    if (result->is_error) {
        printf("Error: %s\n", result->error_message);
    } else {
        char* buf = malloc(strlen(expr) * 3 + 1);
        write_tree_to_string(result->node, buf);
        printf("%s\n", buf);
    }
    return result->is_error;
}

canonical_original_code:
static int dump_tree(char *expr) {
    struct parse_result *result = parse(expr, 0);
    if (result->is_error) {
        printf("Error: %s\n", result->error_message);
    } else {
        char *buf = malloc(strlen(expr) * 3 + 1);
        write_tree_to_string(result->node, buf);
        printf("%s\n", buf);
    }
    return result->is_error;
}

variable_types:
expr
char *

variable_types: struct parse_result { int is_error; union { struct parse_tree_node { enum token_type { LITERAL_OR_ID=1, OPEN_PAREN=2, CLOSE_PAREN=3, OPEN_BRACKET=4, CLOSE_BRACKET=5, OPEN_CURLY=6, CLOSE_CURLY=7, BANG=8, PERCENT=9, CARET=10, AMPERSAND=11, BAR=12, STAR=13, MINUS=14, PLUS=15, SLASH=16, LEFT_SHIFT=17, RIGHT_SHIFT=18, BANG_EQUAL=19, PERCENT_EQUAL=20, CARET_EQUAL=21, AMPERSAND_EQUAL=22, BAR_EQUAL=23, STAR_EQUAL=24, MINUS_EQUAL=25, PLUS_EQUAL=26, SLASH_EQUAL=27, LEFT_SHIFT_EQUAL=28, RIGHT_SHIFT_EQUAL=29, ARROW=30, DOT=31, ASSIGN=32, IS_EQUAL=33, LTE=34, GTE=35, LT=36, GT=37, DOUBLE_AMPERSAND=38, DOUBLE_BAR=39, DOUBLE_PLUS=40, DOUBLE_MINUS=41, QUESTION=42, COLON=43, SIZEOF=44, COMMA=45, TILDE=46, TYPECAST=47, FUNCTION_CALL=48, SUBSCRIPT=49, REFERENCE=50, DEREFERENCE=51, UNARY_MINUS=52, POSTINCREMENT=53, POSTDECREMENT=54, PREINCREMENT=55, PREDECREMENT=56, START_COMMENT=57, BOGUS=58, END_OF_EXPRESSION=59 } op; char *text; struct parse_tree_node *first_child; struct parse_tree_node *next_sibling; } *node; char *error_message; }; struct obstack { long chunk_size; struct _obstack_chunk { char *limit; struct _obstack_chunk *prev; char contents[4]; } *chunk; char *object_base; char *next_free; char *chunk_limit; union { long tempint; void *tempptr; } temp; int alignment_mask; struct _obstack_chunk *(*chunkfun)(void *, long); void (*freefun)(void *, struct _obstack_chunk *); void *extra_arg; unsigned int use_extra_arg; unsigned int maybe_empty_object; unsigned int alloc_failed; } *obstack; } *

variable_types:
buf
char *

user_defined_types: struct parse_result { int is_error; union { struct parse_tree_node *node; char *error_message; }; struct obstack *obstack; }

user_defined_types: struct obstack { long chunk_size; struct _obstack_chunk *chunk; char *object_base; char *next_free; char *chunk_limit; union { long tempint; void *tempptr; } temp; int alignment_mask; struct _obstack_chunk *(*chunkfun)(void *, long); void (*freefun)(void *, struct _obstack_chunk *); void *extra_arg; unsigned int use_extra_arg; unsigned int maybe_empty_object; unsigned int alloc_failed; }

user_defined_types: struct parse_tree_node { enum token_type op; char *text; struct parse_tree_node *first_child; struct parse_tree_node *next_sibling; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc == 2 )
return dump_tree((char *)argv[1]);
puts("Error: must supply a single argument");
return 2;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc == 2 )
return func0((char *)argv[1]);
puts("Error: must supply a single argument");
return 2;
}

original_code:
int main(int argc, char** argv) {
    if (argc != 2) {
        printf("Error: must supply a single argument\n");
        return 2;
    }
    return dump_tree(argv[1]);
}

canonical_original_code:
int main(int argc, char **argv) {
    if (argc != 2) {
        printf("Error: must supply a single argument\n");
        return 2;
    }
    return dump_tree(argv[1]);
}

variable_types:
argv
char **


original_code:
static void add_child_node(struct label *parent, struct label *child) {
    struct label* last_child = parent->first_child;
    if (!last_child) {
        parent->first_child = child;
        return;
    }
    child->number = 1;
    while (last_child->next_sibling) {
        last_child = last_child->next_sibling;
        child->number ++;
    }
    child->prev_sibling = last_child;
    last_child->next_sibling = child;
}

canonical_original_code:
static void add_child_node(struct label *parent, struct label *child) {
    struct label *last_child = parent->first_child;
    if (!last_child) {
        parent->first_child = child;
        return;
    }
    child->number = 1;
    while (last_child->next_sibling) {
        last_child = last_child->next_sibling;
        child->number ++;
    }
    child->prev_sibling = last_child;
    last_child->next_sibling = child;
}

variable_types: struct label { struct label *parent; struct label *prev_sibling; struct label *next_sibling; struct label *first_child; struct label *thread; struct label *ancestor; int number; double change; double shift; char *text; double width; double xcoord; double ycoord; double modifier; } *

variable_types:
child
struct label *


next

decompiled_code:
__int64 __fastcall next(_QWORD *a1)
{
__int64 result; // rax

result = a1[3];
if ( !result )
{
result = a1[2];
if ( !result )
{
while ( 1 )
{
a1 = (_QWORD *)*a1;
if ( !a1 )
break;
result = a1[2];
if ( result )
return result;
}
result = 0LL;
}
}
return result;
}

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

result = a1[3];
if ( !result )
{
result = a1[2];
if ( !result )
{
while ( 1 )
{
a1 = (_QWORD *)*a1;
if ( !a1 )
break;
result = a1[2];
if ( result )
return result;
}
result = 0LL;
}
}
return result;
}

original_code:
static struct label* next(struct label* node) {
    if (node->first_child) {
        return node->first_child;
    }
    if (node->next_sibling) {
        return node->next_sibling;
    }
    while (node->parent) {
        if (node->parent->next_sibling)
            return node->parent->next_sibling;
        node = node->parent;
    }
    return 0;
}

canonical_original_code:
static struct label *next(struct label *node) {
    if (node->first_child) {
        return node->first_child;
    }
    if (node->next_sibling) {
        return node->next_sibling;
    }
    while (node->parent) {
        if (node->parent->next_sibling)
            return node->parent->next_sibling;
        node = node->parent;
    }
    return 0;
}

variable_types:
node
struct label *

return_type: struct label { struct label *parent; struct label *prev_sibling; struct label *next_sibling; struct label *first_child; struct label *thread; struct label *ancestor; int number; double change; double shift; char *text; double width; double xcoord; double ycoord; double modifier; } *


max

decompiled_code:
double __fastcall max(double a1, double a2)
{
return fmax(a1, a2);
}

canonical_decompiled_code:
double __fastcall func2(double a1, double a2)
{
return fmax(a1, a2);
}

original_code:
static double max(double a, double b) {
    return a > b ? a : b;
}

variable_types: a double

variable_types: b double

return_type: double


decompiled_code:
void __fastcall free_label_tree(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 3);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[2];
free(v3);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 3);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[2];
free(v3);
}
free(ptr);
}

original_code:
static void free_label_tree(struct label* label) {
    struct label* child = label->first_child;
    while (child) {
        struct label* next_child = child->next_sibling;
        free(child);
        child = next_child;
    }
    free(label);
}

canonical_original_code:
static void free_label_tree(struct label *label) {
    struct label *child = label->first_child;
    while (child) {
        struct label *next_child = child->next_sibling;
        free(child);
        child = next_child;
    }
    free(label);
}

user_defined_types: struct label { struct label *parent; struct label *prev_sibling; struct label *next_sibling; struct label *first_child; struct label *thread; struct label *ancestor; int number; double change; double shift; char *text; double width; double xcoord; double ycoord; double modifier; }


original_code:
static struct label* make_label(struct parse_tree_node* node,
                         struct label *parent) {
    struct label* label = malloc(sizeof(struct label));
    label->parent = parent;
    label->first_child = 0;
    label->next_sibling = 0;
    label->prev_sibling = 0;
    label->thread = 0;
    label->ancestor = label;
    label->number = 0;
    label->modifier = label->change = label->shift = 0;
    switch (node->op) {
    case LITERAL_OR_ID:
        label->text = strdup(node->text);
        break;
    case TYPECAST:
        label->text = malloc(strlen(node->text) + 3);
        sprintf(label->text, "(%s)", node->text);
        break;
    case FUNCTION_CALL:
        label->text = strdup("function call");
        break;
    default:
        label->text = strdup(token_names[node->op]);
        break;
    }
    label->width = (strlen(label->text) + 2) * 8.4;
    char* old_text = label->text;
    label->text = xml_escape(old_text);
    free(old_text);
    label->xcoord = 500;
    label->ycoord = 0;
    label->modifier = 0;
    return label;
}

canonical_original_code:
static struct label *make_label(struct parse_tree_node *node, struct label *parent) {
    struct label *label = malloc(sizeof(struct label));
    label->parent = parent;
    label->first_child = 0;
    label->next_sibling = 0;
    label->prev_sibling = 0;
    label->thread = 0;
    label->ancestor = label;
    label->number = 0;
    label->modifier = label->change = label->shift = 0;
    switch (node->op) {
    case LITERAL_OR_ID:
        label->text = strdup(node->text);
        break;
    case TYPECAST:
        label->text = malloc(strlen(node->text) + 3);
        sprintf(label->text, "(%s)", node->text);
        break;
    case FUNCTION_CALL:
        label->text = strdup("function call");
        break;
    default:
        label->text = strdup(token_names[node->op]);
        break;
    }
    label->width = (strlen(label->text) + 2) * 8.4;
    char *old_text = label->text;
    label->text = xml_escape(old_text);
    free(old_text);
    label->xcoord = 500;
    label->ycoord = 0;
    label->modifier = 0;
    return label;
}

variable_types: struct parse_tree_node { enum token_type { LITERAL_OR_ID=1, OPEN_PAREN=2, CLOSE_PAREN=3, OPEN_BRACKET=4, CLOSE_BRACKET=5, OPEN_CURLY=6, CLOSE_CURLY=7, BANG=8, PERCENT=9, CARET=10, AMPERSAND=11, BAR=12, STAR=13, MINUS=14, PLUS=15, SLASH=16, LEFT_SHIFT=17, RIGHT_SHIFT=18, BANG_EQUAL=19, PERCENT_EQUAL=20, CARET_EQUAL=21, AMPERSAND_EQUAL=22, BAR_EQUAL=23, STAR_EQUAL=24, MINUS_EQUAL=25, PLUS_EQUAL=26, SLASH_EQUAL=27, LEFT_SHIFT_EQUAL=28, RIGHT_SHIFT_EQUAL=29, ARROW=30, DOT=31, ASSIGN=32, IS_EQUAL=33, LTE=34, GTE=35, LT=36, GT=37, DOUBLE_AMPERSAND=38, DOUBLE_BAR=39, DOUBLE_PLUS=40, DOUBLE_MINUS=41, QUESTION=42, COLON=43, SIZEOF=44, COMMA=45, TILDE=46, TYPECAST=47, FUNCTION_CALL=48, SUBSCRIPT=49, REFERENCE=50, DEREFERENCE=51, UNARY_MINUS=52, POSTINCREMENT=53, POSTDECREMENT=54, PREINCREMENT=55, PREDECREMENT=56, START_COMMENT=57, BOGUS=58, END_OF_EXPRESSION=59 } op; char *text; struct parse_tree_node *first_child; struct parse_tree_node *next_sibling; } *

variable_types:
parent
struct label *


decompiled_code:
__int64 __fastcall get_label_tree(__int64 a1, __int64 a2)
{
void *v3; // rax
__int64 v4; // rbx
__int64 v5; // rdi
__int64 v6; // rax
__int64 i; // rbp
__int64 v8; // rax

v3 = make_label((int *)a1, a2);
v4 = (__int64)v3;
v5 = *(_QWORD *)(a1 + 16);
if ( v5 )
{
v6 = get_label_tree(v5, v3);
add_child_node(v4, v6);
for ( i = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 24LL); i; i = *(_QWORD *)(i + 24) )
{
v8 = get_label_tree(i, v4);
add_child_node(v4, v8);
}
}
return v4;
}

original_code:
static struct label* get_label_tree(struct parse_tree_node* node,
                             struct label *parent) {
    struct label* label = make_label(node, parent);
    if (node->first_child) {
        add_child_node(label, get_label_tree(node->first_child, label));
        struct parse_tree_node* cur = node->first_child->next_sibling;
        while (cur) {
            add_child_node(label, get_label_tree(cur, label));
            cur = cur->next_sibling;
        }
    }
    return label;
}

canonical_original_code:
static struct label *get_label_tree(struct parse_tree_node *node, struct label *parent) {
    struct label *label = make_label(node, parent);
    if (node->first_child) {
        add_child_node(label, get_label_tree(node->first_child, label));
        struct parse_tree_node *cur = node->first_child->next_sibling;
        while (cur) {
            add_child_node(label, get_label_tree(cur, label));
            cur = cur->next_sibling;
        }
    }
    return label;
}

user_defined_types: enum token_type { LITERAL_OR_ID=1, OPEN_PAREN=2, CLOSE_PAREN=3, OPEN_BRACKET=4, CLOSE_BRACKET=5, OPEN_CURLY=6, CLOSE_CURLY=7, BANG=8, PERCENT=9, CARET=10, AMPERSAND=11, BAR=12, STAR=13, MINUS=14, PLUS=15, SLASH=16, LEFT_SHIFT=17, RIGHT_SHIFT=18, BANG_EQUAL=19, PERCENT_EQUAL=20, CARET_EQUAL=21, AMPERSAND_EQUAL=22, BAR_EQUAL=23, STAR_EQUAL=24, MINUS_EQUAL=25, PLUS_EQUAL=26, SLASH_EQUAL=27, LEFT_SHIFT_EQUAL=28, RIGHT_SHIFT_EQUAL=29, ARROW=30, DOT=31, ASSIGN=32, IS_EQUAL=33, LTE=34, GTE=35, LT=36, GT=37, DOUBLE_AMPERSAND=38, DOUBLE_BAR=39, DOUBLE_PLUS=40, DOUBLE_MINUS=41, QUESTION=42, COLON=43, SIZEOF=44, COMMA=45, TILDE=46, TYPECAST=47, FUNCTION_CALL=48, SUBSCRIPT=49, REFERENCE=50, DEREFERENCE=51, UNARY_MINUS=52, POSTINCREMENT=53, POSTDECREMENT=54, PREINCREMENT=55, PREDECREMENT=56, START_COMMENT=57, BOGUS=58, END_OF_EXPRESSION=59 }


original_code:
static char* tree_to_svg(struct label* tree) {
    int allocated = 1024;
    char* svg = malloc(allocated);
    int used = strlen(svg_header);
    realloc_if_necessary(&svg, &allocated, used);
    strcpy(svg, svg_header);
    int rect_len = strlen(svg_rect);
    int text_len = strlen(svg_text);
    int line_len = strlen(svg_line);
    int buf_size = max(max(rect_len, text_len), line_len) + 5 * 15 + 1;
    char svg_buf[buf_size];
    struct label* label = tree;
    do {
        double width = label->width;
        double x = label->xcoord - width / 2;
        double y = label->ycoord;
        if (label->parent) {
            double parent_width = label->parent->width;
            double parent_x = label->parent->xcoord - parent_width / 2;
            double parent_y = label->parent->ycoord;
            int needed = sprintf(svg_buf, svg_line, x + width / 2,
                                 y, parent_x + parent_width / 2,
                                 parent_y + 17.0);
            realloc_if_necessary(&svg, &allocated, used + needed);
            strcpy(svg + used, svg_buf);
            used += needed;
        }
        int needed = sprintf(svg_buf, svg_rect, width, 17.0, x, y);
        realloc_if_necessary(&svg, &allocated, used + needed);
        strcpy(svg + used, svg_buf);
        used += needed;
        x += 8.4;
        y += 13.0;
        needed = sprintf(svg_buf, svg_text, 14.0, x, y, x, y, label->text);
        realloc_if_necessary(&svg, &allocated, used + needed);
        strcpy(svg + used, svg_buf);
        used += needed;
        label = next(label);
    } while (label);
    int needed = strlen(svg_footer);
    realloc_if_necessary(&svg, &allocated, used + needed);
    strcpy(svg + used, svg_footer);
    used += needed;
    return svg;
}

canonical_original_code:
static char *tree_to_svg(struct label *tree) {
    int allocated = 1024;
    char *svg = malloc(allocated);
    int used = strlen(svg_header);
    realloc_if_necessary(&svg, &allocated, used);
    strcpy(svg, svg_header);
    int rect_len = strlen(svg_rect);
    int text_len = strlen(svg_text);
    int line_len = strlen(svg_line);
    int buf_size = max(max(rect_len, text_len), line_len) + 5 * 15 + 1;
    char svg_buf[-1];
    struct label *label = tree;
    do {
        double width = label->width;
        double x = label->xcoord - width / 2;
        double y = label->ycoord;
        if (label->parent) {
            double parent_width = label->parent->width;
            double parent_x = label->parent->xcoord - parent_width / 2;
            double parent_y = label->parent->ycoord;
            int needed = sprintf(svg_buf, svg_line, x + width / 2,
                                 y, parent_x + parent_width / 2,
                                 parent_y + 17.0);
            realloc_if_necessary(&svg, &allocated, used + needed);
            strcpy(svg + used, svg_buf);
            used += needed;
        }
        int needed = sprintf(svg_buf, svg_rect, width, 17.0, x, y);
        realloc_if_necessary(&svg, &allocated, used + needed);
        strcpy(svg + used, svg_buf);
        used += needed;
        x += 8.4;
        y += 13.0;
        needed = sprintf(svg_buf, svg_text, 14.0, x, y, x, y, label->text);
        realloc_if_necessary(&svg, &allocated, used + needed);
        strcpy(svg + used, svg_buf);
        used += needed;
        label = next(label);
    } while (label);
    int needed = strlen(svg_footer);
    realloc_if_necessary(&svg, &allocated, used + needed);
    strcpy(svg + used, svg_footer);
    used += needed;
    return svg;
}

variable_types: allocated int

variable_types:
svg
char *

variable_types: used int

variable_types: width double

variable_types: x double

variable_types: y double

variable_types: needed int

return_type: char *


decompiled_code:
char *__fastcall parse_tree_to_svg(__int64 a1)
{
double *v1; // rbx
char *v2; // rbp
__int64 v4[7]; // [rsp+0h] [rbp-38h] BYREF

v1 = (double *)get_label_tree(a1, 0LL);
v4[0] = LC18;
v4[1] = LC19;
v4[2] = LC20;
walker_layout(v1, v4);
v2 = tree_to_svg(v1);
free_label_tree(v1);
return v2;
}

canonical_decompiled_code:
char *__fastcall func8(__int64 a1)
{
double *v1; // rbx
char *v2; // rbp
__int64 v4[7]; // [rsp+0h] [rbp-38h] BYREF

v1 = (double *)func6(a1, 0LL);
v4[0] = LC18;
v4[1] = LC19;
v4[2] = LC20;
walker_layout(v1, v4);
v2 = func7(v1);
func3(v1);
return v2;
}

original_code:
char* parse_tree_to_svg(struct parse_tree_node* node) {
    struct label* label = get_label_tree(node, 0);
    struct walker_layout_rules rules;
    rules.sibling_separation = 10;
    rules.subtree_separation = 20;
    rules.level_separation = 30;
    walker_layout(label, &rules);
    char* svg = tree_to_svg(label);
    free_label_tree(label);
    return svg;
}

canonical_original_code:
char *parse_tree_to_svg(struct parse_tree_node *node) {
    struct label *label = get_label_tree(node, 0);
    struct walker_layout_rules rules;
    rules.sibling_separation = 10;
    rules.subtree_separation = 20;
    rules.level_separation = 30;
    walker_layout(label, &rules);
    char *svg = tree_to_svg(label);
    free_label_tree(label);
    return svg;
}

variable_types: struct walker_layout_rules { double sibling_separation; double subtree_separation; double level_separation; }


decompiled_code:
char *__fastcall obstack_strdup(struct obstack *a1, char *a2)
{
char *v3; // rax
char v4; // r12
char *v5; // rsi
char *v6; // rdx
char *v7; // rax

do
{
v4 = *a2++;
if ( a1->chunk_limit < a1->next_free + 1 )
obstack_newchunk(a1, 1);
v3 = a1->next_free;
a1->next_free = v3 + 1;
*v3 = v4;
}
while ( v4 );
v5 = a1->object_base;
v6 = a1->next_free;
if ( v6 == v5 )
*((_BYTE *)a1 + 80) |= 2u;
v7 = (char *)(~a1->alignment_mask & (unsigned __int64)&v6[a1->alignment_mask]);
if ( v7 > a1->chunk_limit )
v7 = a1->chunk_limit;
a1->next_free = v7;
a1->object_base = v7;
return v5;
}

canonical_decompiled_code:
char *__fastcall func0(struct obstack *a1, char *a2)
{
char *v3; // rax
char v4; // r12
char *v5; // rsi
char *v6; // rdx
char *v7; // rax

do
{
v4 = *a2++;
if ( a1->chunk_limit < a1->next_free + 1 )
obstack_newchunk(a1, 1);
v3 = a1->next_free;
a1->next_free = v3 + 1;
*v3 = v4;
}
while ( v4 );
v5 = a1->object_base;
v6 = a1->next_free;
if ( v6 == v5 )
*((_BYTE *)a1 + 80) |= 2u;
v7 = (char *)(~a1->alignment_mask & (unsigned __int64)&v6[a1->alignment_mask]);
if ( v7 > a1->chunk_limit )
v7 = a1->chunk_limit;
a1->next_free = v7;
a1->object_base = v7;
return v5;
}

original_code:
char* obstack_strdup(struct obstack* obstack, const char* str) {
    while(1) {
        char c = *str++;
        __extension__ ({ struct obstack *__o = (obstack); if (__o->next_free + 1 > __o->chunk_limit) _obstack_newchunk (__o, 1); (*((__o)->next_free)++ = (c)); (void) 0; });
        if (!c) {
            break;
        }
    }
    return __extension__ ({ struct obstack *__o1 = (obstack); void *__value = (void *) __o1->object_base; if (__o1->next_free == __value) __o1->maybe_empty_object = 1; __o1->next_free = ((sizeof (long int) < sizeof (void *) ? (__o1->object_base) : (char *) 0) + (((__o1->next_free) - (sizeof (long int) < sizeof (void *) ? (__o1->object_base) : (char *) 0) + (__o1->alignment_mask)) & ~(__o1->alignment_mask))); if (__o1->next_free - (char *) __o1->chunk > __o1->chunk_limit - (char *) __o1->chunk) __o1->next_free = __o1->chunk_limit; __o1->object_base = __o1->next_free; __value; });
}

canonical_original_code:
char *obstack_strdup(struct obstack *obstack, char *str) {
    while(1) {
        char c = *str++;
        __extension__ ({ struct obstack *__o = (obstack); if (__o->next_free + 1 > __o->chunk_limit) _obstack_newchunk (__o, 1); (*((__o)->next_free)++ = (c)); (void) 0; });
        if (!c) {
            break;
        }
    }
    return __extension__ ({ struct obstack *__o1 = (obstack); void *__value = (void *) __o1->object_base; if (__o1->next_free == __value) __o1->maybe_empty_object = 1; __o1->next_free = ((sizeof (long) < sizeof (void *) ? (__o1->object_base) : (char *) 0) + (((__o1->next_free) - (sizeof (long) < sizeof (void *) ? (__o1->object_base) : (char *) 0) + (__o1->alignment_mask)) & ~(__o1->alignment_mask))); if (__o1->next_free - (char *) __o1->chunk > __o1->chunk_limit - (char *) __o1->chunk) __o1->next_free = __o1->chunk_limit; __o1->object_base = __o1->next_free; __value; });
}

variable_types: struct obstack { long chunk_size; struct _obstack_chunk { char *limit; struct _obstack_chunk *prev; char contents[4]; } *chunk; char *object_base; char *next_free; char *chunk_limit; union { long tempint; void *tempptr; } temp; int alignment_mask; struct _obstack_chunk *(*chunkfun)(void *, long); void (*freefun)(void *, struct _obstack_chunk *); void *extra_arg; unsigned int use_extra_arg; unsigned int maybe_empty_object; unsigned int alloc_failed; } *

variable_types:
str
char *

variable_types: c char


decompiled_code:
char *__fastcall obstack_strndup(struct obstack *a1, char *a2, __int64 a3)
{
char v3; // r12
char *v4; // rbp
__int64 v5; // r13
char *v6; // rax
char *v7; // rax
char *v8; // rsi
char *v9; // rdx
char *v10; // rax

v3 = *a2;
if ( *a2 )
{
v4 = a2 + 1;
if ( a3 )
{
v5 = (__int64)&a2[a3 + 1];
do
{
if ( a1->chunk_limit < a1->next_free + 1 )
obstack_newchunk(a1, 1);
v6 = a1->next_free;
a1->next_free = v6 + 1;
*v6 = v3;
v3 = *v4++;
}
while ( v3 && (char *)v5 != v4 );
}
}
if ( a1->chunk_limit < a1->next_free + 1 )
obstack_newchunk(a1, 1);
v7 = a1->next_free;
a1->next_free = v7 + 1;
*v7 = 0;
v8 = a1->object_base;
v9 = a1->next_free;
if ( v9 == v8 )
*((_BYTE *)a1 + 80) |= 2u;
v10 = (char *)(~a1->alignment_mask & (unsigned __int64)&v9[a1->alignment_mask]);
if ( v10 > a1->chunk_limit )
v10 = a1->chunk_limit;
a1->next_free = v10;
a1->object_base = v10;
return v8;
}

canonical_decompiled_code:
char *__fastcall func1(struct obstack *a1, char *a2, __int64 a3)
{
char v3; // r12
char *v4; // rbp
__int64 v5; // r13
char *v6; // rax
char *v7; // rax
char *v8; // rsi
char *v9; // rdx
char *v10; // rax

v3 = *a2;
if ( *a2 )
{
v4 = a2 + 1;
if ( a3 )
{
v5 = (__int64)&a2[a3 + 1];
do
{
if ( a1->chunk_limit < a1->next_free + 1 )
obstack_newchunk(a1, 1);
v6 = a1->next_free;
a1->next_free = v6 + 1;
*v6 = v3;
v3 = *v4++;
}
while ( v3 && (char *)v5 != v4 );
}
}
if ( a1->chunk_limit < a1->next_free + 1 )
obstack_newchunk(a1, 1);
v7 = a1->next_free;
a1->next_free = v7 + 1;
*v7 = 0;
v8 = a1->object_base;
v9 = a1->next_free;
if ( v9 == v8 )
*((_BYTE *)a1 + 80) |= 2u;
v10 = (char *)(~a1->alignment_mask & (unsigned __int64)&v9[a1->alignment_mask]);
if ( v10 > a1->chunk_limit )
v10 = a1->chunk_limit;
a1->next_free = v10;
a1->object_base = v10;
return v8;
}

original_code:
char* obstack_strndup(struct obstack* obstack, const char* str,
                             size_t n) {
    char c;
    size_t i = 0;
    while((c = *str++) && i++ < n) {
        __extension__ ({ struct obstack *__o = (obstack); if (__o->next_free + 1 > __o->chunk_limit) _obstack_newchunk (__o, 1); (*((__o)->next_free)++ = (c)); (void) 0; });
    }
    __extension__ ({ struct obstack *__o = (obstack); if (__o->next_free + 1 > __o->chunk_limit) _obstack_newchunk (__o, 1); (*((__o)->next_free)++ = (0)); (void) 0; });
    return __extension__ ({ struct obstack *__o1 = (obstack); void *__value = (void *) __o1->object_base; if (__o1->next_free == __value) __o1->maybe_empty_object = 1; __o1->next_free = ((sizeof (long int) < sizeof (void *) ? (__o1->object_base) : (char *) 0) + (((__o1->next_free) - (sizeof (long int) < sizeof (void *) ? (__o1->object_base) : (char *) 0) + (__o1->alignment_mask)) & ~(__o1->alignment_mask))); if (__o1->next_free - (char *) __o1->chunk > __o1->chunk_limit - (char *) __o1->chunk) __o1->next_free = __o1->chunk_limit; __o1->object_base = __o1->next_free; __value; });
}

canonical_original_code:
char *obstack_strndup(struct obstack *obstack, char *str, unsigned long n) {
    char c;
    unsigned long i = 0;
    while((c = *str++) && i++ < n) {
        __extension__ ({ struct obstack *__o = (obstack); if (__o->next_free + 1 > __o->chunk_limit) _obstack_newchunk (__o, 1); (*((__o)->next_free)++ = (c)); (void) 0; });
    }
    __extension__ ({ struct obstack *__o = (obstack); if (__o->next_free + 1 > __o->chunk_limit) _obstack_newchunk (__o, 1); (*((__o)->next_free)++ = (0)); (void) 0; });
    return __extension__ ({ struct obstack *__o1 = (obstack); void *__value = (void *) __o1->object_base; if (__o1->next_free == __value) __o1->maybe_empty_object = 1; __o1->next_free = ((sizeof (long) < sizeof (void *) ? (__o1->object_base) : (char *) 0) + (((__o1->next_free) - (sizeof (long) < sizeof (void *) ? (__o1->object_base) : (char *) 0) + (__o1->alignment_mask)) & ~(__o1->alignment_mask))); if (__o1->next_free - (char *) __o1->chunk > __o1->chunk_limit - (char *) __o1->chunk) __o1->next_free = __o1->chunk_limit; __o1->object_base = __o1->next_free; __value; });
}

variable_types:
n
unsigned long

variable_types:
i
unsigned long

user_defined_types: struct _obstack_chunk { char *limit; struct _obstack_chunk *prev; char contents[4]; }


unescape

original_code:
static char* unescape(const char* str) {
    char* dup = strdup(str);
    const char* read = dup;
    char* write = dup;
    char c;
    while ((c = *read++)) {
        if (c == '%') {
            unsigned int x;
            int n = sscanf(read, "%2x", &x);
            if (n == 1) {
                read += 2;
            } else {
                return dup;
            }
            *write++ = x;
        } else if (c == '+') {
            *write++ = ' ';
        } else {
            *write++ = c;
        }
    }
    *write = 0;
    return dup;
}

canonical_original_code:
static char *unescape(char *str) {
    char *dup = strdup(str);
    char *read = dup;
    char *write = dup;
    char c;
    while ((c = *read++)) {
        if (c == '%') {
            unsigned int x;
            int n = sscanf(read, "%2x", &x);
            if (n == 1) {
                read += 2;
            } else {
                return dup;
            }
            *write++ = x;
        } else if (c == '+') {
            *write++ = ' ';
        } else {
            *write++ = c;
        }
    }
    *write = 0;
    return dup;
}

variable_types:
dup
char *

variable_types:
read
char *

variable_types:
write
char *

variable_types:
x
unsigned int

variable_types: n int


decompiled_code:
char *__fastcall add_value(__int64 a1, const char *a2)
{
int v3; // esi
int v4; // eax
char **v5; // rbx
char *result; // rax
int v7; // esi

v3 = *(_DWORD *)(a1 + 20);
if ( *(_DWORD *)(a1 + 16) >= v3 )
{
v7 = 2 * v3;
*(_DWORD *)(a1 + 20) = v7;
*(_QWORD *)(a1 + 8) = realloc(*(void **)(a1 + 8), 8LL * v7);
}
v4 = *(_DWORD *)(a1 + 16);
*(_DWORD *)(a1 + 16) = v4 + 1;
v5 = (char **)(*(_QWORD *)(a1 + 8) + 8LL * v4);
result = unescape(a2);
*v5 = result;
return result;
}

original_code:
static void add_value(struct cgi_var* var, const char* value) {
    if (var->n_values >= var->values_allocated) {
        var->values_allocated *= 2;
        var->values = realloc(var->values, var->values_allocated * sizeof(char*));
    }
    var->values[var->n_values++] = unescape(value);
}

canonical_original_code:
static void add_value(struct cgi_var *var, char *value) {
    if (var->n_values >= var->values_allocated) {
        var->values_allocated *= 2;
        var->values = realloc(var->values, var->values_allocated * sizeof(char *));
    }
    var->values[var->n_values++] = unescape(value);
}

variable_types: struct cgi_var { char *var; char **values; int n_values; int values_allocated; } *

variable_types:
value
char *


decompiled_code:
const char **__fastcall cgi_get_var(__int64 a1, const char *a2)
{
int v2; // eax
const char **v3; // rbx
__int64 v4; // r13
const char **v5; // r12

v2 = *(_DWORD *)(a1 + 8);
if ( v2 <= 0 )
return 0LL;
v3 = *(const char ***)a1;
v4 = *(_QWORD *)a1 + 24LL * (unsigned int)(v2 - 1) + 24;
while ( 1 )
{
v5 = v3;
if ( !strcmp(*v3, a2) )
break;
v3 += 3;
if ( v3 == (const char **)v4 )
return 0LL;
}
return v5;
}

canonical_decompiled_code:
const char **__fastcall func3(__int64 a1, const char *a2)
{
int v2; // eax
const char **v3; // rbx
__int64 v4; // r13
const char **v5; // r12

v2 = *(_DWORD *)(a1 + 8);
if ( v2 <= 0 )
return 0LL;
v3 = *(const char ***)a1;
v4 = *(_QWORD *)a1 + 24LL * (unsigned int)(v2 - 1) + 24;
while ( 1 )
{
v5 = v3;
if ( !strcmp(*v3, a2) )
break;
v3 += 3;
if ( v3 == (const char **)v4 )
return 0LL;
}
return v5;
}

original_code:
struct cgi_var* cgi_get_var(struct cgi* cgi, const char* var_name) {
    for (int i = 0; i < cgi->n_vars; ++i) {
        struct cgi_var* var = cgi->vars + i;
        if (!strcmp(var->var, var_name)) {
            return var;
        }
    }
    return 0;
}

canonical_original_code:
struct cgi_var *cgi_get_var(struct cgi *cgi, char *var_name) {
    for (int i = 0; i < cgi->n_vars; ++i) {
        struct cgi_var *var = cgi->vars + i;
        if (!strcmp(var->var, var_name)) {
            return var;
        }
    }
    return 0;
}

variable_types: struct cgi { struct cgi_var *vars; int n_vars; int vars_allocated; } *

variable_types: i int

return_type: struct cgi_var { char *var; char **values; int n_values; int values_allocated; } *


decompiled_code:
_DWORD *cgi_init()
{
char *v0; // r8
char **v1; // rdx
char *v3; // rax

v0 = *environ;
if ( !*environ )
return parse_query_string((char *)&s);
v1 = environ + 1;
while ( memcmp(v0, "QUERY_STRING", 0xCuLL) )
{
v0 = *v1++;
if ( !v0 )
return parse_query_string((char *)&s);
}
v3 = strchr(v0, 61);
return parse_query_string(v3 + 1);
}

canonical_decompiled_code:
_DWORD *func4()
{
char *v0; // r8
char **v1; // rdx
char *v3; // rax

v0 = *environ;
if ( !*environ )
return parse_query_string((char *)&s);
v1 = environ + 1;
while ( memcmp(v0, "QUERY_STRING", 0xCuLL) )
{
v0 = *v1++;
if ( !v0 )
return parse_query_string((char *)&s);
}
v3 = strchr(v0, 61);
return parse_query_string(v3 + 1);
}

original_code:
struct cgi* cgi_init() {
    const char* query_string = "QUERY_STRING";
    int query_string_len = strlen(query_string);
    int i = 0;
    while(environ[i]) {
        if (strncmp(environ[i], query_string, query_string_len) == 0) {
            struct cgi* cgi = parse_query_string(strchr(environ[i], '=') + 1);
            return cgi;
        }
        ++i;
    }
    return parse_query_string("");
}

canonical_original_code:
struct cgi *cgi_init() {
    char *query_string = "QUERY_STRING";
    int query_string_len = strlen(query_string);
    int i = 0;
    while(environ[i]) {
        if (strncmp(environ[i], query_string, query_string_len) == 0) {
            struct cgi *cgi = parse_query_string(strchr(environ[i], '=') + 1);
            return cgi;
        }
        ++i;
    }
    return parse_query_string("");
}

variable_types: struct cgi { struct cgi_var { char *var; char **values; int n_values; int values_allocated; } *vars; int n_vars; int vars_allocated; } *

user_defined_types: struct cgi { struct cgi_var *vars; int n_vars; int vars_allocated; }


decompiled_code:
__int64 __fastcall execute_shifts(__int64 a1)
{
__int64 result; // rax
double v2; // xmm1_8
double v3; // xmm0_8

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
v2 = 0.0;
v3 = 0.0;
do
{
*(double *)(result + 88) = v3 + *(double *)(result + 88);
*(double *)(result + 104) = v3 + *(double *)(result + 104);
v2 = v2 + *(double *)(result + 56);
v3 = v3 + v2 + *(double *)(result + 64);
result = *(_QWORD *)(result + 8);
}
while ( result );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
double v2; // xmm1_8
double v3; // xmm0_8

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
v2 = 0.0;
v3 = 0.0;
do
{
*(double *)(result + 88) = v3 + *(double *)(result + 88);
*(double *)(result + 104) = v3 + *(double *)(result + 104);
v2 = v2 + *(double *)(result + 56);
v3 = v3 + v2 + *(double *)(result + 64);
result = *(_QWORD *)(result + 8);
}
while ( result );
return result;
}

original_code:
static void execute_shifts(struct label* node) {
    double shift = 0;
    double change = 0;
    struct label* child = node;
    while (child->next_sibling) {
        child = child->next_sibling;
    }
    while (child) {
        child->xcoord += shift;
        child->modifier += shift;
        change += child->change;
        shift += child->shift + change;
        child = child->prev_sibling;
    }
}

canonical_original_code:
static void execute_shifts(struct label *node) {
    double shift = 0;
    double change = 0;
    struct label *child = node;
    while (child->next_sibling) {
        child = child->next_sibling;
    }
    while (child) {
        child->xcoord += shift;
        child->modifier += shift;
        change += child->change;
        shift += child->shift + change;
        child = child->prev_sibling;
    }
}

variable_types: struct label { struct label *parent; struct label *prev_sibling; struct label *next_sibling; struct label *first_child; struct label *thread; struct label *ancestor; int number; double change; double shift; char *text; double width; double xcoord; double ycoord; double modifier; } *

variable_types: shift double

variable_types: change double


original_code:
static void move_subtree(struct label* left, struct label* right, double shift) {
    int subtrees = right->number - left->number;
    right->change -= shift / subtrees;
    right->shift += shift;
    left->change += shift / subtrees;
    right->xcoord += shift;
    right->modifier += shift;
}

canonical_original_code:
static void move_subtree(struct label *left, struct label *right, double shift) {
    int subtrees = right->number - left->number;
    right->change -= shift / subtrees;
    right->shift += shift;
    left->change += shift / subtrees;
    right->xcoord += shift;
    right->modifier += shift;
}

variable_types:
right
struct label *

variable_types: subtrees int


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

result = *(_QWORD *)(a1 + 24);
if ( !result )
result = *(_QWORD *)(a1 + 32);
return result;
}

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

result = *(_QWORD *)(a1 + 24);
if ( !result )
result = *(_QWORD *)(a1 + 32);
return result;
}

original_code:
static struct label* next_left(struct label *node) {
    if (node->first_child) {
        return node->first_child;
    }
    return node->thread;
}

canonical_original_code:
static struct label *next_left(struct label *node) {
    if (node->first_child) {
        return node->first_child;
    }
    return node->thread;
}

variable_types:
node
struct label *


original_code:
static struct label* next_right(struct label *node) {
    if (node->first_child) {
        struct label* child = node->first_child;
        while(child->next_sibling) {
            child = child->next_sibling;
        }
        return child;
    }
    return node->thread;
}

canonical_original_code:
static struct label *next_right(struct label *node) {
    if (node->first_child) {
        struct label *child = node->first_child;
        while(child->next_sibling) {
            child = child->next_sibling;
        }
        return child;
    }
    return node->thread;
}


decompiled_code:
__int64 __fastcall second_walk(__int64 a1, __int64 a2, int a3, double a4)
{
__int64 result; // rax
__int64 v7; // rsi
__int64 v8; // rsi

*(double *)(a2 + 88) = *(double *)a1 + *(double *)(a2 + 88) + a4;
result = *(_QWORD *)(a1 + 24);
*(double *)(a2 + 96) = (double)a3 * *(double *)(result + 16) + *(double *)(a1 + 8);
v7 = *(_QWORD *)(a2 + 24);
if ( v7 )
result = second_walk(a1, v7, (unsigned int)(a3 + 1), a4 + *(double *)(a2 + 104));
v8 = *(_QWORD *)(a2 + 16);
if ( v8 )
result = second_walk(a1, v8, (unsigned int)a3, a4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, int a3, double a4)
{
__int64 result; // rax
__int64 v7; // rsi
__int64 v8; // rsi

*(double *)(a2 + 88) = *(double *)a1 + *(double *)(a2 + 88) + a4;
result = *(_QWORD *)(a1 + 24);
*(double *)(a2 + 96) = (double)a3 * *(double *)(result + 16) + *(double *)(a1 + 8);
v7 = *(_QWORD *)(a2 + 24);
if ( v7 )
result = func6(a1, v7, (unsigned int)(a3 + 1), a4 + *(double *)(a2 + 104));
v8 = *(_QWORD *)(a2 + 16);
if ( v8 )
result = func6(a1, v8, (unsigned int)a3, a4);
return result;
}

original_code:
static void second_walk(struct layout_ctx* ctx, struct label *node, int level,
                        double modsum) {
    node->xcoord = ctx->x_top_adjustment + node->xcoord + modsum;
    node->ycoord = ctx->y_top_adjustment + level * ctx->rules->level_separation;
    if (node->first_child) {
        second_walk(ctx, node->first_child, level + 1,
                    modsum + node->modifier);
    }
    if (node->next_sibling) {
        second_walk(ctx, node->next_sibling, level, modsum);
    }
}

canonical_original_code:
static void second_walk(struct layout_ctx *ctx, struct label *node, int level, double modsum) {
    node->xcoord = ctx->x_top_adjustment + node->xcoord + modsum;
    node->ycoord = ctx->y_top_adjustment + level * ctx->rules->level_separation;
    if (node->first_child) {
        second_walk(ctx, node->first_child, level + 1,
                    modsum + node->modifier);
    }
    if (node->next_sibling) {
        second_walk(ctx, node->next_sibling, level, modsum);
    }
}

variable_types: struct layout_ctx { double x_top_adjustment; double y_top_adjustment; struct label { struct label *parent; struct label *prev_sibling; struct label *next_sibling; struct label *first_child; struct label *thread; struct label *ancestor; int number; double change; double shift; char *text; double width; double xcoord; double ycoord; double modifier; } **prev_node_at_level; struct walker_layout_rules { double sibling_separation; double subtree_separation; double level_separation; } *rules; } *

variable_types: level int

variable_types: modsum double

user_defined_types: struct layout_ctx { double x_top_adjustment; double y_top_adjustment; struct label **prev_node_at_level; struct walker_layout_rules *rules; }


original_code:
static void first_walk(struct layout_ctx* ctx, struct label *node) {
    if (node->first_child) {
        struct label *default_ancestor = node->first_child;
        struct label *cur = node->first_child;
        struct label *last_child;
        while (cur) {
            first_walk(ctx, cur);
            default_ancestor = apportion(ctx, cur, default_ancestor);
            last_child = cur;
            cur = cur->next_sibling;
        }
        execute_shifts(node);
        double midpoint = (node->first_child->xcoord + last_child->xcoord) / 2;
        if (node->prev_sibling) {
            node->xcoord = node->prev_sibling->xcoord
                + spacing(ctx, node->prev_sibling, node, 1)
                + ctx->rules->sibling_separation;
            node->modifier = node->xcoord - midpoint;
        } else {
            node->xcoord = midpoint;
        }
    } else {
        if (node->prev_sibling) {
            node->xcoord = node->prev_sibling->xcoord
                + spacing(ctx, node, node->prev_sibling, 1);
        } else {
            node->xcoord = 0;
        }
    }
}

canonical_original_code:
static void first_walk(struct layout_ctx *ctx, struct label *node) {
    if (node->first_child) {
        struct label *default_ancestor = node->first_child;
        struct label *cur = node->first_child;
        struct label *last_child;
        while (cur) {
            first_walk(ctx, cur);
            default_ancestor = apportion(ctx, cur, default_ancestor);
            last_child = cur;
            cur = cur->next_sibling;
        }
        execute_shifts(node);
        double midpoint = (node->first_child->xcoord + last_child->xcoord) / 2;
        if (node->prev_sibling) {
            node->xcoord = node->prev_sibling->xcoord
                + spacing(ctx, node->prev_sibling, node, 1)
                + ctx->rules->sibling_separation;
            node->modifier = node->xcoord - midpoint;
        } else {
            node->xcoord = midpoint;
        }
    } else {
        if (node->prev_sibling) {
            node->xcoord = node->prev_sibling->xcoord
                + spacing(ctx, node, node->prev_sibling, 1);
        } else {
            node->xcoord = 0;
        }
    }
}

variable_types: midpoint double

user_defined_types: struct walker_layout_rules { double sibling_separation; double subtree_separation; double level_separation; }


original_code:
void walker_layout(struct label *node, struct walker_layout_rules* rules) {
    if (!node) {
        return;
    }
    struct layout_ctx ctx;
    ctx.prev_node_at_level = calloc(get_max_depth(node), sizeof(node));
    ctx.rules = rules;
    ctx.x_top_adjustment = node->xcoord;
    ctx.y_top_adjustment = node->ycoord;
    first_walk(&ctx, node);
    second_walk(&ctx, node, 0, -node->xcoord);
}

canonical_original_code:
void walker_layout(struct label *node, struct walker_layout_rules *rules) {
    if (!node) {
        return;
    }
    struct layout_ctx ctx;
    ctx.prev_node_at_level = calloc(get_max_depth(node), sizeof(node));
    ctx.rules = rules;
    ctx.x_top_adjustment = node->xcoord;
    ctx.y_top_adjustment = node->ycoord;
    first_walk(&ctx, node);
    second_walk(&ctx, node, 0, -node->xcoord);
}

variable_types: struct layout_ctx { double x_top_adjustment; double y_top_adjustment; struct label { struct label *parent; struct label *prev_sibling; struct label *next_sibling; struct label *first_child; struct label *thread; struct label *ancestor; int number; double change; double shift; char *text; double width; double xcoord; double ycoord; double modifier; } **prev_node_at_level; struct walker_layout_rules { double sibling_separation; double subtree_separation; double level_separation; } *rules; }


decompiled_code:
__int64 __fastcall read_integer_literal(unsigned __int8 **a1)
{
unsigned __int8 *v1; // rdx
__int64 result; // rax

v1 = *a1;
for ( result = **a1; (_BYTE)result; result = *++v1 )
{
result = (unsigned int)(result - 48);
if ( (unsigned __int8)result > 9u )
break;
}
*a1 = v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 **a1)
{
unsigned __int8 *v1; // rdx
__int64 result; // rax

v1 = *a1;
for ( result = **a1; (_BYTE)result; result = *++v1 )
{
result = (unsigned int)(result - 48);
if ( (unsigned __int8)result > 9u )
break;
}
*a1 = v1;
return result;
}

original_code:
static void read_integer_literal(const char** pos_ref) {
    const char* pos = *pos_ref;
    char c;
    while ((c = *pos)) {
        if (c < '0' || c > '9') {
            break;
        }
        pos++;
    }
    *pos_ref = pos;
}

canonical_original_code:
static void read_integer_literal(char **pos_ref) {
    char *pos = *pos_ref;
    char c;
    while ((c = *pos)) {
        if (c < '0' || c > '9') {
            break;
        }
        pos++;
    }
    *pos_ref = pos;
}

variable_types:
pos
char *

variable_types: c char


original_code:
static _Bool read_float(const char** pos_ref) {
    char c;
    _Bool dot_seen = 0;
    _Bool exp_seen = 0;
    const char* pos = *pos_ref;
    while ((c = *pos)) {
        if (c == '.') {
            if (dot_seen || exp_seen) {
                *pos_ref = pos;
                return 0;
            }
            dot_seen = 1;
        } else if (c == 'E' || c == 'e') {
            if (exp_seen) {
                *pos_ref = pos;
                return 0;
            }
            if (pos[1] == '-' || pos[1] == '+') {
                pos++;
            }
            exp_seen = 1;
        } else if (c < '0' || c > '9') {
            break;
        }
        pos++;
    }
    *pos_ref = pos;
    return 1;
}

canonical_original_code:
static _Bool read_float(char **pos_ref) {
    char c;
    _Bool dot_seen = 0;
    _Bool exp_seen = 0;
    char *pos = *pos_ref;
    while ((c = *pos)) {
        if (c == '.') {
            if (dot_seen || exp_seen) {
                *pos_ref = pos;
                return 0;
            }
            dot_seen = 1;
        } else if (c == 'E' || c == 'e') {
            if (exp_seen) {
                *pos_ref = pos;
                return 0;
            }
            if (pos[1] == '-' || pos[1] == '+') {
                pos++;
            }
            exp_seen = 1;
        } else if (c < '0' || c > '9') {
            break;
        }
        pos++;
    }
    *pos_ref = pos;
    return 1;
}


decompiled_code:
__int64 __fastcall check_octal(_BYTE *a1, _BYTE *a2)
{
_BYTE *v2; // rax
unsigned int v3; // edx

if ( a1 == a2 )
return 1;
v2 = a1;
while ( 1 )
{
v3 = *v2 & 0xDF;
LOBYTE(v3) = *v2 == 46 || (*v2 & 0xDF) == 69;
if ( (_BYTE)v3 )
break;
if ( a2 == ++v2 )
{
if ( a1 == v2 )
return 1;
while ( (unsigned __int8)(*a1 - 56) > 1u )
{
if ( ++a1 == v2 )
return 1;
}
return v3;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, _BYTE *a2)
{
_BYTE *v2; // rax
unsigned int v3; // edx

if ( a1 == a2 )
return 1;
v2 = a1;
while ( 1 )
{
v3 = *v2 & 0xDF;
LOBYTE(v3) = *v2 == 46 || (*v2 & 0xDF) == 69;
if ( (_BYTE)v3 )
break;
if ( a2 == ++v2 )
{
if ( a1 == v2 )
return 1;
while ( (unsigned __int8)(*a1 - 56) > 1u )
{
if ( ++a1 == v2 )
return 1;
}
return v3;
}
}
return v3;
}

original_code:
static _Bool check_octal(const char* start, const char* end) {
    for (const char* c = start; c != end; ++c) {
        if (*c == '.' || *c == 'E' || *c == 'e') {
            return 1;
        }
    }
    for (const char* c = start; c != end; ++c) {
        if (*c == '8' || *c == '9') {
            return 0;
        }
    }
    return 1;
}

canonical_original_code:
static _Bool check_octal(char *start, char *end) {
    for (char *c = start; c != end; ++c) {
        if (*c == '.' || *c == 'E' || *c == 'e') {
            return 1;
        }
    }
    for (char *c = start; c != end; ++c) {
        if (*c == '8' || *c == '9') {
            return 0;
        }
    }
    return 1;
}

variable_types:
start
char *

variable_types:
end
char *

variable_types:
c
char *


decompiled_code:
__int64 __fastcall read_hex_literal(unsigned __int8 **a1)
{
unsigned __int8 *v2; // rax
unsigned __int8 v3; // dl
bool v4; // di
unsigned __int8 *v6; // rbx
unsigned __int8 *v7; // [rsp+8h] [rbp-18h] BYREF

v2 = *a1;
v7 = v2;
v3 = *v2;
if ( !*v2 )
goto LABEL_16;
v4 = 0;
while ( (unsigned __int8)(v3 - 48) <= 9u || (unsigned __int8)((v3 & 0xDF) - 65) <= 5u )
{
v7 = v2 + 1;
LABEL_5:
v2 = v7;
v3 = *v7;
if ( !*v7 )
{
if ( !v4 )
{
LABEL_16:
*a1 = v7;
return 1LL;
}
LABEL_14:
*a1 = v2;
return 0LL;
}
}
if ( v3 == 46 )
{
if ( v4 )
{
*a1 = v2;
return 0LL;
}
v7 = v2 + 1;
v4 = (unsigned __int8)(v3 - 48) > 9u && (unsigned __int8)((v3 & 0xDF) - 65) > 5u;
goto LABEL_5;
}
if ( !v4 )
goto LABEL_16;
if ( v3 != 112 )
goto LABEL_14;
v6 = v2 + 1;
v7 = v2 + 1;
read_integer_literal(&v7);
if ( v6 != v7 )
goto LABEL_16;
*a1 = v7;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 **a1)
{
unsigned __int8 *v2; // rax
unsigned __int8 v3; // dl
bool v4; // di
unsigned __int8 *v6; // rbx
unsigned __int8 *v7; // [rsp+8h] [rbp-18h] BYREF

v2 = *a1;
v7 = v2;
v3 = *v2;
if ( !*v2 )
goto LABEL_16;
v4 = 0;
while ( (unsigned __int8)(v3 - 48) <= 9u || (unsigned __int8)((v3 & 0xDF) - 65) <= 5u )
{
v7 = v2 + 1;
LABEL_5:
v2 = v7;
v3 = *v7;
if ( !*v7 )
{
if ( !v4 )
{
LABEL_16:
*a1 = v7;
return 1LL;
}
LABEL_14:
*a1 = v2;
return 0LL;
}
}
if ( v3 == 46 )
{
if ( v4 )
{
*a1 = v2;
return 0LL;
}
v7 = v2 + 1;
v4 = (unsigned __int8)(v3 - 48) > 9u && (unsigned __int8)((v3 & 0xDF) - 65) > 5u;
goto LABEL_5;
}
if ( !v4 )
goto LABEL_16;
if ( v3 != 112 )
goto LABEL_14;
v6 = v2 + 1;
v7 = v2 + 1;
func0(&v7);
if ( v6 != v7 )
goto LABEL_16;
*a1 = v7;
return 0LL;
}

original_code:
static _Bool read_hex_literal(const char** pos_ref) {
    char c;
    _Bool dot_seen = 0;
    const char* pos = *pos_ref;
    while ((c = *pos)) {
        if ((c < '0' || c > '9') && (c < 'A' || c > 'F') && (c < 'a' || c > 'f')) {
            if (c == '.') {
                if (dot_seen) {
                    *pos_ref = pos;
                    return 0;
                }
                dot_seen = 1;
                pos ++;
            } else {
                break;
            }
        } else {
            pos ++;
        }
    }
    if (dot_seen) {
        if (*pos != 'p') {
            *pos_ref = pos;
            return 0;
        }
        pos ++;
        const char* old_pos = pos;
        read_integer_literal(&pos);
        if (old_pos == pos) {
            *pos_ref = pos;
            return 0;
        }
    }
    *pos_ref = pos;
    return 1;
}

canonical_original_code:
static _Bool read_hex_literal(char **pos_ref) {
    char c;
    _Bool dot_seen = 0;
    char *pos = *pos_ref;
    while ((c = *pos)) {
        if ((c < '0' || c > '9') && (c < 'A' || c > 'F') && (c < 'a' || c > 'f')) {
            if (c == '.') {
                if (dot_seen) {
                    *pos_ref = pos;
                    return 0;
                }
                dot_seen = 1;
                pos ++;
            } else {
                break;
            }
        } else {
            pos ++;
        }
    }
    if (dot_seen) {
        if (*pos != 'p') {
            *pos_ref = pos;
            return 0;
        }
        pos ++;
        char *old_pos = pos;
        read_integer_literal(&pos);
        if (old_pos == pos) {
            *pos_ref = pos;
            return 0;
        }
    }
    *pos_ref = pos;
    return 1;
}


decompiled_code:
void __fastcall add_child_token_rule(__int64 a1, unsigned __int8 *a2, unsigned int a3)
{
unsigned __int8 v4; // bl

v4 = *a2;
if ( *a2 )
{
if ( !*(_QWORD *)a1 )
*(_QWORD *)a1 = calloc(0x100uLL, 0x10uLL);
add_child_token_rule(*(_QWORD *)a1 + 16LL * v4, a2 + 1, a3);
}
else
{
*(_DWORD *)(a1 + 8) = a3;
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, unsigned __int8 *a2, unsigned int a3)
{
unsigned __int8 v4; // bl

v4 = *a2;
if ( *a2 )
{
if ( !*(_QWORD *)a1 )
*(_QWORD *)a1 = calloc(0x100uLL, 0x10uLL);
func4(*(_QWORD *)a1 + 16LL * v4, a2 + 1, a3);
}
else
{
*(_DWORD *)(a1 + 8) = a3;
}
}

original_code:
static void add_child_token_rule(struct token_rule* rule, const char* text,
                          enum token_type token_type) {
    unsigned char c = *text;
    if (!c) {
        rule->token_type = token_type;
        return;
    }
    if (rule->children == 0) {
        rule->children = calloc(256, sizeof(struct token_rule));
    }
    add_child_token_rule(rule->children + c, text + 1, token_type);
}

canonical_original_code:
static void add_child_token_rule(struct token_rule *rule, char *text, enum token_type token_type) {
    unsigned char c = *text;
    if (!c) {
        rule->token_type = token_type;
        return;
    }
    if (rule->children == 0) {
        rule->children = calloc(256, sizeof(struct token_rule));
    }
    add_child_token_rule(rule->children + c, text + 1, token_type);
}

variable_types: struct token_rule { struct token_rule *children; enum token_type { LITERAL_OR_ID=1, OPEN_PAREN=2, CLOSE_PAREN=3, OPEN_BRACKET=4, CLOSE_BRACKET=5, OPEN_CURLY=6, CLOSE_CURLY=7, BANG=8, PERCENT=9, CARET=10, AMPERSAND=11, BAR=12, STAR=13, MINUS=14, PLUS=15, SLASH=16, LEFT_SHIFT=17, RIGHT_SHIFT=18, BANG_EQUAL=19, PERCENT_EQUAL=20, CARET_EQUAL=21, AMPERSAND_EQUAL=22, BAR_EQUAL=23, STAR_EQUAL=24, MINUS_EQUAL=25, PLUS_EQUAL=26, SLASH_EQUAL=27, LEFT_SHIFT_EQUAL=28, RIGHT_SHIFT_EQUAL=29, ARROW=30, DOT=31, ASSIGN=32, IS_EQUAL=33, LTE=34, GTE=35, LT=36, GT=37, DOUBLE_AMPERSAND=38, DOUBLE_BAR=39, DOUBLE_PLUS=40, DOUBLE_MINUS=41, QUESTION=42, COLON=43, SIZEOF=44, COMMA=45, TILDE=46, TYPECAST=47, FUNCTION_CALL=48, SUBSCRIPT=49, REFERENCE=50, DEREFERENCE=51, UNARY_MINUS=52, POSTINCREMENT=53, POSTDECREMENT=54, PREINCREMENT=55, PREDECREMENT=56, START_COMMENT=57, BOGUS=58, END_OF_EXPRESSION=59 } token_type; } *

variable_types:
text
char *

variable_types:
c
unsigned char

user_defined_types: struct token_rule { struct token_rule *children; enum token_type token_type; }


decompiled_code:
void __fastcall done_lex(int a1, int a2, int a3, int a4, int a5, int a6, int a7, struct obstack obstack)
{
obstack_free(&obstack, 0LL);
}

canonical_decompiled_code:
void __fastcall func6(int a1, int a2, int a3, int a4, int a5, int a6, int a7, struct obstack obstack)
{
obstack_free(&obstack, 0LL);
}

original_code:
void done_lex(lex_buf buf) {
    __extension__ ({ struct obstack *__o = (&buf.obstack); void *__obj = (0); if (__obj > (void *) __o->chunk && __obj < (void *) __o->chunk_limit) __o->next_free = __o->object_base = (char *) __obj; else (obstack_free) (__o, __obj); });
}

canonical_original_code:
void done_lex(struct lex_buf buf) {
    __extension__ ({ struct obstack *__o = (&buf.obstack); void *__obj = (0); if (__obj > (void *) __o->chunk && __obj < (void *) __o->chunk_limit) __o->next_free = __o->object_base = (char *) __obj; else (obstack_free) (__o, __obj); });
}

variable_types: struct lex_buf { char *pos; struct obstack { long chunk_size; struct _obstack_chunk { char *limit; struct _obstack_chunk *prev; char contents[4]; } *chunk; char *object_base; char *next_free; char *chunk_limit; union { long tempint; void *tempptr; } temp; int alignment_mask; struct _obstack_chunk *(*chunkfun)(void *, long); void (*freefun)(void *, struct _obstack_chunk *); void *extra_arg; unsigned int use_extra_arg; unsigned int maybe_empty_object; unsigned int alloc_failed; } obstack; }

variable_types: struct obstack { long chunk_size; struct _obstack_chunk { char *limit; struct _obstack_chunk *prev; char contents[4]; } *chunk; char *object_base; char *next_free; char *chunk_limit; union { long tempint; void *tempptr; } temp; int alignment_mask; struct _obstack_chunk *(*chunkfun)(void *, long); void (*freefun)(void *, struct _obstack_chunk *); void *extra_arg; unsigned int use_extra_arg; unsigned int maybe_empty_object; unsigned int alloc_failed; } *

user_defined_types: struct lex_buf { char *pos; struct obstack obstack; }


decompiled_code:
__int64 __fastcall get_next_token(unsigned __int8 **a1)
{
unsigned __int8 *v2; // rbx
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rcx
int v6; // eax
char v7; // dl
unsigned __int8 v8; // al
unsigned __int8 *v9; // rdx
unsigned __int8 *v11; // rsi
unsigned __int8 *v12; // rax
unsigned __int8 *v13; // rsi
unsigned __int8 v14; // cl
const unsigned __int16 **v15; // rdx
signed __int8 v16; // al
__int64 v17; // [rsp+0h] [rbp-28h] BYREF
__int64 v18; // [rsp+8h] [rbp-20h]

v2 = *a1;
v18 = 0LL;
while ( 1 )
{
while ( 1 )
{
LABEL_2:
v3 = rules;
v4 = *(_QWORD *)rules;
v5 = rules;
if ( *(_QWORD *)rules )
{
while ( 1 )
{
v5 = v3;
v3 = v4 + 16LL * *v2;
if ( !*(_DWORD *)(v3 + 8) )
break;
++v2;
v4 = *(_QWORD *)v3;
if ( !*(_QWORD *)v3 )
{
v5 = v3;
break;
}
}
}
v6 = *(_DWORD *)(v5 + 8);
if ( v6 == 31 )
{
if ( (unsigned __int8)(*v2 - 48) <= 9u )
v2 = read_literal_or_id((__int64)a1, v2 - 1, (__int64)&v17);
else
LODWORD(v17) = 31;
goto LABEL_28;
}
if ( v6 != 57 )
break;
v8 = *v2;
if ( *v2 )
{
while ( 1 )
{
v9 = v2++;
if ( v8 == 42 && *v2 == 47 )
break;
v8 = *v2;
if ( !*v2 )
goto LABEL_2;
}
v2 = v9 + 2;
}
}
if ( rules != v5 )
{
LODWORD(v17) = *(_DWORD *)(v5 + 8);
goto LABEL_28;
}
v7 = *v2;
if ( (char)*v2 > 95 )
break;
if ( v7 > 31 )
{
switch ( v7 )
{
case ' ':
goto LABEL_24;
case '"':
case '\'':
v12 = v2;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
goto LABEL_36;
default:
goto LABEL_26;
}
while ( 1 )
{
v13 = v12++;
v14 = *v12;
if ( v7 == *v12 )
break;
if ( !v14 )
{
LODWORD(v17) = 58;
v2 = v12;
goto LABEL_28;
}
v11 = v13 + 2;
if ( v14 == 92 )
v12 = v11;
}
v18 = obstack_strndup(a1 + 1, v2, v13 + 2 - v2);
LODWORD(v17) = 1;
v2 = v13 + 2;
goto LABEL_28;
}
if ( !v7 )
{
LODWORD(v17) = 59;
goto LABEL_28;
}
if ( (unsigned __int8)(v7 - 9) > 2u )
goto LABEL_26;
LABEL_24:
++v2;
}
if ( (unsigned __int8)(v7 - 97) > 0x19u )
{
LABEL_26:
v18 = obstack_strdup(a1 + 1, v2);
LODWORD(v17) = 58;
++v2;
goto LABEL_28;
}
LABEL_36:
if ( memcmp(v2, "sizeof", 6uLL) || (v15 = _ctype_b_loc(), v16 = v2[6], ((*v15)[v16] & 8) != 0) || v16 == 95 )
{
v2 = read_literal_or_id((__int64)a1, v2, (__int64)&v17);
}
else
{
LODWORD(v17) = 44;
v2 += 6;
}
LABEL_28:
*a1 = v2;
return v17;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 **a1)
{
unsigned __int8 *v2; // rbx
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rcx
int v6; // eax
char v7; // dl
unsigned __int8 v8; // al
unsigned __int8 *v9; // rdx
unsigned __int8 *v11; // rsi
unsigned __int8 *v12; // rax
unsigned __int8 *v13; // rsi
unsigned __int8 v14; // cl
const unsigned __int16 **v15; // rdx
signed __int8 v16; // al
__int64 v17; // [rsp+0h] [rbp-28h] BYREF
__int64 v18; // [rsp+8h] [rbp-20h]

v2 = *a1;
v18 = 0LL;
while ( 1 )
{
while ( 1 )
{
LABEL_2:
v3 = rules;
v4 = *(_QWORD *)rules;
v5 = rules;
if ( *(_QWORD *)rules )
{
while ( 1 )
{
v5 = v3;
v3 = v4 + 16LL * *v2;
if ( !*(_DWORD *)(v3 + 8) )
break;
++v2;
v4 = *(_QWORD *)v3;
if ( !*(_QWORD *)v3 )
{
v5 = v3;
break;
}
}
}
v6 = *(_DWORD *)(v5 + 8);
if ( v6 == 31 )
{
if ( (unsigned __int8)(*v2 - 48) <= 9u )
v2 = func5((__int64)a1, v2 - 1, (__int64)&v17);
else
LODWORD(v17) = 31;
goto LABEL_28;
}
if ( v6 != 57 )
break;
v8 = *v2;
if ( *v2 )
{
while ( 1 )
{
v9 = v2++;
if ( v8 == 42 && *v2 == 47 )
break;
v8 = *v2;
if ( !*v2 )
goto LABEL_2;
}
v2 = v9 + 2;
}
}
if ( rules != v5 )
{
LODWORD(v17) = *(_DWORD *)(v5 + 8);
goto LABEL_28;
}
v7 = *v2;
if ( (char)*v2 > 95 )
break;
if ( v7 > 31 )
{
switch ( v7 )
{
case ' ':
goto LABEL_24;
case '"':
case '\'':
v12 = v2;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
goto LABEL_36;
default:
goto LABEL_26;
}
while ( 1 )
{
v13 = v12++;
v14 = *v12;
if ( v7 == *v12 )
break;
if ( !v14 )
{
LODWORD(v17) = 58;
v2 = v12;
goto LABEL_28;
}
v11 = v13 + 2;
if ( v14 == 92 )
v12 = v11;
}
v18 = obstack_strndup(a1 + 1, v2, v13 + 2 - v2);
LODWORD(v17) = 1;
v2 = v13 + 2;
goto LABEL_28;
}
if ( !v7 )
{
LODWORD(v17) = 59;
goto LABEL_28;
}
if ( (unsigned __int8)(v7 - 9) > 2u )
goto LABEL_26;
LABEL_24:
++v2;
}
if ( (unsigned __int8)(v7 - 97) > 0x19u )
{
LABEL_26:
v18 = obstack_strdup(a1 + 1, v2);
LODWORD(v17) = 58;
++v2;
goto LABEL_28;
}
LABEL_36:
if ( memcmp(v2, "sizeof", 6uLL) || (v15 = _ctype_b_loc(), v16 = v2[6], ((*v15)[v16] & 8) != 0) || v16 == 95 )
{
v2 = func5((__int64)a1, v2, (__int64)&v17);
}
else
{
LODWORD(v17) = 44;
v2 += 6;
}
LABEL_28:
*a1 = v2;
return v17;
}

original_code:
struct token get_next_token(lex_buf* buf) {
    const char* pos = buf->pos;
    struct token token;
    token.token_value = 0;
    while (1) {
        struct token_rule *rule = rules;
        while (rule->children && rule->children[(unsigned char)*pos].token_type) {
            rule = rule->children + (unsigned char)*pos++;
        }
        if (rule->token_type == DOT) {
            char nextc = *pos;
            if (nextc < '0' || nextc > '9') {
                token.token_type = rule->token_type;
            } else {
                pos = read_literal_or_id(buf, pos - 1, &token);
            }
            goto done;
        } else if (rule->token_type == START_COMMENT) {
            while (*pos) {
                char c = *pos++;
                if (c == '*') {
                    if (*pos == '/') {
                        pos++;
                        break;
                    }
                }
            }
        } else if (rule != rules) {
            token.token_type = rule->token_type;
            goto done;
        } else {
            switch (*pos) {
            case 0:
                token.token_type = END_OF_EXPRESSION;
                goto done;
            case ' ': case '\t': case '\v': case '\n':
                break;
            case '\'':
            case '"':
            {
                char delimiter = *pos;
                const char *start = pos;
                while (*++pos != delimiter) {
                    if (!*pos) {
                        token.token_type = BOGUS;
                        goto done;
                    } else if (*pos == '\\') {
                        pos ++;
                    }
                }
                pos++;
                char* val = obstack_strndup(&buf->obstack, start, pos - start);
                token.token_value = val;
                token.token_type = LITERAL_OR_ID;
                goto done;
            }
            case '_': case 'A': case 'a': case 'B': case 'b': case 'C': case 'c': case 'D': case 'd': case 'E': case 'e': case 'F': case 'f': case 'G': case 'g': case 'H': case 'h': case 'I': case 'i': case 'J': case 'j': case 'K': case 'k': case 'L': case 'l': case 'M': case 'm': case 'N': case 'n': case 'O': case 'o': case 'P': case 'p': case 'Q': case 'q': case 'R': case 'r': case 'S': case 's': case 'T': case 't': case 'U': case 'u': case 'V': case 'v': case 'W': case 'w': case 'X': case 'x': case 'Y': case 'y': case 'Z': case 'z': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
                if (strncmp(pos, "sizeof", 6) == 0 &&
                    !((*__ctype_b_loc ())[(int) ((pos[6]))] & (unsigned short int) _ISalnum) &&
                    pos[6] != '_') {
                        token.token_type = SIZEOF;
                        pos += 6;
                        goto done;
                } else {
                    pos = read_literal_or_id(buf, pos, &token);
                    goto done;
                }
                break;
            default:
                token.token_value = obstack_strdup(&buf->obstack, pos);
                token.token_type = BOGUS;
                pos++;
                goto done;
            }
            ++pos;
        }
    }
done:
    buf->pos = pos;
    return token;
}

canonical_original_code:
struct token get_next_token(struct lex_buf *buf) {
    char *pos = buf->pos;
    struct token token;
    token.token_value = 0;
    while (1) {
        struct token_rule *rule = rules;
        while (rule->children && rule->children[(unsigned char)*pos].token_type) {
            rule = rule->children + (unsigned char)*pos++;
        }
        if (rule->token_type == DOT) {
            char nextc = *pos;
            if (nextc < '0' || nextc > '9') {
                token.token_type = rule->token_type;
            } else {
                pos = read_literal_or_id(buf, pos - 1, &token);
            }
            goto done;
        } else if (rule->token_type == START_COMMENT) {
            while (*pos) {
                char c = *pos++;
                if (c == '*') {
                    if (*pos == '/') {
                        pos++;
                        break;
                    }
                }
            }
        } else if (rule != rules) {
            token.token_type = rule->token_type;
            goto done;
        } else {
            switch (*pos) {
            case 0:
                token.token_type = END_OF_EXPRESSION;
                goto done;
            case ' ': case '\t': case '\v': case '\n':
                break;
            case '\'':
            case '"':
            {
                char delimiter = *pos;
                char *start = pos;
                while (*++pos != delimiter) {
                    if (!*pos) {
                        token.token_type = BOGUS;
                        goto done;
                    } else if (*pos == '\\') {
                        pos ++;
                    }
                }
                pos++;
                char *val = obstack_strndup(&buf->obstack, start, pos - start);
                token.token_value = val;
                token.token_type = LITERAL_OR_ID;
                goto done;
            }
            case '_': case 'A': case 'a': case 'B': case 'b': case 'C': case 'c': case 'D': case 'd': case 'E': case 'e': case 'F': case 'f': case 'G': case 'g': case 'H': case 'h': case 'I': case 'i': case 'J': case 'j': case 'K': case 'k': case 'L': case 'l': case 'M': case 'm': case 'N': case 'n': case 'O': case 'o': case 'P': case 'p': case 'Q': case 'q': case 'R': case 'r': case 'S': case 's': case 'T': case 't': case 'U': case 'u': case 'V': case 'v': case 'W': case 'w': case 'X': case 'x': case 'Y': case 'y': case 'Z': case 'z': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
                if (strncmp(pos, "sizeof", 6) == 0 &&
                    !((*__ctype_b_loc ())[(int) ((pos[6]))] & (unsigned short) _ISalnum) &&
                    pos[6] != '_') {
                        token.token_type = SIZEOF;
                        pos += 6;
                        goto done;
                } else {
                    pos = read_literal_or_id(buf, pos, &token);
                    goto done;
                }
                break;
            default:
                token.token_value = obstack_strdup(&buf->obstack, pos);
                token.token_type = BOGUS;
                pos++;
                goto done;
            }
            ++pos;
        }
    }
done:
    buf->pos = pos;
    return token;
}

variable_types: struct lex_buf { char *pos; struct obstack { long chunk_size; struct _obstack_chunk { char *limit; struct _obstack_chunk *prev; char contents[4]; } *chunk; char *object_base; char *next_free; char *chunk_limit; union { long tempint; void *tempptr; } temp; int alignment_mask; struct _obstack_chunk *(*chunkfun)(void *, long); void (*freefun)(void *, struct _obstack_chunk *); void *extra_arg; unsigned int use_extra_arg; unsigned int maybe_empty_object; unsigned int alloc_failed; } obstack; } *

variable_types: struct token { enum token_type { LITERAL_OR_ID=1, OPEN_PAREN=2, CLOSE_PAREN=3, OPEN_BRACKET=4, CLOSE_BRACKET=5, OPEN_CURLY=6, CLOSE_CURLY=7, BANG=8, PERCENT=9, CARET=10, AMPERSAND=11, BAR=12, STAR=13, MINUS=14, PLUS=15, SLASH=16, LEFT_SHIFT=17, RIGHT_SHIFT=18, BANG_EQUAL=19, PERCENT_EQUAL=20, CARET_EQUAL=21, AMPERSAND_EQUAL=22, BAR_EQUAL=23, STAR_EQUAL=24, MINUS_EQUAL=25, PLUS_EQUAL=26, SLASH_EQUAL=27, LEFT_SHIFT_EQUAL=28, RIGHT_SHIFT_EQUAL=29, ARROW=30, DOT=31, ASSIGN=32, IS_EQUAL=33, LTE=34, GTE=35, LT=36, GT=37, DOUBLE_AMPERSAND=38, DOUBLE_BAR=39, DOUBLE_PLUS=40, DOUBLE_MINUS=41, QUESTION=42, COLON=43, SIZEOF=44, COMMA=45, TILDE=46, TYPECAST=47, FUNCTION_CALL=48, SUBSCRIPT=49, REFERENCE=50, DEREFERENCE=51, UNARY_MINUS=52, POSTINCREMENT=53, POSTDECREMENT=54, PREINCREMENT=55, PREDECREMENT=56, START_COMMENT=57, BOGUS=58, END_OF_EXPRESSION=59 } token_type; char *token_value; }

variable_types: nextc char

variable_types: delimiter char

variable_types:
val
char *

user_defined_types: struct token { enum token_type token_type; char *token_value; }


repo: nowylie/space

original_code:
window_t *window_get(Window id)
{
 window_t *window;
 do { unsigned _hf_bkt,_hf_hashv; window=((void *)0); if (window_map) { do { unsigned _hj_i,_hj_j,_hj_k; unsigned char *_hj_key=(unsigned char*)(&id); _hf_hashv = 0xfeedbeef; _hj_i = _hj_j = 0x9e3779b9; _hj_k = (unsigned)(sizeof(Window)); while (_hj_k >= 12) { _hj_i += (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 ) + ( (unsigned)_hj_key[2] << 16 ) + ( (unsigned)_hj_key[3] << 24 ) ); _hj_j += (_hj_key[4] + ( (unsigned)_hj_key[5] << 8 ) + ( (unsigned)_hj_key[6] << 16 ) + ( (unsigned)_hj_key[7] << 24 ) ); _hf_hashv += (_hj_key[8] + ( (unsigned)_hj_key[9] << 8 ) + ( (unsigned)_hj_key[10] << 16 ) + ( (unsigned)_hj_key[11] << 24 ) ); do { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 13 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 12 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 3 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 15 ); } while (0); _hj_key += 12; _hj_k -= 12; } _hf_hashv += sizeof(Window); switch ( _hj_k ) { case 11: _hf_hashv += ( (unsigned)_hj_key[10] << 24 ); case 10: _hf_hashv += ( (unsigned)_hj_key[9] << 16 ); case 9: _hf_hashv += ( (unsigned)_hj_key[8] << 8 ); case 8: _hj_j += ( (unsigned)_hj_key[7] << 24 ); case 7: _hj_j += ( (unsigned)_hj_key[6] << 16 ); case 6: _hj_j += ( (unsigned)_hj_key[5] << 8 ); case 5: _hj_j += _hj_key[4]; case 4: _hj_i += ( (unsigned)_hj_key[3] << 24 ); case 3: _hj_i += ( (unsigned)_hj_key[2] << 16 ); case 2: _hj_i += ( (unsigned)_hj_key[1] << 8 ); case 1: _hj_i += _hj_key[0]; } do { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 13 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 12 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 3 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 15 ); } while (0); _hf_bkt = _hf_hashv & ((window_map)->hh.tbl->num_buckets-1); } while(0); if ((1)) { do { if ((window_map)->hh.tbl->buckets[ _hf_bkt ].hh_head) do { (window) = (__typeof(window))(((void*)(((char*)((window_map)->hh.tbl->buckets[ _hf_bkt ].hh_head)) - (((window_map)->hh.tbl)->hho)))); } while(0); else window=((void *)0); while (window) { if ((window)->hh.keylen == sizeof(Window)) { if ((memcmp((window)->hh.key,&id,sizeof(Window))) == 0) break; } if ((window)->hh.hh_next) do { (window) = (__typeof(window))(((void*)(((char*)((window)->hh.hh_next)) - (((window_map)->hh.tbl)->hho)))); } while(0); else window = ((void *)0); } } while(0); } } } while (0);
 return window;
}

canonical_original_code:
struct window_def *window_get(unsigned long id)
{
 struct window_def *window;
 do { unsigned int _hf_bkt; unsigned int _hf_hashv; window=((void *)0); if (window_map) { do { unsigned int _hj_i; unsigned int _hj_j; unsigned int _hj_k; unsigned char *_hj_key = (unsigned char*)(&id); _hf_hashv = 0xfeedbeef; _hj_i = _hj_j = 0x9e3779b9; _hj_k = (unsigned int)(sizeof(Window)); while (_hj_k >= 12) { _hj_i += (_hj_key[0] + ( (unsigned int)_hj_key[1] << 8 ) + ( (unsigned int)_hj_key[2] << 16 ) + ( (unsigned int)_hj_key[3] << 24 ) ); _hj_j += (_hj_key[4] + ( (unsigned int)_hj_key[5] << 8 ) + ( (unsigned int)_hj_key[6] << 16 ) + ( (unsigned int)_hj_key[7] << 24 ) ); _hf_hashv += (_hj_key[8] + ( (unsigned int)_hj_key[9] << 8 ) + ( (unsigned int)_hj_key[10] << 16 ) + ( (unsigned int)_hj_key[11] << 24 ) ); do { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 13 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 12 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 3 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 15 ); } while (0); _hj_key += 12; _hj_k -= 12; } _hf_hashv += sizeof(Window); switch ( _hj_k ) { case 11: _hf_hashv += ( (unsigned int)_hj_key[10] << 24 ); case 10: _hf_hashv += ( (unsigned int)_hj_key[9] << 16 ); case 9: _hf_hashv += ( (unsigned int)_hj_key[8] << 8 ); case 8: _hj_j += ( (unsigned int)_hj_key[7] << 24 ); case 7: _hj_j += ( (unsigned int)_hj_key[6] << 16 ); case 6: _hj_j += ( (unsigned int)_hj_key[5] << 8 ); case 5: _hj_j += _hj_key[4]; case 4: _hj_i += ( (unsigned int)_hj_key[3] << 24 ); case 3: _hj_i += ( (unsigned int)_hj_key[2] << 16 ); case 2: _hj_i += ( (unsigned int)_hj_key[1] << 8 ); case 1: _hj_i += _hj_key[0]; } do { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 13 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 12 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 3 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 15 ); } while (0); _hf_bkt = _hf_hashv & ((window_map)->hh.tbl->num_buckets-1); } while(0); if ((1)) { do { if ((window_map)->hh.tbl->buckets[ _hf_bkt ].hh_head) do { (window) = (__typeof(window))(((void *)(((char *)((window_map)->hh.tbl->buckets[ _hf_bkt ].hh_head)) - (((window_map)->hh.tbl)->hho)))); } while(0); else window=((void *)0); while (window) { if ((window)->hh.keylen == sizeof(Window)) { if ((memcmp((window)->hh.key,&id,sizeof(Window))) == 0) break; } if ((window)->hh.hh_next) do { (window) = (__typeof(window))(((void *)(((char *)((window)->hh.hh_next)) - (((window_map)->hh.tbl)->hho)))); } while(0); else window = ((void *)0); } } while(0); } } } while (0);
 return window;
}

variable_types:
id
unsigned long

variable_types: struct window_def { unsigned long id; int x; unsigned int width; unsigned long pixmap; unsigned long picture; char mapped; char dirty; struct window_def *prev; struct UT_hash_handle { struct UT_hash_table { struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; } *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; } *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; } hh; } *

user_defined_types: struct window_def { unsigned long id; int x; unsigned int width; unsigned long pixmap; unsigned long picture; char mapped; char dirty; struct window_def *prev; struct UT_hash_handle hh; }

user_defined_types: struct UT_hash_handle { struct UT_hash_table *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; }

user_defined_types: struct UT_hash_table { struct UT_hash_bucket *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; }


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

result = window_get(a1);
if ( window_list == result )
window_list = *(_QWORD *)(result + 56);
if ( window_list_last == result )
window_list_last = *(_QWORD *)(result + 48);
v2 = *(_QWORD *)(result + 48);
if ( v2 )
*(_QWORD *)(v2 + 56) = *(_QWORD *)(result + 56);
v3 = *(_QWORD *)(result + 56);
if ( v3 )
*(_QWORD *)(v3 + 48) = *(_QWORD *)(result + 48);
*(_QWORD *)(result + 48) = 0LL;
*(_QWORD *)(result + 56) = 0LL;
return result;
}

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

result = func0(a1);
if ( window_list == result )
window_list = *(_QWORD *)(result + 56);
if ( window_list_last == result )
window_list_last = *(_QWORD *)(result + 48);
v2 = *(_QWORD *)(result + 48);
if ( v2 )
*(_QWORD *)(v2 + 56) = *(_QWORD *)(result + 56);
v3 = *(_QWORD *)(result + 56);
if ( v3 )
*(_QWORD *)(v3 + 48) = *(_QWORD *)(result + 48);
*(_QWORD *)(result + 48) = 0LL;
*(_QWORD *)(result + 56) = 0LL;
return result;
}

original_code:
window_t *window_list_remove(Window id)
{
 window_t *window = window_get(id);
 if (window_list == window)
  window_list = window->next;
 if (window_list_last == window)
  window_list_last = window->prev;
 if (window->prev != ((void *)0)) {
  window->prev->next = window->next;
 }
 if (window->next != ((void *)0)) {
  window->next->prev = window->prev;
 }
 window->prev = ((void *)0);
 window->next = ((void *)0);
 return window;
}

canonical_original_code:
struct window_def *window_list_remove(unsigned long id)
{
 struct window_def *window = window_get(id);
 if (window_list == window)
  window_list = window->next;
 if (window_list_last == window)
  window_list_last = window->prev;
 if (window->prev != ((void *)0)) {
  window->prev->next = window->next;
 }
 if (window->next != ((void *)0)) {
  window->next->prev = window->prev;
 }
 window->prev = ((void *)0);
 window->next = ((void *)0);
 return window;
}

return_type: struct window_def { unsigned long id; int x; unsigned int width; unsigned long pixmap; unsigned long picture; char mapped; char dirty; struct window_def *prev; struct UT_hash_handle { struct UT_hash_table { struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; } *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; } *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; } hh; } *


decompiled_code:
__int64 __fastcall window_list_prepend(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = window_get(a1);
*(_QWORD *)(result + 48) = 0LL;
v2 = window_list;
*(_QWORD *)(result + 56) = window_list;
if ( v2 )
*(_QWORD *)(v2 + 48) = result;
else
window_list_last = result;
window_list = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = func0(a1);
*(_QWORD *)(result + 48) = 0LL;
v2 = window_list;
*(_QWORD *)(result + 56) = window_list;
if ( v2 )
*(_QWORD *)(v2 + 48) = result;
else
window_list_last = result;
window_list = result;
return result;
}

original_code:
void window_list_prepend(Window id)
{
 window_t *window = window_get(id);
 window->prev = ((void *)0);
 window->next = window_list;
 if (window_list != ((void *)0))
  window_list->prev = window;
 else
  window_list_last = window;
 window_list = window;
}

canonical_original_code:
void window_list_prepend(unsigned long id)
{
 struct window_def *window = window_get(id);
 window->prev = ((void *)0);
 window->next = window_list;
 if (window_list != ((void *)0))
  window_list->prev = window;
 else
  window_list_last = window;
 window_list = window;
}

user_defined_types: struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; }


decompiled_code:
__int64 __fastcall window_list_append(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = window_get(a1);
v2 = window_list_last;
*(_QWORD *)(result + 48) = window_list_last;
*(_QWORD *)(result + 56) = 0LL;
if ( v2 )
*(_QWORD *)(v2 + 56) = result;
else
window_list = result;
window_list_last = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = func0(a1);
v2 = window_list_last;
*(_QWORD *)(result + 48) = window_list_last;
*(_QWORD *)(result + 56) = 0LL;
if ( v2 )
*(_QWORD *)(v2 + 56) = result;
else
window_list = result;
window_list_last = result;
return result;
}

original_code:
void window_list_append(Window id)
{
 window_t *window = window_get(id);
 window->prev = window_list_last;
 window->next = ((void *)0);
 if (window_list_last != ((void *)0))
  window_list_last->next = window;
 else
  window_list = window;
 window_list_last = window;
}

canonical_original_code:
void window_list_append(unsigned long id)
{
 struct window_def *window = window_get(id);
 window->prev = window_list_last;
 window->next = ((void *)0);
 if (window_list_last != ((void *)0))
  window_list_last->next = window;
 else
  window_list = window;
 window_list_last = window;
}


decompiled_code:
__int64 __fastcall window_list_move_before(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 result; // rax
__int64 v4; // rdx

v2 = window_list_remove(a1);
result = window_get(a2);
*(_QWORD *)(v2 + 48) = *(_QWORD *)(result + 48);
*(_QWORD *)(v2 + 56) = result;
v4 = *(_QWORD *)(result + 48);
if ( v4 )
*(_QWORD *)(v4 + 56) = v2;
*(_QWORD *)(result + 48) = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 result; // rax
__int64 v4; // rdx

v2 = func1(a1);
result = func0(a2);
*(_QWORD *)(v2 + 48) = *(_QWORD *)(result + 48);
*(_QWORD *)(v2 + 56) = result;
v4 = *(_QWORD *)(result + 48);
if ( v4 )
*(_QWORD *)(v4 + 56) = v2;
*(_QWORD *)(result + 48) = v2;
return result;
}

original_code:
void window_list_move_before(Window id, Window sibling)
{
 window_t *window, *after;
 window = window_list_remove(id);
 after = window_get(sibling);
 window->prev = after->prev;
 window->next = after;
 if (after->prev != ((void *)0))
  after->prev->next = window;
 after->prev = window;
}

canonical_original_code:
void window_list_move_before(unsigned long id, unsigned long sibling)
{
 struct window_def *window; struct window_def *after;
 window = window_list_remove(id);
 after = window_get(sibling);
 window->prev = after->prev;
 window->next = after;
 if (after->prev != ((void *)0))
  after->prev->next = window;
 after->prev = window;
}

variable_types:
sibling
unsigned long


decompiled_code:
__int64 __fastcall window_list_move_after(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 result; // rax
__int64 v4; // rdx

v2 = window_list_remove(a1);
result = window_get(a2);
*(_QWORD *)(v2 + 48) = result;
v4 = *(_QWORD *)(result + 56);
*(_QWORD *)(v2 + 56) = v4;
if ( v4 )
*(_QWORD *)(v4 + 48) = v2;
*(_QWORD *)(result + 56) = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 result; // rax
__int64 v4; // rdx

v2 = func1(a1);
result = func0(a2);
*(_QWORD *)(v2 + 48) = result;
v4 = *(_QWORD *)(result + 56);
*(_QWORD *)(v2 + 56) = v4;
if ( v4 )
*(_QWORD *)(v4 + 48) = v2;
*(_QWORD *)(result + 56) = v2;
return result;
}

original_code:
void window_list_move_after(Window id, Window sibling)
{
 window_t *window, *before;
 window = window_list_remove(id);
 before = window_get(sibling);
 window->prev = before;
 window->next = before->next;
 if (before->next != ((void *)0))
  before->next->prev = window;
 before->next = window;
}

canonical_original_code:
void window_list_move_after(unsigned long id, unsigned long sibling)
{
 struct window_def *window; struct window_def *before;
 window = window_list_remove(id);
 before = window_get(sibling);
 window->prev = before;
 window->next = before->next;
 if (before->next != ((void *)0))
  before->next->prev = window;
 before->next = window;
}


decompiled_code:
__int64 window_list_get()
{
return window_list;
}

canonical_decompiled_code:
__int64 func6()
{
return window_list;
}

original_code:
window_t *window_list_get()
{
 return window_list;
}

canonical_original_code:
struct window_def *window_list_get()
{
 return window_list;
}