decompiled_code:
int __fastcall validate_timestamp(__int64 a1)
{
_DWORD *v1; // rax
_DWORD *v2; // r9
__int64 v3; // rcx
char *v4; // rcx

LODWORD(v1) = *(_BYTE *)(a1 + 15) & 0xF0;
if ( (*(_BYTE *)(a1 + 15) & 0xF0) != 16 )
__assert_fail("TRACE_REC_TYPE_TYPED == rec->rec_type", "tools/dump_file_diags.c", 0x6Au, "validate_timestamp");
if ( (*(_BYTE *)(a1 + 14) & 2) != 0 )
{
v2 = *(_DWORD **)a1;
v3 = *(unsigned __int16 *)(a1 + 10);
v1 = (_DWORD *)*((_QWORD *)&thread_access_info + 2 * v3);
if ( *(_QWORD *)a1 > (unsigned __int64)v1 )
{
v4 = (char *)&thread_access_info + 16 * (int)v3;
*(_QWORD *)v4 = v2;
LODWORD(v1) = record_num;
*((_DWORD *)v4 + 2) = record_num;
}
else if ( *(_DWORD **)a1 == v1 )
{
v1 = &show_duplicates;
if ( show_duplicates )
LODWORD(v1) = printf(
"n=%lu: \t\tDuplicate record with sev=%u for thread %u last accessed n=%u, with ts=%llu \n",
*(_QWORD *)&record_num,
*(_BYTE *)(a1 + 15) & 0xF,
v3,
*((unsigned int *)&thread_access_info + 4 * *(unsigned __int16 *)(a1 + 10) + 2),
v2);
}
else if ( show_out_of_order )
{
LODWORD(v1) = printf(
"n=%lu: \t\tOut of order record with sev=%u for thread %u last accessed n=%u, with ts=%llu < %llu\n",
*(_QWORD *)&record_num,
*(_BYTE *)(a1 + 15) & 0xF,
*(unsigned __int16 *)(a1 + 10),
*((unsigned int *)&thread_access_info + 4 * *(unsigned __int16 *)(a1 + 10) + 2),
v2,
*((_QWORD *)&thread_access_info + 2 * *(unsigned __int16 *)(a1 + 10)));
}
}
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
_DWORD *v1; // rax
_DWORD *v2; // r9
__int64 v3; // rcx
char *v4; // rcx

LODWORD(v1) = *(_BYTE *)(a1 + 15) & 0xF0;
if ( (*(_BYTE *)(a1 + 15) & 0xF0) != 16 )
__assert_fail("TRACE_REC_TYPE_TYPED == rec->rec_type", "tools/dump_file_diags.c", 0x6Au, "validate_timestamp");
if ( (*(_BYTE *)(a1 + 14) & 2) != 0 )
{
v2 = *(_DWORD **)a1;
v3 = *(unsigned __int16 *)(a1 + 10);
v1 = (_DWORD *)*((_QWORD *)&thread_access_info + 2 * v3);
if ( *(_QWORD *)a1 > (unsigned __int64)v1 )
{
v4 = (char *)&thread_access_info + 16 * (int)v3;
*(_QWORD *)v4 = v2;
LODWORD(v1) = record_num;
*((_DWORD *)v4 + 2) = record_num;
}
else if ( *(_DWORD **)a1 == v1 )
{
v1 = &show_duplicates;
if ( show_duplicates )
LODWORD(v1) = printf(
"n=%lu: \t\tDuplicate record with sev=%u for thread %u last accessed n=%u, with ts=%llu \n",
*(_QWORD *)&record_num,
*(_BYTE *)(a1 + 15) & 0xF,
v3,
*((unsigned int *)&thread_access_info + 4 * *(unsigned __int16 *)(a1 + 10) + 2),
v2);
}
else if ( show_out_of_order )
{
LODWORD(v1) = printf(
"n=%lu: \t\tOut of order record with sev=%u for thread %u last accessed n=%u, with ts=%llu < %llu\n",
*(_QWORD *)&record_num,
*(_BYTE *)(a1 + 15) & 0xF,
*(unsigned __int16 *)(a1 + 10),
*((unsigned int *)&thread_access_info + 4 * *(unsigned __int16 *)(a1 + 10) + 2),
v2,
*((_QWORD *)&thread_access_info + 2 * *(unsigned __int16 *)(a1 + 10)));
}
}
return (int)v1;
}

original_code:
static void validate_timestamp(const struct trace_record *rec)
{
 ((void) sizeof ((TRACE_REC_TYPE_TYPED == rec->rec_type) ? 1 : 0), __extension__ ({ if (TRACE_REC_TYPE_TYPED == rec->rec_type) ; else __assert_fail ("TRACE_REC_TYPE_TYPED == rec->rec_type", "tools/dump_file_diags.c", 106, __extension__ __PRETTY_FUNCTION__); }));
 trace_pid_t tid = rec->tid;
 if (0 == (rec->termination & TRACE_TERMINATION_FIRST)) {
  return;
 }
 if (rec->ts <= thread_access_info[tid].last_ts) {
  if (rec->ts == thread_access_info[tid].last_ts) {
   if (show_duplicates)
    printf("n=%lu: \t\tDuplicate record with sev=%u for thread %u last accessed n=%u, with ts=%llu \n", record_num, rec->severity, tid, thread_access_info[tid].last_n, rec->ts);
  }
  else if (show_out_of_order) {
   printf("n=%lu: \t\tOut of order record with sev=%u for thread %u last accessed n=%u, with ts=%llu < %llu\n", record_num, rec->severity, tid, thread_access_info[tid].last_n, rec->ts, thread_access_info[tid].last_ts);
  }
 }
 else {
  thread_access_info[tid].last_ts = rec->ts;
  thread_access_info[tid].last_n = record_num;
 }
}

canonical_original_code:
static void validate_timestamp(struct trace_record *rec)
{
 ((void) sizeof ((TRACE_REC_TYPE_TYPED == rec->rec_type) ? 1 : 0), __extension__ ({ if (TRACE_REC_TYPE_TYPED == rec->rec_type) ; else __assert_fail ("TRACE_REC_TYPE_TYPED == rec->rec_type", "tools/dump_file_diags.c", 106, __extension__ __PRETTY_FUNCTION__); }));
 unsigned short tid = rec->tid;
 if (0 == (rec->termination & TRACE_TERMINATION_FIRST)) {
  return;
 }
 if (rec->ts <= thread_access_info[tid].last_ts) {
  if (rec->ts == thread_access_info[tid].last_ts) {
   if (show_duplicates)
    printf("n=%lu: \t\tDuplicate record with sev=%u for thread %u last accessed n=%u, with ts=%llu \n", record_num, rec->severity, tid, thread_access_info[tid].last_n, rec->ts);
  }
  else if (show_out_of_order) {
   printf("n=%lu: \t\tOut of order record with sev=%u for thread %u last accessed n=%u, with ts=%llu < %llu\n", record_num, rec->severity, tid, thread_access_info[tid].last_n, rec->ts, thread_access_info[tid].last_ts);
  }
 }
 else {
  thread_access_info[tid].last_ts = rec->ts;
  thread_access_info[tid].last_n = record_num;
 }
}

variable_types: struct trace_record { unsigned long long ts; unsigned short pid; unsigned short tid; short nesting; short bit_fields[]; unsigned int termination; unsigned int module_id; unsigned int reserved; unsigned int severity; unsigned int rec_type; unsigned int generation; union trace_record_u { unsigned char payload[44]; struct trace_record_typed { unsigned int log_id; unsigned char payload[]; } typed; struct trace_record_file_header { char machine_id[24]; unsigned short format_version; unsigned short flags; unsigned char reserved[4]; unsigned int magic; } file_header; struct trace_record_metadata { unsigned int metadata_size_bytes; unsigned short dead_pids[4]; unsigned char reserved[-1]; unsigned int metadata_magic; } metadata; struct trace_record_dump_header { unsigned int prev_dump_offset; unsigned int total_dump_size; unsigned int first_chunk_offset; unsigned long records_previously_discarded; } dump_header; struct trace_record_buffer_dump { unsigned int last_metadata_offset; unsigned int prev_chunk_offset; unsigned int dump_header_offset; unsigned long long ts; unsigned int records; unsigned int severity_type; unsigned int lost_records; unsigned short flags; unsigned char slack_bytes; } buffer_chunk; struct trace_record_data_loss { unsigned int lost_records; unsigned long long ts_start; unsigned long long ts_end; } data_loss; } u; } *

variable_types:
tid
unsigned short


repo: Infinidat/infinitrace

decompiled_code:
__int64 __fastcall process_records(int fd)
{
unsigned int v1; // ebx
unsigned int v2; // er15
int v3; // er14
unsigned __int8 v4; // dl
__int64 v6; // [rsp+0h] [rbp-78h] BYREF
unsigned __int16 v7; // [rsp+8h] [rbp-70h]
char v8; // [rsp+Eh] [rbp-6Ah]
unsigned __int8 v9; // [rsp+Fh] [rbp-69h]
unsigned int v10; // [rsp+14h] [rbp-64h]
unsigned int v11; // [rsp+18h] [rbp-60h]
unsigned int v12; // [rsp+1Ch] [rbp-5Ch]
__int64 v13; // [rsp+24h] [rbp-54h]
unsigned int v14; // [rsp+2Ch] [rbp-4Ch]
unsigned int v15; // [rsp+30h] [rbp-48h]
unsigned int v16; // [rsp+34h] [rbp-44h]

*(_QWORD *)&record_num = record_range[0];
if ( record_range[0] > record_range[1] )
{
v3 = 0;
}
else
{
v1 = 0;
v2 = 0;
do
{
v3 = read(fd, &v6, 0x40uLL);
if ( v3 != 64 )
break;
if ( (v9 & 0xF0) == 16 )
{
if ( (v8 & 2) != 0 )
{
validate_timestamp((__int64)&v6);
++v1;
}
}
else
{
if ( v1 )
printf("n=%lu: \t\tChunk ended with %u records\n", *(_QWORD *)&record_num, v1);
v4 = v9 >> 4;
if ( (v9 & 0x80u) != 0 )
{
LABEL_20:
printf("n=%lu: Unrecognized record of type %d\n", *(_QWORD *)&record_num, v4);
v1 = 0;
}
else
{
switch ( v4 )
{
case 0u:
case 1u:
goto LABEL_20;
case 2u:
printf(
"n=%lu: Start of file. Format ver=%X, flags = %X\n",
*(_QWORD *)&record_num,
(unsigned __int16)v14,
HIWORD(v14));
v1 = 0;
break;
case 3u:
printf(
"n=%lu: \tStart of %u byte (%u records) metadata block for pid=%u\n",
*(_QWORD *)&record_num,
v10,
(v10 + 43) / 0x2CuLL,
v7);
v1 = 0;
v2 = 0;
break;
case 4u:
if ( (v8 & 1) != 0 )
{
printf("n=%lu: \tEnd of metadata block of %u records for pid=%u\n", *(_QWORD *)&record_num, v2, v7);
v1 = 0;
v2 = 0;
}
else
{
++v2;
v1 = 0;
}
break;
case 5u:
printf("n=%lu: \tDump size=%u, first chunk at %u\n", *(_QWORD *)&record_num, v11, v12);
v1 = 0;
break;
case 6u:
printf(
"n=%lu: \t\tChunk recs=%u, ts=%llu, sev_mask=%X, lost=%u\n",
*(_QWORD *)&record_num,
v14,
v13,
v15,
v16);
v1 = 0;
break;
case 7u:
printf("n=%lu: End of file\n", *(_QWORD *)&record_num);
v1 = 0;
break;
}
}
}
++*(_QWORD *)&record_num;
}
while ( *(_QWORD *)&record_num <= record_range[1] );
}
return print_end_diagnostics(v3);
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd)
{
unsigned int v1; // ebx
unsigned int v2; // er15
int v3; // er14
unsigned __int8 v4; // dl
__int64 v6; // [rsp+0h] [rbp-78h] BYREF
unsigned __int16 v7; // [rsp+8h] [rbp-70h]
char v8; // [rsp+Eh] [rbp-6Ah]
unsigned __int8 v9; // [rsp+Fh] [rbp-69h]
unsigned int v10; // [rsp+14h] [rbp-64h]
unsigned int v11; // [rsp+18h] [rbp-60h]
unsigned int v12; // [rsp+1Ch] [rbp-5Ch]
__int64 v13; // [rsp+24h] [rbp-54h]
unsigned int v14; // [rsp+2Ch] [rbp-4Ch]
unsigned int v15; // [rsp+30h] [rbp-48h]
unsigned int v16; // [rsp+34h] [rbp-44h]

*(_QWORD *)&record_num = record_range[0];
if ( record_range[0] > record_range[1] )
{
v3 = 0;
}
else
{
v1 = 0;
v2 = 0;
do
{
v3 = read(fd, &v6, 0x40uLL);
if ( v3 != 64 )
break;
if ( (v9 & 0xF0) == 16 )
{
if ( (v8 & 2) != 0 )
{
func9((__int64)&v6);
++v1;
}
}
else
{
if ( v1 )
printf("n=%lu: \t\tChunk ended with %u records\n", *(_QWORD *)&record_num, v1);
v4 = v9 >> 4;
if ( (v9 & 0x80u) != 0 )
{
LABEL_20:
printf("n=%lu: Unrecognized record of type %d\n", *(_QWORD *)&record_num, v4);
v1 = 0;
}
else
{
switch ( v4 )
{
case 0u:
case 1u:
goto LABEL_20;
case 2u:
printf(
"n=%lu: Start of file. Format ver=%X, flags = %X\n",
*(_QWORD *)&record_num,
(unsigned __int16)v14,
HIWORD(v14));
v1 = 0;
break;
case 3u:
printf(
"n=%lu: \tStart of %u byte (%u records) metadata block for pid=%u\n",
*(_QWORD *)&record_num,
v10,
(v10 + 43) / 0x2CuLL,
v7);
v1 = 0;
v2 = 0;
break;
case 4u:
if ( (v8 & 1) != 0 )
{
printf("n=%lu: \tEnd of metadata block of %u records for pid=%u\n", *(_QWORD *)&record_num, v2, v7);
v1 = 0;
v2 = 0;
}
else
{
++v2;
v1 = 0;
}
break;
case 5u:
printf("n=%lu: \tDump size=%u, first chunk at %u\n", *(_QWORD *)&record_num, v11, v12);
v1 = 0;
break;
case 6u:
printf(
"n=%lu: \t\tChunk recs=%u, ts=%llu, sev_mask=%X, lost=%u\n",
*(_QWORD *)&record_num,
v14,
v13,
v15,
v16);
v1 = 0;
break;
case 7u:
printf("n=%lu: End of file\n", *(_QWORD *)&record_num);
v1 = 0;
break;
}
}
}
++*(_QWORD *)&record_num;
}
while ( *(_QWORD *)&record_num <= record_range[1] );
}
return func7(v3);
}

