decompiled_code:
void __noreturn do_start()
{
__int64 v0; // rax
int v1; // ebx
__int64 v2; // rbp
void *v3; // rax
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax
struct pollfd v8; // [rsp+0h] [rbp-28h] BYREF
int v9; // [rsp+8h] [rbp-20h]
__int16 v10; // [rsp+Ch] [rbp-1Ch]
__int16 v11; // [rsp+Eh] [rbp-1Ah]

v0 = perf_ctrs;
if ( perf_ctrs )
{
*(_BYTE *)(perf_ctrs + 40LL) |= 1u;
*(_BYTE *)(v0 + 41) |= 0x10u;
}
v1 = create_sig_fd();
exec_pid = ctrs_execvp_cb(
&perf_ctrs,
(unsigned int)monitor_cpu,
0LL,
setup_child,
0LL,
*(_QWORD *)exec_argv,
exec_argv);
if ( exec_pid != -1 )
{
v2 = page_size;
v3 = mmap(0LL, 17 * page_size, 3, 1, *(_DWORD *)(perf_ctrs + 112LL), 0LL);
perf_header = (__int64)v3;
if ( v3 != (void *)-1LL )
{
perf_buf = (__int64)v3 + v2;
while ( 1 )
{
v8.fd = *(_DWORD *)(perf_ctrs + 112LL);
v8.events = 1;
v8.revents = 0;
v9 = v1;
v10 = 1;
v11 = 0;
if ( poll(&v8, 2uLL, -1) == -1 )
break;
if ( (v8.revents & 1) != 0 )
dump_events();
if ( (v11 & 1) != 0 )
handle_signal(v1);
}
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "%s:%i: %s\n %s\n", "perfrecord.c", 317LL, "poll(pfd, 2, -1) != -1", v7);
abort();
}
v4 = _errno_location();
v5 = strerror(*v4);
fprintf(stderr, "%s:%i: %s\n %s\n", "perfrecord.c", 306LL, "perf_header != MAP_FAILED", v5);
abort();
}
fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 299LL, "exec_pid != -1");
abort();
}

canonical_decompiled_code:
void __noreturn func9()
{
__int64 v0; // rax
int v1; // ebx
__int64 v2; // rbp
void *v3; // rax
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax
struct pollfd v8; // [rsp+0h] [rbp-28h] BYREF
int v9; // [rsp+8h] [rbp-20h]
__int16 v10; // [rsp+Ch] [rbp-1Ch]
__int16 v11; // [rsp+Eh] [rbp-1Ah]

v0 = perf_ctrs;
if ( perf_ctrs )
{
*(_BYTE *)(perf_ctrs + 40LL) |= 1u;
*(_BYTE *)(v0 + 41) |= 0x10u;
}
v1 = func3();
exec_pid = ctrs_execvp_cb(
&perf_ctrs,
(unsigned int)monitor_cpu,
0LL,
setup_child,
0LL,
*(_QWORD *)exec_argv,
exec_argv);
if ( exec_pid != -1 )
{
v2 = page_size;
v3 = mmap(0LL, 17 * page_size, 3, 1, *(_DWORD *)(perf_ctrs + 112LL), 0LL);
perf_header = (__int64)v3;
if ( v3 != (void *)-1LL )
{
perf_buf = (__int64)v3 + v2;
while ( 1 )
{
v8.fd = *(_DWORD *)(perf_ctrs + 112LL);
v8.events = 1;
v8.revents = 0;
v9 = v1;
v10 = 1;
v11 = 0;
if ( poll(&v8, 2uLL, -1) == -1 )
break;
if ( (v8.revents & 1) != 0 )
func7();
if ( (v11 & 1) != 0 )
func8(v1);
}
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "%s:%i: %s\n %s\n", "perfrecord.c", 317LL, "poll(pfd, 2, -1) != -1", v7);
abort();
}
v4 = _errno_location();
v5 = strerror(*v4);
fprintf(stderr, "%s:%i: %s\n %s\n", "perfrecord.c", 306LL, "perf_header != MAP_FAILED", v5);
abort();
}
fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 299LL, "exec_pid != -1");
abort();
}

original_code:
static void
do_start()
{
    int sfd;
    if (perf_ctrs.head) {
        perf_ctrs.head->attr.disabled = 1;
        perf_ctrs.head->attr.enable_on_exec = 1;
    }
    sfd = create_sig_fd();
    exec_pid = ctrs_execvp_cb(&perf_ctrs, monitor_cpu , 0 ,
                              &setup_child, ((void *)0),
                              exec_argv[0], exec_argv);
    do { if (!(exec_pid != -1)) { fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 299, "exec_pid != -1"); abort(); } } while (0);
    perf_header = mmap(((void *)0),
                       page_size * 17,
                       0x1 | 0x2,
                       0x01,
                       perf_ctrs.head->fd, 0);
    do { if (!(perf_header != ((void *) -1))) { fprintf(stderr, "%s:%i: %s\n  %s\n", "perfrecord.c", 306, "perf_header != MAP_FAILED", strerror((*__errno_location ()))); abort(); } } while (0);
    perf_buf = (void *)((char *)perf_header + page_size);
    while (1) {
        struct pollfd pfd[] = {
            { perf_ctrs.head->fd, 0x001, 0 },
            { sfd, 0x001, 0 }
        };
        do { if (!(poll(pfd, 2, -1) != -1)) { fprintf(stderr, "%s:%i: %s\n  %s\n", "perfrecord.c", 317, "poll(pfd, 2, -1) != -1", strerror((*__errno_location ()))); abort(); } } while (0);
        if (pfd[0].revents & 0x001)
            dump_events();
        if (pfd[1].revents & 0x001)
            handle_signal(sfd);
    }
}

variable_types: struct pollfd { int fd; short events; short revents; } []


decompiled_code:
void __noreturn do_attach()
{
int v0; // ebx
__int64 v1; // rbp
void *v2; // rax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
struct pollfd v7; // [rsp+0h] [rbp-28h] BYREF
int v8; // [rsp+8h] [rbp-20h]
__int16 v9; // [rsp+Ch] [rbp-1Ch]
__int16 v10; // [rsp+Eh] [rbp-1Ah]

v0 = create_sig_fd();
printf("Attaching to PID %i.\n", (unsigned int)attach_pid);
if ( (unsigned int)ctrs_attach(&perf_ctrs, (unsigned int)attach_pid, (unsigned int)monitor_cpu, 0LL) != -1 )
{
v1 = page_size;
v2 = mmap(0LL, 17 * page_size, 3, 1, *(_DWORD *)(perf_ctrs + 112LL), 0LL);
perf_header = (__int64)v2;
if ( v2 != (void *)-1LL )
{
perf_buf = (__int64)v2 + v1;
while ( 1 )
{
v7.fd = *(_DWORD *)(perf_ctrs + 112LL);
v7.events = 1;
v7.revents = 0;
v8 = v0;
v9 = 1;
v10 = 0;
if ( poll(&v7, 2uLL, -1) == -1 )
break;
if ( (v7.revents & 1) != 0 )
dump_events();
if ( (v10 & 1) != 0 )
handle_signal(v0);
}
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "%s:%i: %s\n %s\n", "perfrecord.c", 258LL, "poll(pfd, 2, -1) != -1", v6);
abort();
}
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "%s:%i: %s\n %s\n", "perfrecord.c", 247LL, "perf_header != MAP_FAILED", v4);
abort();
}
exit(1);
}

canonical_decompiled_code:
void __noreturn func10()
{
int v0; // ebx
__int64 v1; // rbp
void *v2; // rax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
struct pollfd v7; // [rsp+0h] [rbp-28h] BYREF
int v8; // [rsp+8h] [rbp-20h]
__int16 v9; // [rsp+Ch] [rbp-1Ch]
__int16 v10; // [rsp+Eh] [rbp-1Ah]

v0 = func3();
printf("Attaching to PID %i.\n", (unsigned int)attach_pid);
if ( (unsigned int)ctrs_attach(&perf_ctrs, (unsigned int)attach_pid, (unsigned int)monitor_cpu, 0LL) != -1 )
{
v1 = page_size;
v2 = mmap(0LL, 17 * page_size, 3, 1, *(_DWORD *)(perf_ctrs + 112LL), 0LL);
perf_header = (__int64)v2;
if ( v2 != (void *)-1LL )
{
perf_buf = (__int64)v2 + v1;
while ( 1 )
{
v7.fd = *(_DWORD *)(perf_ctrs + 112LL);
v7.events = 1;
v7.revents = 0;
v8 = v0;
v9 = 1;
v10 = 0;
if ( poll(&v7, 2uLL, -1) == -1 )
break;
if ( (v7.revents & 1) != 0 )
func7();
if ( (v10 & 1) != 0 )
func8(v0);
}
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "%s:%i: %s\n %s\n", "perfrecord.c", 258LL, "poll(pfd, 2, -1) != -1", v6);
abort();
}
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "%s:%i: %s\n %s\n", "perfrecord.c", 247LL, "perf_header != MAP_FAILED", v4);
abort();
}
exit(1);
}

original_code:
static void
do_attach()
{
    int sfd;
    sfd = create_sig_fd();
    printf("Attaching to PID %i.\n", attach_pid);
    if (ctrs_attach(&perf_ctrs, attach_pid, monitor_cpu, 0 ) == -1)
        exit(1);
    perf_header = mmap(((void *)0),
                       page_size * 17,
                       0x1 | 0x2,
                       0x01,
                       perf_ctrs.head->fd, 0);
    do { if (!(perf_header != ((void *) -1))) { fprintf(stderr, "%s:%i: %s\n  %s\n", "perfrecord.c", 247, "perf_header != MAP_FAILED", strerror((*__errno_location ()))); abort(); } } while (0);
    perf_buf = (void *)((char *)perf_header + page_size);
    while (1) {
        struct pollfd pfd[] = {
            { perf_ctrs.head->fd, 0x001, 0 },
            { sfd, 0x001, 0 }
        };
        do { if (!(poll(pfd, 2, -1) != -1)) { fprintf(stderr, "%s:%i: %s\n  %s\n", "perfrecord.c", 258, "poll(pfd, 2, -1) != -1", strerror((*__errno_location ()))); abort(); } } while (0);
        if (pfd[0].revents & 0x001)
            dump_events();
        if (pfd[1].revents & 0x001)
            handle_signal(sfd);
    }
}

variable_types: sfd int

return_type: void

user_defined_types: struct pollfd { int fd; short events; short revents; }


main

canonical_name: main

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

perf_base_attr[3] = 149LL;
perf_base_attr[4] = 12LL;
argp_parse(&argp, argc, (char **)argv, 8u, 0LL, 0LL);
page_size = sysconf(30);
buf_mask = 16 * page_size - 1;
if ( page_size != -1 )
{
if ( (unsigned int)ctrs_write_header(&perf_ctrs, output) == 1 )
{
if ( exec_argv )
do_start();
do_attach();
}
fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 441LL, "ctrs_write_header(&perf_ctrs, output) == 1");
abort();
}
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "%s:%i: %s\n %s\n", "perfrecord.c", 439LL, "page_size != -1", v4);
abort();
}

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

perf_base_attr[3] = 149LL;
perf_base_attr[4] = 12LL;
argp_parse(&argp, argc, (char **)argv, 8u, 0LL, 0LL);
page_size = sysconf(30);
buf_mask = 16 * page_size - 1;
if ( page_size != -1 )
{
if ( (unsigned int)ctrs_write_header(&perf_ctrs, output) == 1 )
{
if ( exec_argv )
func9();
func10();
}
fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 441LL, "ctrs_write_header(&perf_ctrs, output) == 1");
abort();
}
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "%s:%i: %s\n %s\n", "perfrecord.c", 439LL, "page_size != -1", v4);
abort();
}

original_code:
int
main(int argc, char **argv)
{
    perf_base_attr.sample_type =
        PERF_SAMPLE_IP | PERF_SAMPLE_TIME | PERF_SAMPLE_CPU | PERF_SAMPLE_READ;
    perf_base_attr.read_format =
        PERF_FORMAT_ID | PERF_FORMAT_GROUP;
    argp_parse (&argp, argc, argv,
                0x08,
                0,
                ((void *)0));
    page_size = sysconf(_SC_PAGESIZE);
    buf_mask = page_size * (17 - 1) - 1;
    do { if (!(page_size != -1)) { fprintf(stderr, "%s:%i: %s\n  %s\n", "perfrecord.c", 439, "page_size != -1", strerror((*__errno_location ()))); abort(); } } while (0);
    do { if (!(ctrs_write_header(&perf_ctrs, output) == 1)) { fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 441, "ctrs_write_header(&perf_ctrs, output) == 1"); abort(); } } while (0);
    if (exec_argv)
        do_start();
    else
        do_attach();
    exit(0);
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


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

result = (char *)dumper + 24;
if ( !*((_QWORD *)dumper + 4) )
return (char *)dumper + 8;
while ( *(_DWORD *)result != a1 )
{
result += 16;
if ( !*((_QWORD *)result + 1) )
return (char *)dumper + 8;
}
return result;
}

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

result = (char *)dumper + 24;
if ( !*((_QWORD *)dumper + 4) )
return (char *)dumper + 8;
while ( *(_DWORD *)result != a1 )
{
result += 16;
if ( !*((_QWORD *)result + 1) )
return (char *)dumper + 8;
}
return result;
}

original_code:
static event_dumper_t *
find_dumper(uint32_t type)
{
    for (event_dumper_t *ed = dumper->events; ed->f; ed++)
        if (ed->type == type)
            return ed;
    return &dumper->event_unknown;
}

canonical_original_code:
static struct event_dumper_t *find_dumper(unsigned int type)
{
    for (struct event_dumper_t *ed = dumper->events; ed->f; ed++)
        if (ed->type == type)
            return ed;
    return &dumper->event_unknown;
}

variable_types:
type
unsigned int

variable_types: struct event_dumper_t { unsigned int type; void (*f)(void *data, unsigned int type, unsigned short misc, unsigned short size); } *


decompiled_code:
__int64 dump_event()
{
unsigned int v0; // ebx
char *v1; // rax
_BYTE v3[65544]; // [rsp+0h] [rbp-10018h] BYREF
unsigned int ptr; // [rsp+10008h] [rbp-10h] BYREF
unsigned __int16 v5; // [rsp+1000Ch] [rbp-Ch]
unsigned __int16 v6; // [rsp+1000Eh] [rbp-Ah]

if ( fread(&ptr, 8uLL, 1uLL, input) != 1 )
return 0xFFFFFFFFLL;
if ( v6 <= 7u )
_assert_fail("hdr.size >= sizeof(hdr)", "perfdump.c", 0x4Du, "dump_event");
if ( fread(v3, v6 - 8LL, 1uLL, input) != 1 )
return 0xFFFFFFFFLL;
v0 = ptr;
v1 = find_dumper(ptr);
(*((void (__fastcall **)(_BYTE *, _QWORD, _QWORD, _QWORD))v1 + 1))(v3, v0, v5, (unsigned __int16)(v6 - 8));
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx
char *v1; // rax
_BYTE v3[65544]; // [rsp+0h] [rbp-10018h] BYREF
unsigned int ptr; // [rsp+10008h] [rbp-10h] BYREF
unsigned __int16 v5; // [rsp+1000Ch] [rbp-Ch]
unsigned __int16 v6; // [rsp+1000Eh] [rbp-Ah]

if ( fread(&ptr, 8uLL, 1uLL, input) != 1 )
return 0xFFFFFFFFLL;
if ( v6 <= 7u )
_assert_fail("hdr.size >= sizeof(hdr)", "perfdump.c", 0x4Du, "dump_event");
if ( fread(v3, v6 - 8LL, 1uLL, input) != 1 )
return 0xFFFFFFFFLL;
v0 = ptr;
v1 = func0(ptr);
(*((void (__fastcall **)(_BYTE *, _QWORD, _QWORD, _QWORD))v1 + 1))(v3, v0, v5, (unsigned __int16)(v6 - 8));
return 0LL;
}

