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

switch ( a1 )
{
case '0':
result = 0LL;
break;
case '1':
result = 1LL;
break;
case '2':
result = 2LL;
break;
case '3':
result = 3LL;
break;
case '4':
result = 4LL;
break;
case '5':
result = 5LL;
break;
case '6':
result = 6LL;
break;
case '7':
result = 7LL;
break;
case '8':
result = 8LL;
break;
case '9':
result = 9LL;
break;
case 'A':
case 'a':
result = 10LL;
break;
case 'B':
case 'b':
result = 11LL;
break;
case 'C':
case 'c':
result = 12LL;
break;
case 'D':
case 'd':
result = 13LL;
break;
case 'E':
case 'e':
result = 14LL;
break;
case 'F':
case 'f':
result = 15LL;
break;
default:
fwrite("you inputted a non-digit character in one of your number string \n", 1uLL, 0x41uLL, stderr);
result = 0LL;
break;
}
return result;
}

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

switch ( a1 )
{
case '0':
result = 0LL;
break;
case '1':
result = 1LL;
break;
case '2':
result = 2LL;
break;
case '3':
result = 3LL;
break;
case '4':
result = 4LL;
break;
case '5':
result = 5LL;
break;
case '6':
result = 6LL;
break;
case '7':
result = 7LL;
break;
case '8':
result = 8LL;
break;
case '9':
result = 9LL;
break;
case 'A':
case 'a':
result = 10LL;
break;
case 'B':
case 'b':
result = 11LL;
break;
case 'C':
case 'c':
result = 12LL;
break;
case 'D':
case 'd':
result = 13LL;
break;
case 'E':
case 'e':
result = 14LL;
break;
case 'F':
case 'f':
result = 15LL;
break;
default:
fwrite("you inputted a non-digit character in one of your number string \n", 1uLL, 0x41uLL, stderr);
result = 0LL;
break;
}
return result;
}

original_code:
int single_digit_hex_to_dec(char hex_dig) {
 switch (hex_dig) {
  case '0':
   return 0;
   break;
  case '1':
   return 1;
   break;
  case '2':
   return 2;
   break;
  case '3':
   return 3;
   break;
  case '4':
   return 4;
   break;
  case '5':
   return 5;
   break;
  case '6':
   return 6;
   break;
  case '7':
   return 7;
   break;
  case '8':
   return 8;
   break;
  case '9':
   return 9;
   break;
  case 'A':
  case 'a':
   return 10;
   break;
  case 'B':
  case 'b':
   return 11;
   break;
  case 'C':
  case 'c':
   return 12;
   break;
  case 'D':
  case 'd':
   return 13;
   break;
  case 'E':
  case 'e':
   return 14;
   break;
  case 'F':
  case 'f':
   return 15;
   break;
  default:
   fprintf(stderr, "you inputted a non-digit character in one of your number string \n");
   return 0;
   break;
 }
}


