introChangeState

decompiled_code:
__int64 __fastcall introChangeState(__int64 a1)
{
unsigned int v1; // er8

if ( !buttonPressed )
return 0LL;
buttonPressed = 0;
if ( selectedAlternative == 1 )
{
initGameObjects(1, a1);
v1 = 2;
}
else if ( selectedAlternative == 2 )
{
initGameObjects(0, a1);
v1 = 3;
}
else
{
v1 = 5;
if ( selectedAlternative != 3 )
v1 = 0;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
unsigned int v1; // er8

if ( !buttonPressed )
return 0LL;
buttonPressed = 0;
if ( selectedAlternative == 1 )
{
func11(1, a1);
v1 = 2;
}
else if ( selectedAlternative == 2 )
{
func11(0, a1);
v1 = 3;
}
else
{
v1 = 5;
if ( selectedAlternative != 3 )
v1 = 0;
}
return v1;
}

original_code:
GPngState introChangeState(GPngGame *gPngGame) {
    if (buttonPressed) {
 buttonPressed = 0;
 if (selectedAlternative == OnePlayerGame) {
     initGameObjects(1, gPngGame);
     return GAME_STATE_SINGLE;
 } else if (selectedAlternative == TwoPlayerGame) {
     initGameObjects(0, gPngGame);
     return GAME_STATE_DOUBLE;
 } else if (selectedAlternative == HowToPlay) {
     return HOW_TO_PLAY_STATE;
 } else {
     return MENU_STATE;
 }
    } else {
 return MENU_STATE;
    }
}

canonical_original_code:
enum PNG_STATE introChangeState(struct PONGGAME *gPngGame) {
    if (buttonPressed) {
 buttonPressed = 0;
 if (selectedAlternative == OnePlayerGame) {
     initGameObjects(1, gPngGame);
     return GAME_STATE_SINGLE;
 } else if (selectedAlternative == TwoPlayerGame) {
     initGameObjects(0, gPngGame);
     return GAME_STATE_DOUBLE;
 } else if (selectedAlternative == HowToPlay) {
     return HOW_TO_PLAY_STATE;
 } else {
     return MENU_STATE;
 }
    } else {
 return MENU_STATE;
    }
}

return_type: enum PNG_STATE { MENU_STATE=0, HIGHSCORE_STATE=1, GAME_STATE_SINGLE=2, GAME_STATE_DOUBLE=3, TITLE_STATE=4, HOW_TO_PLAY_STATE=5 }

user_defined_types: enum GRAVITY_DIRECTION { noGravity=8, northGravity=2, northEastGravity=1, eastGravity=0, southEastGravity=7, southGravity=6, southWestGravity=5, westGravity=4, northWestGravity=3 }

user_defined_types: struct PADDLE { int x; int y; int xVel; int yVel; int height; int width; int disabledCounter; unsigned char weight; }

user_defined_types: struct BALL { int x; int y; int xVel; int yVel; int height; int width; int disabledCounter; unsigned char weight; }

user_defined_types: struct COURT { int width; int height; int x; int y; int leftAccAreaX; int leftAccAreaWidth; int rightAccAreaX; int rightAccAreaWidth; }


printLine

repo: andrsoze/gPng

decompiled_code:
__int64 __fastcall printLine(unsigned __int8 a1, unsigned __int8 a2, __int64 a3, int a4)
{
char v6; // dl
__int64 result; // rax
__int64 v8; // rsi
__int64 v9; // rcx
char v10; // dl

v6 = a4;
if ( a1 + a4 > 40 )
v6 = 40 - a1;
result = a1 + 40 * (unsigned int)a2 + 1024;
if ( v6 )
{
result = (unsigned __int16)(a1 + 40 * a2 + 1024);
v8 = a3 - (unsigned __int16)result;
v9 = (unsigned __int8)(v6 - 1) + (__int64)(a1 + 40 * a2 + 1025);
do
{
v10 = *(_BYTE *)(v8 + result++);
*(_BYTE *)(result - 1) = v10;
}
while ( result != v9 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, unsigned __int8 a2, __int64 a3, int a4)
{
char v6; // dl
__int64 result; // rax
__int64 v8; // rsi
__int64 v9; // rcx
char v10; // dl

v6 = a4;
if ( a1 + a4 > 40 )
v6 = 40 - a1;
result = a1 + 40 * (unsigned int)a2 + 1024;
if ( v6 )
{
result = (unsigned __int16)(a1 + 40 * a2 + 1024);
v8 = a3 - (unsigned __int16)result;
v9 = (unsigned __int8)(v6 - 1) + (__int64)(a1 + 40 * a2 + 1025);
do
{
v10 = *(_BYTE *)(v8 + result++);
*(_BYTE *)(result - 1) = v10;
}
while ( result != v9 );
}
return result;
}

original_code:
void printLine(unsigned char indent,
        unsigned char row,
        char* lineOfChars,
        int length)
{
    unsigned char i;
    unsigned char * vidMemDst = (unsigned char*) ((1024) + ((40)*row) + indent);
    int actualLength = (length + indent > (40))?(40)-indent:length;
    unsigned char uchar_actualLength = (unsigned char)actualLength;
    for(i = 0; i < uchar_actualLength; i++){
 *(vidMemDst+i)=lineOfChars[i];
    }
}

canonical_original_code:
void printLine(unsigned char indent, unsigned char row, char *lineOfChars, int length)
{
    unsigned char i;
    unsigned char *vidMemDst = (unsigned char*) ((1024) + ((40)*row) + indent);
    int actualLength = (length + indent > (40))?(40)-indent:length;
    unsigned char uchar_actualLength = (unsigned char)actualLength;
    for(i = 0; i < uchar_actualLength; i++){
 *(vidMemDst+i)=lineOfChars[i];
    }
}

variable_types:
indent
unsigned char

variable_types:
row
unsigned char

variable_types:
lineOfChars
char *

variable_types: length int

variable_types:
i
unsigned char

variable_types:
vidMemDst
unsigned char *

variable_types: actualLength int

return_type: void


clearScreen

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

result = 0x2020202020202020LL;
memset((void *)0x400, 0x20u, 0x3E8uLL);
return result;
}

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

result = 0x2020202020202020LL;
memset((void *)0x400, 0x20u, 0x3E8uLL);
return result;
}

original_code:
void clearScreen(void)
{
    unsigned char *vidMemPtr;
    unsigned char character = ' ';
    int i;
    for(i = 1024; i < 2024; i++) {
 vidMemPtr = (unsigned char *)i;
 (*vidMemPtr)=character;
    }
}

canonical_original_code:
void clearScreen()
{
    unsigned char *vidMemPtr;
    unsigned char character = ' ';
    int i;
    for(i = 1024; i < 2024; i++) {
 vidMemPtr = (unsigned char *)i;
 (*vidMemPtr)=character;
    }
}

variable_types:
vidMemPtr
unsigned char *

variable_types:
character
unsigned char

variable_types: i int


decompiled_code:
void __noreturn events_usage()
{
const char **v0; // rbx
const char *v1; // rsi
const char **v2; // rbx
const char *v3; // rsi
const char **v4; // rbx
const char *v5; // rsi

v0 = (const char **)&sw_events;
puts("Software events:");
v1 = "cpu_clock";
do
{
v0 += 2;
printf(" sw:%s\n", v1);
v1 = *v0;
}
while ( *v0 );
v2 = (const char **)&hw_events;
putchar(10);
puts("Hardware events:");
v3 = "cpu_cycles";
do
{
v2 += 2;
printf(" hw:%s\n", v3);
v3 = *v2;
}
while ( *v2 );
v4 = (const char **)&hwc_events;
putchar(10);
puts("Hardware cache events:");
puts(" Specified on the form 'hwc:cache:operation:result'.");
puts(" Available cache levels:");
v5 = "l1d";
do
{
v4 += 2;
printf(" %s\n", v5);
v5 = *v4;
}
while ( *v4 );
puts(" Available operations:");
puts(" r - Read");
puts(" w - Write");
puts(" p - Prefetch");
puts(" Available results:");
puts(" a - Access");
puts(" m - Miss");
putchar(10);
puts("Raw events:");
puts(" Raw events are specified on the form 'raw:NUM' where NUM is the event number.");
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
const char **v0; // rbx
const char *v1; // rsi
const char **v2; // rbx
const char *v3; // rsi
const char **v4; // rbx
const char *v5; // rsi

v0 = (const char **)&sw_events;
puts("Software events:");
v1 = "cpu_clock";
do
{
v0 += 2;
printf(" sw:%s\n", v1);
v1 = *v0;
}
while ( *v0 );
v2 = (const char **)&hw_events;
putchar(10);
puts("Hardware events:");
v3 = "cpu_cycles";
do
{
v2 += 2;
printf(" hw:%s\n", v3);
v3 = *v2;
}
while ( *v2 );
v4 = (const char **)&hwc_events;
putchar(10);
puts("Hardware cache events:");
puts(" Specified on the form 'hwc:cache:operation:result'.");
puts(" Available cache levels:");
v5 = "l1d";
do
{
v4 += 2;
printf(" %s\n", v5);
v5 = *v4;
}
while ( *v4 );
puts(" Available operations:");
puts(" r - Read");
puts(" w - Write");
puts(" p - Prefetch");
puts(" Available results:");
puts(" a - Access");
puts(" m - Miss");
putchar(10);
puts("Raw events:");
puts(" Raw events are specified on the form 'raw:NUM' where NUM is the event number.");
exit(0);
}

original_code:
static void
events_usage()
{
    printf("Software events:\n");
    for (const event_name_id_t *cur = sw_events; cur->name; cur++)
        printf("  sw:%s\n", cur->name);
    printf("\n");
    printf("Hardware events:\n");
    for (const event_name_id_t *cur = hw_events; cur->name; cur++)
        printf("  hw:%s\n", cur->name);
    printf("\n");
    printf("Hardware cache events:\n");
    printf("  Specified on the form 'hwc:cache:operation:result'.\n");
    printf("  Available cache levels:\n");
    for (const event_name_id_t *cur = hwc_events; cur->name; cur++)
        printf("    %s\n", cur->name);
    printf("  Available operations:\n");
    printf("    r - Read\n");
    printf("    w - Write\n");
    printf("    p - Prefetch\n");
    printf("  Available results:\n");
    printf("    a - Access\n");
    printf("    m - Miss\n");
    printf("\n");
    printf("Raw events:\n");
    printf("  Raw events are specified on the form 'raw:NUM' where NUM "
           "is the event number.\n");
    exit(0);
}

canonical_original_code:
static void events_usage()
{
    printf("Software events:\n");
    for (struct event_name_id_t *cur = sw_events; cur->name; cur++)
        printf("  sw:%s\n", cur->name);
    printf("\n");
    printf("Hardware events:\n");
    for (struct event_name_id_t *cur = hw_events; cur->name; cur++)
        printf("  hw:%s\n", cur->name);
    printf("\n");
    printf("Hardware cache events:\n");
    printf("  Specified on the form 'hwc:cache:operation:result'.\n");
    printf("  Available cache levels:\n");
    for (struct event_name_id_t *cur = hwc_events; cur->name; cur++)
        printf("    %s\n", cur->name);
    printf("  Available operations:\n");
    printf("    r - Read\n");
    printf("    w - Write\n");
    printf("    p - Prefetch\n");
    printf("  Available results:\n");
    printf("    a - Access\n");
    printf("    m - Miss\n");
    printf("\n");
    printf("Raw events:\n");
    printf("  Raw events are specified on the form 'raw:NUM' where NUM "
           "is the event number.\n");
    exit(0);
}

variable_types: struct event_name_id_t { char *name; unsigned long id; } *


decompiled_code:
_BOOL8 __fastcall is_sw_event(unsigned __int8 *a1)
{
int v1; // edx
int v2; // eax
int v3; // edx
_BOOL8 result; // rax

v1 = *a1;
v2 = 115 - v1;
if ( v1 == 115 && (v3 = a1[1], v2 = 119 - v3, v3 == 119) )
result = a1[2] == 58;
else
result = v2 == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(unsigned __int8 *a1)
{
int v1; // edx
int v2; // eax
int v3; // edx
_BOOL8 result; // rax

v1 = *a1;
v2 = 115 - v1;
if ( v1 == 115 && (v3 = a1[1], v2 = 119 - v3, v3 == 119) )
result = a1[2] == 58;
else
result = v2 == 0;
return result;
}

original_code:
static int
is_sw_event(const char *arg)
{
    return !strncmp(prefix_sw_event, arg, sizeof(prefix_sw_event) - 1);
}

canonical_original_code:
static int is_sw_event(char *arg)
{
    return !strncmp(prefix_sw_event, arg, sizeof(prefix_sw_event) - 1);
}

variable_types:
arg
char *

return_type: int


decompiled_code:
_BOOL8 __fastcall is_hw_event(unsigned __int8 *a1)
{
int v1; // edx
int v2; // eax
int v3; // edx
_BOOL8 result; // rax

v1 = *a1;
v2 = 104 - v1;
if ( v1 == 104 && (v3 = a1[1], v2 = 119 - v3, v3 == 119) )
result = a1[2] == 58;
else
result = v2 == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(unsigned __int8 *a1)
{
int v1; // edx
int v2; // eax
int v3; // edx
_BOOL8 result; // rax

v1 = *a1;
v2 = 104 - v1;
if ( v1 == 104 && (v3 = a1[1], v2 = 119 - v3, v3 == 119) )
result = a1[2] == 58;
else
result = v2 == 0;
return result;
}

original_code:
static int
is_hw_event(const char *arg)
{
    return !strncmp(prefix_hw_event, arg, sizeof(prefix_hw_event) - 1);
}

canonical_original_code:
static int is_hw_event(char *arg)
{
    return !strncmp(prefix_hw_event, arg, sizeof(prefix_hw_event) - 1);
}


decompiled_code:
_BOOL8 __fastcall is_hwc_event(char *s2)
{
return strncmp("hwc:", s2, 4uLL) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(char *s2)
{
return strncmp("hwc:", s2, 4uLL) == 0;
}

original_code:
static int
is_hwc_event(const char *arg)
{
    return !strncmp(prefix_hwc_event, arg, sizeof(prefix_hwc_event) - 1);
}

canonical_original_code:
static int is_hwc_event(char *arg)
{
    return !strncmp(prefix_hwc_event, arg, sizeof(prefix_hwc_event) - 1);
}


decompiled_code:
_BOOL8 __fastcall is_raw_event(char *s2)
{
return strncmp("raw:", s2, 4uLL) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(char *s2)
{
return strncmp("raw:", s2, 4uLL) == 0;
}

original_code:
static int
is_raw_event(const char *arg)
{
    return !strncmp(prefix_raw_event, arg, sizeof(prefix_raw_event) - 1);
}

canonical_original_code:
static int is_raw_event(char *arg)
{
    return !strncmp(prefix_raw_event, arg, sizeof(prefix_raw_event) - 1);
}


decompiled_code:
const char *__fastcall find_event(const char **a1, const char *a2, char a3)
{
const char *v3; // rbp
const char **v4; // r12
char v5; // r14
size_t v6; // rbx
char v7; // al

if ( !a2 )
_assert_fail("name", "perf_argp.c", 0xB2u, "find_event");
v3 = *a1;
v4 = a1;
v5 = a3 & 1;
if ( !*a1 )
return v3;
while ( 1 )
{
v6 = (int)strlen(v3);
if ( !strncmp(v3, a2, v6) )
{
v7 = a2[v6];
if ( !v7 || v7 == 58 && v5 )
break;
}
v3 = v4[2];
v4 += 2;
if ( !v3 )
return v3;
}
return (const char *)v4;
}

canonical_decompiled_code:
const char *__fastcall func5(const char **a1, const char *a2, char a3)
{
const char *v3; // rbp
const char **v4; // r12
char v5; // r14
size_t v6; // rbx
char v7; // al

if ( !a2 )
_assert_fail("name", "perf_argp.c", 0xB2u, "find_event");
v3 = *a1;
v4 = a1;
v5 = a3 & 1;
if ( !*a1 )
return v3;
while ( 1 )
{
v6 = (int)strlen(v3);
if ( !strncmp(v3, a2, v6) )
{
v7 = a2[v6];
if ( !v7 || v7 == 58 && v5 )
break;
}
v3 = v4[2];
v4 += 2;
if ( !v3 )
return v3;
}
return (const char *)v4;
}

original_code:
static const event_name_id_t *
find_event(const event_name_id_t *list, const char *name, int extended)
{
    ((void) sizeof ((list) ? 1 : 0), __extension__ ({ if (list) ; else __assert_fail ("list", "perf_argp.c", 177, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((name) ? 1 : 0), __extension__ ({ if (name) ; else __assert_fail ("name", "perf_argp.c", 178, __extension__ __PRETTY_FUNCTION__); }));
    for (const event_name_id_t *cur = list; cur->name; cur++) {
        const int cur_len = strlen(cur->name);
        if (!strncmp(cur->name, name, cur_len) &&
            (name[cur_len] == '\0' || (extended && name[cur_len] == ':')))
            return cur;
    }
    return ((void *)0);
}

canonical_original_code:
static struct event_name_id_t *find_event(struct event_name_id_t *list, char *name, int extended)
{
    ((void) sizeof ((list) ? 1 : 0), __extension__ ({ if (list) ; else __assert_fail ("list", "perf_argp.c", 177, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((name) ? 1 : 0), __extension__ ({ if (name) ; else __assert_fail ("name", "perf_argp.c", 178, __extension__ __PRETTY_FUNCTION__); }));
    for (struct event_name_id_t *cur = list; cur->name; cur++) {
        int cur_len = strlen(cur->name);
        if (!strncmp(cur->name, name, cur_len) &&
            (name[cur_len] == '\0' || (extended && name[cur_len] == ':')))
            return cur;
    }
    return ((void *)0);
}

variable_types:
list
struct event_name_id_t *

variable_types:
name
char *

variable_types: extended int

return_type: struct event_name_id_t { char *name; unsigned long id; } *


decompiled_code:
int create_sig_fd()
{
int result; // eax
const char *v1; // r8
__int64 v2; // rcx
sigset_t v3; // [rsp+0h] [rbp-88h] BYREF

sigemptyset(&v3);
sigaddset(&v3, 17);
sigaddset(&v3, 2);
sigaddset(&v3, 10);
if ( sigprocmask(0, &v3, 0LL) == -1 )
{
v1 = "sigprocmask(SIG_BLOCK, &mask, NULL) != -1";
v2 = 174LL;
goto LABEL_5;
}
result = signalfd(-1, &v3, 0);
if ( result == -1 )
{
v1 = "sfd != -1";
v2 = 176LL;
LABEL_5:
fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", v2, v1);
abort();
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax
const char *v1; // r8
__int64 v2; // rcx
sigset_t v3; // [rsp+0h] [rbp-88h] BYREF

sigemptyset(&v3);
sigaddset(&v3, 17);
sigaddset(&v3, 2);
sigaddset(&v3, 10);
if ( sigprocmask(0, &v3, 0LL) == -1 )
{
v1 = "sigprocmask(SIG_BLOCK, &mask, NULL) != -1";
v2 = 174LL;
goto LABEL_5;
}
result = signalfd(-1, &v3, 0);
if ( result == -1 )
{
v1 = "sfd != -1";
v2 = 176LL;
LABEL_5:
fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", v2, v1);
abort();
}
return result;
}

original_code:
static int
create_sig_fd()
{
    sigset_t mask;
    int sfd;
    sigemptyset(&mask);
    sigaddset(&mask, 17);
    sigaddset(&mask, 2);
    sigaddset(&mask, 10);
    do { if (!(sigprocmask(0, &mask, ((void *)0)) != -1)) { fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 174, "sigprocmask(SIG_BLOCK, &mask, NULL) != -1"); abort(); } } while (0);
    sfd = signalfd(-1, &mask, 0);
    do { if (!(sfd != -1)) { fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 176, "sfd != -1"); abort(); } } while (0);
    return sfd;
}

canonical_original_code:
static int create_sig_fd()
{
    struct __sigset_t mask;
    int sfd;
    sigemptyset(&mask);
    sigaddset(&mask, 17);
    sigaddset(&mask, 2);
    sigaddset(&mask, 10);
    do { if (!(sigprocmask(0, &mask, ((void *)0)) != -1)) { fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 174, "sigprocmask(SIG_BLOCK, &mask, NULL) != -1"); abort(); } } while (0);
    sfd = signalfd(-1, &mask, 0);
    do { if (!(sfd != -1)) { fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 176, "sfd != -1"); abort(); } } while (0);
    return sfd;
}

variable_types: struct __sigset_t { unsigned long __val[-1]; }

variable_types: sfd int


barrier

decompiled_code:
void barrier()
{
_mm_mfence();
}

canonical_decompiled_code:
void func2()
{
_mm_mfence();
}

original_code:
static inline void
barrier()
{
    __sync_synchronize();
}


decompiled_code:
__int64 read_head()
{
__int64 v0; // r8

barrier();
return v0;
}

original_code:
static uint64_t
read_head()
{
    long head;
    head = perf_header->data_head;
    barrier();
    return head;
}

canonical_original_code:
static unsigned long read_head()
{
    long head;
    head = perf_header->data_head;
    barrier();
    return head;
}

variable_types: head long

return_type: unsigned long


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

barrier();
result = perf_header;
*(_QWORD *)(perf_header + 1032) = a1;
return result;
}

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

func2();
result = perf_header;
*(_QWORD *)(perf_header + 1032) = a1;
return result;
}

original_code:
static void
write_tail(uint64_t tail)
{
    barrier();
    perf_header->data_tail = tail;
}

canonical_original_code:
static void write_tail(unsigned long tail)
{
    barrier();
    perf_header->data_tail = tail;
}

variable_types:
tail
unsigned long


decompiled_code:
int __fastcall handle_signal(int a1)
{
ssize_t v1; // rax
__int64 v2; // rdx
int *v3; // rax
char *v4; // rax
int stat_loc; // [rsp+Ch] [rbp-8Ch] BYREF
unsigned int buf[3]; // [rsp+10h] [rbp-88h] BYREF
__pid_t pid; // [rsp+1Ch] [rbp-7Ch]

v1 = read(a1, buf, 0x80uLL);
if ( v1 != 128 )
{
fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 185LL, "read(sfd, &fdsi, sizeof(fdsi)) == sizeof(fdsi)");
abort();
}
if ( buf[0] != 10 )
{
if ( buf[0] == 17 )
{
if ( attach_pid == -1 )
{
if ( exec_pid != -1 )
{
if ( pid == exec_pid )
{
if ( waitpid(pid, &stat_loc, 1) > 0 )
{
dump_events();
v2 = stat_loc & 0x7F;
if ( (stat_loc & 0x7F) != 0 )
{
if ( (char)(v2 + 1) > 1 )
{
fprintf(stderr, "Child terminated by signal '%i'.\n", v2);
if ( (stat_loc & 0x80u) != 0 )
fwrite("Core dumped.\n", 1uLL, 0xDuLL, stderr);
exit(1);
}
fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 220LL, "0");
abort();
}
fprintf(stderr, "Child exited with status '%i'.\n", BYTE1(stat_loc));
exit(BYTE1(stat_loc) != 0);
}
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(
stderr,
"%s:%i: %s\n %s\n",
"perfrecord.c",
206LL,
"waitpid(fdsi.ssi_pid, &status, WNOHANG) > 0",
v4);
abort();
}
_assert_fail("exec_pid == fdsi.ssi_pid", "perfrecord.c", 0xCCu, "handle_signal");
}
_assert_fail("exec_pid != NO_PID", "perfrecord.c", 0xCBu, "handle_signal");
}
_assert_fail("attach_pid == NO_PID", "perfrecord.c", 0xCAu, "handle_signal");
}
if ( buf[0] == 2 )
{
dump_events();
if ( exec_pid == -1 )
exit(0);
fwrite("Sending SIGTERM to child.\n", 1uLL, 0x1AuLL, stderr);
LODWORD(v1) = kill(exec_pid, 15);
}
else
{
LODWORD(v1) = fprintf(stderr, "Unhandled signal: %i\n", buf[0]);
}
}
return v1;
}

canonical_decompiled_code:
int __fastcall func6(int a1)
{
ssize_t v1; // rax
__int64 v2; // rdx
int *v3; // rax
char *v4; // rax
int stat_loc; // [rsp+Ch] [rbp-8Ch] BYREF
unsigned int buf[3]; // [rsp+10h] [rbp-88h] BYREF
__pid_t pid; // [rsp+1Ch] [rbp-7Ch]

v1 = read(a1, buf, 0x80uLL);
if ( v1 != 128 )
{
fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 185LL, "read(sfd, &fdsi, sizeof(fdsi)) == sizeof(fdsi)");
abort();
}
if ( buf[0] != 10 )
{
if ( buf[0] == 17 )
{
if ( attach_pid == -1 )
{
if ( exec_pid != -1 )
{
if ( pid == exec_pid )
{
if ( waitpid(pid, &stat_loc, 1) > 0 )
{
func5();
v2 = stat_loc & 0x7F;
if ( (stat_loc & 0x7F) != 0 )
{
if ( (char)(v2 + 1) > 1 )
{
fprintf(stderr, "Child terminated by signal '%i'.\n", v2);
if ( (stat_loc & 0x80u) != 0 )
fwrite("Core dumped.\n", 1uLL, 0xDuLL, stderr);
exit(1);
}
fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 220LL, "0");
abort();
}
fprintf(stderr, "Child exited with status '%i'.\n", BYTE1(stat_loc));
exit(BYTE1(stat_loc) != 0);
}
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(
stderr,
"%s:%i: %s\n %s\n",
"perfrecord.c",
206LL,
"waitpid(fdsi.ssi_pid, &status, WNOHANG) > 0",
v4);
abort();
}
_assert_fail("exec_pid == fdsi.ssi_pid", "perfrecord.c", 0xCCu, "handle_signal");
}
_assert_fail("exec_pid != NO_PID", "perfrecord.c", 0xCBu, "handle_signal");
}
_assert_fail("attach_pid == NO_PID", "perfrecord.c", 0xCAu, "handle_signal");
}
if ( buf[0] == 2 )
{
func5();
if ( exec_pid == -1 )
exit(0);
fwrite("Sending SIGTERM to child.\n", 1uLL, 0x1AuLL, stderr);
LODWORD(v1) = kill(exec_pid, 15);
}
else
{
LODWORD(v1) = fprintf(stderr, "Unhandled signal: %i\n", buf[0]);
}
}
return v1;
}

original_code:
static void
handle_signal(int sfd)
{
    struct signalfd_siginfo fdsi;
    do { if (!(read(sfd, &fdsi, sizeof(fdsi)) == sizeof(fdsi))) { fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 185, "read(sfd, &fdsi, sizeof(fdsi)) == sizeof(fdsi)"); abort(); } } while (0);
    switch (fdsi.ssi_signo) {
    case 2:
        dump_events();
        if (exec_pid != -1) {
            fprintf(stderr, "Sending SIGTERM to child.\n");
            kill(exec_pid, 15);
        } else
            exit(0);
        break;
    case 17: {
        int status;
        ((void) sizeof ((attach_pid == -1) ? 1 : 0), __extension__ ({ if (attach_pid == -1) ; else __assert_fail ("attach_pid == NO_PID", "perfrecord.c", 202, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((exec_pid != -1) ? 1 : 0), __extension__ ({ if (exec_pid != -1) ; else __assert_fail ("exec_pid != NO_PID", "perfrecord.c", 203, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((exec_pid == fdsi.ssi_pid) ? 1 : 0), __extension__ ({ if (exec_pid == fdsi.ssi_pid) ; else __assert_fail ("exec_pid == fdsi.ssi_pid", "perfrecord.c", 204, __extension__ __PRETTY_FUNCTION__); }));
        do { if (!(waitpid(fdsi.ssi_pid, &status, 1) > 0)) { fprintf(stderr, "%s:%i: %s\n  %s\n", "perfrecord.c", 206, "waitpid(fdsi.ssi_pid, &status, WNOHANG) > 0", strerror((*__errno_location ()))); abort(); } } while (0);
        dump_events();
        if ((((status) & 0x7f) == 0)) {
            fprintf(stderr, "Child exited with status '%i'.\n",
                    (((status) & 0xff00) >> 8));
            exit((((status) & 0xff00) >> 8) == 0 ? 0 : 1);
        } else if ((((signed char) (((status) & 0x7f) + 1) >> 1) > 0)) {
            fprintf(stderr, "Child terminated by signal '%i'.\n",
                    ((status) & 0x7f));
            if (((status) & 0x80))
                fprintf(stderr, "Core dumped.\n");
            exit(1);
        } else
            do { if (!(0)) { fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 220, "0"); abort(); } } while (0);
    } break;
    case 10:
        break;
    default:
        fprintf(stderr, "Unhandled signal: %i\n", fdsi.ssi_signo);
        break;
    }
}

canonical_original_code:
static void handle_signal(int sfd)
{
    struct signalfd_siginfo fdsi;
    do { if (!(read(sfd, &fdsi, sizeof(fdsi)) == sizeof(fdsi))) { fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 185, "read(sfd, &fdsi, sizeof(fdsi)) == sizeof(fdsi)"); abort(); } } while (0);
    switch (fdsi.ssi_signo) {
    case 2:
        dump_events();
        if (exec_pid != -1) {
            fprintf(stderr, "Sending SIGTERM to child.\n");
            kill(exec_pid, 15);
        } else
            exit(0);
        break;
    case 17: {
        int status;
        ((void) sizeof ((attach_pid == -1) ? 1 : 0), __extension__ ({ if (attach_pid == -1) ; else __assert_fail ("attach_pid == NO_PID", "perfrecord.c", 202, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((exec_pid != -1) ? 1 : 0), __extension__ ({ if (exec_pid != -1) ; else __assert_fail ("exec_pid != NO_PID", "perfrecord.c", 203, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((exec_pid == fdsi.ssi_pid) ? 1 : 0), __extension__ ({ if (exec_pid == fdsi.ssi_pid) ; else __assert_fail ("exec_pid == fdsi.ssi_pid", "perfrecord.c", 204, __extension__ __PRETTY_FUNCTION__); }));
        do { if (!(waitpid(fdsi.ssi_pid, &status, 1) > 0)) { fprintf(stderr, "%s:%i: %s\n  %s\n", "perfrecord.c", 206, "waitpid(fdsi.ssi_pid, &status, WNOHANG) > 0", strerror((*__errno_location ()))); abort(); } } while (0);
        dump_events();
        if ((((status) & 0x7f) == 0)) {
            fprintf(stderr, "Child exited with status '%i'.\n",
                    (((status) & 0xff00) >> 8));
            exit((((status) & 0xff00) >> 8) == 0 ? 0 : 1);
        } else if ((((char) (((status) & 0x7f) + 1) >> 1) > 0)) {
            fprintf(stderr, "Child terminated by signal '%i'.\n",
                    ((status) & 0x7f));
            if (((status) & 0x80))
                fprintf(stderr, "Core dumped.\n");
            exit(1);
        } else
            do { if (!(0)) { fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 220, "0"); abort(); } } while (0);
    } break;
    case 10:
        break;
    default:
        fprintf(stderr, "Unhandled signal: %i\n", fdsi.ssi_signo);
        break;
    }
}

variable_types: struct signalfd_siginfo { unsigned int ssi_signo; int ssi_errno; int ssi_code; unsigned int ssi_pid; unsigned int ssi_uid; int ssi_fd; unsigned int ssi_tid; unsigned int ssi_band; unsigned int ssi_overrun; unsigned int ssi_trapno; int ssi_status; int ssi_int; unsigned long ssi_ptr; unsigned long ssi_utime; unsigned long ssi_stime; unsigned long ssi_addr; unsigned char __pad[48]; }

variable_types: status int


decompiled_code:
unsigned __int64 dump_events()
{
unsigned __int64 result; // rax
__int64 v1; // rbp
size_t v2; // rsi
__int64 v3; // rdi
__int64 v4; // rbx

result = read_head();
if ( my_head > result )
_assert_fail("new_head >= my_head", "perfrecord.c", 0x6Au, "dump_events");
if ( my_head != result )
{
v1 = result;
v2 = result - my_head;
v3 = buf_mask & my_head;
if ( (~buf_mask & (result - my_head + (buf_mask & my_head) - 1)) != 0 )
{
v4 = buf_mask & (result - my_head + (buf_mask & my_head));
fwrite((const void *)(perf_buf + v3), v2 - v4, 1uLL, output);
v2 = v4;
v3 = 0LL;
}
if ( fwrite((const void *)(perf_buf + v3), v2, 1uLL, output) != 1 )
{
fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 132LL, "fwrite(perf_buf + start, size, 1, output) == 1");
abort();
}
my_head = v1;
result = write_tail(v1);
}
return result;
}

canonical_decompiled_code:
unsigned __int64 func5()
{
unsigned __int64 result; // rax
__int64 v1; // rbp
size_t v2; // rsi
__int64 v3; // rdi
__int64 v4; // rbx

result = func3();
if ( my_head > result )
_assert_fail("new_head >= my_head", "perfrecord.c", 0x6Au, "dump_events");
if ( my_head != result )
{
v1 = result;
v2 = result - my_head;
v3 = buf_mask & my_head;
if ( (~buf_mask & (result - my_head + (buf_mask & my_head) - 1)) != 0 )
{
v4 = buf_mask & (result - my_head + (buf_mask & my_head));
fwrite((const void *)(perf_buf + v3), v2 - v4, 1uLL, output);
v2 = v4;
v3 = 0LL;
}
if ( fwrite((const void *)(perf_buf + v3), v2, 1uLL, output) != 1 )
{
fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 132LL, "fwrite(perf_buf + start, size, 1, output) == 1");
abort();
}
my_head = v1;
result = func4(v1);
}
return result;
}

original_code:
static void
dump_events()
{
    uint64_t new_head = read_head();
    size_t size, start;
    ((void) sizeof ((new_head >= my_head) ? 1 : 0), __extension__ ({ if (new_head >= my_head) ; else __assert_fail ("new_head >= my_head", "perfrecord.c", 106, __extension__ __PRETTY_FUNCTION__); }));
    if (new_head == my_head)
        return;
    size = new_head - my_head;
    start = my_head & buf_mask;
    if ((start + size - 1) & (~buf_mask)) {
        size_t start_size = (start + size) & buf_mask;
        fwrite(perf_buf + start, size - start_size, 1, output);
        start = 0;
        size = start_size;
    }
    do { if (!(fwrite(perf_buf + start, size, 1, output) == 1)) { fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 132, "fwrite(perf_buf + start, size, 1, output) == 1"); abort(); } } while (0);
    my_head = new_head;
    write_tail(new_head);
}

canonical_original_code:
static void dump_events()
{
    unsigned long new_head = read_head();
    unsigned long size; unsigned long start;
    ((void) sizeof ((new_head >= my_head) ? 1 : 0), __extension__ ({ if (new_head >= my_head) ; else __assert_fail ("new_head >= my_head", "perfrecord.c", 106, __extension__ __PRETTY_FUNCTION__); }));
    if (new_head == my_head)
        return;
    size = new_head - my_head;
    start = my_head & buf_mask;
    if ((start + size - 1) & (~buf_mask)) {
        unsigned long start_size = (start + size) & buf_mask;
        fwrite(perf_buf + start, size - start_size, 1, output);
        start = 0;
        size = start_size;
    }
    do { if (!(fwrite(perf_buf + start, size, 1, output) == 1)) { fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 132, "fwrite(perf_buf + start, size, 1, output) == 1"); abort(); } } while (0);
    my_head = new_head;
    write_tail(new_head);
}

variable_types:
size
unsigned long

variable_types:
start
unsigned long


decompiled_code:
void __noreturn do_start()
{
int v0; // ebx
__int64 v1; // r13
__int64 v2; // rbp
int *v3; // rax
int *v4; // r12
int v5; // eax
char *v6; // rax
const char *v7; // r8
__int64 v8; // rcx
const char *v9; // r9
char *v10; // rax
struct pollfd v11; // [rsp+0h] [rbp-38h] BYREF
int v12; // [rsp+8h] [rbp-30h]
int v13; // [rsp+Ch] [rbp-2Ch]

if ( perf_ctrs )
*(_WORD *)(perf_ctrs + 40LL) |= 0x1001u;
v0 = 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 )
{
v1 = page_size;
perf_header = (__int64)mmap(0LL, 17 * page_size, 3, 1, *(_DWORD *)(perf_ctrs + 112LL), 0LL);
v2 = perf_header;
v3 = _errno_location();
v4 = v3;
if ( v2 == -1 )
{
v10 = strerror(*v3);
v7 = "perf_header != MAP_FAILED";
v8 = 306LL;
v9 = v10;
}
else
{
perf_buf = v1 + v2;
while ( 1 )
{
*(_DWORD *)&v11.events = 1;
v5 = *(_DWORD *)(perf_ctrs + 112LL);
v12 = v0;
v13 = 1;
v11.fd = v5;
if ( poll(&v11, 2uLL, -1) == -1 )
break;
if ( (v11.revents & 1) != 0 )
dump_events();
if ( (v13 & 0x10000) != 0 )
handle_signal(v0);
}
v6 = strerror(*v4);
v7 = "poll(pfd, 2, -1) != -1";
v8 = 317LL;
v9 = v6;
}
fprintf(stderr, "%s:%i: %s\n %s\n", "perfrecord.c", v8, v7, v9);
abort();
}
fprintf(stderr, "%s:%i: %s\n", "perfrecord.c", 299LL, "exec_pid != -1");
abort();
}

canonical_decompiled_code:
void __noreturn func7()
{
int v0; // ebx
__int64 v1; // r13
__int64 v2; // rbp
int *v3; // rax
int *v4; // r12
int v5; // eax
char *v6; // rax
const char *v7; // r8
__int64 v8; // rcx
const char *v9; // r9
char *v10; // rax
struct pollfd v11; // [rsp+0h] [rbp-38h] BYREF
int v12; // [rsp+8h] [rbp-30h]
int v13; // [rsp+Ch] [rbp-2Ch]

if ( perf_ctrs )
*(_WORD *)(perf_ctrs + 40LL) |= 0x1001u;
v0 = func1();
exec_pid = ctrs_execvp_cb(
&perf_ctrs,
(unsigned int)monitor_cpu,
0LL,
setup_child,
0LL,
*(_QWORD *)exec_argv,
exec_argv);
if ( exec_pid != -1 )
{
v1 = page_size;
perf_header = (__int64)mmap(0LL, 17 * page_size, 3, 1, *(_DWORD *)(perf_ctrs + 112LL), 0LL);
v2 = perf_header;
v3 = _errno_location();
v4 = v3;
if ( v2 == -1 )
{
v10 = strerror(*v3);
v7 = "perf_header != MAP_FAILED";
v8 = 306LL;
v9 = v10;
}
else
{
perf_buf = v1 + v2;
while ( 1 )
{
*(_DWORD *)&v11.events = 1;
v5 = *(_DWORD *)(perf_ctrs + 112LL);
v12 = v0;
v13 = 1;
v11.fd = v5;
if ( poll(&v11, 2uLL, -1) == -1 )
break;
if ( (v11.revents & 1) != 0 )
func5();
if ( (v13 & 0x10000) != 0 )
func6(v0);
}
v6 = strerror(*v4);
v7 = "poll(pfd, 2, -1) != -1";
v8 = 317LL;
v9 = v6;
}
fprintf(stderr, "%s:%i: %s\n %s\n", "perfrecord.c", v8, v7, v9);
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; // r13
__int64 v2; // rbp
int *v3; // rax
int *v4; // r12
int v5; // eax
char *v6; // rax
const char *v7; // r8
__int64 v8; // rcx
const char *v9; // r9
char *v10; // rax
struct pollfd v11; // [rsp+0h] [rbp-38h] BYREF
int v12; // [rsp+8h] [rbp-30h]
int v13; // [rsp+Ch] [rbp-2Ch]

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;
perf_header = (__int64)mmap(0LL, 17 * page_size, 3, 1, *(_DWORD *)(perf_ctrs + 112LL), 0LL);
v2 = perf_header;
v3 = _errno_location();
v4 = v3;
if ( v2 == -1 )
{
v10 = strerror(*v3);
v7 = "perf_header != MAP_FAILED";
v8 = 247LL;
v9 = v10;
}
else
{
perf_buf = v1 + v2;
while ( 1 )
{
*(_DWORD *)&v11.events = 1;
v5 = *(_DWORD *)(perf_ctrs + 112LL);
v12 = v0;
v13 = 1;
v11.fd = v5;
if ( poll(&v11, 2uLL, -1) == -1 )
break;
if ( (v11.revents & 1) != 0 )
dump_events();
if ( (v13 & 0x10000) != 0 )
handle_signal(v0);
}
v6 = strerror(*v4);
v7 = "poll(pfd, 2, -1) != -1";
v8 = 258LL;
v9 = v6;
}
fprintf(stderr, "%s:%i: %s\n %s\n", "perfrecord.c", v8, v7, v9);
abort();
}
exit(1);
}

canonical_decompiled_code:
void __noreturn func8()
{
int v0; // ebx
__int64 v1; // r13
__int64 v2; // rbp
int *v3; // rax
int *v4; // r12
int v5; // eax
char *v6; // rax
const char *v7; // r8
__int64 v8; // rcx
const char *v9; // r9
char *v10; // rax
struct pollfd v11; // [rsp+0h] [rbp-38h] BYREF
int v12; // [rsp+8h] [rbp-30h]
int v13; // [rsp+Ch] [rbp-2Ch]

v0 = func1();
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;
perf_header = (__int64)mmap(0LL, 17 * page_size, 3, 1, *(_DWORD *)(perf_ctrs + 112LL), 0LL);
v2 = perf_header;
v3 = _errno_location();
v4 = v3;
if ( v2 == -1 )
{
v10 = strerror(*v3);
v7 = "perf_header != MAP_FAILED";
v8 = 247LL;
v9 = v10;
}
else
{
perf_buf = v1 + v2;
while ( 1 )
{
*(_DWORD *)&v11.events = 1;
v5 = *(_DWORD *)(perf_ctrs + 112LL);
v12 = v0;
v13 = 1;
v11.fd = v5;
if ( poll(&v11, 2uLL, -1) == -1 )
break;
if ( (v11.revents & 1) != 0 )
func5();
if ( (v13 & 0x10000) != 0 )
func6(v0);
}
v6 = strerror(*v4);
v7 = "poll(pfd, 2, -1) != -1";
v8 = 258LL;
v9 = v6;
}
fprintf(stderr, "%s:%i: %s\n %s\n", "perfrecord.c", v8, v7, v9);
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);
    }
}

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


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

if ( force_cpu != -1 )
result = pin_process_constprop_0(force_cpu);
return result;
}

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

if ( force_cpu != -1 )
result = func9(force_cpu);
return result;
}

original_code:
static void
setup_child(void *data)
{
    if (force_cpu != -1)
        pin_process(0, force_cpu);
}

variable_types:
data
void *


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 )
func7();
func8();
}
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 **


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()
{
__int64 v0; // rsi
char *v1; // rax
unsigned int ptr; // [rsp+8h] [rbp-10010h] BYREF
unsigned __int16 v4; // [rsp+Ch] [rbp-1000Ch]
unsigned __int16 v5; // [rsp+Eh] [rbp-1000Ah]
char v6[65544]; // [rsp+10h] [rbp-10008h] BYREF

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

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rsi
char *v1; // rax
unsigned int ptr; // [rsp+8h] [rbp-10010h] BYREF
unsigned __int16 v4; // [rsp+Ch] [rbp-1000Ch]
unsigned __int16 v5; // [rsp+Eh] [rbp-1000Ah]
char v6[65544]; // [rsp+10h] [rbp-10008h] BYREF

if ( fread(&ptr, 8uLL, 1uLL, input) != 1 )
return 0xFFFFFFFFLL;
if ( v5 <= 7u )
_assert_fail("hdr.size >= sizeof(hdr)", "perfdump.c", 0x4Du, "dump_event");
if ( fread(v6, v5 - 8LL, 1uLL, input) != 1 )
return 0xFFFFFFFFLL;
v0 = ptr;
v1 = func0(ptr);
(*((void (__fastcall **)(char *, __int64, _QWORD, _QWORD))v1 + 1))(v6, v0, v4, (unsigned __int16)(v5 - 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)
{
const char *v3; // r8
__int64 v4; // rcx

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);
}
v3 = "ctrs.head";
v4 = 192LL;
}
else
{
v3 = "ctrs_read_header(&ctrs, input) == 1";
v4 = 191LL;
}
fprintf(stderr, "%s:%i: %s\n", "perfdump.c", v4, v3);
abort();
}

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

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);
}
v3 = "ctrs.head";
v4 = 192LL;
}
else
{
v3 = "ctrs_read_header(&ctrs, input) == 1";
v4 = 191LL;
}
fprintf(stderr, "%s:%i: %s\n", "perfdump.c", v4, v3);
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(_QWORD *a1, _WORD *a2)
{
__int64 result; // rax

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

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

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

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(_QWORD **a1, _WORD *a2)
{
if ( *a2 <= 7u )
_assert_fail("*size >= sizeof(uint64_t)", "dumpers.h", 0x51u, "read_uint64_t");
*a2 -= 8;
return *(*a1)++;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD **a1, _WORD *a2)
{
if ( *a2 <= 7u )
_assert_fail("*size >= sizeof(uint64_t)", "dumpers.h", 0x51u, "read_uint64_t");
*a2 -= 8;
return *(*a1)++;
}

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)++; }


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_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 func3(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:
misc
unsigned short

variable_types:
size
unsigned short

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 func4(_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 func5(_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 func6(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 func7(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 func8(_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 func9(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:
data
void *

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


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

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

canonical_decompiled_code:
int __fastcall func13(unsigned int *a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
__int64 v4; // rdx
__int64 v5; // rsi
__int16 v7; // [rsp+6h] [rbp-12h] BYREF
_QWORD *v8; // [rsp+8h] [rbp-10h] BYREF

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

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_SAMPLE(_QWORD *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
_QWORD *v20[4]; // [rsp+8h] [rbp-20h] BYREF

v20[0] = a1;
v4 = *(_QWORD *)(attr + 24);
v19[0] = a4;
result = dump_printf("[SAMPLE]\n");
if ( (v4 & 1) != 0 )
{
v6 = read_uint64_t(v20, v19);
result = dump_printf(" IP: 0x%lx\n", v6);
if ( (v4 & 2) == 0 )
{
LABEL_3:
if ( (v4 & 4) == 0 )
goto LABEL_4;
goto LABEL_15;
}
}
else if ( (v4 & 2) == 0 )
{
goto LABEL_3;
}
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 )
{
LABEL_4:
if ( (v4 & 8) == 0 )
goto LABEL_5;
goto LABEL_16;
}
LABEL_15:
v9 = read_uint64_t(v20, v19);
result = dump_printf(" TIME: %lu\n", v9);
if ( (v4 & 8) == 0 )
{
LABEL_5:
if ( (v4 & 0x40) == 0 )
goto LABEL_6;
goto LABEL_17;
}
LABEL_16:
v10 = read_uint64_t(v20, v19);
result = dump_printf(" ADDR: 0x%lx\n", v10);
if ( (v4 & 0x40) == 0 )
{
LABEL_6:
if ( (v4 & 0x200) == 0 )
goto LABEL_7;
goto LABEL_18;
}
LABEL_17:
v11 = read_uint64_t(v20, v19);
result = dump_printf(" ID: %lu\n", v11);
if ( (v4 & 0x200) == 0 )
{
LABEL_7:
if ( (v4 & 0x80u) == 0LL )
goto LABEL_8;
goto LABEL_19;
}
LABEL_18:
v12 = read_uint64_t(v20, v19);
result = dump_printf(" STREAM_ID: %lu\n", v12);
if ( (v4 & 0x80u) == 0LL )
{
LABEL_8:
if ( (v4 & 0x100) == 0 )
goto LABEL_9;
goto LABEL_20;
}
LABEL_19:
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 )
{
LABEL_9:
if ( (v4 & 0x10) == 0 )
goto LABEL_10;
goto LABEL_21;
}
LABEL_20:
v15 = read_uint64_t(v20, v19);
result = dump_printf(" PERIOD: %lu\n", v15);
if ( (v4 & 0x10) == 0 )
{
LABEL_10:
if ( (v4 & 0x20) == 0 )
goto LABEL_11;
goto LABEL_22;
}
LABEL_21:
result = dump_read_format_isra_0(v20, v19, *(_QWORD *)(attr + 32));
if ( (v4 & 0x20) == 0 )
{
LABEL_11:
if ( (v4 & 0x400) == 0 )
return result;
return dump_printf(" Raw Sample - Unhandled\n");
}
LABEL_22:
v16 = read_uint64_t(v20, v19);
dump_printf(" Call Chain:");
if ( v16 )
{
for ( i = 0LL; i != v16; ++i )
{
v18 = read_uint64_t(v20, v19);
dump_printf(" 0x%lx", v18);
}
}
result = dump_printf("\n");
if ( (v4 & 0x400) != 0 )
return 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:
type
unsigned int

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:
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 v4; // r12
size_t v5; // rbp
ssize_t v7; // rax
int v9; // edi
char *v10; // rax

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

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

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

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 v3; // r13
size_t v6; // rbx
ssize_t v7; // rax
int v8; // edi
char *v9; // rax

v3 = 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 v3;
}

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

v3 = 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 v3;
}

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
__int64 v5[2]; // [rsp+0h] [rbp-68h] BYREF
int v6; // [rsp+10h] [rbp-58h]
struct msghdr message; // [rsp+20h] [rbp-48h] BYREF

v6 = a2;
*(_QWORD *)&message.msg_flags = 0LL;
message.msg_control = v5;
v5[0] = 20LL;
v5[1] = 0x100000001LL;
message.msg_controllen = 20LL;
*(_OWORD *)&message.msg_name = 0LL;
*(_OWORD *)&message.msg_iov = 0LL;
result = sendmsg(a1, &message, 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
__int64 v5[2]; // [rsp+0h] [rbp-68h] BYREF
int v6; // [rsp+10h] [rbp-58h]
struct msghdr message; // [rsp+20h] [rbp-48h] BYREF

v6 = a2;
*(_QWORD *)&message.msg_flags = 0LL;
message.msg_control = v5;
v5[0] = 20LL;
v5[1] = 0x100000001LL;
message.msg_controllen = 20LL;
*(_OWORD *)&message.msg_name = 0LL;
*(_OWORD *)&message.msg_iov = 0LL;
result = sendmsg(a1, &message, 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
__int64 v4; // [rsp+0h] [rbp-68h] BYREF
struct msghdr message; // [rsp+20h] [rbp-48h] BYREF

message.msg_control = &v4;
*(_QWORD *)&message.msg_flags = 0LL;
message.msg_controllen = 24LL;
*(_OWORD *)&message.msg_name = 0LL;
*(_OWORD *)&message.msg_iov = 0LL;
if ( recvmsg(a1, &message, 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 ( message.msg_controllen <= 0xF || !message.msg_control )
{
fwrite("Failed to receive fds, aborting.\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
if ( *((_DWORD *)message.msg_control + 3) != 1 )
_assert_fail("cmsg->cmsg_type == SCM_RIGHTS", "util.c", 0x7Fu, "recv_fd");
return *((unsigned int *)message.msg_control + 4);
}

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

message.msg_control = &v4;
*(_QWORD *)&message.msg_flags = 0LL;
message.msg_controllen = 24LL;
*(_OWORD *)&message.msg_name = 0LL;
*(_OWORD *)&message.msg_iov = 0LL;
if ( recvmsg(a1, &message, 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 ( message.msg_controllen <= 0xF || !message.msg_control )
{
fwrite("Failed to receive fds, aborting.\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
if ( *((_DWORD *)message.msg_control + 3) != 1 )
_assert_fail("cmsg->cmsg_type == SCM_RIGHTS", "util.c", 0x7Fu, "recv_fd");
return *((unsigned int *)message.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(_QWORD **a1, _WORD *a2)
{
if ( *a2 <= 7u )
_assert_fail("*size >= sizeof(uint64_t)", "dumpers.h", 0x51u, "read_uint64_t");
*a2 -= 8;
return *(*a1)++;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD **a1, _WORD *a2)
{
if ( *a2 <= 7u )
_assert_fail("*size >= sizeof(uint64_t)", "dumpers.h", 0x51u, "read_uint64_t");
*a2 -= 8;
return *(*a1)++;
}

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