original_code:
static int process_records(int fd)
{
 unsigned metadata_len = 0;
 unsigned data_records = 0;
 int rc = 0;
 struct trace_record rec;
 for (record_num = record_range[0]; record_num <= record_range[1] ; record_num++) {
  rc = read(fd, &rec, 64U);
  if (64U != rc) {
   break;
  }
  if (TRACE_REC_TYPE_TYPED == rec.rec_type) {
   if (TRACE_TERMINATION_FIRST & rec.termination) {
    validate_timestamp(&rec);
    data_records++;
   }
   continue;
  }
  if (data_records > 0) {
   printf("n=%lu: \t\tChunk ended with %u records\n", record_num, data_records);
  }
  data_records = 0;
  switch(rec.rec_type) {
  case TRACE_REC_TYPE_METADATA_PAYLOAD:
   if (rec.termination & TRACE_TERMINATION_LAST) {
    printf("n=%lu: \tEnd of metadata block of %u records for pid=%u\n", record_num, metadata_len, rec.pid);
    metadata_len = 0;
   }
   else metadata_len++;
   break;
  case TRACE_REC_TYPE_METADATA_HEADER:
   printf("n=%lu: \tStart of %u byte (%u records) metadata block for pid=%u\n",
     record_num, rec.u.metadata.metadata_size_bytes,
     (rec.u.metadata.metadata_size_bytes + 44U - 1) / 44U, rec.pid);
   metadata_len = 0;
   break;
  case TRACE_REC_TYPE_DUMP_HEADER:
   printf("n=%lu: \tDump size=%u, first chunk at %u\n", record_num, rec.u.dump_header.total_dump_size, rec.u.dump_header.first_chunk_offset);
   break;
  case TRACE_REC_TYPE_BUFFER_CHUNK:
   printf("n=%lu: \t\tChunk recs=%u, ts=%llu, sev_mask=%X, lost=%u\n",
     record_num,
     rec.u.buffer_chunk.records,
     rec.u.buffer_chunk.ts,
     rec.u.buffer_chunk.severity_type,
     rec.u.buffer_chunk.lost_records);
   break;
  case TRACE_REC_TYPE_FILE_HEADER:
   printf("n=%lu: Start of file. Format ver=%X, flags = %X\n", record_num, rec.u.file_header.format_version, rec.u.file_header.flags);
   break;
  case TRACE_REC_TYPE_END_OF_FILE:
   printf("n=%lu: End of file\n", record_num);
   break;
  default:
   printf("n=%lu: Unrecognized record of type %d\n", record_num, rec.rec_type);
   break;
  }
 }
 return print_end_diagnostics(rc);
}

canonical_original_code:
static int process_records(int fd)
{
 unsigned int metadata_len = 0;
 unsigned int data_records = 0;
 int rc = 0;
 struct trace_record rec;
 for (record_num = record_range[0]; record_num <= record_range[1] ; record_num++) {
  rc = read(fd, &rec, 64U);
  if (64U != rc) {
   break;
  }
  if (TRACE_REC_TYPE_TYPED == rec.rec_type) {
   if (TRACE_TERMINATION_FIRST & rec.termination) {
    validate_timestamp(&rec);
    data_records++;
   }
   continue;
  }
  if (data_records > 0) {
   printf("n=%lu: \t\tChunk ended with %u records\n", record_num, data_records);
  }
  data_records = 0;
  switch(rec.rec_type) {
  case TRACE_REC_TYPE_METADATA_PAYLOAD:
   if (rec.termination & TRACE_TERMINATION_LAST) {
    printf("n=%lu: \tEnd of metadata block of %u records for pid=%u\n", record_num, metadata_len, rec.pid);
    metadata_len = 0;
   }
   else metadata_len++;
   break;
  case TRACE_REC_TYPE_METADATA_HEADER:
   printf("n=%lu: \tStart of %u byte (%u records) metadata block for pid=%u\n",
     record_num, rec.u.metadata.metadata_size_bytes,
     (rec.u.metadata.metadata_size_bytes + 44U - 1) / 44U, rec.pid);
   metadata_len = 0;
   break;
  case TRACE_REC_TYPE_DUMP_HEADER:
   printf("n=%lu: \tDump size=%u, first chunk at %u\n", record_num, rec.u.dump_header.total_dump_size, rec.u.dump_header.first_chunk_offset);
   break;
  case TRACE_REC_TYPE_BUFFER_CHUNK:
   printf("n=%lu: \t\tChunk recs=%u, ts=%llu, sev_mask=%X, lost=%u\n",
     record_num,
     rec.u.buffer_chunk.records,
     rec.u.buffer_chunk.ts,
     rec.u.buffer_chunk.severity_type,
     rec.u.buffer_chunk.lost_records);
   break;
  case TRACE_REC_TYPE_FILE_HEADER:
   printf("n=%lu: Start of file. Format ver=%X, flags = %X\n", record_num, rec.u.file_header.format_version, rec.u.file_header.flags);
   break;
  case TRACE_REC_TYPE_END_OF_FILE:
   printf("n=%lu: End of file\n", record_num);
   break;
  default:
   printf("n=%lu: Unrecognized record of type %d\n", record_num, rec.rec_type);
   break;
  }
 }
 return print_end_diagnostics(rc);
}

variable_types: fd int

variable_types: rc int

variable_types: struct trace_record { unsigned long long ts; unsigned short pid; unsigned short tid; short nesting; short bit_fields[]; unsigned int termination; unsigned int module_id; unsigned int reserved; unsigned int severity; unsigned int rec_type; unsigned int generation; union trace_record_u { unsigned char payload[44]; struct trace_record_typed { unsigned int log_id; unsigned char payload[]; } typed; struct trace_record_file_header { char machine_id[24]; unsigned short format_version; unsigned short flags; unsigned char reserved[4]; unsigned int magic; } file_header; struct trace_record_metadata { unsigned int metadata_size_bytes; unsigned short dead_pids[4]; unsigned char reserved[-1]; unsigned int metadata_magic; } metadata; struct trace_record_dump_header { unsigned int prev_dump_offset; unsigned int total_dump_size; unsigned int first_chunk_offset; unsigned long records_previously_discarded; } dump_header; struct trace_record_buffer_dump { unsigned int last_metadata_offset; unsigned int prev_chunk_offset; unsigned int dump_header_offset; unsigned long long ts; unsigned int records; unsigned int severity_type; unsigned int lost_records; unsigned short flags; unsigned char slack_bytes; } buffer_chunk; struct trace_record_data_loss { unsigned int lost_records; unsigned long long ts_start; unsigned long long ts_end; } data_loss; } u; }

return_type: int

user_defined_types: struct trace_record { unsigned long long ts; unsigned short pid; unsigned short tid; short nesting; short bit_fields[]; unsigned int termination; unsigned int module_id; unsigned int reserved; unsigned int severity; unsigned int rec_type; unsigned int generation; union trace_record_u u; }

user_defined_types: union trace_record_u { unsigned char payload[44]; struct trace_record_typed typed; struct trace_record_file_header file_header; struct trace_record_metadata metadata; struct trace_record_dump_header dump_header; struct trace_record_buffer_dump buffer_chunk; struct trace_record_data_loss data_loss; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // ebx
_QWORD *v5; // rdx
int *v6; // rax
char *v7; // rax

result = parse_options(argc, (char **)argv);
if ( result )
{
if ( result == 1 )
result = 0;
}
else
{
while ( 1 )
{
v4 = open((const char *)*filenames, 0);
if ( v4 < 0 )
break;
if ( (int)lseek64(v4, record_range[0] << 6, 0) < 0 )
{
v6 = __errno_location();
v7 = strerror(*v6);
fprintf(stderr, "Could not seek to record %lu in %s due to %s", record_range[0], (const char *)*filenames, v7);
return 65;
}
result = process_records(v4);
if ( !result )
{
v5 = filenames++;
if ( *v5 )
continue;
}
return result;
}
result = 66;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // ebx
_QWORD *v5; // rdx
int *v6; // rax
char *v7; // rax

result = func8(argc, (char **)argv);
if ( result )
{
if ( result == 1 )
result = 0;
}
else
{
while ( 1 )
{
v4 = open((const char *)*filenames, 0);
if ( v4 < 0 )
break;
if ( (int)lseek64(v4, record_range[0] << 6, 0) < 0 )
{
v6 = __errno_location();
v7 = strerror(*v6);
fprintf(stderr, "Could not seek to record %lu in %s due to %s", record_range[0], (const char *)*filenames, v7);
return 65;
}
result = func10(v4);
if ( !result )
{
v5 = filenames++;
if ( *v5 )
continue;
}
return result;
}
result = 66;
}
return result;
}

original_code:
int main(int argc, const char *argv[])
{
 int rc = parse_options(argc, argv);
 switch (rc) {
 case 1:
  return 0;
 case 0:
  break;
 default:
  return rc;
 }
 do {
  int fd = open(*filenames, 00);
  if (fd < 0) {
   rc = 66;
  }
  else {
   rc = lseek64(fd, record_range[0] * 64U, 0);
   if (rc < 0) {
    fprintf(stderr, "Could not seek to record %lu in %s due to %s", record_range[0], *filenames, strerror((*__errno_location ())));
    rc = 65;
   }
   else {
    rc = process_records(fd);
   }
  }
 } while((0 == rc) && (*(filenames++) != ((void *)0)));
 return rc;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int rc = parse_options(argc, argv);
 switch (rc) {
 case 1:
  return 0;
 case 0:
  break;
 default:
  return rc;
 }
 do {
  int fd = open(*filenames, 00);
  if (fd < 0) {
   rc = 66;
  }
  else {
   rc = lseek64(fd, record_range[0] * 64U, 0);
   if (rc < 0) {
    fprintf(stderr, "Could not seek to record %lu in %s due to %s", record_range[0], *filenames, strerror((*__errno_location ())));
    rc = 65;
   }
   else {
    rc = process_records(fd);
   }
  }
 } while((0 == rc) && (*(filenames++) != ((void *)0)));
 return rc;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 __fastcall trace_delete_shm_if_necessary(char *name)
{
int *v1; // rbx
int v2; // er12

v1 = _errno_location();
v2 = *v1;
if ( shm_unlink(name) < 0 && *v1 != 2 )
return 0xFFFFFFFFLL;
*v1 = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *name)
{
int *v1; // rbx
int v2; // er12

v1 = _errno_location();
v2 = *v1;
if ( shm_unlink(name) < 0 && *v1 != 2 )
return 0xFFFFFFFFLL;
*v1 = v2;
return 0LL;
}

original_code:
int trace_delete_shm_if_necessary(const char *shm_name) {
    const int saved_errno = (*__errno_location ());
    if ((shm_unlink(shm_name) < 0) && (2 != (*__errno_location ()))) {
        return -1;
    }
    (*__errno_location ()) = saved_errno;
    return 0;
}

canonical_original_code:
int trace_delete_shm_if_necessary(char *shm_name) {
    int saved_errno = (*__errno_location ());
    if ((shm_unlink(shm_name) < 0) && (2 != (*__errno_location ()))) {
        return -1;
    }
    (*__errno_location ()) = saved_errno;
    return 0;
}


decompiled_code:
__int64 __fastcall trace_shm_delete_files(int a1)
{
int v1; // ebx
int v2; // ebp
int v4[2]; // [rsp+0h] [rbp-A8h] BYREF
__int64 v5; // [rsp+8h] [rbp-A0h]
__int64 v6; // [rsp+10h] [rbp-98h]
char name[136]; // [rsp+20h] [rbp-88h] BYREF

v5 = 0LL;
v6 = 0LL;
v4[0] = a1;
v1 = 0;
v2 = 0;
do
{
v4[1] = v1;
if ( (int)trace_generate_shm_name(name, v4, 2LL, 0LL) <= 0 )
_assert_fail(
"(trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0) || TRACE_LOG_ASS"
"ERTION_FAILURE(trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0)",
"trace_shm_util.c",
0x32u,
"trace_shm_delete_files");
v2 |= trace_delete_shm_if_necessary(name);
++v1;
}
while ( v1 != 16 );
if ( (int)trace_generate_shm_name(name, v4, 1LL, 0LL) <= 0 )
_assert_fail(
"(trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_DYNAMIC, (0)) > 0) || TRACE_LOG_ASSERTION_FAILUR"
"E(trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_DYNAMIC, (0)) > 0)",
"trace_shm_util.c",
0x36u,
"trace_shm_delete_files");
return v2 | (unsigned int)trace_delete_shm_if_necessary(name);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // ebx
int v2; // ebp
int v4[2]; // [rsp+0h] [rbp-A8h] BYREF
__int64 v5; // [rsp+8h] [rbp-A0h]
__int64 v6; // [rsp+10h] [rbp-98h]
char name[136]; // [rsp+20h] [rbp-88h] BYREF

v5 = 0LL;
v6 = 0LL;
v4[0] = a1;
v1 = 0;
v2 = 0;
do
{
v4[1] = v1;
if ( (int)trace_generate_shm_name(name, v4, 2LL, 0LL) <= 0 )
_assert_fail(
"(trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0) || TRACE_LOG_ASS"
"ERTION_FAILURE(trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0)",
"trace_shm_util.c",
0x32u,
"trace_shm_delete_files");
v2 |= func0(name);
++v1;
}
while ( v1 != 16 );
if ( (int)trace_generate_shm_name(name, v4, 1LL, 0LL) <= 0 )
_assert_fail(
"(trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_DYNAMIC, (0)) > 0) || TRACE_LOG_ASSERTION_FAILUR"
"E(trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_DYNAMIC, (0)) > 0)",
"trace_shm_util.c",
0x36u,
"trace_shm_delete_files");
return v2 | (unsigned int)func0(name);
}

original_code:
int trace_shm_delete_files(pid_t pid)
{
    int rc = 0;
    trace_shm_name_buf trace_shm_name;
    struct trace_shm_module_details details = {
            .pid = pid,
    };
    for (trace_module_id_t i = 0; i < TRACE_MODULE_ID_COUNT; i++) {
        details.module_id = i,
        ((void) sizeof (((trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0) || (0)) ? 1 : 0), __extension__ ({ if ((trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0) || (0)) ; else __assert_fail ("(trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0) || TRACE_LOG_ASSERTION_FAILURE(trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0)", "trace_shm_util.c", 50, __extension__ __PRETTY_FUNCTION__); }));
        rc |= trace_delete_shm_if_necessary(trace_shm_name);
    }
    ((void) sizeof (((trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_DYNAMIC, (0)) > 0) || (0)) ? 1 : 0), __extension__ ({ if ((trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_DYNAMIC, (0)) > 0) || (0)) ; else __assert_fail ("(trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_DYNAMIC, (0)) > 0) || TRACE_LOG_ASSERTION_FAILURE(trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_DYNAMIC, (0)) > 0)", "trace_shm_util.c", 54, __extension__ __PRETTY_FUNCTION__); }));
    rc |= trace_delete_shm_if_necessary(trace_shm_name);
    return rc;
}