decompiled_code:
const char *__fastcall single_digit_hex_to_bin(char a1)
{
const char *result; // rax

switch ( a1 )
{
case '0':
result = "0000";
break;
case '1':
result = "0001";
break;
case '2':
result = "0010";
break;
case '3':
result = "0011";
break;
case '4':
result = "0100";
break;
case '5':
result = "0101";
break;
case '6':
result = "0110";
break;
case '7':
result = "0111";
break;
case '8':
result = "1000";
break;
case '9':
result = "1001";
break;
case 'A':
case 'a':
result = "1010";
break;
case 'B':
case 'b':
result = "1011";
break;
case 'C':
case 'c':
result = "1100";
break;
case 'D':
case 'd':
result = "1101";
break;
case 'E':
case 'e':
result = "1110";
break;
case 'F':
case 'f':
result = "1111";
break;
default:
fwrite("you inputted a non-digit character in one of your number string \n", 1uLL, 0x41uLL, stderr);
result = (const char *)&unk_710;
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(char a1)
{
const char *result; // rax

switch ( a1 )
{
case '0':
result = "0000";
break;
case '1':
result = "0001";
break;
case '2':
result = "0010";
break;
case '3':
result = "0011";
break;
case '4':
result = "0100";
break;
case '5':
result = "0101";
break;
case '6':
result = "0110";
break;
case '7':
result = "0111";
break;
case '8':
result = "1000";
break;
case '9':
result = "1001";
break;
case 'A':
case 'a':
result = "1010";
break;
case 'B':
case 'b':
result = "1011";
break;
case 'C':
case 'c':
result = "1100";
break;
case 'D':
case 'd':
result = "1101";
break;
case 'E':
case 'e':
result = "1110";
break;
case 'F':
case 'f':
result = "1111";
break;
default:
fwrite("you inputted a non-digit character in one of your number string \n", 1uLL, 0x41uLL, stderr);
result = (const char *)&unk_710;
break;
}
return result;
}

original_code:
char * single_digit_hex_to_bin (char hex_dig) {
 switch (hex_dig) {
  case '0':
   return "0000";
   break;
  case '1':
   return "0001";
   break;
  case '2':
   return "0010";
   break;
  case '3':
   return "0011";
   break;
  case '4':
   return "0100";
   break;
  case '5':
   return "0101";
   break;
  case '6':
   return "0110";
   break;
  case '7':
   return "0111";
   break;
  case '8':
   return "1000";
   break;
  case '9':
   return "1001";
   break;
  case 'A':
  case 'a':
   return "1010";
   break;
  case 'B':
  case 'b':
   return "1011";
   break;
  case 'C':
  case 'c':
   return "1100";
   break;
  case 'D':
  case 'd':
   return "1101";
   break;
  case 'E':
  case 'e':
   return "1110";
   break;
  case 'F':
  case 'f':
   return "1111";
   break;
  default:
   fprintf(stderr, "you inputted a non-digit character in one of your number string \n");
   return "";
   break;
 }
}

canonical_original_code:
char *single_digit_hex_to_bin(char hex_dig) {
 switch (hex_dig) {
  case '0':
   return "0000";
   break;
  case '1':
   return "0001";
   break;
  case '2':
   return "0010";
   break;
  case '3':
   return "0011";
   break;
  case '4':
   return "0100";
   break;
  case '5':
   return "0101";
   break;
  case '6':
   return "0110";
   break;
  case '7':
   return "0111";
   break;
  case '8':
   return "1000";
   break;
  case '9':
   return "1001";
   break;
  case 'A':
  case 'a':
   return "1010";
   break;
  case 'B':
  case 'b':
   return "1011";
   break;
  case 'C':
  case 'c':
   return "1100";
   break;
  case 'D':
  case 'd':
   return "1101";
   break;
  case 'E':
  case 'e':
   return "1110";
   break;
  case 'F':
  case 'f':
   return "1111";
   break;
  default:
   fprintf(stderr, "you inputted a non-digit character in one of your number string \n");
   return "";
   break;
 }
}

return_type: char *


decompiled_code:
char *__fastcall hex_to_bin(char *s)
{
size_t v2; // rbx
char *v3; // rax
char *v4; // rbp
size_t i; // rbx
char v6; // di
const char *v7; // rax

v2 = strlen(s);
v3 = (char *)malloc(4 * v2 + 1);
v3[4 * v2] = 0;
v4 = v3;
for ( i = 0LL; strlen(s) > i; ++i )
{
v6 = s[i];
v7 = single_digit_hex_to_bin(v6);
strcat(v4, v7);
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func2(char *s)
{
size_t v2; // rbx
char *v3; // rax
char *v4; // rbp
size_t i; // rbx
char v6; // di
const char *v7; // rax

v2 = strlen(s);
v3 = (char *)malloc(4 * v2 + 1);
v3[4 * v2] = 0;
v4 = v3;
for ( i = 0LL; strlen(s) > i; ++i )
{
v6 = s[i];
v7 = func1(v6);
strcat(v4, v7);
}
return v4;
}

original_code:
char * hex_to_bin (char * hex) {
 char * bin = malloc(strlen(hex) * 4+1);
 int i = 0;
 bin[strlen(hex)*4] = '\0';
 for (i = 0; i < strlen(hex); i++) {
  bin = strcat(bin, single_digit_hex_to_bin(hex[i]));
 }
 return bin;
}

canonical_original_code:
char *hex_to_bin(char *hex) {
 char *bin = malloc(strlen(hex) * 4+1);
 int i = 0;
 bin[strlen(hex)*4] = '\0';
 for (i = 0; i < strlen(hex); i++) {
  bin = strcat(bin, single_digit_hex_to_bin(hex[i]));
 }
 return bin;
}

variable_types:
hex
char *

variable_types:
bin
char *

variable_types: i int


decompiled_code:
__int64 __fastcall bin_to_dec(char *s)
{
unsigned int v1; // er12
__int64 v2; // rbx
int v3; // eax
int v4; // er13

v1 = 0;
v2 = 0LL;
v3 = strlen(s);
v4 = v3 - 1;
while ( v3 > (int)v2 )
{
if ( s[v2] == 49 )
{
v1 += (int)pow(2.0, (double)(v4 - (int)v2));
v3 = strlen(s);
}
++v2;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s)
{
unsigned int v1; // er12
__int64 v2; // rbx
int v3; // eax
int v4; // er13

v1 = 0;
v2 = 0LL;
v3 = strlen(s);
v4 = v3 - 1;
while ( v3 > (int)v2 )
{
if ( s[v2] == 49 )
{
v1 += (int)pow(2.0, (double)(v4 - (int)v2));
v3 = strlen(s);
}
++v2;
}
return v1;
}

original_code:
int bin_to_dec (char * bin) {
 int i = 0;
 int power = (int)strlen(bin) - 1;
 int value = 0;
 for (i = 0; i < (int)strlen(bin); i++) {
  if (bin[i] == '1') {
   value += (int)pow(2, power);
  }
  power--;
 }
 return value;
}

canonical_original_code:
int bin_to_dec(char *bin) {
 int i = 0;
 int power = (int)strlen(bin) - 1;
 int value = 0;
 for (i = 0; i < (int)strlen(bin); i++) {
  if (bin[i] == '1') {
   value += (int)pow(2, power);
  }
  power--;
 }
 return value;
}

variable_types: power int

variable_types: value int

return_type: int


decompiled_code:
__int64 __fastcall hex_to_dec(char *a1)
{
char *v1; // rax

v1 = hex_to_bin(a1);
return bin_to_dec(v1);
}

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

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

original_code:
int hex_to_dec(char * hex) {
 char * bin = hex_to_bin(hex);
 return bin_to_dec(bin);
}

canonical_original_code:
int hex_to_dec(char *hex) {
 char *bin = hex_to_bin(hex);
 return bin_to_dec(bin);
}


main

canonical_name: main

repo: PSU-ChipLab/SimpleProcessor

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rdi
char **i; // rbx

if ( argc <= 1 )
fatal("no input files\n", (char)argv);
v3 = (char *)argv[1];
for ( i = (char **)(argv + 2); v3; ++i )
{
genFile(v3);
v3 = *i;
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rdi
char **i; // rbx

if ( argc <= 1 )
func7("no input files\n", (char)argv);
v3 = (char *)argv[1];
for ( i = (char **)(argv + 2); v3; ++i )
{
func8(v3);
v3 = *i;
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    int i;
    if (argc < 2)
        fatal("no input files\n");
    for (i = 1; argv[i]; ++i)
        genFile(argv[i]);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


fatal

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

va_start(arg, format);
fwrite("** Simple Loader Error: ", 1uLL, 0x18uLL, stderr);
vfprintf(stderr, format, arg);
exit(1);
}

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

va_start(arg, format);
fwrite("** Simple Loader Error: ", 1uLL, 0x18uLL, stderr);
vfprintf(stderr, format, arg);
exit(1);
}

original_code:
void fatal(const char *format, ...)
{
    va_list args;
    __builtin_va_start(args,format);
    fprintf(stderr, "** Simple Loader Error: ");
    vfprintf(stderr, format, args);
    __builtin_va_end(args);
    exit(1);
}

canonical_original_code:
void fatal(char *format, ...)
{
    __builtin_va_list args;
    __builtin_va_start(args,format);
    fprintf(stderr, "** Simple Loader Error: ");
    vfprintf(stderr, format, args);
    __builtin_va_end(args);
    exit(1);
}

variable_types:
format
char *

return_type: void


repo: Paluche/BlueLib

decompiled_code:
__int64 __fastcall bt_uuid16_to_uuid128(__int64 a1, __int64 a2)
{
__m128i v2; // xmm0
__int64 result; // rax

v2 = _mm_load_si128((const __m128i *)&bluetooth_base_uuid);
*(_DWORD *)a2 = 128;
*(__m128i *)(a2 + 4) = v2;
result = *(unsigned __int16 *)(a1 + 4);
*(_WORD *)(a2 + 16) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__m128i v2; // xmm0
__int64 result; // rax

v2 = _mm_load_si128((const __m128i *)&bluetooth_base_uuid);
*(_DWORD *)a2 = 128;
*(__m128i *)(a2 + 4) = v2;
result = *(unsigned __int16 *)(a1 + 4);
*(_WORD *)(a2 + 16) = result;
return result;
}

original_code:
static void bt_uuid16_to_uuid128(const bt_uuid_t *src, bt_uuid_t *dst)
{
    dst->value.u128 = bluetooth_base_uuid;
    dst->type = BT_UUID128;
    memcpy(&dst->value.u128.data[12],
           &src->value.u16, sizeof(src->value.u16));
}

canonical_original_code:
static void bt_uuid16_to_uuid128(struct bt_uuid_t *src, struct bt_uuid_t *dst)
{
    dst->value.u128 = bluetooth_base_uuid;
    dst->type = BT_UUID128;
    memcpy(&dst->value.u128.data[12],
           &src->value.u16, sizeof(src->value.u16));
}

variable_types: struct bt_uuid_t { enum { BT_UUID_UNSPEC=0, BT_UUID16=16, BT_UUID32=32, BT_UUID128=128 } type; union { unsigned short u16; unsigned int u32; struct uint128_t { unsigned char data[16]; } u128; } value; } *

variable_types:
dst
struct bt_uuid_t *

user_defined_types: struct bt_uuid_t { enum { BT_UUID_UNSPEC=0, BT_UUID16=16, BT_UUID32=32, BT_UUID128=128 } type; union { unsigned short u16; unsigned int u32; struct uint128_t u128; } value; }


decompiled_code:
__int64 __fastcall bt_uuid32_to_uuid128(__int64 a1, __int64 a2)
{
__m128i v2; // xmm0
__int64 result; // rax

v2 = _mm_load_si128((const __m128i *)&bluetooth_base_uuid);
*(_DWORD *)a2 = 128;
*(__m128i *)(a2 + 4) = v2;
result = *(unsigned int *)(a1 + 4);
*(_DWORD *)(a2 + 16) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__m128i v2; // xmm0
__int64 result; // rax

v2 = _mm_load_si128((const __m128i *)&bluetooth_base_uuid);
*(_DWORD *)a2 = 128;
*(__m128i *)(a2 + 4) = v2;
result = *(unsigned int *)(a1 + 4);
*(_DWORD *)(a2 + 16) = result;
return result;
}

original_code:
static void bt_uuid32_to_uuid128(const bt_uuid_t *src, bt_uuid_t *dst)
{
    dst->value.u128 = bluetooth_base_uuid;
    dst->type = BT_UUID128;
    memcpy(&dst->value.u128.data[12],
           &src->value.u32, sizeof(src->value.u32));
}

canonical_original_code:
static void bt_uuid32_to_uuid128(struct bt_uuid_t *src, struct bt_uuid_t *dst)
{
    dst->value.u128 = bluetooth_base_uuid;
    dst->type = BT_UUID128;
    memcpy(&dst->value.u128.data[12],
           &src->value.u32, sizeof(src->value.u32));
}

user_defined_types: struct uint128_t { unsigned char data[16]; }


decompiled_code:
int __fastcall bt_uuid128_cmp(__int64 a1, __int64 a2)
{
return memcmp((const void *)(a1 + 4), (const void *)(a2 + 4), 0x10uLL);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2)
{
return memcmp((const void *)(a1 + 4), (const void *)(a2 + 4), 0x10uLL);
}

original_code:
static int bt_uuid128_cmp(const bt_uuid_t *u1, const bt_uuid_t *u2)
{
    return memcmp(&u1->value.u128, &u2->value.u128, sizeof(uint128_t));
}

canonical_original_code:
static int bt_uuid128_cmp(struct bt_uuid_t *u1, struct bt_uuid_t *u2)
{
    return memcmp(&u1->value.u128, &u2->value.u128, sizeof(uint128_t));
}


original_code:
static inline int is_uuid128(const char *string)
{
    return (strlen(string) == 36 &&
            string[8] == '-' &&
            string[13] == '-' &&
            string[18] == '-' &&
            string[23] == '-');
}

canonical_original_code:
static inline int is_uuid128(char *string)
{
    return (strlen(string) == 36 &&
            string[8] == '-' &&
            string[13] == '-' &&
            string[18] == '-' &&
            string[23] == '-');
}

variable_types:
string
char *


decompiled_code:
_BOOL8 __fastcall is_uuid32(const char *a1)
{
return (strlen(a1) & 0xFFFFFFFFFFFFFFFDLL) == 8;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(const char *a1)
{
return (strlen(a1) & 0xFFFFFFFFFFFFFFFDLL) == 8;
}

original_code:
static inline int is_uuid32(const char *string)
{
    return (strlen(string) == 8 || strlen(string) == 10);
}

canonical_original_code:
static inline int is_uuid32(char *string)
{
    return (strlen(string) == 8 || strlen(string) == 10);
}


decompiled_code:
_BOOL8 __fastcall is_uuid16(const char *a1)
{
return (strlen(a1) & 0xFFFFFFFFFFFFFFFDLL) == 4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(const char *a1)
{
return (strlen(a1) & 0xFFFFFFFFFFFFFFFDLL) == 4;
}

original_code:
static inline int is_uuid16(const char *string)
{
    return (strlen(string) == 4 || strlen(string) == 6);
}

canonical_original_code:
static inline int is_uuid16(char *string)
{
    return (strlen(string) == 4 || strlen(string) == 6);
}


decompiled_code:
__int64 __fastcall bt_uuid_to_uuid128(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = *(unsigned int *)a1;
switch ( (_DWORD)result )
{
case 0x20:
return bt_uuid32_to_uuid128(a1, a2);
case 0x80:
*(__m128i *)a2 = _mm_loadu_si128((const __m128i *)a1);
result = *(unsigned int *)(a1 + 16);
*(_DWORD *)(a2 + 16) = result;
break;
case 0x10:
result = bt_uuid16_to_uuid128(a1, a2);
break;
}
return result;
}

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

result = *(unsigned int *)a1;
switch ( (_DWORD)result )
{
case 0x20:
return func3(a1, a2);
case 0x80:
*(__m128i *)a2 = _mm_loadu_si128((const __m128i *)a1);
result = *(unsigned int *)(a1 + 16);
*(_DWORD *)(a2 + 16) = result;
break;
case 0x10:
result = func2(a1, a2);
break;
}
return result;
}

original_code:
void bt_uuid_to_uuid128(const bt_uuid_t *src, bt_uuid_t *dst)
{
    switch (src->type) {
        case BT_UUID128:
            *dst = *src;
            break;
        case BT_UUID32:
            bt_uuid32_to_uuid128(src, dst);
            break;
        case BT_UUID16:
            bt_uuid16_to_uuid128(src, dst);
            break;
        default:
            break;
    }
}

canonical_original_code:
void bt_uuid_to_uuid128(struct bt_uuid_t *src, struct bt_uuid_t *dst)
{
    switch (src->type) {
        case BT_UUID128:
            *dst = *src;
            break;
        case BT_UUID32:
            bt_uuid32_to_uuid128(src, dst);
            break;
        case BT_UUID16:
            bt_uuid16_to_uuid128(src, dst);
            break;
        default:
            break;
    }
}


decompiled_code:
__int64 __fastcall bt_uuid16_create(__int64 a1, __int16 a2)
{
__int64 result; // rax

*(_DWORD *)(a1 + 16) = 0;
result = 0LL;
*(_OWORD *)a1 = 0LL;
*(_DWORD *)a1 = 16;
*(_WORD *)(a1 + 4) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int16 a2)
{
__int64 result; // rax

*(_DWORD *)(a1 + 16) = 0;
result = 0LL;
*(_OWORD *)a1 = 0LL;
*(_DWORD *)a1 = 16;
*(_WORD *)(a1 + 4) = a2;
return result;
}

original_code:
int bt_uuid16_create(bt_uuid_t *btuuid, uint16_t value)
{
    memset(btuuid, 0, sizeof(bt_uuid_t));
    btuuid->type = BT_UUID16;
    btuuid->value.u16 = value;
    return 0;
}

canonical_original_code:
int bt_uuid16_create(struct bt_uuid_t *btuuid, unsigned short value)
{
    memset(btuuid, 0, sizeof(bt_uuid_t));
    btuuid->type = BT_UUID16;
    btuuid->value.u16 = value;
    return 0;
}

variable_types:
value
unsigned short


decompiled_code:
__int64 __fastcall bt_string_to_uuid16(__int64 a1, const char *a2)
{
__int16 v2; // ax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

endptr = 0LL;
v2 = strtol(a2, &endptr, 16);
if ( !endptr || *endptr )
return 4294967274LL;
bt_uuid16_create(a1, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, const char *a2)
{
__int16 v2; // ax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

endptr = 0LL;
v2 = strtol(a2, &endptr, 16);
if ( !endptr || *endptr )
return 4294967274LL;
func11(a1, v2);
return 0LL;
}

original_code:
static int bt_string_to_uuid16(bt_uuid_t *uuid, const char *string)
{
    uint16_t u16;
    char *endptr = ((void *)0);
    u16 = strtol(string, &endptr, 16);
    if (endptr && *endptr == '\0') {
        bt_uuid16_create(uuid, u16);
        return 0;
    }
    return -22;
}

canonical_original_code:
static int bt_string_to_uuid16(struct bt_uuid_t *uuid, char *string)
{
    unsigned short u16;
    char *endptr = ((void *)0);
    u16 = strtol(string, &endptr, 16);
    if (endptr && *endptr == '\0') {
        bt_uuid16_create(uuid, u16);
        return 0;
    }
    return -22;
}

variable_types:
endptr
char *


decompiled_code:
__int64 __fastcall bt_uuid32_create(__int64 a1, int a2)
{
__int64 result; // rax

*(_QWORD *)(a1 + 8) = 0LL;
result = 0LL;
*(_DWORD *)(a1 + 16) = 0;
*(_DWORD *)a1 = 32;
*(_DWORD *)(a1 + 4) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2)
{
__int64 result; // rax

*(_QWORD *)(a1 + 8) = 0LL;
result = 0LL;
*(_DWORD *)(a1 + 16) = 0;
*(_DWORD *)a1 = 32;
*(_DWORD *)(a1 + 4) = a2;
return result;
}

original_code:
int bt_uuid32_create(bt_uuid_t *btuuid, uint32_t value)
{
    memset(btuuid, 0, sizeof(bt_uuid_t));
    btuuid->type = BT_UUID32;
    btuuid->value.u32 = value;
    return 0;
}

canonical_original_code:
int bt_uuid32_create(struct bt_uuid_t *btuuid, unsigned int value)
{
    memset(btuuid, 0, sizeof(bt_uuid_t));
    btuuid->type = BT_UUID32;
    btuuid->value.u32 = value;
    return 0;
}

variable_types:
value
unsigned int


decompiled_code:
__int64 __fastcall bt_string_to_uuid32(__int64 a1, const char *a2)
{
int v2; // eax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

endptr = 0LL;
v2 = strtol(a2, &endptr, 16);
if ( !endptr || *endptr )
return 4294967274LL;
bt_uuid32_create(a1, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, const char *a2)
{
int v2; // eax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

endptr = 0LL;
v2 = strtol(a2, &endptr, 16);
if ( !endptr || *endptr )
return 4294967274LL;
func13(a1, v2);
return 0LL;
}

original_code:
static int bt_string_to_uuid32(bt_uuid_t *uuid, const char *string)
{
    uint32_t u32;
    char *endptr = ((void *)0);
    u32 = strtol(string, &endptr, 16);
    if (endptr && *endptr == '\0') {
        bt_uuid32_create(uuid, u32);
        return 0;
    }
    return -22;
}

canonical_original_code:
static int bt_string_to_uuid32(struct bt_uuid_t *uuid, char *string)
{
    unsigned int u32;
    char *endptr = ((void *)0);
    u32 = strtol(string, &endptr, 16);
    if (endptr && *endptr == '\0') {
        bt_uuid32_create(uuid, u32);
        return 0;
    }
    return -22;
}


decompiled_code:
__int64 __fastcall bt_uuid128_create(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

*(_DWORD *)a1 = 128;
result = 0LL;
*(_QWORD *)(a1 + 4) = a2;
*(_QWORD *)(a1 + 12) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

*(_DWORD *)a1 = 128;
result = 0LL;
*(_QWORD *)(a1 + 4) = a2;
*(_QWORD *)(a1 + 12) = a3;
return result;
}

original_code:
int bt_uuid128_create(bt_uuid_t *btuuid, uint128_t value)
{
    memset(btuuid, 0, sizeof(bt_uuid_t));
    btuuid->type = BT_UUID128;
    btuuid->value.u128 = value;
    return 0;
}

canonical_original_code:
int bt_uuid128_create(struct bt_uuid_t *btuuid, struct uint128_t value)
{
    memset(btuuid, 0, sizeof(bt_uuid_t));
    btuuid->type = BT_UUID128;
    btuuid->value.u128 = value;
    return 0;
}

variable_types:
value
struct uint128_t


original_code:
static int bt_string_to_uuid128(bt_uuid_t *uuid, const char *string)
{
    uint32_t data0, data4;
    uint16_t data1, data2, data3, data5;
    uint128_t n128, u128;
    uint8_t *val = (uint8_t *) &n128;
    if (sscanf(string, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
               &data0, &data1, &data2,
               &data3, &data4, &data5) != 6)
        return -22;
    data0 = htonl(data0);
    data1 = htons(data1);
    data2 = htons(data2);
    data3 = htons(data3);
    data4 = htonl(data4);
    data5 = htons(data5);
    memcpy(&val[0], &data0, 4);
    memcpy(&val[4], &data1, 2);
    memcpy(&val[6], &data2, 2);
    memcpy(&val[8], &data3, 2);
    memcpy(&val[10], &data4, 4);
    memcpy(&val[14], &data5, 2);
    ntoh128(&n128, &u128);
    bt_uuid128_create(uuid, u128);
    return 0;
}

canonical_original_code:
static int bt_string_to_uuid128(struct bt_uuid_t *uuid, char *string)
{
    unsigned int data0; unsigned int data4;
    unsigned short data1; unsigned short data2; unsigned short data3; unsigned short data5;
    struct uint128_t n128; struct uint128_t u128;
    unsigned char *val = (uint8_t *) &n128;
    if (sscanf(string, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
               &data0, &data1, &data2,
               &data3, &data4, &data5) != 6)
        return -22;
    data0 = htonl(data0);
    data1 = htons(data1);
    data2 = htons(data2);
    data3 = htons(data3);
    data4 = htonl(data4);
    data5 = htons(data5);
    memcpy(&val[0], &data0, 4);
    memcpy(&val[4], &data1, 2);
    memcpy(&val[6], &data2, 2);
    memcpy(&val[8], &data3, 2);
    memcpy(&val[10], &data4, 4);
    memcpy(&val[14], &data5, 2);
    ntoh128(&n128, &u128);
    bt_uuid128_create(uuid, u128);
    return 0;
}

variable_types: struct uint128_t { unsigned char data[16]; }

variable_types:
val
unsigned char *


decompiled_code:
int __fastcall bt_uuid_cmp(__int64 a1)
{
__int64 v1; // r8
_BYTE v3[32]; // [rsp+0h] [rbp-48h] BYREF
char v4[40]; // [rsp+20h] [rbp-28h] BYREF

bt_uuid_to_uuid128(a1, (__int64)v3);
bt_uuid_to_uuid128(v1, (__int64)v4);
return bt_uuid128_cmp((__int64)v3, (__int64)v4);
}

original_code:
int bt_uuid_cmp(const bt_uuid_t *uuid1, const bt_uuid_t *uuid2)
{
    bt_uuid_t u1, u2;
    bt_uuid_to_uuid128(uuid1, &u1);
    bt_uuid_to_uuid128(uuid2, &u2);
    return bt_uuid128_cmp(&u1, &u2);
}

canonical_original_code:
int bt_uuid_cmp(struct bt_uuid_t *uuid1, struct bt_uuid_t *uuid2)
{
    struct bt_uuid_t u1; struct bt_uuid_t u2;
    bt_uuid_to_uuid128(uuid1, &u1);
    bt_uuid_to_uuid128(uuid2, &u2);
    return bt_uuid128_cmp(&u1, &u2);
}

variable_types: struct bt_uuid_t { enum { BT_UUID_UNSPEC=0, BT_UUID16=16, BT_UUID32=32, BT_UUID128=128 } type; union { unsigned short u16; unsigned int u32; struct uint128_t { unsigned char data[16]; } u128; } value; }


decompiled_code:
__int64 __fastcall bt_uuid_to_string(unsigned __int8 *a1, char *a2, size_t a3)
{
__int64 v3; // rcx
__int64 result; // rax
__int64 v5; // rsi
unsigned int v6; // eax
__int64 v7; // rdx
__int64 v8; // rcx
__int64 v9; // r8
__int64 v10; // r9
size_t v11; // r10
char *v12; // r11
unsigned int v13; // [rsp+0h] [rbp-18h] BYREF
__int16 v14; // [rsp+4h] [rbp-14h]
__int16 v15; // [rsp+6h] [rbp-12h]
__int16 v16; // [rsp+8h] [rbp-10h]
unsigned int v17; // [rsp+Ah] [rbp-Eh]
__int16 v18; // [rsp+Eh] [rbp-Ah]

if ( a1 )
{
v3 = *(unsigned int *)a1;
if ( (_DWORD)v3 == 32 )
{
snprintf(a2, a3, "%.8x", *((unsigned int *)a1 + 1));
return 0LL;
}
if ( (_DWORD)v3 != 128 )
{
if ( (_DWORD)v3 != 16 )
{
snprintf(a2, a3, "Type of UUID (%x) unknown.", v3);
return 4294967274LL;
}
snprintf(a2, a3, "%.4x", *((unsigned __int16 *)a1 + 2));
return 0LL;
}
ntoh128(a1 + 4, (__int64)&v13);
_bswap_16(v18);
v5 = (unsigned int)_bswap_32(v17);
_bswap_16(v16);
_bswap_16(v15);
_bswap_16(v14);
v6 = _bswap_32(v13);
snprintf(v12, v11, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x", v6, v9, v10, v7, v5, v8);
result = 0LL;
}
else
{
snprintf(a2, a3, "NULL");
result = 4294967274LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(unsigned __int8 *a1, char *a2, size_t a3)
{
__int64 v3; // rcx
__int64 result; // rax
__int64 v5; // rsi
unsigned int v6; // eax
__int64 v7; // rdx
__int64 v8; // rcx
__int64 v9; // r8
__int64 v10; // r9
size_t v11; // r10
char *v12; // r11
unsigned int v13; // [rsp+0h] [rbp-18h] BYREF
__int16 v14; // [rsp+4h] [rbp-14h]
__int16 v15; // [rsp+6h] [rbp-12h]
__int16 v16; // [rsp+8h] [rbp-10h]
unsigned int v17; // [rsp+Ah] [rbp-Eh]
__int16 v18; // [rsp+Eh] [rbp-Ah]

if ( a1 )
{
v3 = *(unsigned int *)a1;
if ( (_DWORD)v3 == 32 )
{
snprintf(a2, a3, "%.8x", *((unsigned int *)a1 + 1));
return 0LL;
}
if ( (_DWORD)v3 != 128 )
{
if ( (_DWORD)v3 != 16 )
{
snprintf(a2, a3, "Type of UUID (%x) unknown.", v3);
return 4294967274LL;
}
snprintf(a2, a3, "%.4x", *((unsigned __int16 *)a1 + 2));
return 0LL;
}
func1(a1 + 4, (__int64)&v13);
func5(v18);
v5 = (unsigned int)func6(v17);
func5(v16);
func5(v15);
func5(v14);
v6 = func6(v13);
snprintf(v12, v11, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x", v6, v9, v10, v7, v5, v8);
result = 0LL;
}
else
{
snprintf(a2, a3, "NULL");
result = 4294967274LL;
}
return result;
}

original_code:
int bt_uuid_to_string(const bt_uuid_t *uuid, char *str, size_t n)
{
    if (!uuid) {
        snprintf(str, n, "NULL");
        return -22;
    }
    switch (uuid->type) {
        case BT_UUID16:
            snprintf(str, n, "%.4x", uuid->value.u16);
            break;
        case BT_UUID32:
            snprintf(str, n, "%.8x", uuid->value.u32);
            break;
        case BT_UUID128:
            {
                unsigned int data0;
                unsigned short data1;
                unsigned short data2;
                unsigned short data3;
                unsigned int data4;
                unsigned short data5;
                uint128_t nvalue;
                const uint8_t *data = (uint8_t *) &nvalue;
                ntoh128(&uuid->value.u128, &nvalue);
                memcpy(&data0, &data[0], 4);
                memcpy(&data1, &data[4], 2);
                memcpy(&data2, &data[6], 2);
                memcpy(&data3, &data[8], 2);
                memcpy(&data4, &data[10], 4);
                memcpy(&data5, &data[14], 2);
                snprintf(str, n, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x",
                         ntohl(data0), ntohs(data1),
                         ntohs(data2), ntohs(data3),
                         ntohl(data4), ntohs(data5));
            }
            break;
        default:
            snprintf(str, n, "Type of UUID (%x) unknown.", uuid->type);
            return -22;
    }
    return 0;
}

canonical_original_code:
int bt_uuid_to_string(struct bt_uuid_t *uuid, char *str, unsigned long n)
{
    if (!uuid) {
        snprintf(str, n, "NULL");
        return -22;
    }
    switch (uuid->type) {
        case BT_UUID16:
            snprintf(str, n, "%.4x", uuid->value.u16);
            break;
        case BT_UUID32:
            snprintf(str, n, "%.8x", uuid->value.u32);
            break;
        case BT_UUID128:
            {
                unsigned int data0;
                unsigned short data1;
                unsigned short data2;
                unsigned short data3;
                unsigned int data4;
                unsigned short data5;
                struct uint128_t nvalue;
                unsigned char *data = (uint8_t *) &nvalue;
                ntoh128(&uuid->value.u128, &nvalue);
                memcpy(&data0, &data[0], 4);
                memcpy(&data1, &data[4], 2);
                memcpy(&data2, &data[6], 2);
                memcpy(&data3, &data[8], 2);
                memcpy(&data4, &data[10], 4);
                memcpy(&data5, &data[14], 2);
                snprintf(str, n, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x",
                         ntohl(data0), ntohs(data1),
                         ntohs(data2), ntohs(data3),
                         ntohl(data4), ntohs(data5));
            }
            break;
        default:
            snprintf(str, n, "Type of UUID (%x) unknown.", uuid->type);
            return -22;
    }
    return 0;
}

variable_types:
str
char *

variable_types:
n
unsigned long

variable_types:
data
unsigned char *


decompiled_code:
__int64 __fastcall bt_string_to_uuid(__int64 a1, const char *a2)
{
if ( is_uuid128((__int64)a2) )
return bt_string_to_uuid128(a1, (__int64)a2);
if ( is_uuid32(a2) )
return bt_string_to_uuid32(a1, a2);
if ( is_uuid16(a2) )
return bt_string_to_uuid16(a1, a2);
return 4294967274LL;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, const char *a2)
{
if ( func7((__int64)a2) )
return func16(a1, (__int64)a2);
if ( func8(a2) )
return func14(a1, a2);
if ( func9(a2) )
return func12(a1, a2);
return 4294967274LL;
}

original_code:
int bt_string_to_uuid(bt_uuid_t *uuid, const char *string)
{
    if (is_uuid128(string))
        return bt_string_to_uuid128(uuid, string);
    else if (is_uuid32(string))
        return bt_string_to_uuid32(uuid, string);
    else if (is_uuid16(string))
        return bt_string_to_uuid16(uuid, string);
    return -22;
}

canonical_original_code:
int bt_string_to_uuid(struct bt_uuid_t *uuid, char *string)
{
    if (is_uuid128(string))
        return bt_string_to_uuid128(uuid, string);
    else if (is_uuid32(string))
        return bt_string_to_uuid32(uuid, string);
    else if (is_uuid16(string))
        return bt_string_to_uuid16(uuid, string);
    return -22;
}


decompiled_code:
// attributes: thunk
int bt_uuid_strcmp(const char *s1, const char *s2)
{
return strcasecmp(s1, s2);
}

canonical_decompiled_code:
int func20(const char *s1, const char *s2)
{
return strcasecmp(s1, s2);
}

original_code:
int bt_uuid_strcmp(const void *a, const void *b)
{
    return strcasecmp(a, b);
}

canonical_original_code:
int bt_uuid_strcmp(void *a, void *b)
{
    return strcasecmp(a, b);
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
char *__fastcall bl_primary_new(char *src, int a2, __int16 a3, __int16 a4)
{
char *v6; // rax
char *v7; // r8

v6 = (char *)malloc(0x30uLL);
v7 = v6;
if ( v6 )
{
if ( src )
v7 = strcpy(v6, src);
else
*v6 = 0;
*((_DWORD *)v7 + 10) = a2;
*((_WORD *)v7 + 22) = a3;
*((_WORD *)v7 + 23) = a4;
}
return v7;
}

canonical_decompiled_code:
char *__fastcall func0(char *src, int a2, __int16 a3, __int16 a4)
{
char *v6; // rax
char *v7; // r8

v6 = (char *)malloc(0x30uLL);
v7 = v6;
if ( v6 )
{
if ( src )
v7 = strcpy(v6, src);
else
*v6 = 0;
*((_DWORD *)v7 + 10) = a2;
*((_WORD *)v7 + 22) = a3;
*((_WORD *)v7 + 23) = a4;
}
return v7;
}

original_code:
bl_primary_t *bl_primary_new(char *uuid_str, const gboolean changed,
                             const uint16_t start_handle,
                             const uint16_t end_handle)
{
    bl_primary_t *new_bl_primary = malloc(sizeof(bl_primary_t));
    if (new_bl_primary == ((void *)0))
        return ((void *)0);
    if (uuid_str)
        strcpy(new_bl_primary->uuid_str, uuid_str);
    else
        new_bl_primary->uuid_str[0] = '\0';
    memcpy(&new_bl_primary->changed, &changed, sizeof(gboolean));
    memcpy(&new_bl_primary->start_handle, &start_handle, sizeof(uint16_t));
    memcpy(&new_bl_primary->end_handle, &end_handle, sizeof(uint16_t));
    return new_bl_primary;
}

canonical_original_code:
struct bl_primary_t *bl_primary_new(char *uuid_str, int changed, unsigned short start_handle, unsigned short end_handle)
{
    struct bl_primary_t *new_bl_primary = malloc(sizeof(bl_primary_t));
    if (new_bl_primary == ((void *)0))
        return ((void *)0);
    if (uuid_str)
        strcpy(new_bl_primary->uuid_str, uuid_str);
    else
        new_bl_primary->uuid_str[0] = '\0';
    memcpy(&new_bl_primary->changed, &changed, sizeof(gboolean));
    memcpy(&new_bl_primary->start_handle, &start_handle, sizeof(unsigned short));
    memcpy(&new_bl_primary->end_handle, &end_handle, sizeof(unsigned short));
    return new_bl_primary;
}

variable_types: changed int

variable_types: struct bl_primary_t { char uuid_str[37]; int changed; unsigned short start_handle; unsigned short end_handle; } *


decompiled_code:
char *__fastcall bl_included_new(char *src, __int16 a2, __int16 a3, __int16 a4)
{
char *v6; // rax
char *v7; // r8

v6 = (char *)malloc(0x2CuLL);
v7 = v6;
if ( v6 )
{
if ( src )
v7 = strcpy(v6, src);
else
*v6 = 0;
*((_WORD *)v7 + 19) = a2;
*((_WORD *)v7 + 20) = a3;
*((_WORD *)v7 + 21) = a4;
}
return v7;
}

canonical_decompiled_code:
char *__fastcall func1(char *src, __int16 a2, __int16 a3, __int16 a4)
{
char *v6; // rax
char *v7; // r8

v6 = (char *)malloc(0x2CuLL);
v7 = v6;
if ( v6 )
{
if ( src )
v7 = strcpy(v6, src);
else
*v6 = 0;
*((_WORD *)v7 + 19) = a2;
*((_WORD *)v7 + 20) = a3;
*((_WORD *)v7 + 21) = a4;
}
return v7;
}

original_code:
bl_included_t *bl_included_new(char *uuid_str, const uint16_t handle,
                               const uint16_t start_handle,
                               const uint16_t end_handle)
{
    bl_included_t *new_bl_included = malloc(sizeof(bl_included_t));
    if (new_bl_included == ((void *)0))
        return ((void *)0);
    if (uuid_str)
        strcpy(new_bl_included->uuid_str, uuid_str);
    else
        new_bl_included->uuid_str[0] = '\0';
    memcpy(&new_bl_included->handle, &handle, sizeof(uint16_t));
    memcpy(&new_bl_included->start_handle, &start_handle, sizeof(uint16_t));
    memcpy(&new_bl_included->end_handle, &end_handle, sizeof(uint16_t));
    return new_bl_included;
}

canonical_original_code:
struct bl_included_t *bl_included_new(char *uuid_str, unsigned short handle, unsigned short start_handle, unsigned short end_handle)
{
    struct bl_included_t *new_bl_included = malloc(sizeof(bl_included_t));
    if (new_bl_included == ((void *)0))
        return ((void *)0);
    if (uuid_str)
        strcpy(new_bl_included->uuid_str, uuid_str);
    else
        new_bl_included->uuid_str[0] = '\0';
    memcpy(&new_bl_included->handle, &handle, sizeof(unsigned short));
    memcpy(&new_bl_included->start_handle, &start_handle, sizeof(unsigned short));
    memcpy(&new_bl_included->end_handle, &end_handle, sizeof(unsigned short));
    return new_bl_included;
}

variable_types:
handle
unsigned short

variable_types: struct bl_included_t { char uuid_str[37]; unsigned short handle; unsigned short start_handle; unsigned short end_handle; } *


decompiled_code:
char *__fastcall bl_char_new(char *src, __int16 a2, char a3, __int16 a4)
{
char *v6; // rax
char *v7; // r8

v6 = (char *)malloc(0x2CuLL);
v7 = v6;
if ( v6 )
{
if ( src )
v7 = strcpy(v6, src);
else
*v6 = 0;
*((_WORD *)v7 + 19) = a2;
v7[40] = a3;
*((_WORD *)v7 + 21) = a4;
}
return v7;
}

canonical_decompiled_code:
char *__fastcall func2(char *src, __int16 a2, char a3, __int16 a4)
{
char *v6; // rax
char *v7; // r8

v6 = (char *)malloc(0x2CuLL);
v7 = v6;
if ( v6 )
{
if ( src )
v7 = strcpy(v6, src);
else
*v6 = 0;
*((_WORD *)v7 + 19) = a2;
v7[40] = a3;
*((_WORD *)v7 + 21) = a4;
}
return v7;
}

original_code:
bl_char_t *bl_char_new(char *uuid_str, const uint16_t handle,
                       const uint8_t properties, const uint16_t value_handle)
{
    bl_char_t *new_bl_char = malloc(sizeof(bl_char_t));
    if (new_bl_char == ((void *)0))
        return ((void *)0);
    if (uuid_str)
        strcpy(new_bl_char->uuid_str, uuid_str);
    else
        new_bl_char->uuid_str[0] = '\0';
    memcpy(&new_bl_char->handle, &handle, sizeof(uint16_t));
    memcpy(&new_bl_char->properties, &properties, sizeof(uint8_t));
    memcpy(&new_bl_char->value_handle, &value_handle, sizeof(uint16_t));
    return new_bl_char;
}

canonical_original_code:
struct bl_char_t *bl_char_new(char *uuid_str, unsigned short handle, unsigned char properties, unsigned short value_handle)
{
    struct bl_char_t *new_bl_char = malloc(sizeof(bl_char_t));
    if (new_bl_char == ((void *)0))
        return ((void *)0);
    if (uuid_str)
        strcpy(new_bl_char->uuid_str, uuid_str);
    else
        new_bl_char->uuid_str[0] = '\0';
    memcpy(&new_bl_char->handle, &handle, sizeof(unsigned short));
    memcpy(&new_bl_char->properties, &properties, sizeof(unsigned char));
    memcpy(&new_bl_char->value_handle, &value_handle, sizeof(unsigned short));
    return new_bl_char;
}

variable_types:
properties
unsigned char

variable_types: struct bl_char_t { char uuid_str[37]; unsigned short handle; unsigned char properties; unsigned short value_handle; } *


decompiled_code:
char *__fastcall bl_desc_new(char *src, __int16 a2)
{
char *v2; // rax
char *v3; // r8

v2 = (char *)malloc(0x28uLL);
v3 = v2;
if ( v2 )
{
if ( src )
v3 = strcpy(v2, src);
else
*v2 = 0;
*((_WORD *)v3 + 19) = a2;
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func3(char *src, __int16 a2)
{
char *v2; // rax
char *v3; // r8

v2 = (char *)malloc(0x28uLL);
v3 = v2;
if ( v2 )
{
if ( src )
v3 = strcpy(v2, src);
else
*v2 = 0;
*((_WORD *)v3 + 19) = a2;
}
return v3;
}

original_code:
bl_desc_t *bl_desc_new(char *uuid_str, const uint16_t handle)
{
    bl_desc_t *new_bl_desc = malloc(sizeof(bl_desc_t));
    if (new_bl_desc == ((void *)0))
        return ((void *)0);
    if (uuid_str)
        strcpy(new_bl_desc->uuid_str, uuid_str);
    else
        new_bl_desc->uuid_str[0] = '\0';
    new_bl_desc->handle = handle;
    return new_bl_desc;
}

canonical_original_code:
struct bl_desc_t *bl_desc_new(char *uuid_str, unsigned short handle)
{
    struct bl_desc_t *new_bl_desc = malloc(sizeof(bl_desc_t));
    if (new_bl_desc == ((void *)0))
        return ((void *)0);
    if (uuid_str)
        strcpy(new_bl_desc->uuid_str, uuid_str);
    else
        new_bl_desc->uuid_str[0] = '\0';
    new_bl_desc->handle = handle;
    return new_bl_desc;
}

variable_types: struct bl_desc_t { char uuid_str[37]; unsigned short handle; } *


decompiled_code:
char *__fastcall bl_value_new(char *src, __int16 a2, size_t a3, const void *a4)
{
char *v6; // rax
char *v7; // r12
void *v8; // rax

v6 = (char *)malloc(0x38uLL);
v7 = v6;
if ( v6 )
{
if ( src )
strcpy(v6, src);
else
*v6 = 0;
*((_WORD *)v7 + 19) = a2;
*((_QWORD *)v7 + 5) = a3;
v8 = malloc(a3);
*((_QWORD *)v7 + 6) = v8;
memcpy(v8, a4, a3);
}
return v7;
}

canonical_decompiled_code:
char *__fastcall func4(char *src, __int16 a2, size_t a3, const void *a4)
{
char *v6; // rax
char *v7; // r12
void *v8; // rax

v6 = (char *)malloc(0x38uLL);
v7 = v6;
if ( v6 )
{
if ( src )
strcpy(v6, src);
else
*v6 = 0;
*((_WORD *)v7 + 19) = a2;
*((_QWORD *)v7 + 5) = a3;
v8 = malloc(a3);
*((_QWORD *)v7 + 6) = v8;
memcpy(v8, a4, a3);
}
return v7;
}

original_code:
bl_value_t *bl_value_new(char *uuid_str, const uint16_t handle,
                         const size_t data_size, uint8_t *data)
{
    bl_value_t *new_bl_value = malloc(sizeof(bl_value_t));
    if (new_bl_value == ((void *)0))
        return ((void *)0);
    if (uuid_str)
        strcpy(new_bl_value->uuid_str, uuid_str);
    else
        new_bl_value->uuid_str[0] = '\0';
    memcpy(&new_bl_value->handle, &handle, sizeof(uint16_t));
    memcpy(&new_bl_value->data_size, &data_size, sizeof(size_t));
    new_bl_value->data = malloc(new_bl_value->data_size*sizeof(uint8_t));
    memcpy(new_bl_value->data, data, new_bl_value->data_size*sizeof(uint8_t));
    return new_bl_value;
}

canonical_original_code:
struct bl_value_t *bl_value_new(char *uuid_str, unsigned short handle, unsigned long data_size, unsigned char *data)
{
    struct bl_value_t *new_bl_value = malloc(sizeof(bl_value_t));
    if (new_bl_value == ((void *)0))
        return ((void *)0);
    if (uuid_str)
        strcpy(new_bl_value->uuid_str, uuid_str);
    else
        new_bl_value->uuid_str[0] = '\0';
    memcpy(&new_bl_value->handle, &handle, sizeof(unsigned short));
    memcpy(&new_bl_value->data_size, &data_size, sizeof(unsigned long));
    new_bl_value->data = malloc(new_bl_value->data_size*sizeof(unsigned char));
    memcpy(new_bl_value->data, data, new_bl_value->data_size*sizeof(unsigned char));
    return new_bl_value;
}

variable_types: struct bl_value_t { char uuid_str[37]; unsigned short handle; unsigned long data_size; unsigned char *data; } *


decompiled_code:
char *__fastcall bl_primary_cpy(__int64 a1)
{
char *result; // rax

if ( a1 )
result = bl_primary_new((char *)a1, *(_DWORD *)(a1 + 40), *(_WORD *)(a1 + 44), *(_WORD *)(a1 + 46));
else
result = 0LL;
return result;
}

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

if ( a1 )
result = func0((char *)a1, *(_DWORD *)(a1 + 40), *(_WORD *)(a1 + 44), *(_WORD *)(a1 + 46));
else
result = 0LL;
return result;
}

original_code:
bl_primary_t *bl_primary_cpy(bl_primary_t *bl_primary)
{
    if (bl_primary) {
        return bl_primary_new(bl_primary->uuid_str, bl_primary->changed,
                              bl_primary->start_handle,
                              bl_primary->end_handle);
    }
    return ((void *)0);
}

canonical_original_code:
struct bl_primary_t *bl_primary_cpy(struct bl_primary_t *bl_primary)
{
    if (bl_primary) {
        return bl_primary_new(bl_primary->uuid_str, bl_primary->changed,
                              bl_primary->start_handle,
                              bl_primary->end_handle);
    }
    return ((void *)0);
}

return_type: struct bl_primary_t { char uuid_str[37]; int changed; unsigned short start_handle; unsigned short end_handle; } *


decompiled_code:
char *__fastcall bl_included_cpy(__int64 a1)
{
char *result; // rax

if ( a1 )
result = bl_included_new((char *)a1, *(_WORD *)(a1 + 38), *(_WORD *)(a1 + 40), *(_WORD *)(a1 + 42));
else
result = 0LL;
return result;
}

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

if ( a1 )
result = func1((char *)a1, *(_WORD *)(a1 + 38), *(_WORD *)(a1 + 40), *(_WORD *)(a1 + 42));
else
result = 0LL;
return result;
}

original_code:
bl_included_t *bl_included_cpy(bl_included_t *bl_included)
{
    if (bl_included) {
        return bl_included_new(bl_included->uuid_str, bl_included->handle,
                               bl_included->start_handle,
                               bl_included->end_handle);
    }
    return ((void *)0);
}

canonical_original_code:
struct bl_included_t *bl_included_cpy(struct bl_included_t *bl_included)
{
    if (bl_included) {
        return bl_included_new(bl_included->uuid_str, bl_included->handle,
                               bl_included->start_handle,
                               bl_included->end_handle);
    }
    return ((void *)0);
}

return_type: struct bl_included_t { char uuid_str[37]; unsigned short handle; unsigned short start_handle; unsigned short end_handle; } *


decompiled_code:
char *__fastcall bl_char_cpy(__int64 a1)
{
char *result; // rax

if ( a1 )
result = bl_char_new((char *)a1, *(_WORD *)(a1 + 38), *(_BYTE *)(a1 + 40), *(_WORD *)(a1 + 42));
else
result = 0LL;
return result;
}

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

if ( a1 )
result = func2((char *)a1, *(_WORD *)(a1 + 38), *(_BYTE *)(a1 + 40), *(_WORD *)(a1 + 42));
else
result = 0LL;
return result;
}

original_code:
bl_char_t *bl_char_cpy(bl_char_t *bl_char)
{
    if (bl_char) {
        return bl_char_new(bl_char->uuid_str, bl_char->handle,
                           bl_char->properties, bl_char->value_handle);
    }
    return ((void *)0);
}

canonical_original_code:
struct bl_char_t *bl_char_cpy(struct bl_char_t *bl_char)
{
    if (bl_char) {
        return bl_char_new(bl_char->uuid_str, bl_char->handle,
                           bl_char->properties, bl_char->value_handle);
    }
    return ((void *)0);
}

return_type: struct bl_char_t { char uuid_str[37]; unsigned short handle; unsigned char properties; unsigned short value_handle; } *


decompiled_code:
char *__fastcall bl_desc_cpy(__int64 a1)
{
char *result; // rax

if ( a1 )
result = bl_desc_new((char *)a1, *(_WORD *)(a1 + 38));
else
result = 0LL;
return result;
}

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

if ( a1 )
result = func3((char *)a1, *(_WORD *)(a1 + 38));
else
result = 0LL;
return result;
}

original_code:
bl_desc_t *bl_desc_cpy(bl_desc_t *bl_desc)
{
    if (bl_desc) {
        return bl_desc_new(bl_desc->uuid_str, bl_desc->handle);
    }
    return ((void *)0);
}

canonical_original_code:
struct bl_desc_t *bl_desc_cpy(struct bl_desc_t *bl_desc)
{
    if (bl_desc) {
        return bl_desc_new(bl_desc->uuid_str, bl_desc->handle);
    }
    return ((void *)0);
}

return_type: struct bl_desc_t { char uuid_str[37]; unsigned short handle; } *


decompiled_code:
char *__fastcall bl_value_cpy(__int64 a1)
{
char *result; // rax

if ( a1 )
result = bl_value_new((char *)a1, *(_WORD *)(a1 + 38), *(_QWORD *)(a1 + 40), *(const void **)(a1 + 48));
else
result = 0LL;
return result;
}

canonical_decompiled_code:
char *__fastcall func9(__int64 a1)
{
char *result; // rax

if ( a1 )
result = func4((char *)a1, *(_WORD *)(a1 + 38), *(_QWORD *)(a1 + 40), *(const void **)(a1 + 48));
else
result = 0LL;
return result;
}

original_code:
bl_value_t *bl_value_cpy(bl_value_t *bl_value)
{
    if (bl_value) {
        return bl_value_new(bl_value->uuid_str, bl_value->handle,
                            bl_value->data_size, bl_value->data);
    }
    return ((void *)0);
}

canonical_original_code:
struct bl_value_t *bl_value_cpy(struct bl_value_t *bl_value)
{
    if (bl_value) {
        return bl_value_new(bl_value->uuid_str, bl_value->handle,
                            bl_value->data_size, bl_value->data);
    }
    return ((void *)0);
}

return_type: struct bl_value_t { char uuid_str[37]; unsigned short handle; unsigned long data_size; unsigned char *data; } *


decompiled_code:
void __fastcall struct_free(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func10(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void struct_free(void *bl_struct)
{
    if (bl_struct) {
        free(bl_struct);
        bl_struct = ((void *)0);
    }
}


decompiled_code:
void __fastcall value_free_func(_QWORD *a1)
{
void *v2; // rdi

v2 = (void *)a1[6];
if ( v2 )
free(v2);
struct_free(a1);
}

canonical_decompiled_code:
void __fastcall func11(_QWORD *a1)
{
void *v2; // rdi

v2 = (void *)a1[6];
if ( v2 )
free(v2);
func10(a1);
}

original_code:
static void value_free_func(gpointer data)
{
    if (((bl_value_t *) data)->data)
        free(((bl_value_t *) data)->data);
    free_func(data);
}

canonical_original_code:
static void value_free_func(void *data)
{
    if (((struct bl_value_t *) data)->data)
        free(((struct bl_value_t *) data)->data);
    free_func(data);
}

variable_types:
data
void *

user_defined_types: struct bl_value_t { char uuid_str[37]; unsigned short handle; unsigned long data_size; unsigned char *data; }


decompiled_code:
// attributes: thunk
void __fastcall free_func(void *a1)
{
struct_free(a1);
}

canonical_decompiled_code:
void __fastcall func12(void *a1)
{
func10(a1);
}

original_code:
static void free_func(gpointer data)
{
    if (data)
        free(data);
}

canonical_original_code:
static void free_func(void *data)
{
    if (data)
        free(data);
}


decompiled_code:
void __fastcall bl_value_free(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 6);
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func13(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 6);
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void bl_value_free(bl_value_t *bl_value)
{
    if (bl_value) {
        if (bl_value->data)
            free(bl_value->data);
        free(bl_value);
        bl_value = ((void *)0);
    }
}

canonical_original_code:
void bl_value_free(struct bl_value_t *bl_value)
{
    if (bl_value) {
        if (bl_value->data)
            free(bl_value->data);
        free(bl_value);
        bl_value = ((void *)0);
    }
}


decompiled_code:
__int64 __fastcall list_free(__int64 a1)
{
return g_slist_free_full(a1, free_func);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return g_slist_free_full(a1, free_func);
}

original_code:
void list_free(GSList *list)
{
    g_slist_free_full(list, free_func);
}

canonical_original_code:
void list_free(struct _GSList *list)
{
    g_slist_free_full(list, free_func);
}

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


decompiled_code:
__int64 __fastcall bl_value_list_free(__int64 a1)
{
return g_slist_free_full(a1, value_free_func);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return g_slist_free_full(a1, value_free_func);
}

original_code:
void bl_value_list_free(GSList *list)
{
    g_slist_free_full(list, value_free_func);
}

canonical_original_code:
void bl_value_list_free(struct _GSList *list)
{
    g_slist_free_full(list, value_free_func);
}

user_defined_types: struct _GSList { void *data; struct _GSList *next; }


decompiled_code:
__int64 __fastcall thd2(__int64 a1)
{
get_ble_tree(2u, *(_QWORD *)a1, *(const char **)(a1 + 8));
g_thread_exit(0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
func3(2u, *(_QWORD *)a1, *(const char **)(a1 + 8));
g_thread_exit(0LL);
return 0LL;
}

original_code:
static gpointer thd2(gpointer data)
{
    arg_t *arg = data;
    get_ble_tree(2, arg->mac, arg->file_path);
    g_thread_exit(0);
    return ((void *)0);
}

canonical_original_code:
static void *thd2(void *data)
{
    struct arg_t *arg = data;
    get_ble_tree(2, arg->mac, arg->file_path);
    g_thread_exit(0);
    return ((void *)0);
}

variable_types: struct arg_t { char *mac; char *file_path; } *

return_type: void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
const char *v4; // rax
const char *v5; // rbp
const char *v6; // r12
__int64 v7; // [rsp+8h] [rbp-30h] BYREF
__int64 v8[5]; // [rsp+10h] [rbp-28h] BYREF

puts(
"get_ble_tree Copyright (C) 2014 Hubert Lefevre\n"
"This program comes with ABSOLUTELY NO WARRANTY\n"
"This is free software, and you are welcome to redistribute it\n"
"under certain conditions; See the GNU General Public License\n"
"for more details.\n");
if ( argc == 5 )
{
v4 = argv[2];
v5 = argv[1];
v6 = argv[3];
v7 = 0LL;
v8[0] = (__int64)v4;
v8[1] = (__int64)argv[4];
g_thread_try_new("Thread 2", thd2, v8, &v7);
result = get_ble_tree(1u, (__int64)v5, v6);
}
else
{
usage();
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
const char *v4; // rax
const char *v5; // rbp
const char *v6; // r12
__int64 v7; // [rsp+8h] [rbp-30h] BYREF
__int64 v8[5]; // [rsp+10h] [rbp-28h] BYREF

puts(
"get_ble_tree Copyright (C) 2014 Hubert Lefevre\n"
"This program comes with ABSOLUTELY NO WARRANTY\n"
"This is free software, and you are welcome to redistribute it\n"
"under certain conditions; See the GNU General Public License\n"
"for more details.\n");
if ( argc == 5 )
{
v4 = argv[2];
v5 = argv[1];
v6 = argv[3];
v7 = 0LL;
v8[0] = (__int64)v4;
v8[1] = (__int64)argv[4];
g_thread_try_new("Thread 2", thd2, v8, &v7);
result = func3(1u, (__int64)v5, v6);
}
else
{
func0();
result = 0;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
    printf("get_ble_tree  Copyright (C) 2014 Hubert Lefevre\nThis program com"
           "es with ABSOLUTELY NO WARRANTY\nThis is free software, and you ar"
           "e welcome to redistribute it\nunder certain conditions; See the G"
           "NU General Public License\nfor more details.\n\n");
    if(argc != 5) {
        usage();
        return 0;
    }
    arg_t thd2_arg;
    char *mac = argv[1];
    thd2_arg.mac = argv[2];
    char *file_path = argv[3];
    thd2_arg.file_path = argv[4];
    GError *gerr = ((void *)0);
    g_thread_try_new("Thread 2", thd2, &thd2_arg, &gerr);
    return get_ble_tree(1, mac, file_path);
}

canonical_original_code:
int main(int argc, char **argv)
{
    printf("get_ble_tree  Copyright (C) 2014 Hubert Lefevre\nThis program com"
           "es with ABSOLUTELY NO WARRANTY\nThis is free software, and you ar"
           "e welcome to redistribute it\nunder certain conditions; See the G"
           "NU General Public License\nfor more details.\n\n");
    if(argc != 5) {
        usage();
        return 0;
    }
    struct arg_t thd2_arg;
    char *mac = argv[1];
    thd2_arg.mac = argv[2];
    char *file_path = argv[3];
    thd2_arg.file_path = argv[4];
    struct _GError *gerr = ((void *)0);
    g_thread_try_new("Thread 2", thd2, &thd2_arg, &gerr);
    return get_ble_tree(1, mac, file_path);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct arg_t { char *mac; char *file_path; }

variable_types:
mac
char *

variable_types: struct _GError { unsigned int domain; int code; char *message; } *


usage

decompiled_code:
int usage()
{
return puts(
"Description: This program make a get_ble_tree on two different devices, each get_ble_tree is made within two "
"seperate threads.\n"
"Usage: ble_tree <MAC address 1> <MAC address 2> <file name 1> <file name 2>");
}

canonical_decompiled_code:
int func0()
{
return puts(
"Description: This program make a get_ble_tree on two different devices, each get_ble_tree is made within two "
"seperate threads.\n"
"Usage: ble_tree <MAC address 1> <MAC address 2> <file name 1> <file name 2>");
}

original_code:
static void usage(void)
{
    printf("Description: This program make a get_ble_tree on two different de"
           "vices, each get_ble_tree is made within two seperate threads.\nUs"
           "age: ble_tree <MAC address 1> <MAC address 2> <file name 1> <file"
           " name 2>\n");
}

canonical_original_code:
static void usage()
{
    printf("Description: This program make a get_ble_tree on two different de"
           "vices, each get_ble_tree is made within two seperate threads.\nUs"
           "age: ble_tree <MAC address 1> <MAC address 2> <file name 1> <file"
           " name 2>\n");
}


decompiled_code:
__int64 __fastcall check_errors(unsigned int a1, unsigned int a2)
{
__int64 v3; // rbx
unsigned int v4; // eax
__int64 v5; // rdx
unsigned __int64 v6; // rax

printf("[THD%d]Error code = %d\n", a1, a2);
if ( !a2 )
{
error_cnt = 0;
return 0LL;
}
printf("[THD%d]error count: %d\n", a1, (unsigned int)error_cnt);
if ( error_cnt > 6 )
LABEL_10:
exit(-1);
++error_cnt;
switch ( a2 )
{
case 0xFFFFFFED:
case 0xFFFFFFEE:
case 0xFFFFFFF0:
case 0xFFFFFFF1:
case 0xFFFFFFF7:
case 0xFFFFFFF9:
case 0x16u:
error_cnt = 0;
printf("[THD%d] Going on anyway\n", a1);
return 0LL;
case 0xFFFFFFF4:
case 0xFFFFFFFD:
case 0xFFFFFFFE:
v3 = 264193LL;
while ( 2 )
{
printf("[THD%d] Next try in 10 seconds\n", a1);
sleep(0xAu);
printf("[THD%d] Try to reconnect\n", a1);
v4 = bl_connect(&dev_ctx);
v5 = v4;
v6 = v4 + 18;
if ( (unsigned int)v6 > 0x12 || !_bittest64(&v3, v6) )
{
printf("[THD%d] ERROR <%d>\n", a1, v5);
if ( error_cnt <= 6 )
{
printf("[THD%d] Error count: %d\n", a1, (unsigned int)++error_cnt);
continue;
}
goto LABEL_10;
}
break;
}
printf("[THD%d] Reconnected\n", a1);
return 1LL;
case 0xFFFFFFF5:
return 1LL;
case 0xFFFFFFFB:
while ( 2 )
{
if ( !(unsigned int)bl_init(0LL) )
return 1LL;
printf("[THD%d] error count: %d\n", a1, (unsigned int)error_cnt);
if ( error_cnt <= 6 )
{
++error_cnt;
continue;
}
break;
}
goto LABEL_10;
default:
goto LABEL_10;
}
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2)
{
__int64 v3; // rbx
unsigned int v4; // eax
__int64 v5; // rdx
unsigned __int64 v6; // rax

printf("[THD%d]Error code = %d\n", a1, a2);
if ( !a2 )
{
error_cnt = 0;
return 0LL;
}
printf("[THD%d]error count: %d\n", a1, (unsigned int)error_cnt);
if ( error_cnt > 6 )
LABEL_10:
exit(-1);
++error_cnt;
switch ( a2 )
{
case 0xFFFFFFED:
case 0xFFFFFFEE:
case 0xFFFFFFF0:
case 0xFFFFFFF1:
case 0xFFFFFFF7:
case 0xFFFFFFF9:
case 0x16u:
error_cnt = 0;
printf("[THD%d] Going on anyway\n", a1);
return 0LL;
case 0xFFFFFFF4:
case 0xFFFFFFFD:
case 0xFFFFFFFE:
v3 = 264193LL;
while ( 2 )
{
printf("[THD%d] Next try in 10 seconds\n", a1);
sleep(0xAu);
printf("[THD%d] Try to reconnect\n", a1);
v4 = bl_connect(&dev_ctx);
v5 = v4;
v6 = v4 + 18;
if ( (unsigned int)v6 > 0x12 || !_bittest64(&v3, v6) )
{
printf("[THD%d] ERROR <%d>\n", a1, v5);
if ( error_cnt <= 6 )
{
printf("[THD%d] Error count: %d\n", a1, (unsigned int)++error_cnt);
continue;
}
goto LABEL_10;
}
break;
}
printf("[THD%d] Reconnected\n", a1);
return 1LL;
case 0xFFFFFFF5:
return 1LL;
case 0xFFFFFFFB:
while ( 2 )
{
if ( !(unsigned int)bl_init(0LL) )
return 1LL;
printf("[THD%d] error count: %d\n", a1, (unsigned int)error_cnt);
if ( error_cnt <= 6 )
{
++error_cnt;
continue;
}
break;
}
goto LABEL_10;
default:
goto LABEL_10;
}
}

original_code:
static int check_errors(int thd_nb, int code)
{
    printf("[THD%d]Error code = %d\n", thd_nb, code);
    if (code != 0) {
        printf("[THD%d]error count: %d\n", thd_nb, error_cnt);
        if (error_cnt < 7)
            error_cnt++;
        else
            exit(-1);
        switch(code) {
            case 0:
            case -7:
            case -9:
            case -15:
            case -18:
            case -19:
            case 22:
            case -16:
                error_cnt = 0;
                printf("[THD%d] Going on anyway\n", thd_nb);
                return 0;
            case -5:
                while(bl_init(((void *)0))) {
                    printf("[THD%d] error count: %d\n", thd_nb, error_cnt);
                    if (error_cnt < 7)
                        error_cnt++;
                    else
                        exit(-1);
                }
                return 1;
                break;
            case -12:
            case -2:
            case -3:
                for(;;) {
                    printf("[THD%d] Next try in 10 seconds\n", thd_nb);
                    sleep(10);
                    printf("[THD%d] Try to reconnect\n", thd_nb);
                    int ret = bl_connect(&dev_ctx);
                    if ((ret != 0) &&
                        (ret != -7) &&
                        (ret != -18 )) {
                        printf("[THD%d] ERROR <%d>\n", thd_nb, ret);
                        if (error_cnt < 7) {
                            error_cnt++;
                            printf("[THD%d] Error count: %d\n", thd_nb, error_cnt);
                        } else
                            exit(-1);
                    } else {
                        printf("[THD%d] Reconnected\n", thd_nb);
                        return 1;
                    }
                }
                break;
            case -11:
                return 1;
                break;
            default:
            case -1:
            case -8:
            case -10:
            case -17:
                exit(-1);
        }
    } else {
        error_cnt = 0;
        return 0;
    }
}

variable_types: code int

variable_types: ret int


decompiled_code:
__int64 __fastcall check_gerrors(unsigned int a1, __int64 a2)
{
unsigned int v2; // er12
__int64 result; // rax

if ( a2 )
{
printf("[THD%d] %s", a1, *(const char **)(a2 + 8));
v2 = check_errors(a1, *(_DWORD *)(a2 + 4));
g_error_free(a2);
result = v2;
}
else
{
error_cnt = 0;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2)
{
unsigned int v2; // er12
__int64 result; // rax

if ( a2 )
{
printf("[THD%d] %s", a1, *(const char **)(a2 + 8));
v2 = func1(a1, *(_DWORD *)(a2 + 4));
g_error_free(a2);
result = v2;
}
else
{
error_cnt = 0;
result = 0LL;
}
return result;
}

original_code:
static int check_gerrors(int thd_nb, GError *gerr)
{
    int ret = 0;
    if (gerr) {
        printf("[THD%d] %s", thd_nb, gerr->message);
        ret = check_errors(thd_nb, gerr->code);
        g_error_free(gerr);
        gerr = ((void *)0);
    } else {
        error_cnt = 0;
    }
    return ret;
}

canonical_original_code:
static int check_gerrors(int thd_nb, struct _GError *gerr)
{
    int ret = 0;
    if (gerr) {
        printf("[THD%d] %s", thd_nb, gerr->message);
        ret = check_errors(thd_nb, gerr->code);
        g_error_free(gerr);
        gerr = ((void *)0);
    } else {
        error_cnt = 0;
    }
    return ret;
}

user_defined_types: struct _GError { unsigned int domain; int code; char *message; }


decompiled_code:
size_t __fastcall gatt_attr_data_from_string(const char *a1, __int64 *a2)
{
size_t v2; // r12
__int64 v3; // rax
__int64 i; // rbx
char nptr[2]; // [rsp+Dh] [rbp-2Bh] BYREF
char v7; // [rsp+Fh] [rbp-29h]

v2 = strlen(a1) >> 1;
v3 = g_try_malloc0(v2);
*a2 = v3;
if ( !v3 )
return 0LL;
v7 = 0;
if ( !v2 )
return 0LL;
for ( i = 0LL; i != v2; ++i )
{
*(_WORD *)nptr = *(_WORD *)&a1[2 * i];
*(_BYTE *)(*a2 + i) = strtol(nptr, 0LL, 16);
}
return v2;
}

canonical_decompiled_code:
size_t __fastcall func2(const char *a1, __int64 *a2)
{
size_t v2; // r12
__int64 v3; // rax
__int64 i; // rbx
char nptr[2]; // [rsp+Dh] [rbp-2Bh] BYREF
char v7; // [rsp+Fh] [rbp-29h]

v2 = strlen(a1) >> 1;
v3 = g_try_malloc0(v2);
*a2 = v3;
if ( !v3 )
return 0LL;
v7 = 0;
if ( !v2 )
return 0LL;
for ( i = 0LL; i != v2; ++i )
{
*(_WORD *)nptr = *(_WORD *)&a1[2 * i];
*(_BYTE *)(*a2 + i) = strtol(nptr, 0LL, 16);
}
return v2;
}

original_code:
size_t gatt_attr_data_from_string(const char *str, uint8_t **data)
{
    char tmp[3];
    size_t size, i;
    size = strlen(str) / 2;
    *data = g_try_malloc0(size);
    if (*data == ((void *)0))
        return 0;
    tmp[2] = '\0';
    for (i = 0; i < size; i++) {
        memcpy(tmp, str + (i * 2), 2);
        (*data)[i] = (uint8_t) strtol(tmp, ((void *)0), 16);
    }
    return size;
}

canonical_original_code:
unsigned long gatt_attr_data_from_string(char *str, unsigned char **data)
{
    char tmp[3];
    unsigned long size; unsigned long i;
    size = strlen(str) / 2;
    *data = g_try_malloc0(size);
    if (*data == ((void *)0))
        return 0;
    tmp[2] = '\0';
    for (i = 0; i < size; i++) {
        memcpy(tmp, str + (i * 2), 2);
        (*data)[i] = (unsigned char) strtol(tmp, ((void *)0), 16);
    }
    return size;
}

variable_types:
str
char *

variable_types:
data
unsigned char **

variable_types:
tmp
char [3]

variable_types:
size
unsigned long

variable_types:
i
unsigned long

return_type: unsigned long


main

repo: PapkaOrk/cups

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // ax
int v4; // eax
int v5; // ebp
ssize_t v6; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-1002Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-10028h] BYREF
char s[6]; // [rsp+20h] [rbp-10018h] BYREF
char v11[65554]; // [rsp+26h] [rbp-10012h] BYREF

v3 = _bswap_16_constprop_0(17LL, 3LL, envp);
v4 = socket(17, 3, v3);
if ( v4 < 0 )
{
perror("The raw socket was not created");
}
else
{
v5 = v4;
addr_len = 16;
memset(s, 0, 0xFFFFuLL);
v6 = recvfrom(v5, s, 0xFFFFuLL, 0, &addr, &addr_len);
printf("\nBytes received :: %5d\n", v6);
printf("Source address :: %06x\n", (unsigned int)s);
printf("Source address :: %06x\n", v11);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // ax
int v4; // eax
int v5; // ebp
ssize_t v6; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-1002Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-10028h] BYREF
char s[6]; // [rsp+20h] [rbp-10018h] BYREF
char v11[65554]; // [rsp+26h] [rbp-10012h] BYREF

v3 = func7(17LL, 3LL, envp);
v4 = socket(17, 3, v3);
if ( v4 < 0 )
{
perror("The raw socket was not created");
}
else
{
v5 = v4;
addr_len = 16;
memset(s, 0, 0xFFFFuLL);
v6 = recvfrom(v5, s, 0xFFFFuLL, 0, &addr, &addr_len);
printf("\nBytes received :: %5d\n", v6);
printf("Source address :: %06x\n", (unsigned int)s);
printf("Source address :: %06x\n", v11);
}
return 0;
}

original_code:
int
main ( int argc, char **argv)
{
 int sock, bytes_recieved;
 socklen_t fromlen;
 char buffer[65535];
 struct sockaddr_in from;
 struct packet *packet;
 if ((sock = socket (17, SOCK_RAW, htons (0x0003))) < 0)
 {
  perror ("The raw socket was not created");
  return 0;
 }
 {
  fromlen = sizeof (from);
  memset (buffer, 0, 65535);
  bytes_recieved = recvfrom(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&from, &fromlen);
  printf ("\nBytes received :: %5d\n", bytes_recieved);
  packet = (struct packet *) buffer;
  printf ("Source address :: %06x\n", (unsigned int)packet->eth.h_dest);
  printf ("Source address :: %06x\n", (unsigned int)packet->eth.h_source);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int sock; int bytes_recieved;
 unsigned int fromlen;
 char buffer[65535];
 struct sockaddr_in from;
 struct packet *packet;
 if ((sock = socket (17, SOCK_RAW, htons (0x0003))) < 0)
 {
  perror ("The raw socket was not created");
  return 0;
 }
 {
  fromlen = sizeof (from);
  memset (buffer, 0, 65535);
  bytes_recieved = recvfrom(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&from, &fromlen);
  printf ("\nBytes received :: %5d\n", bytes_recieved);
  packet = (struct packet *) buffer;
  printf ("Source address :: %06x\n", (unsigned int)packet->eth.h_dest);
  printf ("Source address :: %06x\n", (unsigned int)packet->eth.h_source);
 }
 return 0;
}

variable_types: sock int

variable_types:
fromlen
unsigned int

variable_types:
buffer
char [65535]

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: struct packet { struct packet_ethhdr { unsigned char h_dest[6]; unsigned char h_source[6]; unsigned short h_proto; } eth; struct packet_ip { unsigned int ip_length; unsigned int ip_version; unsigned int ip_tos; unsigned short ip_total_length; unsigned short ip_id; unsigned short ip_flags; unsigned int ip_ttl; unsigned int ip_protocol; unsigned short ip_cksum; struct in_addr { unsigned int s_addr; } ip_source; struct in_addr ip_dest; } ip; struct packet_tcp { unsigned int tcp_source_port; unsigned int tcp_dest_port; unsigned int tcp_seqno; unsigned int tcp_ackno; unsigned int tcp_res1; unsigned int tcp_hlen; unsigned int tcp_res2; unsigned int tcp_urg; unsigned int tcp_ack; unsigned int tcp_psh; unsigned int tcp_rst; unsigned int tcp_syn; unsigned int tcp_fin; unsigned int tcp_winsize; unsigned int tcp_cksum; unsigned int tcp_urgent; } tcp; } *

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 packet { struct packet_ethhdr eth; struct packet_ip ip; struct packet_tcp tcp; }

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

user_defined_types: struct packet_ip { unsigned int ip_length; unsigned int ip_version; unsigned int ip_tos; unsigned short ip_total_length; unsigned short ip_id; unsigned short ip_flags; unsigned int ip_ttl; unsigned int ip_protocol; unsigned short ip_cksum; struct in_addr ip_source; struct in_addr ip_dest; }


repo: ParRes/Kernels

decompiled_code:
void __fastcall bail_out(int a1)
{
if ( a1 )
exit(1);
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 )
exit(1);
}

original_code:
void bail_out(int error) {
#pragma omp barrier
  if (error != 0) exit(1);
}

variable_types: error int


original_code:
static inline void sweep_tile(int startm, int endm,
                              int startn, int endn,
                              int n, double * restrict grid)
{
  for (int i=startm; i<endm; i++) {
    for (int j=startn; j<endn; j++) {
      grid[i*n+j] = grid[(i-1)*n+j] + grid[i*n+(j-1)] - grid[(i-1)*n+(j-1)];
    }
  }
}

canonical_original_code:
static inline void sweep_tile(int startm, int endm, int startn, int endn, int n, double *grid)
{
  for (int i = startm; i<endm; i++) {
    for (int j = startn; j<endn; j++) {
      grid[i*n+j] = grid[(i-1)*n+j] + grid[i*n+(j-1)] - grid[(i-1)*n+(j-1)];
    }
  }
}

variable_types: startm int

variable_types: endm int

variable_types: startn int

variable_types: endn int

variable_types: n int

variable_types:
grid
double *

variable_types: i int

variable_types: j int


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

timespec_get(&v1, 1);
return (double)SLODWORD(v1.tv_nsec) * 0.000000001 + (double)SLODWORD(v1.tv_sec);
}

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

timespec_get(&v1, 1);
return (double)SLODWORD(v1.tv_nsec) * 0.000000001 + (double)SLODWORD(v1.tv_sec);
}

original_code:
static inline double prk_wtime(void)
{
    struct timespec ts;
    timespec_get(&ts, 1);
    time_t s = ts.tv_sec;
    long ns = ts.tv_nsec;
    double t = (double)s + 1.e-9 * (double)ns;
    return t;
}

canonical_original_code:
static inline double prk_wtime()
{
    struct timespec ts;
    timespec_get(&ts, 1);
    long s = ts.tv_sec;
    long ns = ts.tv_nsec;
    double t = (double)s + 1.e-9 * (double)ns;
    return t;
}

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

variable_types: s long

variable_types: ns long

variable_types: t double

return_type: double


wtime

decompiled_code:
double wtime()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) * 0.000001 + (double)SLODWORD(v1.tv_sec);
}

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

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) * 0.000001 + (double)SLODWORD(v1.tv_sec);
}

original_code:
double wtime() {
  double time_seconds;
  struct timeval time_data;
  gettimeofday(&time_data,((void *)0));
  time_seconds = (double) time_data.tv_sec;
  time_seconds += (double) time_data.tv_usec * 1.0e-6;
  return time_seconds;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
__int64 __fastcall sweep_tile_2d(int a1, int a2, int a3, int a4, int a5, __int64 a6)
{
__int64 result; // rax
__int64 v10; // rdx
__int64 v11; // r8
int v12; // edi
int v13; // er11
__int64 v14; // rcx

result = a5;
if ( a1 < a2 )
{
v10 = a1;
v11 = 8LL * a5;
v12 = a1 - 1;
v13 = a2 - 1;
result *= v10;
v14 = a6 + 8 * result;
do
{
if ( a3 < a4 )
{
result = a3;
do
{
*(double *)(v14 + 8 * result) = *(double *)(a6 + v11 * v12 + 8 * result)
+ *(double *)(v14 + 8 * result - 8)
- *(double *)(a6 + v11 * v12 + 8 * result - 8);
++result;
}
while ( a4 > (int)result );
}
++v12;
v14 += v11;
}
while ( v12 != v13 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2, int a3, int a4, int a5, __int64 a6)
{
__int64 result; // rax
__int64 v10; // rdx
__int64 v11; // r8
int v12; // edi
int v13; // er11
__int64 v14; // rcx

result = a5;
if ( a1 < a2 )
{
v10 = a1;
v11 = 8LL * a5;
v12 = a1 - 1;
v13 = a2 - 1;
result *= v10;
v14 = a6 + 8 * result;
do
{
if ( a3 < a4 )
{
result = a3;
do
{
*(double *)(v14 + 8 * result) = *(double *)(a6 + v11 * v12 + 8 * result)
+ *(double *)(v14 + 8 * result - 8)
- *(double *)(a6 + v11 * v12 + 8 * result - 8);
++result;
}
while ( a4 > (int)result );
}
++v12;
v14 += v11;
}
while ( v12 != v13 );
}
return result;
}

original_code:
static inline void sweep_tile_2d(int startm, int endm,
                                 int startn, int endn,
                                 int n, double (* restrict grid)[n])
{
  for (int i=startm; i<endm; i++) {
    for (int j=startn; j<endn; j++) {
      grid[i][j] = grid[i-1][j] + grid[i][j-1] - grid[i-1][j-1];
    }
  }
}

canonical_original_code:
static inline void sweep_tile_2d(int startm, int endm, int startn, int endn, int n, double (*grid)[-1])
{
  for (int i = startm; i<endm; i++) {
    for (int j = startn; j<endn; j++) {
      grid[i][j] = grid[i-1][j] + grid[i][j-1] - grid[i-1][j-1];
    }
  }
}

variable_types:
grid
double (*)[-1]


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


functionCall

repo: PatrickHead/ucBasic

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

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

original_code:
int functionCall(int value)
{
 return 0;
}

variable_types: value int


functionPeek

decompiled_code:
// attributes: thunk
__int64 functionPeek()
{
return programGetValue();
}

canonical_decompiled_code:
__int64 func1()
{
return programGetValue();
}

original_code:
int functionPeek(unsigned int address)
{
 return programGetValue(address);
}

variable_types:
address
unsigned int


pushGosubCaller

decompiled_code:
__int64 __fastcall pushGosubCaller(int a1)
{
int v1; // eax
__int64 result; // rax

v1 = gosubStackIndex + 1;
gosubStackIndex = v1;
if ( v1 == 10 )
{
gosubStackIndex = -1;
result = 0xFFFFFFFFLL;
}
else
{
*((_DWORD *)&gosubStack + v1) = a1;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // eax
__int64 result; // rax

v1 = gosubStackIndex + 1;
gosubStackIndex = v1;
if ( v1 == 10 )
{
gosubStackIndex = -1;
result = 0xFFFFFFFFLL;
}
else
{
*((_DWORD *)&gosubStack + v1) = a1;
result = 0LL;
}
return result;
}

original_code:
static int pushGosubCaller(int ln)
{
 ++_gosubStackIndex;
 if (_gosubStackIndex == 10)
 {
  _gosubStackIndex = -1;
  return -1;
 }
 _gosubStack[_gosubStackIndex] = ln;
 return 0;
}

variable_types: ln int


popGosubCaller

decompiled_code:
__int64 popGosubCaller()
{
if ( gosubStackIndex < 0 )
return 0xFFFFFFFFLL;
return *((unsigned int *)&gosubStack + gosubStackIndex--);
}

canonical_decompiled_code:
__int64 func1()
{
if ( gosubStackIndex < 0 )
return 0xFFFFFFFFLL;
return *((unsigned int *)&gosubStack + gosubStackIndex--);
}

original_code:
static int popGosubCaller(void)
{
 if (_gosubStackIndex < 0) return -1;
 --_gosubStackIndex;
 return _gosubStack[_gosubStackIndex + 1];
}

canonical_original_code:
static int popGosubCaller()
{
 if (_gosubStackIndex < 0) return -1;
 --_gosubStackIndex;
 return _gosubStack[_gosubStackIndex + 1];
}


programSetLineNumber

decompiled_code:
void __fastcall programSetLineNumber(int a1)
{
lineNumber = a1;
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
lineNumber = a1;
}

original_code:
void programSetLineNumber(int ln)
{
 _lineNumber = ln;
 return;
}


programGetLineNumber

decompiled_code:
__int64 programGetLineNumber()
{
return (unsigned int)lineNumber;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)lineNumber;
}

original_code:
int programGetLineNumber(void)
{
 return _lineNumber;
}

canonical_original_code:
int programGetLineNumber()
{
 return _lineNumber;
}


programSetValue

decompiled_code:
char *__fastcall programSetValue(__int16 a1, char a2)
{
char *result; // rax

result = program;
program[a1 & 0x7FF] = a2;
return result;
}

canonical_decompiled_code:
char *__fastcall func4(__int16 a1, char a2)
{
char *result; // rax

result = program;
program[a1 & 0x7FF] = a2;
return result;
}

original_code:
void programSetValue(unsigned int address, unsigned char value)
{
 _program[address % 2048] = value;
}

variable_types:
value
unsigned char


programGetValue

decompiled_code:
__int64 __fastcall programGetValue(__int16 a1)
{
return (unsigned int)program[a1 & 0x7FF];
}

canonical_decompiled_code:
__int64 __fastcall func5(__int16 a1)
{
return (unsigned int)program[a1 & 0x7FF];
}

original_code:
int programGetValue(unsigned int address)
{
 return (int)_program[address % 2048];
}


programFindLineNumber

decompiled_code:
char *__fastcall programFindLineNumber(int a1)
{
char *v1; // r12
char *v2; // rax

v1 = program;
if ( program )
{
if ( *program )
{
while ( atoi(v1) != a1 )
{
while ( *v1 != 10 )
++v1;
v2 = v1++;
if ( !v2[1] )
goto LABEL_8;
}
}
else
{
LABEL_8:
v1 = 0LL;
}
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func6(int a1)
{
char *v1; // r12
char *v2; // rax

v1 = program;
if ( program )
{
if ( *program )
{
while ( atoi(v1) != a1 )
{
while ( *v1 != 10 )
++v1;
v2 = v1++;
if ( !v2[1] )
goto LABEL_8;
}
}
else
{
LABEL_8:
v1 = 0LL;
}
}
return v1;
}

original_code:
char *programFindLineNumber(int ln)
{
 char *t = _program;
 int tln;
 if (!t) return ((void *)0);
 while (*t)
 {
  tln = atoi(t);
  if (tln == ln) return t;
  while (*t != '\n') ++t;
  ++t;
 }
 return ((void *)0);
}

variable_types:
t
char *

variable_types: tln int


programGotoLineNumber

decompiled_code:
char *__fastcall programGotoLineNumber(int a1)
{
char *v1; // rax
char *v2; // r12
int v3; // eax

v1 = programFindLineNumber(a1);
v2 = v1;
if ( v1 )
{
v3 = atoi(v1);
programSetLineNumber(v3);
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func7(int a1)
{
char *v1; // rax
char *v2; // r12
int v3; // eax

v1 = func6(a1);
v2 = v1;
if ( v1 )
{
v3 = atoi(v1);
func2(v3);
}
return v2;
}

original_code:
char *programGotoLineNumber(int ln)
{
 char *newLineLocation = ((void *)0);
 newLineLocation = programFindLineNumber(ln);
 if (!newLineLocation) return ((void *)0);
 programSetLineNumber(atoi(newLineLocation));
 return newLineLocation;
}

variable_types:
newLineLocation
char *


programFindNextLineNumber

decompiled_code:
const char *__fastcall programFindNextLineNumber(int a1)
{
const char *v1; // r12
const char *v2; // rax

v1 = program;
if ( program && *program )
{
do
{
if ( atoi(v1) > a1 )
break;
while ( *v1 != 10 )
++v1;
v2 = v1++;
}
while ( v2[1] );
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func8(int a1)
{
const char *v1; // r12
const char *v2; // rax

v1 = program;
if ( program && *program )
{
do
{
if ( atoi(v1) > a1 )
break;
while ( *v1 != 10 )
++v1;
v2 = v1++;
}
while ( v2[1] );
}
return v1;
}

original_code:
char *programFindNextLineNumber(int ln)
{
 char *t = _program;
 int tln;
 if (!t) return ((void *)0);
 while (*t)
 {
  tln = atoi(t);
  if (tln > ln) return t;
  while (*t != '\n') ++t;
  ++t;
 }
 return t;
}


programGosub

decompiled_code:
__int64 __fastcall programGosub(int a1)
{
int v2; // ebp
char *v3; // rax
const char *v4; // rdi
char v5; // al
char v6; // dl
__int64 v7; // r8

v2 = programGetLineNumber();
v3 = programFindLineNumber(v2);
if ( !v3 )
return 0LL;
v4 = v3;
v5 = *v3;
do
{
if ( !v5 )
goto LABEL_5;
v6 = v5;
v5 = *++v4;
}
while ( v6 != 10 );
if ( !v5 )
{
LABEL_5:
if ( !programGotoLineNumber(a1) )
return 0LL;
goto LABEL_6;
}
v2 = atoi(v4);
if ( !programGotoLineNumber(a1) )
return 0LL;
LABEL_6:
if ( (unsigned int)pushGosubCaller(v2) )
return 0LL;
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
int v2; // ebp
char *v3; // rax
const char *v4; // rdi
char v5; // al
char v6; // dl
__int64 v7; // r8

v2 = func3();
v3 = func6(v2);
if ( !v3 )
return 0LL;
v4 = v3;
v5 = *v3;
do
{
if ( !v5 )
goto LABEL_5;
v6 = v5;
v5 = *++v4;
}
while ( v6 != 10 );
if ( !v5 )
{
LABEL_5:
if ( !func7(a1) )
return 0LL;
goto LABEL_6;
}
v2 = atoi(v4);
if ( !func7(a1) )
return 0LL;
LABEL_6:
if ( (unsigned int)func0(v2) )
return 0LL;
return v7;
}

original_code:
char *programGosub(int ln)
{
 char *loc;
 int tmpLN;
 tmpLN = programGetLineNumber();
 loc = programFindLineNumber(tmpLN);
 if (!loc) return ((void *)0);
 while (*loc)
 {
  if (*loc == '\n')
  {
   ++loc;
   break;
  }
  ++loc;
 }
 if (*loc) tmpLN = atoi(loc);
 loc = programGotoLineNumber(ln);
 if (!loc) return ((void *)0);
 if (pushGosubCaller(tmpLN)) return ((void *)0);
 return loc;
}

variable_types:
loc
char *

variable_types: tmpLN int


programReturn

decompiled_code:
char *programReturn()
{
int v0; // eax
char *result; // rax

v0 = popGosubCaller();
if ( v0 < 0 )
result = 0LL;
else
result = programGotoLineNumber(v0);
return result;
}

canonical_decompiled_code:
char *func10()
{
int v0; // eax
char *result; // rax

v0 = func1();
if ( v0 < 0 )
result = 0LL;
else
result = func7(v0);
return result;
}

original_code:
char *programReturn(void)
{
 int tmpLN;
 char *loc;
 tmpLN = popGosubCaller();
 if (tmpLN < 0) return ((void *)0);
 loc = programGotoLineNumber(tmpLN);
 return loc;
}

canonical_original_code:
char *programReturn()
{
 int tmpLN;
 char *loc;
 tmpLN = popGosubCaller();
 if (tmpLN < 0) return ((void *)0);
 loc = programGotoLineNumber(tmpLN);
 return loc;
}


programRun

decompiled_code:
__int64 __fastcall programRun(int a1)
{
char *v1; // rax
__int64 result; // rax
char *v3; // [rsp+8h] [rbp-20h] BYREF
char v4[24]; // [rsp+10h] [rbp-18h] BYREF

v1 = program;
v3 = program;
if ( a1 )
{
v1 = programGotoLineNumber(a1);
v3 = v1;
}
if ( v1 )
{
while ( 1 )
{
tokenClear(v4);
result = parseLine(v4, &v3);
if ( !(_DWORD)result )
break;
if ( !*v3 )
return 1LL;
}
}
else
{
errorSet(40LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
char *v1; // rax
__int64 result; // rax
char *v3; // [rsp+8h] [rbp-20h] BYREF
char v4[24]; // [rsp+10h] [rbp-18h] BYREF

v1 = program;
v3 = program;
if ( a1 )
{
v1 = func7(a1);
v3 = v1;
}
if ( v1 )
{
while ( 1 )
{
tokenClear(v4);
result = parseLine(v4, &v3);
if ( !(_DWORD)result )
break;
if ( !*v3 )
return 1LL;
}
}
else
{
errorSet(40LL);
result = 0LL;
}
return result;
}

original_code:
int programRun(int ln)
{
 char *lp = _program;
 token tok;
 if (ln) lp = programGotoLineNumber(ln);
 if (!lp)
 {
  errorSet(40);
  return 0;
 }
 do
 {
  tokenClear(&tok);
  if (!parseLine(&tok, &lp)) return 0;
 } while (*lp);
 if (!*lp) return 1;
 return 0;
}

canonical_original_code:
int programRun(int ln)
{
 char *lp = _program;
 struct token tok;
 if (ln) lp = programGotoLineNumber(ln);
 if (!lp)
 {
  errorSet(40);
  return 0;
 }
 do
 {
  tokenClear(&tok);
  if (!parseLine(&tok, &lp)) return 0;
 } while (*lp);
 if (!*lp) return 1;
 return 0;
}

variable_types:
lp
char *

variable_types: struct token { enum tokenType { tokTypeComma=0, tokTypeNumber=1, tokTypeEOL=2, tokTypeCharacterString=3, tokTypeColon=4, tokTypeDividedBy=5, tokTypeEquals=6, tokTypeFree=7, tokTypeFunctionCall=8, tokTypeFunctionPeek=9, tokTypeGosub=10, tokTypeGoto=11, tokTypeGreaterThan=12, tokTypeGreaterThanOrEquals=13, tokTypeIf=14, tokTypeInput=15, tokTypeLeftParenthesis=16, tokTypeLessThan=17, tokTypeLessThanOrEquals=18, tokTypeLet=19, tokTypeMinus=20, tokTypeNotEquals=21, tokTypePlus=22, tokTypePoke=23, tokTypePrint=24, tokTypeRemark=25, tokTypeReturn=26, tokTypeRightParenthesis=27, tokTypeSemicolon=28, tokTypeSize=29, tokTypeString=30, tokTypeDoubleQuote=31, tokTypeThen=32, tokTypeTimes=33, tokTypeVariable=34, tokTypeWhiteSpace=35, tokTypeClear=36, tokTypeRun=37, tokTypeList=38 } type; enum tokenValueType { tokValueTypeNone=0, tokValueTypeString=1, tokValueTypeCharacter=2, tokValueTypeNumber=3 } valueType; union { char *s; char c; int n; }; }

user_defined_types: struct token { enum tokenType type; enum tokenValueType valueType; union { char *s; char c; int n; }; }


programPoke

decompiled_code:
char *__fastcall programPoke(__int16 a1, char a2)
{
return programSetValue(a1, a2);
}

canonical_decompiled_code:
char *__fastcall func12(__int16 a1, char a2)
{
return func4(a1, a2);
}

original_code:
void programPoke(unsigned int address, unsigned char value)
{
 programSetValue(address, value);
}


programGetProgram

decompiled_code:
char *programGetProgram()
{
return program;
}

canonical_decompiled_code:
char *func13()
{
return program;
}

original_code:
char *programGetProgram(void)
{
 return _program;
}

canonical_original_code:
char *programGetProgram()
{
 return _program;
}


programGetMode

decompiled_code:
__int64 programGetMode()
{
return (unsigned int)mode;
}

canonical_decompiled_code:
__int64 func14()
{
return (unsigned int)mode;
}

original_code:
programMode programGetMode(void)
{
 return _mode;
}

canonical_original_code:
enum programMode programGetMode()
{
 return _mode;
}

return_type: enum programMode { progModeImmediate=0, progModeStored=1 }


programSetMode

decompiled_code:
void __fastcall programSetMode(int a1)
{
mode = a1;
}

canonical_decompiled_code:
void __fastcall func15(int a1)
{
mode = a1;
}

original_code:
void programSetMode(programMode mode)
{
 _mode = mode;
 return;
}

canonical_original_code:
void programSetMode(enum programMode mode)
{
 _mode = mode;
 return;
}

variable_types: enum programMode { progModeImmediate=0, progModeStored=1 }


programInit

decompiled_code:
char *programInit()
{
char *result; // rax

if ( !firstTime_0 )
{
result = program;
LABEL_3:
*(_QWORD *)result = 0LL;
*((_QWORD *)result + 255) = 0LL;
memset(
(void *)((unsigned __int64)(result + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)result - (((_DWORD)result + 8) & 0xFFFFFFF8) + 2048) >> 3));
programSetLineNumber(0);
gosubStack = 0LL;
qword_460 = 0LL;
gosubStackIndex = -1;
xmmword_450 = 0LL;
variableInit();
programSetMode(1);
return program;
}
result = (char *)malloc(0x800uLL);
program = result;
if ( result )
{
firstTime_0 = 0;
goto LABEL_3;
}
return result;
}

canonical_decompiled_code:
char *func16()
{
char *result; // rax

if ( !firstTime_0 )
{
result = program;
LABEL_3:
*(_QWORD *)result = 0LL;
*((_QWORD *)result + 255) = 0LL;
memset(
(void *)((unsigned __int64)(result + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)result - (((_DWORD)result + 8) & 0xFFFFFFF8) + 2048) >> 3));
func2(0);
gosubStack = 0LL;
qword_460 = 0LL;
gosubStackIndex = -1;
xmmword_450 = 0LL;
variableInit();
func15(1);
return program;
}
result = (char *)malloc(0x800uLL);
program = result;
if ( result )
{
firstTime_0 = 0;
goto LABEL_3;
}
return result;
}

original_code:
char *programInit(void)
{
 static int firstTime = 1;
 if (firstTime)
 {
  _program = (char *)malloc(2048);
  if (!_program) return ((void *)0);
  firstTime = 0;
 }
 memset(_program, 0, 2048);
 programSetLineNumber(0);
 memset(_gosubStack, 0, sizeof(int) * 10);
 _gosubStackIndex = -1;
 variableInit();
 programSetMode(progModeStored);
 return _program;
}

canonical_original_code:
char *programInit()
{
 static int firstTime = 1;
 if (firstTime)
 {
  _program = (char *)malloc(2048);
  if (!_program) return ((void *)0);
  firstTime = 0;
 }
 memset(_program, 0, 2048);
 programSetLineNumber(0);
 memset(_gosubStack, 0, sizeof(int) * 10);
 _gosubStackIndex = -1;
 variableInit();
 programSetMode(progModeStored);
 return _program;
}

variable_types: firstTime int


programGetSize

decompiled_code:
size_t programGetSize()
{
return strlen(program);
}

canonical_decompiled_code:
size_t func17()
{
return strlen(program);
}

original_code:
int programGetSize(void)
{
 return strlen(_program);
}

canonical_original_code:
int programGetSize()
{
 return strlen(_program);
}


programGetFree

decompiled_code:
__int64 programGetFree()
{
return 2048 - (unsigned int)programGetSize();
}

canonical_decompiled_code:
__int64 func18()
{
return 2048 - (unsigned int)func17();
}

original_code:
int programGetFree(void)
{
 int size = programGetSize();
 return (2048 - size);
}

canonical_original_code:
int programGetFree()
{
 int size = programGetSize();
 return (2048 - size);
}

variable_types: size int


matchEOL

decompiled_code:
__int64 __fastcall matchEOL(__int64 a1, _BYTE **a2)
{
if ( **a2 != 10 )
return 0LL;
tokenFill(a1, 2LL, 0LL, 0LL, 0LL);
++*a2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _BYTE **a2)
{
if ( **a2 != 10 )
return 0LL;
tokenFill(a1, 2LL, 0LL, 0LL, 0LL);
++*a2;
return 1LL;
}

original_code:
int matchEOL(token *tok, char **s)
{
 if (**s == '\n')
 {
  tokenFill(tok, tokTypeEOL, tokValueTypeNone, ((void *)0), 0);
  ++*s;
  return 1;
 }
 return 0;
}

canonical_original_code:
int matchEOL(struct token *tok, char **s)
{
 if (**s == '\n')
 {
  tokenFill(tok, tokTypeEOL, tokValueTypeNone, ((void *)0), 0);
  ++*s;
  return 1;
 }
 return 0;
}

variable_types: struct token { enum tokenType { tokTypeComma=0, tokTypeNumber=1, tokTypeEOL=2, tokTypeCharacterString=3, tokTypeColon=4, tokTypeDividedBy=5, tokTypeEquals=6, tokTypeFree=7, tokTypeFunctionCall=8, tokTypeFunctionPeek=9, tokTypeGosub=10, tokTypeGoto=11, tokTypeGreaterThan=12, tokTypeGreaterThanOrEquals=13, tokTypeIf=14, tokTypeInput=15, tokTypeLeftParenthesis=16, tokTypeLessThan=17, tokTypeLessThanOrEquals=18, tokTypeLet=19, tokTypeMinus=20, tokTypeNotEquals=21, tokTypePlus=22, tokTypePoke=23, tokTypePrint=24, tokTypeRemark=25, tokTypeReturn=26, tokTypeRightParenthesis=27, tokTypeSemicolon=28, tokTypeSize=29, tokTypeString=30, tokTypeDoubleQuote=31, tokTypeThen=32, tokTypeTimes=33, tokTypeVariable=34, tokTypeWhiteSpace=35, tokTypeClear=36, tokTypeRun=37, tokTypeList=38 } type; enum tokenValueType { tokValueTypeNone=0, tokValueTypeString=1, tokValueTypeCharacter=2, tokValueTypeNumber=3 } valueType; union { char *s; char c; int n; }; } *

variable_types:
s
char **


matchComma

decompiled_code:
__int64 __fastcall matchComma(__int64 a1, _BYTE **a2)
{
if ( **a2 != 44 )
return 0LL;
tokenFill(a1, 0LL, 0LL, 0LL, 0LL);
++*a2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _BYTE **a2)
{
if ( **a2 != 44 )
return 0LL;
tokenFill(a1, 0LL, 0LL, 0LL, 0LL);
++*a2;
return 1LL;
}

original_code:
int matchComma(token *tok, char **s)
{
 if (**s == ',')
 {
  tokenFill(tok, tokTypeComma, tokValueTypeNone, ((void *)0), 0);
  ++*s;
  return 1;
 }
 return 0;
}

canonical_original_code:
int matchComma(struct token *tok, char **s)
{
 if (**s == ',')
 {
  tokenFill(tok, tokTypeComma, tokValueTypeNone, ((void *)0), 0);
  ++*s;
  return 1;
 }
 return 0;
}

user_defined_types: enum tokenType { tokTypeComma=0, tokTypeNumber=1, tokTypeEOL=2, tokTypeCharacterString=3, tokTypeColon=4, tokTypeDividedBy=5, tokTypeEquals=6, tokTypeFree=7, tokTypeFunctionCall=8, tokTypeFunctionPeek=9, tokTypeGosub=10, tokTypeGoto=11, tokTypeGreaterThan=12, tokTypeGreaterThanOrEquals=13, tokTypeIf=14, tokTypeInput=15, tokTypeLeftParenthesis=16, tokTypeLessThan=17, tokTypeLessThanOrEquals=18, tokTypeLet=19, tokTypeMinus=20, tokTypeNotEquals=21, tokTypePlus=22, tokTypePoke=23, tokTypePrint=24, tokTypeRemark=25, tokTypeReturn=26, tokTypeRightParenthesis=27, tokTypeSemicolon=28, tokTypeSize=29, tokTypeString=30, tokTypeDoubleQuote=31, tokTypeThen=32, tokTypeTimes=33, tokTypeVariable=34, tokTypeWhiteSpace=35, tokTypeClear=36, tokTypeRun=37, tokTypeList=38 }

user_defined_types: enum tokenValueType { tokValueTypeNone=0, tokValueTypeString=1, tokValueTypeCharacter=2, tokValueTypeNumber=3 }


matchNumber

decompiled_code:
__int64 __fastcall matchNumber(__int64 a1, char **a2)
{
char *v2; // r12
const unsigned __int16 *v3; // rdx
char *i; // rbx
__int64 result; // rax

v2 = *a2;
v3 = *_ctype_b_loc();
for ( i = v2; (v3[*i] & 0x800) != 0; ++i )
;
result = 0LL;
if ( i != v2 )
{
tokenFill(a1, 1LL, 3LL, v2, (unsigned int)((_DWORD)i - (_DWORD)v2));
*a2 = i;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char **a2)
{
char *v2; // r12
const unsigned __int16 *v3; // rdx
char *i; // rbx
__int64 result; // rax

v2 = *a2;
v3 = *_ctype_b_loc();
for ( i = v2; (v3[*i] & 0x800) != 0; ++i )
;
result = 0LL;
if ( i != v2 )
{
tokenFill(a1, 1LL, 3LL, v2, (unsigned int)((_DWORD)i - (_DWORD)v2));
*a2 = i;
result = 1LL;
}
return result;
}

original_code:
int matchNumber(token *tok, char **s)
{
 char *t = *s;
 while (((*__ctype_b_loc ())[(int) ((*t))] & (unsigned short int) _ISdigit)) ++t;
 if (t != *s)
 {
  tokenFill(tok, tokTypeNumber, tokValueTypeNumber, *s, t - *s);
  *s += t - *s;
  return 1;
 }
 return 0;
}

canonical_original_code:
int matchNumber(struct token *tok, char **s)
{
 char *t = *s;
 while (((*__ctype_b_loc ())[(int) ((*t))] & (unsigned short) _ISdigit)) ++t;
 if (t != *s)
 {
  tokenFill(tok, tokTypeNumber, tokValueTypeNumber, *s, t - *s);
  *s += t - *s;
  return 1;
 }
 return 0;
}


matchWhiteSpace

decompiled_code:
__int64 __fastcall matchWhiteSpace(__int64 a1, char **a2)
{
char v2; // al
char *v3; // rbx
char v4; // al
__int64 result; // rax

v2 = **a2;
if ( v2 != 32 && v2 != 9 )
return 0LL;
v3 = *a2;
do
{
do
v4 = *++v3;
while ( v4 == 32 );
}
while ( v4 == 9 );
result = 0LL;
if ( *a2 != v3 )
{
tokenFill(a1, 35LL, 0LL, 0LL, 0LL);
*a2 = v3;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char **a2)
{
char v2; // al
char *v3; // rbx
char v4; // al
__int64 result; // rax

v2 = **a2;
if ( v2 != 32 && v2 != 9 )
return 0LL;
v3 = *a2;
do
{
do
v4 = *++v3;
while ( v4 == 32 );
}
while ( v4 == 9 );
result = 0LL;
if ( *a2 != v3 )
{
tokenFill(a1, 35LL, 0LL, 0LL, 0LL);
*a2 = v3;
result = 1LL;
}
return result;
}

original_code:
int matchWhiteSpace(token *tok, char **s)
{
 char *t = *s;
 while ((*t == ' ') || (*t == '\t')) ++t;
 if (t != *s)
 {
  tokenFill(tok, tokTypeWhiteSpace, tokValueTypeNone, ((void *)0), 0);
  *s += t - *s;
  return 1;
 }
 return 0;
}

canonical_original_code:
int matchWhiteSpace(struct token *tok, char **s)
{
 char *t = *s;
 while ((*t == ' ') || (*t == '\t')) ++t;
 if (t != *s)
 {
  tokenFill(tok, tokTypeWhiteSpace, tokValueTypeNone, ((void *)0), 0);
  *s += t - *s;
  return 1;
 }
 return 0;
}


matchString

decompiled_code:
__int64 __fastcall matchString(__int64 a1, _QWORD *a2)
{
__int64 v2; // r8
__int64 v3; // rbp
_BYTE *i; // [rsp+8h] [rbp-30h] BYREF
char v6[40]; // [rsp+10h] [rbp-28h] BYREF

for ( i = (_BYTE *)*a2; !(unsigned int)matchEOL((__int64)v6, &i); ++i )
;
v2 = (unsigned int)i + ~(unsigned int)*a2;
v3 = (int)v2;
tokenFill(a1, 30LL, 1LL, *a2, v2);
*a2 += v3;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _QWORD *a2)
{
__int64 v2; // r8
__int64 v3; // rbp
_BYTE *i; // [rsp+8h] [rbp-30h] BYREF
char v6[40]; // [rsp+10h] [rbp-28h] BYREF

for ( i = (_BYTE *)*a2; !(unsigned int)func0((__int64)v6, &i); ++i )
;
v2 = (unsigned int)i + ~(unsigned int)*a2;
v3 = (int)v2;
tokenFill(a1, 30LL, 1LL, *a2, v2);
*a2 += v3;
return 1LL;
}

original_code:
int matchString(token *tok, char **s)
{
 char *t = *s;
 token testToken;
 int len = 0;
 while (!matchEOL(&testToken, &t)) ++t;
 len = t - *s - 1;
 tokenFill(tok, tokTypeString, tokValueTypeString, *s, len);
 *s += len;
 return 1;
}

canonical_original_code:
int matchString(struct token *tok, char **s)
{
 char *t = *s;
 struct token testToken;
 int len = 0;
 while (!matchEOL(&testToken, &t)) ++t;
 len = t - *s - 1;
 tokenFill(tok, tokTypeString, tokValueTypeString, *s, len);
 *s += len;
 return 1;
}

variable_types: len int


matchDoubleQuote

decompiled_code:
__int64 __fastcall matchDoubleQuote(__int64 a1, _BYTE **a2)
{
if ( **a2 != 34 )
return 0LL;
tokenFill(a1, 31LL, 0LL, 0LL, 0LL);
++*a2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, _BYTE **a2)
{
if ( **a2 != 34 )
return 0LL;
tokenFill(a1, 31LL, 0LL, 0LL, 0LL);
++*a2;
return 1LL;
}

original_code:
int matchDoubleQuote(token *tok, char **s)
{
 if (**s == '"')
 {
  tokenFill(tok, tokTypeDoubleQuote, tokValueTypeNone, ((void *)0), 0);
  *s += 1;
  return 1;
 }
 return 0;
}

canonical_original_code:
int matchDoubleQuote(struct token *tok, char **s)
{
 if (**s == '"')
 {
  tokenFill(tok, tokTypeDoubleQuote, tokValueTypeNone, ((void *)0), 0);
  *s += 1;
  return 1;
 }
 return 0;
}


matchCharacterString

decompiled_code:
__int64 __fastcall matchCharacterString(__int64 a1, char **a2)
{
int v2; // ebp
__int64 v3; // rbx
unsigned int v4; // er12
char v5; // dl
char *v7; // [rsp+8h] [rbp-B0h] BYREF
char v8[16]; // [rsp+10h] [rbp-A8h] BYREF
char v9[152]; // [rsp+20h] [rbp-98h] BYREF

v2 = 0;
v3 = 0LL;
memset(v9, 0, 0x50uLL);
v7 = *a2;
v9[80] = 0;
while ( 1 )
{
v4 = matchDoubleQuote((__int64)v8, &v7);
if ( v4 )
break;
if ( (unsigned int)matchEOL((__int64)v8, &v7) )
return v4;
++v2;
v5 = *v7++;
v9[v3] = v5;
LABEL_4:
++v3;
}
if ( (unsigned int)matchDoubleQuote((__int64)v8, &v7) )
{
v9[v3] = 34;
v2 += 2;
goto LABEL_4;
}
--v7;
v4 = 1;
tokenFill(a1, 3LL, 1LL, v9, (unsigned int)v3);
*a2 += v2;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, char **a2)
{
int v2; // ebp
__int64 v3; // rbx
unsigned int v4; // er12
char v5; // dl
char *v7; // [rsp+8h] [rbp-B0h] BYREF
char v8[16]; // [rsp+10h] [rbp-A8h] BYREF
char v9[152]; // [rsp+20h] [rbp-98h] BYREF

v2 = 0;
v3 = 0LL;
memset(v9, 0, 0x50uLL);
v7 = *a2;
v9[80] = 0;
while ( 1 )
{
v4 = func5((__int64)v8, &v7);
if ( v4 )
break;
if ( (unsigned int)func0((__int64)v8, &v7) )
return v4;
++v2;
v5 = *v7++;
v9[v3] = v5;
LABEL_4:
++v3;
}
if ( (unsigned int)func5((__int64)v8, &v7) )
{
v9[v3] = 34;
v2 += 2;
goto LABEL_4;
}
--v7;
v4 = 1;
tokenFill(a1, 3LL, 1LL, v9, (unsigned int)v3);
*a2 += v2;
return v4;
}

original_code:
int matchCharacterString(token *tok, char **s)
{
 char *t;
 token testToken;
 int i, len;
 char string[81];
 memset(string, 0, 81);
 for (len = i = 0, t = *s;;)
 {
  while (!matchDoubleQuote(&testToken, &t))
  {
   if (matchEOL(&testToken, &t)) return 0;
   string[i] = *t;
   ++t;
   ++len;
   ++i;
  }
  if (!matchDoubleQuote(&testToken, &t))
  {
   --t;
   break;
  }
  string[i] = '"';
  len += 2;
  ++i;
 }
 tokenFill(tok, tokTypeCharacterString, tokValueTypeString, string, i);
 *s += len;
 return 1;
}

canonical_original_code:
int matchCharacterString(struct token *tok, char **s)
{
 char *t;
 struct token testToken;
 int i; int len;
 char string[81];
 memset(string, 0, 81);
 for (len = i = 0, t = *s;;)
 {
  while (!matchDoubleQuote(&testToken, &t))
  {
   if (matchEOL(&testToken, &t)) return 0;
   string[i] = *t;
   ++t;
   ++len;
   ++i;
  }
  if (!matchDoubleQuote(&testToken, &t))
  {
   --t;
   break;
  }
  string[i] = '"';
  len += 2;
  ++i;
 }
 tokenFill(tok, tokTypeCharacterString, tokValueTypeString, string, i);
 *s += len;
 return 1;
}

variable_types: i int

variable_types:
string
char [81]