original_code:
mqtt_serialiser_rc_t mqtt_serialiser_write(mqtt_serialiser_t* serialiser, mqtt_message_t* message, uint8_t* buffer, size_t len) {
  unsigned int offset = 0;
  buffer[offset++] = message->common.retain + (message->common.qos << 1) + (message->common.dup << 3) + (message->common.type << 4);
  uint32_t remaining_length = message->common.length;
  do {
    buffer[offset++] = remaining_length & 0x7f;
    remaining_length >>= 7;
  } while (remaining_length > 0);
  switch (message->common.type) {
    case MQTT_TYPE_CONNECT: {
      { buffer[offset++] = message->connect.protocol_name.length / 0xff; buffer[offset++] = message->connect.protocol_name.length & 0xff; memcpy(&(buffer[offset]), message->connect.protocol_name.data, message->connect.protocol_name.length); offset += message->connect.protocol_name.length; };
      buffer[offset++] = message->connect.protocol_version;
      buffer[offset++] =
        (message->connect.flags.username_follows << 7) +
        (message->connect.flags.password_follows << 6) +
        (message->connect.flags.will_retain << 5) +
        (message->connect.flags.will_qos << 3) +
        (message->connect.flags.will << 2) +
        (message->connect.flags.clean_session << 1);
      buffer[offset++] = message->connect.keep_alive >> 8;
      buffer[offset++] = message->connect.keep_alive & 0xff;
      { buffer[offset++] = message->connect.client_id.length / 0xff; buffer[offset++] = message->connect.client_id.length & 0xff; memcpy(&(buffer[offset]), message->connect.client_id.data, message->connect.client_id.length); offset += message->connect.client_id.length; };
      if (message->connect.flags.will) {
        { buffer[offset++] = message->connect.will_topic.length / 0xff; buffer[offset++] = message->connect.will_topic.length & 0xff; memcpy(&(buffer[offset]), message->connect.will_topic.data, message->connect.will_topic.length); offset += message->connect.will_topic.length; };
        { buffer[offset++] = message->connect.will_message.length / 0xff; buffer[offset++] = message->connect.will_message.length & 0xff; memcpy(&(buffer[offset]), message->connect.will_message.data, message->connect.will_message.length); offset += message->connect.will_message.length; };
      }
      if (message->connect.flags.username_follows) {
        { buffer[offset++] = message->connect.username.length / 0xff; buffer[offset++] = message->connect.username.length & 0xff; memcpy(&(buffer[offset]), message->connect.username.data, message->connect.username.length); offset += message->connect.username.length; };
      }
      if (message->connect.flags.password_follows) {
        { buffer[offset++] = message->connect.password.length / 0xff; buffer[offset++] = message->connect.password.length & 0xff; memcpy(&(buffer[offset]), message->connect.password.data, message->connect.password.length); offset += message->connect.password.length; };
      }
      break;
    }
    case MQTT_TYPE_CONNACK: {
      buffer[offset++] = message->connack._unused;
      buffer[offset++] = message->connack.return_code;
      break;
    }
    default: {
      serialiser->error = MQTT_ERROR_SERIALISER_INVALID_MESSAGE_ID;
      return MQTT_SERIALISER_RC_ERROR;
    }
  }
  return MQTT_SERIALISER_RC_SUCCESS;
}

canonical_original_code:
enum mqtt_serialiser_rc_e mqtt_serialiser_write(struct mqtt_serialiser_s *serialiser, union mqtt_message_u *message, unsigned char *buffer, unsigned long len) {
  unsigned int offset = 0;
  buffer[offset++] = message->common.retain + (message->common.qos << 1) + (message->common.dup << 3) + (message->common.type << 4);
  unsigned int remaining_length = message->common.length;
  do {
    buffer[offset++] = remaining_length & 0x7f;
    remaining_length >>= 7;
  } while (remaining_length > 0);
  switch (message->common.type) {
    case MQTT_TYPE_CONNECT: {
      { buffer[offset++] = message->connect.protocol_name.length / 0xff; buffer[offset++] = message->connect.protocol_name.length & 0xff; memcpy(&(buffer[offset]), message->connect.protocol_name.data, message->connect.protocol_name.length); offset += message->connect.protocol_name.length; };
      buffer[offset++] = message->connect.protocol_version;
      buffer[offset++] =
        (message->connect.flags.username_follows << 7) +
        (message->connect.flags.password_follows << 6) +
        (message->connect.flags.will_retain << 5) +
        (message->connect.flags.will_qos << 3) +
        (message->connect.flags.will << 2) +
        (message->connect.flags.clean_session << 1);
      buffer[offset++] = message->connect.keep_alive >> 8;
      buffer[offset++] = message->connect.keep_alive & 0xff;
      { buffer[offset++] = message->connect.client_id.length / 0xff; buffer[offset++] = message->connect.client_id.length & 0xff; memcpy(&(buffer[offset]), message->connect.client_id.data, message->connect.client_id.length); offset += message->connect.client_id.length; };
      if (message->connect.flags.will) {
        { buffer[offset++] = message->connect.will_topic.length / 0xff; buffer[offset++] = message->connect.will_topic.length & 0xff; memcpy(&(buffer[offset]), message->connect.will_topic.data, message->connect.will_topic.length); offset += message->connect.will_topic.length; };
        { buffer[offset++] = message->connect.will_message.length / 0xff; buffer[offset++] = message->connect.will_message.length & 0xff; memcpy(&(buffer[offset]), message->connect.will_message.data, message->connect.will_message.length); offset += message->connect.will_message.length; };
      }
      if (message->connect.flags.username_follows) {
        { buffer[offset++] = message->connect.username.length / 0xff; buffer[offset++] = message->connect.username.length & 0xff; memcpy(&(buffer[offset]), message->connect.username.data, message->connect.username.length); offset += message->connect.username.length; };
      }
      if (message->connect.flags.password_follows) {
        { buffer[offset++] = message->connect.password.length / 0xff; buffer[offset++] = message->connect.password.length & 0xff; memcpy(&(buffer[offset]), message->connect.password.data, message->connect.password.length); offset += message->connect.password.length; };
      }
      break;
    }
    case MQTT_TYPE_CONNACK: {
      buffer[offset++] = message->connack._unused;
      buffer[offset++] = message->connack.return_code;
      break;
    }
    default: {
      serialiser->error = MQTT_ERROR_SERIALISER_INVALID_MESSAGE_ID;
      return MQTT_SERIALISER_RC_ERROR;
    }
  }
  return MQTT_SERIALISER_RC_SUCCESS;
}

variable_types:
buffer
unsigned char *

variable_types:
offset
unsigned int

return_type: enum mqtt_serialiser_rc_e { MQTT_SERIALISER_RC_ERROR=0, MQTT_SERIALISER_RC_SUCCESS=1 }


repo: deoxxa/semver-c

original_code:
void spec_init(spec_t* spec) {
  spec->major = 0;
  spec->minor = 0;
  spec->patch = 0;
  spec->releaseLen = 0;
  spec->releaseRaw = ((void *)0);
  spec->release = ((void *)0);
  spec->buildLen = 0;
  spec->buildRaw = ((void *)0);
  spec->build = ((void *)0);
}

canonical_original_code:
void spec_init(struct spec_s *spec) {
  spec->major = 0;
  spec->minor = 0;
  spec->patch = 0;
  spec->releaseLen = 0;
  spec->releaseRaw = ((void *)0);
  spec->release = ((void *)0);
  spec->buildLen = 0;
  spec->buildRaw = ((void *)0);
  spec->build = ((void *)0);
}

variable_types: struct spec_s { int major; int minor; int patch; unsigned long releaseLen; char *releaseRaw; struct component_s { struct component_s *next; char numeric; unsigned long dataLen; char *dataRaw; int dataInt; } *release; unsigned long buildLen; char *buildRaw; struct component_s *build; } *

return_type: void

user_defined_types: struct spec_s { int major; int minor; int patch; unsigned long releaseLen; char *releaseRaw; struct component_s *release; unsigned long buildLen; char *buildRaw; struct component_s *build; }


decompiled_code:
__int64 __fastcall spec_dump(unsigned int *a1)
{
printf("Major: %d\n", *a1);
printf("Minor: %d\n", a1[1]);
printf("Patch: %d\n", a1[2]);
printf("Release: (%ld) ", *((_QWORD *)a1 + 2));
semver_private_print(*((char **)a1 + 3), *((_QWORD *)a1 + 2));
putchar(10);
component_dump(*((_QWORD *)a1 + 4));
printf("Build: (%ld) ", *((_QWORD *)a1 + 5));
semver_private_print(*((char **)a1 + 6), *((_QWORD *)a1 + 5));
putchar(10);
return component_dump(*((_QWORD *)a1 + 7));
}

original_code:
void spec_dump(const spec_t* spec) {
  printf("Major:   %d\n", spec->major);
  printf("Minor:   %d\n", spec->minor);
  printf("Patch:   %d\n", spec->patch);
  printf("Release: (%ld) ", spec->releaseLen);
  semver_private_print(spec->releaseRaw, spec->releaseLen);
  printf("\n");
  component_dump(spec->release);
  printf("Build:   (%ld) ", spec->buildLen);
  semver_private_print(spec->buildRaw, spec->buildLen);
  printf("\n");
  component_dump(spec->build);
}

canonical_original_code:
void spec_dump(struct spec_s *spec) {
  printf("Major:   %d\n", spec->major);
  printf("Minor:   %d\n", spec->minor);
  printf("Patch:   %d\n", spec->patch);
  printf("Release: (%ld) ", spec->releaseLen);
  semver_private_print(spec->releaseRaw, spec->releaseLen);
  printf("\n");
  component_dump(spec->release);
  printf("Build:   (%ld) ", spec->buildLen);
  semver_private_print(spec->buildRaw, spec->buildLen);
  printf("\n");
  component_dump(spec->build);
}

user_defined_types: struct component_s { struct component_s *next; char numeric; unsigned long dataLen; char *dataRaw; int dataInt; }


decompiled_code:
int __fastcall spec_print(unsigned int *a1)
{
printf("%d.%d.%d", *a1, a1[1], a1[2]);
if ( *((_QWORD *)a1 + 3) )
{
putchar(45);
component_print(*((_QWORD *)a1 + 4));
}
if ( *((_QWORD *)a1 + 6) )
{
putchar(43);
component_print(*((_QWORD *)a1 + 7));
}
return putchar(10);
}

original_code:
void spec_print(const spec_t* spec) {
  printf("%d.%d.%d", spec->major, spec->minor, spec->patch);
  if (spec->releaseRaw) {
    printf("-");
    component_print(spec->release);
  }
  if (spec->buildRaw) {
    printf("+");
    component_print(spec->build);
  }
  printf("\n");
}

canonical_original_code:
void spec_print(struct spec_s *spec) {
  printf("%d.%d.%d", spec->major, spec->minor, spec->patch);
  if (spec->releaseRaw) {
    printf("-");
    component_print(spec->release);
  }
  if (spec->buildRaw) {
    printf("+");
    component_print(spec->build);
  }
  printf("\n");
}


decompiled_code:
__int64 __fastcall spec_read(__int64 a1, char *a2, unsigned __int64 a3)
{
unsigned __int64 v3; // rax
int v7; // ebx
unsigned __int64 i; // rdx
int v9; // ebx
unsigned __int64 v10; // r13
unsigned __int64 v11; // rax
__int64 v12; // rsi
char v13; // al
int v14; // eax
int v15; // esi
unsigned __int64 v16; // rax
char v17; // al
int v18; // eax
char v19; // al
int v21; // eax
char v22; // al
unsigned __int64 v23; // r15
char *v24; // rcx
char v25; // al
__int64 v26; // rdi
unsigned __int64 v27; // rsi
__int64 v28; // rdi
__int64 v29; // rsi
char *v30; // [rsp+8h] [rbp-40h]

v3 = 0LL;
while ( 1 )
{
i = (unsigned __int8)a2[v3];
v7 = v3;
if ( (_BYTE)i != 32 )
break;
v7 = v3 + 2;
v3 += 2LL;
if ( a3 < v3 )
{
i = (unsigned __int8)a2[v3];
break;
}
}
v9 = ((_BYTE)i == 118) + v7;
v10 = v9;
v11 = v9;
if ( a3 >= v9 )
{
while ( a2[v11] == 32 )
{
v11 += 2LL;
v9 += 2;
if ( v11 > a3 )
{
LABEL_23:
v10 = v9;
goto LABEL_24;
}
}
v12 = v9;
v10 = v9;
if ( a3 < v9 )
goto LABEL_24;
for ( i = v9 + 1LL; ; ++i )
{
v13 = a2[v12];
if ( v13 == 46 )
break;
if ( (unsigned __int8)(v13 - 48) > 9u )
return 0xFFFFFFFFLL;
++v9;
v12 = i;
if ( a3 < i )
goto LABEL_23;
}
v14 = semver_private_strntol(a2, v12);
v15 = v9 + 1;
v10 = v9 + 1;
*(_DWORD *)a1 = v14;
v16 = v10;
if ( v10 == a3 )
return 0xFFFFFFFFLL;
if ( v15 <= a3 )
{
i = v15 + 1LL;
++v9;
while ( 1 )
{
v17 = a2[v16];
if ( v17 == 46 )
break;
if ( (unsigned __int8)(v17 - 48) > 9u )
return 0xFFFFFFFFLL;
++v9;
v16 = i;
if ( i > a3 )
goto LABEL_36;
++i;
}
v18 = v9++;
v10 = v9;
*(_DWORD *)(a1 + 4) = semver_private_strntol(&a2[v15], v18 - v15);
if ( v9 != a3 )
{
v15 = v9;
goto LABEL_25;
}
return 0xFFFFFFFFLL;
}
++v9;
}
else
{
LABEL_24:
v15 = 0;
}
LABEL_25:
if ( a3 < v10 )
{
LABEL_53:
v10 = v15;
}
else
{
v19 = a2[v10];
i = (unsigned __int8)(v19 - 43) & 0xFD;
if ( ((v19 - 43) & 0xFD) != 0 )
{
v10 = v9 + 1;
while ( (unsigned __int8)(v19 - 48) <= 9u )
{
v9 = v10;
if ( v10 > a3 )
goto LABEL_53;
v19 = a2[v10];
i = (unsigned __int8)(v19 - 43) & 0xFD;
if ( ((v19 - 43) & 0xFD) == 0 || v10 == a3 )
goto LABEL_35;
++v10;
}
return 0xFFFFFFFFLL;
}
LABEL_35:
v21 = semver_private_strntol(&a2[v15], v9 - v15);
v15 = v9;
*(_DWORD *)(a1 + 8) = v21;
}
LABEL_36:
if ( a3 == v10 )
return 0LL;
v22 = a2[v10];
if ( v22 == 45 )
{
v23 = v9;
if ( a3 < v9 )
return 0LL;
v24 = &a2[v9];
v25 = *v24;
if ( *v24 != 43 && a3 != v9 )
{
v23 = v9 + 1;
while ( (unsigned __int8)(v25 - 48) <= 9u
|| (unsigned __int8)((v25 & 0xDF) - 65) <= 0x19u
|| (unsigned __int8)(v25 - 45) <= 1u )
{
v9 = v23;
if ( a3 < v23 )
return 0LL;
v25 = a2[v23];
v24 = &a2[v23];
i = v23 + 1;
if ( v25 == 43 || a3 == v23 )
goto LABEL_54;
++v23;
}
return 0xFFFFFFFFLL;
}
LABEL_54:
v28 = (__int64)&a2[v10 + 1];
v30 = v24;
v10 = v23;
*(_QWORD *)(a1 + 24) = v28;
v29 = v9 - v15 - 1;
*(_QWORD *)(a1 + 16) = v29;
*(_QWORD *)(a1 + 32) = component_read(v28, v29, i);
v22 = *v30;
}
if ( v22 != 43 )
return 0LL;
v26 = (__int64)&a2[v10 + 1];
v27 = a3 - 1 - v10;
*(_QWORD *)(a1 + 48) = v26;
*(_QWORD *)(a1 + 40) = v27;
*(_QWORD *)(a1 + 56) = component_read(v26, v27, i);
return 0LL;
}