original_code:
static int
dump_event()
{
    struct perf_event_header hdr;
    event_dumper_t *dumper;
    char data[0xFFFF];
    if (fread(&hdr, sizeof(hdr), 1, input) != 1)
        return -1;
    ((void) sizeof ((hdr.size >= sizeof(hdr)) ? 1 : 0), __extension__ ({ if (hdr.size >= sizeof(hdr)) ; else __assert_fail ("hdr.size >= sizeof(hdr)", "perfdump.c", 77, __extension__ __PRETTY_FUNCTION__); }));
    if (fread(data, hdr.size - sizeof(hdr), 1, input) != 1)
        return -1;
    dumper = find_dumper(hdr.type);
    dumper->f(data, hdr.type, hdr.misc, hdr.size - sizeof(hdr));
    return 0;
}

canonical_original_code:
static int dump_event()
{
    struct perf_event_header hdr;
    struct event_dumper_t *dumper;
    char data[65535];
    if (fread(&hdr, sizeof(hdr), 1, input) != 1)
        return -1;
    ((void) sizeof ((hdr.size >= sizeof(hdr)) ? 1 : 0), __extension__ ({ if (hdr.size >= sizeof(hdr)) ; else __assert_fail ("hdr.size >= sizeof(hdr)", "perfdump.c", 77, __extension__ __PRETTY_FUNCTION__); }));
    if (fread(data, hdr.size - sizeof(hdr), 1, input) != 1)
        return -1;
    dumper = find_dumper(hdr.type);
    dumper->f(data, hdr.type, hdr.misc, hdr.size - sizeof(hdr));
    return 0;
}

variable_types: struct perf_event_header { unsigned int type; unsigned short misc; unsigned short size; }

variable_types:
data
char [65535]

user_defined_types: struct event_dumper_t { unsigned int type; void (*f)(void *data, unsigned int type, unsigned short misc, unsigned short size); }


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

while ( (unsigned int)dump_event() != -1 )
;
result = ferror(input);
if ( result )
{
perror("Failed to read events");
exit(1);
}
return result;
}

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

while ( (unsigned int)func2() != -1 )
;
result = ferror(input);
if ( result )
{
perror("Failed to read events");
exit(1);
}
return result;
}

original_code:
static void
dump_events()
{
    while (dump_event() != -1)
        ;
    if (ferror(input)) {
        perror("Failed to read events");
        exit(1);
    }
}


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
argp_parse(&argp, argc, (char **)argv, 8u, 0LL, 0LL);
if ( (unsigned int)ctrs_read_header(&ctrs, input) == 1 )
{
if ( ctrs )
{
(*(void (__fastcall **)(__int64 *, __int64 *))dumper)(&ctrs, &conf);
dump_events();
exit(0);
}
fprintf(stderr, "%s:%i: %s\n", "perfdump.c", 192LL, "ctrs.head");
abort();
}
fprintf(stderr, "%s:%i: %s\n", "perfdump.c", 191LL, "ctrs_read_header(&ctrs, input) == 1");
abort();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
argp_parse(&argp, argc, (char **)argv, 8u, 0LL, 0LL);
if ( (unsigned int)ctrs_read_header(&ctrs, input) == 1 )
{
if ( ctrs )
{
(*(void (__fastcall **)(__int64 *, __int64 *))dumper)(&ctrs, &conf);
func3();
exit(0);
}
fprintf(stderr, "%s:%i: %s\n", "perfdump.c", 192LL, "ctrs.head");
abort();
}
fprintf(stderr, "%s:%i: %s\n", "perfdump.c", 191LL, "ctrs_read_header(&ctrs, input) == 1");
abort();
}

original_code:
int
main(int argc, char **argv)
{
    argp_parse (&argp, argc, argv,
                0x08,
                0,
                ((void *)0));
    do { if (!(ctrs_read_header(&ctrs, input) == 1)) { fprintf(stderr, "%s:%i: %s\n", "perfdump.c", 191, "ctrs_read_header(&ctrs, input) == 1"); abort(); } } while (0);
    do { if (!(ctrs.head)) { fprintf(stderr, "%s:%i: %s\n", "perfdump.c", 192, "ctrs.head"); abort(); } } while (0);
    dumper->init(&ctrs, &conf);
    dump_events();
    exit(0);
}


decompiled_code:
__int64 __fastcall read_uint32_t(unsigned int **a1, _WORD *a2)
{
unsigned int *v2; // rax

if ( *a2 <= 3u )
_assert_fail("*size >= sizeof(uint32_t)", "dumpers.h", 0x52u, "read_uint32_t");
*a2 -= 4;
v2 = (*a1)++;
return *v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int **a1, _WORD *a2)
{
unsigned int *v2; // rax

if ( *a2 <= 3u )
_assert_fail("*size >= sizeof(uint32_t)", "dumpers.h", 0x52u, "read_uint32_t");
*a2 -= 4;
v2 = (*a1)++;
return *v2;
}

original_code: static inline uint32_t read_uint32_t(void **data, uint16_t *size) { ((void) sizeof ((*size >= sizeof(uint32_t)) ? 1 : 0), __extension__ ({ if (*size >= sizeof(uint32_t)) ; else __assert_fail ("*size >= sizeof(uint32_t)", "dumpers.h", 82, __extension__ __PRETTY_FUNCTION__); })); *size -= sizeof(uint32_t); return *(*(uint32_t **)data)++; }

canonical_original_code: static inline unsigned int read_uint32_t(void **data, unsigned short *size) { ((void) sizeof ((*size >= sizeof(unsigned int)) ? 1 : 0), __extension__ ({ if (*size >= sizeof(unsigned int)) ; else __assert_fail ("*size >= sizeof(uint32_t)", "dumpers.h", 82, __extension__ __PRETTY_FUNCTION__); })); *size -= sizeof(unsigned int); return *(*(unsigned int **)data)++; }

variable_types:
data
void **

variable_types:
size
unsigned short *

return_type: unsigned int


decompiled_code:
__int64 __fastcall read_uint64_t(__int64 *a1, _WORD *a2)
{
__int64 v2; // rax

if ( *a2 <= 7u )
_assert_fail("*size >= sizeof(uint64_t)", "dumpers.h", 0x51u, "read_uint64_t");
*a2 -= 8;
v2 = *a1;
*a1 += 8LL;
return *(_QWORD *)v2;
}

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

if ( *a2 <= 7u )
_assert_fail("*size >= sizeof(uint64_t)", "dumpers.h", 0x51u, "read_uint64_t");
*a2 -= 8;
v2 = *a1;
*a1 += 8LL;
return *(_QWORD *)v2;
}

original_code: static inline uint64_t read_uint64_t(void **data, uint16_t *size) { ((void) sizeof ((*size >= sizeof(uint64_t)) ? 1 : 0), __extension__ ({ if (*size >= sizeof(uint64_t)) ; else __assert_fail ("*size >= sizeof(uint64_t)", "dumpers.h", 81, __extension__ __PRETTY_FUNCTION__); })); *size -= sizeof(uint64_t); return *(*(uint64_t **)data)++; }

canonical_original_code: static inline unsigned long read_uint64_t(void **data, unsigned short *size) { ((void) sizeof ((*size >= sizeof(unsigned long)) ? 1 : 0), __extension__ ({ if (*size >= sizeof(unsigned long)) ; else __assert_fail ("*size >= sizeof(uint64_t)", "dumpers.h", 81, __extension__ __PRETTY_FUNCTION__); })); *size -= sizeof(unsigned long); return *(*(unsigned long **)data)++; }

return_type: unsigned long


decompiled_code:
int dump_printf(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(conf, format, arg);
}

canonical_decompiled_code:
int func2(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(conf, format, arg);
}