canonical_original_code:
int trace_shm_delete_files(int pid)
{
    int rc = 0;
    char trace_shm_name[-1];
    struct trace_shm_module_details details = {
            .pid = pid,
    };
    for (unsigned int i = 0; i < TRACE_MODULE_ID_COUNT; i++) {
        details.module_id = i,
        ((void) sizeof (((trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0) || (0)) ? 1 : 0), __extension__ ({ if ((trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0) || (0)) ; else __assert_fail ("(trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0) || TRACE_LOG_ASSERTION_FAILURE(trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_STATIC_PER_PROCESS, (0)) > 0)", "trace_shm_util.c", 50, __extension__ __PRETTY_FUNCTION__); }));
        rc |= trace_delete_shm_if_necessary(trace_shm_name);
    }
    ((void) sizeof (((trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_DYNAMIC, (0)) > 0) || (0)) ? 1 : 0), __extension__ ({ if ((trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_DYNAMIC, (0)) > 0) || (0)) ; else __assert_fail ("(trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_DYNAMIC, (0)) > 0) || TRACE_LOG_ASSERTION_FAILURE(trace_generate_shm_name(trace_shm_name, &details, TRACE_SHM_TYPE_DYNAMIC, (0)) > 0)", "trace_shm_util.c", 54, __extension__ __PRETTY_FUNCTION__); }));
    rc |= trace_delete_shm_if_necessary(trace_shm_name);
    return rc;
}

variable_types: pid int

variable_types: struct trace_shm_module_details { int pid; unsigned int module_id; char *file_name; char *file_dir; }

variable_types:
i
unsigned int


decompiled_code:
int __fastcall trace_open_shm(const char *a1)
{
return shm_open(a1, 578, 0x1B0u);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
return shm_open(a1, 578, 0x1B0u);
}


decompiled_code:
char *trace_shm_get_path()
{
return shm_dir_path;
}

canonical_decompiled_code:
char *func3()
{
return shm_dir_path;
}

original_code:
const char *trace_shm_get_path(void)
{
    return shm_dir_path;
}

return_type: char *


decompiled_code:
__int64 __fastcall perform_2_path_operation_in_shm_dir(__int64 (__fastcall *a1)(char *, char *), const char *a2, const char *a3)
{
char *v4; // rax
size_t v5; // r14
void *v6; // rsp
char *v7; // rax
void *v8; // rsp
char *v9; // rax
char v11[8]; // [rsp+0h] [rbp-40h] BYREF
__int64 (__fastcall *v12)(char *, char *); // [rsp+8h] [rbp-38h]

v12 = a1;
v4 = trace_shm_get_path();
v5 = strlen(v4);
v6 = alloca(16 * ((v5 + strlen(a2) + 33) / 0x10));
v7 = trace_shm_get_path();
sprintf(v11, "%s/%s", v7, a2);
v8 = alloca(16 * ((v5 + strlen(a3) + 33) / 0x10));
v9 = trace_shm_get_path();
sprintf(v11, "%s/%s", v9, a3);
return v12(v11, v11);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 (__fastcall *a1)(char *, char *), const char *a2, const char *a3)
{
char *v4; // rax
size_t v5; // r14
void *v6; // rsp
char *v7; // rax
void *v8; // rsp
char *v9; // rax
char v11[8]; // [rsp+0h] [rbp-40h] BYREF
__int64 (__fastcall *v12)(char *, char *); // [rsp+8h] [rbp-38h]

v12 = a1;
v4 = func3();
v5 = strlen(v4);
v6 = alloca(16 * ((v5 + strlen(a2) + 33) / 0x10));
v7 = func3();
sprintf(v11, "%s/%s", v7, a2);
v8 = alloca(16 * ((v5 + strlen(a3) + 33) / 0x10));
v9 = func3();
sprintf(v11, "%s/%s", v9, a3);
return v12(v11, v11);
}

original_code:
static int perform_2_path_operation_in_shm_dir(
        int (*func)(const char *p1, const char *p2),
        const char *file1,
        const char *file2)
{
    const size_t len_dir = strlen(trace_shm_get_path());
    const size_t len1 = strlen(file1); char *const path1 = __builtin_alloca (len_dir + len1 + 10); sprintf(path1, "%s/%s", trace_shm_get_path(), file1);;
    const size_t len2 = strlen(file2); char *const path2 = __builtin_alloca (len_dir + len2 + 10); sprintf(path2, "%s/%s", trace_shm_get_path(), file2);;
    return func(path1, path2);
}

canonical_original_code:
static int perform_2_path_operation_in_shm_dir(int (*func)(char *p1, char *p2), char *file1, char *file2)
{
    unsigned long len_dir = strlen(trace_shm_get_path());
    unsigned long len1 = strlen(file1); char *path1 = __builtin_alloca (len_dir + len1 + 10); sprintf(path1, "%s/%s", trace_shm_get_path(), file1);;
    unsigned long len2 = strlen(file2); char *path2 = __builtin_alloca (len_dir + len2 + 10); sprintf(path2, "%s/%s", trace_shm_get_path(), file2);;
    return func(path1, path2);
}

variable_types:
func
int (*)(char *p1, char *p2)