original_code:
int spec_read(spec_t* spec, const char* str, size_t len) {
  int i = 0, o = 0;
  for (;i<=len;++i) {
    if (str[i] == ' ') {
      i++;
    } else {
      break;
    }
  }
  if (str[i] == 'v') {
    i++;
  }
  for (;i<=len;++i) {
    if (str[i] == ' ') {
      i++;
    } else {
      break;
    }
  }
  for (;i<=len;++i) {
    if (str[i] == '.') {
      spec->major = semver_private_strntol(str + o, i - o);
      i++;
      o = i;
      break;
    }
    if (str[i] < '0' || str[i] > '9') {
      return -1;
    }
  }
  if (i == len) {
    return -1;
  }
  for (;i<=len;++i) {
    if (str[i] == '.') {
      spec->minor = semver_private_strntol(str + o, i - o);
      i++;
      o = i;
      break;
    }
    if (str[i] < '0' || str[i] > '9') {
      return -1;
    }
  }
  if (i == len) {
    return -1;
  }
  for (;i<=len;++i) {
    if (str[i] == '-' || str[i] == '+' || i == len) {
      spec->patch = semver_private_strntol(str + o, i - o);
      o = i;
      break;
    }
    if (str[i] < '0' || str[i] > '9') {
      return -1;
    }
  }
  if (o == len) {
    return 0;
  }
  if (str[o] == '-') {
    for (;i<=len;++i) {
      if (str[i] == '+' || i == len) {
        spec->releaseLen = i - o - 1;
        spec->releaseRaw = str + o + 1;
        o = i;
        spec->release = component_read(spec->releaseRaw, spec->releaseLen);
        break;
      }
      if (!(str[i] >= '0' && str[i] <= '9') && !(str[i] >= 'a' && str[i] <= 'z') && !(str[i] >= 'A' && str[i] <= 'Z') && str[i] != '-' && str[i] != '.') {
        return -1;
      }
    }
  }
  if (str[o] == '+') {
    spec->buildLen = len - o - 1;
    spec->buildRaw = str + o + 1;
    o = len;
    spec->build = component_read(spec->buildRaw, spec->buildLen);
  }
  return 0;
}

canonical_original_code:
int spec_read(struct spec_s *spec, char *str, unsigned long len) {
  int i = 0; int o = 0;
  for (;i<=len;++i) {
    if (str[i] == ' ') {
      i++;
    } else {
      break;
    }
  }
  if (str[i] == 'v') {
    i++;
  }
  for (;i<=len;++i) {
    if (str[i] == ' ') {
      i++;
    } else {
      break;
    }
  }
  for (;i<=len;++i) {
    if (str[i] == '.') {
      spec->major = semver_private_strntol(str + o, i - o);
      i++;
      o = i;
      break;
    }
    if (str[i] < '0' || str[i] > '9') {
      return -1;
    }
  }
  if (i == len) {
    return -1;
  }
  for (;i<=len;++i) {
    if (str[i] == '.') {
      spec->minor = semver_private_strntol(str + o, i - o);
      i++;
      o = i;
      break;
    }
    if (str[i] < '0' || str[i] > '9') {
      return -1;
    }
  }
  if (i == len) {
    return -1;
  }
  for (;i<=len;++i) {
    if (str[i] == '-' || str[i] == '+' || i == len) {
      spec->patch = semver_private_strntol(str + o, i - o);
      o = i;
      break;
    }
    if (str[i] < '0' || str[i] > '9') {
      return -1;
    }
  }
  if (o == len) {
    return 0;
  }
  if (str[o] == '-') {
    for (;i<=len;++i) {
      if (str[i] == '+' || i == len) {
        spec->releaseLen = i - o - 1;
        spec->releaseRaw = str + o + 1;
        o = i;
        spec->release = component_read(spec->releaseRaw, spec->releaseLen);
        break;
      }
      if (!(str[i] >= '0' && str[i] <= '9') && !(str[i] >= 'a' && str[i] <= 'z') && !(str[i] >= 'A' && str[i] <= 'Z') && str[i] != '-' && str[i] != '.') {
        return -1;
      }
    }
  }
  if (str[o] == '+') {
    spec->buildLen = len - o - 1;
    spec->buildRaw = str + o + 1;
    o = len;
    spec->build = component_read(spec->buildRaw, spec->buildLen);
  }
  return 0;
}

variable_types:
str
char *

variable_types:
len
unsigned long

variable_types: i int

variable_types: o int

return_type: int


decompiled_code:
__int64 __fastcall spec_compare(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v4; // eax
bool v5; // cc
int v6; // eax
__int64 v7; // rsi
__int64 v8; // rsi

if ( *(_DWORD *)a1 == *(_DWORD *)a2 )
{
v4 = *(_DWORD *)(a2 + 4);
v5 = *(_DWORD *)(a1 + 4) <= v4;
if ( *(_DWORD *)(a1 + 4) == v4
&& (v6 = *(_DWORD *)(a2 + 8), v5 = *(_DWORD *)(a1 + 8) <= v6, *(_DWORD *)(a1 + 8) == v6) )
{
v7 = *(_QWORD *)(a2 + 32);
if ( *(_QWORD *)(a1 + 32) )
{
if ( v7 )
{
result = component_compare();
if ( (_DWORD)result )
return result;
goto LABEL_13;
}
return 0xFFFFFFFFLL;
}
if ( !v7 )
{
LABEL_13:
v8 = *(_QWORD *)(a2 + 56);
if ( !*(_QWORD *)(a1 + 56) )
return (unsigned int)-(v8 != 0);
if ( v8 )
return component_compare();
return 1LL;
}
}
else if ( v5 )
{
return 0xFFFFFFFFLL;
}
return 1LL;
}
result = 0xFFFFFFFFLL;
if ( *(_DWORD *)a1 > *(_DWORD *)a2 )
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v4; // eax
bool v5; // cc
int v6; // eax
__int64 v7; // rsi
__int64 v8; // rsi

if ( *(_DWORD *)a1 == *(_DWORD *)a2 )
{
v4 = *(_DWORD *)(a2 + 4);
v5 = *(_DWORD *)(a1 + 4) <= v4;
if ( *(_DWORD *)(a1 + 4) == v4
&& (v6 = *(_DWORD *)(a2 + 8), v5 = *(_DWORD *)(a1 + 8) <= v6, *(_DWORD *)(a1 + 8) == v6) )
{
v7 = *(_QWORD *)(a2 + 32);
if ( *(_QWORD *)(a1 + 32) )
{
if ( v7 )
{
result = func20();
if ( (_DWORD)result )
return result;
goto LABEL_13;
}
return 0xFFFFFFFFLL;
}
if ( !v7 )
{
LABEL_13:
v8 = *(_QWORD *)(a2 + 56);
if ( !*(_QWORD *)(a1 + 56) )
return (unsigned int)-(v8 != 0);
if ( v8 )
return func20();
return 1LL;
}
}
else if ( v5 )
{
return 0xFFFFFFFFLL;
}
return 1LL;
}
result = 0xFFFFFFFFLL;
if ( *(_DWORD *)a1 > *(_DWORD *)a2 )
result = 1LL;
return result;
}

original_code:
int spec_compare(const spec_t* a, const spec_t* b) {
  if (a->major != b->major) {
    return a->major > b->major ? 1 : -1;
  }
  if (a->minor != b->minor) {
    return a->minor > b->minor ? 1 : -1;
  }
  if (a->patch != b->patch) {
    return a->patch > b->patch ? 1 : -1;
  }
  if (a->release == ((void *)0) && b->release != ((void *)0)) {
    return 1;
  }
  if (a->release != ((void *)0) && b->release == ((void *)0)) {
    return -1;
  }
  if (a->release != ((void *)0) || b->release != ((void *)0)) {
    int release = component_compare(a->release, b->release);
    if (release != 0) {
      return release;
    }
  }
  if (a->build != ((void *)0) && b->build == ((void *)0)) {
    return 1;
  }
  if (a->build == ((void *)0) && b->build != ((void *)0)) {
    return -1;
  }
  if (a->build != ((void *)0) || b->build != ((void *)0)) {
    int build = component_compare(a->build, b->build);
    if (build != 0) {
      return build;
    }
  }
  return 0;
}

canonical_original_code:
int spec_compare(struct spec_s *a, struct spec_s *b) {
  if (a->major != b->major) {
    return a->major > b->major ? 1 : -1;
  }
  if (a->minor != b->minor) {
    return a->minor > b->minor ? 1 : -1;
  }
  if (a->patch != b->patch) {
    return a->patch > b->patch ? 1 : -1;
  }
  if (a->release == ((void *)0) && b->release != ((void *)0)) {
    return 1;
  }
  if (a->release != ((void *)0) && b->release == ((void *)0)) {
    return -1;
  }
  if (a->release != ((void *)0) || b->release != ((void *)0)) {
    int release = component_compare(a->release, b->release);
    if (release != 0) {
      return release;
    }
  }
  if (a->build != ((void *)0) && b->build == ((void *)0)) {
    return 1;
  }
  if (a->build == ((void *)0) && b->build != ((void *)0)) {
    return -1;
  }
  if (a->build != ((void *)0) || b->build != ((void *)0)) {
    int build = component_compare(a->build, b->build);
    if (build != 0) {
      return build;
    }
  }
  return 0;
}

variable_types:
b
struct spec_s *

variable_types: release int

variable_types: build int


decompiled_code:
// attributes: thunk
__int64 __fastcall spec_compare_qsort_a(__int64 a1, __int64 a2)
{
return spec_compare(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
return func13(a1, a2);
}

original_code:
int spec_compare_qsort_a(const void* a, const void* b) {
  return spec_compare(a, b);
}

canonical_original_code:
int spec_compare_qsort_a(void *a, void *b) {
  return spec_compare(a, b);
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
__int64 __fastcall spec_compare_qsort_d(__int64 a1, __int64 a2)
{
return spec_compare(a2, a1);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2)
{
return func13(a2, a1);
}

original_code:
int spec_compare_qsort_d(const void* a, const void* b) {
  return spec_compare(b, a);
}

canonical_original_code:
int spec_compare_qsort_d(void *a, void *b) {
  return spec_compare(b, a);
}


help

decompiled_code:
int help()
{
puts("semver-c 0.0.0");
putchar(10);
puts("A C implementation of the http://semver.org/ specification");
puts("Copyright Conrad Pankoff <deoxxa@fknsrs.biz>");
putchar(10);
puts("This is a very rough clone of node-semver - please see");
puts("https://github.com/isaacs/node-semver for what that is.");
putchar(10);
puts("Usage: semver-c [options] <version> [<version> [...]]");
puts("Prints valid versions sorted by SemVer precedence");
putchar(10);
puts("Options:");
puts("-v");
puts("\tPrints out the version number.");
putchar(10);
puts("-h");
puts("\tThis is the help. You're looking at it.");
putchar(10);
puts("-r <range>");
puts("\tPrint versions that match the specified range.");
putchar(10);
puts("-R");
puts("\tPrint versions in reverse order.");
putchar(10);
puts("Program exits successfully if any valid version satisfies all");
puts("supplied ranges, and prints all satisfying versions.");
putchar(10);
puts("If no satisfying versions are found, then exits failure.");
putchar(10);
puts("Versions are printed in order, so supplying multiple versions");
return puts("to the utility will just sort them.");
}

canonical_decompiled_code:
int func0()
{
puts("semver-c 0.0.0");
putchar(10);
puts("A C implementation of the http://semver.org/ specification");
puts("Copyright Conrad Pankoff <deoxxa@fknsrs.biz>");
putchar(10);
puts("This is a very rough clone of node-semver - please see");
puts("https://github.com/isaacs/node-semver for what that is.");
putchar(10);
puts("Usage: semver-c [options] <version> [<version> [...]]");
puts("Prints valid versions sorted by SemVer precedence");
putchar(10);
puts("Options:");
puts("-v");
puts("\tPrints out the version number.");
putchar(10);
puts("-h");
puts("\tThis is the help. You're looking at it.");
putchar(10);
puts("-r <range>");
puts("\tPrint versions that match the specified range.");
putchar(10);
puts("-R");
puts("\tPrint versions in reverse order.");
putchar(10);
puts("Program exits successfully if any valid version satisfies all");
puts("supplied ranges, and prints all satisfying versions.");
putchar(10);
puts("If no satisfying versions are found, then exits failure.");
putchar(10);
puts("Versions are printed in order, so supplying multiple versions");
return puts("to the utility will just sort them.");
}

original_code:
void help() {
  printf("semver-c " "0.0.0" "\n");
  printf("\n");
  printf("A C implementation of the http://semver.org/ specification\n");
  printf("Copyright Conrad Pankoff <deoxxa@fknsrs.biz>\n");
  printf("\n");
  printf("This is a very rough clone of node-semver - please see\n");
  printf("https://github.com/isaacs/node-semver for what that is.\n");
  printf("\n");
  printf("Usage: semver-c [options] <version> [<version> [...]]\n");
  printf("Prints valid versions sorted by SemVer precedence\n");
  printf("\n");
  printf("Options:\n");
  printf("-v\n");
  printf("\tPrints out the version number.\n");
  printf("\n");
  printf("-h\n");
  printf("\tThis is the help. You're looking at it.\n");
  printf("\n");
  printf("-r <range>\n");
  printf("\tPrint versions that match the specified range.\n");
  printf("\n");
  printf("-R\n");
  printf("\tPrint versions in reverse order.\n");
  printf("\n");
  printf("Program exits successfully if any valid version satisfies all\n");
  printf("supplied ranges, and prints all satisfying versions.\n");
  printf("\n");
  printf("If no satisfying versions are found, then exits failure.\n");
  printf("\n");
  printf("Versions are printed in order, so supplying multiple versions\n");
  printf("to the utility will just sort them.\n");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // r15
__int64 v4; // r12
int v5; // eax
int result; // eax
char *v7; // r12
size_t v8; // rax
__int64 v9; // r13
char *v10; // r14
size_t v11; // rax
__int64 v12; // rbx
__int64 v13; // rdi
int v14; // [rsp+Ch] [rbp-FA4Ch]
const char *v15; // [rsp+10h] [rbp-FA48h]
char v16[64056]; // [rsp+20h] [rbp-FA38h] BYREF

v3 = 0;
v4 = 0LL;
if ( argc == 1 )
{
LABEL_7:
help();
result = 0;
}
else
{
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "vhr:R");
if ( v5 == -1 )
break;
if ( v5 == 114 )
{
v7 = optarg;
v8 = strlen(optarg);
v4 = range_read(v7, v8);
}
else if ( v5 > 114 )
{
if ( v5 == 118 )
{
puts("0.0.0");
return 0;
}
}
else if ( v5 == 82 )
{
v3 = 1;
}
else if ( v5 == 104 )
{
goto LABEL_7;
}
}
v9 = optind;
if ( argc <= optind )
goto LABEL_26;
v14 = 0;
do
{
v10 = &v16[64 * (__int64)v14];
spec_init(v10);
v15 = argv[v9];
v11 = strlen(v15);
if ( (unsigned int)spec_read(v10, v15, v11) != -1 && (!v4 || (unsigned int)range_compare(v4, v10) == 1) )
++v14;
++v9;
}
while ( argc > (int)v9 );
if ( v14 )
{
if ( v3 )
qsort(v16, v14, 0x40uLL, (__compar_fn_t)&spec_compare_qsort_d);
else
qsort(v16, v14, 0x40uLL, (__compar_fn_t)&spec_compare_qsort_a);
v12 = 0LL;
do
{
v13 = v12++;
spec_print(&v16[64 * v13]);
}
while ( v14 > (int)v12 );
result = 0;
}
else
{
LABEL_26:
result = 1;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // r15
__int64 v4; // r12
int v5; // eax
int result; // eax
char *v7; // r12
size_t v8; // rax
__int64 v9; // r13
char *v10; // r14
size_t v11; // rax
__int64 v12; // rbx
__int64 v13; // rdi
int v14; // [rsp+Ch] [rbp-FA4Ch]
const char *v15; // [rsp+10h] [rbp-FA48h]
char v16[64056]; // [rsp+20h] [rbp-FA38h] BYREF

v3 = 0;
v4 = 0LL;
if ( argc == 1 )
{
LABEL_7:
func0();
result = 0;
}
else
{
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "vhr:R");
if ( v5 == -1 )
break;
if ( v5 == 114 )
{
v7 = optarg;
v8 = strlen(optarg);
v4 = range_read(v7, v8);
}
else if ( v5 > 114 )
{
if ( v5 == 118 )
{
puts("0.0.0");
return 0;
}
}
else if ( v5 == 82 )
{
v3 = 1;
}
else if ( v5 == 104 )
{
goto LABEL_7;
}
}
v9 = optind;
if ( argc <= optind )
goto LABEL_26;
v14 = 0;
do
{
v10 = &v16[64 * (__int64)v14];
spec_init(v10);
v15 = argv[v9];
v11 = strlen(v15);
if ( (unsigned int)spec_read(v10, v15, v11) != -1 && (!v4 || (unsigned int)range_compare(v4, v10) == 1) )
++v14;
++v9;
}
while ( argc > (int)v9 );
if ( v14 )
{
if ( v3 )
qsort(v16, v14, 0x40uLL, (__compar_fn_t)&spec_compare_qsort_d);
else
qsort(v16, v14, 0x40uLL, (__compar_fn_t)&spec_compare_qsort_a);
v12 = 0LL;
do
{
v13 = v12++;
spec_print(&v16[64 * v13]);
}
while ( v14 > (int)v12 );
result = 0;
}
else
{
LABEL_26:
result = 1;
}
}
return result;
}