original_code:
static void
dump_printf(const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    vfprintf(conf.output, fmt, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
static void dump_printf(char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    vfprintf(conf.output, fmt, ap);
    __builtin_va_end(ap);
}

variable_types:
fmt
char *


decompiled_code:
int __fastcall dump_PERF_RECORD_SAMPLE(unsigned int *a1, __int64 a2, __int64 a3, __int16 a4)
{
__int64 v4; // rbx
int result; // eax
__int64 v6; // rax
unsigned int v7; // ebp
unsigned int v8; // eax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
unsigned int v13; // ebp
unsigned int v14; // eax
__int64 v15; // rax
__int64 v16; // r12
__int64 i; // rbp
__int64 v18; // rax
__int16 v19[2]; // [rsp+4h] [rbp-24h] BYREF
unsigned int *v20[4]; // [rsp+8h] [rbp-20h] BYREF

v20[0] = a1;
v19[0] = a4;
v4 = *(_QWORD *)(attr + 24);
result = dump_printf("[SAMPLE]\n");
if ( (v4 & 1) != 0 )
{
v6 = read_uint64_t((__int64 *)v20, v19);
result = dump_printf(" IP: 0x%lx\n", v6);
}
if ( (v4 & 2) != 0 )
{
v7 = read_uint32_t(v20, v19);
v8 = read_uint32_t(v20, v19);
result = dump_printf(" PID: %u TID: %u\n", v7, v8);
}
if ( (v4 & 4) != 0 )
{
v9 = read_uint64_t((__int64 *)v20, v19);
result = dump_printf(" TIME: %lu\n", v9);
}
if ( (v4 & 8) != 0 )
{
v10 = read_uint64_t((__int64 *)v20, v19);
result = dump_printf(" ADDR: 0x%lx\n", v10);
}
if ( (v4 & 0x40) != 0 )
{
v11 = read_uint64_t((__int64 *)v20, v19);
result = dump_printf(" ID: %lu\n", v11);
}
if ( (v4 & 0x200) != 0 )
{
v12 = read_uint64_t((__int64 *)v20, v19);
result = dump_printf(" STREAM_ID: %lu\n", v12);
}
if ( (v4 & 0x80u) != 0LL )
{
v13 = read_uint32_t(v20, v19);
v14 = read_uint32_t(v20, v19);
result = dump_printf(" CPU: %u RES: %u\n", v13, v14);
}
if ( (v4 & 0x100) != 0 )
{
v15 = read_uint64_t((__int64 *)v20, v19);
result = dump_printf(" PERIOD: %lu\n", v15);
}
if ( (v4 & 0x10) != 0 )
result = dump_read_format((__int64 *)v20, v19, attr);
if ( (v4 & 0x20) != 0 )
{
v16 = read_uint64_t((__int64 *)v20, v19);
dump_printf(" Call Chain:");
if ( v16 )
{
for ( i = 0LL; i != v16; ++i )
{
v18 = read_uint64_t((__int64 *)v20, v19);
dump_printf(" 0x%lx", v18);
}
}
result = dump_printf("\n");
}
if ( (v4 & 0x400) != 0 )
result = dump_printf(" Raw Sample - Unhandled\n");
return result;
}

original_code:
static void dump_PERF_RECORD_SAMPLE (void *data, uint32_t type, uint16_t misc, uint16_t size)
{
    const uint64_t sample_type = attr->sample_type;
    dump_printf("[SAMPLE]\n");
    if (sample_type & PERF_SAMPLE_IP)
        dump_printf("  IP: 0x%" "l" "x" "\n", read_uint64_t(&data, &size));
    if (sample_type & PERF_SAMPLE_TID) {
        uint32_t pid = read_uint32_t(&data, &size);
        uint32_t tid = read_uint32_t(&data, &size);
        dump_printf("  PID: %" "u" " TID: %" "u" "\n", pid, tid);
    }
    if (sample_type & PERF_SAMPLE_TIME)
        dump_printf("  TIME: %" "l" "u" "\n", read_uint64_t(&data, &size));
    if (sample_type & PERF_SAMPLE_ADDR)
        dump_printf("  ADDR: 0x%" "l" "x" "\n", read_uint64_t(&data, &size));
    if (sample_type & PERF_SAMPLE_ID)
        dump_printf("  ID: %" "l" "u" "\n", read_uint64_t(&data, &size));
    if (sample_type & PERF_SAMPLE_STREAM_ID)
        dump_printf("  STREAM_ID: %" "l" "u" "\n", read_uint64_t(&data, &size));
    if (sample_type & PERF_SAMPLE_CPU) {
        uint32_t cpu = read_uint32_t(&data, &size);
        uint32_t res = read_uint32_t(&data, &size);
        dump_printf("  CPU: %" "u" " RES: %" "u" "\n", cpu, res);
    }
    if (sample_type & PERF_SAMPLE_PERIOD)
        dump_printf("  PERIOD: %" "l" "u" "\n", read_uint64_t(&data, &size));
    if (sample_type & PERF_SAMPLE_READ)
        dump_read_format(&data, &size, attr);
    if (sample_type & PERF_SAMPLE_CALLCHAIN) {
        uint64_t nr = read_uint64_t(&data, &size);
        dump_printf("  Call Chain:");
        for (int i = 0; i < nr; i++)
            dump_printf(" 0x%" "l" "x", read_uint64_t(&data, &size));
        dump_printf("\n");
    }
    if (sample_type & PERF_SAMPLE_RAW)
        dump_printf("  Raw Sample - Unhandled\n");
}

canonical_original_code:
static void dump_PERF_RECORD_SAMPLE(void *data, unsigned int type, unsigned short misc, unsigned short size)
{
    unsigned long sample_type = attr->sample_type;
    dump_printf("[SAMPLE]\n");
    if (sample_type & PERF_SAMPLE_IP)
        dump_printf("  IP: 0x%" "l" "x" "\n", read_uint64_t(&data, &size));
    if (sample_type & PERF_SAMPLE_TID) {
        unsigned int pid = read_uint32_t(&data, &size);
        unsigned int tid = read_uint32_t(&data, &size);
        dump_printf("  PID: %" "u" " TID: %" "u" "\n", pid, tid);
    }
    if (sample_type & PERF_SAMPLE_TIME)
        dump_printf("  TIME: %" "l" "u" "\n", read_uint64_t(&data, &size));
    if (sample_type & PERF_SAMPLE_ADDR)
        dump_printf("  ADDR: 0x%" "l" "x" "\n", read_uint64_t(&data, &size));
    if (sample_type & PERF_SAMPLE_ID)
        dump_printf("  ID: %" "l" "u" "\n", read_uint64_t(&data, &size));
    if (sample_type & PERF_SAMPLE_STREAM_ID)
        dump_printf("  STREAM_ID: %" "l" "u" "\n", read_uint64_t(&data, &size));
    if (sample_type & PERF_SAMPLE_CPU) {
        unsigned int cpu = read_uint32_t(&data, &size);
        unsigned int res = read_uint32_t(&data, &size);
        dump_printf("  CPU: %" "u" " RES: %" "u" "\n", cpu, res);
    }
    if (sample_type & PERF_SAMPLE_PERIOD)
        dump_printf("  PERIOD: %" "l" "u" "\n", read_uint64_t(&data, &size));
    if (sample_type & PERF_SAMPLE_READ)
        dump_read_format(&data, &size, attr);
    if (sample_type & PERF_SAMPLE_CALLCHAIN) {
        unsigned long nr = read_uint64_t(&data, &size);
        dump_printf("  Call Chain:");
        for (int i = 0; i < nr; i++)
            dump_printf(" 0x%" "l" "x", read_uint64_t(&data, &size));
        dump_printf("\n");
    }
    if (sample_type & PERF_SAMPLE_RAW)
        dump_printf("  Raw Sample - Unhandled\n");
}

variable_types:
data
void *

variable_types:
misc
unsigned short

variable_types:
size
unsigned short

variable_types:
pid
unsigned int

variable_types:
tid
unsigned int

variable_types:
cpu
unsigned int

variable_types:
res
unsigned int

variable_types:
nr
unsigned long

variable_types: i int


decompiled_code:
int __fastcall dump_PERF_RECORD_READ(unsigned int *a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
__int16 v5; // [rsp+6h] [rbp-12h] BYREF
unsigned int *v6; // [rsp+8h] [rbp-10h] BYREF

if ( a4 <= 7u )
_assert_fail("size >= sizeof(perf_record_read_t)", "dumper_dump.c", 0xA8u, "dump_PERF_RECORD_READ");
v6 = a1 + 2;
v5 = a4 - 8;
dump_printf("[READ] pid: %u tid: %u", *a1, a1[1]);
return dump_read_format((__int64 *)&v6, &v5, attr);
}

canonical_decompiled_code:
int __fastcall func5(unsigned int *a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
__int16 v5; // [rsp+6h] [rbp-12h] BYREF
unsigned int *v6; // [rsp+8h] [rbp-10h] BYREF

if ( a4 <= 7u )
_assert_fail("size >= sizeof(perf_record_read_t)", "dumper_dump.c", 0xA8u, "dump_PERF_RECORD_READ");
v6 = a1 + 2;
v5 = a4 - 8;
func2("[READ] pid: %u tid: %u", *a1, a1[1]);
return func3((__int64 *)&v6, &v5, attr);
}

original_code:
static void dump_PERF_RECORD_READ (void *data, uint32_t type, uint16_t misc, uint16_t size)
{
    ((void) sizeof ((size >= sizeof(perf_record_read_t)) ? 1 : 0), __extension__ ({ if (size >= sizeof(perf_record_read_t)) ; else __assert_fail ("size >= sizeof(perf_record_read_t)", "dumper_dump.c", 168, __extension__ __PRETTY_FUNCTION__); }));
    perf_record_read_t *rec = (perf_record_read_t *)data;
    void *read_data = (void *)rec->data;
    uint16_t data_size = size - sizeof(perf_record_read_t);
    dump_printf("[READ] pid: %" "u" " tid: %" "u",
                rec->pid, rec->tid);
    dump_read_format(&read_data, &data_size, attr);
}

canonical_original_code:
static void dump_PERF_RECORD_READ(void *data, unsigned int type, unsigned short misc, unsigned short size)
{
    ((void) sizeof ((size >= sizeof(perf_record_read_t)) ? 1 : 0), __extension__ ({ if (size >= sizeof(perf_record_read_t)) ; else __assert_fail ("size >= sizeof(perf_record_read_t)", "dumper_dump.c", 168, __extension__ __PRETTY_FUNCTION__); }));
    struct perf_record_read_t *rec = (perf_record_read_t *)data;
    void *read_data = (void *)rec->data;
    unsigned short data_size = size - sizeof(perf_record_read_t);
    dump_printf("[READ] pid: %" "u" " tid: %" "u",
                rec->pid, rec->tid);
    dump_read_format(&read_data, &data_size, attr);
}

variable_types: struct perf_record_read_t { unsigned int pid; unsigned long data[]; } *


decompiled_code:
int __fastcall dump_PERF_RECORD_FORK(unsigned int *a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
if ( a4 <= 0x17u )
_assert_fail("size >= sizeof(perf_record_fork_t)", "dumper_dump.c", 0x7Eu, "dump_PERF_RECORD_FORK");
return dump_printf("[FORK] pid: %u tid: %u\n", *a1, a1[2]);
}

canonical_decompiled_code:
int __fastcall func6(unsigned int *a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
if ( a4 <= 0x17u )
_assert_fail("size >= sizeof(perf_record_fork_t)", "dumper_dump.c", 0x7Eu, "dump_PERF_RECORD_FORK");
return func2("[FORK] pid: %u tid: %u\n", *a1, a1[2]);
}

original_code:
static void dump_PERF_RECORD_FORK (void *data, uint32_t type, uint16_t misc, uint16_t size)
{
    ((void) sizeof ((size >= sizeof(perf_record_fork_t)) ? 1 : 0), __extension__ ({ if (size >= sizeof(perf_record_fork_t)) ; else __assert_fail ("size >= sizeof(perf_record_fork_t)", "dumper_dump.c", 126, __extension__ __PRETTY_FUNCTION__); }));
    perf_record_fork_t *rec = (perf_record_fork_t *)data;
    dump_printf("[FORK] pid: %" "u" " tid: %" "u" "\n",
                rec->pid, rec->tid);
}

canonical_original_code:
static void dump_PERF_RECORD_FORK(void *data, unsigned int type, unsigned short misc, unsigned short size)
{
    ((void) sizeof ((size >= sizeof(perf_record_fork_t)) ? 1 : 0), __extension__ ({ if (size >= sizeof(perf_record_fork_t)) ; else __assert_fail ("size >= sizeof(perf_record_fork_t)", "dumper_dump.c", 126, __extension__ __PRETTY_FUNCTION__); }));
    struct perf_record_fork_t *rec = (perf_record_fork_t *)data;
    dump_printf("[FORK] pid: %" "u" " tid: %" "u" "\n",
                rec->pid, rec->tid);
}

variable_types:
type
unsigned int

variable_types: struct perf_record_fork_t { unsigned int pid; unsigned int tid; unsigned long time; } *


decompiled_code:
int __fastcall dump_PERF_RECORD_UNTHROTTLE(_QWORD *a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
if ( a4 <= 0x17u )
_assert_fail("size >= sizeof(perf_record_unthrottle_t)", "dumper_dump.c", 0x74u, "dump_PERF_RECORD_UNTHROTTLE");
return dump_printf("[UNTHROTTLE] time: %lu id: %lu stream_id: %lu\n", *a1, a1[1], a1[2]);
}

canonical_decompiled_code:
int __fastcall func7(_QWORD *a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
if ( a4 <= 0x17u )
_assert_fail("size >= sizeof(perf_record_unthrottle_t)", "dumper_dump.c", 0x74u, "dump_PERF_RECORD_UNTHROTTLE");
return func2("[UNTHROTTLE] time: %lu id: %lu stream_id: %lu\n", *a1, a1[1], a1[2]);
}

original_code:
static void dump_PERF_RECORD_UNTHROTTLE (void *data, uint32_t type, uint16_t misc, uint16_t size)
{
    ((void) sizeof ((size >= sizeof(perf_record_unthrottle_t)) ? 1 : 0), __extension__ ({ if (size >= sizeof(perf_record_unthrottle_t)) ; else __assert_fail ("size >= sizeof(perf_record_unthrottle_t)", "dumper_dump.c", 116, __extension__ __PRETTY_FUNCTION__); }));
    perf_record_unthrottle_t *rec = (perf_record_unthrottle_t *)data;
    dump_printf("[UNTHROTTLE] time: %" "l" "u" " id: %" "l" "u"
                " stream_id: %" "l" "u" "\n",
                rec->time, rec->id, rec->stream_id);
}

canonical_original_code:
static void dump_PERF_RECORD_UNTHROTTLE(void *data, unsigned int type, unsigned short misc, unsigned short size)
{
    ((void) sizeof ((size >= sizeof(perf_record_unthrottle_t)) ? 1 : 0), __extension__ ({ if (size >= sizeof(perf_record_unthrottle_t)) ; else __assert_fail ("size >= sizeof(perf_record_unthrottle_t)", "dumper_dump.c", 116, __extension__ __PRETTY_FUNCTION__); }));
    struct perf_record_throttle_t *rec = (perf_record_unthrottle_t *)data;
    dump_printf("[UNTHROTTLE] time: %" "l" "u" " id: %" "l" "u"
                " stream_id: %" "l" "u" "\n",
                rec->time, rec->id, rec->stream_id);
}

variable_types: struct perf_record_throttle_t { unsigned long time; unsigned long id; unsigned long stream_id; } *


decompiled_code:
int __fastcall dump_PERF_RECORD_THROTTLE(_QWORD *a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
if ( a4 <= 0x17u )
_assert_fail("size >= sizeof(perf_record_throttle_t)", "dumper_dump.c", 0x6Au, "dump_PERF_RECORD_THROTTLE");
return dump_printf("[THROTTLE] time: %lu id: %lu stream_id: %lu\n", *a1, a1[1], a1[2]);
}

canonical_decompiled_code:
int __fastcall func8(_QWORD *a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
if ( a4 <= 0x17u )
_assert_fail("size >= sizeof(perf_record_throttle_t)", "dumper_dump.c", 0x6Au, "dump_PERF_RECORD_THROTTLE");
return func2("[THROTTLE] time: %lu id: %lu stream_id: %lu\n", *a1, a1[1], a1[2]);
}

original_code:
static void dump_PERF_RECORD_THROTTLE (void *data, uint32_t type, uint16_t misc, uint16_t size)
{
    ((void) sizeof ((size >= sizeof(perf_record_throttle_t)) ? 1 : 0), __extension__ ({ if (size >= sizeof(perf_record_throttle_t)) ; else __assert_fail ("size >= sizeof(perf_record_throttle_t)", "dumper_dump.c", 106, __extension__ __PRETTY_FUNCTION__); }));
    perf_record_throttle_t *rec = (perf_record_throttle_t *)data;
    dump_printf("[THROTTLE] time: %" "l" "u" " id: %" "l" "u"
                " stream_id: %" "l" "u" "\n",
                rec->time, rec->id, rec->stream_id);
}

canonical_original_code:
static void dump_PERF_RECORD_THROTTLE(void *data, unsigned int type, unsigned short misc, unsigned short size)
{
    ((void) sizeof ((size >= sizeof(perf_record_throttle_t)) ? 1 : 0), __extension__ ({ if (size >= sizeof(perf_record_throttle_t)) ; else __assert_fail ("size >= sizeof(perf_record_throttle_t)", "dumper_dump.c", 106, __extension__ __PRETTY_FUNCTION__); }));
    struct perf_record_throttle_t *rec = (perf_record_throttle_t *)data;
    dump_printf("[THROTTLE] time: %" "l" "u" " id: %" "l" "u"
                " stream_id: %" "l" "u" "\n",
                rec->time, rec->id, rec->stream_id);
}

user_defined_types: struct perf_record_throttle_t { unsigned long time; unsigned long id; unsigned long stream_id; }


decompiled_code:
int __fastcall dump_PERF_RECORD_EXIT(unsigned int *a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
if ( a4 <= 0x17u )
_assert_fail("size >= sizeof(perf_record_exit_t)", "dumper_dump.c", 0x5Fu, "dump_PERF_RECORD_EXIT");
return dump_printf(
"[EXIT] pid: %u tid: %u ppid: %u ptid: %u time: %lu\n",
*a1,
a1[2],
a1[1],
a1[3],
*((_QWORD *)a1 + 2));
}

canonical_decompiled_code:
int __fastcall func9(unsigned int *a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
if ( a4 <= 0x17u )
_assert_fail("size >= sizeof(perf_record_exit_t)", "dumper_dump.c", 0x5Fu, "dump_PERF_RECORD_EXIT");
return func2(
"[EXIT] pid: %u tid: %u ppid: %u ptid: %u time: %lu\n",
*a1,
a1[2],
a1[1],
a1[3],
*((_QWORD *)a1 + 2));
}

original_code:
static void dump_PERF_RECORD_EXIT (void *data, uint32_t type, uint16_t misc, uint16_t size)
{
    ((void) sizeof ((size >= sizeof(perf_record_exit_t)) ? 1 : 0), __extension__ ({ if (size >= sizeof(perf_record_exit_t)) ; else __assert_fail ("size >= sizeof(perf_record_exit_t)", "dumper_dump.c", 95, __extension__ __PRETTY_FUNCTION__); }));
    perf_record_exit_t *rec = (perf_record_exit_t *)data;
    dump_printf("[EXIT] pid: %" "u" " tid: %" "u"
                " ppid: %" "u" " ptid: %" "u"
                " time: %" "l" "u" "\n",
                rec->pid, rec->tid, rec->ppid, rec->ptid, rec->time);
}

canonical_original_code:
static void dump_PERF_RECORD_EXIT(void *data, unsigned int type, unsigned short misc, unsigned short size)
{
    ((void) sizeof ((size >= sizeof(perf_record_exit_t)) ? 1 : 0), __extension__ ({ if (size >= sizeof(perf_record_exit_t)) ; else __assert_fail ("size >= sizeof(perf_record_exit_t)", "dumper_dump.c", 95, __extension__ __PRETTY_FUNCTION__); }));
    struct perf_record_exit_t *rec = (perf_record_exit_t *)data;
    dump_printf("[EXIT] pid: %" "u" " tid: %" "u"
                " ppid: %" "u" " ptid: %" "u"
                " time: %" "l" "u" "\n",
                rec->pid, rec->tid, rec->ppid, rec->ptid, rec->time);
}

variable_types: struct perf_record_exit_t { unsigned int pid; unsigned int tid; unsigned long time; } *


decompiled_code:
int __fastcall dump_PERF_RECORD_COMM(unsigned int *a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
if ( a4 <= 7u )
_assert_fail("size >= sizeof(perf_record_comm_t)", "dumper_dump.c", 0x55u, "dump_PERF_RECORD_COMM");
return dump_printf("[COMM] pid: %u tid: %u DATA\n", *a1, a1[1]);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int *a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
if ( a4 <= 7u )
_assert_fail("size >= sizeof(perf_record_comm_t)", "dumper_dump.c", 0x55u, "dump_PERF_RECORD_COMM");
return func2("[COMM] pid: %u tid: %u DATA\n", *a1, a1[1]);
}

original_code:
static void dump_PERF_RECORD_COMM (void *data, uint32_t type, uint16_t misc, uint16_t size)
{
    ((void) sizeof ((size >= sizeof(perf_record_comm_t)) ? 1 : 0), __extension__ ({ if (size >= sizeof(perf_record_comm_t)) ; else __assert_fail ("size >= sizeof(perf_record_comm_t)", "dumper_dump.c", 85, __extension__ __PRETTY_FUNCTION__); }));
    perf_record_comm_t *rec = (perf_record_comm_t *)data;
    dump_printf("[COMM] pid: %" "u" " tid: %" "u" " DATA\n",
                rec->pid, rec->tid);
}

canonical_original_code:
static void dump_PERF_RECORD_COMM(void *data, unsigned int type, unsigned short misc, unsigned short size)
{
    ((void) sizeof ((size >= sizeof(perf_record_comm_t)) ? 1 : 0), __extension__ ({ if (size >= sizeof(perf_record_comm_t)) ; else __assert_fail ("size >= sizeof(perf_record_comm_t)", "dumper_dump.c", 85, __extension__ __PRETTY_FUNCTION__); }));
    struct perf_record_comm_t *rec = (perf_record_comm_t *)data;
    dump_printf("[COMM] pid: %" "u" " tid: %" "u" " DATA\n",
                rec->pid, rec->tid);
}

variable_types: struct perf_record_comm_t { unsigned int pid; char comm[]; } *


decompiled_code:
int __fastcall dump_PERF_RECORD_LOST(_QWORD *a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
if ( a4 <= 0xFu )
_assert_fail("size >= sizeof(perf_record_lost_t)", "dumper_dump.c", 0x4Cu, "dump_PERF_RECORD_LOST");
return dump_printf("[LOST] id: %lu lost: %lu\n", *a1, a1[1]);
}

canonical_decompiled_code:
int __fastcall func11(_QWORD *a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
if ( a4 <= 0xFu )
_assert_fail("size >= sizeof(perf_record_lost_t)", "dumper_dump.c", 0x4Cu, "dump_PERF_RECORD_LOST");
return func2("[LOST] id: %lu lost: %lu\n", *a1, a1[1]);
}

original_code:
static void dump_PERF_RECORD_LOST (void *data, uint32_t type, uint16_t misc, uint16_t size)
{
    ((void) sizeof ((size >= sizeof(perf_record_lost_t)) ? 1 : 0), __extension__ ({ if (size >= sizeof(perf_record_lost_t)) ; else __assert_fail ("size >= sizeof(perf_record_lost_t)", "dumper_dump.c", 76, __extension__ __PRETTY_FUNCTION__); }));
    perf_record_lost_t *rec = (perf_record_lost_t *)data;
    dump_printf("[LOST] id: %" "l" "u" " lost: %" "l" "u" "\n",
                rec->id, rec->lost);
}

canonical_original_code:
static void dump_PERF_RECORD_LOST(void *data, unsigned int type, unsigned short misc, unsigned short size)
{
    ((void) sizeof ((size >= sizeof(perf_record_lost_t)) ? 1 : 0), __extension__ ({ if (size >= sizeof(perf_record_lost_t)) ; else __assert_fail ("size >= sizeof(perf_record_lost_t)", "dumper_dump.c", 76, __extension__ __PRETTY_FUNCTION__); }));
    struct perf_record_lost_t *rec = (perf_record_lost_t *)data;
    dump_printf("[LOST] id: %" "l" "u" " lost: %" "l" "u" "\n",
                rec->id, rec->lost);
}

variable_types: struct perf_record_lost_t { unsigned long id; unsigned long lost; } *


decompiled_code:
int __fastcall dump_PERF_RECORD_MMAP(unsigned int *a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
if ( a4 <= 0x1Fu )
_assert_fail("size >= sizeof(perf_record_mmap_t)", "dumper_dump.c", 0x3Fu, "dump_PERF_RECORD_MMAP");
return dump_printf(
"[MMAP] pid: %u tid: %u addr: 0x%lx len: 0x%lx pgoff: 0x%lx file: %s\n",
*a1,
a1[1],
*((_QWORD *)a1 + 1),
*((_QWORD *)a1 + 2),
*((_QWORD *)a1 + 3),
(const char *)a1 + 32);
}

canonical_decompiled_code:
int __fastcall func12(unsigned int *a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
if ( a4 <= 0x1Fu )
_assert_fail("size >= sizeof(perf_record_mmap_t)", "dumper_dump.c", 0x3Fu, "dump_PERF_RECORD_MMAP");
return func2(
"[MMAP] pid: %u tid: %u addr: 0x%lx len: 0x%lx pgoff: 0x%lx file: %s\n",
*a1,
a1[1],
*((_QWORD *)a1 + 1),
*((_QWORD *)a1 + 2),
*((_QWORD *)a1 + 3),
(const char *)a1 + 32);
}

original_code:
static void dump_PERF_RECORD_MMAP (void *data, uint32_t type, uint16_t misc, uint16_t size)
{
    ((void) sizeof ((size >= sizeof(perf_record_mmap_t)) ? 1 : 0), __extension__ ({ if (size >= sizeof(perf_record_mmap_t)) ; else __assert_fail ("size >= sizeof(perf_record_mmap_t)", "dumper_dump.c", 63, __extension__ __PRETTY_FUNCTION__); }));
    perf_record_mmap_t *rec = (perf_record_mmap_t *)data;
    dump_printf("[MMAP] pid: %" "u" " tid: %" "u"
                " addr: 0x%" "l" "x" " len: 0x%" "l" "x"
                " pgoff: 0x%" "l" "x" " file: %s\n",
                rec->pid, rec->tid,
                rec->addr, rec->len,
                rec->pgoff, rec->filename);
}

canonical_original_code:
static void dump_PERF_RECORD_MMAP(void *data, unsigned int type, unsigned short misc, unsigned short size)
{
    ((void) sizeof ((size >= sizeof(perf_record_mmap_t)) ? 1 : 0), __extension__ ({ if (size >= sizeof(perf_record_mmap_t)) ; else __assert_fail ("size >= sizeof(perf_record_mmap_t)", "dumper_dump.c", 63, __extension__ __PRETTY_FUNCTION__); }));
    struct perf_record_mmap_t *rec = (perf_record_mmap_t *)data;
    dump_printf("[MMAP] pid: %" "u" " tid: %" "u"
                " addr: 0x%" "l" "x" " len: 0x%" "l" "x"
                " pgoff: 0x%" "l" "x" " file: %s\n",
                rec->pid, rec->tid,
                rec->addr, rec->len,
                rec->pgoff, rec->filename);
}

variable_types: struct perf_record_mmap_t { unsigned int pid; unsigned long addr; unsigned long len; unsigned long pgoff; char filename[]; } *


decompiled_code:
ssize_t __fastcall sync_wait(int a1, void *a2)
{
ssize_t result; // rax
int *v3; // rax
char *v4; // rax

result = recv(a1, a2, 4uLL, 256);
if ( result != 4 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(
stderr,
"%s:%i: %s\n %s\n",
"perf_common.c",
154LL,
"recv(fd, msg, sizeof(sync_msg_t), MSG_WAITALL) == sizeof(sync_msg_t)",
v4);
abort();
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(int a1, void *a2)
{
ssize_t result; // rax
int *v3; // rax
char *v4; // rax

result = recv(a1, a2, 4uLL, 256);
if ( result != 4 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(
stderr,
"%s:%i: %s\n %s\n",
"perf_common.c",
154LL,
"recv(fd, msg, sizeof(sync_msg_t), MSG_WAITALL) == sizeof(sync_msg_t)",
v4);
abort();
}
return result;
}

original_code:
static void
sync_wait(int fd, sync_msg_t *msg)
{
    do { if (!(recv(fd, msg, sizeof(sync_msg_t), MSG_WAITALL) == sizeof(sync_msg_t))) { fprintf(stderr, "%s:%i: %s\n  %s\n", "perf_common.c", 154, "recv(fd, msg, sizeof(sync_msg_t), MSG_WAITALL) == sizeof(sync_msg_t)", strerror((*__errno_location ()))); abort(); } } while (0);
}

canonical_original_code:
static void sync_wait(int fd, struct sync_msg_t *msg)
{
    do { if (!(recv(fd, msg, sizeof(sync_msg_t), MSG_WAITALL) == sizeof(sync_msg_t))) { fprintf(stderr, "%s:%i: %s\n  %s\n", "perf_common.c", 154, "recv(fd, msg, sizeof(sync_msg_t), MSG_WAITALL) == sizeof(sync_msg_t)", strerror((*__errno_location ()))); abort(); } } while (0);
}

variable_types: fd int

variable_types: struct sync_msg_t { enum sync_type_t { SYNC_WAITING=0, SYNC_GO=1, SYNC_ABORT=2 } type; } *

user_defined_types: struct sync_msg_t { enum sync_type_t type; }


decompiled_code:
__int64 __fastcall sync_wait_simple(int a1, int a2)
{
__int64 result; // rax
unsigned int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

sync_wait(a1, v3);
result = v3[0];
if ( v3[0] == 2 )
{
fwrite("Abort signalled while doing child synchronization.\n", 1uLL, 0x33uLL, stderr);
exit(1);
}
if ( v3[0] != a2 )
{
fprintf(stderr, "%s:%i: %s\n", "perf_common.c", 177LL, "msg.type == type");
abort();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
__int64 result; // rax
unsigned int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

func1(a1, v3);
result = v3[0];
if ( v3[0] == 2 )
{
fwrite("Abort signalled while doing child synchronization.\n", 1uLL, 0x33uLL, stderr);
exit(1);
}
if ( v3[0] != a2 )
{
fprintf(stderr, "%s:%i: %s\n", "perf_common.c", 177LL, "msg.type == type");
abort();
}
return result;
}

original_code:
static void
sync_wait_simple(int fd, sync_type_t type)
{
    sync_msg_t msg;
    sync_wait(fd, &msg);
    if (msg.type == SYNC_ABORT) {
        fprintf(stderr, "Abort signalled while doing child synchronization.\n");
        exit(1);
    }
    do { if (!(msg.type == type)) { fprintf(stderr, "%s:%i: %s\n", "perf_common.c", 177, "msg.type == type"); abort(); } } while (0);
}

canonical_original_code:
static void sync_wait_simple(int fd, enum sync_type_t type)
{
    struct sync_msg_t msg;
    sync_wait(fd, &msg);
    if (msg.type == SYNC_ABORT) {
        fprintf(stderr, "Abort signalled while doing child synchronization.\n");
        exit(1);
    }
    do { if (!(msg.type == type)) { fprintf(stderr, "%s:%i: %s\n", "perf_common.c", 177, "msg.type == type"); abort(); } } while (0);
}

variable_types: struct sync_msg_t { enum sync_type_t { SYNC_WAITING=0, SYNC_GO=1, SYNC_ABORT=2 } type; }


decompiled_code:
ssize_t __fastcall sync_send(int a1, const void *a2)
{
ssize_t result; // rax
int *v3; // rax
char *v4; // rax

result = send(a1, a2, 4uLL, 0);
if ( result != 4 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(
stderr,
"%s:%i: %s\n %s\n",
"perf_common.c",
148LL,
"send(fd, msg, sizeof(sync_msg_t), 0) == sizeof(sync_msg_t)",
v4);
abort();
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func3(int a1, const void *a2)
{
ssize_t result; // rax
int *v3; // rax
char *v4; // rax

result = send(a1, a2, 4uLL, 0);
if ( result != 4 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(
stderr,
"%s:%i: %s\n %s\n",
"perf_common.c",
148LL,
"send(fd, msg, sizeof(sync_msg_t), 0) == sizeof(sync_msg_t)",
v4);
abort();
}
return result;
}

original_code:
static void
sync_send(int fd, const sync_msg_t *msg)
{
    do { if (!(send(fd, msg, sizeof(sync_msg_t), 0) == sizeof(sync_msg_t))) { fprintf(stderr, "%s:%i: %s\n  %s\n", "perf_common.c", 148, "send(fd, msg, sizeof(sync_msg_t), 0) == sizeof(sync_msg_t)", strerror((*__errno_location ()))); abort(); } } while (0);
}

canonical_original_code:
static void sync_send(int fd, struct sync_msg_t *msg)
{
    do { if (!(send(fd, msg, sizeof(sync_msg_t), 0) == sizeof(sync_msg_t))) { fprintf(stderr, "%s:%i: %s\n  %s\n", "perf_common.c", 148, "send(fd, msg, sizeof(sync_msg_t), 0) == sizeof(sync_msg_t)", strerror((*__errno_location ()))); abort(); } } while (0);
}

user_defined_types: enum sync_type_t { SYNC_WAITING=0, SYNC_GO=1, SYNC_ABORT=2 }


decompiled_code:
ssize_t __fastcall sync_send_simple(int a1, int a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return sync_send(a1, v3);
}

canonical_decompiled_code:
ssize_t __fastcall func4(int a1, int a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return func3(a1, v3);
}

original_code:
static void
sync_send_simple(int fd, sync_type_t type)
{
    sync_msg_t msg = {
        .type = type,
    };
    sync_send(fd, &msg);
}

canonical_original_code:
static void sync_send_simple(int fd, enum sync_type_t type)
{
    struct sync_msg_t msg = {
        .type = type,
    };
    sync_send(fd, &msg);
}

variable_types: enum sync_type_t { SYNC_WAITING=0, SYNC_GO=1, SYNC_ABORT=2 }


decompiled_code:
size_t __fastcall read_all(int fd, void *buf, size_t nbytes)
{
size_t v5; // r12
size_t v6; // rbp
int v7; // edi
ssize_t v8; // rax
char *v9; // rax

v5 = nbytes;
v6 = nbytes;
while ( 1 )
{
v8 = read(fd, buf, v6);
if ( v8 == -1 )
{
v7 = *_errno_location();
if ( v7 != 11 )
{
v9 = strerror(v7);
fprintf(stderr, "%s:%i: %s\n %s\n", "util.c", 49LL, "errno == EAGAIN", v9);
abort();
}
goto LABEL_3;
}
if ( !v8 )
return 0LL;
v6 -= v8;
buf = (char *)buf + v8;
LABEL_3:
if ( !v6 )
return v5;
}
}

canonical_decompiled_code:
size_t __fastcall func0(int fd, void *buf, size_t nbytes)
{
size_t v5; // r12
size_t v6; // rbp
int v7; // edi
ssize_t v8; // rax
char *v9; // rax

v5 = nbytes;
v6 = nbytes;
while ( 1 )
{
v8 = read(fd, buf, v6);
if ( v8 == -1 )
{
v7 = *_errno_location();
if ( v7 != 11 )
{
v9 = strerror(v7);
fprintf(stderr, "%s:%i: %s\n %s\n", "util.c", 49LL, "errno == EAGAIN", v9);
abort();
}
goto LABEL_3;
}
if ( !v8 )
return 0LL;
v6 -= v8;
buf = (char *)buf + v8;
LABEL_3:
if ( !v6 )
return v5;
}
}

original_code:
size_t
read_all(int fd, void *buf, size_t size)
{
    char *_buf = (char *)buf;
    size_t _size = size;
    do {
        ssize_t ret;
        ret = read(fd, _buf, _size);
        switch (ret) {
        case -1:
            do { if (!((*__errno_location ()) == 11)) { fprintf(stderr, "%s:%i: %s\n  %s\n", "util.c", 49, "errno == EAGAIN", strerror((*__errno_location ()))); abort(); } } while (0);
            break;
        case 0:
            return 0;
        default:
            _size -= ret;
            _buf += ret;
            break;
        }
    } while(_size);
    return size;
}

canonical_original_code:
unsigned long read_all(int fd, void *buf, unsigned long size)
{
    char *_buf = (char *)buf;
    unsigned long _size = size;
    do {
        long ret;
        ret = read(fd, _buf, _size);
        switch (ret) {
        case -1:
            do { if (!((*__errno_location ()) == 11)) { fprintf(stderr, "%s:%i: %s\n  %s\n", "util.c", 49, "errno == EAGAIN", strerror((*__errno_location ()))); abort(); } } while (0);
            break;
        case 0:
            return 0;
        default:
            _size -= ret;
            _buf += ret;
            break;
        }
    } while(_size);
    return size;
}

variable_types:
buf
void *

variable_types:
size
unsigned long

variable_types: ret long


decompiled_code:
size_t __fastcall write_all(int fd, void *buf, size_t n)
{
size_t v5; // r13
size_t v6; // rbx
ssize_t v7; // rax
int v8; // edi
char *v9; // rax

v5 = n;
v6 = n;
do
{
v7 = write(fd, buf, v6);
if ( v7 == -1 )
{
v8 = *_errno_location();
if ( v8 != 11 )
{
v9 = strerror(v8);
fprintf(stderr, "%s:%i: %s\n %s\n", "util.c", 74LL, "errno == EAGAIN", v9);
abort();
}
}
else
{
v6 -= v7;
buf = (char *)buf + v7;
}
}
while ( v6 );
return v5;
}

canonical_decompiled_code:
size_t __fastcall func1(int fd, void *buf, size_t n)
{
size_t v5; // r13
size_t v6; // rbx
ssize_t v7; // rax
int v8; // edi
char *v9; // rax

v5 = n;
v6 = n;
do
{
v7 = write(fd, buf, v6);
if ( v7 == -1 )
{
v8 = *_errno_location();
if ( v8 != 11 )
{
v9 = strerror(v8);
fprintf(stderr, "%s:%i: %s\n %s\n", "util.c", 74LL, "errno == EAGAIN", v9);
abort();
}
}
else
{
v6 -= v7;
buf = (char *)buf + v7;
}
}
while ( v6 );
return v5;
}

original_code:
size_t
write_all(int fd, const void *buf, size_t size)
{
    char *_buf = (char *)buf;
    size_t _size = size;
    do {
        ssize_t ret;
        ret = write(fd, _buf, _size);
        if (ret == -1)
            do { if (!((*__errno_location ()) == 11)) { fprintf(stderr, "%s:%i: %s\n  %s\n", "util.c", 74, "errno == EAGAIN", strerror((*__errno_location ()))); abort(); } } while (0);
        else {
            _size -= ret;
            _buf += ret;
        }
    } while(_size);
    return size;
}

canonical_original_code:
unsigned long write_all(int fd, void *buf, unsigned long size)
{
    char *_buf = (char *)buf;
    unsigned long _size = size;
    do {
        long ret;
        ret = write(fd, _buf, _size);
        if (ret == -1)
            do { if (!((*__errno_location ()) == 11)) { fprintf(stderr, "%s:%i: %s\n  %s\n", "util.c", 74, "errno == EAGAIN", strerror((*__errno_location ()))); abort(); } } while (0);
        else {
            _size -= ret;
            _buf += ret;
        }
    } while(_size);
    return size;
}


decompiled_code:
ssize_t __fastcall send_fd(int a1, int a2)
{
ssize_t result; // rax
int *v3; // rax
char *v4; // rax
struct msghdr v5; // [rsp+0h] [rbp-68h] BYREF
__int64 v6; // [rsp+40h] [rbp-28h] BYREF
int v7; // [rsp+48h] [rbp-20h]
int v8; // [rsp+4Ch] [rbp-1Ch]
int v9; // [rsp+50h] [rbp-18h]

v5.msg_name = 0LL;
*(_QWORD *)&v5.msg_namelen = 0LL;
v5.msg_iov = 0LL;
v5.msg_iovlen = 0LL;
*(_QWORD *)&v5.msg_flags = 0LL;
v5.msg_control = &v6;
v7 = 1;
v8 = 1;
v6 = 20LL;
v9 = a2;
v5.msg_controllen = 20LL;
result = sendmsg(a1, &v5, 0);
if ( result == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "%s:%i: %s\n %s\n", "util.c", 103LL, "sendmsg(sockfd, &msg, 0) != -1", v4);
abort();
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(int a1, int a2)
{
ssize_t result; // rax
int *v3; // rax
char *v4; // rax
struct msghdr v5; // [rsp+0h] [rbp-68h] BYREF
__int64 v6; // [rsp+40h] [rbp-28h] BYREF
int v7; // [rsp+48h] [rbp-20h]
int v8; // [rsp+4Ch] [rbp-1Ch]
int v9; // [rsp+50h] [rbp-18h]

v5.msg_name = 0LL;
*(_QWORD *)&v5.msg_namelen = 0LL;
v5.msg_iov = 0LL;
v5.msg_iovlen = 0LL;
*(_QWORD *)&v5.msg_flags = 0LL;
v5.msg_control = &v6;
v7 = 1;
v8 = 1;
v6 = 20LL;
v9 = a2;
v5.msg_controllen = 20LL;
result = sendmsg(a1, &v5, 0);
if ( result == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "%s:%i: %s\n %s\n", "util.c", 103LL, "sendmsg(sockfd, &msg, 0) != -1", v4);
abort();
}
return result;
}

original_code:
void
send_fd(int sockfd, int fd)
{
    char buf[((((sizeof(int)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)))];
    struct msghdr msg = {
        .msg_control = buf,
        .msg_controllen = sizeof(buf)
    };
    struct cmsghdr *cmsg;
    cmsg = ((size_t) (&msg)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msg)->msg_control : (struct cmsghdr *) 0);
    cmsg->cmsg_level = 1;
    cmsg->cmsg_type = SCM_RIGHTS;
    cmsg->cmsg_len = ((((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (sizeof(int)));
    *(int *)((cmsg)->__cmsg_data) = fd;
    msg.msg_controllen = cmsg->cmsg_len;
    do { if (!(sendmsg(sockfd, &msg, 0) != -1)) { fprintf(stderr, "%s:%i: %s\n  %s\n", "util.c", 103, "sendmsg(sockfd, &msg, 0) != -1", strerror((*__errno_location ()))); abort(); } } while (0);
}

canonical_original_code:
void send_fd(int sockfd, int fd)
{
    char buf[-1];
    struct msghdr msg = {
        .msg_control = buf,
        .msg_controllen = sizeof(buf)
    };
    struct cmsghdr *cmsg;
    cmsg = ((unsigned long) (&msg)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msg)->msg_control : (struct cmsghdr *) 0);
    cmsg->cmsg_level = 1;
    cmsg->cmsg_type = SCM_RIGHTS;
    cmsg->cmsg_len = ((((sizeof (struct cmsghdr)) + sizeof (unsigned long) - 1) & (unsigned long) ~(sizeof (unsigned long) - 1)) + (sizeof(int)));
    *(int *)((cmsg)->__cmsg_data) = fd;
    msg.msg_controllen = cmsg->cmsg_len;
    do { if (!(sendmsg(sockfd, &msg, 0) != -1)) { fprintf(stderr, "%s:%i: %s\n  %s\n", "util.c", 103, "sendmsg(sockfd, &msg, 0) != -1", strerror((*__errno_location ()))); abort(); } } while (0);
}

variable_types: sockfd int

variable_types:
buf
char [-1]

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

variable_types: struct cmsghdr { unsigned long cmsg_len; int cmsg_level; int cmsg_type; unsigned char __cmsg_data[]; } *

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }


decompiled_code:
__int64 __fastcall recv_fd(int a1)
{
int *v2; // rax
char *v3; // rax
struct msghdr v4; // [rsp+0h] [rbp-68h] BYREF
char v5; // [rsp+40h] [rbp-28h] BYREF

v4.msg_name = 0LL;
*(_QWORD *)&v4.msg_namelen = 0LL;
v4.msg_iov = 0LL;
v4.msg_iovlen = 0LL;
*(_QWORD *)&v4.msg_flags = 0LL;
v4.msg_control = &v5;
v4.msg_controllen = 24LL;
if ( recvmsg(a1, &v4, 0) == -1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "%s:%i: %s\n %s\n", "util.c", 119LL, "recvmsg(sockfd, &msg, 0) != -1", v3);
abort();
}
if ( v4.msg_controllen <= 0xF || !v4.msg_control )
{
fwrite("Failed to receive fds, aborting.\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
if ( *((_DWORD *)v4.msg_control + 3) != 1 )
_assert_fail("cmsg->cmsg_type == SCM_RIGHTS", "util.c", 0x7Fu, "recv_fd");
return *((unsigned int *)v4.msg_control + 4);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int *v2; // rax
char *v3; // rax
struct msghdr v4; // [rsp+0h] [rbp-68h] BYREF
char v5; // [rsp+40h] [rbp-28h] BYREF

v4.msg_name = 0LL;
*(_QWORD *)&v4.msg_namelen = 0LL;
v4.msg_iov = 0LL;
v4.msg_iovlen = 0LL;
*(_QWORD *)&v4.msg_flags = 0LL;
v4.msg_control = &v5;
v4.msg_controllen = 24LL;
if ( recvmsg(a1, &v4, 0) == -1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "%s:%i: %s\n %s\n", "util.c", 119LL, "recvmsg(sockfd, &msg, 0) != -1", v3);
abort();
}
if ( v4.msg_controllen <= 0xF || !v4.msg_control )
{
fwrite("Failed to receive fds, aborting.\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
if ( *((_DWORD *)v4.msg_control + 3) != 1 )
_assert_fail("cmsg->cmsg_type == SCM_RIGHTS", "util.c", 0x7Fu, "recv_fd");
return *((unsigned int *)v4.msg_control + 4);
}

original_code:
int
recv_fd(int sockfd)
{
    char buf[((((sizeof(int)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)))];
    struct msghdr msg = {
        .msg_control = buf,
        .msg_controllen = sizeof(buf)
    };
    struct cmsghdr *cmsg;
    msg.msg_control = buf;
    msg.msg_controllen = sizeof(buf);
    do { if (!(recvmsg(sockfd, &msg, 0) != -1)) { fprintf(stderr, "%s:%i: %s\n  %s\n", "util.c", 119, "recvmsg(sockfd, &msg, 0) != -1", strerror((*__errno_location ()))); abort(); } } while (0);
    cmsg = ((size_t) (&msg)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msg)->msg_control : (struct cmsghdr *) 0);
    if (!cmsg) {
        fprintf(stderr, "Failed to receive fds, aborting.\n");
        exit(1);
    }
    ((void) sizeof ((cmsg->cmsg_type == SCM_RIGHTS) ? 1 : 0), __extension__ ({ if (cmsg->cmsg_type == SCM_RIGHTS) ; else __assert_fail ("cmsg->cmsg_type == SCM_RIGHTS", "util.c", 127, __extension__ __PRETTY_FUNCTION__); }));
    return *(int *)((cmsg)->__cmsg_data);
}

canonical_original_code:
int recv_fd(int sockfd)
{
    char buf[-1];
    struct msghdr msg = {
        .msg_control = buf,
        .msg_controllen = sizeof(buf)
    };
    struct cmsghdr *cmsg;
    msg.msg_control = buf;
    msg.msg_controllen = sizeof(buf);
    do { if (!(recvmsg(sockfd, &msg, 0) != -1)) { fprintf(stderr, "%s:%i: %s\n  %s\n", "util.c", 119, "recvmsg(sockfd, &msg, 0) != -1", strerror((*__errno_location ()))); abort(); } } while (0);
    cmsg = ((unsigned long) (&msg)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msg)->msg_control : (struct cmsghdr *) 0);
    if (!cmsg) {
        fprintf(stderr, "Failed to receive fds, aborting.\n");
        exit(1);
    }
    ((void) sizeof ((cmsg->cmsg_type == SCM_RIGHTS) ? 1 : 0), __extension__ ({ if (cmsg->cmsg_type == SCM_RIGHTS) ; else __assert_fail ("cmsg->cmsg_type == SCM_RIGHTS", "util.c", 127, __extension__ __PRETTY_FUNCTION__); }));
    return *(int *)((cmsg)->__cmsg_data);
}

user_defined_types: struct cmsghdr { unsigned long cmsg_len; int cmsg_level; int cmsg_type; unsigned char __cmsg_data[]; }

user_defined_types: struct iovec { void *iov_base; unsigned long iov_len; }


decompiled_code:
__int64 __fastcall read_uint64_t(__int64 *a1, _WORD *a2)
{
__int64 v2; // rax

if ( *a2 <= 7u )
_assert_fail("*size >= sizeof(uint64_t)", "dumpers.h", 0x51u, "read_uint64_t");
*a2 -= 8;
v2 = *a1;
*a1 += 8LL;
return *(_QWORD *)v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, _WORD *a2)
{
__int64 v2; // rax

if ( *a2 <= 7u )
_assert_fail("*size >= sizeof(uint64_t)", "dumpers.h", 0x51u, "read_uint64_t");
*a2 -= 8;
v2 = *a1;
*a1 += 8LL;
return *(_QWORD *)v2;
}

original_code: static inline uint64_t read_uint64_t(void **data, uint16_t *size) { ((void) sizeof ((*size >= sizeof(uint64_t)) ? 1 : 0), __extension__ ({ if (*size >= sizeof(uint64_t)) ; else __assert_fail ("*size >= sizeof(uint64_t)", "dumpers.h", 81, __extension__ __PRETTY_FUNCTION__); })); *size -= sizeof(uint64_t); return *(*(uint64_t **)data)++; }

canonical_original_code: static inline unsigned long read_uint64_t(void **data, unsigned short *size) { ((void) sizeof ((*size >= sizeof(unsigned long)) ? 1 : 0), __extension__ ({ if (*size >= sizeof(unsigned long)) ; else __assert_fail ("*size >= sizeof(uint64_t)", "dumpers.h", 81, __extension__ __PRETTY_FUNCTION__); })); *size -= sizeof(unsigned long); return *(*(unsigned long **)data)++; }

variable_types:
data
void **

variable_types:
size
unsigned short *


decompiled_code:
int dump_printf(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(conf, format, arg);
}

canonical_decompiled_code:
int func4(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(conf, format, arg);
}

original_code:
static void
dump_printf(const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    vfprintf(conf.output, fmt, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
static void dump_printf(char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    vfprintf(conf.output, fmt, ap);
    __builtin_va_end(ap);
}

variable_types:
fmt
char *


original_code:
static void
dump_sample(void *data, uint32_t type, uint16_t misc, uint16_t size)
{
    const uint64_t sample_type = attr->sample_type;
    if (sample_type & PERF_SAMPLE_IP)
        skip_uint64_t(&data, &size);
    if (sample_type & PERF_SAMPLE_TID) {
        skip_uint32_t(&data, &size);
        skip_uint32_t(&data, &size);
    }
    if (sample_type & PERF_SAMPLE_TIME) {
        uint64_t time = read_uint64_t(&data, &size);
        if (start_time == -1)
            start_time = time;
        dump_printf("%" "l" "u", time - start_time);
    } else
        dump_printf("%" "l" "u", sample_no);
    if (sample_type & PERF_SAMPLE_ADDR)
        skip_uint64_t(&data, &size);
    if (sample_type & PERF_SAMPLE_ID)
        skip_uint64_t(&data, &size);
    if (sample_type & PERF_SAMPLE_STREAM_ID)
        skip_uint64_t(&data, &size);
    if (sample_type & PERF_SAMPLE_CPU) {
        skip_uint32_t(&data, &size);
        skip_uint32_t(&data, &size);
    }
    if (sample_type & PERF_SAMPLE_PERIOD)
        skip_uint64_t(&data, &size);
    if (sample_type & PERF_SAMPLE_READ) {
        const uint64_t read_format = attr->read_format;
        if (!(read_format & PERF_FORMAT_GROUP)) {
            uint64_t value = read_uint64_t(&data, &size);
            dump_printf(",%" "l" "u" "\n", value);
        } else {
            uint64_t nr = read_uint64_t(&data, &size);
            ((void) sizeof ((no_counters == nr) ? 1 : 0), __extension__ ({ if (no_counters == nr) ; else __assert_fail ("no_counters == nr", "dumper_csv.c", 103, __extension__ __PRETTY_FUNCTION__); }));
            if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
                skip_uint64_t(&data, &size);
            if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
                skip_uint64_t(&data, &size);
            for (int i = 0; i < nr; i++) {
                uint64_t value = read_uint64_t(&data, &size);
                if (read_format & PERF_FORMAT_ID)
                    skip_uint64_t(&data, &size);
                if (conf.delta) {
                    dump_printf(",%" "l" "u", value - old_values[i]);
                    old_values[i] = value;
                } else
                    dump_printf(",%" "l" "u", value);
            }
            dump_printf("\n");
        }
    }
    sample_no++;
}

canonical_original_code:
static void dump_sample(void *data, unsigned int type, unsigned short misc, unsigned short size)
{
    unsigned long sample_type = attr->sample_type;
    if (sample_type & PERF_SAMPLE_IP)
        skip_uint64_t(&data, &size);
    if (sample_type & PERF_SAMPLE_TID) {
        skip_uint32_t(&data, &size);
        skip_uint32_t(&data, &size);
    }
    if (sample_type & PERF_SAMPLE_TIME) {
        unsigned long time = read_uint64_t(&data, &size);
        if (start_time == -1)
            start_time = time;
        dump_printf("%" "l" "u", time - start_time);
    } else
        dump_printf("%" "l" "u", sample_no);
    if (sample_type & PERF_SAMPLE_ADDR)
        skip_uint64_t(&data, &size);
    if (sample_type & PERF_SAMPLE_ID)
        skip_uint64_t(&data, &size);
    if (sample_type & PERF_SAMPLE_STREAM_ID)
        skip_uint64_t(&data, &size);
    if (sample_type & PERF_SAMPLE_CPU) {
        skip_uint32_t(&data, &size);
        skip_uint32_t(&data, &size);
    }
    if (sample_type & PERF_SAMPLE_PERIOD)
        skip_uint64_t(&data, &size);
    if (sample_type & PERF_SAMPLE_READ) {
        unsigned long read_format = attr->read_format;
        if (!(read_format & PERF_FORMAT_GROUP)) {
            unsigned long value = read_uint64_t(&data, &size);
            dump_printf(",%" "l" "u" "\n", value);
        } else {
            unsigned long nr = read_uint64_t(&data, &size);
            ((void) sizeof ((no_counters == nr) ? 1 : 0), __extension__ ({ if (no_counters == nr) ; else __assert_fail ("no_counters == nr", "dumper_csv.c", 103, __extension__ __PRETTY_FUNCTION__); }));
            if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
                skip_uint64_t(&data, &size);
            if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
                skip_uint64_t(&data, &size);
            for (int i = 0; i < nr; i++) {
                unsigned long value = read_uint64_t(&data, &size);
                if (read_format & PERF_FORMAT_ID)
                    skip_uint64_t(&data, &size);
                if (conf.delta) {
                    dump_printf(",%" "l" "u", value - old_values[i]);
                    old_values[i] = value;
                } else
                    dump_printf(",%" "l" "u", value);
            }
            dump_printf("\n");
        }
    }
    sample_no++;
}

variable_types:
data
void *

variable_types:
type
unsigned int

variable_types:
misc
unsigned short

variable_types:
size
unsigned short

variable_types:
time
unsigned long

variable_types:
value
unsigned long

variable_types:
nr
unsigned long

variable_types: i int


repo: andytwmvp/rpi-gpio-demo

decompiled_code:
unsigned __int64 __fastcall parse_gpio_pin(const char *a1)
{
unsigned __int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

if ( !*a1 )
{
error(2, 0, "empty string given for GPIO pin number");
goto LABEL_5;
}
result = strtoul(a1, &endptr, 0);
if ( *endptr )
{
LABEL_5:
error(2, 0, "%s is not a valid GPIO pin number", a1);
result = allow_access_by_user();
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(const char *a1)
{
unsigned __int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

if ( !*a1 )
{
error(2, 0, "empty string given for GPIO pin number");
goto LABEL_5;
}
result = strtoul(a1, &endptr, 0);
if ( *endptr )
{
LABEL_5:
error(2, 0, "%s is not a valid GPIO pin number", a1);
result = func8();
}
return result;
}

original_code:
static unsigned int parse_gpio_pin(const char *pin_str) {
  char *endp;
  unsigned int pin;
  if (pin_str[0] == '\0') {
    error(2, 0, "empty string given for GPIO pin number");
  }
  pin = strtoul(pin_str, &endp, 0);
  if (*endp != '\0') {
    error(2, 0, "%s is not a valid GPIO pin number", pin_str);
  }
  return pin;
}

canonical_original_code:
static unsigned int parse_gpio_pin(char *pin_str) {
  char *endp;
  unsigned int pin;
  if (pin_str[0] == '\0') {
    error(2, 0, "empty string given for GPIO pin number");
  }
  pin = strtoul(pin_str, &endp, 0);
  if (*endp != '\0') {
    error(2, 0, "%s is not a valid GPIO pin number", pin_str);
  }
  return pin;
}

variable_types:
endp
char *

variable_types:
pin
unsigned int


decompiled_code:
int __fastcall allow_access_by_user(unsigned int a1, const char *a2)
{
__gid_t v2; // ebx
__uid_t v3; // eax
int result; // eax
int *v5; // rax
int *v6; // rax
char v7[4104]; // [rsp+0h] [rbp-1008h] BYREF

if ( snprintf(v7, 0x1000uLL, "/sys/devices/virtual/gpio/gpio%u/%s", a1, a2) > 4095 )
{
error(7, 0, "path of GPIO pin is too long!");
goto LABEL_6;
}
v2 = getgid();
v3 = getuid();
if ( chown(v7, v3, v2) )
{
LABEL_6:
v5 = __errno_location();
error(5, *v5, "failed to change group ownership of %s", v7);
LABEL_7:
v6 = __errno_location();
error(6, *v6, "failed to set permissions of %s", v7);
usage_error();
}
result = chmod(v7, 0x180u);
if ( result )
goto LABEL_7;
return result;
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1, const char *a2)
{
__gid_t v2; // ebx
__uid_t v3; // eax
int result; // eax
int *v5; // rax
int *v6; // rax
char v7[4104]; // [rsp+0h] [rbp-1008h] BYREF

if ( snprintf(v7, 0x1000uLL, "/sys/devices/virtual/gpio/gpio%u/%s", a1, a2) > 4095 )
{
error(7, 0, "path of GPIO pin is too long!");
goto LABEL_6;
}
v2 = getgid();
v3 = getuid();
if ( chown(v7, v3, v2) )
{
LABEL_6:
v5 = __errno_location();
error(5, *v5, "failed to change group ownership of %s", v7);
LABEL_7:
v6 = __errno_location();
error(6, *v6, "failed to set permissions of %s", v7);
func9();
}
result = chmod(v7, 0x180u);
if ( result )
goto LABEL_7;
return result;
}

original_code:
static void allow_access_by_user(unsigned int pin, const char *filename) {
  char path[4096];
  int size = snprintf(path, 4096, "/sys/devices/virtual/gpio/gpio%u/%s", pin, filename);
  if (size >= 4096) {
    error(7, 0, "path of GPIO pin is too long!");
  }
  if (chown(path, getuid(), getgid()) != 0) {
    error(5, (*__errno_location ()), "failed to change group ownership of %s", path);
  }
  if (chmod(path, 0400|0200) != 0) {
    error(6, (*__errno_location ()), "failed to set permissions of %s", path);
  }
}

canonical_original_code:
static void allow_access_by_user(unsigned int pin, char *filename) {
  char path[4096];
  int size = snprintf(path, 4096, "/sys/devices/virtual/gpio/gpio%u/%s", pin, filename);
  if (size >= 4096) {
    error(7, 0, "path of GPIO pin is too long!");
  }
  if (chown(path, getuid(), getgid()) != 0) {
    error(5, (*__errno_location ()), "failed to change group ownership of %s", path);
  }
  if (chmod(path, 0400|0200) != 0) {
    error(6, (*__errno_location ()), "failed to set permissions of %s", path);
  }
}

variable_types:
filename
char *

variable_types:
path
char [4096]

variable_types: size int


decompiled_code:
int __fastcall set_pullupdown(int a1, int a2)
{
int v2; // eax
int v3; // ebp
_DWORD *v4; // rax
_DWORD *v5; // rbx
_DWORD *v6; // r13
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax

v2 = open("/dev/mem", 1052674);
if ( v2 < 0 )
{
v8 = __errno_location();
v9 = strerror(*v8);
fprintf(_bss_start, "could not open /dev/mem: %s\n", v9);
exit(-1);
}
v3 = v2;
v4 = mmap(0LL, 0x1000uLL, 3, 1, v2, 538968064LL);
v5 = v4;
if ( v4 == (_DWORD *)-1LL )
{
v10 = __errno_location();
v11 = strerror(*v10);
fprintf(_bss_start, "could not map GPIO region: %s\n", v11);
close(v3);
exit(-1);
}
v4[37] = a2;
usleep(0x64u);
v6 = &v5[((a1 >> 5) & 1) + 38];
*v6 = 1 << a1;
usleep(0x64u);
v5[37] = 0;
*v6 = 0;
munmap(v5, 0x1000uLL);
return close(v3);
}

canonical_decompiled_code:
int __fastcall func10(int a1, int a2)
{
int v2; // eax
int v3; // ebp
_DWORD *v4; // rax
_DWORD *v5; // rbx
_DWORD *v6; // r13
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax

v2 = open("/dev/mem", 1052674);
if ( v2 < 0 )
{
v8 = __errno_location();
v9 = strerror(*v8);
fprintf(_bss_start, "could not open /dev/mem: %s\n", v9);
exit(-1);
}
v3 = v2;
v4 = mmap(0LL, 0x1000uLL, 3, 1, v2, 538968064LL);
v5 = v4;
if ( v4 == (_DWORD *)-1LL )
{
v10 = __errno_location();
v11 = strerror(*v10);
fprintf(_bss_start, "could not map GPIO region: %s\n", v11);
close(v3);
exit(-1);
}
v4[37] = a2;
usleep(0x64u);
v6 = &v5[((a1 >> 5) & 1) + 38];
*v6 = 1 << a1;
usleep(0x64u);
v5[37] = 0;
*v6 = 0;
munmap(v5, 0x1000uLL);
return close(v3);
}

original_code:
static void set_pullupdown(int pin, int direction) {
    volatile uint32_t* gpio;
    int fd = open("/dev/mem", 02|04010000);
    if (fd < 0) {
        fprintf(stderr, "could not open /dev/mem: %s\n", strerror((*__errno_location ())));
        exit(-1);
    }
    gpio = (volatile uint32_t*) mmap(((void *)0), 4096, 0x1|0x2, 0x01, fd, 0x20200000);
    if (gpio == ((void *) -1)) {
        fprintf(stderr, "could not map GPIO region: %s\n", strerror((*__errno_location ())));
        close(fd);
        exit(-1);
    }
    gpio[37] = direction;
    usleep(100);
    gpio[38 +(((pin) & 32) >> 5)] = (1 << ((pin) & 31));
    usleep(100);
    gpio[37] = 0;
    gpio[38 +(((pin) & 32) >> 5)] = 0;
    munmap((char*)gpio, 4096);
    close(fd);
}

canonical_original_code:
static void set_pullupdown(int pin, int direction) {
    unsigned int *gpio;
    int fd = open("/dev/mem", 02|04010000);
    if (fd < 0) {
        fprintf(stderr, "could not open /dev/mem: %s\n", strerror((*__errno_location ())));
        exit(-1);
    }
    gpio = (unsigned int *) mmap(((void *)0), 4096, 0x1|0x2, 0x01, fd, 0x20200000);
    if (gpio == ((void *) -1)) {
        fprintf(stderr, "could not map GPIO region: %s\n", strerror((*__errno_location ())));
        close(fd);
        exit(-1);
    }
    gpio[37] = direction;
    usleep(100);
    gpio[38 +(((pin) & 32) >> 5)] = (1 << ((pin) & 31));
    usleep(100);
    gpio[37] = 0;
    gpio[38 +(((pin) & 32) >> 5)] = 0;
    munmap((char *)gpio, 4096);
    close(fd);
}

variable_types: pin int

variable_types: direction int

variable_types:
gpio
unsigned int *

variable_types: fd int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
unsigned int v4; // ebx
const char *v6; // r12
int v7; // eax
int v8; // er12

if ( (unsigned int)(argc - 3) > 1 )
usage_error(argv);
v3 = argv[1];
v4 = parse_gpio_pin(argv[2]);
if ( argc == 4 )
{
v6 = argv[3];
if ( !strcmp("pullup", v6) )
{
v8 = 2;
}
else
{
v7 = strcmp("pulldown", v6);
v8 = 1;
if ( v7 )
usage_error(argv);
}
if ( !strcmp(v3, "export") )
{
write_pin_to_path("/sys/class/gpio/export", v4);
allow_access_by_user(v4, "direction");
allow_access_by_user(v4, "value");
allow_access_by_user(v4, "active_low");
allow_access_by_user(v4, "edge");
set_pullupdown(v4, v8);
return 0;
}
}
else if ( !strcmp(v3, "export") )
{
write_pin_to_path("/sys/class/gpio/export", v4);
allow_access_by_user(v4, "direction");
allow_access_by_user(v4, "value");
allow_access_by_user(v4, "active_low");
allow_access_by_user(v4, "edge");
return 0;
}
if ( strcmp(v3, "unexport") )
usage_error(argv);
write_pin_to_path("/sys/class/gpio/unexport", v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
unsigned int v4; // ebx
const char *v6; // r12
int v7; // eax
int v8; // er12

if ( (unsigned int)(argc - 3) > 1 )
func9(argv);
v3 = argv[1];
v4 = func7(argv[2]);
if ( argc == 4 )
{
v6 = argv[3];
if ( !strcmp("pullup", v6) )
{
v8 = 2;
}
else
{
v7 = strcmp("pulldown", v6);
v8 = 1;
if ( v7 )
func9(argv);
}
if ( !strcmp(v3, "export") )
{
func11("/sys/class/gpio/export", v4);
func8(v4, "direction");
func8(v4, "value");
func8(v4, "active_low");
func8(v4, "edge");
func10(v4, v8);
return 0;
}
}
else if ( !strcmp(v3, "export") )
{
func11("/sys/class/gpio/export", v4);
func8(v4, "direction");
func8(v4, "value");
func8(v4, "active_low");
func8(v4, "edge");
return 0;
}
if ( strcmp(v3, "unexport") )
func9(argv);
func11("/sys/class/gpio/unexport", v4);
return 0;
}

original_code:
int main(int argc, char **argv) {
  int pullupdown = -1;
  if (argc != 3 && argc != 4) {
    usage_error(argv);
  }
  const char *command = argv[1];
  const char *pin_str = argv[2];
  unsigned int pin = parse_gpio_pin(pin_str);
  if (argc == 4) {
    if (strcmp("pullup", argv[3]) == 0)
      pullupdown = 2;
    else if (strcmp("pulldown", argv[3]) == 0)
      pullupdown = 1;
    else {
      usage_error(argv);
    }
  }
  if (strcmp(command, "export") == 0) {
    write_pin_to_path(("/sys/class/gpio/" "export"), pin);
    allow_access_by_user(pin, "direction");
    allow_access_by_user(pin, "value");
    allow_access_by_user(pin, "active_low");
    allow_access_by_user(pin, "edge");
    if (pullupdown != -1) {
      set_pullupdown(pin, pullupdown);
    }
  }
  else if (strcmp(command, "unexport") == 0) {
    write_pin_to_path(("/sys/class/gpio/" "unexport"), pin);
  }
  else {
    usage_error(argv);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  int pullupdown = -1;
  if (argc != 3 && argc != 4) {
    usage_error(argv);
  }
  char *command = argv[1];
  char *pin_str = argv[2];
  unsigned int pin = parse_gpio_pin(pin_str);
  if (argc == 4) {
    if (strcmp("pullup", argv[3]) == 0)
      pullupdown = 2;
    else if (strcmp("pulldown", argv[3]) == 0)
      pullupdown = 1;
    else {
      usage_error(argv);
    }
  }
  if (strcmp(command, "export") == 0) {
    write_pin_to_path(("/sys/class/gpio/" "export"), pin);
    allow_access_by_user(pin, "direction");
    allow_access_by_user(pin, "value");
    allow_access_by_user(pin, "active_low");
    allow_access_by_user(pin, "edge");
    if (pullupdown != -1) {
      set_pullupdown(pin, pullupdown);
    }
  }
  else if (strcmp(command, "unexport") == 0) {
    write_pin_to_path(("/sys/class/gpio/" "unexport"), pin);
  }
  else {
    usage_error(argv);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: pullupdown int

variable_types:
command
char *


repo: andywarduk/LEDs

decompiled_code:
__int64 get_gpio_revision()
{
FILE *v0; // rax
unsigned int v1; // ebp
FILE *v2; // rbx
_BOOL4 v4; // ebp
unsigned int v5; // [rsp+Ch] [rbp-1Ch]

v0 = get_cpuinfo_revision();
v1 = 0;
if ( v0 )
{
v2 = v0;
if ( strlen((const char *)v0) > 3 )
{
v1 = __isoc99_sscanf();
if ( v1 )
{
printf("cpuinfo revision bits: %x\n", v5);
if ( v5 > 5 )
{
if ( v5 > 9 )
v4 = v5 - 13 > 2;
else
v4 = v5 < 7;
v1 = v4 + 2;
}
else if ( v5 > 3 )
{
v1 = 2;
}
else
{
v1 = v5 - 2 < 2 ? 1 : 3;
}
}
}
free(v2);
}
return v1;
}

canonical_decompiled_code:
__int64 func8()
{
FILE *v0; // rax
unsigned int v1; // ebp
FILE *v2; // rbx
_BOOL4 v4; // ebp
unsigned int v5; // [rsp+Ch] [rbp-1Ch]

v0 = func7();
v1 = 0;
if ( v0 )
{
v2 = v0;
if ( strlen((const char *)v0) > 3 )
{
v1 = __isoc99_sscanf();
if ( v1 )
{
printf("cpuinfo revision bits: %x\n", v5);
if ( v5 > 5 )
{
if ( v5 > 9 )
v4 = v5 - 13 > 2;
else
v4 = v5 < 7;
v1 = v4 + 2;
}
else if ( v5 > 3 )
{
v1 = 2;
}
else
{
v1 = v5 - 2 < 2 ? 1 : 3;
}
}
}
free(v2);
}
return v1;
}

original_code:
static int get_gpio_revision(void)
{
    int rev = 0;
    char *full_revision;
    unsigned revision;
    full_revision = get_cpuinfo_revision();
    if (full_revision != ((void *)0)) {
        if (strlen(full_revision) >= 4 && sscanf(full_revision + strlen(full_revision) - 4, "%x", &revision)) {
            printf("cpuinfo revision bits: %x\n", revision);
            switch (revision) {
                case 0x0002:
                case 0x0003:
                    rev = 1;
                    break;
                case 0x0004:
                case 0x0005:
                case 0x0007:
                case 0x0008:
                case 0x0009:
                case 0x000d:
                case 0x000e:
                case 0x000f:
                    rev = 2;
                    break;
                default:
                    rev = 3;
                    break;
            }
        }
        free(full_revision);
    }
    return rev;
}

canonical_original_code:
static int get_gpio_revision()
{
    int rev = 0;
    char *full_revision;
    unsigned int revision;
    full_revision = get_cpuinfo_revision();
    if (full_revision != ((void *)0)) {
        if (strlen(full_revision) >= 4 && sscanf(full_revision + strlen(full_revision) - 4, "%x", &revision)) {
            printf("cpuinfo revision bits: %x\n", revision);
            switch (revision) {
                case 0x0002:
                case 0x0003:
                    rev = 1;
                    break;
                case 0x0004:
                case 0x0005:
                case 0x0007:
                case 0x0008:
                case 0x0009:
                case 0x000d:
                case 0x000e:
                case 0x000f:
                    rev = 2;
                    break;
                default:
                    rev = 3;
                    break;
            }
        }
        free(full_revision);
    }
    return rev;
}

variable_types: rev int

variable_types:
revision
unsigned int


decompiled_code:
__int64 bcm_host_get_peripheral_address()
{
__int64 result; // rax

result = get_dt_ranges("/proc/device-tree/soc/ranges", 4u);
if ( !(_DWORD)result )
result = get_dt_ranges("/proc/device-tree/soc/ranges", 8u);
if ( (_DWORD)result == -1 )
result = 0x20000000LL;
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 result; // rax

result = func9("/proc/device-tree/soc/ranges", 4u);
if ( !(_DWORD)result )
result = func9("/proc/device-tree/soc/ranges", 8u);
if ( (_DWORD)result == -1 )
result = 0x20000000LL;
return result;
}

original_code:
unsigned bcm_host_get_peripheral_address()
{
   unsigned address = get_dt_ranges("/proc/device-tree/soc/ranges", 4);
   if (address == 0)
      address = get_dt_ranges("/proc/device-tree/soc/ranges", 8);
   return address == (unsigned) ~0 ? 0x20000000 : address;
}

canonical_original_code:
unsigned int bcm_host_get_peripheral_address()
{
   unsigned int address = get_dt_ranges("/proc/device-tree/soc/ranges", 4);
   if (address == 0)
      address = get_dt_ranges("/proc/device-tree/soc/ranges", 8);
   return address == (unsigned int) ~0 ? 0x20000000 : address;
}

variable_types:
address
unsigned int


decompiled_code:
__int64 bcm_host_get_peripheral_size()
{
int v0; // eax
__int64 result; // rax

v0 = get_dt_ranges("/proc/device-tree/soc/ranges", 4u);
result = get_dt_ranges("/proc/device-tree/soc/ranges", v0 == 0 ? 12 : 8);
if ( (_DWORD)result == -1 )
result = 0x1000000LL;
return result;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // eax
__int64 result; // rax

v0 = func9("/proc/device-tree/soc/ranges", 4u);
result = func9("/proc/device-tree/soc/ranges", v0 == 0 ? 12 : 8);
if ( (_DWORD)result == -1 )
result = 0x1000000LL;
return result;
}

original_code:
unsigned bcm_host_get_peripheral_size()
{
   unsigned address = get_dt_ranges("/proc/device-tree/soc/ranges", 4);
   address = get_dt_ranges("/proc/device-tree/soc/ranges", (address == 0) ? 12 : 8);
   return address == (unsigned) ~0 ? 0x01000000 : address;
}

canonical_original_code:
unsigned int bcm_host_get_peripheral_size()
{
   unsigned int address = get_dt_ranges("/proc/device-tree/soc/ranges", 4);
   address = get_dt_ranges("/proc/device-tree/soc/ranges", (address == 0) ? 12 : 8);
   return address == (unsigned int) ~0 ? 0x01000000 : address;
}


decompiled_code:
__int64 gpio_setup()
{
unsigned int v0; // eax
__int64 result; // rax
unsigned int v2; // ebx
unsigned int v3; // eax
unsigned int v4; // ebx
int v5; // eax
int v6; // ebp
void *v7; // rax
void *v8; // rbx

v0 = get_gpio_revision();
switch ( v0 )
{
case 2u:
gpio_pinmap = &gpio_pinmap_r2;
gpio_pins = 27;
break;
case 3u:
gpio_pinmap = &gpio_pinmap_r3;
gpio_pins = 41;
break;
case 1u:
gpio_pinmap = &gpio_pinmap_r1;
gpio_pins = 27;
break;
default:
puts("Unable to get GPIO revision");
return 0LL;
}
printf("Running on Raspberry pi GPIO revision %d (%d pins)\n", v0, (unsigned int)(gpio_pins - 1));
v2 = bcm_host_get_peripheral_address();
v3 = bcm_host_get_peripheral_size();
printf("Peripheral base 0x%x, length 0x%x\n", v2, v3);
v4 = v2 + 0x200000;
printf("GPIO base 0x%x\n", v4);
v5 = open("/dev/mem", 1052674);
v6 = v5;
if ( v5 < 0 )
{
perror("Unable to open /dev/mem");
result = 0LL;
}
else
{
v7 = mmap(0LL, 0x1000uLL, 3, 1, v5, v4);
v8 = v7;
if ( v7 == (void *)-1LL )
{
perror("mmap error");
result = 0LL;
}
else
{
printf("GPIO mapped to address 0x%lx\n", v7);
close(v6);
gpio = v8;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
unsigned int v0; // eax
__int64 result; // rax
unsigned int v2; // ebx
unsigned int v3; // eax
unsigned int v4; // ebx
int v5; // eax
int v6; // ebp
void *v7; // rax
void *v8; // rbx

v0 = func8();
switch ( v0 )
{
case 2u:
gpio_pinmap = &gpio_pinmap_r2;
gpio_pins = 27;
break;
case 3u:
gpio_pinmap = &gpio_pinmap_r3;
gpio_pins = 41;
break;
case 1u:
gpio_pinmap = &gpio_pinmap_r1;
gpio_pins = 27;
break;
default:
puts("Unable to get GPIO revision");
return 0LL;
}
printf("Running on Raspberry pi GPIO revision %d (%d pins)\n", v0, (unsigned int)(gpio_pins - 1));
v2 = func10();
v3 = func11();
printf("Peripheral base 0x%x, length 0x%x\n", v2, v3);
v4 = v2 + 0x200000;
printf("GPIO base 0x%x\n", v4);
v5 = open("/dev/mem", 1052674);
v6 = v5;
if ( v5 < 0 )
{
perror("Unable to open /dev/mem");
result = 0LL;
}
else
{
v7 = mmap(0LL, 0x1000uLL, 3, 1, v5, v4);
v8 = v7;
if ( v7 == (void *)-1LL )
{
perror("mmap error");
result = 0LL;
}
else
{
printf("GPIO mapped to address 0x%lx\n", v7);
close(v6);
gpio = v8;
result = 1LL;
}
}
return result;
}

original_code:
int gpio_setup()
{
    int mem_fd;
    void *gpio_map = ((void *)0);
    int rpi_revision = 0;
    unsigned peripheral_base;
    unsigned peripheral_len;
    unsigned gpio_base;
    rpi_revision = get_gpio_revision();
    switch (rpi_revision) {
    case 1:
        gpio_pinmap = gpio_pinmap_r1;
        gpio_pins = sizeof(gpio_pinmap_r1) / sizeof(gpio_pinmap_r1[0]);
        break;
    case 2:
        gpio_pinmap = gpio_pinmap_r2;
        gpio_pins = sizeof(gpio_pinmap_r2) / sizeof(gpio_pinmap_r2[0]);
        break;
    case 3:
        gpio_pinmap = gpio_pinmap_r3;
        gpio_pins = sizeof(gpio_pinmap_r3) / sizeof(gpio_pinmap_r3[0]);
        break;
    default:
        printf("Unable to get GPIO revision\n");
        return 0;
    }
    printf("Running on Raspberry pi GPIO revision %d (%d pins)\n", rpi_revision, gpio_pins - 1);
    peripheral_base = bcm_host_get_peripheral_address();
    peripheral_len = bcm_host_get_peripheral_size();
    printf("Peripheral base 0x%x, length 0x%x\n", peripheral_base, peripheral_len);
    gpio_base = peripheral_base + 0x200000;
    printf("GPIO base 0x%x\n", gpio_base);
    if ((mem_fd = open("/dev/mem", 02 | 04010000)) < 0) {
        perror("Unable to open /dev/mem");
        return 0;
    }
    gpio_map = mmap(
                    ((void *)0),
                    4 * 1024,
                    0x1 | 0x2,
                    0x01,
                    mem_fd,
                    gpio_base
                    );
    if (gpio_map == ((void *) -1)) {
        perror("mmap error");
        return 0;
    }
    printf("GPIO mapped to address 0x%lx\n", (unsigned long) gpio_map);
    close(mem_fd);
    gpio = (volatile unsigned *) gpio_map;
    return 1;
}

canonical_original_code:
int gpio_setup()
{
    int mem_fd;
    void *gpio_map = ((void *)0);
    int rpi_revision = 0;
    unsigned int peripheral_base;
    unsigned int peripheral_len;
    unsigned int gpio_base;
    rpi_revision = get_gpio_revision();
    switch (rpi_revision) {
    case 1:
        gpio_pinmap = gpio_pinmap_r1;
        gpio_pins = sizeof(gpio_pinmap_r1) / sizeof(gpio_pinmap_r1[0]);
        break;
    case 2:
        gpio_pinmap = gpio_pinmap_r2;
        gpio_pins = sizeof(gpio_pinmap_r2) / sizeof(gpio_pinmap_r2[0]);
        break;
    case 3:
        gpio_pinmap = gpio_pinmap_r3;
        gpio_pins = sizeof(gpio_pinmap_r3) / sizeof(gpio_pinmap_r3[0]);
        break;
    default:
        printf("Unable to get GPIO revision\n");
        return 0;
    }
    printf("Running on Raspberry pi GPIO revision %d (%d pins)\n", rpi_revision, gpio_pins - 1);
    peripheral_base = bcm_host_get_peripheral_address();
    peripheral_len = bcm_host_get_peripheral_size();
    printf("Peripheral base 0x%x, length 0x%x\n", peripheral_base, peripheral_len);
    gpio_base = peripheral_base + 0x200000;
    printf("GPIO base 0x%x\n", gpio_base);
    if ((mem_fd = open("/dev/mem", 02 | 04010000)) < 0) {
        perror("Unable to open /dev/mem");
        return 0;
    }
    gpio_map = mmap(
                    ((void *)0),
                    4 * 1024,
                    0x1 | 0x2,
                    0x01,
                    mem_fd,
                    gpio_base
                    );
    if (gpio_map == ((void *) -1)) {
        perror("mmap error");
        return 0;
    }
    printf("GPIO mapped to address 0x%lx\n", (unsigned long) gpio_map);
    close(mem_fd);
    gpio = (unsigned int *) gpio_map;
    return 1;
}


decompiled_code:
int __fastcall dump_reg(int a1, const char *a2, unsigned int a3)
{
unsigned int v4; // er12
unsigned int i; // ebx

v4 = *(_DWORD *)(gpio + 4LL * a1);
fprintf(stdout, " GP%-7s : 0x%08x : ", a2, v4);
for ( i = 31; i != -1; --i )
{
if ( (v4 & (1 << i)) != 0 )
putc(49, stdout);
else
putc(48, stdout);
if ( a3 && !(i % a3) )
putc(32, stdout);
}
return fputc(10, stdout);
}

canonical_decompiled_code:
int __fastcall func13(int a1, const char *a2, unsigned int a3)
{
unsigned int v4; // er12
unsigned int i; // ebx

v4 = *(_DWORD *)(gpio + 4LL * a1);
fprintf(stdout, " GP%-7s : 0x%08x : ", a2, v4);
for ( i = 31; i != -1; --i )
{
if ( (v4 & (1 << i)) != 0 )
putc(49, stdout);
else
putc(48, stdout);
if ( a3 && !(i % a3) )
putc(32, stdout);
}
return fputc(10, stdout);
}

original_code:
void dump_reg(int offset, char *name, unsigned bitmod) {
    unsigned value;
    value = *(gpio + offset);
    fprintf(stdout, "  GP%-7s : 0x%08x : ", name, value);
    for (int bit = 31; bit >= 0; bit--) {
        if (value & (1 << bit)) {
            putc('1', stdout);
        } else {
            putc('0', stdout);
        }
        if (bitmod && (bit % bitmod) == 0) {
            putc(' ', stdout);
        }
    }
    fputs("\n", stdout);
}

canonical_original_code:
void dump_reg(int offset, char *name, unsigned int bitmod) {
    unsigned int value;
    value = *(gpio + offset);
    fprintf(stdout, "  GP%-7s : 0x%08x : ", name, value);
    for (int bit = 31; bit >= 0; bit--) {
        if (value & (1 << bit)) {
            putc('1', stdout);
        } else {
            putc('0', stdout);
        }
        if (bitmod && (bit % bitmod) == 0) {
            putc(' ', stdout);
        }
    }
    fputs("\n", stdout);
}

variable_types: offset int

variable_types:
name
char *

variable_types:
bitmod
unsigned int

variable_types:
value
unsigned int

variable_types: bit int


decompiled_code:
int __fastcall dump_regn(int a1, unsigned int a2, const char *a3, unsigned int a4)
{
char v6[72]; // [rsp+0h] [rbp-48h] BYREF

sprintf(v6, "%s%d", a3, a2);
return dump_reg(a2 + a1, v6, a4);
}

canonical_decompiled_code:
int __fastcall func14(int a1, unsigned int a2, const char *a3, unsigned int a4)
{
char v6[72]; // [rsp+0h] [rbp-48h] BYREF

sprintf(v6, "%s%d", a3, a2);
return func13(a2 + a1, v6, a4);
}

original_code:
void dump_regn(int offset, int reg, char *name, unsigned bitmod) {
    char fullname[32];
    sprintf(fullname, "%s%d", name, reg);
    dump_reg(offset + reg, fullname, bitmod);
}

canonical_original_code:
void dump_regn(int offset, int reg, char *name, unsigned int bitmod) {
    char fullname[32];
    sprintf(fullname, "%s%d", name, reg);
    dump_reg(offset + reg, fullname, bitmod);
}

variable_types: reg int

variable_types:
fullname
char [32]


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

if ( gpio_pins <= 1u )
return 0xFFFFFFFFLL;
result = 1LL;
while ( *(_DWORD *)(gpio_pinmap + 4 * result) != a1 )
{
if ( ++result == gpio_pins )
return 0xFFFFFFFFLL;
}
return result;
}

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

if ( gpio_pins <= 1u )
return 0xFFFFFFFFLL;
result = 1LL;
while ( *(_DWORD *)(gpio_pinmap + 4 * result) != a1 )
{
if ( ++result == gpio_pins )
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
int find_pin(int gpio) {
    for (unsigned i = 1; i < gpio_pins; i++) {
        if (gpio_pinmap[i] == gpio) return i;
    }
    return -1;
}

canonical_original_code:
int find_pin(int gpio) {
    for (unsigned int i = 1; i < gpio_pins; i++) {
        if (gpio_pinmap[i] == gpio) return i;
    }
    return -1;
}

variable_types: gpio int

variable_types:
i
unsigned int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
int j; // ebx
int v5; // eax
unsigned int v6; // ebp

if ( !(unsigned int)gpio_setup(argc, argv, envp) )
exit(-1);
puts("Register dump:");
for ( i = 0; i != 6; ++i )
dump_regn(0, i, "FSEL", 3u);
dump_regn(13, 0, "LEV", 4u);
dump_regn(13, 1u, "LEV", 4u);
dump_regn(16, 0, "EDS", 4u);
dump_regn(16, 1u, "EDS", 4u);
dump_regn(19, 0, "REN", 4u);
dump_regn(19, 1u, "REN", 4u);
dump_regn(22, 0, "FEN", 4u);
dump_regn(22, 1u, "FEN", 4u);
dump_regn(25, 0, "HEN", 4u);
dump_regn(25, 1u, "HEN", 4u);
dump_regn(28, 0, "LEN", 4u);
dump_regn(28, 1u, "LEN", 4u);
dump_regn(31, 0, "AREN", 4u);
dump_regn(31, 1u, "AREN", 4u);
dump_regn(34, 0, "AFEN", 4u);
dump_regn(34, 1u, "AFEN", 4u);
dump_reg(37, "PUD", 4u);
dump_regn(38, 0, "PUDCLK", 4u);
dump_regn(38, 1u, "PUDCLK", 4u);
for ( j = 0; j != 54; ++j )
{
printf("GPIO %2d: ", (unsigned int)j);
v5 = find_pin(j);
if ( v5 >= 0 )
printf("pin %d, ", (unsigned int)v5);
v6 = (*(_DWORD *)(gpio + 4LL * (j / 10)) & (unsigned int)(7 << (3 * (j % 10)))) >> (3 * (j % 10));
printf("mode %d, ", v6);
switch ( v6 )
{
case 0u:
printf("input");
break;
case 1u:
printf("output");
break;
case 2u:
printf("alt function 5");
break;
case 3u:
printf("alt function 4");
break;
case 4u:
printf("alt function 0");
break;
case 5u:
printf("alt function 1");
break;
case 6u:
printf("alt function 2");
break;
case 7u:
printf("alt function 3");
break;
default:
break;
}
printf(", level %d ", (*(_DWORD *)(gpio + 4LL * (j / 32 + 13)) & (unsigned int)(1 << (j % 32))) >> (j % 32));
putchar(10);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
int j; // ebx
int v5; // eax
unsigned int v6; // ebp

if ( !(unsigned int)func12(argc, argv, envp) )
exit(-1);
puts("Register dump:");
for ( i = 0; i != 6; ++i )
func14(0, i, "FSEL", 3u);
func14(13, 0, "LEV", 4u);
func14(13, 1u, "LEV", 4u);
func14(16, 0, "EDS", 4u);
func14(16, 1u, "EDS", 4u);
func14(19, 0, "REN", 4u);
func14(19, 1u, "REN", 4u);
func14(22, 0, "FEN", 4u);
func14(22, 1u, "FEN", 4u);
func14(25, 0, "HEN", 4u);
func14(25, 1u, "HEN", 4u);
func14(28, 0, "LEN", 4u);
func14(28, 1u, "LEN", 4u);
func14(31, 0, "AREN", 4u);
func14(31, 1u, "AREN", 4u);
func14(34, 0, "AFEN", 4u);
func14(34, 1u, "AFEN", 4u);
func13(37, "PUD", 4u);
func14(38, 0, "PUDCLK", 4u);
func14(38, 1u, "PUDCLK", 4u);
for ( j = 0; j != 54; ++j )
{
printf("GPIO %2d: ", (unsigned int)j);
v5 = func15(j);
if ( v5 >= 0 )
printf("pin %d, ", (unsigned int)v5);
v6 = (*(_DWORD *)(gpio + 4LL * (j / 10)) & (unsigned int)(7 << (3 * (j % 10)))) >> (3 * (j % 10));
printf("mode %d, ", v6);
switch ( v6 )
{
case 0u:
printf("input");
break;
case 1u:
printf("output");
break;
case 2u:
printf("alt function 5");
break;
case 3u:
printf("alt function 4");
break;
case 4u:
printf("alt function 0");
break;
case 5u:
printf("alt function 1");
break;
case 6u:
printf("alt function 2");
break;
case 7u:
printf("alt function 3");
break;
default:
break;
}
printf(", level %d ", (*(_DWORD *)(gpio + 4LL * (j / 32 + 13)) & (unsigned int)(1 << (j % 32))) >> (j % 32));
putchar(10);
}
return 0;
}

original_code:
int main()
{
    int i;
    int mode;
    if (!gpio_setup()) exit(-1);
    printf("Register dump:\n");
    for (i = 0; i < 6; i++) {
        dump_regn(0, i, "FSEL", 3);
    }
    for (i = 0; i < 2; i++) {
        dump_regn(13, i, "LEV", 4);
    }
    for (i = 0; i < 2; i++) {
        dump_regn(16, i, "EDS", 4);
    }
    for (i = 0; i < 2; i++) {
        dump_regn(19, i, "REN", 4);
    }
    for (i = 0; i < 2; i++) {
        dump_regn(22, i, "FEN", 4);
    }
    for (i = 0; i < 2; i++) {
        dump_regn(25, i, "HEN", 4);
    }
    for (i = 0; i < 2; i++) {
        dump_regn(28, i, "LEN", 4);
    }
    for (i = 0; i < 2; i++) {
        dump_regn(31, i, "AREN", 4);
    }
    for (i = 0; i < 2; i++) {
        dump_regn(34, i, "AFEN", 4);
    }
    dump_reg(37, "PUD", 4);
    for (i = 0; i < 2; i++) {
        dump_regn(38, i, "PUDCLK", 4);
    }
    for (i = 0; i < 54; i++) {
        printf("GPIO %2d: ", i);
        int pin = find_pin(i);
        if (pin >=0 ) {
            printf("pin %d, ", pin);
        }
        mode = (((*(gpio + ((i) / 10))) & (7 << (((i) % 10) * 3))) >> (((i) % 10) * 3));
        printf("mode %d, ", mode);
        switch (mode) {
        case 0:
            printf("input");
            break;
        case 1:
            printf("output");
            break;
        case 4:
            printf("alt function 0");
            break;
        case 5:
            printf("alt function 1");
            break;
        case 6:
            printf("alt function 2");
            break;
        case 7:
            printf("alt function 3");
            break;
        case 3:
            printf("alt function 4");
            break;
        case 2:
            printf("alt function 5");
            break;
        }
        printf(", level %d ", (((*(gpio + (13 + ((i) / 32)))) & (1 << ((i) % 32))) >> ((i) % 32)));
        printf("\n");
    }
    return 0;
}

variable_types: i int

variable_types: mode int

variable_types: pin int


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
printf("Usage: %s {delay in micro seconds}\n", a1);
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func19(const char *a1)
{
printf("Usage: %s {delay in micro seconds}\n", a1);
exit(-1);
}

original_code:
void usage(char *prog)
{
    printf("Usage: %s {delay in micro seconds}\n", prog);
    exit(-1);
}

variable_types:
prog
char *


onfor

decompiled_code:
__int64 __fastcall onfor(int a1, int a2, int a3, int a4, __useconds_t a5)
{
led_on(a1, a2, a3, a4);
usleep(a5);
return led_off(a1);
}

canonical_decompiled_code:
__int64 __fastcall func20(int a1, int a2, int a3, int a4, __useconds_t a5)
{
func17(a1, a2, a3, a4);
usleep(a5);
return func18(a1);
}

original_code:
void onfor(int led, int r, int g, int b, useconds_t usecs)
{
    led_on(led, r, g, b);
    usleep(usecs);
    led_off(led);
}

canonical_original_code:
void onfor(int led, int r, int g, int b, unsigned int usecs)
{
    led_on(led, r, g, b);
    usleep(usecs);
    led_off(led);
}

variable_types: led int

variable_types: r int

variable_types: g int

variable_types: b int

variable_types:
usecs
unsigned int


decompiled_code:
__int64 __fastcall get_pin(unsigned int a1, const char *a2)
{
unsigned int v2; // ebx

v2 = *(_DWORD *)(gpio_pinmap + 4LL * (int)a1);
printf("Header pin %d (%s) is GPIO %d\n", a1, a2, v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1, const char *a2)
{
unsigned int v2; // ebx

v2 = *(_DWORD *)(gpio_pinmap + 4LL * (int)a1);
printf("Header pin %d (%s) is GPIO %d\n", a1, a2, v2);
return v2;
}

original_code:
static int get_pin(int hdr_num, char *desc)
{
    int gpio_num;
    gpio_num = gpio_pinmap[hdr_num];
    printf("Header pin %d (%s) is GPIO %d\n", hdr_num, desc, gpio_num);
    return gpio_num;
}

variable_types:
desc
char *