decompiled_code:
_QWORD *mount_list_new()
{
_QWORD *v0; // rax
_QWORD *v1; // rcx
_QWORD *v2; // rdx

v0 = malloc(0x320uLL);
v1 = v0;
v2 = v0 + 100;
do
*v0++ = 0LL;
while ( v0 != v2 );
return v1;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *v0; // rax
_QWORD *v1; // rcx
_QWORD *v2; // rdx

v0 = malloc(0x320uLL);
v1 = v0;
v2 = v0 + 100;
do
*v0++ = 0LL;
while ( v0 != v2 );
return v1;
}

original_code:
MountList *mount_list_new()
{
    MountList *mount_list = (MountList *)malloc(sizeof(MountList));
    int index = -1;
    for (index = 0; index < 100; index++) {
        mount_list -> mounts[index] = ((void *)0);
    }
    return mount_list;
}

canonical_original_code:
struct MountList *mount_list_new()
{
    struct MountList *mount_list = (MountList *)malloc(sizeof(MountList));
    int index = -1;
    for (index = 0; index < 100; index++) {
        mount_list -> mounts[index] = ((void *)0);
    }
    return mount_list;
}

variable_types: index int

return_type: struct MountList { struct Mount { char *directory_path; char *device; } *mounts[100]; } *


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

result = (int)mount_list_size(a1);
a1[(int)result] = a2;
return result;
}

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

result = (int)func0(a1);
a1[(int)result] = a2;
return result;
}

original_code:
void mount_list_add(MountList *mount_list, Mount *mount) {
    int index = mount_list_size(mount_list);
    mount_list -> mounts[index] = mount;
}

canonical_original_code:
void mount_list_add(struct MountList *mount_list, struct Mount *mount) {
    int index = mount_list_size(mount_list);
    mount_list -> mounts[index] = mount;
}

variable_types: struct MountList { struct Mount { char *directory_path; char *device; } *mounts[100]; } *

variable_types:
mount
struct Mount *

return_type: void

user_defined_types: struct MountList { struct Mount *mounts[100]; }