original_code:
int main(int argc, char** argv) {
  int spec_count = 0;
  spec_t spec[1000];
  char reverse = 0;
  range_t* range = ((void *)0);
  int c, i;
  if (argc == 1) {
    help();
    return 0;
  }
  while ((c = getopt(argc, argv, "vhr:R")) != -1) {
    switch (c) {
      case 'v': {
        printf("0.0.0" "\n");
        return 0;
      }
      case 'h': {
        help();
        return 0;
      }
      case 'r': {
        range = range_read(optarg, strlen(optarg));
        break;
      }
      case 'R': {
        reverse = 1;
        break;
      }
    }
  }
  for (i=optind;i<argc;++i) {
    spec_init(&spec[spec_count]);
    if (spec_read(&spec[spec_count], argv[i], strlen(argv[i])) == -1) {
      continue;
    }
    if (range && range_compare(range, &spec[spec_count]) != 1) {
      continue;
    }
    spec_count++;
  }
  if (spec_count == 0) {
    return 1;
  }
  if (reverse) {
    qsort(&spec, spec_count, sizeof(spec_t), &spec_compare_qsort_d);
  } else {
    qsort(&spec, spec_count, sizeof(spec_t), &spec_compare_qsort_a);
  }
  for (i=0;i<spec_count;++i) {
    spec_print(&spec[i]);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  int spec_count = 0;
  struct spec_s spec[1000];
  char reverse = 0;
  struct range_s *range = ((void *)0);
  int c; int i;
  if (argc == 1) {
    help();
    return 0;
  }
  while ((c = getopt(argc, argv, "vhr:R")) != -1) {
    switch (c) {
      case 'v': {
        printf("0.0.0" "\n");
        return 0;
      }
      case 'h': {
        help();
        return 0;
      }
      case 'r': {
        range = range_read(optarg, strlen(optarg));
        break;
      }
      case 'R': {
        reverse = 1;
        break;
      }
    }
  }
  for (i=optind;i<argc;++i) {
    spec_init(&spec[spec_count]);
    if (spec_read(&spec[spec_count], argv[i], strlen(argv[i])) == -1) {
      continue;
    }
    if (range && range_compare(range, &spec[spec_count]) != 1) {
      continue;
    }
    spec_count++;
  }
  if (spec_count == 0) {
    return 1;
  }
  if (reverse) {
    qsort(&spec, spec_count, sizeof(spec_t), &spec_compare_qsort_d);
  } else {
    qsort(&spec, spec_count, sizeof(spec_t), &spec_compare_qsort_a);
  }
  for (i=0;i<spec_count;++i) {
    spec_print(&spec[i]);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct spec_s { int major; int minor; int patch; unsigned long releaseLen; char *releaseRaw; struct component_s { struct component_s *next; char numeric; unsigned long dataLen; char *dataRaw; int dataInt; } *release; unsigned long buildLen; char *buildRaw; struct component_s *build; } [1000]

variable_types: reverse char

variable_types: struct range_s { struct range_s *next; char hasLower; char hasUpper; char includesLower; char includesUpper; struct spec_s { int major; int minor; int patch; unsigned long releaseLen; char *releaseRaw; struct component_s { struct component_s *next; char numeric; unsigned long dataLen; char *dataRaw; int dataInt; } *release; unsigned long buildLen; char *buildRaw; struct component_s *build; } *lower; struct spec_s *upper; } *

variable_types: c int

user_defined_types: struct range_s { struct range_s *next; char hasLower; char hasUpper; char includesLower; char includesUpper; struct spec_s *lower; struct spec_s *upper; }


original_code:
void range_init(range_t* range) {
  range->next = ((void *)0);
  range->hasLower = 0;
  range->hasUpper = 0;
  range->includesLower = 0;
  range->includesUpper = 0;
  range->lower = ((void *)0);
  range->upper = ((void *)0);
}

canonical_original_code:
void range_init(struct range_s *range) {
  range->next = ((void *)0);
  range->hasLower = 0;
  range->hasUpper = 0;
  range->includesLower = 0;
  range->includesUpper = 0;
  range->lower = ((void *)0);
  range->upper = ((void *)0);
}


decompiled_code:
__int64 __fastcall range_compare_one(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // er8

if ( !*(_BYTE *)(a1 + 8) )
{
result = 0LL;
if ( !*(_BYTE *)(a1 + 9) )
return result;
return (int)spec_compare(a2, *(_QWORD *)(a1 + 24)) >= *(char *)(a1 + 11);
}
v3 = spec_compare(a2, *(_QWORD *)(a1 + 16));
result = 0xFFFFFFFFLL;
if ( v3 >= 1 - *(char *)(a1 + 10) )
{
result = 0LL;
if ( *(_BYTE *)(a1 + 9) )
return (int)spec_compare(a2, *(_QWORD *)(a1 + 24)) >= *(char *)(a1 + 11);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // er8

if ( !*(_BYTE *)(a1 + 8) )
{
result = 0LL;
if ( !*(_BYTE *)(a1 + 9) )
return result;
return (int)spec_compare(a2, *(_QWORD *)(a1 + 24)) >= *(char *)(a1 + 11);
}
v3 = spec_compare(a2, *(_QWORD *)(a1 + 16));
result = 0xFFFFFFFFLL;
if ( v3 >= 1 - *(char *)(a1 + 10) )
{
result = 0LL;
if ( *(_BYTE *)(a1 + 9) )
return (int)spec_compare(a2, *(_QWORD *)(a1 + 24)) >= *(char *)(a1 + 11);
}
return result;
}

original_code:
int range_compare_one(const range_t* range, const spec_t* spec) {
  if (range->hasLower && spec_compare(spec, range->lower) < 1 - range->includesLower) {
    return -1;
  }
  if (range->hasUpper && spec_compare(spec, range->upper) >= range->includesUpper) {
    return 1;
  }
  return 0;
}

canonical_original_code:
int range_compare_one(struct range_s *range, struct spec_s *spec) {
  if (range->hasLower && spec_compare(spec, range->lower) < 1 - range->includesLower) {
    return -1;
  }
  if (range->hasUpper && spec_compare(spec, range->upper) >= range->includesUpper) {
    return 1;
  }
  return 0;
}

variable_types:
spec
struct spec_s *


decompiled_code:
__int64 __fastcall range_compare(_QWORD *a1, __int64 a2)
{
do
{
if ( (unsigned int)range_compare_one((__int64)a1, a2) )
return 0LL;
a1 = (_QWORD *)*a1;
}
while ( a1 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, __int64 a2)
{
do
{
if ( (unsigned int)func2((__int64)a1, a2) )
return 0LL;
a1 = (_QWORD *)*a1;
}
while ( a1 );
return 1LL;
}

original_code:
int range_compare(const range_t* range, const spec_t* spec) {
  const range_t* current = range;
  do {
    if (range_compare_one(current, spec) != 0) {
      return 0;
    }
    current = current->next;
  } while (current != ((void *)0));
  return 1;
}

canonical_original_code:
int range_compare(struct range_s *range, struct spec_s *spec) {
  struct range_s *current = range;
  do {
    if (range_compare_one(current, spec) != 0) {
      return 0;
    }
    current = current->next;
  } while (current != ((void *)0));
  return 1;
}


repo: derekchiang/dlmalloc

decompiled_code:
void *__fastcall get_memory(intptr_t delta)
{
void *result; // rax

result = sbrk((unsigned int)delta);
if ( result == (void *)-1LL )
result = 0LL;
return result;
}

canonical_decompiled_code:
void *__fastcall func6(intptr_t delta)
{
void *result; // rax

result = sbrk((unsigned int)delta);
if ( result == (void *)-1LL )
result = 0LL;
return result;
}

original_code:
char* get_memory(unsigned num_bytes) {
    char *page = sbrk((intptr_t) num_bytes);
    return (page != (char*) -1 ? page : ((void *)0));
}

canonical_original_code:
char *get_memory(unsigned int num_bytes) {
    char *page = sbrk((intptr_t) num_bytes);
    return (page != (char *) -1 ? page : ((void *)0));
}

variable_types:
page
char *

return_type: char *


decompiled_code:
char *__fastcall size_to_bin(unsigned __int64 a1)
{
char *i; // rax

for ( i = (char *)&bins; a1 > 0x3F; i += 128 )
a1 >>= 1;
return &i[(4 * a1 - 128) & 0xFFFFFFFFFFFFFFE0LL];
}

canonical_decompiled_code:
char *__fastcall func7(unsigned __int64 a1)
{
char *i; // rax

for ( i = (char *)&bins; a1 > 0x3F; i += 128 )
a1 >>= 1;
return &i[(4 * a1 - 128) & 0xFFFFFFFFFFFFFFE0LL];
}

original_code:
static inline mbin *size_to_bin(size_t sz)
{
    mbin *b = bins;
    while (sz >= ((sizeof(mchunk) + (sizeof(size_t))) * 2)) {
        b += 4;
        sz >>= 1;
    }
    b += (sz - (sizeof(mchunk) + (sizeof(size_t)))) >> ((((sizeof(mchunk) + (sizeof(size_t))) / 4) == 4) ? 2 : 3);
    return b;
}

canonical_original_code:
static inline struct mbin *size_to_bin(unsigned long sz)
{
    struct mbin *b = bins;
    while (sz >= ((sizeof(mchunk) + (sizeof(unsigned long))) * 2)) {
        b += 4;
        sz >>= 1;
    }
    b += (sz - (sizeof(mchunk) + (sizeof(unsigned long)))) >> ((((sizeof(mchunk) + (sizeof(unsigned long))) / 4) == 4) ? 2 : 3);
    return b;
}

variable_types:
sz
unsigned long

variable_types: struct mbin { struct mchunk { unsigned long size; struct mchunk *next; struct mchunk *prev; } head; unsigned long dirty; } *

user_defined_types: struct mbin { struct mchunk head; unsigned long dirty; }


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

result = (a1 + 31) & 0xFFFFFFFFFFFFFFF0LL;
if ( !a1 )
result = 32LL;
return result;
}

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

result = (a1 + 31) & 0xFFFFFFFFFFFFFFF0LL;
if ( !a1 )
result = 32LL;
return result;
}

original_code:
static inline size_t request_to_size(size_t request)
{
    if (request == 0) {
        return (sizeof(mchunk) + (sizeof(size_t)));
    } else {
        return ((request + ((sizeof(size_t)) + (sizeof(size_t))) + (((sizeof(size_t)) + (sizeof(size_t))) - 1))
                & ~((((sizeof(size_t)) + (sizeof(size_t))) - 1)));
    }
}

canonical_original_code:
static inline unsigned long request_to_size(unsigned long request)
{
    if (request == 0) {
        return (sizeof(mchunk) + (sizeof(unsigned long)));
    } else {
        return ((request + ((sizeof(unsigned long)) + (sizeof(unsigned long))) + (((sizeof(unsigned long)) + (sizeof(unsigned long))) - 1))
                & ~((((sizeof(unsigned long)) + (sizeof(unsigned long))) - 1)));
    }
}

variable_types:
request
unsigned long

return_type: unsigned long


decompiled_code:
_BOOL8 __fastcall is_aligned(char a1)
{
return (a1 & 0xF) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(char a1)
{
return (a1 & 0xF) == 0;
}

original_code:
static inline int is_aligned(void *m)
{
    return ((size_t) (m) & ((((sizeof(size_t)) + (sizeof(size_t))) - 1))) == 0;
}

canonical_original_code:
static inline int is_aligned(void *m)
{
    return ((unsigned long) (m) & ((((sizeof(unsigned long)) + (sizeof(unsigned long))) - 1))) == 0;
}

variable_types:
m
void *


inuse

decompiled_code:
__int64 __fastcall inuse(_QWORD *a1)
{
return *a1 & 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1)
{
return *a1 & 1LL;
}

original_code:
static inline int inuse(mchunk *chunk)
{
    return chunk->size & 0x1;
}

canonical_original_code:
static inline int inuse(struct mchunk *chunk)
{
    return chunk->size & 0x1;
}

variable_types: struct mchunk { unsigned long size; struct mchunk *next; struct mchunk *prev; } *


decompiled_code:
char *__fastcall next_chunk(_QWORD *a1)
{
return (char *)a1 + *a1;
}

canonical_decompiled_code:
char *__fastcall func13(_QWORD *a1)
{
return (char *)a1 + *a1;
}

original_code:
static inline mchunk *next_chunk(mchunk *p)
{
    return ((mchunk *)((char *)(p) + (p)->size));
}

canonical_original_code:
static inline struct mchunk *next_chunk(struct mchunk *p)
{
    return ((struct mchunk *)((char *)(p) + (p)->size));
}

variable_types:
p
struct mchunk *

return_type: struct mchunk { unsigned long size; struct mchunk *next; struct mchunk *prev; } *


decompiled_code:
__int64 __fastcall prev_chunk(__int64 a1)
{
return a1 - (*(_QWORD *)(a1 - 8) & 0xFFFFFFFFFFFFFFFELL);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return a1 - (*(_QWORD *)(a1 - 8) & 0xFFFFFFFFFFFFFFFELL);
}

original_code:
static inline mchunk *prev_chunk(mchunk *p)
{
    size_t prev_size = ((size_t *)(p))[-1] & ~(0x1);
    return (mchunk *)((char *)(p) - prev_size);
}

canonical_original_code:
static inline struct mchunk *prev_chunk(struct mchunk *p)
{
    unsigned long prev_size = ((size_t *)(p))[-1] & ~(0x1);
    return (struct mchunk *)((char *)(p) - prev_size);
}

user_defined_types: struct mchunk { unsigned long size; struct mchunk *next; struct mchunk *prev; }


decompiled_code:
void __fastcall set_size(_QWORD *a1, __int64 a2)
{
*a1 = a2;
*(_QWORD *)((char *)a1 + a2 - 8) = a2;
}

canonical_decompiled_code:
void __fastcall func15(_QWORD *a1, __int64 a2)
{
*a1 = a2;
*(_QWORD *)((char *)a1 + a2 - 8) = a2;
}

original_code:
static inline void set_size(mchunk *ptr, size_t sz)
{
    ptr->size = sz;
    *(((size_t*)(((char *) ptr) + ptr->size - (sizeof(size_t))))) = sz;
}

canonical_original_code:
static inline void set_size(struct mchunk *ptr, unsigned long sz)
{
    ptr->size = sz;
    *(((unsigned long *)(((char *) ptr) + ptr->size - (sizeof(unsigned long))))) = sz;
}


decompiled_code:
void __fastcall mem_to_chunk(__int64 a1)
{
unset_inuse((_QWORD *)(a1 - 8));
}

canonical_decompiled_code:
void __fastcall func16(__int64 a1)
{
func12((_QWORD *)(a1 - 8));
}

original_code:
static inline mchunk *mem_to_chunk(void *mem)
{
    mchunk *chunk = (mchunk *) ((char *)mem - (sizeof(size_t)));
    unset_inuse(chunk);
    return chunk;
}

canonical_original_code:
static inline struct mchunk *mem_to_chunk(void *mem)
{
    struct mchunk *chunk = (mchunk *) ((char *)mem - (sizeof(size_t)));
    unset_inuse(chunk);
    return chunk;
}

variable_types:
mem
void *


decompiled_code:
__int64 __fastcall rm_chunk_from_bin(__int64 a1)
{
__int64 v1; // rdx
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 16);
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(v1 + 8) = result;
*(_QWORD *)(result + 16) = v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
__int64 v1; // rdx
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 16);
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(v1 + 8) = result;
*(_QWORD *)(result + 16) = v1;
return result;
}

original_code:
static inline void rm_chunk_from_bin(mchunk *chunk)
{
    mchunk *p = chunk->prev;
    mchunk *n = chunk->next;
    p->next = n;
    n->prev = p;
}

canonical_original_code:
static inline void rm_chunk_from_bin(struct mchunk *chunk)
{
    struct mchunk *p = chunk->prev;
    struct mchunk *n = chunk->next;
    p->next = n;
    n->prev = p;
}


decompiled_code:
char *__fastcall place_chunk_back(unsigned __int64 *a1)
{
char *result; // rax
__int64 v2; // rdx
__int64 v3; // rcx

result = size_to_bin(*a1);
v2 = *((_QWORD *)result + 2);
*((_QWORD *)result + 2) = v3;
*(_QWORD *)(v2 + 8) = v3;
*(_QWORD *)(v3 + 16) = v2;
*(_QWORD *)(v3 + 8) = result;
if ( result == (char *)v2 && max_used_bin < result )
max_used_bin = result;
return result;
}

canonical_decompiled_code:
char *__fastcall func18(unsigned __int64 *a1)
{
char *result; // rax
__int64 v2; // rdx
__int64 v3; // rcx

result = func7(*a1);
v2 = *((_QWORD *)result + 2);
*((_QWORD *)result + 2) = v3;
*(_QWORD *)(v2 + 8) = v3;
*(_QWORD *)(v3 + 16) = v2;
*(_QWORD *)(v3 + 8) = result;
if ( result == (char *)v2 && max_used_bin < result )
max_used_bin = result;
return result;
}

original_code:
static inline void place_chunk_back(mchunk *chunk)
{
    mbin *bin = size_to_bin(chunk->size);
    mchunk *head = (&(bin->head));
    mchunk *back = head->prev;
    back->next = head->prev = chunk;
    chunk->prev = back;
    chunk->next = head;
    if (head == back && bin > max_used_bin) {
        max_used_bin = bin;
    }
}

canonical_original_code:
static inline void place_chunk_back(struct mchunk *chunk)
{
    struct mbin *bin = size_to_bin(chunk->size);
    struct mchunk *head = (&(bin->head));
    struct mchunk *back = head->prev;
    back->next = head->prev = chunk;
    chunk->prev = back;
    chunk->next = head;
    if (head == back && bin > max_used_bin) {
        max_used_bin = bin;
    }
}


decompiled_code:
char *__fastcall place_chunk_front(unsigned __int64 *a1)
{
char *result; // rax
__int64 v2; // rdx
__int64 v3; // rcx

result = size_to_bin(*a1);
v2 = *((_QWORD *)result + 1);
*((_QWORD *)result + 1) = v3;
*(_QWORD *)(v2 + 16) = v3;
*(_QWORD *)(v3 + 16) = result;
*(_QWORD *)(v3 + 8) = v2;
if ( result == (char *)v2 && max_used_bin < result )
{
max_used_bin = result;
*((_QWORD *)result + 3) = 1LL;
}
else
{
*((_QWORD *)result + 3) = 1LL;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func19(unsigned __int64 *a1)
{
char *result; // rax
__int64 v2; // rdx
__int64 v3; // rcx

result = func7(*a1);
v2 = *((_QWORD *)result + 1);
*((_QWORD *)result + 1) = v3;
*(_QWORD *)(v2 + 16) = v3;
*(_QWORD *)(v3 + 16) = result;
*(_QWORD *)(v3 + 8) = v2;
if ( result == (char *)v2 && max_used_bin < result )
{
max_used_bin = result;
*((_QWORD *)result + 3) = 1LL;
}
else
{
*((_QWORD *)result + 3) = 1LL;
}
return result;
}

original_code:
static inline void place_chunk_front(mchunk *chunk)
{
    mbin *bin = size_to_bin(chunk->size);
    mchunk *head = (&(bin->head));
    mchunk *front = head->next;
    front->prev = head->next = chunk;
    chunk->prev = head;
    chunk->next = front;
    if (head == front && bin > max_used_bin) {
        max_used_bin = bin;
    }
    bin->dirty = 1;
}

canonical_original_code:
static inline void place_chunk_front(struct mchunk *chunk)
{
    struct mbin *bin = size_to_bin(chunk->size);
    struct mchunk *head = (&(bin->head));
    struct mchunk *front = head->next;
    front->prev = head->next = chunk;
    chunk->prev = head;
    chunk->next = front;
    if (head == front && bin > max_used_bin) {
        max_used_bin = bin;
    }
    bin->dirty = 1;
}


decompiled_code:
char *__fastcall split_chunk(unsigned __int64 *a1, unsigned __int64 a2)
{
char *result; // rax
unsigned __int64 *v3; // rdi
__int64 v4; // rax

result = (char *)*a1;
if ( *a1 > a2 )
{
result -= a2;
if ( (unsigned __int64)result > 0x1F )
{
set_size(a1, a2);
v3 = (unsigned __int64 *)((char *)a1 + a2);
set_size(v3, v4);
result = place_chunk_back(v3);
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func20(unsigned __int64 *a1, unsigned __int64 a2)
{
char *result; // rax
unsigned __int64 *v3; // rdi
__int64 v4; // rax

result = (char *)*a1;
if ( *a1 > a2 )
{
result -= a2;
if ( (unsigned __int64)result > 0x1F )
{
func15(a1, a2);
v3 = (unsigned __int64 *)((char *)a1 + a2);
func15(v3, v4);
result = func18(v3);
}
}
return result;
}

original_code:
static inline void split_chunk(mchunk *chunk, size_t offset)
{
    if (chunk->size > offset) {
        size_t new_chunk_sz = chunk->size - offset;
        mchunk *new_chunk = (mchunk *)((char *)chunk + offset);
        if (new_chunk_sz >= (sizeof(mchunk) + (sizeof(size_t)))) {
            set_size(chunk, offset);
            set_size(new_chunk, new_chunk_sz);
            place_chunk_back(new_chunk);
        }
    }
}

canonical_original_code:
static inline void split_chunk(struct mchunk *chunk, unsigned long offset)
{
    if (chunk->size > offset) {
        unsigned long new_chunk_sz = chunk->size - offset;
        struct mchunk *new_chunk = (mchunk *)((char *)chunk + offset);
        if (new_chunk_sz >= (sizeof(mchunk) + (sizeof(unsigned long)))) {
            set_size(chunk, offset);
            set_size(new_chunk, new_chunk_sz);
            place_chunk_back(new_chunk);
        }
    }
}

variable_types:
offset
unsigned long


decompiled_code:
unsigned __int64 *__fastcall merge_and_find_chunks(unsigned __int64 a1)
{
_QWORD *v1; // r10
_QWORD *v2; // r11
char v3; // al
_QWORD *v5; // r9
__int64 v6; // r8
int i; // esi
_QWORD *v8; // rdi
_QWORD *v9; // r8
_QWORD *v10; // rcx
_QWORD *v11; // rax
__int64 v12; // rcx
_QWORD *v13; // r8
__int64 v14; // rcx
_QWORD *v15; // rcx
_QWORD *v16; // r8
char *v17; // rax
unsigned __int64 *v18; // r8
unsigned __int64 *result; // rax

v1 = max_used_bin;
v2 = &bins;
if ( max_used_bin < &bins )
return 0LL;
v3 = 0;
while ( v1 == (_QWORD *)v1[2] )
{
v1[3] = 0LL;
v1 -= 4;
v3 = 1;
if ( v1 < &bins )
{
max_used_bin = v1;
return 0LL;
}
}
if ( v3 )
max_used_bin = v1;
if ( v1 >= &bins )
{
do
{
if ( v1[3] )
{
v5 = (_QWORD *)v1[1];
while ( v5 != v1 )
{
while ( 1 )
{
v6 = (__int64)v5;
for ( i = 0; ; i = 1 )
{
v11 = (_QWORD *)prev_chunk(v6);
if ( (unsigned int)inuse(v11) )
break;
if ( !i )
rm_chunk_from_bin((__int64)v13);
v8 = (_QWORD *)v12;
rm_chunk_from_bin(v12);
set_size(v8, *v10 + *v9);
}
while ( 1 )
{
v17 = next_chunk(v13);
if ( (unsigned int)inuse(v17) )
break;
if ( !i )
rm_chunk_from_bin((__int64)v18);
rm_chunk_from_bin(v14);
set_size(v16, *v16 + *v15);
i = 1;
}
if ( !i )
break;
if ( *v18 >= a1 )
{
v18[2] = (unsigned __int64)v18;
result = v18;
v18[1] = (unsigned __int64)v18;
return result;
}
place_chunk_back(v18);
if ( v5 == v1 )
goto LABEL_26;
}
}
LABEL_26:
v1[3] = 0LL;
}
v1 -= 4;
}
while ( v1 >= v2 );
}
return 0LL;
}

canonical_decompiled_code:
unsigned __int64 *__fastcall func21(unsigned __int64 a1)
{
_QWORD *v1; // r10
_QWORD *v2; // r11
char v3; // al
_QWORD *v5; // r9
__int64 v6; // r8
int i; // esi
_QWORD *v8; // rdi
_QWORD *v9; // r8
_QWORD *v10; // rcx
_QWORD *v11; // rax
__int64 v12; // rcx
_QWORD *v13; // r8
__int64 v14; // rcx
_QWORD *v15; // rcx
_QWORD *v16; // r8
char *v17; // rax
unsigned __int64 *v18; // r8
unsigned __int64 *result; // rax

v1 = max_used_bin;
v2 = &bins;
if ( max_used_bin < &bins )
return 0LL;
v3 = 0;
while ( v1 == (_QWORD *)v1[2] )
{
v1[3] = 0LL;
v1 -= 4;
v3 = 1;
if ( v1 < &bins )
{
max_used_bin = v1;
return 0LL;
}
}
if ( v3 )
max_used_bin = v1;
if ( v1 >= &bins )
{
do
{
if ( v1[3] )
{
v5 = (_QWORD *)v1[1];
while ( v5 != v1 )
{
while ( 1 )
{
v6 = (__int64)v5;
for ( i = 0; ; i = 1 )
{
v11 = (_QWORD *)func14(v6);
if ( (unsigned int)func10(v11) )
break;
if ( !i )
func17((__int64)v13);
v8 = (_QWORD *)v12;
func17(v12);
func15(v8, *v10 + *v9);
}
while ( 1 )
{
v17 = func13(v13);
if ( (unsigned int)func10(v17) )
break;
if ( !i )
func17((__int64)v18);
func17(v14);
func15(v16, *v16 + *v15);
i = 1;
}
if ( !i )
break;
if ( *v18 >= a1 )
{
v18[2] = (unsigned __int64)v18;
result = v18;
v18[1] = (unsigned __int64)v18;
return result;
}
func18(v18);
if ( v5 == v1 )
goto LABEL_26;
}
}
LABEL_26:
v1[3] = 0LL;
}
v1 -= 4;
}
while ( v1 >= v2 );
}
return 0LL;
}

original_code:
static mchunk *merge_and_find_chunks(size_t sz)
{
    while ((max_used_bin >= (&(bins[0]))) &&
           ((&(max_used_bin->head))->prev == (&(max_used_bin->head)))) {
        max_used_bin->dirty = 0;
        max_used_bin -= 1;
    }
    mbin *b = max_used_bin;
    while (b >= (&(bins[0]))) {
        if (b->dirty) {
            mchunk *bin_head = (&(b->head));
            mchunk *chunk = bin_head->next;
            while (chunk != bin_head) {
                mchunk *next_to_merge = chunk->next;
                int merged = 0;
                mchunk *prev;
                while (!inuse(prev = prev_chunk(chunk))) {
                    if (!merged) {
                        merged = 1;
                        rm_chunk_from_bin(chunk);
                    }
                    if (prev == next_to_merge) {
                        next_to_merge = prev->next;
                    }
                    rm_chunk_from_bin(prev);
                    set_size(prev, prev->size + chunk->size);
                    chunk = prev;
                }
                mchunk *next;
                while (!inuse(next = next_chunk(chunk))) {
                    if (!merged) {
                        merged = 1;
                        rm_chunk_from_bin(chunk);
                    }
                    if (next == next_to_merge) {
                        next_to_merge = next->next;
                    }
                    rm_chunk_from_bin(next);
                    set_size(chunk, chunk->size + next->size);
                }
                if (merged) {
                    if (chunk->size >= sz) {
                        chunk->next = chunk->prev = chunk;
                        return chunk;
                    } else {
                        place_chunk_back(chunk);
                    }
                }
                chunk = next_to_merge;
            }
            b->dirty = 0;
        }
        b--;
    }
    return ((void *)0);
}

canonical_original_code:
static struct mchunk *merge_and_find_chunks(unsigned long sz)
{
    while ((max_used_bin >= (&(bins[0]))) &&
           ((&(max_used_bin->head))->prev == (&(max_used_bin->head)))) {
        max_used_bin->dirty = 0;
        max_used_bin -= 1;
    }
    struct mbin *b = max_used_bin;
    while (b >= (&(bins[0]))) {
        if (b->dirty) {
            struct mchunk *bin_head = (&(b->head));
            struct mchunk *chunk = bin_head->next;
            while (chunk != bin_head) {
                struct mchunk *next_to_merge = chunk->next;
                int merged = 0;
                struct mchunk *prev;
                while (!inuse(prev = prev_chunk(chunk))) {
                    if (!merged) {
                        merged = 1;
                        rm_chunk_from_bin(chunk);
                    }
                    if (prev == next_to_merge) {
                        next_to_merge = prev->next;
                    }
                    rm_chunk_from_bin(prev);
                    set_size(prev, prev->size + chunk->size);
                    chunk = prev;
                }
                struct mchunk *next;
                while (!inuse(next = next_chunk(chunk))) {
                    if (!merged) {
                        merged = 1;
                        rm_chunk_from_bin(chunk);
                    }
                    if (next == next_to_merge) {
                        next_to_merge = next->next;
                    }
                    rm_chunk_from_bin(next);
                    set_size(chunk, chunk->size + next->size);
                }
                if (merged) {
                    if (chunk->size >= sz) {
                        chunk->next = chunk->prev = chunk;
                        return chunk;
                    } else {
                        place_chunk_back(chunk);
                    }
                }
                chunk = next_to_merge;
            }
            b->dirty = 0;
        }
        b--;
    }
    return ((void *)0);
}

variable_types: merged int


highest

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

for ( result = 0LL; a1; a1 >>= 1 )
++result;
return result;
}

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

for ( result = 0LL; a1; a1 >>= 1 )
++result;
return result;
}

original_code:
static size_t highest(size_t in)
{
    size_t num_bits = 0;
    while (in != 0) {
        ++num_bits;
        in >>= 1;
    }
    return num_bits;
}

canonical_original_code:
static unsigned long highest(unsigned long in)
{
    unsigned long num_bits = 0;
    while (in != 0) {
        ++num_bits;
        in >>= 1;
    }
    return num_bits;
}

variable_types:
in
unsigned long


calloc

decompiled_code:
void *__fastcall calloc(unsigned __int64 a1, unsigned __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 v4; // rcx

highest(a1);
v2 = highest(a2);
if ( (unsigned __int64)(v2 + v4) <= 0x40 )
return calloc(a2 * v3, 1uLL);
*__errno_location() = 12;
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func23(unsigned __int64 a1, unsigned __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 v4; // rcx

func22(a1);
v2 = func22(a2);
if ( (unsigned __int64)(v2 + v4) <= 0x40 )
return func23(a2 * v3, 1uLL);
*__errno_location() = 12;
return 0LL;
}

original_code:
void *calloc(size_t number, size_t size)
{
    size_t number_size = 0;
    if (highest(number) + highest(size) > sizeof(size_t) * 8) {
        (*__errno_location ()) = 12;
        return ((void *)0);
    }
    number_size = number * size;
    void *ret = malloc(number_size);
    if (ret) {
        memset(ret, 0, number_size);
    }
    return ret;
}

canonical_original_code:
void *calloc(unsigned long number, unsigned long size)
{
    unsigned long number_size = 0;
    if (highest(number) + highest(size) > sizeof(unsigned long) * 8) {
        (*__errno_location ()) = 12;
        return ((void *)0);
    }
    number_size = number * size;
    void *ret = malloc(number_size);
    if (ret) {
        memset(ret, 0, number_size);
    }
    return ret;
}

variable_types:
number
unsigned long

variable_types:
size
unsigned long

variable_types:
ret
void *

return_type: void *


free

decompiled_code:
void __fastcall free(__int64 a1)
{
unsigned __int64 *v1; // rax

if ( a1 )
{
mem_to_chunk(a1);
place_chunk_front(v1);
}
}

canonical_decompiled_code:
void __fastcall func24(__int64 a1)
{
unsigned __int64 *v1; // rax

if ( a1 )
{
func16(a1);
func19(v1);
}
}

original_code:
void free(void *ptr)
{
    if (ptr != 0) {
        mchunk *chunk = mem_to_chunk(ptr);
        place_chunk_front(chunk);
    }
}

canonical_original_code:
void free(void *ptr)
{
    if (ptr != 0) {
        struct mchunk *chunk = mem_to_chunk(ptr);
        place_chunk_front(chunk);
    }
}

variable_types:
ptr
void *


decompiled_code:
__int64 __fastcall is_completed()
{
unsigned int v0; // er12

pthread_mutex_lock(&completed_mutex);
LOBYTE(v0) = completed == N;
pthread_mutex_unlock(&completed_mutex);
return v0;
}

canonical_decompiled_code:
__int64 __fastcall func7()
{
unsigned int v0; // er12

pthread_mutex_lock(&completed_mutex);
LOBYTE(v0) = completed == N;
pthread_mutex_unlock(&completed_mutex);
return v0;
}

original_code:
bool is_completed() {
  pthread_mutex_lock(&completed_mutex);
  bool res = (completed == N);
  pthread_mutex_unlock(&completed_mutex);
  return res;
}

canonical_original_code:
_Bool is_completed() {
  pthread_mutex_lock(&completed_mutex);
  _Bool res = (completed == N);
  pthread_mutex_unlock(&completed_mutex);
  return res;
}


decompiled_code:
int __fastcall report_completed(int a1)
{
pthread_mutex_lock(&completed_mutex);
completed += a1;
return pthread_mutex_unlock(&completed_mutex);
}

canonical_decompiled_code:
int __fastcall func8(int a1)
{
pthread_mutex_lock(&completed_mutex);
completed += a1;
return pthread_mutex_unlock(&completed_mutex);
}

original_code:
void report_completed(int num) {
  pthread_mutex_lock(&completed_mutex);
  completed += num;
  pthread_mutex_unlock(&completed_mutex);
}

variable_types: num int


swap

decompiled_code:
int *__fastcall swap(int a1, int a2)
{
int *v2; // rdx
int *result; // rax
int v4; // ecx

if ( a1 != a2 )
{
v2 = (int *)((char *)array + 4 * a1);
result = (int *)((char *)array + 4 * a2);
v4 = *v2;
*v2 = *result;
*result = v4;
}
return result;
}

canonical_decompiled_code:
int *__fastcall func9(int a1, int a2)
{
int *v2; // rdx
int *result; // rax
int v4; // ecx

if ( a1 != a2 )
{
v2 = (int *)((char *)array + 4 * a1);
result = (int *)((char *)array + 4 * a2);
v4 = *v2;
*v2 = *result;
*result = v4;
}
return result;
}

original_code:
void swap(int a, int b)
{
  if (a == b) return;
  int tmp = array[a];
  array[a] = array[b];
  array[b] = tmp;
}

variable_types: a int

variable_types: b int

variable_types: tmp int


decompiled_code:
int __fastcall bubble_sort(int a1, int a2)
{
__int64 v3; // r13
int v4; // ebx
int i; // ebp
__int64 v6; // r11
__int64 v7; // r9
int v8; // er8
int result; // eax

if ( a1 <= a2 )
{
v3 = 4LL * a1 + 4;
v4 = a1;
for ( i = a1 + 1; a2 >= i; ++i )
{
v6 = v3 - 4;
v7 = v3;
v8 = i;
do
{
while ( *(_DWORD *)((char *)array + v6) <= *(_DWORD *)((char *)array + v7) )
{
++v8;
v7 += 4LL;
if ( a2 < v8 )
goto LABEL_7;
}
swap(v4, v8);
}
while ( a2 >= v8 );
LABEL_7:
v4 = i;
v3 += 4LL;
}
result = report_completed(a2 - a1 + 1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(int a1, int a2)
{
__int64 v3; // r13
int v4; // ebx
int i; // ebp
__int64 v6; // r11
__int64 v7; // r9
int v8; // er8
int result; // eax

if ( a1 <= a2 )
{
v3 = 4LL * a1 + 4;
v4 = a1;
for ( i = a1 + 1; a2 >= i; ++i )
{
v6 = v3 - 4;
v7 = v3;
v8 = i;
do
{
while ( *(_DWORD *)((char *)array + v6) <= *(_DWORD *)((char *)array + v7) )
{
++v8;
v7 += 4LL;
if ( a2 < v8 )
goto LABEL_7;
}
func9(v4, v8);
}
while ( a2 >= v8 );
LABEL_7:
v4 = i;
v3 += 4LL;
}
result = func8(a2 - a1 + 1);
}
return result;
}

original_code:
void bubble_sort(int low, int high)
{
  if (low > high) return;
  int i, j;
  for (i = low; i <= high; i++)
    for (j = i+1; j <= high; j++)
      if (array[i] > array[j])
 swap(i, j);
  report_completed(high-low+1);
}

canonical_original_code:
void bubble_sort(int low, int high)
{
  if (low > high) return;
  int i; int j;
  for (i = low; i <= high; i++)
    for (j = i+1; j <= high; j++)
      if (array[i] > array[j])
 swap(i, j);
  report_completed(high-low+1);
}

variable_types: low int

variable_types: high int

variable_types: i int

variable_types: j int


partition

decompiled_code:
__int64 __fastcall partition(int a1, int a2)
{
unsigned int v2; // er12
__int64 v3; // r9
int v4; // er10
int v5; // er11
int v6; // er8
int v7; // esi
__int64 v8; // r9

v2 = a1;
swap(a1, a2);
if ( a1 < v4 )
{
v6 = a1;
do
{
while ( *(_DWORD *)((char *)array + v3) >= v5 )
{
++v6;
v3 += 4LL;
if ( v4 == v6 )
goto LABEL_6;
}
v7 = v2++;
swap(v6, v7);
v3 = v8 + 4;
}
while ( v4 != v6 );
}
LABEL_6:
swap(v4, v2);
report_completed(1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int a2)
{
unsigned int v2; // er12
__int64 v3; // r9
int v4; // er10
int v5; // er11
int v6; // er8
int v7; // esi
__int64 v8; // r9

v2 = a1;
func9(a1, a2);
if ( a1 < v4 )
{
v6 = a1;
do
{
while ( *(_DWORD *)((char *)array + v3) >= v5 )
{
++v6;
v3 += 4LL;
if ( v4 == v6 )
goto LABEL_6;
}
v7 = v2++;
func9(v6, v7);
v3 = v8 + 4;
}
while ( v4 != v6 );
}
LABEL_6:
func9(v4, v2);
func8(1);
return v2;
}

original_code:
int partition(int low, int high)
{
  int pivot = array[low], middle = low, i;
  swap(low, high);
  for(i=low; i<high; i++) {
    if(array[i] < pivot) {
      swap(i, middle);
      middle++;
    }
  }
  swap(high, middle);
  report_completed(1);
  return(middle);
}

canonical_original_code:
int partition(int low, int high)
{
  int pivot = array[low]; int middle = low; int i;
  swap(low, high);
  for(i=low; i<high; i++) {
    if(array[i] < pivot) {
      swap(i, middle);
      middle++;
    }
  }
  swap(high, middle);
  report_completed(1);
  return(middle);
}

variable_types: pivot int

variable_types: middle int


submit

decompiled_code:
int __fastcall submit(int a1, int a2)
{
_DWORD *v2; // rax
_DWORD *v3; // rbp

v2 = malloc(8uLL);
*v2 = a1;
v3 = v2;
v2[1] = a2;
pthread_mutex_lock(&queue_mutex);
enqueue(v3);
pthread_cond_signal(&queue_cond);
return pthread_mutex_unlock(&queue_mutex);
}

canonical_decompiled_code:
int __fastcall func12(int a1, int a2)
{
_DWORD *v2; // rax
_DWORD *v3; // rbp

v2 = malloc(8uLL);
*v2 = a1;
v3 = v2;
v2[1] = a2;
pthread_mutex_lock(&queue_mutex);
enqueue(v3);
pthread_cond_signal(&queue_cond);
return pthread_mutex_unlock(&queue_mutex);
}

original_code:
void submit(int low, int high) {
  struct range *r = (struct range*) malloc(sizeof(struct range));
  r->begin = low;
  r->end = high;
  pthread_mutex_lock(&queue_mutex);
  enqueue(r);
  pthread_cond_signal(&queue_cond);
  if(0) printf ("submit (%d, %d)\n", low, high);
  pthread_mutex_unlock(&queue_mutex);
}

variable_types:
r
struct range { int begin; int end; } *


quicksort

decompiled_code:
int __fastcall quicksort(int a1, int a2)
{
int v2; // ebp
int v3; // ebx

v2 = a1;
if ( a2 - a1 > 9 )
{
do
{
v3 = partition(v2, a2);
submit(v2, v3 - 1);
v2 = v3 + 1;
}
while ( a2 - (v3 + 1) > 9 );
}
return bubble_sort(v2, a2);
}

original_code:
void quicksort(int low, int high)
{
  if (high - low < 10) {
    bubble_sort(low, high);
    return;
  }
  int middle = partition(low, high);
  submit(low, middle-1);
  quicksort(middle+1, high);
}


worker

decompiled_code:
int __fastcall worker(__int64 a1)
{
int *v1; // rbp

printf("Thread %ld starts ...\n", a1);
while ( !(unsigned __int8)is_completed() )
{
while ( 1 )
{
pthread_mutex_lock(&queue_mutex);
while ( (unsigned __int8)empty() && !(unsigned __int8)is_completed() )
pthread_cond_wait(&queue_cond, &queue_mutex);
v1 = (int *)dequeue();
pthread_mutex_unlock(&queue_mutex);
if ( !v1 )
break;
quicksort(*v1, v1[1]);
free(v1);
printf("%ld.", a1);
if ( (unsigned __int8)is_completed() )
return pthread_cond_signal(&queue_cond);
}
}
return pthread_cond_signal(&queue_cond);
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1)
{
int *v1; // rbp

printf("Thread %ld starts ...\n", a1);
while ( !(unsigned __int8)func7() )
{
while ( 1 )
{
pthread_mutex_lock(&queue_mutex);
while ( (unsigned __int8)func16() && !(unsigned __int8)func7() )
pthread_cond_wait(&queue_cond, &queue_mutex);
v1 = (int *)func17();
pthread_mutex_unlock(&queue_mutex);
if ( !v1 )
break;
func13(*v1, v1[1]);
free(v1);
printf("%ld.", a1);
if ( (unsigned __int8)func7() )
return pthread_cond_signal(&queue_cond);
}
}
return pthread_cond_signal(&queue_cond);
}

original_code:
void worker(long rank) {
  struct range *r = ((void *)0);
  printf("Thread %ld starts ...\n", rank);
  while (!is_completed()) {
    if(0) printf ("TID (%ld): ready\n", rank);
    pthread_mutex_lock(&queue_mutex);
    while (empty() && !is_completed()) {
      if(0) printf ("TID (%ld): waiting for signal\n", rank);
      pthread_cond_wait(&queue_cond, &queue_mutex);
    }
    r = dequeue();
    pthread_mutex_unlock(&queue_mutex);
    if (r != ((void *)0)) {
      if(0) printf ("TID (%ld): get (%d, %d)\n", rank, r->begin, r->end);
      quicksort(r->begin, r->end);
      free(r);
      printf("%ld.", rank);
    }
  }
  pthread_cond_signal(&queue_cond);
  if(0) printf ("TID (%ld): thread quit\n", rank);
}

variable_types: rank long


decompiled_code:
void *__fastcall child_proc(void *a1)
{
worker((__int64)a1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func15(void *a1)
{
func14((__int64)a1);
return 0LL;
}

original_code:
void* child_proc(void *ip)
{
  worker((long)ip);
  return ((void *)0);
}

canonical_original_code:
void *child_proc(void *ip)
{
  worker((long)ip);
  return ((void *)0);
}

variable_types:
ip
void *


empty

decompiled_code:
bool empty()
{
return head == 0LL;
}

canonical_decompiled_code:
bool func16()
{
return head == 0LL;
}

original_code:
bool empty() {
  if(head == ((void *)0)) {
    return (1==1);
  } else {
    return (1!=1);
  }
}

canonical_original_code:
_Bool empty() {
  if(head == ((void *)0)) {
    return (1==1);
  } else {
    return (1!=1);
  }
}


dequeue

decompiled_code:
__int64 dequeue()
{
void *v0; // rdi
__int64 v1; // r12

if ( empty() )
return 0LL;
v0 = head;
v1 = *((_QWORD *)head + 1);
head = *(void **)head;
if ( !head )
tail = 0LL;
free(v0);
return v1;
}

canonical_decompiled_code:
__int64 func17()
{
void *v0; // rdi
__int64 v1; // r12

if ( func16() )
return 0LL;
v0 = head;
v1 = *((_QWORD *)head + 1);
head = *(void **)head;
if ( !head )
tail = 0LL;
free(v0);
return v1;
}

original_code:
void* dequeue() {
  if(empty()) {
    return ((void *)0);
  }
  struct node *temp = head;
  void *data = temp->data;
  head = head->next;
  if (head == ((void *)0)) {
    tail = head;
  }
  free(temp);
  return data;
}

canonical_original_code:
void *dequeue() {
  if(empty()) {
    return ((void *)0);
  }
  struct node *temp = head;
  void *data = temp->data;
  head = head->next;
  if (head == ((void *)0)) {
    tail = head;
  }
  free(temp);
  return data;
}

variable_types: struct node { struct node *next; void *data; } *

variable_types:
data
void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // er13
int v5; // eax
int v6; // er12
__int64 v7; // rbx
pthread_t *v8; // rbp
pthread_t *v9; // r13
int v10; // ebx
_DWORD *v11; // rdx
__int64 v12; // rax
int v13; // ebx
unsigned int v14; // eax
int v15; // esi
int v16; // eax
__int64 v17; // rdi
pthread_t *v18; // rbx
__int64 v19; // r12
pthread_t v20; // rdi
__int64 v21; // rcx
__int64 v22; // r8
unsigned int *v23; // rax
__int64 v24; // rdx
unsigned int v25; // er9

if ( (unsigned int)(argc - 2) > 1 )
{
puts("Usage: qsort_queue N [num_threads]");
exit(0);
}
v3 = atoi(argv[1]);
N = v3;
v4 = v3;
if ( v3 <= 1 )
{
puts("N must be greater than 2");
exit(0);
}
if ( argc == 2 )
{
printf("Quicksort with %d threads (queue version), array_size = %d\n", 1LL, (unsigned int)v3);
v8 = 0LL;
pthread_mutex_init(&queue_mutex, 0LL);
v6 = 1;
pthread_cond_init(&queue_cond, 0LL);
pthread_mutex_init(&completed_mutex, 0LL);
}
else
{
v5 = atoi(argv[2]);
v6 = v5;
if ( v5 <= 0 )
{
puts("num_threads must be greater than 1");
exit(0);
}
printf("Quicksort with %d threads (queue version), array_size = %d\n", (unsigned int)v5, v4);
pthread_mutex_init(&queue_mutex, 0LL);
pthread_cond_init(&queue_cond, 0LL);
pthread_mutex_init(&completed_mutex, 0LL);
if ( v6 == 1 )
{
v8 = 0LL;
}
else
{
v7 = 1LL;
v8 = (pthread_t *)malloc(8LL * (v6 - 1));
v9 = v8;
if ( !v8 )
{
puts("Lack of memory when creating threads");
LABEL_27:
if ( array )
{
free(array);
array = 0LL;
}
return 0;
}
do
pthread_create(v9++, 0LL, child_proc, (void *)v7++);
while ( v6 > (int)v7 );
}
}
v10 = N;
array = malloc(4LL * N);
v11 = array;
if ( !array )
{
puts("Lack of memory when allocating data buffer");
LABEL_25:
if ( v8 )
free(v8);
goto LABEL_27;
}
if ( v10 > 0 )
{
v12 = 1LL;
do
{
v11[v12 - 1] = v12;
++v12;
}
while ( v10 + 1 != v12 );
}
v13 = 0;
v14 = time(0LL);
srand(v14);
v15 = N;
if ( N > 0 )
{
do
{
v16 = rand();
v17 = (unsigned int)v13++;
swap(v17, (unsigned int)(int)((double)(N - 1) * ((double)v16 / 2147483647.0)));
v15 = N;
}
while ( N > v13 );
}
submit(0LL, (unsigned int)(v15 - 1));
worker(0LL);
if ( v6 != 1 )
{
v18 = v8;
v19 = (__int64)&v8[(unsigned int)(v6 - 2) + 1];
do
{
v20 = *v18++;
pthread_join(v20, 0LL);
}
while ( (pthread_t *)v19 != v18 );
}
if ( N - 1 <= 0 )
{
LABEL_24:
printf("\n...\nSorting result verified (cnt=%d)!\n", (unsigned int)N);
goto LABEL_25;
}
LODWORD(v21) = 0;
LODWORD(v22) = *(_DWORD *)array;
v23 = (unsigned int *)((char *)array + 4);
while ( 1 )
{
v24 = (unsigned int)v22;
v22 = *v23;
v25 = v21;
v21 = (unsigned int)(v21 + 1);
if ( (int)v22 < (int)v24 )
return printf("Verification failed, array[%d]=%d, array[%d]=%d\n", v25, v24, v21, v22);
++v23;
if ( (_DWORD)v21 == N - 1 )
goto LABEL_24;
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // er13
int v5; // eax
int v6; // er12
__int64 v7; // rbx
pthread_t *v8; // rbp
pthread_t *v9; // r13
int v10; // ebx
_DWORD *v11; // rdx
__int64 v12; // rax
int v13; // ebx
unsigned int v14; // eax
int v15; // esi
int v16; // eax
__int64 v17; // rdi
pthread_t *v18; // rbx
__int64 v19; // r12
pthread_t v20; // rdi
__int64 v21; // rcx
__int64 v22; // r8
unsigned int *v23; // rax
__int64 v24; // rdx
unsigned int v25; // er9

if ( (unsigned int)(argc - 2) > 1 )
{
puts("Usage: qsort_queue N [num_threads]");
exit(0);
}
v3 = atoi(argv[1]);
N = v3;
v4 = v3;
if ( v3 <= 1 )
{
puts("N must be greater than 2");
exit(0);
}
if ( argc == 2 )
{
printf("Quicksort with %d threads (queue version), array_size = %d\n", 1LL, (unsigned int)v3);
v8 = 0LL;
pthread_mutex_init(&queue_mutex, 0LL);
v6 = 1;
pthread_cond_init(&queue_cond, 0LL);
pthread_mutex_init(&completed_mutex, 0LL);
}
else
{
v5 = atoi(argv[2]);
v6 = v5;
if ( v5 <= 0 )
{
puts("num_threads must be greater than 1");
exit(0);
}
printf("Quicksort with %d threads (queue version), array_size = %d\n", (unsigned int)v5, v4);
pthread_mutex_init(&queue_mutex, 0LL);
pthread_cond_init(&queue_cond, 0LL);
pthread_mutex_init(&completed_mutex, 0LL);
if ( v6 == 1 )
{
v8 = 0LL;
}
else
{
v7 = 1LL;
v8 = (pthread_t *)malloc(8LL * (v6 - 1));
v9 = v8;
if ( !v8 )
{
puts("Lack of memory when creating threads");
LABEL_27:
if ( array )
{
free(array);
array = 0LL;
}
return 0;
}
do
pthread_create(v9++, 0LL, child_proc, (void *)v7++);
while ( v6 > (int)v7 );
}
}
v10 = N;
array = malloc(4LL * N);
v11 = array;
if ( !array )
{
puts("Lack of memory when allocating data buffer");
LABEL_25:
if ( v8 )
free(v8);
goto LABEL_27;
}
if ( v10 > 0 )
{
v12 = 1LL;
do
{
v11[v12 - 1] = v12;
++v12;
}
while ( v10 + 1 != v12 );
}
v13 = 0;
v14 = time(0LL);
srand(v14);
v15 = N;
if ( N > 0 )
{
do
{
v16 = rand();
v17 = (unsigned int)v13++;
func9(v17, (unsigned int)(int)((double)(N - 1) * ((double)v16 / 2147483647.0)));
v15 = N;
}
while ( N > v13 );
}
func12(0LL, (unsigned int)(v15 - 1));
func14(0LL);
if ( v6 != 1 )
{
v18 = v8;
v19 = (__int64)&v8[(unsigned int)(v6 - 2) + 1];
do
{
v20 = *v18++;
pthread_join(v20, 0LL);
}
while ( (pthread_t *)v19 != v18 );
}
if ( N - 1 <= 0 )
{
LABEL_24:
printf("\n...\nSorting result verified (cnt=%d)!\n", (unsigned int)N);
goto LABEL_25;
}
LODWORD(v21) = 0;
LODWORD(v22) = *(_DWORD *)array;
v23 = (unsigned int *)((char *)array + 4);
while ( 1 )
{
v24 = (unsigned int)v22;
v22 = *v23;
v25 = v21;
v21 = (unsigned int)(v21 + 1);
if ( (int)v22 < (int)v24 )
return printf("Verification failed, array[%d]=%d, array[%d]=%d\n", v25, v24, v21, v22);
++v23;
if ( (_DWORD)v21 == N - 1 )
goto LABEL_24;
}
}

original_code:
int main(int argc, char **argv)
{
  int i, j;
  int num_threads;
  char ans;
  pthread_t *thread_id = ((void *)0);
  if((argc != 2) && (argc != 3))
  {
    printf("Usage: qsort_queue N [num_threads]\n");
    exit(0);
  }
  N = atoi(argv[1]);
  if(N < 2)
  {
    printf("N must be greater than 2\n");
    exit(0);
  }
  if(argc == 2)
  {
    num_threads = 1;
  }
  else
  {
    num_threads = atoi(argv[2]);
    if(num_threads < 1)
    {
      printf("num_threads must be greater than 1\n");
      exit(0);
    }
  }
  printf("Quicksort with %d threads (queue version), array_size = %d\n", num_threads, N);
  pthread_mutex_init(&queue_mutex, ((void *)0));
  pthread_cond_init(&queue_cond, ((void *)0));
  pthread_mutex_init(&completed_mutex, ((void *)0));
  if(num_threads > 1) {
    thread_id = (pthread_t*)malloc((num_threads-1)*sizeof(pthread_t));
    if (thread_id == ((void *)0)) {
      printf("Lack of memory when creating threads\n");
      goto QUIT_POINT;
    }
    for(i=1;i<num_threads;i++)
    {
      pthread_create(&thread_id[i-1],((void *)0),child_proc,(void*)i);
      if(0) printf ("Child thread %d created\n",i);
    }
  }
  array = (int *) malloc(sizeof(int) * N);
  if (array == ((void *)0)) {
    printf("Lack of memory when allocating data buffer\n");
    goto QUIT_POINT;
  }
  for (i=0; i<N; i++)
    array[i] = i+1;
  srand(time(((void *)0)));
  for (i=0; i<N; i++) {
    j = (rand()*1./2147483647)*(N-1);
    swap(i, j);
  }
  ans = 'n';
  if (ans=='y') {
    for (i=0; i<N; i++)
      printf("%d, ", array[i]);
    printf("\n");
  }
  submit(0, N-1);
  worker (0);
  if(num_threads > 1) {
    for(i=1;i<num_threads;i++)
    {
      pthread_join(thread_id[i-1],((void *)0));
    }
  }
  for (i=0; i<N-1; i++) {
    if (array[i]>array[i+1]) {
      printf("Verification failed, array[%d]=%d, array[%d]=%d\n",
      i, array[i], i+1, array[i+1]);
      return;
    }
  }
  printf("\n...\nSorting result verified (cnt=%d)!\n", N);
QUIT_POINT:
  if (thread_id != ((void *)0)) {
    free(thread_id);
    thread_id = ((void *)0);
  }
  if (array != ((void *)0)) {
    free(array);
    array = ((void *)0);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int i; int j;
  int num_threads;
  char ans;
  unsigned long *thread_id = ((void *)0);
  if((argc != 2) && (argc != 3))
  {
    printf("Usage: qsort_queue N [num_threads]\n");
    exit(0);
  }
  N = atoi(argv[1]);
  if(N < 2)
  {
    printf("N must be greater than 2\n");
    exit(0);
  }
  if(argc == 2)
  {
    num_threads = 1;
  }
  else
  {
    num_threads = atoi(argv[2]);
    if(num_threads < 1)
    {
      printf("num_threads must be greater than 1\n");
      exit(0);
    }
  }
  printf("Quicksort with %d threads (queue version), array_size = %d\n", num_threads, N);
  pthread_mutex_init(&queue_mutex, ((void *)0));
  pthread_cond_init(&queue_cond, ((void *)0));
  pthread_mutex_init(&completed_mutex, ((void *)0));
  if(num_threads > 1) {
    thread_id = (unsigned long *)malloc((num_threads-1)*sizeof(pthread_t));
    if (thread_id == ((void *)0)) {
      printf("Lack of memory when creating threads\n");
      goto QUIT_POINT;
    }
    for(i=1;i<num_threads;i++)
    {
      pthread_create(&thread_id[i-1],((void *)0),child_proc,(void *)i);
      if(0) printf ("Child thread %d created\n",i);
    }
  }
  array = (int *) malloc(sizeof(int) * N);
  if (array == ((void *)0)) {
    printf("Lack of memory when allocating data buffer\n");
    goto QUIT_POINT;
  }
  for (i=0; i<N; i++)
    array[i] = i+1;
  srand(time(((void *)0)));
  for (i=0; i<N; i++) {
    j = (rand()*1./2147483647)*(N-1);
    swap(i, j);
  }
  ans = 'n';
  if (ans=='y') {
    for (i=0; i<N; i++)
      printf("%d, ", array[i]);
    printf("\n");
  }
  submit(0, N-1);
  worker (0);
  if(num_threads > 1) {
    for(i=1;i<num_threads;i++)
    {
      pthread_join(thread_id[i-1],((void *)0));
    }
  }
  for (i=0; i<N-1; i++) {
    if (array[i]>array[i+1]) {
      printf("Verification failed, array[%d]=%d, array[%d]=%d\n",
      i, array[i], i+1, array[i+1]);
      return;
    }
  }
  printf("\n...\nSorting result verified (cnt=%d)!\n", N);
QUIT_POINT:
  if (thread_id != ((void *)0)) {
    free(thread_id);
    thread_id = ((void *)0);
  }
  if (array != ((void *)0)) {
    free(array);
    array = ((void *)0);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: ans char


decompiled_code:
__int64 __fastcall process_response(int a1, int a2)
{
unsigned __int16 v2; // dx
__int64 v3; // rdx
unsigned int v4; // er8

v2 = __ROL2__(msgbuf, 8);
if ( msgbuf != 768 )
{
if ( v2 == 5 )
{
fprintf(stderr, "error: %s\n", byte_4040C4);
exit(1);
}
fprintf(stderr, "unknown opcode 0x%04x received, giving up\n", v2);
exit(1);
}
v3 = (unsigned __int16)__ROL2__(*(_WORD *)dest, 8);
if ( (unsigned __int16)v3 == a2 )
{
v4 = fwrite(byte_4040C4, 1uLL, a1 - 4, _bss_start);
if ( a1 - 4 != v4 )
__assert_fail("r == msglen - 4", "tftpread.c", 0x2Eu, "process_response");
}
else
{
fprintf(stderr, "received unexpected block %d\n", v3);
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
unsigned __int16 v2; // dx
__int64 v3; // rdx
unsigned int v4; // er8

v2 = __ROL2__(msgbuf, 8);
if ( msgbuf != 768 )
{
if ( v2 == 5 )
{
fprintf(stderr, "error: %s\n", byte_4040C4);
exit(1);
}
fprintf(stderr, "unknown opcode 0x%04x received, giving up\n", v2);
exit(1);
}
v3 = (unsigned __int16)__ROL2__(*(_WORD *)dest, 8);
if ( (unsigned __int16)v3 == a2 )
{
v4 = fwrite(byte_4040C4, 1uLL, a1 - 4, _bss_start);
if ( a1 - 4 != v4 )
__assert_fail("r == msglen - 4", "tftpread.c", 0x2Eu, "process_response");
}
else
{
fprintf(stderr, "received unexpected block %d\n", v3);
v4 = -1;
}
return v4;
}

original_code:
static int process_response(int msglen, int blocknum) {
    unsigned short opcode = (msgbuf[0] << 8) | msgbuf[1];
    switch (opcode) {
    case 5 :
        fprintf(stderr, "error: %s\n", msgbuf + 4);
        exit(1);
    case 3 : {
        int actualblock = (msgbuf[2] << 8) | msgbuf[3];
        if (actualblock != blocknum) {
            fprintf(stderr, "received unexpected block %d\n", actualblock);
            return -1;
        }
        int r = fwrite(msgbuf + 4, 1, msglen - 4, stdout);
        ((void) sizeof ((r == msglen - 4) ? 1 : 0), __extension__ ({ if (r == msglen - 4) ; else __assert_fail ("r == msglen - 4", "tftpread.c", 46, __extension__ __PRETTY_FUNCTION__); }));
        return msglen - 4; }
    }
    fprintf(stderr, "unknown opcode 0x%04x received, giving up\n", opcode);
    exit(1);
}

variable_types: msglen int

variable_types: blocknum int

variable_types:
opcode
unsigned short

variable_types: actualblock int

variable_types: r int


decompiled_code:
__int64 __fastcall format_rrq(char *s)
{
size_t v1; // rax

msgbuf = 256;
strcpy(dest, s);
v1 = strlen(s);
*(_DWORD *)(v1 + 4210883) = 1702126447;
*(__int16 *)((char *)&word_4040C7 + v1) = 116;
return (unsigned int)strlen(s) + 9;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *s)
{
size_t v1; // rax

msgbuf = 256;
strcpy(dest, s);
v1 = strlen(s);
*(_DWORD *)(v1 + 4210883) = 1702126447;
*(__int16 *)((char *)&word_4040C7 + v1) = 116;
return (unsigned int)strlen(s) + 9;
}

original_code:
static int format_rrq(char *filename) {
    char *modestr = "octet";
    msgbuf[0] = 0;
    msgbuf[1] = 1;
    strcpy((char *)msgbuf + 2, filename);
    strcpy((char *)msgbuf + 2 + strlen(filename) + 1, modestr);
    return 2 + strlen(filename) + 1 + strlen(modestr) + 1;
}

variable_types:
filename
char *

variable_types:
modestr
char *


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

result = 1024LL;
msgbuf = 1024;
*(_WORD *)dest = __ROL2__(a1, 8);
return result;
}

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

result = 1024LL;
msgbuf = 1024;
*(_WORD *)dest = __ROL2__(a1, 8);
return result;
}

original_code:
void format_ack(int blocknum) {
    msgbuf[0] = 0;
    msgbuf[1] = 4;
    msgbuf[2] = (blocknum >> 8) & 0xff;
    msgbuf[3] = blocknum & 0xff;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct hostent *v3; // rax
struct hostent *v4; // rbx
int v5; // er12
__int16 v6; // ax
char *v7; // rdi
size_t v8; // r13
int v9; // er14
unsigned int i; // ebp
int v11; // ebx
__int64 v12; // r8
size_t v13; // rdx
int v14; // ecx
socklen_t v15; // er9
socklen_t addr_len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr v19; // [rsp+20h] [rbp-38h] BYREF

if ( argc != 3 )
__assert_fail("argc == 3", "tftpread.c", 0x3Du, "main");
v3 = gethostbyname(argv[1]);
v4 = v3;
if ( !v3 )
{
herror("bad destination");
exit(1);
}
if ( v3->h_addrtype != 2 )
__assert_fail("h->h_addrtype == AF_INET", "tftpread.c", 0x45u, "main");
v5 = socket(2, 2, 0);
if ( v5 == -1 )
__assert_fail("s != -1", "tftpread.c", 0x48u, "main");
addr.sa_family = 2;
v6 = _bswap_16_constprop_0();
v7 = (char *)argv[2];
*(_WORD *)addr.sa_data = v6;
*(_DWORD *)&addr.sa_data[2] = **(_DWORD **)v4->h_addr_list;
v8 = (int)format_rrq(v7);
if ( (_DWORD)v8 != (unsigned int)sendto(v5, &msgbuf, v8, 0, &addr, 0x10u) )
__assert_fail("r == size", "tftpread.c", 0x53u, "main");
addr_len = 16;
v9 = recvfrom(v5, &msgbuf, 0x204uLL, 0, &v19, &addr_len);
if ( v9 < 0 )
__assert_fail("r >= 0", "tftpread.c", 0x59u, "main");
for ( i = 1; ; ++i )
{
do
v11 = process_response((unsigned int)v9, i);
while ( v11 == -1 );
format_ack(i, i, v8, 0LL, v12, 16LL);
sendto(v5, &msgbuf, v13, v14, &v19, v15);
if ( v11 <= 511 )
break;
addr_len = 16;
v9 = recvfrom(v5, &msgbuf, 0x204uLL, 0, &v19, &addr_len);
if ( v9 < 0 )
__assert_fail("r >= 0", "tftpread.c", 0x6Cu, "main");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct hostent *v3; // rax
struct hostent *v4; // rbx
int v5; // er12
__int16 v6; // ax
char *v7; // rdi
size_t v8; // r13
int v9; // er14
unsigned int i; // ebp
int v11; // ebx
__int64 v12; // r8
size_t v13; // rdx
int v14; // ecx
socklen_t v15; // er9
socklen_t addr_len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr v19; // [rsp+20h] [rbp-38h] BYREF

if ( argc != 3 )
__assert_fail("argc == 3", "tftpread.c", 0x3Du, "main");
v3 = gethostbyname(argv[1]);
v4 = v3;
if ( !v3 )
{
herror("bad destination");
exit(1);
}
if ( v3->h_addrtype != 2 )
__assert_fail("h->h_addrtype == AF_INET", "tftpread.c", 0x45u, "main");
v5 = socket(2, 2, 0);
if ( v5 == -1 )
__assert_fail("s != -1", "tftpread.c", 0x48u, "main");
addr.sa_family = 2;
v6 = func9();
v7 = (char *)argv[2];
*(_WORD *)addr.sa_data = v6;
*(_DWORD *)&addr.sa_data[2] = **(_DWORD **)v4->h_addr_list;
v8 = (int)func8(v7);
if ( (_DWORD)v8 != (unsigned int)sendto(v5, &msgbuf, v8, 0, &addr, 0x10u) )
__assert_fail("r == size", "tftpread.c", 0x53u, "main");
addr_len = 16;
v9 = recvfrom(v5, &msgbuf, 0x204uLL, 0, &v19, &addr_len);
if ( v9 < 0 )
__assert_fail("r >= 0", "tftpread.c", 0x59u, "main");
for ( i = 1; ; ++i )
{
do
v11 = func7((unsigned int)v9, i);
while ( v11 == -1 );
func10(i, i, v8, 0LL, v12, 16LL);
sendto(v5, &msgbuf, v13, v14, &v19, v15);
if ( v11 <= 511 )
break;
addr_len = 16;
v9 = recvfrom(v5, &msgbuf, 0x204uLL, 0, &v19, &addr_len);
if ( v9 < 0 )
__assert_fail("r >= 0", "tftpread.c", 0x6Cu, "main");
}
return 0;
}

original_code:
int main(int argc, char **argv) {
    ((void) sizeof ((argc == 3) ? 1 : 0), __extension__ ({ if (argc == 3) ; else __assert_fail ("argc == 3", "tftpread.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    struct hostent *h = gethostbyname(argv[1]);
    if (!h) {
        herror("bad destination");
        exit(1);
    }
    ((void) sizeof ((h->h_addrtype == 2) ? 1 : 0), __extension__ ({ if (h->h_addrtype == 2) ; else __assert_fail ("h->h_addrtype == AF_INET", "tftpread.c", 69, __extension__ __PRETTY_FUNCTION__); }));
    int s = socket(2, SOCK_DGRAM, 0);
    ((void) sizeof ((s != -1) ? 1 : 0), __extension__ ({ if (s != -1) ; else __assert_fail ("s != -1", "tftpread.c", 72, __extension__ __PRETTY_FUNCTION__); }));
    struct sockaddr_in sin;
    sin.sin_family = 2;
    sin.sin_port = htons(69);
    sin.sin_addr.s_addr = *(uint32_t *)h->h_addr_list[0];
    int size = format_rrq(argv[2]);
    int r = sendto(s, msgbuf, size, 0,
                   (const struct sockaddr *)&sin, (socklen_t)sizeof(sin));
    ((void) sizeof ((r == size) ? 1 : 0), __extension__ ({ if (r == size) ; else __assert_fail ("r == size", "tftpread.c", 83, __extension__ __PRETTY_FUNCTION__); }));
    struct sockaddr_in ssin;
    socklen_t ssaddrlen = sizeof(ssin);
    r = recvfrom(s, (void *)msgbuf, sizeof(msgbuf), 0,
                 (struct sockaddr *)&ssin, &ssaddrlen);
    ((void) sizeof ((r >= 0) ? 1 : 0), __extension__ ({ if (r >= 0) ; else __assert_fail ("r >= 0", "tftpread.c", 89, __extension__ __PRETTY_FUNCTION__); }));
    int blocknum = 1;
    while (1) {
        int transferred = process_response(r, blocknum);
        if (transferred == -1)
            continue;
        format_ack(blocknum);
        r = sendto(s, msgbuf, size, 0,
                   (const struct sockaddr *)&ssin, (socklen_t)sizeof(ssin));
        if (transferred < 512) {
            break;
        }
        ssaddrlen = sizeof(ssin);
        r = recvfrom(s, (void *)msgbuf, sizeof(msgbuf), 0,
                     (struct sockaddr *)&ssin, &ssaddrlen);
        ((void) sizeof ((r >= 0) ? 1 : 0), __extension__ ({ if (r >= 0) ; else __assert_fail ("r >= 0", "tftpread.c", 108, __extension__ __PRETTY_FUNCTION__); }));
        blocknum++;
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    ((void) sizeof ((argc == 3) ? 1 : 0), __extension__ ({ if (argc == 3) ; else __assert_fail ("argc == 3", "tftpread.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    struct hostent *h = gethostbyname(argv[1]);
    if (!h) {
        herror("bad destination");
        exit(1);
    }
    ((void) sizeof ((h->h_addrtype == 2) ? 1 : 0), __extension__ ({ if (h->h_addrtype == 2) ; else __assert_fail ("h->h_addrtype == AF_INET", "tftpread.c", 69, __extension__ __PRETTY_FUNCTION__); }));
    int s = socket(2, SOCK_DGRAM, 0);
    ((void) sizeof ((s != -1) ? 1 : 0), __extension__ ({ if (s != -1) ; else __assert_fail ("s != -1", "tftpread.c", 72, __extension__ __PRETTY_FUNCTION__); }));
    struct sockaddr_in sin;
    sin.sin_family = 2;
    sin.sin_port = htons(69);
    sin.sin_addr.s_addr = *(unsigned int *)h->h_addr_list[0];
    int size = format_rrq(argv[2]);
    int r = sendto(s, msgbuf, size, 0,
                   (const struct sockaddr *)&sin, (socklen_t)sizeof(sin));
    ((void) sizeof ((r == size) ? 1 : 0), __extension__ ({ if (r == size) ; else __assert_fail ("r == size", "tftpread.c", 83, __extension__ __PRETTY_FUNCTION__); }));
    struct sockaddr_in ssin;
    unsigned int ssaddrlen = sizeof(ssin);
    r = recvfrom(s, (void *)msgbuf, sizeof(msgbuf), 0,
                 (struct sockaddr *)&ssin, &ssaddrlen);
    ((void) sizeof ((r >= 0) ? 1 : 0), __extension__ ({ if (r >= 0) ; else __assert_fail ("r >= 0", "tftpread.c", 89, __extension__ __PRETTY_FUNCTION__); }));
    int blocknum = 1;
    while (1) {
        int transferred = process_response(r, blocknum);
        if (transferred == -1)
            continue;
        format_ack(blocknum);
        r = sendto(s, msgbuf, size, 0,
                   (struct sockaddr *)&ssin, (unsigned int)sizeof(ssin));
        if (transferred < 512) {
            break;
        }
        ssaddrlen = sizeof(ssin);
        r = recvfrom(s, (void *)msgbuf, sizeof(msgbuf), 0,
                     (struct sockaddr *)&ssin, &ssaddrlen);
        ((void) sizeof ((r >= 0) ? 1 : 0), __extension__ ({ if (r >= 0) ; else __assert_fail ("r >= 0", "tftpread.c", 108, __extension__ __PRETTY_FUNCTION__); }));
        blocknum++;
    }
    return 0;
}

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types: s int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: size int

variable_types:
ssaddrlen
unsigned int

variable_types: transferred int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


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

result = getchar();
if ( result == -1 )
exit(0);
return result;
}

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

result = getchar();
if ( result == -1 )
exit(0);
return result;
}

original_code:
int get8(void) {
  int b1 = getchar();
  if(b1 == (-1)) exit(0);
  return b1;
}

canonical_original_code:
int get8() {
  int b1 = getchar();
  if(b1 == (-1)) exit(0);
  return b1;
}


decompiled_code:
__int64 get16()
{
int v0; // eax
__int16 v1; // bx
int v2; // eax

v0 = getchar();
if ( v0 == -1 || (v1 = v0, v2 = getchar(), v2 == -1) )
exit(0);
return (unsigned __int8)v2 | (unsigned int)(unsigned __int16)(v1 << 8);
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // eax
__int16 v1; // bx
int v2; // eax

v0 = getchar();
if ( v0 == -1 || (v1 = v0, v2 = getchar(), v2 == -1) )
exit(0);
return (unsigned __int8)v2 | (unsigned int)(unsigned __int16)(v1 << 8);
}


dump

decompiled_code:
void __fastcall dump(int a1, int a2)
{
int v2; // ebx
int j; // ebx
int v4; // eax
int i; // ebx
unsigned int v6; // eax
unsigned int v7; // eax

v2 = a2;
if ( a2 )
{
if ( a2 == 1 )
{
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
while ( (i & 0xF) == 0 )
{
v7 = get8();
++i;
printf("%02x", v7);
if ( a1 == i )
goto LABEL_18;
}
v6 = get8();
if ( (i & 0xF) == 15 )
printf(", %02x\n", v6);
else
printf(", %02x", v6);
}
LABEL_18:
if ( (a1 & 0xF) != 0 )
putchar(10);
}
}
else if ( a2 == 2 && a1 > 0 )
{
for ( j = 0; j != a1; ++j )
{
v4 = get8();
putchar(v4);
}
}
}
else if ( a1 > 0 )
{
do
{
get8();
++v2;
}
while ( a1 != v2 );
}
}

canonical_decompiled_code:
void __fastcall func10(int a1, int a2)
{
int v2; // ebx
int j; // ebx
int v4; // eax
int i; // ebx
unsigned int v6; // eax
unsigned int v7; // eax

v2 = a2;
if ( a2 )
{
if ( a2 == 1 )
{
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
while ( (i & 0xF) == 0 )
{
v7 = func7();
++i;
printf("%02x", v7);
if ( a1 == i )
goto LABEL_18;
}
v6 = func7();
if ( (i & 0xF) == 15 )
printf(", %02x\n", v6);
else
printf(", %02x", v6);
}
LABEL_18:
if ( (a1 & 0xF) != 0 )
putchar(10);
}
}
else if ( a2 == 2 && a1 > 0 )
{
for ( j = 0; j != a1; ++j )
{
v4 = func7();
putchar(v4);
}
}
}
else if ( a1 > 0 )
{
do
{
func7();
++v2;
}
while ( a1 != v2 );
}
}

original_code:
void dump(int size, int screen) {
  int i;
  if(screen == 0) {
    for(i=0; i<size; i++) {
      get8();
    }
  } else if(screen == 1) {
    for(i=0; i<size; i++) {
      if(i%16 == 0) {
 printf("%02x", get8());
      } else if(i%16 == 15) {
 printf(", %02x\n", get8());
      } else {
 printf(", %02x", get8());
      }
    }
    if(i%16 != 0) {
      printf("\n");
    }
  } else if(screen == 2) {
    for(i=0; i<size; i++) {
      printf("%c", get8());
    }
  }
}

variable_types: screen int

variable_types: i int


decompiled_code:
__int64 __fastcall get_ether(_BYTE *a1)
{
_BYTE *v1; // rbx
__int64 result; // rax

v1 = a1;
do
*v1++ = get8();
while ( v1 != a1 + 6 );
do
*v1++ = get8();
while ( v1 != a1 + 12 );
result = get16();
*((_WORD *)a1 + 6) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_BYTE *a1)
{
_BYTE *v1; // rbx
__int64 result; // rax

v1 = a1;
do
*v1++ = func7();
while ( v1 != a1 + 6 );
do
*v1++ = func7();
while ( v1 != a1 + 12 );
result = func8();
*((_WORD *)a1 + 6) = result;
return result;
}

original_code:
void get_ether(struct EthernetHeader* ehead) {
  int i;
  for(i=0; i<6; i++) {
    ehead->dest[i] = get8();
  }
  for(i=0; i<6; i++) {
    ehead->src[i] = get8();
  }
  ehead->length_type = get16();
}

canonical_original_code:
void get_ether(struct EthernetHeader *ehead) {
  int i;
  for(i=0; i<6; i++) {
    ehead->dest[i] = get8();
  }
  for(i=0; i<6; i++) {
    ehead->src[i] = get8();
  }
  ehead->length_type = get16();
}

variable_types: struct EthernetHeader { unsigned char dest[6]; unsigned char src[6]; unsigned short length_type; } *


decompiled_code:
int __fastcall print_ether(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
__int64 v2; // rsi
unsigned __int8 *v3; // rbx
__int64 v4; // rsi

v1 = a1 + 7;
puts("<<<Ethernet");
printf(" %02x", a1[6]);
do
{
v2 = *v1++;
printf(":%02x", v2);
}
while ( v1 != a1 + 12 );
v3 = a1 + 1;
printf(" -> ");
printf("%02x", *a1);
do
{
v4 = *v3++;
printf(":%02x", v4);
}
while ( a1 + 6 != v3 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func12(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
__int64 v2; // rsi
unsigned __int8 *v3; // rbx
__int64 v4; // rsi

v1 = a1 + 7;
puts("<<<Ethernet");
printf(" %02x", a1[6]);
do
{
v2 = *v1++;
printf(":%02x", v2);
}
while ( v1 != a1 + 12 );
v3 = a1 + 1;
printf(" -> ");
printf("%02x", *a1);
do
{
v4 = *v3++;
printf(":%02x", v4);
}
while ( a1 + 6 != v3 );
return putchar(10);
}

original_code:
void print_ether(struct EthernetHeader* ehead) {
    int i;
    printf("<<<Ethernet\n");
    printf("    %02x", ehead->src[0]);
    for (i = 1; i < 6; i++)
        printf(":%02x", ehead->src[i]);
    printf(" -> ");
    printf("%02x", ehead->dest[0]);
    for (i = 1; i < 6; i++)
        printf(":%02x", ehead->dest[i]);
    printf("\n");
}

canonical_original_code:
void print_ether(struct EthernetHeader *ehead) {
    int i;
    printf("<<<Ethernet\n");
    printf("    %02x", ehead->src[0]);
    for (i = 1; i < 6; i++)
        printf(":%02x", ehead->src[i]);
    printf(" -> ");
    printf("%02x", ehead->dest[0]);
    for (i = 1; i < 6; i++)
        printf(":%02x", ehead->dest[i]);
    printf("\n");
}

user_defined_types: struct EthernetHeader { unsigned char dest[6]; unsigned char src[6]; unsigned short length_type; }


original_code:
void get_ipv4(struct IPv4Header* ip4head) {
  int i;
  ip4head->byte0 = get8();
  ip4head->byte1 = get8();
  ip4head->datalen = get16();
  ip4head->id = get16();
  ip4head->word0 = get16();
  ip4head->TTL = get8();
  ip4head->protocol= get8();
  ip4head->headchecksum = get16();
  for(i=0; i<4; i++) {
    ip4head->src[i] = get8();
  }
  for(i=0; i<4; i++) {
    ip4head->dest[i] = get8();
  }
}

canonical_original_code:
void get_ipv4(struct IPv4Header *ip4head) {
  int i;
  ip4head->byte0 = get8();
  ip4head->byte1 = get8();
  ip4head->datalen = get16();
  ip4head->id = get16();
  ip4head->word0 = get16();
  ip4head->TTL = get8();
  ip4head->protocol= get8();
  ip4head->headchecksum = get16();
  for(i=0; i<4; i++) {
    ip4head->src[i] = get8();
  }
  for(i=0; i<4; i++) {
    ip4head->dest[i] = get8();
  }
}

variable_types: struct IPv4Header { unsigned char byte0; unsigned char byte1; unsigned short datalen; unsigned short id; unsigned short word0; unsigned char TTL; unsigned char protocol; unsigned short headchecksum; unsigned char src[4]; unsigned char dest[4]; } *


decompiled_code:
int __fastcall print_ipv4(__int64 a1)
{
puts("<<<IP");
printf(" %d", *(unsigned __int8 *)(a1 + 12));
printf(".%d", *(unsigned __int8 *)(a1 + 13));
printf(".%d", *(unsigned __int8 *)(a1 + 14));
printf(".%d", *(unsigned __int8 *)(a1 + 15));
printf(" -> ");
printf("%d", *(unsigned __int8 *)(a1 + 16));
printf(".%d", *(unsigned __int8 *)(a1 + 17));
printf(".%d", *(unsigned __int8 *)(a1 + 18));
printf(".%d", *(unsigned __int8 *)(a1 + 19));
putchar(10);
printf(" id: %d\n", *(unsigned __int16 *)(a1 + 4));
printf(" length: %d\n", *(unsigned __int16 *)(a1 + 2));
return printf(" TTL: %d\n", *(unsigned __int8 *)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1)
{
puts("<<<IP");
printf(" %d", *(unsigned __int8 *)(a1 + 12));
printf(".%d", *(unsigned __int8 *)(a1 + 13));
printf(".%d", *(unsigned __int8 *)(a1 + 14));
printf(".%d", *(unsigned __int8 *)(a1 + 15));
printf(" -> ");
printf("%d", *(unsigned __int8 *)(a1 + 16));
printf(".%d", *(unsigned __int8 *)(a1 + 17));
printf(".%d", *(unsigned __int8 *)(a1 + 18));
printf(".%d", *(unsigned __int8 *)(a1 + 19));
putchar(10);
printf(" id: %d\n", *(unsigned __int16 *)(a1 + 4));
printf(" length: %d\n", *(unsigned __int16 *)(a1 + 2));
return printf(" TTL: %d\n", *(unsigned __int8 *)(a1 + 8));
}

original_code:
void print_ipv4(struct IPv4Header* ip4head) {
  int i;
  printf("<<<IP\n");
  printf("    %d", ip4head->src[0]);
  for(i=1; i<4; i++) {
    printf(".%d", ip4head->src[i]);
  }
  printf(" -> ");
  printf("%d", ip4head->dest[0]);
  for(i=1; i<4; i++) {
    printf(".%d", ip4head->dest[i]);
  }
  printf("\n");
  printf("    id: %d\n", ip4head->id);
  printf("    length: %d\n", ip4head->datalen);
  printf("    TTL: %d\n", ip4head->TTL);
}

canonical_original_code:
void print_ipv4(struct IPv4Header *ip4head) {
  int i;
  printf("<<<IP\n");
  printf("    %d", ip4head->src[0]);
  for(i=1; i<4; i++) {
    printf(".%d", ip4head->src[i]);
  }
  printf(" -> ");
  printf("%d", ip4head->dest[0]);
  for(i=1; i<4; i++) {
    printf(".%d", ip4head->dest[i]);
  }
  printf("\n");
  printf("    id: %d\n", ip4head->id);
  printf("    length: %d\n", ip4head->datalen);
  printf("    TTL: %d\n", ip4head->TTL);
}

user_defined_types: struct IPv4Header { unsigned char byte0; unsigned char byte1; unsigned short datalen; unsigned short id; unsigned short word0; unsigned char TTL; unsigned char protocol; unsigned short headchecksum; unsigned char src[4]; unsigned char dest[4]; }


decompiled_code:
int __fastcall print_udp(unsigned __int16 *a1)
{
puts("<<<UDP");
printf(" %d -> %d\n", *a1, a1[1]);
return printf(" size: %d\n", a1[2]);
}

canonical_decompiled_code:
int __fastcall func16(unsigned __int16 *a1)
{
puts("<<<UDP");
printf(" %d -> %d\n", *a1, a1[1]);
return printf(" size: %d\n", a1[2]);
}

original_code:
void print_udp(struct UDPHeader* udphead) {
  printf("<<<UDP\n");
  printf("    %d -> %d\n", udphead->src, udphead->dest);
  printf("    size: %d\n", udphead->size);
}

canonical_original_code:
void print_udp(struct UDPHeader *udphead) {
  printf("<<<UDP\n");
  printf("    %d -> %d\n", udphead->src, udphead->dest);
  printf("    size: %d\n", udphead->size);
}

variable_types: struct UDPHeader { unsigned short src; unsigned short dest; unsigned short size; unsigned short checksum; } *