decompiled_code:
__int64 __fastcall trace_shm_rename(const char *a1, char *a2)
{
__int64 result; // rax

if ( (int)trace_delete_shm_if_necessary(a2) < 0 )
result = 0xFFFFFFFFLL;
else
result = perform_2_path_operation_in_shm_dir((__int64 (__fastcall *)(char *, char *))&rename, a1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, char *a2)
{
__int64 result; // rax

if ( (int)func0(a2) < 0 )
result = 0xFFFFFFFFLL;
else
result = func4((__int64 (__fastcall *)(char *, char *))&rename, a1, a2);
return result;
}

original_code:
int trace_shm_rename(const char *old_name, const char *new_name) {
    if (trace_delete_shm_if_necessary(new_name) < 0) {
        return -1;
    }
    return perform_2_path_operation_in_shm_dir(rename, old_name, new_name);
}

canonical_original_code:
int trace_shm_rename(char *old_name, char *new_name) {
    if (trace_delete_shm_if_necessary(new_name) < 0) {
        return -1;
    }
    return perform_2_path_operation_in_shm_dir(rename, old_name, new_name);
}


decompiled_code:
__int64 __fastcall trace_shm_duplicate(const char *a1, char *a2)
{
__int64 result; // rax

if ( (int)trace_delete_shm_if_necessary(a2) < 0 )
result = 0xFFFFFFFFLL;
else
result = perform_2_path_operation_in_shm_dir((__int64 (__fastcall *)(char *, char *))&link, a1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, char *a2)
{
__int64 result; // rax

if ( (int)func0(a2) < 0 )
result = 0xFFFFFFFFLL;
else
result = func4((__int64 (__fastcall *)(char *, char *))&link, a1, a2);
return result;
}

original_code:
int trace_shm_duplicate(const char *orig_name, const char *duplicate_name)
{
    if (trace_delete_shm_if_necessary(duplicate_name) < 0) {
        return -1;
    }
    return perform_2_path_operation_in_shm_dir(link, orig_name, duplicate_name);
}

canonical_original_code:
int trace_shm_duplicate(char *orig_name, char *duplicate_name)
{
    if (trace_delete_shm_if_necessary(duplicate_name) < 0) {
        return -1;
    }
    return perform_2_path_operation_in_shm_dir(link, orig_name, duplicate_name);
}


decompiled_code:
__int64 __fastcall trace_shm_init_dir_from_fd(unsigned int a1)
{
char *v1; // rax
__int64 v3[2]; // [rsp+0h] [rbp-1008h] BYREF
char v4[4080]; // [rsp+10h] [rbp-FF8h] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
memset(v4, 0, sizeof(v4));
if ( (int)trace_get_fd_path(a1, v3, 4096LL) < 0 )
return 0xFFFFFFFFLL;
byte_45F = 0;
v1 = dirname((char *)v3);
strncpy(shm_dir_path, v1, 0x100uLL);
if ( !byte_45F )
return 0LL;
byte_45F = 0;
*_errno_location() = 36;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
char *v1; // rax
__int64 v3[2]; // [rsp+0h] [rbp-1008h] BYREF
char v4[4080]; // [rsp+10h] [rbp-FF8h] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
memset(v4, 0, sizeof(v4));
if ( (int)trace_get_fd_path(a1, v3, 4096LL) < 0 )
return 0xFFFFFFFFLL;
byte_45F = 0;
v1 = dirname((char *)v3);
strncpy(shm_dir_path, v1, 0x100uLL);
if ( !byte_45F )
return 0LL;
byte_45F = 0;
*_errno_location() = 36;
return 0xFFFFFFFFLL;
}

original_code:
int trace_shm_init_dir_from_fd(int shm_fd)
{
    char shm_path[4096] = "";
    if (trace_get_fd_path(shm_fd, shm_path, sizeof(shm_path)) < 0) {
        return -1;
    }
    shm_dir_path[sizeof(shm_dir_path) - 1] = '\0';
    strncpy(shm_dir_path, dirname(shm_path), sizeof(shm_dir_path));
    if ('\0' != shm_dir_path[sizeof(shm_dir_path) - 1]) {
        shm_dir_path[sizeof(shm_dir_path) - 1] = '\0';
        (*__errno_location ()) = 36;
        return -1;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall trace_shm_set_size_and_mmap(size_t len, int fd)
{
int v2; // edx
__int64 result; // rax

v2 = ftruncate(fd, len);
result = -1LL;
if ( v2 >= 0 )
result = (__int64)mmap(0LL, len, 2, 1, fd, 0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(size_t len, int fd)
{
int v2; // edx
__int64 result; // rax

v2 = ftruncate(fd, len);
result = -1LL;
if ( v2 >= 0 )
result = (__int64)mmap(0LL, len, 2, 1, fd, 0LL);
return result;
}

original_code:
void *trace_shm_set_size_and_mmap(size_t length, int shm_fd)
{
    if (ftruncate(shm_fd, length) < 0) {
        return ((void *) -1);
    }
    return mmap(((void *)0), length, 0x2, 0x01, shm_fd, 0);
}

canonical_original_code:
void *trace_shm_set_size_and_mmap(unsigned long length, int shm_fd)
{
    if (ftruncate(shm_fd, length) < 0) {
        return ((void *) -1);
    }
    return mmap(((void *)0), length, 0x2, 0x01, shm_fd, 0);
}

variable_types:
length
unsigned long

return_type: void *


decompiled_code:
__int64 __fastcall get_trace_file_timestamp(__int64 a1)
{
char *v1; // rax
__int64 result; // rax
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

if ( !(unsigned int)trace_is_valid_file_name() )
return 0xFFFFFFFFLL;
trace_strncpy_and_terminate((__int64)v3, a1 + 6, 50LL);
v1 = index(v3, 46);
if ( !v1 )
return 0xFFFFFFFFLL;
*v1 = 0;
result = strtol(v3, 0LL, 10);
if ( (unsigned __int64)(result + 0x7FFFFFFFFFFFFFFFLL) > 0xFFFFFFFFFFFFFFFDLL )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
char *v1; // rax
__int64 result; // rax
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

if ( !(unsigned int)trace_is_valid_file_name() )
return 0xFFFFFFFFLL;
func0((__int64)v3, a1 + 6, 50LL);
v1 = index(v3, 46);
if ( !v1 )
return 0xFFFFFFFFLL;
*v1 = 0;
result = strtol(v3, 0LL, 10);
if ( (unsigned __int64)(result + 0x7FFFFFFFFFFFFFFFLL) > 0xFFFFFFFFFFFFFFFDLL )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static int get_trace_file_timestamp(const char *filename)
{
    if (!trace_is_valid_file_name(filename)) {
        return -1;
    }
    char timestamp[50];
    trace_strncpy_and_terminate(timestamp, filename + strlen("trace."), sizeof(timestamp));
    char *tmp_ptr = index(timestamp, '.');
    if (((void *)0) == tmp_ptr) {
        return -1;
    }
    *tmp_ptr = '\0';
    long int result = strtol(timestamp, (char **) ((void *)0), 10);
    if (result == 0x7fffffffffffffffL || result == (-0x7fffffffffffffffL - 1L)) {
        return -1;
    }
    return result;
}

canonical_original_code:
static int get_trace_file_timestamp(char *filename)
{
    if (!trace_is_valid_file_name(filename)) {
        return -1;
    }
    char timestamp[50];
    trace_strncpy_and_terminate(timestamp, filename + strlen("trace."), sizeof(timestamp));
    char *tmp_ptr = index(timestamp, '.');
    if (((void *)0) == tmp_ptr) {
        return -1;
    }
    *tmp_ptr = '\0';
    long result = strtol(timestamp, (char **) ((void *)0), 10);
    if (result == 0x7fffffffffffffffL || result == (-0x7fffffffffffffffL - 1L)) {
        return -1;
    }
    return result;
}

variable_types:
filename
char *

variable_types:
timestamp
char [50]

variable_types: result long


decompiled_code:
__fsblkcnt_t __fastcall free_bytes_in_fs(const char *a1)
{
__fsblkcnt_t result; // rax
struct statvfs v2; // [rsp+0h] [rbp-78h] BYREF

if ( statvfs(a1, &v2) )
result = -1LL;
else
result = v2.f_bfree * v2.f_bsize;
return result;
}

canonical_decompiled_code:
__fsblkcnt_t __fastcall func3(const char *a1)
{
__fsblkcnt_t result; // rax
struct statvfs v2; // [rsp+0h] [rbp-78h] BYREF

if ( statvfs(a1, &v2) )
result = -1LL;
else
result = v2.f_bfree * v2.f_bsize;
return result;
}

original_code:
static long long free_bytes_in_fs(const char *mnt)
{
    struct statvfs vfs;
    int rc = statvfs(mnt, &vfs);
    if (0 != rc) {
        return -1;
    }
    return vfs.f_bsize * vfs.f_bfree;
}

canonical_original_code:
static long long free_bytes_in_fs(char *mnt)
{
    struct statvfs vfs;
    int rc = statvfs(mnt, &vfs);
    if (0 != rc) {
        return -1;
    }
    return vfs.f_bsize * vfs.f_bfree;
}

variable_types:
mnt
char *

variable_types: struct statvfs { unsigned long f_bsize; unsigned long f_frsize; unsigned long f_blocks; unsigned long f_bfree; unsigned long f_bavail; unsigned long f_files; unsigned long f_ffree; unsigned long f_favail; unsigned long f_fsid; unsigned long f_flag; unsigned long f_namemax; int __f_spare[6]; }

return_type: long long


decompiled_code:
__off_t __fastcall get_file_size(const char *a1)
{
__off_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v2) )
result = -1LL;
else
result = v2.st_size;
return result;
}

canonical_decompiled_code:
__off_t __fastcall func4(const char *a1)
{
__off_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v2) )
result = -1LL;
else
result = v2.st_size;
return result;
}

original_code:
long long get_file_size(const char *filename)
{
    struct stat st;
    int rc = stat(filename, &st);
    if (0 != rc) {
        return -1;
    } else {
        return st.st_size;
    }
}

canonical_original_code:
long long get_file_size(char *filename)
{
    struct stat st;
    int rc = stat(filename, &st);
    if (0 != rc) {
        return -1;
    } else {
        return st.st_size;
    }
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall calculate_free_percentage(unsigned int a1, const char *a2)
{
__int64 result; // rax
__int64 v3; // rbp

result = 0LL;
if ( a1 - 1 <= 0x63 )
{
v3 = total_records_in_logdir(a2);
if ( v3 == -1 )
v3 = 0LL;
result = a1 * ((__int64)(free_bytes_in_fs(a2) + (v3 << 6)) / 100);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, const char *a2)
{
__int64 result; // rax
__int64 v3; // rbp

result = 0LL;
if ( a1 - 1 <= 0x63 )
{
v3 = func6(a2);
if ( v3 == -1 )
v3 = 0LL;
result = a1 * ((__int64)(free_bytes_in_fs(a2) + (v3 << 6)) / 100);
}
return result;
}

original_code:
unsigned long long calculate_free_percentage(unsigned int percent, const char *logdir)
{
    if (percent > 100 || percent == 0) {
        return 0;
    }
    long long records_in_logdir = total_records_in_logdir(logdir);
    if (-1 == records_in_logdir) {
        records_in_logdir = 0;
    }
    long long free_bytes = free_bytes_in_fs(logdir) + (records_in_logdir * sizeof(struct trace_record));
    return (free_bytes / 100) * percent;
}

canonical_original_code:
unsigned long long calculate_free_percentage(unsigned int percent, char *logdir)
{
    if (percent > 100 || percent == 0) {
        return 0;
    }
    long long records_in_logdir = total_records_in_logdir(logdir);
    if (-1 == records_in_logdir) {
        records_in_logdir = 0;
    }
    long long free_bytes = free_bytes_in_fs(logdir) + (records_in_logdir * sizeof(struct trace_record));
    return (free_bytes / 100) * percent;
}

variable_types:
percent
unsigned int

variable_types:
logdir
char *

return_type: unsigned long long


decompiled_code:
__int64 __fastcall trace_create_dir_if_necessary(char *path)
{
int *v1; // rbx
int v2; // er12
int v3; // edx
__int64 result; // rax
char *v5; // rax

v1 = _errno_location();
v2 = *v1;
v3 = mkdir(path, 0x1EDu);
result = 0LL;
if ( v3 < 0 )
{
if ( *v1 == 17 )
{
*v1 = v2;
}
else
{
v5 = strerror(*v1);
syslog(11, "The trace directory %s does not exist and could not be created due to error %s", path, v5);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *path)
{
int *v1; // rbx
int v2; // er12
int v3; // edx
__int64 result; // rax
char *v5; // rax

v1 = _errno_location();
v2 = *v1;
v3 = mkdir(path, 0x1EDu);
result = 0LL;
if ( v3 < 0 )
{
if ( *v1 == 17 )
{
*v1 = v2;
}
else
{
v5 = strerror(*v1);
syslog(11, "The trace directory %s does not exist and could not be created due to error %s", path, v5);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int trace_create_dir_if_necessary(const char *base_dir)
{
 int saved_errno = (*__errno_location ());
 int rc = mkdir(base_dir, 0755);
 if (rc < 0)
 {
  switch ((*__errno_location ()))
  {
  case 17:
   (*__errno_location ()) = saved_errno;
   break;
  default:
   syslog(3|(1<<3), "The trace directory %s does not exist and could not be created due to error %s",
     base_dir, strerror((*__errno_location ())));
   return -1;
  }
 }
 return 0;
}

canonical_original_code:
int trace_create_dir_if_necessary(char *base_dir)
{
 int saved_errno = (*__errno_location ());
 int rc = mkdir(base_dir, 0755);
 if (rc < 0)
 {
  switch ((*__errno_location ()))
  {
  case 17:
   (*__errno_location ()) = saved_errno;
   break;
  default:
   syslog(3|(1<<3), "The trace directory %s does not exist and could not be created due to error %s",
     base_dir, strerror((*__errno_location ())));
   return -1;
  }
 }
 return 0;
}

variable_types: rc int


decompiled_code:
int __fastcall prepend_prefix_to_filename(char *old, const char *a2)
{
char *v2; // rax
char *v3; // rax
char v5[528]; // [rsp+0h] [rbp-538h] BYREF
char path[256]; // [rsp+210h] [rbp-328h] BYREF
char v7[256]; // [rsp+310h] [rbp-228h] BYREF
char v8[296]; // [rsp+410h] [rbp-128h] BYREF

trace_strncpy_and_terminate((__int64)path, (__int64)old, 256LL);
v2 = dirname(path);
trace_strncpy_and_terminate((__int64)v8, (__int64)v2, 256LL);
trace_strncpy_and_terminate((__int64)path, (__int64)old, 256LL);
v3 = _xpg_basename(path);
trace_strncpy_and_terminate((__int64)v7, (__int64)v3, 256LL);
snprintf(v5, 0x210uLL, "%s/%s%s", v8, a2, v7);
return rename(old, v5);
}

canonical_decompiled_code:
int __fastcall func10(char *old, const char *a2)
{
char *v2; // rax
char *v3; // rax
char v5[528]; // [rsp+0h] [rbp-538h] BYREF
char path[256]; // [rsp+210h] [rbp-328h] BYREF
char v7[256]; // [rsp+310h] [rbp-228h] BYREF
char v8[296]; // [rsp+410h] [rbp-128h] BYREF

func0((__int64)path, (__int64)old, 256LL);
v2 = dirname(path);
func0((__int64)v8, (__int64)v2, 256LL);
func0((__int64)path, (__int64)old, 256LL);
v3 = _xpg_basename(path);
func0((__int64)v7, (__int64)v3, 256LL);
snprintf(v5, 0x210uLL, "%s/%s%s", v8, a2, v7);
return rename(old, v5);
}

original_code:
int prepend_prefix_to_filename(const char *filename, const char *prefix)
{
    char dir[0x100];
    char base[0x100];
    char orig_filename[0x100];
    char snapshot_filename[sizeof(dir) + sizeof(base) + 0x10];
    trace_strncpy_and_terminate(orig_filename, filename, sizeof(orig_filename));
    char *dirname_ptr = dirname(orig_filename);
    trace_strncpy_and_terminate(dir, dirname_ptr, sizeof(dir));
    trace_strncpy_and_terminate(orig_filename, filename, sizeof(orig_filename));
    char *basename_ptr = __xpg_basename(orig_filename);
    trace_strncpy_and_terminate(base, basename_ptr, sizeof(base));
    snprintf(snapshot_filename, sizeof(snapshot_filename), "%s/%s%s", dir, prefix, base);
    return rename(filename, snapshot_filename);
}

canonical_original_code:
int prepend_prefix_to_filename(char *filename, char *prefix)
{
    char dir[256];
    char base[256];
    char orig_filename[256];
    char snapshot_filename[-1];
    trace_strncpy_and_terminate(orig_filename, filename, sizeof(orig_filename));
    char *dirname_ptr = dirname(orig_filename);
    trace_strncpy_and_terminate(dir, dirname_ptr, sizeof(dir));
    trace_strncpy_and_terminate(orig_filename, filename, sizeof(orig_filename));
    char *basename_ptr = __xpg_basename(orig_filename);
    trace_strncpy_and_terminate(base, basename_ptr, sizeof(base));
    snprintf(snapshot_filename, sizeof(snapshot_filename), "%s/%s%s", dir, prefix, base);
    return rename(filename, snapshot_filename);
}

variable_types:
prefix
char *

variable_types:
dir
char [256]

variable_types:
base
char [256]


DEBUG

decompiled_code:
void DEBUG()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code: void DEBUG() {}

canonical_original_code: void DEBUG() {}

return_type: void


TRIO

decompiled_code:
void TRIO()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code: void TRIO() {}

canonical_original_code: void TRIO() {}


INFO

decompiled_code:
void INFO()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code: void INFO() {}

canonical_original_code: void INFO() {}


NOTE

decompiled_code:
void NOTE()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code: void NOTE() {}

canonical_original_code: void NOTE() {}


WARN

decompiled_code:
void WARN()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code: void WARN() {}

canonical_original_code: void WARN() {}


ERR

decompiled_code:
void ERR()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code: void ERR() {}

canonical_original_code: void ERR() {}


FATAL

decompiled_code:
void FATAL()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code: void FATAL() {}

canonical_original_code: void FATAL() {}


decompiled_code:
__int64 trace_register_fatal_sig_handlers()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func18()
{
return 0LL;
}

original_code: int trace_register_fatal_sig_handlers(const void *unused __attribute__ ((unused))) { return 0; }

canonical_original_code: int trace_register_fatal_sig_handlers(void *unused) { return 0; }

variable_types:
unused
void *


decompiled_code:
__int64 trace_runtime_control_set_default_min_sev()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
return 0LL;
}

original_code: enum trace_severity trace_runtime_control_set_default_min_sev(enum trace_severity sev __attribute__ ((unused))) {return TRACE_SEV_INVALID;}

canonical_original_code: enum trace_severity trace_runtime_control_set_default_min_sev(enum trace_severity sev) {return TRACE_SEV_INVALID;}

variable_types: enum trace_severity { TRACE_SEV_INVALID=0, TRACE_SEV_FUNC_TRACE=1, TRACE_SEV_DEBUG=2, TRACE_SEV_TRIO=3, TRACE_SEV_INFO=4, TRACE_SEV_NOTE=5, TRACE_SEV_WARN=6, TRACE_SEV_ERR=7, TRACE_SEV_FATAL=8, TRACE_SEV__COUNT=9, TRACE_SEV__MIN=expr, TRACE_SEV__MAX=expr }


decompiled_code:
__int64 trace_finalize()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
return 0LL;
}

original_code: int trace_finalize(void) { return 0; }

canonical_original_code: int trace_finalize() { return 0; }


decompiled_code:
__pid_t trace_fork()
{
return fork();
}

canonical_decompiled_code:
__pid_t func12()
{
return fork();
}

original_code: pid_t trace_fork(void) { return fork(); }

canonical_original_code: int trace_fork() { return fork(); }


decompiled_code:
void *trace_internal_err_get_last()
{
return &internal_err_info;
}

canonical_decompiled_code:
void *func13()
{
return &internal_err_info;
}

original_code: const struct trace_internal_err_info *trace_internal_err_get_last(void) { return &internal_err_info; }

canonical_original_code: struct trace_internal_err_info *trace_internal_err_get_last() { return &internal_err_info; }

return_type: struct trace_internal_err_info { unsigned long long ts; unsigned int log_id; unsigned int module_id; int err_num; } *


decompiled_code:
void trace_internal_err_clear()
{
;
}

canonical_decompiled_code:
void func14()
{
;
}

original_code: void trace_internal_err_clear(void) {}

canonical_original_code: void trace_internal_err_clear() {}


decompiled_code:
// attributes: thunk
__int64 __fastcall trace_runtime_control_set_thread_overwrite_protection(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
return trace_runtime_control_set_overwrite_protection_impl(a1, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
return func0(a1, a2, a3, a4);
}

original_code:
int trace_runtime_control_set_thread_overwrite_protection(unsigned stop_threshold_ppm, unsigned flags, unsigned wait_timeout_us, struct trace_thresholds *old_thresholds)
{
    return trace_runtime_control_set_overwrite_protection_impl(stop_threshold_ppm, flags, wait_timeout_us, old_thresholds);
}

canonical_original_code:
int trace_runtime_control_set_thread_overwrite_protection(unsigned int stop_threshold_ppm, unsigned int flags, unsigned int wait_timeout_us, struct trace_thresholds *old_thresholds)
{
    return trace_runtime_control_set_overwrite_protection_impl(stop_threshold_ppm, flags, wait_timeout_us, old_thresholds);
}

variable_types:
flags
unsigned int

variable_types: struct trace_thresholds { enum trace_severity { TRACE_SEV_INVALID=0, TRACE_SEV_FUNC_TRACE=1, TRACE_SEV_DEBUG=2, TRACE_SEV_TRIO=3, TRACE_SEV_INFO=4, TRACE_SEV_NOTE=5, TRACE_SEV_WARN=6, TRACE_SEV_ERR=7, TRACE_SEV_FATAL=8, TRACE_SEV__COUNT=9, TRACE_SEV__MIN=expr, TRACE_SEV__MAX=expr } min_sev; enum trace_severity { TRACE_SEV_INVALID=0, TRACE_SEV_FUNC_TRACE=1, TRACE_SEV_DEBUG=2, TRACE_SEV_TRIO=3, TRACE_SEV_INFO=4, TRACE_SEV_NOTE=5, TRACE_SEV_WARN=6, TRACE_SEV_ERR=7, TRACE_SEV_FATAL=8, TRACE_SEV__COUNT=9, TRACE_SEV__MIN=expr, TRACE_SEV__MAX=expr } min_stop_trace_sev; unsigned int free_ppm_stop_trace_threshold; unsigned int wait_timeout_us; } *

user_defined_types: struct trace_thresholds { enum trace_severity min_sev; enum trace_severity min_stop_trace_sev; unsigned int free_ppm_stop_trace_threshold; unsigned int wait_timeout_us; }


decompiled_code:
__int64 __fastcall trace_runtime_control_load_thread_overwrite_protection(__int64 a1, _QWORD *a2)
{
return trace_runtime_control_set_overwrite_protection_impl(0LL, 0LL, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, _QWORD *a2)
{
return func0(0LL, 0LL, 0LL, a2);
}

original_code:
void trace_runtime_control_load_thread_overwrite_protection(
        const struct trace_thresholds *thresholds __attribute__((unused)),
        struct trace_thresholds *old_thresholds)
{
    trace_runtime_control_set_overwrite_protection_impl(0, 0, 0, old_thresholds);
}

canonical_original_code:
void trace_runtime_control_load_thread_overwrite_protection(struct trace_thresholds *thresholds, struct trace_thresholds *old_thresholds)
{
    trace_runtime_control_set_overwrite_protection_impl(0, 0, 0, old_thresholds);
}

user_defined_types: enum trace_severity { TRACE_SEV_INVALID=0, TRACE_SEV_FUNC_TRACE=1, TRACE_SEV_DEBUG=2, TRACE_SEV_TRIO=3, TRACE_SEV_INFO=4, TRACE_SEV_NOTE=5, TRACE_SEV_WARN=6, TRACE_SEV_ERR=7, TRACE_SEV_FATAL=8, TRACE_SEV__COUNT=9, TRACE_SEV__MIN=expr, TRACE_SEV__MAX=expr }


decompiled_code:
__int64 __fastcall total_iovec_len(__int64 a1, int a2)
{
_QWORD *v2; // rax
__int64 v3; // rdx

if ( a2 <= 0 )
return 0LL;
v2 = (_QWORD *)(a1 + 8);
v3 = 0LL;
do
{
v3 += *v2;
v2 += 2;
}
while ( v2 != (_QWORD *)(a1 + 16LL * (unsigned int)(a2 - 1) + 24) );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
_QWORD *v2; // rax
__int64 v3; // rdx

if ( a2 <= 0 )
return 0LL;
v2 = (_QWORD *)(a1 + 8);
v3 = 0LL;
do
{
v3 += *v2;
v2 += 2;
}
while ( v2 != (_QWORD *)(a1 + 16LL * (unsigned int)(a2 - 1) + 24) );
return v3;
}

original_code:
size_t total_iovec_len(const struct iovec *iov, int iovcnt)
{
    size_t total = 0;
    int i;
    for (i = 0; i < iovcnt; i++) {
        total += iov[i].iov_len;
    }
    return total;
}

canonical_original_code:
unsigned long total_iovec_len(struct iovec *iov, int iovcnt)
{
    unsigned long total = 0;
    int i;
    for (i = 0; i < iovcnt; i++) {
        total += iov[i].iov_len;
    }
    return total;
}

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

variable_types: iovcnt int

variable_types:
total
unsigned long

variable_types: i int

return_type: unsigned long


decompiled_code:
__int64 __fastcall max_iovecs_fitting_size(__int64 a1, int a2, unsigned __int64 a3)
{
unsigned __int64 v3; // rcx
_QWORD *v4; // rdi
__int64 result; // rax

if ( a2 <= 0 )
return 0LL;
v3 = *(_QWORD *)(a1 + 8);
if ( a3 < v3 )
return 0LL;
v4 = (_QWORD *)(a1 + 24);
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
if ( a2 == (_DWORD)result )
break;
v3 += *v4;
v4 += 2;
}
while ( v3 <= a3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, unsigned __int64 a3)
{
unsigned __int64 v3; // rcx
_QWORD *v4; // rdi
__int64 result; // rax

if ( a2 <= 0 )
return 0LL;
v3 = *(_QWORD *)(a1 + 8);
if ( a3 < v3 )
return 0LL;
v4 = (_QWORD *)(a1 + 24);
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
if ( a2 == (_DWORD)result )
break;
v3 += *v4;
v4 += 2;
}
while ( v3 <= a3 );
return result;
}

original_code:
int max_iovecs_fitting_size(const struct iovec *iov, int iovcnt, size_t max_size)
{
    size_t total = 0;
    int i;
    for (i = 0; i < iovcnt; i++) {
        total += iov[i].iov_len;
        if (total > max_size) {
            break;
        }
    }
    return i;
}

canonical_original_code:
int max_iovecs_fitting_size(struct iovec *iov, int iovcnt, unsigned long max_size)
{
    unsigned long total = 0;
    int i;
    for (i = 0; i < iovcnt; i++) {
        total += iov[i].iov_len;
        if (total > max_size) {
            break;
        }
    }
    return i;
}

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


decompiled_code:
__int64 __fastcall copy_iov_to_buffer(_BYTE *a1, __int64 a2, int a3)
{
_BYTE *v3; // rbp
__int64 v4; // rbx
__int64 v5; // r12

if ( a2 )
{
v3 = a1;
if ( a1 )
{
if ( a3 < 0 )
{
*_errno_location() = 22;
return -1LL;
}
if ( a3 <= 0 )
return a1 - v3;
v4 = a2;
v5 = a2 + 16LL * (unsigned int)(a3 - 1) + 16;
while ( *(_QWORD *)v4 )
{
a1 = mempcpy(a1, *(const void **)v4, *(_QWORD *)(v4 + 8));
v4 += 16LL;
if ( v4 == v5 )
return a1 - v3;
}
}
}
*_errno_location() = 14;
return -1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, __int64 a2, int a3)
{
_BYTE *v3; // rbp
__int64 v4; // rbx
__int64 v5; // r12

if ( a2 )
{
v3 = a1;
if ( a1 )
{
if ( a3 < 0 )
{
*_errno_location() = 22;
return -1LL;
}
if ( a3 <= 0 )
return a1 - v3;
v4 = a2;
v5 = a2 + 16LL * (unsigned int)(a3 - 1) + 16;
while ( *(_QWORD *)v4 )
{
a1 = mempcpy(a1, *(const void **)v4, *(_QWORD *)(v4 + 8));
v4 += 16LL;
if ( v4 == v5 )
return a1 - v3;
}
}
}
*_errno_location() = 14;
return -1LL;
}

original_code:
ssize_t copy_iov_to_buffer(void *buffer, const struct iovec *iov, int iovcnt)
{
    if ((((void *)0) == iov) || (((void *)0) == buffer)) {
        (*__errno_location ()) = 14;
        return -1;
    }
    if (iovcnt < 0) {
        (*__errno_location ()) = 22;
        return -1;
    }
    void *target = buffer;
    for (int i = 0; i < iovcnt; i++) {
        if (((void *)0) == iov[i].iov_base) {
            (*__errno_location ()) = 14;
            return -1;
        }
        target = mempcpy(target, iov[i].iov_base, iov[i].iov_len);
    }
    return (const char *)target - (const char *)buffer;
}

canonical_original_code:
long copy_iov_to_buffer(void *buffer, struct iovec *iov, int iovcnt)
{
    if ((((void *)0) == iov) || (((void *)0) == buffer)) {
        (*__errno_location ()) = 14;
        return -1;
    }
    if (iovcnt < 0) {
        (*__errno_location ()) = 22;
        return -1;
    }
    void *target = buffer;
    for (int i = 0; i < iovcnt; i++) {
        if (((void *)0) == iov[i].iov_base) {
            (*__errno_location ()) = 14;
            return -1;
        }
        target = mempcpy(target, iov[i].iov_base, iov[i].iov_len);
    }
    return (char *)target - (char *)buffer;
}

variable_types:
buffer
void *

variable_types:
target
void *

return_type: long


decompiled_code:
ssize_t __fastcall trace_dumper_writev(int fd, __int64 a2, int a3)
{
__int64 v4; // r12
_BYTE *v5; // rax
void *v6; // rbp
ssize_t v7; // rbx

v4 = total_iovec_len(a2, a3);
v5 = malloc(v4);
if ( !v5 )
return -1LL;
v6 = v5;
if ( copy_iov_to_buffer(v5, a2, a3) != v4 )
_assert_fail(
"(copy_iov_to_buffer(buffer, iov, iovcnt) == length) || TRACE_LOG_ASSERTION_FAILURE(copy_iov_to_buffer(buffer, iov,"
" iovcnt) == length)",
"trace_dumper/sgio_util.c",
0x5Eu,
"trace_dumper_writev");
do
v7 = write(fd, v6, v4);
while ( v7 == -1 && *_errno_location() == 4 );
free(v6);
return v7;
}

canonical_decompiled_code:
ssize_t __fastcall func3(int fd, __int64 a2, int a3)
{
__int64 v4; // r12
_BYTE *v5; // rax
void *v6; // rbp
ssize_t v7; // rbx

v4 = func0(a2, a3);
v5 = malloc(v4);
if ( !v5 )
return -1LL;
v6 = v5;
if ( func2(v5, a2, a3) != v4 )
_assert_fail(
"(copy_iov_to_buffer(buffer, iov, iovcnt) == length) || TRACE_LOG_ASSERTION_FAILURE(copy_iov_to_buffer(buffer, iov,"
" iovcnt) == length)",
"trace_dumper/sgio_util.c",
0x5Eu,
"trace_dumper_writev");
do
v7 = write(fd, v6, v4);
while ( v7 == -1 && *_errno_location() == 4 );
free(v6);
return v7;
}

original_code:
ssize_t trace_dumper_writev(int fd, const struct iovec *iov, int iovcnt)
{
    ssize_t length = total_iovec_len(iov, iovcnt);
    void *buffer = malloc(length);
    if (((void *)0) == buffer) {
        return -1;
    }
    ((void) sizeof (((copy_iov_to_buffer(buffer, iov, iovcnt) == length) || (0)) ? 1 : 0), __extension__ ({ if ((copy_iov_to_buffer(buffer, iov, iovcnt) == length) || (0)) ; else __assert_fail ("(copy_iov_to_buffer(buffer, iov, iovcnt) == length) || TRACE_LOG_ASSERTION_FAILURE(copy_iov_to_buffer(buffer, iov, iovcnt) == length)", "trace_dumper/sgio_util.c", 94, __extension__ __PRETTY_FUNCTION__); }));
    ssize_t bytes_written = (__extension__ ({ long int __result; do __result = (long int) (write(fd, buffer, length)); while (__result == -1L && (*__errno_location ()) == 4); __result; }));
    free(buffer);
    return bytes_written;
}

canonical_original_code:
long trace_dumper_writev(int fd, struct iovec *iov, int iovcnt)
{
    long length = total_iovec_len(iov, iovcnt);
    void *buffer = malloc(length);
    if (((void *)0) == buffer) {
        return -1;
    }
    ((void) sizeof (((copy_iov_to_buffer(buffer, iov, iovcnt) == length) || (0)) ? 1 : 0), __extension__ ({ if ((copy_iov_to_buffer(buffer, iov, iovcnt) == length) || (0)) ; else __assert_fail ("(copy_iov_to_buffer(buffer, iov, iovcnt) == length) || TRACE_LOG_ASSERTION_FAILURE(copy_iov_to_buffer(buffer, iov, iovcnt) == length)", "trace_dumper/sgio_util.c", 94, __extension__ __PRETTY_FUNCTION__); }));
    long bytes_written = (__extension__ ({ long int __result; do __result = (long int) (write(fd, buffer, length)); while (__result == -1L && (*__errno_location ()) == 4); __result; }));
    free(buffer);
    return bytes_written;
}

variable_types: fd int

variable_types: length long


variable_types:
str
char *

variable_types:
num
long long *

variable_types: negative int

variable_types:
n
long long


decompiled_code:
unsigned __int64 __fastcall num_to_severity(char *a1)
{
int v1; // edx
unsigned __int64 result; // rax
unsigned __int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = -1LL;
v1 = trace_get_number(a1, (__int64 *)&v3);
result = 0LL;
if ( v1 )
{
result = v3;
if ( v3 > 8 )
result = 0LL;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(char *a1)
{
int v1; // edx
unsigned __int64 result; // rax
unsigned __int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = -1LL;
v1 = func0(a1, (__int64 *)&v3);
result = 0LL;
if ( v1 )
{
result = v3;
if ( v3 > 8 )
result = 0LL;
}
return result;
}

original_code:
static enum trace_severity num_to_severity(const char *s)
{
    long long num = -1;
    bool_t is_num = trace_get_number(s, &num);
    if (is_num && (num >= TRACE_SEV_INVALID) && (num <= TRACE_SEV__MAX)) {
        return (enum trace_severity) num;
    }
    return TRACE_SEV_INVALID;
}

canonical_original_code:
static enum trace_severity num_to_severity(char *s)
{
    long long num = -1;
    int is_num = trace_get_number(s, &num);
    if (is_num && (num >= TRACE_SEV_INVALID) && (num <= TRACE_SEV__MAX)) {
        return (enum trace_severity) num;
    }
    return TRACE_SEV_INVALID;
}

variable_types:
s
char *

variable_types:
num
long long

return_type: enum trace_severity { TRACE_SEV_INVALID=0, TRACE_SEV_FUNC_TRACE=1, TRACE_SEV_DEBUG=2, TRACE_SEV_TRIO=3, TRACE_SEV_INFO=4, TRACE_SEV_NOTE=5, TRACE_SEV_WARN=6, TRACE_SEV_ERR=7, TRACE_SEV_FATAL=8, TRACE_SEV__COUNT=9, TRACE_SEV__MIN=expr, TRACE_SEV__MAX=expr }


decompiled_code:
__int64 __fastcall trace_str_to_severity_case_sensitive(void *s1)
{
size_t v1; // rax
__int64 result; // rax
int v3; // edx
int v4; // edx
int v5; // edx
int v6; // edx

v1 = strlen((const char *)s1);
if ( v1 == 5 )
{
if ( !memcmp(s1, "DEBUG", 5uLL) )
return 2LL;
v3 = memcmp(s1, "FATAL", 5uLL);
result = 8LL;
if ( v3 )
return num_to_severity((char *)s1);
}
else
{
if ( v1 != 4 )
{
if ( v1 == 3 && !memcmp(s1, "ERR", 3uLL) )
return 7LL;
return num_to_severity((char *)s1);
}
v4 = memcmp(s1, "TRIO", 4uLL);
result = 3LL;
if ( v4 )
{
v5 = memcmp(s1, "INFO", 4uLL);
result = 4LL;
if ( v5 )
{
v6 = memcmp(s1, "NOTE", 4uLL);
result = 5LL;
if ( v6 )
{
if ( !memcmp(s1, "WARN", 4uLL) )
return 6LL;
return num_to_severity((char *)s1);
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *s1)
{
size_t v1; // rax
__int64 result; // rax
int v3; // edx
int v4; // edx
int v5; // edx
int v6; // edx

v1 = strlen((const char *)s1);
if ( v1 == 5 )
{
if ( !memcmp(s1, "DEBUG", 5uLL) )
return 2LL;
v3 = memcmp(s1, "FATAL", 5uLL);
result = 8LL;
if ( v3 )
return func1((char *)s1);
}
else
{
if ( v1 != 4 )
{
if ( v1 == 3 && !memcmp(s1, "ERR", 3uLL) )
return 7LL;
return func1((char *)s1);
}
v4 = memcmp(s1, "TRIO", 4uLL);
result = 3LL;
if ( v4 )
{
v5 = memcmp(s1, "INFO", 4uLL);
result = 4LL;
if ( v5 )
{
v6 = memcmp(s1, "NOTE", 4uLL);
result = 5LL;
if ( v6 )
{
if ( !memcmp(s1, "WARN", 4uLL) )
return 6LL;
return func1((char *)s1);
}
}
}
}
return result;
}

original_code:
enum trace_severity trace_str_to_severity_case_sensitive(const char *s)
{
    const size_t len_s = strlen(s);
 if (!( (sizeof("DEBUG") - 1 == len_s) && (memcmp(s, "DEBUG", sizeof("DEBUG") - 1) == 0) ) == 0) { return TRACE_SEV_DEBUG; } if (!( (sizeof("TRIO") - 1 == len_s) && (memcmp(s, "TRIO", sizeof("TRIO") - 1) == 0) ) == 0) { return TRACE_SEV_TRIO; } if (!( (sizeof("INFO") - 1 == len_s) && (memcmp(s, "INFO", sizeof("INFO") - 1) == 0) ) == 0) { return TRACE_SEV_INFO; } if (!( (sizeof("NOTE") - 1 == len_s) && (memcmp(s, "NOTE", sizeof("NOTE") - 1) == 0) ) == 0) { return TRACE_SEV_NOTE; } if (!( (sizeof("WARN") - 1 == len_s) && (memcmp(s, "WARN", sizeof("WARN") - 1) == 0) ) == 0) { return TRACE_SEV_WARN; } if (!( (sizeof("ERR") - 1 == len_s) && (memcmp(s, "ERR", sizeof("ERR") - 1) == 0) ) == 0) { return TRACE_SEV_ERR; } if (!( (sizeof("FATAL") - 1 == len_s) && (memcmp(s, "FATAL", sizeof("FATAL") - 1) == 0) ) == 0) { return TRACE_SEV_FATAL; }
 return num_to_severity(s);
}

canonical_original_code:
enum trace_severity trace_str_to_severity_case_sensitive(char *s)
{
    unsigned long len_s = strlen(s);
 if (!( (sizeof("DEBUG") - 1 == len_s) && (memcmp(s, "DEBUG", sizeof("DEBUG") - 1) == 0) ) == 0) { return TRACE_SEV_DEBUG; } if (!( (sizeof("TRIO") - 1 == len_s) && (memcmp(s, "TRIO", sizeof("TRIO") - 1) == 0) ) == 0) { return TRACE_SEV_TRIO; } if (!( (sizeof("INFO") - 1 == len_s) && (memcmp(s, "INFO", sizeof("INFO") - 1) == 0) ) == 0) { return TRACE_SEV_INFO; } if (!( (sizeof("NOTE") - 1 == len_s) && (memcmp(s, "NOTE", sizeof("NOTE") - 1) == 0) ) == 0) { return TRACE_SEV_NOTE; } if (!( (sizeof("WARN") - 1 == len_s) && (memcmp(s, "WARN", sizeof("WARN") - 1) == 0) ) == 0) { return TRACE_SEV_WARN; } if (!( (sizeof("ERR") - 1 == len_s) && (memcmp(s, "ERR", sizeof("ERR") - 1) == 0) ) == 0) { return TRACE_SEV_ERR; } if (!( (sizeof("FATAL") - 1 == len_s) && (memcmp(s, "FATAL", sizeof("FATAL") - 1) == 0) ) == 0) { return TRACE_SEV_FATAL; }
 return num_to_severity(s);
}


decompiled_code:
unsigned __int64 __fastcall trace_str_to_severity_case_insensitive(char *s1)
{
int v1; // edx
unsigned __int64 result; // rax
int v3; // edx
int v4; // edx
int v5; // edx
int v6; // edx
int v7; // edx
int v8; // edx

v1 = strcasecmp(s1, "DEBUG");
result = 2LL;
if ( v1 )
{
v3 = strcasecmp(s1, "TRIO");
result = 3LL;
if ( v3 )
{
v4 = strcasecmp(s1, "INFO");
result = 4LL;
if ( v4 )
{
v5 = strcasecmp(s1, "NOTE");
result = 5LL;
if ( v5 )
{
v6 = strcasecmp(s1, "WARN");
result = 6LL;
if ( v6 )
{
v7 = strcasecmp(s1, "ERR");
result = 7LL;
if ( v7 )
{
v8 = strcasecmp(s1, "FATAL");
result = 8LL;
if ( v8 )
result = num_to_severity(s1);
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(char *s1)
{
int v1; // edx
unsigned __int64 result; // rax
int v3; // edx
int v4; // edx
int v5; // edx
int v6; // edx
int v7; // edx
int v8; // edx

v1 = strcasecmp(s1, "DEBUG");
result = 2LL;
if ( v1 )
{
v3 = strcasecmp(s1, "TRIO");
result = 3LL;
if ( v3 )
{
v4 = strcasecmp(s1, "INFO");
result = 4LL;
if ( v4 )
{
v5 = strcasecmp(s1, "NOTE");
result = 5LL;
if ( v5 )
{
v6 = strcasecmp(s1, "WARN");
result = 6LL;
if ( v6 )
{
v7 = strcasecmp(s1, "ERR");
result = 7LL;
if ( v7 )
{
v8 = strcasecmp(s1, "FATAL");
result = 8LL;
if ( v8 )
result = func1(s1);
}
}
}
}
}
}
return result;
}

original_code:
enum trace_severity trace_str_to_severity_case_insensitive(const char *s)
{
 if (strcasecmp(s, "DEBUG") == 0) { return TRACE_SEV_DEBUG; } if (strcasecmp(s, "TRIO") == 0) { return TRACE_SEV_TRIO; } if (strcasecmp(s, "INFO") == 0) { return TRACE_SEV_INFO; } if (strcasecmp(s, "NOTE") == 0) { return TRACE_SEV_NOTE; } if (strcasecmp(s, "WARN") == 0) { return TRACE_SEV_WARN; } if (strcasecmp(s, "ERR") == 0) { return TRACE_SEV_ERR; } if (strcasecmp(s, "FATAL") == 0) { return TRACE_SEV_FATAL; }
 return num_to_severity(s);
}

canonical_original_code:
enum trace_severity trace_str_to_severity_case_insensitive(char *s)
{
 if (strcasecmp(s, "DEBUG") == 0) { return TRACE_SEV_DEBUG; } if (strcasecmp(s, "TRIO") == 0) { return TRACE_SEV_TRIO; } if (strcasecmp(s, "INFO") == 0) { return TRACE_SEV_INFO; } if (strcasecmp(s, "NOTE") == 0) { return TRACE_SEV_NOTE; } if (strcasecmp(s, "WARN") == 0) { return TRACE_SEV_WARN; } if (strcasecmp(s, "ERR") == 0) { return TRACE_SEV_ERR; } if (strcasecmp(s, "FATAL") == 0) { return TRACE_SEV_FATAL; }
 return num_to_severity(s);
}


decompiled_code:
__int64 __fastcall trace_parse_name_value_pair(char *s, char **a2, char **a3, __int64 *a4)
{
char *v6; // rax
char *v7; // rbx
const unsigned __int16 **v8; // rsi
char *v9; // rbx
const unsigned __int16 **v10; // rcx
__int64 result; // rax

if ( s == 0LL || a3 == 0LL || !a2 )
return 0LL;
*a2 = s;
v6 = strchr(s, 61);
v7 = v6;
if ( v6 )
{
*v6 = 0;
*a3 = v6 + 1;
v8 = _ctype_b_loc();
while ( ((*v8)[**a3] & 0x2000) != 0 )
++*a3;
}
else
{
v7 = &s[strlen(s)];
*a3 = v7;
}
v9 = v7 - 1;
v10 = _ctype_b_loc();
while ( ((*v10)[*v9] & 0x2000) != 0 )
*v9-- = 0;
result = 0LL;
if ( a4 )
result = trace_get_number(*a3, a4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s, char **a2, char **a3, __int64 *a4)
{
char *v6; // rax
char *v7; // rbx
const unsigned __int16 **v8; // rsi
char *v9; // rbx
const unsigned __int16 **v10; // rcx
__int64 result; // rax

if ( s == 0LL || a3 == 0LL || !a2 )
return 0LL;
*a2 = s;
v6 = strchr(s, 61);
v7 = v6;
if ( v6 )
{
*v6 = 0;
*a3 = v6 + 1;
v8 = _ctype_b_loc();
while ( ((*v8)[**a3] & 0x2000) != 0 )
++*a3;
}
else
{
v7 = &s[strlen(s)];
*a3 = v7;
}
v9 = v7 - 1;
v10 = _ctype_b_loc();
while ( ((*v10)[*v9] & 0x2000) != 0 )
*v9-- = 0;
result = 0LL;
if ( a4 )
result = func0(*a3, a4);
return result;
}

original_code:
bool_t trace_parse_name_value_pair(char *str, char **name, char **str_value, long long *num_value)
{
    if ((((void *)0) == name) || (((void *)0) == str_value) || (((void *)0) == str)) {
        return (0);
    }
    *name = str;
    char *name_end = strchr(str, '=');
    if (((void *)0) != name_end) {
        *name_end = '\0';
        *str_value = name_end + 1;
        while (((*__ctype_b_loc ())[(int) ((**str_value))] & (unsigned short int) _ISspace)) {
            ++(*str_value);
        }
    }
    else {
        name_end = str + strlen(str);
        *str_value = name_end;
    }
    name_end--;
    while (((*__ctype_b_loc ())[(int) ((*name_end))] & (unsigned short int) _ISspace)) {
        *(name_end--) = '\0';
    }
    if (((void *)0) != num_value) {
        return trace_get_number(*str_value, num_value);
    }
    return (0);
}

canonical_original_code:
int trace_parse_name_value_pair(char *str, char **name, char **str_value, long long *num_value)
{
    if ((((void *)0) == name) || (((void *)0) == str_value) || (((void *)0) == str)) {
        return (0);
    }
    *name = str;
    char *name_end = strchr(str, '=');
    if (((void *)0) != name_end) {
        *name_end = '\0';
        *str_value = name_end + 1;
        while (((*__ctype_b_loc ())[(int) ((**str_value))] & (unsigned short) _ISspace)) {
            ++(*str_value);
        }
    }
    else {
        name_end = str + strlen(str);
        *str_value = name_end;
    }
    name_end--;
    while (((*__ctype_b_loc ())[(int) ((*name_end))] & (unsigned short) _ISspace)) {
        *(name_end--) = '\0';
    }
    if (((void *)0) != num_value) {
        return trace_get_number(*str_value, num_value);
    }
    return (0);
}

variable_types:
name
char **


decompiled_code:
__int64 __fastcall trace_get_number_from_substring(char *src, size_t n, __int64 *a3)
{
void *v4; // rsp
char v6[15]; // [rsp+0h] [rbp-20h] BYREF

v4 = alloca(n + 9);
strncpy(v6, src, n);
v6[n] = 0;
return trace_get_number(v6, a3);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *src, size_t n, __int64 *a3)
{
void *v4; // rsp
char v6[15]; // [rsp+0h] [rbp-20h] BYREF

v4 = alloca(n + 9);
strncpy(v6, src, n);
v6[n] = 0;
return func0(v6, a3);
}

original_code:
bool_t trace_get_number_from_substring(const char* str, size_t substr_len, long long *num)
{
    char *tmp = __builtin_alloca (substr_len+1);
    strncpy(tmp, str, substr_len);
    tmp[substr_len] = 0;
    return trace_get_number(tmp, num);
}

canonical_original_code:
int trace_get_number_from_substring(char *str, unsigned long substr_len, long long *num)
{
    char *tmp = __builtin_alloca (substr_len+1);
    strncpy(tmp, str, substr_len);
    tmp[substr_len] = 0;
    return trace_get_number(tmp, num);
}

variable_types:
tmp
char *


decompiled_code:
__int64 __fastcall trace_strncpy(void *a1, const void *a2, size_t a3)
{
_BYTE *v4; // rdx
__int64 result; // rax

v4 = memccpy(a1, a2, 0, a3);
result = v4 - (_BYTE *)a1 - 1;
if ( !v4 )
result = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(void *a1, const void *a2, size_t a3)
{
_BYTE *v4; // rdx
__int64 result; // rax

v4 = memccpy(a1, a2, 0, a3);
result = v4 - (_BYTE *)a1 - 1;
if ( !v4 )
result = a3;
return result;
}

original_code:
size_t trace_strncpy(char* dest, const char* source, size_t max_size)
{
 const char* p = memccpy(dest, source, '\0', max_size);
 if (p == ((void *)0)) {
  return max_size;
 } else {
  return p - dest - 1;
 }
}

canonical_original_code:
unsigned long trace_strncpy(char *dest, char *source, unsigned long max_size)
{
 char *p = memccpy(dest, source, '\0', max_size);
 if (p == ((void *)0)) {
  return max_size;
 } else {
  return p - dest - 1;
 }
}

variable_types:
dest
char *

variable_types:
source
char *

variable_types:
p
char *


decompiled_code:
__int64 __fastcall trace_r_count_chr_occurrences(unsigned __int64 a1, __int64 a2, int a3)
{
__int64 v4; // rdx
__int64 v5; // rsi
char *v6; // rax

v4 = a2;
if ( a2 )
{
v5 = a1 + a2 - 1;
v6 = (char *)v5;
if ( a1 <= v5 )
{
do
{
if ( *v6 != a3 )
break;
--v6;
}
while ( a1 <= (unsigned __int64)v6 );
}
v4 = v5 - (_QWORD)v6;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int64 a1, __int64 a2, int a3)
{
__int64 v4; // rdx
__int64 v5; // rsi
char *v6; // rax

v4 = a2;
if ( a2 )
{
v5 = a1 + a2 - 1;
v6 = (char *)v5;
if ( a1 <= v5 )
{
do
{
if ( *v6 != a3 )
break;
--v6;
}
while ( a1 <= (unsigned __int64)v6 );
}
v4 = v5 - (_QWORD)v6;
}
return v4;
}

original_code:
size_t trace_r_count_chr_occurrences(const char *s, size_t len, int c)
{
    if (0 == len) {
        return 0;
    }
    const char *const last = s + len - 1;
    const char *p;
    for (p = last; ((p >= s) && (*p == c)); p--)
        ;
    return last - p;
}

canonical_original_code:
unsigned long trace_r_count_chr_occurrences(char *s, unsigned long len, int c)
{
    if (0 == len) {
        return 0;
    }
    char *last = s + len - 1;
    char *p;
    for (p = last; ((p >= s) && (*p == c)); p--)
        ;
    return last - p;
}

variable_types:
len
unsigned long

variable_types: c int

variable_types:
last
char *


decompiled_code:
int remove_limits()
{
struct rlimit v1; // [rsp+0h] [rbp-18h] BYREF

v1.rlim_cur = -1LL;
v1.rlim_max = -1LL;
return setrlimit(RLIMIT_AS, &v1);
}

canonical_decompiled_code:
int func2()
{
struct rlimit v1; // [rsp+0h] [rbp-18h] BYREF

v1.rlim_cur = -1LL;
v1.rlim_max = -1LL;
return setrlimit(RLIMIT_AS, &v1);
}

original_code:
static int remove_limits(void)
{
    const struct rlimit limit = { ((__rlim_t) -1), ((__rlim_t) -1) };
    return setrlimit(RLIMIT_AS, &limit);
}

canonical_original_code:
static int remove_limits()
{
    struct rlimit limit = { ((__rlim_t) -1), ((__rlim_t) -1) };
    return setrlimit(RLIMIT_AS, &limit);
}

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }


decompiled_code:
__int64 __fastcall mmap_fd(int fd, __int64 *a2)
{
__int64 result; // rax

result = mmap_gzip(fd, a2);
if ( !result )
result = (__int64)mmap(0LL, *a2, 1, 1, fd, 0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, __int64 *a2)
{
__int64 result; // rax

result = func3(fd, a2);
if ( !result )
result = (__int64)mmap(0LL, *a2, 1, 1, fd, 0LL);
return result;
}

original_code:
static void *mmap_fd(int fd, off64_t *size)
{
    void *const addr = mmap_gzip(fd, size);
    ((void) sizeof ((((void *) -1) != ((void *)0)) ? 1 : 0), __extension__ ({ if (((void *) -1) != ((void *)0)) ; else __assert_fail ("MAP_FAILED != NULL", "parser_mmap.c", 171, __extension__ __PRETTY_FUNCTION__); }));
    if (addr != ((void *)0)) {
        return addr;
    }
    return mmap(((void *)0), *size, 0x1, 0x01, fd, 0);
}

canonical_original_code:
static void *mmap_fd(int fd, long *size)
{
    void *addr = mmap_gzip(fd, size);
    ((void) sizeof ((((void *) -1) != ((void *)0)) ? 1 : 0), __extension__ ({ if (((void *) -1) != ((void *)0)) ; else __assert_fail ("MAP_FAILED != NULL", "parser_mmap.c", 171, __extension__ __PRETTY_FUNCTION__); }));
    if (addr != ((void *)0)) {
        return addr;
    }
    return mmap(((void *)0), *size, 0x1, 0x01, fd, 0);
}

variable_types: fd int

variable_types:
size
long *

variable_types:
addr
void *


decompiled_code:
void *__fastcall trace_mmap_private_anon_mem(size_t len)
{
return mmap(0LL, len, 3, 34, -1, 0LL);
}

canonical_decompiled_code:
void *__fastcall func0(size_t len)
{
return mmap(0LL, len, 3, 34, -1, 0LL);
}

original_code:
void *trace_mmap_private_anon_mem(size_t size)
{
    return mmap(((void *)0), size, 0x1 | 0x2, 0x02 | 0x20, -1, 0);
}

canonical_original_code:
void *trace_mmap_private_anon_mem(unsigned long size)
{
    return mmap(((void *)0), size, 0x1 | 0x2, 0x02 | 0x20, -1, 0);
}

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall trace_mmap_grow(void *a1, size_t a2, size_t a3)
{
if ( a1 )
return (__int64)mremap(a1, a2, a3, 1);
if ( !a2 )
return (__int64)trace_mmap_private_anon_mem(a3);
*_errno_location() = 22;
return -1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *a1, size_t a2, size_t a3)
{
if ( a1 )
return (__int64)mremap(a1, a2, a3, 1);
if ( !a2 )
return (__int64)func0(a3);
*_errno_location() = 22;
return -1LL;
}

original_code:
void *trace_mmap_grow(void *const addr, size_t size, size_t new_size)
{
    if (((void *)0) == addr) {
        if (0 != size) {
            (*__errno_location ()) = 22;
            return ((void *) -1);
        }
        return trace_mmap_private_anon_mem(new_size);
    }
    return mremap(addr, size, new_size, 1);
}

canonical_original_code:
void *trace_mmap_grow(void *addr, unsigned long size, unsigned long new_size)
{
    if (((void *)0) == addr) {
        if (0 != size) {
            (*__errno_location ()) = 22;
            return ((void *) -1);
        }
        return trace_mmap_private_anon_mem(new_size);
    }
    return mremap(addr, size, new_size, 1);
}


decompiled_code:
__int64 trace_get_page_size()
{
__int64 v1; // rax

if ( page_size_1 )
return page_size_1;
v1 = sysconf(30);
if ( !v1 || (v1 & (v1 - 1)) != 0 )
page_size_1 = 4096LL;
else
page_size_1 = v1;
return page_size_1;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v1; // rax

if ( page_size_1 )
return page_size_1;
v1 = sysconf(30);
if ( !v1 || (v1 & (v1 - 1)) != 0 )
page_size_1 = 4096LL;
else
page_size_1 = v1;
return page_size_1;
}

original_code:
size_t trace_get_page_size()
{
    static long long page_size = 0;
    if (!page_size) {
        page_size = sysconf(_SC_PAGESIZE);
        if (!(((0 != (page_size)) && (0 == ((page_size) & ((page_size) - 1)))))) {
            page_size = 4096;
        }
    }
    return page_size;
}

canonical_original_code:
unsigned long trace_get_page_size()
{
    static long long page_size = 0;
    if (!page_size) {
        page_size = sysconf(_SC_PAGESIZE);
        if (!(((0 != (page_size)) && (0 == ((page_size) & ((page_size) - 1)))))) {
            page_size = 4096;
        }
    }
    return page_size;
}


decompiled_code:
__int64 __fastcall trace_round_size_up_to_multiple(__int64 a1, __int64 a2)
{
if ( !a2 || (a2 & (a2 - 1)) != 0 )
_assert_fail(
"((((0 != (multiple)) && (0 == ((multiple) & ((multiple) - 1)))))) || TRACE_LOG_ASSERTION_FAILURE((((0 != (multiple"
")) && (0 == ((multiple) & ((multiple) - 1))))))",
"trace_mmap_util.c",
0x52u,
"trace_round_size_up_to_multiple");
return -a2 & (a1 + a2 - 1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
if ( !a2 || (a2 & (a2 - 1)) != 0 )
_assert_fail(
"((((0 != (multiple)) && (0 == ((multiple) & ((multiple) - 1)))))) || TRACE_LOG_ASSERTION_FAILURE((((0 != (multiple"
")) && (0 == ((multiple) & ((multiple) - 1))))))",
"trace_mmap_util.c",
0x52u,
"trace_round_size_up_to_multiple");
return -a2 & (a1 + a2 - 1);
}

original_code:
size_t trace_round_size_up_to_multiple(size_t size, size_t multiple)
{
    ((void) sizeof ((((((0 != (multiple)) && (0 == ((multiple) & ((multiple) - 1)))))) || (0)) ? 1 : 0), __extension__ ({ if (((((0 != (multiple)) && (0 == ((multiple) & ((multiple) - 1)))))) || (0)) ; else __assert_fail ("((((0 != (multiple)) && (0 == ((multiple) & ((multiple) - 1)))))) || TRACE_LOG_ASSERTION_FAILURE((((0 != (multiple)) && (0 == ((multiple) & ((multiple) - 1))))))", "trace_mmap_util.c", 82, __extension__ __PRETTY_FUNCTION__); }));
    return (size + multiple - 1) & ~(multiple - 1);
}

canonical_original_code:
unsigned long trace_round_size_up_to_multiple(unsigned long size, unsigned long multiple)
{
    ((void) sizeof ((((((0 != (multiple)) && (0 == ((multiple) & ((multiple) - 1)))))) || (0)) ? 1 : 0), __extension__ ({ if (((((0 != (multiple)) && (0 == ((multiple) & ((multiple) - 1)))))) || (0)) ; else __assert_fail ("((((0 != (multiple)) && (0 == ((multiple) & ((multiple) - 1)))))) || TRACE_LOG_ASSERTION_FAILURE((((0 != (multiple)) && (0 == ((multiple) & ((multiple) - 1))))))", "trace_mmap_util.c", 82, __extension__ __PRETTY_FUNCTION__); }));
    return (size + multiple - 1) & ~(multiple - 1);
}

variable_types:
multiple
unsigned long


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

v1 = trace_get_page_size();
return trace_round_size_up_to_multiple(a1, v1);
}

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

v1 = func2();
return func3(a1, v1);
}

original_code:
size_t trace_round_size_up_to_page_size(size_t size)
{
    return trace_round_size_up_to_multiple(size, trace_get_page_size());
}

canonical_original_code:
unsigned long trace_round_size_up_to_page_size(unsigned long size)
{
    return trace_round_size_up_to_multiple(size, trace_get_page_size());
}


decompiled_code:
int __fastcall trace_munmap_if_necessary(void **a1, size_t a2)
{
void *v2; // rbp
int result; // eax

if ( a1 )
{
v2 = *a1;
result = 0;
if ( *a1 != (void *)-1LL )
{
*a1 = (void *)-1LL;
result = munmap(v2, a2);
if ( result )
{
*a1 = v2;
result = -1;
}
}
}
else
{
*_errno_location() = 14;
result = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(void **a1, size_t a2)
{
void *v2; // rbp
int result; // eax

if ( a1 )
{
v2 = *a1;
result = 0;
if ( *a1 != (void *)-1LL )
{
*a1 = (void *)-1LL;
result = munmap(v2, a2);
if ( result )
{
*a1 = v2;
result = -1;
}
}
}
else
{
*_errno_location() = 14;
result = -1;
}
return result;
}

original_code:
int trace_munmap_if_necessary(void **mapping_base, size_t len)
{
    if (((void *)0) == mapping_base) {
        (*__errno_location ()) = 14;
        return -1;
    }
    void *const addr = *mapping_base;
    if (((void *) -1) != addr) {
        *mapping_base = ((void *) -1);
        if (munmap(addr, len) != 0) {
            *mapping_base = addr;
            return -1;
        }
    }
    return 0;
}

canonical_original_code:
int trace_munmap_if_necessary(void **mapping_base, unsigned long len)
{
    if (((void *)0) == mapping_base) {
        (*__errno_location ()) = 14;
        return -1;
    }
    void *addr = *mapping_base;
    if (((void *) -1) != addr) {
        *mapping_base = ((void *) -1);
        if (munmap(addr, len) != 0) {
            *mapping_base = addr;
            return -1;
        }
    }
    return 0;
}


decompiled_code:
void __fastcall invalidate_record(__int64 a1)
{
*(_BYTE *)(a1 + 15) &= 0xFu;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
*(_BYTE *)(a1 + 15) &= 0xFu;
}

original_code:
static inline void invalidate_record(struct trace_record *record)
{
 record->rec_type = TRACE_REC_TYPE_UNKNOWN;
}

variable_types: struct trace_record { unsigned long long ts; unsigned short pid; unsigned short tid; short nesting; short bit_fields[]; unsigned int termination; unsigned int module_id; unsigned int reserved; unsigned int severity; unsigned int rec_type; unsigned int generation; union trace_record_u { unsigned char payload[44]; struct trace_record_typed { unsigned int log_id; unsigned char payload[]; } typed; struct trace_record_file_header { char machine_id[24]; unsigned short format_version; unsigned short flags; unsigned char reserved[4]; unsigned int magic; } file_header; struct trace_record_metadata { unsigned int metadata_size_bytes; unsigned short dead_pids[4]; unsigned char reserved[-1]; unsigned int metadata_magic; } metadata; struct trace_record_dump_header { unsigned int prev_dump_offset; unsigned int total_dump_size; unsigned int first_chunk_offset; unsigned long records_previously_discarded; } dump_header; struct trace_record_buffer_dump { unsigned int last_metadata_offset; unsigned int prev_chunk_offset; unsigned int dump_header_offset; unsigned long long ts; unsigned int records; unsigned int severity_type; unsigned int lost_records; unsigned short flags; unsigned char slack_bytes; } buffer_chunk; struct trace_record_data_loss { unsigned int lost_records; unsigned long long ts_start; unsigned long long ts_end; } data_loss; } u; } *


original_code:
int trace_typed_record_sequence_validator(struct trace_record *records, int n_records, unsigned flags, void *context __attribute__((unused)))
{
 int records_invalidated = 0;
 const bool_t fix_errors = (0 != (flags & TRACE_VALIDATOR_FIX_ERRORS));
 const bool_t check_pid_consistency = (0 == (flags & TRACE_VALIDATOR_SKIP_PID_CONSISTENCY_CHECK));
 for (; (n_records >= 1) && (TRACE_REC_TYPE_UNKNOWN == records[n_records - 1].rec_type); n_records--)
     ;
 const struct trace_record *end = records + n_records;
 const struct trace_record *earliest_invalidated = ((void *)0);
 if ((n_records >= 1) && (TRACE_REC_TYPE_TYPED != records[n_records - 1].rec_type)) {
     { ERR("Got unexpected type at last record", n_records, (enum trace_rec_type)(records[n_records - 1].rec_type), end); (*__errno_location ()) = 71; return - 46; }
 }
 if (n_records >= 2) {
  const unsigned generation = records[n_records - 1].generation;
  const pid_t pid = records[n_records - 1].pid;
  for (struct trace_record *typed_rec = records + n_records - 2; typed_rec >= records; typed_rec--) {
   if (TRACE_REC_TYPE_TYPED != typed_rec->rec_type) {
    if (TRACE_REC_TYPE_UNKNOWN != typed_rec->rec_type) {
        { ERR("Got unexpected record type at pos", typed_rec - end + n_records, (enum trace_rec_type)(typed_rec->rec_type), typed_rec->termination); (*__errno_location ()) = 71; return - 56; }
    }
    continue;
   }
   if (check_pid_consistency && (pid != typed_rec->pid))
       { ERR("Got unexpected pid", typed_rec->pid, "instead of", pid); (*__errno_location ()) = 71; return - 63; }
   if (typed_rec->generation > generation) {
    conditionally_invalidate_record(fix_errors, typed_rec);
    records_invalidated++;
    earliest_invalidated = typed_rec;
    for (struct trace_record *invalid_rec = typed_rec + 1;
     (invalid_rec < end) && !(invalid_rec->termination & TRACE_TERMINATION_FIRST) && (TRACE_REC_TYPE_UNKNOWN != invalid_rec->rec_type);
     invalid_rec++) {
     conditionally_invalidate_record(fix_errors, typed_rec);
     records_invalidated++;
    }
   }
  }
  if (records_invalidated > 0) {
      WARN("Had to invalidate records", records_invalidated, n_records, pid, generation,
              "Earliest invalidated at index", earliest_invalidated - records, "of generation", earliest_invalidated->generation);
   syslog((1<<3)|7, "Had to invalidate %d of %d records from pid %d, last rec generation=%u, earliest generation=%u, earliest invalidated at offset %ld with generation %u",
     records_invalidated, n_records, pid, records[n_records - 1].generation, generation, earliest_invalidated - records, earliest_invalidated->generation);
  }
 }
 return records_invalidated;
}

canonical_original_code:
int trace_typed_record_sequence_validator(struct trace_record *records, int n_records, unsigned int flags, void *context)
{
 int records_invalidated = 0;
 int fix_errors = (0 != (flags & TRACE_VALIDATOR_FIX_ERRORS));
 int check_pid_consistency = (0 == (flags & TRACE_VALIDATOR_SKIP_PID_CONSISTENCY_CHECK));
 for (; (n_records >= 1) && (TRACE_REC_TYPE_UNKNOWN == records[n_records - 1].rec_type); n_records--)
     ;
 struct trace_record *end = records + n_records;
 struct trace_record *earliest_invalidated = ((void *)0);
 if ((n_records >= 1) && (TRACE_REC_TYPE_TYPED != records[n_records - 1].rec_type)) {
     { ERR("Got unexpected type at last record", n_records, (enum trace_rec_type)(records[n_records - 1].rec_type), end); (*__errno_location ()) = 71; return - 46; }
 }
 if (n_records >= 2) {
  unsigned int generation = records[n_records - 1].generation;
  int pid = records[n_records - 1].pid;
  for (struct trace_record *typed_rec = records + n_records - 2; typed_rec >= records; typed_rec--) {
   if (TRACE_REC_TYPE_TYPED != typed_rec->rec_type) {
    if (TRACE_REC_TYPE_UNKNOWN != typed_rec->rec_type) {
        { ERR("Got unexpected record type at pos", typed_rec - end + n_records, (enum trace_rec_type)(typed_rec->rec_type), typed_rec->termination); (*__errno_location ()) = 71; return - 56; }
    }
    continue;
   }
   if (check_pid_consistency && (pid != typed_rec->pid))
       { ERR("Got unexpected pid", typed_rec->pid, "instead of", pid); (*__errno_location ()) = 71; return - 63; }
   if (typed_rec->generation > generation) {
    conditionally_invalidate_record(fix_errors, typed_rec);
    records_invalidated++;
    earliest_invalidated = typed_rec;
    for (struct trace_record *invalid_rec = typed_rec + 1;
     (invalid_rec < end) && !(invalid_rec->termination & TRACE_TERMINATION_FIRST) && (TRACE_REC_TYPE_UNKNOWN != invalid_rec->rec_type);
     invalid_rec++) {
     conditionally_invalidate_record(fix_errors, typed_rec);
     records_invalidated++;
    }
   }
  }
  if (records_invalidated > 0) {
      WARN("Had to invalidate records", records_invalidated, n_records, pid, generation,
              "Earliest invalidated at index", earliest_invalidated - records, "of generation", earliest_invalidated->generation);
   syslog((1<<3)|7, "Had to invalidate %d of %d records from pid %d, last rec generation=%u, earliest generation=%u, earliest invalidated at offset %ld with generation %u",
     records_invalidated, n_records, pid, records[n_records - 1].generation, generation, earliest_invalidated - records, earliest_invalidated->generation);
  }
 }
 return records_invalidated;
}

variable_types:
flags
unsigned int

variable_types:
context
void *

variable_types:
generation
unsigned int

variable_types: pid int

user_defined_types: enum trace_rec_type { TRACE_REC_TYPE_UNKNOWN=0, TRACE_REC_TYPE_TYPED=1, TRACE_REC_TYPE_FILE_HEADER=2, TRACE_REC_TYPE_METADATA_HEADER=3, TRACE_REC_TYPE_METADATA_PAYLOAD=4, TRACE_REC_TYPE_DUMP_HEADER=5, TRACE_REC_TYPE_BUFFER_CHUNK=6, TRACE_REC_TYPE_END_OF_FILE=7, TRACE_REC_TYPE_DATA_LOSS=8 }

user_defined_types: struct trace_record_typed { unsigned int log_id; unsigned char payload[]; }

user_defined_types: struct trace_record_file_header { char machine_id[24]; unsigned short format_version; unsigned short flags; unsigned char reserved[4]; unsigned int magic; }

user_defined_types: struct trace_record_metadata { unsigned int metadata_size_bytes; unsigned short dead_pids[4]; unsigned char reserved[-1]; unsigned int metadata_magic; }

user_defined_types: struct trace_record_dump_header { unsigned int prev_dump_offset; unsigned int total_dump_size; unsigned int first_chunk_offset; unsigned long records_previously_discarded; }

user_defined_types: struct trace_record_buffer_dump { unsigned int last_metadata_offset; unsigned int prev_chunk_offset; unsigned int dump_header_offset; unsigned long long ts; unsigned int records; unsigned int severity_type; unsigned int lost_records; unsigned short flags; unsigned char slack_bytes; }

user_defined_types: struct trace_record_data_loss { unsigned int lost_records; unsigned long long ts_start; unsigned long long ts_end; }


decompiled_code:
_BOOL8 __fastcall trace_is_valid_file_name(char *s2)
{
int v1; // edx
_BOOL8 result; // rax
char *v3; // rax

v1 = strncmp("trace.", s2, 6uLL);
result = 0LL;
if ( !v1 )
{
v3 = strrchr(s2 + 5, 46);
result = strcmp(v3, ".dump") == 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char *s2)
{
int v1; // edx
_BOOL8 result; // rax
char *v3; // rax

v1 = strncmp("trace.", s2, 6uLL);
result = 0LL;
if ( !v1 )
{
v3 = strrchr(s2 + 5, 46);
result = strcmp(v3, ".dump") == 0;
}
return result;
}

original_code:
bool_t trace_is_valid_file_name(const char *name)
{
 static const char prefix[] = "trace.";
 static const char suffix[] = ".dump";
 const size_t prefix_len = strlen(prefix);
 ((void) sizeof ((prefix[prefix_len - 1] == '.') ? 1 : 0), __extension__ ({ if (prefix[prefix_len - 1] == '.') ; else __assert_fail ("prefix[prefix_len - 1] == '.'", "file_naming.c", 47, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((suffix[0] == '.') ? 1 : 0), __extension__ ({ if (suffix[0] == '.') ; else __assert_fail ("suffix[0] == '.'", "file_naming.c", 48, __extension__ __PRETTY_FUNCTION__); }));
 if (strncmp(prefix, name, prefix_len) != 0) {
  return (0);
 }
 return strcmp(strrchr(name + prefix_len - 1, '.'), suffix) == 0;
}

canonical_original_code:
int trace_is_valid_file_name(char *name)
{
 static char prefix[] = "trace.";
 static char suffix[] = ".dump";
 unsigned long prefix_len = strlen(prefix);
 ((void) sizeof ((prefix[prefix_len - 1] == '.') ? 1 : 0), __extension__ ({ if (prefix[prefix_len - 1] == '.') ; else __assert_fail ("prefix[prefix_len - 1] == '.'", "file_naming.c", 47, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((suffix[0] == '.') ? 1 : 0), __extension__ ({ if (suffix[0] == '.') ; else __assert_fail ("suffix[0] == '.'", "file_naming.c", 48, __extension__ __PRETTY_FUNCTION__); }));
 if (strncmp(prefix, name, prefix_len) != 0) {
  return (0);
 }
 return strcmp(strrchr(name + prefix_len - 1, '.'), suffix) == 0;
}

variable_types:
name
char *

variable_types:
prefix
char []

variable_types:
suffix
char []


decompiled_code:
int __fastcall trace_generate_file_name(char *s, const char *a2, size_t a3, int a4)
{
unsigned __int64 v6; // rax
unsigned __int64 v7; // rbx
unsigned __int64 v8; // r14
int v9; // er13
int v10; // er13
time_t timer; // [rsp+8h] [rbp-80h] BYREF
struct tm tp; // [rsp+10h] [rbp-78h] BYREF

v6 = trace_get_walltime_ms();
v7 = v6;
if ( !a4 )
return snprintf(s, a3, "%s/trace.%llu.dump", a2, v6);
v8 = v6 / 0x3E8;
timer = v6 / 0x3E8;
gmtime_r(&timer, &tp);
v9 = snprintf(s, a3, "%s/trace.", a2);
v10 = strftime(&s[v9], a3 - v9, "%F--%H-%M-%S--", &tp) + v9;
return v10 + snprintf(&s[v10], a3 - v10, "%02llu.dump", (v7 - 1000 * v8) / 0xA);
}

canonical_decompiled_code:
int __fastcall func2(char *s, const char *a2, size_t a3, int a4)
{
unsigned __int64 v6; // rax
unsigned __int64 v7; // rbx
unsigned __int64 v8; // r14
int v9; // er13
int v10; // er13
time_t timer; // [rsp+8h] [rbp-80h] BYREF
struct tm tp; // [rsp+10h] [rbp-78h] BYREF

v6 = trace_get_walltime_ms();
v7 = v6;
if ( !a4 )
return snprintf(s, a3, "%s/trace.%llu.dump", a2, v6);
v8 = v6 / 0x3E8;
timer = v6 / 0x3E8;
gmtime_r(&timer, &tp);
v9 = snprintf(s, a3, "%s/trace.", a2);
v10 = strftime(&s[v9], a3 - v9, "%F--%H-%M-%S--", &tp) + v9;
return v10 + snprintf(&s[v10], a3 - v10, "%02llu.dump", (v7 - 1000 * v8) / 0xA);
}

original_code:
int trace_generate_file_name(char *filename, const char *filename_base, size_t name_len, bool_t human_readable)
{
 const unsigned long long now_ms = trace_get_walltime_ms();
 if (! human_readable) {
  return snprintf(filename, name_len, "%s/" "trace." "%llu" ".dump", filename_base, now_ms);
 }
 struct tm now_tm;
 const time_t now_sec = now_ms / 1000ULL;
 gmtime_r(&now_sec, &now_tm);
 int len = snprintf(filename, name_len, "%s/" "trace.", filename_base);
 len += strftime(filename + len, name_len - len, "%F--%H-%M-%S--", &now_tm);
 return len + snprintf(filename + len, name_len - len, "%02llu" ".dump", (now_ms % 1000) / 10);
}

canonical_original_code:
int trace_generate_file_name(char *filename, char *filename_base, unsigned long name_len, int human_readable)
{
 unsigned long long now_ms = trace_get_walltime_ms();
 if (! human_readable) {
  return snprintf(filename, name_len, "%s/" "trace." "%llu" ".dump", filename_base, now_ms);
 }
 struct tm now_tm;
 long now_sec = now_ms / 1000ULL;
 gmtime_r(&now_sec, &now_tm);
 int len = snprintf(filename, name_len, "%s/" "trace.", filename_base);
 len += strftime(filename + len, name_len - len, "%F--%H-%M-%S--", &now_tm);
 return len + snprintf(filename + len, name_len - len, "%02llu" ".dump", (now_ms % 1000) / 10);
}

variable_types:
filename
char *

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }

variable_types: len int


decompiled_code:
__int64 __fastcall trace_generate_shm_name(char *s, unsigned int *a2, int a3, int a4)
{
const char *v5; // rbp
int v6; // er12
int v8; // eax

v5 = ".tmp";
if ( !a4 )
v5 = &LC7;
v6 = 103 - strlen(v5);
if ( a3 == 1 )
{
v8 = snprintf(s, v6, "_trace_shm_%d_dynamic_trace_data", *a2);
}
else
{
if ( a3 != 2 )
{
*_errno_location() = 22;
return 0xFFFFFFFFLL;
}
v8 = snprintf(s, v6, "_trace_shm_%d_%u_static_trace_metadata", *a2, a2[1]);
}
if ( v8 < v6 )
return (unsigned int)stpcpy(&s[v8], v5) - (unsigned int)s;
s[v6 - 1] = 0;
*_errno_location() = 36;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, unsigned int *a2, int a3, int a4)
{
const char *v5; // rbp
int v6; // er12
int v8; // eax

v5 = ".tmp";
if ( !a4 )
v5 = &LC7;
v6 = 103 - strlen(v5);
if ( a3 == 1 )
{
v8 = snprintf(s, v6, "_trace_shm_%d_dynamic_trace_data", *a2);
}
else
{
if ( a3 != 2 )
{
*_errno_location() = 22;
return 0xFFFFFFFFLL;
}
v8 = snprintf(s, v6, "_trace_shm_%d_%u_static_trace_metadata", *a2, a2[1]);
}
if ( v8 < v6 )
return (unsigned int)stpcpy(&s[v8], v5) - (unsigned int)s;
s[v6 - 1] = 0;
*_errno_location() = 36;
return 0xFFFFFFFFLL;
}

original_code:
int trace_generate_shm_name(trace_shm_name_buf buf, const struct trace_shm_module_details *details, enum trace_shm_object_type shm_type, bool_t temporary)
{
    const char *const extra_suffix = temporary ? ".tmp" : "";
    const int buf_len = sizeof(trace_shm_name_buf) - strlen(extra_suffix);
    int len = 0;
    switch (shm_type) {
    case TRACE_SHM_TYPE_DYNAMIC:
        len = snprintf(buf, buf_len, "_trace_shm_" "%d" "_dynamic_trace_data", (int) (details->pid));
        break;
    case TRACE_SHM_TYPE_STATIC_PER_PROCESS:
        len = snprintf(buf, buf_len, "_trace_shm_" "%d_%u" "_static_trace_metadata",
                (int) (details->pid), (unsigned) (details->module_id));
        break;
    case TRACE_SHM_TYPE_STATIC_PER_FILE:
    case TRACE_SHM_TYPE_ANY:
    case TRACE_SHM_TYPE_COUNT:
    default:
        (*__errno_location ()) = 22;
        return -1;
    }
    if (len >= buf_len) {
        buf[buf_len - 1] = '\0';
        (*__errno_location ()) = 36;
        return -1;
    }
    return stpcpy(buf + len, extra_suffix) - buf;
}

canonical_original_code:
int trace_generate_shm_name(char buf[-1], struct trace_shm_module_details *details, enum trace_shm_object_type shm_type, int temporary)
{
    char *extra_suffix = temporary ? ".tmp" : "";
    int buf_len = sizeof(trace_shm_name_buf) - strlen(extra_suffix);
    int len = 0;
    switch (shm_type) {
    case TRACE_SHM_TYPE_DYNAMIC:
        len = snprintf(buf, buf_len, "_trace_shm_" "%d" "_dynamic_trace_data", (int) (details->pid));
        break;
    case TRACE_SHM_TYPE_STATIC_PER_PROCESS:
        len = snprintf(buf, buf_len, "_trace_shm_" "%d_%u" "_static_trace_metadata",
                (int) (details->pid), (unsigned int) (details->module_id));
        break;
    case TRACE_SHM_TYPE_STATIC_PER_FILE:
    case TRACE_SHM_TYPE_ANY:
    case TRACE_SHM_TYPE_COUNT:
    default:
        (*__errno_location ()) = 22;
        return -1;
    }
    if (len >= buf_len) {
        buf[buf_len - 1] = '\0';
        (*__errno_location ()) = 36;
        return -1;
    }
    return stpcpy(buf + len, extra_suffix) - buf;
}

variable_types:
buf
char [-1]

variable_types: struct trace_shm_module_details { int pid; unsigned int module_id; char *file_name; char *file_dir; } *

variable_types: enum trace_shm_object_type { TRACE_SHM_TYPE_ANY=0, TRACE_SHM_TYPE_DYNAMIC=1, TRACE_SHM_TYPE_STATIC_PER_PROCESS=2, TRACE_SHM_TYPE_STATIC_PER_FILE=3, TRACE_SHM_TYPE_COUNT=4 }

variable_types: temporary int