decompiled_code:
__int64 __fastcall mount_list_get(__int64 a1, int a2)
{
return *(_QWORD *)(a1 + 8LL * a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
return *(_QWORD *)(a1 + 8LL * a2);
}

original_code:
Mount *mount_list_get(MountList *mount_list, int index) {
    Mount *mount = mount_list -> mounts[index];
    return mount;
}

canonical_original_code:
struct Mount *mount_list_get(struct MountList *mount_list, int index) {
    struct Mount *mount = mount_list -> mounts[index];
    return mount;
}

variable_types: struct MountList { struct Mount *mounts[100]; } *

variable_types: struct Mount { char *directory_path; char *device; } *


decompiled_code:
__int64 __fastcall mount_list_contains(_QWORD *a1, __int64 a2)
{
int v2; // eax
int v3; // er12
int v4; // ebx
__int64 v5; // rax
__int64 result; // rax

v2 = mount_list_size(a1);
if ( v2 <= 0 )
return 0LL;
v3 = v2;
v4 = 0;
while ( 1 )
{
v5 = mount_list_get((__int64)a1, v4);
result = mount_are_equal(a2, v5);
if ( (_DWORD)result )
break;
if ( v3 == ++v4 )
return result;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, __int64 a2)
{
int v2; // eax
int v3; // er12
int v4; // ebx
__int64 v5; // rax
__int64 result; // rax

v2 = func0(a1);
if ( v2 <= 0 )
return 0LL;
v3 = v2;
v4 = 0;
while ( 1 )
{
v5 = func3((__int64)a1, v4);
result = mount_are_equal(a2, v5);
if ( (_DWORD)result )
break;
if ( v3 == ++v4 )
return result;
}
return 1LL;
}

original_code:
int mount_list_contains(MountList *mount_list, Mount *mount)
{
    int contains = 0;
    int size = mount_list_size(mount_list);
    int index = -1;
    for (index = 0; index < size; index++) {
        Mount *current_mount = mount_list_get(mount_list, index);
        if (mount_are_equal(mount, current_mount)) {
            contains = 1;
            break;
        }
    }
    return contains;
}

canonical_original_code:
int mount_list_contains(struct MountList *mount_list, struct Mount *mount)
{
    int contains = 0;
    int size = mount_list_size(mount_list);
    int index = -1;
    for (index = 0; index < size; index++) {
        struct Mount *current_mount = mount_list_get(mount_list, index);
        if (mount_are_equal(mount, current_mount)) {
            contains = 1;
            break;
        }
    }
    return contains;
}

variable_types: contains int

variable_types: size int

return_type: int

user_defined_types: struct Mount { char *directory_path; char *device; }


decompiled_code:
__int64 __fastcall mount_list_print(_QWORD *a1)
{
__int64 result; // rax
int v2; // ebp
int i; // ebx
__int64 v4; // rax

result = mount_list_size(a1);
if ( (int)result > 0 )
{
v2 = result;
for ( i = 0; i != v2; ++i )
{
v4 = mount_list_get((__int64)a1, i);
result = mount_print(v4);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
__int64 result; // rax
int v2; // ebp
int i; // ebx
__int64 v4; // rax

result = func0(a1);
if ( (int)result > 0 )
{
v2 = result;
for ( i = 0; i != v2; ++i )
{
v4 = func3((__int64)a1, i);
result = mount_print(v4);
}
}
return result;
}

original_code:
void mount_list_print(MountList *mount_list) {
    int size = mount_list_size(mount_list);
    int index = -1;
    for (index = 0; index < size; index++) {
        Mount *mount = mount_list_get(mount_list, index);
        mount_print(mount);
    }
}

canonical_original_code:
void mount_list_print(struct MountList *mount_list) {
    int size = mount_list_size(mount_list);
    int index = -1;
    for (index = 0; index < size; index++) {
        struct Mount *mount = mount_list_get(mount_list, index);
        mount_print(mount);
    }
}


decompiled_code:
__int64 __fastcall mount_list_diff(_QWORD *a1, _QWORD *a2)
{
int v2; // er15
int v3; // er14
int i; // ebp
__int64 v5; // rbx
int j; // ebp
__int64 v7; // rbx
__int64 v9; // [rsp+8h] [rbp-40h]

if ( !a1 || !a2 )
return 0LL;
v2 = mount_list_size(a1);
v3 = mount_list_size(a2);
if ( v2 <= 0 )
{
v9 = 0LL;
}
else
{
v9 = 0LL;
for ( i = 0; i != v2; ++i )
{
v5 = mount_list_get((__int64)a1, i);
if ( !(unsigned int)mount_list_contains(a2, v5) )
v9 = mount_diff_new(v5, 1LL);
}
}
if ( v3 > 0 )
{
for ( j = 0; j != v3; ++j )
{
v7 = mount_list_get((__int64)a2, j);
if ( !(unsigned int)mount_list_contains(a1, v7) )
v9 = mount_diff_new(v7, 0LL);
}
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, _QWORD *a2)
{
int v2; // er15
int v3; // er14
int i; // ebp
__int64 v5; // rbx
int j; // ebp
__int64 v7; // rbx
__int64 v9; // [rsp+8h] [rbp-40h]

if ( !a1 || !a2 )
return 0LL;
v2 = func0(a1);
v3 = func0(a2);
if ( v2 <= 0 )
{
v9 = 0LL;
}
else
{
v9 = 0LL;
for ( i = 0; i != v2; ++i )
{
v5 = func3((__int64)a1, i);
if ( !(unsigned int)func4(a2, v5) )
v9 = mount_diff_new(v5, 1LL);
}
}
if ( v3 > 0 )
{
for ( j = 0; j != v3; ++j )
{
v7 = func3((__int64)a2, j);
if ( !(unsigned int)func4(a1, v7) )
v9 = mount_diff_new(v7, 0LL);
}
}
return v9;
}

original_code:
MountDiff *mount_list_diff(MountList *old_mount_list, MountList *new_mount_list) {
    if (old_mount_list == ((void *)0) || new_mount_list == ((void *)0)) return ((void *)0);
    int old_size = mount_list_size(old_mount_list);
    int new_size = mount_list_size(new_mount_list);
    int index = -1;
    MountDiff *mount_diff = ((void *)0);
    for (index = 0; index < old_size; index++) {
        Mount *old_mount = mount_list_get(old_mount_list, index);
        if (!mount_list_contains(new_mount_list, old_mount)) {
            mount_diff = mount_diff_new(old_mount, 1);
        }
    }
    for (index = 0; index < new_size; index++) {
        Mount *new_mount = mount_list_get(new_mount_list, index);
        if (!mount_list_contains(old_mount_list, new_mount)) {
            mount_diff = mount_diff_new(new_mount, 0);
        }
    }
    return mount_diff;
}

canonical_original_code:
struct MountDiff *mount_list_diff(struct MountList *old_mount_list, struct MountList *new_mount_list) {
    if (old_mount_list == ((void *)0) || new_mount_list == ((void *)0)) return ((void *)0);
    int old_size = mount_list_size(old_mount_list);
    int new_size = mount_list_size(new_mount_list);
    int index = -1;
    struct MountDiff *mount_diff = ((void *)0);
    for (index = 0; index < old_size; index++) {
        struct Mount *old_mount = mount_list_get(old_mount_list, index);
        if (!mount_list_contains(new_mount_list, old_mount)) {
            mount_diff = mount_diff_new(old_mount, 1);
        }
    }
    for (index = 0; index < new_size; index++) {
        struct Mount *new_mount = mount_list_get(new_mount_list, index);
        if (!mount_list_contains(old_mount_list, new_mount)) {
            mount_diff = mount_diff_new(new_mount, 0);
        }
    }
    return mount_diff;
}

variable_types: struct MountDiff { int type; struct Mount { char *directory_path; char *device; } *mount; } *

user_defined_types: struct MountDiff { int type; struct Mount *mount; }


decompiled_code:
int __fastcall mount_print(const char **a1)
{
return printf("The device [%s] is mounted to [%s]. \n", a1[1], *a1);
}

canonical_decompiled_code:
int __fastcall func0(const char **a1)
{
return printf("The device [%s] is mounted to [%s]. \n", a1[1], *a1);
}

original_code:
void mount_print(Mount *mount)
{
    printf("The device [%s] is mounted to [%s]. \n", mount -> device, mount -> directory_path);
}

canonical_original_code:
void mount_print(struct Mount *mount)
{
    printf("The device [%s] is mounted to [%s]. \n", mount -> device, mount -> directory_path);
}


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

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

original_code:
int mount_are_equal(Mount *one_mount, Mount *other_mount) {
    if (strcmp(one_mount -> directory_path, other_mount -> directory_path) == 0) {
        return 1;
    } else {
        return 0;
    }
}

canonical_original_code:
int mount_are_equal(struct Mount *one_mount, struct Mount *other_mount) {
    if (strcmp(one_mount -> directory_path, other_mount -> directory_path) == 0) {
        return 1;
    } else {
        return 0;
    }
}


decompiled_code:
__int64 __fastcall text_length(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

original_code:
int text_length(char *text)
{
    int length = 0;
    while (text[length] != '\0') length++;
    return length;
}

variable_types:
text
char *

variable_types: length int


decompiled_code:
char *__fastcall text_color(_BYTE *a1, _BYTE *a2)
{
int v2; // ebx
int v3; // ebx
int v4; // eax
char *v5; // rbx

v2 = text_length(a1);
v3 = v2 + text_length(a2) + 1;
v4 = text_length("\x1B[0m");
v5 = (char *)malloc(v3 + v4);
sprintf(v5, "%s%s%s", a2, a1, "\x1B[0m");
return v5;
}

canonical_decompiled_code:
char *__fastcall func1(_BYTE *a1, _BYTE *a2)
{
int v2; // ebx
int v3; // ebx
int v4; // eax
char *v5; // rbx

v2 = func0(a1);
v3 = v2 + func0(a2) + 1;
v4 = func0("\x1B[0m");
v5 = (char *)malloc(v3 + v4);
sprintf(v5, "%s%s%s", a2, a1, "\x1B[0m");
return v5;
}

original_code:
char *text_color(char *text, char *color)
{
    char *colored_text = (char *)malloc(sizeof(char) * (text_length(text) + 1 + text_length(color) + text_length("\033[0m")));
    sprintf(colored_text, "%s%s%s", color, text, "\033[0m");
    return colored_text;
}

variable_types:
color
char *

return_type: char *


decompiled_code:
char *__fastcall text_red(_BYTE *a1)
{
return text_color(a1, "\x1B[0;31m");
}

canonical_decompiled_code:
char *__fastcall func2(_BYTE *a1)
{
return func1(a1, "\x1B[0;31m");
}

original_code:
char *text_red(char *text) {
    return text_color(text, "\033[0;31m");
}


decompiled_code:
char *__fastcall text_copy(char *src)
{
int v1; // eax
char *v2; // rax

v1 = text_length(src);
v2 = (char *)malloc(v1 + 1);
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func3(char *src)
{
int v1; // eax
char *v2; // rax

v1 = func0(src);
v2 = (char *)malloc(v1 + 1);
return strcpy(v2, src);
}

original_code:
char *text_copy(char *text) {
    int size = text_length(text);
    char *copied_text = (char *)malloc(sizeof(char) * (size + 1));
    strcpy(copied_text, text);
    return copied_text;
}


decompiled_code:
void __fastcall mount_poll_handler_user_data_destroy(void *a1)
{
_mount_poll_handler_user_data_free(a1);
}

canonical_decompiled_code:
void __fastcall func8(void *a1)
{
func6(a1);
}

original_code:
void mount_poll_handler_user_data_destroy(MountPollHandlerUserData* user_data)
{
    __mount_poll_handler_user_data_free(user_data);
}

canonical_original_code:
void mount_poll_handler_user_data_destroy(struct MountPollHandlerUserData *user_data)
{
    __mount_poll_handler_user_data_free(user_data);
}

variable_types: struct MountPollHandlerUserData { char *mounts_file_path; struct MountList { struct Mount { char *directory_path; char *device; } *mounts[100]; } *last_mount_list; void (*handler)(struct MountDiff { int type; struct Mount *mount; } *); } *

user_defined_types: struct MountPollHandlerUserData { char *mounts_file_path; struct MountList *last_mount_list; void (*handler)(struct MountDiff *); }


decompiled_code:
void __fastcall poll_destroy(void *a1)
{
_poll_free(a1);
}

canonical_decompiled_code:
void __fastcall func2(void *a1)
{
func1(a1);
}

original_code:
void poll_destroy(Poll *poll)
{
    __poll_free(poll);
}

canonical_original_code:
void poll_destroy(struct Poll *poll)
{
    __poll_free(poll);
}

variable_types: struct Poll { char *directory_path; struct pollfd { int fd; short events; short revents; } *pollfd; } *

user_defined_types: struct Poll { char *directory_path; struct pollfd *pollfd; }


decompiled_code:
void __fastcall poll_event_destroy(void *a1)
{
_poll_event_free(a1);
}

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

original_code:
void poll_event_destroy(PollEvent *poll_event)
{
    __poll_event_free(poll_event);
}

canonical_original_code:
void poll_event_destroy(struct PollEvent *poll_event)
{
    __poll_event_free(poll_event);
}

variable_types: struct PollEvent { struct Poll { char *directory_path; struct pollfd { int fd; short events; short revents; } *pollfd; } *poll; } *


decompiled_code:
int __fastcall handle_mount_diff(int *a1)
{
int v2; // edx
const char *v3; // rdi
__int64 v4; // rbp
const char *v5; // rbx
const char *v6; // rax

v2 = *a1;
v3 = "ADDED";
if ( v2 )
{
v3 = "REMOVED";
if ( v2 != 1 )
v3 = 0LL;
}
v4 = *(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL);
v5 = (const char *)text_red(v3);
v6 = (const char *)text_red(v4);
return printf("%s has been %s\n", v6, v5);
}

canonical_decompiled_code:
int __fastcall func0(int *a1)
{
int v2; // edx
const char *v3; // rdi
__int64 v4; // rbp
const char *v5; // rbx
const char *v6; // rax

v2 = *a1;
v3 = "ADDED";
if ( v2 )
{
v3 = "REMOVED";
if ( v2 != 1 )
v3 = 0LL;
}
v4 = *(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL);
v5 = (const char *)text_red(v3);
v6 = (const char *)text_red(v4);
return printf("%s has been %s\n", v6, v5);
}

original_code:
void handle_mount_diff(MountDiff *mount_diff)
{
    char *label = ((void *)0);
    label = ((void *)0);
    switch(mount_diff -> type)
    {
        case 0:
            label = "ADDED";
            break;
        case 1:
            label = "REMOVED";
            break;
    }
    char *device = mount_diff -> mount -> device;
    printf("%s has been %s\n", text_red(device), text_red(label));
}

canonical_original_code:
void handle_mount_diff(struct MountDiff *mount_diff)
{
    char *label = ((void *)0);
    label = ((void *)0);
    switch(mount_diff -> type)
    {
        case 0:
            label = "ADDED";
            break;
        case 1:
            label = "REMOVED";
            break;
    }
    char *device = mount_diff -> mount -> device;
    printf("%s has been %s\n", text_red(device), text_red(label));
}

variable_types:
label
char *

variable_types:
device
char *


balloc

repo: raedwulf/buddyalloc

variable_types:
size
unsigned int

variable_types:
x
unsigned int

variable_types:
bs
unsigned int

variable_types:
blk
unsigned int

variable_types:
i
unsigned int

variable_types:
b
unsigned int

variable_types:
a
unsigned int

variable_types:
l
unsigned int

variable_types:
r
unsigned int

return_type: void *


btrav

decompiled_code:
__int64 __fastcall btrav(unsigned int a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax
int v5; // eax
unsigned int v6; // esi
unsigned int v7; // ebp
int v8; // ecx
int v9; // edi

result = 0xFFFFFFFFLL;
if ( a3 > 0x3FF )
{
v5 = (btree[a2 >> 3] >> (a2 & 7)) & 1;
if ( a3 == a1 && !v5 )
{
result = a2;
}
else
{
v6 = 2 * a2;
v7 = v6 + 1;
if ( !v5
|| (v8 = btree[v6 >> 3], _bittest(&v8, v6 & 7))
|| (v9 = btree[v7 >> 3], result = 0xFFFFFFFFLL, _bittest(&v9, v7 & 7)) )
{
result = btrav(a1);
if ( (_DWORD)result == -1 )
result = btrav(a1);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax
int v5; // eax
unsigned int v6; // esi
unsigned int v7; // ebp
int v8; // ecx
int v9; // edi

result = 0xFFFFFFFFLL;
if ( a3 > 0x3FF )
{
v5 = (btree[a2 >> 3] >> (a2 & 7)) & 1;
if ( a3 == a1 && !v5 )
{
result = a2;
}
else
{
v6 = 2 * a2;
v7 = v6 + 1;
if ( !v5
|| (v8 = btree[v6 >> 3], _bittest(&v8, v6 & 7))
|| (v9 = btree[v7 >> 3], result = 0xFFFFFFFFLL, _bittest(&v9, v7 & 7)) )
{
result = func8(a1);
if ( (_DWORD)result == -1 )
result = func8(a1);
}
}
}
return result;
}

original_code:
uint32_t btrav(uint32_t size, uint32_t n, uint32_t s)
{
 uint32_t a;
 uint32_t l = n << 1, r = (n << 1) + 1;
 if (s < (1 << 10)) return 0xffffffff;
 if (!(btree[(n) >> 3] & (1 << ((n) & 7))) && size == s)
  return n;
 else if ((btree[(n) >> 3] & (1 << ((n) & 7))) && !((btree[(l) >> 3] & (1 << ((l) & 7))) || (btree[(r) >> 3] & (1 << ((r) & 7)))))
  return 0xffffffff;
 else {
  if ((a = btrav(size, l, s >> 1)) != 0xffffffff)
   return a;
  if ((a = btrav(size, r, s >> 1)) != 0xffffffff)
   return a;
  return 0xffffffff;
 }
}

canonical_original_code:
unsigned int btrav(unsigned int size, unsigned int n, unsigned int s)
{
 unsigned int a;
 unsigned int l = n << 1; unsigned int r = (n << 1) + 1;
 if (s < (1 << 10)) return 0xffffffff;
 if (!(btree[(n) >> 3] & (1 << ((n) & 7))) && size == s)
  return n;
 else if ((btree[(n) >> 3] & (1 << ((n) & 7))) && !((btree[(l) >> 3] & (1 << ((l) & 7))) || (btree[(r) >> 3] & (1 << ((r) & 7)))))
  return 0xffffffff;
 else {
  if ((a = btrav(size, l, s >> 1)) != 0xffffffff)
   return a;
  if ((a = btrav(size, r, s >> 1)) != 0xffffffff)
   return a;
  return 0xffffffff;
 }
}

variable_types:
n
unsigned int

variable_types:
s
unsigned int

return_type: unsigned int


decompiled_code:
char *__fastcall balloc2(unsigned int a1)
{
char *result; // rax
int v2; // ecx
unsigned int v3; // esi
unsigned int v4; // eax
unsigned int v5; // eax

result = 0LL;
if ( a1 )
{
v2 = 1024;
if ( a1 >= 0x400 )
v2 = a1;
_BitScanReverse((unsigned int *)&v2, v2 - 1);
v3 = btrav(0x100000 >> ((v2 ^ 0x1F) - 12), 1u, 0x100000u);
result = 0LL;
if ( v3 != -1 )
{
if ( v3 )
{
v4 = v3;
do
{
btree[v4 >> 3] |= 1 << (v4 & 7);
v4 >>= 1;
}
while ( v4 );
}
_BitScanReverse(&v5, v3);
result = (char *)&bmem + (0x100000 >> (31 - (v5 ^ 0x1F))) * (v3 - (1 << (31 - (v5 ^ 0x1F))));
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func9(unsigned int a1)
{
char *result; // rax
int v2; // ecx
unsigned int v3; // esi
unsigned int v4; // eax
unsigned int v5; // eax

result = 0LL;
if ( a1 )
{
v2 = 1024;
if ( a1 >= 0x400 )
v2 = a1;
_BitScanReverse((unsigned int *)&v2, v2 - 1);
v3 = func8(0x100000 >> ((v2 ^ 0x1F) - 12), 1u, 0x100000u);
result = 0LL;
if ( v3 != -1 )
{
if ( v3 )
{
v4 = v3;
do
{
btree[v4 >> 3] |= 1 << (v4 & 7);
v4 >>= 1;
}
while ( v4 );
}
_BitScanReverse(&v5, v3);
result = (char *)&bmem + (0x100000 >> (31 - (v5 ^ 0x1F))) * (v3 - (1 << (31 - (v5 ^ 0x1F))));
}
}
return result;
}

canonical_original_code:
void *balloc2(unsigned int size)
{
 if (!size) return ((void *)0);
 if (size < (1 << 10)) size = (1 << 10);
 unsigned int x = 20 - (32 - __builtin_clz(size-1));
 unsigned int blk = (1 << 20) >> x; unsigned int n;
 if ((n = btrav((1 << 20) >> x, 1, (1 << 20))) != 0xffffffff) {
  for (unsigned int b = n; b; b >>= 1) btree[(b) >> 3] |= (1 << ((b) & 7));
  unsigned int y = 31 - __builtin_clz(n);
  return bmem + ((1 << 20) >> y) * (n - (1 << y));
 }
 return ((void *)0);
}

variable_types:
y
unsigned int


bfree

decompiled_code:
unsigned int __fastcall bfree(_BYTE *a1)
{
unsigned int v1; // eax
unsigned int v2; // edx
int v3; // esi
unsigned int v4; // ecx
int v5; // edi
unsigned int result; // eax
char v7; // di
int v8; // ecx
int v9; // esi
unsigned int v10; // er8
int v11; // er10
int v12; // esi

if ( a1 > (_BYTE *)&end || a1 < bmem )
return fprintf(stderr, "%s: %p out of range\n", "bfree", a1);
if ( ((a1 - bmem) & 0x3FF) != 0 )
return fprintf(stderr, "%s: %p not on minimum blocksize boundary\n", "bfree", a1);
v1 = ((unsigned int)(a1 - bmem) >> 10) + 1024;
v2 = v1 >> 3;
v3 = (unsigned __int8)btree[v1 >> 3];
v4 = ((unsigned int)(a1 - bmem) >> 10) & 7;
v5 = (char)v3;
if ( !_bittest(&v5, v4) )
{
result = v1 >> 1;
while ( 1 )
{
v7 = btree[result >> 3];
v8 = result & 7;
v9 = v7;
if ( _bittest(&v9, v8) )
{
v10 = 2 * result + 1;
v11 = btree[(2 * result) >> 3];
if ( _bittest(&v11, (2 * result) & 7) )
return result;
v12 = btree[v10 >> 3];
if ( _bittest(&v12, v10 & 7) )
return result;
btree[result >> 3] = v7 & ~(1 << v8);
}
result >>= 1;
if ( !result )
return result;
}
}
result = v3 & ~(1 << v4);
btree[v2] = v3 & ~(1 << v4);
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func10(_BYTE *a1)
{
unsigned int v1; // eax
unsigned int v2; // edx
int v3; // esi
unsigned int v4; // ecx
int v5; // edi
unsigned int result; // eax
char v7; // di
int v8; // ecx
int v9; // esi
unsigned int v10; // er8
int v11; // er10
int v12; // esi

if ( a1 > (_BYTE *)&end || a1 < bmem )
return fprintf(stderr, "%s: %p out of range\n", "bfree", a1);
if ( ((a1 - bmem) & 0x3FF) != 0 )
return fprintf(stderr, "%s: %p not on minimum blocksize boundary\n", "bfree", a1);
v1 = ((unsigned int)(a1 - bmem) >> 10) + 1024;
v2 = v1 >> 3;
v3 = (unsigned __int8)btree[v1 >> 3];
v4 = ((unsigned int)(a1 - bmem) >> 10) & 7;
v5 = (char)v3;
if ( !_bittest(&v5, v4) )
{
result = v1 >> 1;
while ( 1 )
{
v7 = btree[result >> 3];
v8 = result & 7;
v9 = v7;
if ( _bittest(&v9, v8) )
{
v10 = 2 * result + 1;
v11 = btree[(2 * result) >> 3];
if ( _bittest(&v11, (2 * result) & 7) )
return result;
v12 = btree[v10 >> 3];
if ( _bittest(&v12, v10 & 7) )
return result;
btree[result >> 3] = v7 & ~(1 << v8);
}
result >>= 1;
if ( !result )
return result;
}
}
result = v3 & ~(1 << v4);
btree[v2] = v3 & ~(1 << v4);
return result;
}

canonical_original_code:
void bfree(void *mem)
{
 if (mem < (void *)bmem || mem > (void *)bmem + (1 << 20)) {
  fprintf(stderr, "%s: %p out of range\n", __func__, mem);
  return;
 }
 unsigned int y = (uint32_t)(mem - (void *)bmem);
 if (y & ((1 << 10) - 1)) {
  fprintf(stderr, "%s: %p not on minimum blocksize boundary\n",
    __func__, mem);
  return;
 }
 unsigned int b = (1 << (20 - 10)) + (y >> 10);
 if ((btree[(b) >> 3] & (1 << ((b) & 7))))
  btree[(b) >> 3] &= ~(1 << ((b) & 7));
 else
  for (unsigned int a = b >> 1; a; a >>= 1) {
   if ((btree[(a) >> 3] & (1 << ((a) & 7)))) {
    unsigned int l = a << 1; unsigned int r = (a << 1) + 1;
    if ((btree[(l) >> 3] & (1 << ((l) & 7))) || (btree[(r) >> 3] & (1 << ((r) & 7)))) break;
    btree[(a) >> 3] &= ~(1 << ((a) & 7));
   }
  }
}

variable_types:
mem
void *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
char *v4; // r13
char *v5; // r12
char *v6; // rbx
char *v7; // rbp

memset(btree, 0, sizeof(btree));
bdebugtree(1u, 0x400u);
v3 = balloc2(0x19000u);
bdebugtree(1u, 0x400u);
v4 = balloc2(0x3C000u);
bdebugtree(1u, 0x400u);
v5 = balloc2(0x10000u);
bdebugtree(1u, 0x400u);
v6 = balloc2(0x40000u);
bdebugtree(1u, 0x400u);
bfree(v4);
bdebugtree(1u, 0x400u);
bfree(v3);
bdebugtree(1u, 0x400u);
v7 = balloc2(0x12C00u);
bdebugtree(1u, 0x400u);
bfree(v5);
bdebugtree(1u, 0x400u);
bfree(v7);
bdebugtree(1u, 0x400u);
bfree(v6);
bdebugtree(1u, 0x400u);
return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
a
void *

variable_types:
b
void *

variable_types:
c
void *

variable_types:
d
void *

variable_types:
e
void *


utime

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

clock_gettime(1, &v1);
return 1000000 * v1.tv_sec + v1.tv_nsec / 1000;
}

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

clock_gettime(1, &v1);
return 1000000 * v1.tv_sec + v1.tv_nsec / 1000;
}

original_code:
static inline uint64_t utime() {
    struct timespec ts;
    clock_gettime(1, &ts);
    return ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
}

canonical_original_code:
static inline unsigned long utime() {
    struct timespec ts;
    clock_gettime(1, &ts);
    return ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
}

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

return_type: unsigned long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // eax
int v5; // ebp
__int64 v7; // r12
int v8; // eax
size_t v9; // r14
__int64 v10; // r13
__int64 v11; // r15
_BYTE *v12; // r13
__int64 v13; // r12
char *v14; // r12
int v15; // er14
__int64 v16; // rax
unsigned int v17; // esi
char v18; // dl
__int64 k; // r14
int i; // er14
int j; // er14
__int64 l; // r14
__int64 m; // r14
__int64 n; // r13
void *s; // [rsp+8h] [rbp-60h]
__time_t v26; // [rsp+10h] [rbp-58h]
__time_t v27; // [rsp+18h] [rbp-50h]
int longind[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

check_flag = 0;
help_flag = 0;
read_offset = 0;
write_offset = 0;
iterations = 100;
size = 10000;
algtype = 0;
while ( 1 )
{
longind[0] = 0;
v4 = getopt_long(argc, (char *const *)argv, "o:s:i:t:hc", &long_options_0, longind);
if ( v4 == -1 )
break;
if ( v4 )
return 1;
}
v5 = help_flag;
if ( help_flag )
{
printf(
"Usage: %s [-s num] [-o num] [-i num] [-h] filename\n"
" -s set the size of the data to copy\n"
" -o set the offset to copy from (default=0)\n"
" -i set the iterations to run (default=100)\n"
" -t algorithm type (0=c,1=rep movsb,2=sse2)\n"
" -h this help\n",
*argv);
return 0;
}
LODWORD(v7) = read_offset;
if ( (unsigned int)read_offset > 0x10 )
{
fprintf(stderr, "%s: option --read_offset must be between 0 and 15\n", *argv);
return 1;
}
v8 = write_offset;
if ( (unsigned int)write_offset > 0x10 )
{
fprintf(stderr, "%s: option --write_offset must be between 0 and 15\n", *argv);
return 1;
}
if ( read_offset >= write_offset )
v8 = read_offset;
if ( v8 < 0 )
v8 = 0;
if ( size < v8 )
{
fprintf(stderr, "%s: option --size must be greater than 0 and offset\n", *argv);
return 1;
}
if ( (unsigned int)algtype > 2 )
{
fprintf(stderr, "%s: option --type must be between 0 and 2\n", *argv);
return 1;
}
v9 = size + 32;
v10 = (__int64)malloc(v9);
s = (void *)v10;
v11 = (__int64)malloc(v9);
dst_data = v11;
if ( (v10 & 0xF) != 0 )
v10 = v10 - (v10 & 0xF) + 16;
v7 = (int)v7;
v12 = (_BYTE *)((int)v7 + v10);
memset(s, 0, v9);
while ( read_offset + size > (int)v7 )
v12[v7++] = rand() % 255 + 1;
v13 = v11;
if ( (v11 & 0xF) != 0 )
v13 = v11 - (v11 & 0xF) + 16;
v14 = (char *)(write_offset + v13);
memset((void *)v11, 0, size + 32);
v15 = algtype;
switch ( algtype )
{
case 1:
v26 = utime();
for ( i = v5; iterations > i; ++i )
memcpy_movsb(v14, v12, size);
goto LABEL_48;
case 2:
v26 = utime();
for ( j = v5; iterations > j; ++j )
memcpy_sse2(v14, v12, size);
goto LABEL_48;
case 0:
v26 = utime();
while ( iterations > v15 )
{
memcpy(v14, v12, size);
++v15;
}
LABEL_48:
v27 = utime();
break;
}
if ( check_flag )
{
v16 = 0LL;
while ( 1 )
{
v17 = v16;
if ( size <= (int)v16 )
break;
v18 = v12[v16++];
if ( v18 != v14[v16 - 1] )
{
fprintf(stderr, "%s: bad copy %d\n", *argv, v17);
break;
}
}
for ( k = 0LL; read_offset > (int)k; ++k )
{
if ( v12[k] )
fprintf(stderr, "%s: overflow before src %d\n", *argv, (unsigned int)k);
}
for ( l = 0LL; write_offset > (int)l; ++l )
{
if ( v14[l] )
fprintf(stderr, "%s: overflow before dst %d\n", *argv, (unsigned int)l);
}
for ( m = size; read_offset + size > (int)m; ++m )
{
if ( v12[m] )
fprintf(stderr, "%s: overflow before src %d\n", *argv, (unsigned int)m);
}
for ( n = size; size + write_offset > (int)n; ++n )
{
if ( v14[n] )
fprintf(stderr, "%s: overflow before dst %d\n", *argv, (unsigned int)n);
}
}
printf("%llu\n", v27 - v26);
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // eax
int v5; // ebp
__int64 v7; // r12
int v8; // eax
size_t v9; // r14
__int64 v10; // r13
__int64 v11; // r15
_BYTE *v12; // r13
__int64 v13; // r12
char *v14; // r12
int v15; // er14
__int64 v16; // rax
unsigned int v17; // esi
char v18; // dl
__int64 k; // r14
int i; // er14
int j; // er14
__int64 l; // r14
__int64 m; // r14
__int64 n; // r13
void *s; // [rsp+8h] [rbp-60h]
__time_t v26; // [rsp+10h] [rbp-58h]
__time_t v27; // [rsp+18h] [rbp-50h]
int longind[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

check_flag = 0;
help_flag = 0;
read_offset = 0;
write_offset = 0;
iterations = 100;
size = 10000;
algtype = 0;
while ( 1 )
{
longind[0] = 0;
v4 = getopt_long(argc, (char *const *)argv, "o:s:i:t:hc", &long_options_0, longind);
if ( v4 == -1 )
break;
if ( v4 )
return 1;
}
v5 = help_flag;
if ( help_flag )
{
printf(
"Usage: %s [-s num] [-o num] [-i num] [-h] filename\n"
" -s set the size of the data to copy\n"
" -o set the offset to copy from (default=0)\n"
" -i set the iterations to run (default=100)\n"
" -t algorithm type (0=c,1=rep movsb,2=sse2)\n"
" -h this help\n",
*argv);
return 0;
}
LODWORD(v7) = read_offset;
if ( (unsigned int)read_offset > 0x10 )
{
fprintf(stderr, "%s: option --read_offset must be between 0 and 15\n", *argv);
return 1;
}
v8 = write_offset;
if ( (unsigned int)write_offset > 0x10 )
{
fprintf(stderr, "%s: option --write_offset must be between 0 and 15\n", *argv);
return 1;
}
if ( read_offset >= write_offset )
v8 = read_offset;
if ( v8 < 0 )
v8 = 0;
if ( size < v8 )
{
fprintf(stderr, "%s: option --size must be greater than 0 and offset\n", *argv);
return 1;
}
if ( (unsigned int)algtype > 2 )
{
fprintf(stderr, "%s: option --type must be between 0 and 2\n", *argv);
return 1;
}
v9 = size + 32;
v10 = (__int64)malloc(v9);
s = (void *)v10;
v11 = (__int64)malloc(v9);
dst_data = v11;
if ( (v10 & 0xF) != 0 )
v10 = v10 - (v10 & 0xF) + 16;
v7 = (int)v7;
v12 = (_BYTE *)((int)v7 + v10);
memset(s, 0, v9);
while ( read_offset + size > (int)v7 )
v12[v7++] = rand() % 255 + 1;
v13 = v11;
if ( (v11 & 0xF) != 0 )
v13 = v11 - (v11 & 0xF) + 16;
v14 = (char *)(write_offset + v13);
memset((void *)v11, 0, size + 32);
v15 = algtype;
switch ( algtype )
{
case 1:
v26 = func0();
for ( i = v5; iterations > i; ++i )
memcpy_movsb(v14, v12, size);
goto LABEL_48;
case 2:
v26 = func0();
for ( j = v5; iterations > j; ++j )
memcpy_sse2(v14, v12, size);
goto LABEL_48;
case 0:
v26 = func0();
while ( iterations > v15 )
{
memcpy(v14, v12, size);
++v15;
}
LABEL_48:
v27 = func0();
break;
}
if ( check_flag )
{
v16 = 0LL;
while ( 1 )
{
v17 = v16;
if ( size <= (int)v16 )
break;
v18 = v12[v16++];
if ( v18 != v14[v16 - 1] )
{
fprintf(stderr, "%s: bad copy %d\n", *argv, v17);
break;
}
}
for ( k = 0LL; read_offset > (int)k; ++k )
{
if ( v12[k] )
fprintf(stderr, "%s: overflow before src %d\n", *argv, (unsigned int)k);
}
for ( l = 0LL; write_offset > (int)l; ++l )
{
if ( v14[l] )
fprintf(stderr, "%s: overflow before dst %d\n", *argv, (unsigned int)l);
}
for ( m = size; read_offset + size > (int)m; ++m )
{
if ( v12[m] )
fprintf(stderr, "%s: overflow before src %d\n", *argv, (unsigned int)m);
}
for ( n = size; size + write_offset > (int)n; ++n )
{
if ( v14[n] )
fprintf(stderr, "%s: overflow before dst %d\n", *argv, (unsigned int)n);
}
}
printf("%llu\n", v27 - v26);
return v5;
}

original_code:
int main(int argc, char **argv) {
 int c;
 check_flag = 0;
 help_flag = 0;
 read_offset = 0;
 write_offset = 0;
 iterations = 100;
 size = 10000;
 algtype = 0;
 while (1) {
  static struct option long_options[] = {
   {"check", 0, &check_flag, 1},
   {"read_offset", 1, 0, 'r'},
   {"write_offset", 1, 0, 'w'},
   {"size", 1, 0, 's'},
   {"iterations", 1, 0, 'i'},
   {"type", 1, 0, 't'},
   {"help", 0, &help_flag, 'h'},
   {0, 0, 0, 0}
  };
  int option_index = 0;
  c = getopt_long(argc, argv, "o:s:i:t:hc", long_options, &option_index);
  if (c == -1)
   break;
  switch (c) {
  case 0:
   if (long_options[option_index].flag != 0)
    break;
   break;
  case 's':
   sscanf(optarg, "%d", &size);
   break;
  case 'r':
   sscanf(optarg, "%d", &read_offset);
   break;
  case 'w':
   sscanf(optarg, "%d", &write_offset);
   break;
  case 'i':
   sscanf(optarg, "%d", &iterations);
   break;
  case 't':
   sscanf(optarg, "%d", &algtype);
   break;
  case 'h':
   help_flag = 1;
   break;
  case 'c':
   check_flag = 1;
   break;
  default:
   return 1;
  }
 }
 if (help_flag) {
  printf("Usage: %s [-s num] [-o num] [-i num] [-h] filename\n"
         "    -s    set the size of the data to copy\n"
         "    -o    set the offset to copy from (default=0)\n"
         "    -i    set the iterations to run (default=100)\n"
         "    -t    algorithm type (0=c,1=rep movsb,2=sse2)\n"
         "    -h    this help\n", argv[0]);
  return 0;
 }
 if (read_offset < 0 || read_offset > 16) {
  fprintf(stderr,
          "%s: option --read_offset must be between 0 and 15\n",
          argv[0]);
  return 1;
 }
 if (write_offset < 0 || write_offset > 16) {
  fprintf(stderr,
          "%s: option --write_offset must be between 0 and 15\n",
          argv[0]);
  return 1;
 }
 if (size < 0 || size < read_offset || size < write_offset) {
  fprintf(stderr,
          "%s: option --size must be greater than 0 and offset\n",
          argv[0]);
  return 1;
 }
 if (algtype < 0 || algtype > 2) {
  fprintf(stderr,
          "%s: option --type must be between 0 and 2\n",
          argv[0]);
  return 1;
 }
 src_data = malloc(size + 16 * 2);
 dst_data = malloc(size + 16 * 2);
 uint8_t *src = ((((uintptr_t)src_data) % 16) ? (src_data + 16 - (((uintptr_t)src_data) % 16)) : src_data) + read_offset;
 memset(src_data, 0, size + 16 * 2);
 for (int i = read_offset; i < size + read_offset; i++)
  src[i] = rand() % 255 + 1;
 uint8_t *dst = ((((uintptr_t)dst_data) % 16) ? (dst_data + 16 - (((uintptr_t)dst_data) % 16)) : dst_data) + write_offset;
 memset(dst_data, 0, size + 16 * 2);
 uint64_t start, end;
 switch (algtype) {
 case 0:
  start = utime();
  for (int i = 0; i < iterations; i++)
   memcpy(dst, src, size);
  end = utime();
  break;
 case 1:
  start = utime();
  for (int i = 0; i < iterations; i++)
   memcpy_movsb(dst, src, size);
  end = utime();
  break;
 case 2:
  start = utime();
  for (int i = 0; i < iterations; i++)
   memcpy_sse2(dst, src, size);
  end = utime();
  break;
 }
 if (check_flag) {
  for (int i = 0; i < size; i++) {
   if (src[i] != dst[i]) {
    fprintf(stderr, "%s: bad copy %d\n",
     argv[0], i);
    break;
   }
  }
  for (int i = 0; i < read_offset; i++) {
   if (src[i] != 0) {
    fprintf(stderr, "%s: overflow before src %d\n",
     argv[0],
     i);
   }
  }
  for (int i = 0; i < write_offset; i++) {
   if (dst[i] != 0) {
    fprintf(stderr, "%s: overflow before dst %d\n",
     argv[0], i);
   }
  }
  for (int i = size; i < size + read_offset; i++) {
   if (src[i] != 0) {
    fprintf(stderr, "%s: overflow before src %d\n",
     argv[0], i);
   }
  }
  for (int i = size; i < size + write_offset; i++) {
   if (dst[i] != 0) {
    fprintf(stderr, "%s: overflow before dst %d\n",
     argv[0], i);
   }
  }
 }
 printf("%llu\n", end - start);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 int c;
 check_flag = 0;
 help_flag = 0;
 read_offset = 0;
 write_offset = 0;
 iterations = 100;
 size = 10000;
 algtype = 0;
 while (1) {
  static struct option long_options[] = {
   {"check", 0, &check_flag, 1},
   {"read_offset", 1, 0, 'r'},
   {"write_offset", 1, 0, 'w'},
   {"size", 1, 0, 's'},
   {"iterations", 1, 0, 'i'},
   {"type", 1, 0, 't'},
   {"help", 0, &help_flag, 'h'},
   {0, 0, 0, 0}
  };
  int option_index = 0;
  c = getopt_long(argc, argv, "o:s:i:t:hc", long_options, &option_index);
  if (c == -1)
   break;
  switch (c) {
  case 0:
   if (long_options[option_index].flag != 0)
    break;
   break;
  case 's':
   sscanf(optarg, "%d", &size);
   break;
  case 'r':
   sscanf(optarg, "%d", &read_offset);
   break;
  case 'w':
   sscanf(optarg, "%d", &write_offset);
   break;
  case 'i':
   sscanf(optarg, "%d", &iterations);
   break;
  case 't':
   sscanf(optarg, "%d", &algtype);
   break;
  case 'h':
   help_flag = 1;
   break;
  case 'c':
   check_flag = 1;
   break;
  default:
   return 1;
  }
 }
 if (help_flag) {
  printf("Usage: %s [-s num] [-o num] [-i num] [-h] filename\n"
         "    -s    set the size of the data to copy\n"
         "    -o    set the offset to copy from (default=0)\n"
         "    -i    set the iterations to run (default=100)\n"
         "    -t    algorithm type (0=c,1=rep movsb,2=sse2)\n"
         "    -h    this help\n", argv[0]);
  return 0;
 }
 if (read_offset < 0 || read_offset > 16) {
  fprintf(stderr,
          "%s: option --read_offset must be between 0 and 15\n",
          argv[0]);
  return 1;
 }
 if (write_offset < 0 || write_offset > 16) {
  fprintf(stderr,
          "%s: option --write_offset must be between 0 and 15\n",
          argv[0]);
  return 1;
 }
 if (size < 0 || size < read_offset || size < write_offset) {
  fprintf(stderr,
          "%s: option --size must be greater than 0 and offset\n",
          argv[0]);
  return 1;
 }
 if (algtype < 0 || algtype > 2) {
  fprintf(stderr,
          "%s: option --type must be between 0 and 2\n",
          argv[0]);
  return 1;
 }
 src_data = malloc(size + 16 * 2);
 dst_data = malloc(size + 16 * 2);
 unsigned char *src = ((((uintptr_t)src_data) % 16) ? (src_data + 16 - (((uintptr_t)src_data) % 16)) : src_data) + read_offset;
 memset(src_data, 0, size + 16 * 2);
 for (int i = read_offset; i < size + read_offset; i++)
  src[i] = rand() % 255 + 1;
 unsigned char *dst = ((((uintptr_t)dst_data) % 16) ? (dst_data + 16 - (((uintptr_t)dst_data) % 16)) : dst_data) + write_offset;
 memset(dst_data, 0, size + 16 * 2);
 unsigned long start; unsigned long end;
 switch (algtype) {
 case 0:
  start = utime();
  for (int i = 0; i < iterations; i++)
   memcpy(dst, src, size);
  end = utime();
  break;
 case 1:
  start = utime();
  for (int i = 0; i < iterations; i++)
   memcpy_movsb(dst, src, size);
  end = utime();
  break;
 case 2:
  start = utime();
  for (int i = 0; i < iterations; i++)
   memcpy_sse2(dst, src, size);
  end = utime();
  break;
 }
 if (check_flag) {
  for (int i = 0; i < size; i++) {
   if (src[i] != dst[i]) {
    fprintf(stderr, "%s: bad copy %d\n",
     argv[0], i);
    break;
   }
  }
  for (int i = 0; i < read_offset; i++) {
   if (src[i] != 0) {
    fprintf(stderr, "%s: overflow before src %d\n",
     argv[0],
     i);
   }
  }
  for (int i = 0; i < write_offset; i++) {
   if (dst[i] != 0) {
    fprintf(stderr, "%s: overflow before dst %d\n",
     argv[0], i);
   }
  }
  for (int i = size; i < size + read_offset; i++) {
   if (src[i] != 0) {
    fprintf(stderr, "%s: overflow before src %d\n",
     argv[0], i);
   }
  }
  for (int i = size; i < size + write_offset; i++) {
   if (dst[i] != 0) {
    fprintf(stderr, "%s: overflow before dst %d\n",
     argv[0], i);
   }
  }
 }
 printf("%llu\n", end - start);
 return 0;
}

variable_types: c int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types:
src
unsigned char *

variable_types: i int

variable_types:
dst
unsigned char *

variable_types:
start
unsigned long

variable_types:
end
unsigned long


repo: raeffu/ginf-c-pointers

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts(
"struct NODE nodes[5] = {\n"
" { 5, nodes + 3, NULL },\n"
" { 15, nodes + 4, nodes + 3 },\n"
" { 22, NULL, nodes + 4 },\n"
" { 12, nodes + 1, nodes },\n"
" { 18, nodes + 2, nodes + 1 }\n"
"};");
printf("sizeof(int) \t\t%zu\n", 4uLL);
printf("sizeof(struct NODE *) \t%zu\n", 8uLL);
printf("sizeof(nodes[0].a) \t%zu\n", 4uLL);
printf("sizeof(nodes[0].b) \t%zu\n", 8uLL);
printf("sizeof(nodes[0].c) \t%zu\n", 8uLL);
printf("sizeof(nodes[0]) \t%zu\n", 0x18uLL);
printf("sizeof(nodes) \t\t%zu\n", 0x78uLL);
printf("nodes[3].a\t\t%i\n", (unsigned int)dword_4040C8);
printf("nodes[3].a\t\t%i\n", (unsigned int)dword_4040C8);
printf("nodes\t\t\t%p\n", &nodes);
printf("nodes[3].a\t\t%i\n", (unsigned int)dword_4040C8);
printf("nodes[3].c\t\t%p\n", off_4040D8);
printf("nodes[3].c->a\t\t%i\n", (unsigned int)*off_4040D8);
printf("*nodes\t\t\t{ %i, %p, %p }\n", (unsigned int)nodes, off_404088, (const void *)qword_404090);
puts("*nodes.a\t\tillegal");
printf("(*nodes).a\t\t%i\n", (unsigned int)nodes);
printf("nodes->a\t\t%i\n", (unsigned int)nodes);
printf("nodes[3].b->b\t\t%p\n", *((const void **)off_4040D0 + 1));
printf(
"*nodes[3].b->b\t\t{ %i, %p, %p }\n",
**((unsigned int **)off_4040D0 + 1),
*(const void **)(*((_QWORD *)off_4040D0 + 1) + 8LL),
*(const void **)(*((_QWORD *)off_4040D0 + 1) + 16LL));
printf("&nodes\t\t\t%p \n", &nodes);
printf("&nodes[3].a\t\t%p \n", &dword_4040C8);
printf("&nodes[3].b\t\t%p \n", &off_4040D0);
printf("&nodes[3].c\t\t%p \n", &off_4040D8);
printf("&nodes[3].c->a\t\t%p \n", off_4040D8);
printf("np\t\t\t%p \n", np);
printf("np->a\t\t\t%i \n", *(unsigned int *)np);
printf("np->c->c->a\t\t%i \n", **(unsigned int **)(*((_QWORD *)np + 2) + 16LL));
printf("*npp\t\t\t%p \n", *npp);
printf("**npp\t\t\t{ %i, %p, %p }\n", *(unsigned int *)*npp, *((const void **)*npp + 1), *((const void **)*npp + 2));
printf("**npp\t\t\t{ %i, %p, %p }\n", *(unsigned int *)*npp, *((const void **)*npp + 1), *((const void **)*npp + 2));
puts("*npp->a\t\t\tillegal");
printf("(*npp)->a\t\t%i\n", *(unsigned int *)*npp);
printf("&np\t\t\tunknown: %p\n", &np);
printf("&np->a\t\t\t%p\n", np);
printf("&np->c->c->a\t\t%p\n", *(const void **)(*((_QWORD *)np + 2) + 16LL));
return 1;
}

original_code:
int main(){
  printf("struct NODE nodes[5] = {\n { 5, nodes + 3, NULL },\n { 15, nodes + 4, nodes + 3 },\n { 22, NULL, nodes + 4 },\n { 12, nodes + 1, nodes },\n { 18, nodes + 2, nodes + 1 }\n};\n");
  printf("sizeof(int) \t\t%zu\n", sizeof(int));
  printf("sizeof(struct NODE *) \t%zu\n", sizeof(struct NODE *));
  printf("sizeof(nodes[0].a) \t%zu\n", sizeof(nodes[0].a));
  printf("sizeof(nodes[0].b) \t%zu\n", sizeof(nodes[0].b));
  printf("sizeof(nodes[0].c) \t%zu\n", sizeof(nodes[0].c));
    printf("sizeof(nodes[0]) \t%zu\n", sizeof(nodes[0]));
  printf("sizeof(nodes) \t\t%zu\n", sizeof(nodes));
  printf("nodes[3].a\t\t%i\n", nodes[3].a);
  printf("nodes[3].a\t\t%i\n", nodes[3].a);
  printf("nodes\t\t\t%p\n", nodes);
  printf("nodes[3].a\t\t%i\n", nodes[3].a);
  printf("nodes[3].c\t\t%p\n", nodes[3].c);
  printf("nodes[3].c->a\t\t%i\n", nodes[3].c->a);
  printf("*nodes\t\t\t{ %i, %p, %p }\n", (*nodes).a, (*nodes).b, (*nodes).c);
  printf("*nodes.a\t\tillegal\n");
  printf("(*nodes).a\t\t%i\n", (*nodes).a);
  printf("nodes->a\t\t%i\n", nodes->a);
  printf("nodes[3].b->b\t\t%p\n", nodes[3].b->b);
  printf("*nodes[3].b->b\t\t{ %i, %p, %p }\n", (*nodes[3].b->b).a, (*nodes[3].b->b).b, (*nodes[3].b->b).c );
  printf("&nodes\t\t\t%p \n", &nodes);
  printf("&nodes[3].a\t\t%p \n", &nodes[3].a);
    printf("&nodes[3].b\t\t%p \n", &nodes[3].b);
  printf("&nodes[3].c\t\t%p \n", &nodes[3].c);
  printf("&nodes[3].c->a\t\t%p \n", &nodes[3].c->a);
  printf("np\t\t\t%p \n", np);
  printf("np->a\t\t\t%i \n", np->a);
  printf("np->c->c->a\t\t%i \n", np->c->c->a);
  printf("*npp\t\t\t%p \n", *npp);
  printf("**npp\t\t\t{ %i, %p, %p }\n", (**npp).a, (**npp).b, (**npp).c );
  printf("**npp\t\t\t{ %i, %p, %p }\n", (**npp).a, (**npp).b, (**npp).c );
  printf("*npp->a\t\t\tillegal\n" );
  printf("(*npp)->a\t\t%i\n",(*npp)->a );
  printf("&np\t\t\tunknown: %p\n",&np);
  printf("&np->a\t\t\t%p\n",&np->a);
  printf("&np->c->c->a\t\t%p\n",&np->c->c->a);
  return 1;
}

user_defined_types: struct NODE { int a; struct NODE *b; struct NODE *c; }


decompiled_code:
void __fastcall usb_bulk_send(__int64 a1, int a2)
{
int i; // ebx
unsigned int v4; // eax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

for ( i = a2; i > 0; a1 += v5[0] )
{
v4 = libusb_bulk_transfer(usb, 1LL, a1, (unsigned int)i, v5, 0LL);
if ( v4 )
{
fprintf(stderr, "usb_bulk_send error %d\n", v4);
exit(2);
}
i -= v5[0];
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
int i; // ebx
unsigned int v4; // eax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

for ( i = a2; i > 0; a1 += v5[0] )
{
v4 = libusb_bulk_transfer(usb, 1LL, a1, (unsigned int)i, v5, 0LL);
if ( v4 )
{
fprintf(stderr, "usb_bulk_send error %d\n", v4);
exit(2);
}
i -= v5[0];
}
}

original_code:
static void usb_bulk_send(const void *data, int length)
{
    int rc, sent;
    while (length > 0) {
        rc = libusb_bulk_transfer(usb, 1 | LIBUSB_ENDPOINT_OUT,
                (void*)data, length, &sent, 0);
        if (rc != 0) {
            fprintf(stderr, "usb_bulk_send error %d\n", rc);
            exit(2);
        }
        length -= sent;
        data += sent;
    }
}

canonical_original_code:
static void usb_bulk_send(void *data, int length)
{
    int rc; int sent;
    while (length > 0) {
        rc = libusb_bulk_transfer(usb, 1 | LIBUSB_ENDPOINT_OUT,
                (void *)data, length, &sent, 0);
        if (rc != 0) {
            fprintf(stderr, "usb_bulk_send error %d\n", rc);
            exit(2);
        }
        length -= sent;
        data += sent;
    }
}

variable_types:
data
void *

variable_types: length int

variable_types: rc int

variable_types: sent int


decompiled_code:
void __fastcall aw_send_usb_request(unsigned __int16 a1, unsigned int a2)
{
__int64 v2; // [rsp+0h] [rbp-28h] BYREF
__int64 v3; // [rsp+8h] [rbp-20h]
__int64 v4; // [rsp+10h] [rbp-18h]
__int64 v5; // [rsp+18h] [rbp-10h]

v2 = 1129666369LL;
HIWORD(v4) = 0;
v5 = 0LL;
*(_DWORD *)((char *)&v4 + 2) = _uint32_identity(a2);
LODWORD(v3) = *(_DWORD *)((char *)&v4 + 2);
LOWORD(v4) = _uint16_identity(a1);
HIDWORD(v3) = _uint32_identity(0xC000000u);
usb_bulk_send((__int64)&v2, 32);
}

original_code:
static void aw_send_usb_request(int type, int length)
{
    struct aw_usb_request req;
    memset(&req, 0, sizeof(req));
    strcpy(req.signature, "AWUC");
    req.length = req.length2 = __uint32_identity (length);
    req.request = __uint16_identity (type);
    req.unknown1 = __uint32_identity (0x0c000000);
    usb_bulk_send(&req, sizeof(req));
}

variable_types: type int

variable_types: struct aw_usb_request { char signature[8]; unsigned int length; unsigned int unknown1; unsigned short request; unsigned int length2; char pad[10]; }


decompiled_code:
void __fastcall usb_bulk_recv(__int64 a1, int a2)
{
int i; // ebx
unsigned int v4; // eax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

for ( i = a2; i > 0; a1 += v5[0] )
{
v4 = libusb_bulk_transfer(usb, 130LL, a1, (unsigned int)i, v5, 0LL);
if ( v4 )
{
fprintf(stderr, "usb_bulk_recv error %d\n", v4);
exit(2);
}
i -= v5[0];
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int a2)
{
int i; // ebx
unsigned int v4; // eax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

for ( i = a2; i > 0; a1 += v5[0] )
{
v4 = libusb_bulk_transfer(usb, 130LL, a1, (unsigned int)i, v5, 0LL);
if ( v4 )
{
fprintf(stderr, "usb_bulk_recv error %d\n", v4);
exit(2);
}
i -= v5[0];
}
}

original_code:
static void usb_bulk_recv(void *data, int length)
{
    int rc, recv;
    while (length > 0) {
        rc = libusb_bulk_transfer(usb, 2 | LIBUSB_ENDPOINT_IN,
                data, length, &recv, 0);
        if (rc != 0) {
            fprintf(stderr, "usb_bulk_recv error %d\n", rc);
            exit(2);
        }
        length -= recv;
        data += recv;
    }
}

canonical_original_code:
static void usb_bulk_recv(void *data, int length)
{
    int rc; int recv;
    while (length > 0) {
        rc = libusb_bulk_transfer(usb, 2 | LIBUSB_ENDPOINT_IN,
                data, length, &recv, 0);
        if (rc != 0) {
            fprintf(stderr, "usb_bulk_recv error %d\n", rc);
            exit(2);
        }
        length -= recv;
        data += recv;
    }
}

variable_types: recv int


decompiled_code:
char aw_read_usb_response()
{
bool v0; // zf
char result; // al
char v2[21]; // [rsp+3h] [rbp-15h] BYREF

usb_bulk_recv((__int64)v2, 13);
v0 = strcmp(v2, "AWUS") == 0;
result = !v0;
if ( !v0 )
result = puts("warn: bad response from device");
return result;
}

canonical_decompiled_code:
char func5()
{
bool v0; // zf
char result; // al
char v2[21]; // [rsp+3h] [rbp-15h] BYREF

func4((__int64)v2, 13);
v0 = strcmp(v2, "AWUS") == 0;
result = !v0;
if ( !v0 )
result = puts("warn: bad response from device");
return result;
}

original_code:
static void aw_read_usb_response(void)
{
    char buf[13];
    usb_bulk_recv(&buf, sizeof(buf));
    if( strcmp(buf, "AWUS") ) {
        printf("warn: bad response from device\n");
    }
}

canonical_original_code:
static void aw_read_usb_response()
{
    char buf[13];
    usb_bulk_recv(&buf, sizeof(buf));
    if( strcmp(buf, "AWUS") ) {
        printf("warn: bad response from device\n");
    }
}

variable_types:
buf
char [13]


decompiled_code:
char __fastcall aw_usb_write(__int64 a1, unsigned int a2)
{
aw_send_usb_request(0x12u, a2);
usb_bulk_send(a1, a2);
return aw_read_usb_response();
}

canonical_decompiled_code:
char __fastcall func6(__int64 a1, unsigned int a2)
{
func3(0x12u, a2);
func2(a1, a2);
return func5();
}

original_code:
static void aw_usb_write(const void *data, size_t len)
{
    aw_send_usb_request(0x12, len);
    usb_bulk_send(data, len);
    aw_read_usb_response();
}

canonical_original_code:
static void aw_usb_write(void *data, unsigned long len)
{
    aw_send_usb_request(0x12, len);
    usb_bulk_send(data, len);
    aw_read_usb_response();
}

variable_types:
len
unsigned long


decompiled_code:
char __fastcall aw_send_fel_request(unsigned int a1, unsigned int a2, unsigned int a3)
{
int v5[10]; // [rsp+0h] [rbp-28h] BYREF

v5[3] = 0;
v5[0] = _uint32_identity(a1);
v5[1] = _uint32_identity(a2);
v5[2] = _uint32_identity(a3);
return aw_usb_write((__int64)v5, 0x10u);
}

canonical_decompiled_code:
char __fastcall func7(unsigned int a1, unsigned int a2, unsigned int a3)
{
int v5[10]; // [rsp+0h] [rbp-28h] BYREF

v5[3] = 0;
v5[0] = func1(a1);
v5[1] = func1(a2);
v5[2] = func1(a3);
return func6((__int64)v5, 0x10u);
}

original_code:
static void aw_send_fel_request(int type, uint32_t addr,
        uint32_t length)
{
    struct aw_fel_request req;
    memset(&req, 0, sizeof(req));
    req.request = __uint32_identity (type);
    req.address = __uint32_identity (addr);
    req.length = __uint32_identity (length);
    req.flags = 0;
    aw_usb_write(&req, sizeof(req));
}

canonical_original_code:
static void aw_send_fel_request(int type, unsigned int addr, unsigned int length)
{
    struct aw_fel_request req;
    memset(&req, 0, sizeof(req));
    req.request = __uint32_identity (type);
    req.address = __uint32_identity (addr);
    req.length = __uint32_identity (length);
    req.flags = 0;
    aw_usb_write(&req, sizeof(req));
}

variable_types:
addr
unsigned int

variable_types:
length
unsigned int

variable_types: struct aw_fel_request { unsigned int request; unsigned int address; unsigned int length; unsigned int flags; }


decompiled_code:
char aw_read_fel_status()
{
char v1[16]; // [rsp+8h] [rbp-10h] BYREF

return aw_usb_read((__int64)v1, 8u);
}

canonical_decompiled_code:
char func9()
{
char v1[16]; // [rsp+8h] [rbp-10h] BYREF

return func8((__int64)v1, 8u);
}

original_code:
static void aw_read_fel_status(void)
{
    char buf[8];
    aw_usb_read(&buf, sizeof(buf));
}

canonical_original_code:
static void aw_read_fel_status()
{
    char buf[8];
    aw_usb_read(&buf, sizeof(buf));
}

variable_types:
buf
char [8]


decompiled_code:
__int64 __fastcall send_bootfile(const char *a1, unsigned int a2)
{
int v4; // eax
char *v5; // rax
unsigned int v6; // er12
int v7; // edi
char *v8; // rax
signed int v9; // eax
signed int v10; // ebx
char v12[1008]; // [rsp+0h] [rbp-80408h] BYREF
char buf[524312]; // [rsp+3F0h] [rbp-80018h] BYREF

v4 = readlink("/proc/self/exe", buf, 0x80000uLL);
if ( v4 > 0 )
{
buf[v4] = 0;
v5 = dirname(buf);
sprintf(v12, "%s/arm/%s", v5, a1);
v6 = open(v12, 0);
if ( v6 != -1 )
goto LABEL_8;
v7 = *_errno_location();
if ( v7 != 2 )
{
v8 = strerror(v7);
fprintf(stderr, "unable to open FEL bootfile %s: %s\n", v12, v8);
return v6;
}
}
sprintf(v12, "/usr/share/allwindisk/%s", a1);
v6 = open(v12, 0);
if ( v6 == -1 )
{
fprintf(stderr, "unable to open FEL bootfile %s\n", v12);
return v6;
}
LABEL_8:
while ( 1 )
{
v9 = read(v6, buf, 0x80000uLL);
v10 = v9;
if ( v9 <= 0 )
break;
send_write_request(0x101u, a2, v9, (__int64)buf, v9);
a2 += v10;
}
close(v6);
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1, unsigned int a2)
{
int v4; // eax
char *v5; // rax
unsigned int v6; // er12
int v7; // edi
char *v8; // rax
signed int v9; // eax
signed int v10; // ebx
char v12[1008]; // [rsp+0h] [rbp-80408h] BYREF
char buf[524312]; // [rsp+3F0h] [rbp-80018h] BYREF

v4 = readlink("/proc/self/exe", buf, 0x80000uLL);
if ( v4 > 0 )
{
buf[v4] = 0;
v5 = dirname(buf);
sprintf(v12, "%s/arm/%s", v5, a1);
v6 = open(v12, 0);
if ( v6 != -1 )
goto LABEL_8;
v7 = *_errno_location();
if ( v7 != 2 )
{
v8 = strerror(v7);
fprintf(stderr, "unable to open FEL bootfile %s: %s\n", v12, v8);
return v6;
}
}
sprintf(v12, "/usr/share/allwindisk/%s", a1);
v6 = open(v12, 0);
if ( v6 == -1 )
{
fprintf(stderr, "unable to open FEL bootfile %s\n", v12);
return v6;
}
LABEL_8:
while ( 1 )
{
v9 = read(v6, buf, 0x80000uLL);
v10 = v9;
if ( v9 <= 0 )
break;
func10(0x101u, a2, v9, (__int64)buf, v9);
a2 += v10;
}
close(v6);
return 0;
}

original_code:
static int send_bootfile(const char *fname, unsigned load_addr)
{
    int fd = -1, rd;
    char buf[0x80000];
    char filepath[1000];
    if( (rd = readlink("/proc/self/exe", buf, sizeof(buf))) > 0 )
    {
        buf[rd] = '\0';
        char *dname = dirname(buf);
        sprintf(filepath, "%s/arm/%s", dname, fname);
        fd = open(filepath, 00);
        if( fd == -1 && (*__errno_location ()) != 2 ) {
            fprintf(stderr, "unable to open FEL bootfile %s: %s\n",
                    filepath, strerror((*__errno_location ())));
            return -1;
        }
    }
    if( fd == -1 ) {
        sprintf(filepath, "/usr/share/allwindisk/%s", fname);
        if( (fd = open(filepath, 00)) == -1 ) {
            fprintf(stderr, "unable to open FEL bootfile %s\n", filepath);
            return -1;
        }
    }
    while( (rd = read(fd, buf, sizeof(buf))) > 0 ) {
        send_write_request(AW_FEL_1_WRITE, load_addr, rd, buf, rd);
        load_addr += rd;
    }
    close(fd);
    return 0;
}

canonical_original_code:
static int send_bootfile(char *fname, unsigned int load_addr)
{
    int fd = -1; int rd;
    char buf[524288];
    char filepath[1000];
    if( (rd = readlink("/proc/self/exe", buf, sizeof(buf))) > 0 )
    {
        buf[rd] = '\0';
        char *dname = dirname(buf);
        sprintf(filepath, "%s/arm/%s", dname, fname);
        fd = open(filepath, 00);
        if( fd == -1 && (*__errno_location ()) != 2 ) {
            fprintf(stderr, "unable to open FEL bootfile %s: %s\n",
                    filepath, strerror((*__errno_location ())));
            return -1;
        }
    }
    if( fd == -1 ) {
        sprintf(filepath, "/usr/share/allwindisk/%s", fname);
        if( (fd = open(filepath, 00)) == -1 ) {
            fprintf(stderr, "unable to open FEL bootfile %s\n", filepath);
            return -1;
        }
    }
    while( (rd = read(fd, buf, sizeof(buf))) > 0 ) {
        send_write_request(AW_FEL_1_WRITE, load_addr, rd, buf, rd);
        load_addr += rd;
    }
    close(fd);
    return 0;
}

variable_types:
fname
char *

variable_types: fd int

variable_types: rd int

variable_types:
filepath
char [1000]

variable_types:
dname
char *


decompiled_code:
__int64 fel_ainol()
{
__int64 v0; // rax
unsigned int v1; // eax
unsigned int v2; // ebx
const char *v4; // rax

v0 = libusb_open_device_with_vid_pid(0LL, 7994LL, 61416LL);
usb = v0;
if ( !v0 )
return (unsigned int)-1;
v1 = libusb_claim_interface(v0, 0LL);
if ( v1 )
{
v4 = (const char *)libusb_error_name(v1);
fprintf(stderr, "\nunable to claim interface: %s", v4);
v2 = -1;
}
else
{
if ( !(unsigned int)send_bootfile("draminit.bin", 0x2000u) )
send_exec_request(0x102u, 0x2000u);
v2 = send_bootfile("diskboot.bin", 0x4A000000u);
if ( !v2 )
send_exec_request(0x102u, 0x4A000000u);
libusb_release_interface(usb, 0LL);
libusb_close(usb);
}
return v2;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 v0; // rax
unsigned int v1; // eax
unsigned int v2; // ebx
const char *v4; // rax

v0 = libusb_open_device_with_vid_pid(0LL, 7994LL, 61416LL);
usb = v0;
if ( !v0 )
return (unsigned int)-1;
v1 = libusb_claim_interface(v0, 0LL);
if ( v1 )
{
v4 = (const char *)libusb_error_name(v1);
fprintf(stderr, "\nunable to claim interface: %s", v4);
v2 = -1;
}
else
{
if ( !(unsigned int)func11("draminit.bin", 0x2000u) )
func12(0x102u, 0x2000u);
v2 = func11("diskboot.bin", 0x4A000000u);
if ( !v2 )
func12(0x102u, 0x4A000000u);
libusb_release_interface(usb, 0LL);
libusb_close(usb);
}
return v2;
}

original_code:
int fel_ainol(void)
{
    int res;
    usb = libusb_open_device_with_vid_pid(((void *)0), 0x1f3a, 0xefe8);
    if (!usb)
        return -1;
    if( (res = libusb_claim_interface(usb, 0)) != 0 ) {
        fprintf(stderr, "\nunable to claim interface: %s",
                libusb_error_name(res));
        return -1;
    }
    if( (res = send_bootfile("draminit.bin", 0x2000)) == 0 ) {
        send_exec_request(AW_FEL_1_EXEC, 0x2000);
    }
    if( (res = send_bootfile("diskboot.bin", 0x4A000000)) == 0 ) {
        send_exec_request(AW_FEL_1_EXEC, 0x4A000000);
    }
    libusb_release_interface(usb, 0);
    libusb_close(usb);
    return res;
}

canonical_original_code:
int fel_ainol()
{
    int res;
    usb = libusb_open_device_with_vid_pid(((void *)0), 0x1f3a, 0xefe8);
    if (!usb)
        return -1;
    if( (res = libusb_claim_interface(usb, 0)) != 0 ) {
        fprintf(stderr, "\nunable to claim interface: %s",
                libusb_error_name(res));
        return -1;
    }
    if( (res = send_bootfile("draminit.bin", 0x2000)) == 0 ) {
        send_exec_request(AW_FEL_1_EXEC, 0x2000);
    }
    if( (res = send_bootfile("diskboot.bin", 0x4A000000)) == 0 ) {
        send_exec_request(AW_FEL_1_EXEC, 0x4A000000);
    }
    libusb_release_interface(usb, 0);
    libusb_close(usb);
    return res;
}

variable_types: res int


decompiled_code:
__int64 floatformat_always_valid()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 1LL;
}

original_code:
static int
floatformat_always_valid (const struct floatformat *fmt __attribute__ ((__unused__)),
                          const void *from __attribute__ ((__unused__)))
{
  return 1;
}

canonical_original_code:
static int floatformat_always_valid(struct floatformat *fmt, void *from)
{
  return 1;
}

variable_types: struct floatformat { enum floatformat_byteorders { floatformat_little=0, floatformat_big=1, floatformat_littlebyte_bigword=2, floatformat_vax=3 } byteorder; unsigned int totalsize; unsigned int sign_start; unsigned int exp_start; unsigned int exp_len; int exp_bias; unsigned int exp_nan; unsigned int man_start; unsigned int man_len; enum floatformat_intbit { floatformat_intbit_yes=0, floatformat_intbit_no=1 } intbit; char *name; int (*is_valid)(struct floatformat *fmt, void *from); struct floatformat *split_half; } *

variable_types:
from
void *

user_defined_types: struct floatformat { enum floatformat_byteorders byteorder; unsigned int totalsize; unsigned int sign_start; unsigned int exp_start; unsigned int exp_len; int exp_bias; unsigned int exp_nan; unsigned int man_start; unsigned int man_len; enum floatformat_intbit intbit; char *name; int (*is_valid)(struct floatformat *fmt, void *from); struct floatformat *split_half; }


original_code:
static unsigned long
get_field (const unsigned char *data, enum floatformat_byteorders order,
           unsigned int total_len, unsigned int start, unsigned int len)
{
  unsigned long result = 0;
  unsigned int cur_byte;
  int lo_bit, hi_bit, cur_bitshift = 0;
  int nextbyte = (order == floatformat_little) ? 1 : -1;
  start = total_len - (start + len);
  if (order == floatformat_little)
    cur_byte = start / 8;
  else
    cur_byte = (total_len - start - 1) / 8;
  lo_bit = start % 8;
  hi_bit = ((lo_bit + len) < (8) ? (lo_bit + len) : (8));
  do
    {
      unsigned int shifted = *(data + cur_byte) >> lo_bit;
      unsigned int bits = hi_bit - lo_bit;
      unsigned int mask = (1 << bits) - 1;
      result |= (shifted & mask) << cur_bitshift;
      len -= bits;
      cur_bitshift += bits;
      cur_byte += nextbyte;
      lo_bit = 0;
      hi_bit = ((len) < (8) ? (len) : (8));
    }
  while (len != 0);
  return result;
}

canonical_original_code:
static unsigned long get_field(unsigned char *data, enum floatformat_byteorders order, unsigned int total_len, unsigned int start, unsigned int len)
{
  unsigned long result = 0;
  unsigned int cur_byte;
  int lo_bit; int hi_bit; int cur_bitshift = 0;
  int nextbyte = (order == floatformat_little) ? 1 : -1;
  start = total_len - (start + len);
  if (order == floatformat_little)
    cur_byte = start / 8;
  else
    cur_byte = (total_len - start - 1) / 8;
  lo_bit = start % 8;
  hi_bit = ((lo_bit + len) < (8) ? (lo_bit + len) : (8));
  do
    {
      unsigned int shifted = *(data + cur_byte) >> lo_bit;
      unsigned int bits = hi_bit - lo_bit;
      unsigned int mask = (1 << bits) - 1;
      result |= (shifted & mask) << cur_bitshift;
      len -= bits;
      cur_bitshift += bits;
      cur_byte += nextbyte;
      lo_bit = 0;
      hi_bit = ((len) < (8) ? (len) : (8));
    }
  while (len != 0);
  return result;
}

variable_types:
data
unsigned char *

variable_types: enum floatformat_byteorders { floatformat_little=0, floatformat_big=1, floatformat_littlebyte_bigword=2, floatformat_vax=3 }

variable_types:
start
unsigned int

variable_types:
len
unsigned int

variable_types:
result
unsigned long

variable_types: nextbyte int

variable_types:
shifted
unsigned int

variable_types:
bits
unsigned int

variable_types:
mask
unsigned int


original_code:
static int
floatformat_i387_ext_is_valid (const struct floatformat *fmt, const void *from)
{
  unsigned long exponent, int_bit;
  const unsigned char *ufrom = (const unsigned char *) from;
  exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
   fmt->exp_start, fmt->exp_len);
  int_bit = get_field (ufrom, fmt->byteorder, fmt->totalsize,
         fmt->man_start, 1);
  if ((exponent == 0) != (int_bit == 0))
    return 0;
  else
    return 1;
}

canonical_original_code:
static int floatformat_i387_ext_is_valid(struct floatformat *fmt, void *from)
{
  unsigned long exponent; unsigned long int_bit;
  unsigned char *ufrom = (const unsigned char *) from;
  exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
   fmt->exp_start, fmt->exp_len);
  int_bit = get_field (ufrom, fmt->byteorder, fmt->totalsize,
         fmt->man_start, 1);
  if ((exponent == 0) != (int_bit == 0))
    return 0;
  else
    return 1;
}

variable_types:
exponent
unsigned long

variable_types:
ufrom
unsigned char *

user_defined_types: enum floatformat_byteorders { floatformat_little=0, floatformat_big=1, floatformat_littlebyte_bigword=2, floatformat_vax=3 }

user_defined_types: enum floatformat_intbit { floatformat_intbit_yes=0, floatformat_intbit_no=1 }


original_code:
static int
floatformat_ibm_long_double_is_valid (const struct floatformat *fmt,
          const void *from)
{
  const unsigned char *ufrom = (const unsigned char *) from;
  const struct floatformat *hfmt = fmt->split_half;
  long top_exp, bot_exp;
  int top_nan = 0;
  top_exp = get_field (ufrom, hfmt->byteorder, hfmt->totalsize,
         hfmt->exp_start, hfmt->exp_len);
  bot_exp = get_field (ufrom + 8, hfmt->byteorder, hfmt->totalsize,
         hfmt->exp_start, hfmt->exp_len);
  if ((unsigned long) top_exp == hfmt->exp_nan)
    top_nan = mant_bits_set (hfmt, ufrom);
  if (top_nan)
    return 1;
  if ((unsigned long) top_exp == hfmt->exp_nan || top_exp == 0)
    {
      if (bot_exp != 0)
 return 0;
      return !mant_bits_set (hfmt, ufrom + 8);
    }
  if (bot_exp < top_exp - 53)
    return 1;
  if (bot_exp > top_exp - 53 && bot_exp != 0)
    return 0;
  if (bot_exp == 0)
    {
      int first_bit = -1, second_bit = -1, cur_bit;
      for (cur_bit = 0; (unsigned int) cur_bit < hfmt->man_len; cur_bit++)
 if (get_field (ufrom + 8, hfmt->byteorder, hfmt->totalsize,
         hfmt->man_start + cur_bit, 1))
   {
     if (first_bit == -1)
       first_bit = cur_bit;
     else
       {
  second_bit = cur_bit;
  break;
       }
   }
      if (first_bit == -1)
 return 1;
      if (-first_bit < top_exp - 53)
 return 1;
      if (-first_bit > top_exp - 53)
 return 0;
      if (second_bit != -1)
 return 0;
      return !get_field (ufrom, hfmt->byteorder, hfmt->totalsize,
    hfmt->man_start + hfmt->man_len - 1, 1);
    }
  else
    {
      if (get_field (ufrom, hfmt->byteorder, hfmt->totalsize,
       hfmt->man_start + hfmt->man_len - 1, 1))
 return 0;
      return !mant_bits_set (hfmt, ufrom + 8);
    }
}

canonical_original_code:
static int floatformat_ibm_long_double_is_valid(struct floatformat *fmt, void *from)
{
  unsigned char *ufrom = (const unsigned char *) from;
  struct floatformat *hfmt = fmt->split_half;
  long top_exp; long bot_exp;
  int top_nan = 0;
  top_exp = get_field (ufrom, hfmt->byteorder, hfmt->totalsize,
         hfmt->exp_start, hfmt->exp_len);
  bot_exp = get_field (ufrom + 8, hfmt->byteorder, hfmt->totalsize,
         hfmt->exp_start, hfmt->exp_len);
  if ((unsigned long) top_exp == hfmt->exp_nan)
    top_nan = mant_bits_set (hfmt, ufrom);
  if (top_nan)
    return 1;
  if ((unsigned long) top_exp == hfmt->exp_nan || top_exp == 0)
    {
      if (bot_exp != 0)
 return 0;
      return !mant_bits_set (hfmt, ufrom + 8);
    }
  if (bot_exp < top_exp - 53)
    return 1;
  if (bot_exp > top_exp - 53 && bot_exp != 0)
    return 0;
  if (bot_exp == 0)
    {
      int first_bit = -1; int second_bit = -1; int cur_bit;
      for (cur_bit = 0; (unsigned int) cur_bit < hfmt->man_len; cur_bit++)
 if (get_field (ufrom + 8, hfmt->byteorder, hfmt->totalsize,
         hfmt->man_start + cur_bit, 1))
   {
     if (first_bit == -1)
       first_bit = cur_bit;
     else
       {
  second_bit = cur_bit;
  break;
       }
   }
      if (first_bit == -1)
 return 1;
      if (-first_bit < top_exp - 53)
 return 1;
      if (-first_bit > top_exp - 53)
 return 0;
      if (second_bit != -1)
 return 0;
      return !get_field (ufrom, hfmt->byteorder, hfmt->totalsize,
    hfmt->man_start + hfmt->man_len - 1, 1);
    }
  else
    {
      if (get_field (ufrom, hfmt->byteorder, hfmt->totalsize,
       hfmt->man_start + hfmt->man_len - 1, 1))
 return 0;
      return !mant_bits_set (hfmt, ufrom + 8);
    }
}


original_code:
static void
put_field (unsigned char *data, enum floatformat_byteorders order,
           unsigned int total_len, unsigned int start, unsigned int len,
           unsigned long stuff_to_put)
{
  unsigned int cur_byte;
  int lo_bit, hi_bit;
  int nextbyte = (order == floatformat_little) ? 1 : -1;
  start = total_len - (start + len);
  if (order == floatformat_little)
    cur_byte = start / 8;
  else
    cur_byte = (total_len - start - 1) / 8;
  lo_bit = start % 8;
  hi_bit = ((lo_bit + len) < (8) ? (lo_bit + len) : (8));
  do
    {
      unsigned char *byte_ptr = data + cur_byte;
      unsigned int bits = hi_bit - lo_bit;
      unsigned int mask = ((1 << bits) - 1) << lo_bit;
      *byte_ptr = (*byte_ptr & ~mask) | ((stuff_to_put << lo_bit) & mask);
      stuff_to_put >>= bits;
      len -= bits;
      cur_byte += nextbyte;
      lo_bit = 0;
      hi_bit = ((len) < (8) ? (len) : (8));
    }
  while (len != 0);
}

canonical_original_code:
static void put_field(unsigned char *data, enum floatformat_byteorders order, unsigned int total_len, unsigned int start, unsigned int len, unsigned long stuff_to_put)
{
  unsigned int cur_byte;
  int lo_bit; int hi_bit;
  int nextbyte = (order == floatformat_little) ? 1 : -1;
  start = total_len - (start + len);
  if (order == floatformat_little)
    cur_byte = start / 8;
  else
    cur_byte = (total_len - start - 1) / 8;
  lo_bit = start % 8;
  hi_bit = ((lo_bit + len) < (8) ? (lo_bit + len) : (8));
  do
    {
      unsigned char *byte_ptr = data + cur_byte;
      unsigned int bits = hi_bit - lo_bit;
      unsigned int mask = ((1 << bits) - 1) << lo_bit;
      *byte_ptr = (*byte_ptr & ~mask) | ((stuff_to_put << lo_bit) & mask);
      stuff_to_put >>= bits;
      len -= bits;
      cur_byte += nextbyte;
      lo_bit = 0;
      hi_bit = ((len) < (8) ? (len) : (8));
    }
  while (len != 0);
}


original_code:
void
floatformat_from_double (const struct floatformat *fmt,
                         const double *from, void *to)
{
  double dfrom;
  int exponent;
  double mant;
  unsigned int mant_bits, mant_off;
  int mant_bits_left;
  unsigned char *uto = (unsigned char *) to;
  dfrom = *from;
  memset (uto, 0, fmt->totalsize / 8);
  if (dfrom < 0)
    {
      put_field (uto, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1, 1);
      dfrom = -dfrom;
    }
  if (dfrom == 0)
    {
      return;
    }
  if (dfrom != dfrom)
    {
      put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
   fmt->exp_len, fmt->exp_nan);
      put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start,
   32, 1);
      return;
    }
  if (dfrom + dfrom == dfrom)
    {
      put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
   fmt->exp_len, fmt->exp_nan);
      return;
    }
  mant = frexp (dfrom, &exponent);
  if (exponent + fmt->exp_bias - 1 > 0)
    put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
        fmt->exp_len, exponent + fmt->exp_bias - 1);
  else
    {
      put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
   fmt->exp_len, 0);
      mant = ldexp (mant, exponent + fmt->exp_bias - 1);
    }
  mant_bits_left = fmt->man_len;
  mant_off = fmt->man_start;
  while (mant_bits_left > 0)
    {
      unsigned long mant_long;
      mant_bits = mant_bits_left < 32 ? mant_bits_left : 32;
      mant *= 4294967296.0;
      mant_long = (unsigned long)mant;
      mant -= mant_long;
      if ((unsigned int) mant_bits_left == fmt->man_len
   && fmt->intbit == floatformat_intbit_no
   && exponent + fmt->exp_bias - 1 > 0)
 {
   mant_long &= 0x7fffffff;
   mant_bits -= 1;
 }
      else if (mant_bits < 32)
 {
   mant_long >>= 32 - mant_bits;
 }
      put_field (uto, fmt->byteorder, fmt->totalsize,
   mant_off, mant_bits, mant_long);
      mant_off += mant_bits;
      mant_bits_left -= mant_bits;
    }
}

canonical_original_code:
void floatformat_from_double(struct floatformat *fmt, double *from, void *to)
{
  double dfrom;
  int exponent;
  double mant;
  unsigned int mant_bits; unsigned int mant_off;
  int mant_bits_left;
  unsigned char *uto = (unsigned char *) to;
  dfrom = *from;
  memset (uto, 0, fmt->totalsize / 8);
  if (dfrom < 0)
    {
      put_field (uto, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1, 1);
      dfrom = -dfrom;
    }
  if (dfrom == 0)
    {
      return;
    }
  if (dfrom != dfrom)
    {
      put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
   fmt->exp_len, fmt->exp_nan);
      put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start,
   32, 1);
      return;
    }
  if (dfrom + dfrom == dfrom)
    {
      put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
   fmt->exp_len, fmt->exp_nan);
      return;
    }
  mant = frexp (dfrom, &exponent);
  if (exponent + fmt->exp_bias - 1 > 0)
    put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
        fmt->exp_len, exponent + fmt->exp_bias - 1);
  else
    {
      put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
   fmt->exp_len, 0);
      mant = ldexp (mant, exponent + fmt->exp_bias - 1);
    }
  mant_bits_left = fmt->man_len;
  mant_off = fmt->man_start;
  while (mant_bits_left > 0)
    {
      unsigned long mant_long;
      mant_bits = mant_bits_left < 32 ? mant_bits_left : 32;
      mant *= 4294967296.0;
      mant_long = (unsigned long)mant;
      mant -= mant_long;
      if ((unsigned int) mant_bits_left == fmt->man_len
   && fmt->intbit == floatformat_intbit_no
   && exponent + fmt->exp_bias - 1 > 0)
 {
   mant_long &= 0x7fffffff;
   mant_bits -= 1;
 }
      else if (mant_bits < 32)
 {
   mant_long >>= 32 - mant_bits;
 }
      put_field (uto, fmt->byteorder, fmt->totalsize,
   mant_off, mant_bits, mant_long);
      mant_off += mant_bits;
      mant_bits_left -= mant_bits;
    }
}

variable_types:
from
double *

variable_types:
to
void *

variable_types: dfrom double

variable_types: exponent int

variable_types: mant double

variable_types:
uto
unsigned char *


decompiled_code:
__int64 __fastcall floatformat_is_valid(__int64 a1)
{
return (*(__int64 (**)(void))(a1 + 48))();
}

original_code:
int
floatformat_is_valid (const struct floatformat *fmt, const void *from)
{
  return fmt->is_valid (fmt, from);
}

canonical_original_code:
int floatformat_is_valid(struct floatformat *fmt, void *from)
{
  return fmt->is_valid (fmt, from);
}

variable_types: struct floatformat { enum floatformat_byteorders { floatformat_little=0, floatformat_big=1, floatformat_littlebyte_bigword=2, floatformat_vax=3 } byteorder; unsigned int totalsize; unsigned int sign_start; unsigned int exp_start; unsigned int exp_len; int exp_bias; unsigned int exp_nan; unsigned int man_start; unsigned int man_len; enum floatformat_intbit { floatformat_intbit_yes=0, floatformat_intbit_no=1 } intbit; char *name; int (*is_valid)(struct floatformat *fmt, void *from); struct floatformat *split_half; } *

variable_types:
from
void *


ifdown

decompiled_code:
__int64 ifdown()
{
int v0; // eax
int v1; // er14
char *v2; // r13
int i; // er12
__int64 result; // rax
char *j; // rbx
__int16 v6; // ax
int v7; // [rsp+0h] [rbp-A48h] BYREF
char *v8; // [rsp+8h] [rbp-A40h]
char v9[2616]; // [rsp+10h] [rbp-A38h] BYREF

v0 = socket(2, 2, 0);
if ( v0 < 0 )
{
fwrite("ifdown: ", 1uLL, 8uLL, stderr);
perror("socket");
result = 0xFFFFFFFFLL;
}
else
{
v1 = v0;
v7 = 2560;
v8 = v9;
if ( ioctl(v0, 0x8912uLL, &v7) < 0 )
{
fwrite("ifdown: ", 1uLL, 8uLL, stderr);
perror("SIOCGIFCONF");
close(v1);
result = 0xFFFFFFFFLL;
}
else
{
v2 = &v9[v7];
for ( i = 1; i != -1; --i )
{
for ( j = v9; v2 > j; j += 40 )
{
if ( (memcmp(j, "shaper", 6uLL) == 0) == i )
{
if ( memcmp(j, "lo", 2uLL) )
{
if ( !strchr(j, 58) )
{
if ( ioctl(v1, 0x8913uLL, j) < 0
|| (v6 = *((_WORD *)j + 8), (v6 & 1) != 0)
&& (*((_WORD *)j + 8) = v6 & 0xFFFE, ioctl(v1, 0x8914uLL, j) < 0) )
{
fwrite("ifdown: shutdown ", 1uLL, 0x11uLL, stderr);
perror(j);
}
}
}
}
}
}
close(v1);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
int v1; // er14
char *v2; // r13
int i; // er12
__int64 result; // rax
char *j; // rbx
__int16 v6; // ax
int v7; // [rsp+0h] [rbp-A48h] BYREF
char *v8; // [rsp+8h] [rbp-A40h]
char v9[2616]; // [rsp+10h] [rbp-A38h] BYREF

v0 = socket(2, 2, 0);
if ( v0 < 0 )
{
fwrite("ifdown: ", 1uLL, 8uLL, stderr);
perror("socket");
result = 0xFFFFFFFFLL;
}
else
{
v1 = v0;
v7 = 2560;
v8 = v9;
if ( ioctl(v0, 0x8912uLL, &v7) < 0 )
{
fwrite("ifdown: ", 1uLL, 8uLL, stderr);
perror("SIOCGIFCONF");
close(v1);
result = 0xFFFFFFFFLL;
}
else
{
v2 = &v9[v7];
for ( i = 1; i != -1; --i )
{
for ( j = v9; v2 > j; j += 40 )
{
if ( (memcmp(j, "shaper", 6uLL) == 0) == i )
{
if ( memcmp(j, "lo", 2uLL) )
{
if ( !strchr(j, 58) )
{
if ( ioctl(v1, 0x8913uLL, j) < 0
|| (v6 = *((_WORD *)j + 8), (v6 & 1) != 0)
&& (*((_WORD *)j + 8) = v6 & 0xFFFE, ioctl(v1, 0x8914uLL, j) < 0) )
{
fwrite("ifdown: shutdown ", 1uLL, 0x11uLL, stderr);
perror(j);
}
}
}
}
}
}
close(v1);
result = 0LL;
}
}
return result;
}

original_code:
int ifdown(void)
{
 char ifr_buf[sizeof(struct ifreq) * 64];
 char *ifr_end;
 struct ifconf ifc;
 int fd;
 int shaper;
 if ((fd = socket(2, SOCK_DGRAM, 0)) < 0) {
  fprintf(stderr, "ifdown: ");
  perror("socket");
  return -1;
 }
 ifc.ifc_len = sizeof(ifr_buf);
 ifc.ifc_ifcu.ifcu_buf = ifr_buf;
 if (ioctl(fd, 0x8912, &ifc) < 0) {
  fprintf(stderr, "ifdown: ");
  perror("SIOCGIFCONF");
  close(fd);
  return -1;
 }
 ifr_end = ifr_buf + ifc.ifc_len;
 for (shaper = 1; shaper >= 0; shaper--) {
  char *ifr_next = ifr_buf;
  while (ifr_next < ifr_end) {
   struct ifreq *ifr;
   int flags;
   ifr = (struct ifreq *)ifr_next;
   ifr_next += sizeof(struct ifreq);
   if ((strncmp(ifr->ifr_ifrn.ifrn_name, "shaper", 6) == 0)
       != shaper) continue;
   if (strncmp(ifr->ifr_ifrn.ifrn_name, "lo", 2) == 0)
    continue;
   if (strchr(ifr->ifr_ifrn.ifrn_name, ':') != ((void *)0))
    continue;
   if (ioctl(fd, 0x8913, ifr) < 0) {
    fprintf(stderr, "ifdown: shutdown ");
    perror(ifr->ifr_ifrn.ifrn_name);
    continue;
   }
   flags = ifr->ifr_ifru.ifru_flags;
   if (flags & IFF_UP) {
    flags &= ~(IFF_UP);
    ifr->ifr_ifru.ifru_flags = flags;
    if (ioctl(fd, 0x8914, ifr) < 0) {
     fprintf(stderr, "ifdown: shutdown ");
     perror(ifr->ifr_ifrn.ifrn_name);
    }
   }
  }
 }
 close(fd);
 return 0;
}

canonical_original_code:
int ifdown()
{
 char ifr_buf[-1];
 char *ifr_end;
 struct ifconf ifc;
 int fd;
 int shaper;
 if ((fd = socket(2, SOCK_DGRAM, 0)) < 0) {
  fprintf(stderr, "ifdown: ");
  perror("socket");
  return -1;
 }
 ifc.ifc_len = sizeof(ifr_buf);
 ifc.ifc_ifcu.ifcu_buf = ifr_buf;
 if (ioctl(fd, 0x8912, &ifc) < 0) {
  fprintf(stderr, "ifdown: ");
  perror("SIOCGIFCONF");
  close(fd);
  return -1;
 }
 ifr_end = ifr_buf + ifc.ifc_len;
 for (shaper = 1; shaper >= 0; shaper--) {
  char *ifr_next = ifr_buf;
  while (ifr_next < ifr_end) {
   struct ifreq *ifr;
   int flags;
   ifr = (struct ifreq *)ifr_next;
   ifr_next += sizeof(struct ifreq);
   if ((strncmp(ifr->ifr_ifrn.ifrn_name, "shaper", 6) == 0)
       != shaper) continue;
   if (strncmp(ifr->ifr_ifrn.ifrn_name, "lo", 2) == 0)
    continue;
   if (strchr(ifr->ifr_ifrn.ifrn_name, ':') != ((void *)0))
    continue;
   if (ioctl(fd, 0x8913, ifr) < 0) {
    fprintf(stderr, "ifdown: shutdown ");
    perror(ifr->ifr_ifrn.ifrn_name);
    continue;
   }
   flags = ifr->ifr_ifru.ifru_flags;
   if (flags & IFF_UP) {
    flags &= ~(IFF_UP);
    ifr->ifr_ifru.ifru_flags = flags;
    if (ioctl(fd, 0x8914, ifr) < 0) {
     fprintf(stderr, "ifdown: shutdown ");
     perror(ifr->ifr_ifrn.ifrn_name);
    }
   }
  }
 }
 close(fd);
 return 0;
}

variable_types: struct ifconf { int ifc_len; union { char *ifcu_buf; struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; } *ifcu_req; } ifc_ifcu; }

variable_types: fd int

variable_types: shaper int

variable_types: flags int

user_defined_types: struct ifconf { int ifc_len; union { char *ifcu_buf; struct ifreq *ifcu_req; } ifc_ifcu; }

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }


original_code:
static void fb_update(struct FB *fb)
{
    fb->vi.yoffset = 1;
    ioctl(fb->fd, 0x4601, &fb->vi);
    fb->vi.yoffset = 0;
    ioctl(fb->fd, 0x4601, &fb->vi);
}

variable_types: struct FB { unsigned char *bits; int fd; struct fb_var_screeninfo { unsigned int xres; unsigned int yres; unsigned int xres_virtual; unsigned int yres_virtual; unsigned int xoffset; unsigned int yoffset; unsigned int bits_per_pixel; unsigned int grayscale; struct fb_bitfield { unsigned int offset; unsigned int length; unsigned int msb_right; } red; struct fb_bitfield green; struct fb_bitfield blue; struct fb_bitfield transp; unsigned int nonstd; unsigned int activate; unsigned int height; unsigned int width; unsigned int accel_flags; unsigned int pixclock; unsigned int left_margin; unsigned int right_margin; unsigned int upper_margin; unsigned int lower_margin; unsigned int hsync_len; unsigned int vsync_len; unsigned int sync; unsigned int vmode; unsigned int rotate; unsigned int colorspace; unsigned int reserved[4]; } vi; int chars; } *

user_defined_types: struct FB { unsigned char *bits; int fd; struct fb_var_screeninfo vi; int chars; }

user_defined_types: struct fb_var_screeninfo { unsigned int xres; unsigned int yres; unsigned int xres_virtual; unsigned int yres_virtual; unsigned int xoffset; unsigned int yoffset; unsigned int bits_per_pixel; unsigned int grayscale; struct fb_bitfield red; struct fb_bitfield green; struct fb_bitfield blue; struct fb_bitfield transp; unsigned int nonstd; unsigned int activate; unsigned int height; unsigned int width; unsigned int accel_flags; unsigned int pixclock; unsigned int left_margin; unsigned int right_margin; unsigned int upper_margin; unsigned int lower_margin; unsigned int hsync_len; unsigned int vsync_len; unsigned int sync; unsigned int vmode; unsigned int rotate; unsigned int colorspace; unsigned int reserved[4]; }


original_code:
static void print_buf(struct FB *fb, const char *buf, int size)
{
    int pos;
    int x, y, width, height, d, char_width, bytes_per_pixel;
    unsigned char *bits, c;
    width = ((fb)->vi.xres);
    height = ((fb)->vi.yres);
    bytes_per_pixel = fb->vi.bits_per_pixel / 8;
    bits = fb->bits;
    char_width = width / 8;
    for(pos = 0; pos < size; ++pos) {
        c = buf[pos];
        if(fb->chars == char_width ) {
            memmove(bits, bits + 16 * width * bytes_per_pixel,
                    (height - 16) * width * bytes_per_pixel);
            memset(bits + (height - 16) * width * bytes_per_pixel,
                    0, 16 * width * bytes_per_pixel);
            fb->chars = 0;
        }
        if( c == '\n' ) {
            fb->chars = char_width;
            continue;
        }
        for(y = 0; y < 16; ++y) {
            for(x = 0; x < 8; ++x) {
                for(d = 0; d < bytes_per_pixel; ++d) {
                    if(fontdata_8x16[16 * c +y] & 0x80 >> x) {
                        bits[((height-16+y) * width + 8 * fb->chars + x) * bytes_per_pixel + d] = 0xff;
                    }else{
                        bits[((height-16+y) * width + 8 * fb->chars + x) * bytes_per_pixel + d] = 0;
                    }
                }
            }
        }
        ++fb->chars;
    }
}

canonical_original_code:
static void print_buf(struct FB *fb, char *buf, int size)
{
    int pos;
    int x; int y; int width; int height; int d; int char_width; int bytes_per_pixel;
    unsigned char *bits; unsigned char c;
    width = ((fb)->vi.xres);
    height = ((fb)->vi.yres);
    bytes_per_pixel = fb->vi.bits_per_pixel / 8;
    bits = fb->bits;
    char_width = width / 8;
    for(pos = 0; pos < size; ++pos) {
        c = buf[pos];
        if(fb->chars == char_width ) {
            memmove(bits, bits + 16 * width * bytes_per_pixel,
                    (height - 16) * width * bytes_per_pixel);
            memset(bits + (height - 16) * width * bytes_per_pixel,
                    0, 16 * width * bytes_per_pixel);
            fb->chars = 0;
        }
        if( c == '\n' ) {
            fb->chars = char_width;
            continue;
        }
        for(y = 0; y < 16; ++y) {
            for(x = 0; x < 8; ++x) {
                for(d = 0; d < bytes_per_pixel; ++d) {
                    if(fontdata_8x16[16 * c +y] & 0x80 >> x) {
                        bits[((height-16+y) * width + 8 * fb->chars + x) * bytes_per_pixel + d] = 0xff;
                    }else{
                        bits[((height-16+y) * width + 8 * fb->chars + x) * bytes_per_pixel + d] = 0;
                    }
                }
            }
        }
        ++fb->chars;
    }
}

variable_types:
buf
char *

variable_types: size int

variable_types: pos int

variable_types: x int

variable_types: y int

variable_types: width int

variable_types: height int

variable_types: d int

variable_types:
bits
unsigned char *

variable_types:
c
unsigned char

user_defined_types: struct fb_bitfield { unsigned int offset; unsigned int length; unsigned int msb_right; }


decompiled_code:
int __fastcall fb_close(__int64 a1)
{
munmap(*(void **)a1, (unsigned int)(*(_DWORD *)(a1 + 36) * *(_DWORD *)(a1 + 16) * *(_DWORD *)(a1 + 12)) >> 3);
return close(*(_DWORD *)(a1 + 8));
}

original_code:
static void fb_close(struct FB *fb)
{
    munmap(fb->bits, ((fb)->vi.xres * (fb)->vi.yres * (fb)->vi.bits_per_pixel / 8));
    close(fb->fd);
}


decompiled_code:
void print_response_data()
{
__int64 v0; // rcx
unsigned int v1; // eax
bool v2; // zf
_BYTE v3[262156]; // [rsp-4000Ch] [rbp-40018h] BYREF
int v4[3]; // [rsp+0h] [rbp-Ch] BYREF

v0 = (unsigned int)dword_E34;
if ( dword_E34 )
{
do
{
if ( (unsigned int)v0 > 0x40000 )
v0 = 0x40000LL;
v1 = libusb_bulk_transfer(usb, 129LL, v3, v0, v4, 0LL);
if ( v1 )
{
printf("read error: status=%d\n", v1);
exit(1);
}
fwrite(v3, v4[0], 1uLL, stdout);
v2 = dword_E34 == v4[0];
v0 = (unsigned int)(dword_E34 - v4[0]);
dword_E34 -= v4[0];
}
while ( !v2 );
}
}

canonical_decompiled_code:
void func3()
{
__int64 v0; // rcx
unsigned int v1; // eax
bool v2; // zf
_BYTE v3[262156]; // [rsp-4000Ch] [rbp-40018h] BYREF
int v4[3]; // [rsp+0h] [rbp-Ch] BYREF

v0 = (unsigned int)dword_E34;
if ( dword_E34 )
{
do
{
if ( (unsigned int)v0 > 0x40000 )
v0 = 0x40000LL;
v1 = libusb_bulk_transfer(usb, 129LL, v3, v0, v4, 0LL);
if ( v1 )
{
printf("read error: status=%d\n", v1);
exit(1);
}
fwrite(v3, v4[0], 1uLL, stdout);
v2 = dword_E34 == v4[0];
v0 = (unsigned int)(dword_E34 - v4[0]);
dword_E34 -= v4[0];
}
while ( !v2 );
}
}

original_code:
void print_response_data(void)
{
    int status, transferred, toRead;
    char buf[0x40000];
    while( cur_resp_header.datasize > 0 ) {
        toRead = sizeof(buf) < cur_resp_header.datasize ?
            sizeof(buf) : cur_resp_header.datasize;
        if( (status = libusb_bulk_transfer(usb, 1 | LIBUSB_ENDPOINT_IN,
                (unsigned char*)buf, toRead, &transferred, 0)) != 0)
        {
            printf("read error: status=%d\n", status);
            exit(1);
        }
        fwrite(buf, transferred, 1, stdout);
        cur_resp_header.datasize -= transferred;
    }
}

canonical_original_code:
void print_response_data()
{
    int status; int transferred; int toRead;
    char buf[262144];
    while( cur_resp_header.datasize > 0 ) {
        toRead = sizeof(buf) < cur_resp_header.datasize ?
            sizeof(buf) : cur_resp_header.datasize;
        if( (status = libusb_bulk_transfer(usb, 1 | LIBUSB_ENDPOINT_IN,
                (unsigned char *)buf, toRead, &transferred, 0)) != 0)
        {
            printf("read error: status=%d\n", status);
            exit(1);
        }
        fwrite(buf, transferred, 1, stdout);
        cur_resp_header.datasize -= transferred;
    }
}

variable_types: status int

variable_types: transferred int

variable_types: toRead int


decompiled_code:
__int64 __fastcall send_command(unsigned __int16 a1, unsigned int a2, __int64 a3, unsigned int a4, __int64 a5, unsigned int a6)
{
__int16 v10; // ax
unsigned int v11; // eax
unsigned __int16 v12; // bx
unsigned int v14; // [rsp+Ch] [rbp-5Ch] BYREF
__int16 v15[2]; // [rsp+10h] [rbp-58h] BYREF
int v16; // [rsp+14h] [rbp-54h]
__int64 v17; // [rsp+18h] [rbp-50h]
int v18; // [rsp+20h] [rbp-48h]
unsigned int v19; // [rsp+24h] [rbp-44h]

if ( dword_E34 )
{
puts("internal error: unread data of previous command");
exit(1);
}
v15[0] = _uint16_identity(0x1234u);
v15[1] = _uint16_identity(a1);
v16 = _uint32_identity(a2);
v17 = _uint64_identity(a3);
v18 = _uint32_identity(a4);
v19 = a6;
if ( (unsigned int)libusb_bulk_transfer(usb, 2LL, v15, 24LL, &v14, 0LL) )
{
puts("write error");
exit(1);
}
if ( a6 && (unsigned int)libusb_bulk_transfer(usb, 2LL, a5, a6, &v14, 0LL) )
{
puts("write error");
exit(1);
}
do
{
v11 = libusb_bulk_transfer(usb, 129LL, &cur_resp_header, 8LL, &v14, 0LL);
if ( v11 )
{
printf("read error: status=%d\n", v11);
exit(1);
}
if ( v14 != 8 )
{
printf("read error: bad header size=%d\n", v14);
exit(1);
}
v12 = _uint16_identity((unsigned __int16)cur_resp_header);
cur_resp_header = v12;
word_E32 = _uint16_identity((unsigned __int16)word_E32);
dword_E34 = _uint32_identity(dword_E34);
if ( v12 != 4660 )
printf("read error: bad magic=%x\n", v12);
v10 = word_E32;
if ( word_E32 != 2 )
break;
print_response_data();
v10 = word_E32;
}
while ( word_E32 == 2 );
if ( !v10 )
{
puts("command execution failed on device");
exit(1);
}
return (unsigned int)dword_E34;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int16 a1, unsigned int a2, __int64 a3, unsigned int a4, __int64 a5, unsigned int a6)
{
__int16 v10; // ax
unsigned int v11; // eax
unsigned __int16 v12; // bx
unsigned int v14; // [rsp+Ch] [rbp-5Ch] BYREF
__int16 v15[2]; // [rsp+10h] [rbp-58h] BYREF
int v16; // [rsp+14h] [rbp-54h]
__int64 v17; // [rsp+18h] [rbp-50h]
int v18; // [rsp+20h] [rbp-48h]
unsigned int v19; // [rsp+24h] [rbp-44h]

if ( dword_E34 )
{
puts("internal error: unread data of previous command");
exit(1);
}
v15[0] = func0(0x1234u);
v15[1] = func0(a1);
v16 = func1(a2);
v17 = func2(a3);
v18 = func1(a4);
v19 = a6;
if ( (unsigned int)libusb_bulk_transfer(usb, 2LL, v15, 24LL, &v14, 0LL) )
{
puts("write error");
exit(1);
}
if ( a6 && (unsigned int)libusb_bulk_transfer(usb, 2LL, a5, a6, &v14, 0LL) )
{
puts("write error");
exit(1);
}
do
{
v11 = libusb_bulk_transfer(usb, 129LL, &cur_resp_header, 8LL, &v14, 0LL);
if ( v11 )
{
printf("read error: status=%d\n", v11);
exit(1);
}
if ( v14 != 8 )
{
printf("read error: bad header size=%d\n", v14);
exit(1);
}
v12 = func0((unsigned __int16)cur_resp_header);
cur_resp_header = v12;
word_E32 = func0((unsigned __int16)word_E32);
dword_E34 = func1(dword_E34);
if ( v12 != 4660 )
printf("read error: bad magic=%x\n", v12);
v10 = word_E32;
if ( word_E32 != 2 )
break;
func3();
v10 = word_E32;
}
while ( word_E32 == 2 );
if ( !v10 )
{
puts("command execution failed on device");
exit(1);
}
return (unsigned int)dword_E34;
}

original_code:
int send_command(enum BootdiskCommand cmd, unsigned param1,
        unsigned long long start, unsigned count,
        const void *data, unsigned datasize)
{
    struct bootdisk_cmd_header cmd_header;
    int status, transferred;
    if( cur_resp_header.datasize > 0 ) {
        printf("internal error: unread data of previous command\n");
        exit(1);
    }
    cmd_header.magic = __uint16_identity (0x1234);
    cmd_header.cmd = __uint16_identity (cmd);
    cmd_header.param1 = __uint32_identity (param1);
    cmd_header.start = __uint64_identity (start);
    cmd_header.count = __uint32_identity (count);
    cmd_header.datasize = datasize;
    if( libusb_bulk_transfer(usb, 2 | LIBUSB_ENDPOINT_OUT,
                (unsigned char*)&cmd_header, sizeof(cmd_header),
                &transferred, 0) != 0 )
    {
        printf("write error\n");
        exit(1);
    }
    if( datasize > 0 && libusb_bulk_transfer(usb, 2 | LIBUSB_ENDPOINT_OUT,
                (unsigned char*)data, datasize, &transferred, 0) != 0 )
    {
        printf("write error\n");
        exit(1);
    }
    do {
        if( (status = libusb_bulk_transfer(usb, 1 | LIBUSB_ENDPOINT_IN,
                (void*)&cur_resp_header, sizeof(cur_resp_header),
                &transferred, 0)) != 0)
        {
            printf("read error: status=%d\n", status);
            exit(1);
        }
        if( transferred != sizeof(cur_resp_header) ) {
            printf("read error: bad header size=%d\n", transferred);
            exit(1);
        }
        cur_resp_header.magic = __uint16_identity (cur_resp_header.magic);
        cur_resp_header.status = __uint16_identity (cur_resp_header.status);
        cur_resp_header.datasize = __uint32_identity (cur_resp_header.datasize);
        if( cur_resp_header.magic != 0x1234 ) {
            printf("read error: bad magic=%x\n", cur_resp_header.magic);
        }
        if( cur_resp_header.status == BRST_MSG )
            print_response_data();
    }while( cur_resp_header.status == BRST_MSG );
    if( cur_resp_header.status == BRST_FAIL ) {
        printf("command execution failed on device\n");
        exit(1);
    }
    return cur_resp_header.datasize;
}

canonical_original_code:
int send_command(enum BootdiskCommand cmd, unsigned int param1, unsigned long long start, unsigned int count, void *data, unsigned int datasize)
{
    struct bootdisk_cmd_header cmd_header;
    int status; int transferred;
    if( cur_resp_header.datasize > 0 ) {
        printf("internal error: unread data of previous command\n");
        exit(1);
    }
    cmd_header.magic = __uint16_identity (0x1234);
    cmd_header.cmd = __uint16_identity (cmd);
    cmd_header.param1 = __uint32_identity (param1);
    cmd_header.start = __uint64_identity (start);
    cmd_header.count = __uint32_identity (count);
    cmd_header.datasize = datasize;
    if( libusb_bulk_transfer(usb, 2 | LIBUSB_ENDPOINT_OUT,
                (unsigned char *)&cmd_header, sizeof(cmd_header),
                &transferred, 0) != 0 )
    {
        printf("write error\n");
        exit(1);
    }
    if( datasize > 0 && libusb_bulk_transfer(usb, 2 | LIBUSB_ENDPOINT_OUT,
                (unsigned char *)data, datasize, &transferred, 0) != 0 )
    {
        printf("write error\n");
        exit(1);
    }
    do {
        if( (status = libusb_bulk_transfer(usb, 1 | LIBUSB_ENDPOINT_IN,
                (void *)&cur_resp_header, sizeof(cur_resp_header),
                &transferred, 0)) != 0)
        {
            printf("read error: status=%d\n", status);
            exit(1);
        }
        if( transferred != sizeof(cur_resp_header) ) {
            printf("read error: bad header size=%d\n", transferred);
            exit(1);
        }
        cur_resp_header.magic = __uint16_identity (cur_resp_header.magic);
        cur_resp_header.status = __uint16_identity (cur_resp_header.status);
        cur_resp_header.datasize = __uint32_identity (cur_resp_header.datasize);
        if( cur_resp_header.magic != 0x1234 ) {
            printf("read error: bad magic=%x\n", cur_resp_header.magic);
        }
        if( cur_resp_header.status == BRST_MSG )
            print_response_data();
    }while( cur_resp_header.status == BRST_MSG );
    if( cur_resp_header.status == BRST_FAIL ) {
        printf("command execution failed on device\n");
        exit(1);
    }
    return cur_resp_header.datasize;
}

variable_types: enum BootdiskCommand { BCMD_NONE=0, BCMD_FLASHMEM_PARAMS=expr, BCMD_BOARD_EXIT=expr, BCMD_PING=expr, BCMD_MEMJUMPTO=expr, BCMD_GETLOG=expr, BCMD_SLEEPTEST=expr, BCMD_DISKREAD=expr, BCMD_DISKWRITE=expr, BCMD_MEMREAD=expr, BCMD_MEMWRITE=expr, BCMD_MEMEXEC=expr, BCMD_MOUNT=expr, BCMD_GETMOUNT_STATUS=expr }

variable_types:
start
unsigned long long

variable_types:
count
unsigned int

variable_types:
data
void *

variable_types:
datasize
unsigned int

variable_types: struct bootdisk_cmd_header { unsigned short magic; unsigned short cmd; unsigned int param1; unsigned long start; unsigned int count; unsigned int datasize; }


decompiled_code:
void __fastcall get_response_data(__int64 a1, unsigned int a2)
{
__int64 v3; // rcx
unsigned int v4; // eax
bool v5; // zf
int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( dword_E34 != a2 )
{
puts("error: data size to receive doesn't match expected");
exit(1);
}
v3 = a2;
if ( a2 )
{
do
{
v4 = libusb_bulk_transfer(usb, 129LL, a1, v3, v6, 0LL);
if ( v4 )
{
printf("read error: status=%d\n", v4);
exit(1);
}
a1 += v6[0];
v5 = dword_E34 == v6[0];
v3 = (unsigned int)(dword_E34 - v6[0]);
dword_E34 -= v6[0];
}
while ( !v5 );
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, unsigned int a2)
{
__int64 v3; // rcx
unsigned int v4; // eax
bool v5; // zf
int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( dword_E34 != a2 )
{
puts("error: data size to receive doesn't match expected");
exit(1);
}
v3 = a2;
if ( a2 )
{
do
{
v4 = libusb_bulk_transfer(usb, 129LL, a1, v3, v6, 0LL);
if ( v4 )
{
printf("read error: status=%d\n", v4);
exit(1);
}
a1 += v6[0];
v5 = dword_E34 == v6[0];
v3 = (unsigned int)(dword_E34 - v6[0]);
dword_E34 -= v6[0];
}
while ( !v5 );
}
}

original_code:
void get_response_data(void *buf, unsigned bufsize)
{
    int status, transferred;
    if( bufsize != cur_resp_header.datasize ) {
        printf("error: data size to receive doesn't match expected\n");
        exit(1);
    }
    while( cur_resp_header.datasize > 0 ) {
        if( (status = libusb_bulk_transfer(usb, 1 | LIBUSB_ENDPOINT_IN,
                buf, cur_resp_header.datasize, &transferred, 0)) != 0)
        {
            printf("read error: status=%d\n", status);
            exit(1);
        }
        buf += transferred;
        cur_resp_header.datasize -= transferred;
    }
}

canonical_original_code:
void get_response_data(void *buf, unsigned int bufsize)
{
    int status; int transferred;
    if( bufsize != cur_resp_header.datasize ) {
        printf("error: data size to receive doesn't match expected\n");
        exit(1);
    }
    while( cur_resp_header.datasize > 0 ) {
        if( (status = libusb_bulk_transfer(usb, 1 | LIBUSB_ENDPOINT_IN,
                buf, cur_resp_header.datasize, &transferred, 0)) != 0)
        {
            printf("read error: status=%d\n", status);
            exit(1);
        }
        buf += transferred;
        cur_resp_header.datasize -= transferred;
    }
}

variable_types:
buf
void *

variable_types:
bufsize
unsigned int


decompiled_code:
void __fastcall read_disk(unsigned int a1, __int64 a2, unsigned int a3, __int64 a4)
{
send_command(0x52u, a1, a2, a3, 0LL, 0);
get_response_data(a4, a3 << 9);
}

canonical_decompiled_code:
void __fastcall func6(unsigned int a1, __int64 a2, unsigned int a3, __int64 a4)
{
func4(0x52u, a1, a2, a3, 0LL, 0);
func5(a4, a3 << 9);
}

original_code:
void read_disk(enum FlashMemoryArea fmarea,
        unsigned long long firstSector,
        unsigned long long count, void *rdbuf)
{
    send_command(BCMD_DISKREAD, fmarea, firstSector, count, ((void *)0), 0);
    get_response_data(rdbuf, count * 512);
}

variable_types: enum FlashMemoryArea { FMAREA_BOOT0=0, FMAREA_BOOT1=1, FMAREA_PHYDISK=2, FMAREA_LOGDISK=3, FMAREA_COUNT=4 }

variable_types:
firstSector
unsigned long long

variable_types:
count
unsigned long long

variable_types:
rdbuf
void *