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

result = (unsigned int)(0x8000 << a1);
if ( a1 >= 8 )
result = 0xFFFFFFFFLL;
return result;
}

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

result = (unsigned int)(0x8000 << a1);
if ( a1 >= 8 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static int get_cartridge_rom_size(int header_value) {
    if(header_value >= 0 && header_value <= 7) {
        return(0x8000 << header_value);
    }
    return -1;
}


repo: tylerschloesser/cgbemu-core

decompiled_code:
__int64 verify_cartridge()
{
int v0; // eax
int v1; // esi
int v2; // er12
int v3; // esi
__int64 v4; // rdi
__int64 v5; // rdx
unsigned __int8 *v6; // rax
__int64 v7; // rcx
__int16 v8; // dx
unsigned __int16 v9; // si
unsigned __int16 v10; // r13
__int64 result; // rax

v0 = get_cartridge_rom_size(*(unsigned __int8 *)(*(_QWORD *)(cartridge + 40) + 328LL));
v1 = v0 + 1023;
v2 = v0;
if ( v0 >= 0 )
v1 = v0;
printf("expected ROM size: %i KiB\n", (unsigned int)(v1 >> 10));
v3 = *(_DWORD *)(cartridge + 60);
if ( v3 == v2 )
{
v4 = *(_QWORD *)(cartridge + 40);
if ( v3 )
{
v5 = (unsigned int)(v3 - 1);
v6 = *(unsigned __int8 **)(cartridge + 40);
LOWORD(v3) = 0;
v7 = v4 + v5 + 1;
do
{
v8 = *v6++;
LOWORD(v3) = v8 + v3;
}
while ( v6 != (unsigned __int8 *)v7 );
}
v9 = v3 - (*(unsigned __int8 *)(v4 + 335) + *(unsigned __int8 *)(v4 + 334));
v10 = __ROL2__(*(_WORD *)(v4 + 334), 8);
if ( v10 != v9 )
{
puts("WARNING: invalid checksum");
printf("\t%X != %X\n", v9, v10);
}
result = 0LL;
}
else
{
puts("The size of the Cartridge is invalid");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // eax
int v1; // esi
int v2; // er12
int v3; // esi
__int64 v4; // rdi
__int64 v5; // rdx
unsigned __int8 *v6; // rax
__int64 v7; // rcx
__int16 v8; // dx
unsigned __int16 v9; // si
unsigned __int16 v10; // r13
__int64 result; // rax

v0 = func1(*(unsigned __int8 *)(*(_QWORD *)(cartridge + 40) + 328LL));
v1 = v0 + 1023;
v2 = v0;
if ( v0 >= 0 )
v1 = v0;
printf("expected ROM size: %i KiB\n", (unsigned int)(v1 >> 10));
v3 = *(_DWORD *)(cartridge + 60);
if ( v3 == v2 )
{
v4 = *(_QWORD *)(cartridge + 40);
if ( v3 )
{
v5 = (unsigned int)(v3 - 1);
v6 = *(unsigned __int8 **)(cartridge + 40);
LOWORD(v3) = 0;
v7 = v4 + v5 + 1;
do
{
v8 = *v6++;
LOWORD(v3) = v8 + v3;
}
while ( v6 != (unsigned __int8 *)v7 );
}
v9 = v3 - (*(unsigned __int8 *)(v4 + 335) + *(unsigned __int8 *)(v4 + 334));
v10 = __ROL2__(*(_WORD *)(v4 + 334), 8);
if ( v10 != v9 )
{
puts("WARNING: invalid checksum");
printf("\t%X != %X\n", v9, v10);
}
result = 0LL;
}
else
{
puts("The size of the Cartridge is invalid");
result = 1LL;
}
return result;
}

original_code:
static int verify_cartridge(void) {
    int expected_cartridge_rom_size =
       get_cartridge_rom_size(cartridge->rom[0x148]);
    printf("expected ROM size: %i KiB\n",
            expected_cartridge_rom_size / 1024);
    if(cartridge->rom_size != expected_cartridge_rom_size) {
        printf("The size of the Cartridge is invalid\n");
        return 1;
    }
    uint32_t sum = 0;
    for(int i = 0; i < cartridge->rom_size; ++i) {
        sum += cartridge->rom[i];
    }
    sum -= ((u16)cartridge->rom[0x14e] + cartridge->rom[0x14f]);
    sum &= 0x0000FFFF;
    u16 checksum = (cartridge->rom[0x014E] << 8) | cartridge->rom[0x014F];
    if(sum != checksum) {
        printf("WARNING: invalid checksum\n");
        printf("\t%X != %X\n", sum, checksum);
    }
    return 0;
}

canonical_original_code:
static int verify_cartridge() {
    int expected_cartridge_rom_size = get_cartridge_rom_size(cartridge->rom[0x148]);
    printf("expected ROM size: %i KiB\n",
            expected_cartridge_rom_size / 1024);
    if(cartridge->rom_size != expected_cartridge_rom_size) {
        printf("The size of the Cartridge is invalid\n");
        return 1;
    }
    unsigned int sum = 0;
    for(int i = 0; i < cartridge->rom_size; ++i) {
        sum += cartridge->rom[i];
    }
    sum -= ((unsigned short)cartridge->rom[0x14e] + cartridge->rom[0x14f]);
    sum &= 0x0000FFFF;
    unsigned short checksum = (cartridge->rom[0x014E] << 8) | cartridge->rom[0x014F];
    if(sum != checksum) {
        printf("WARNING: invalid checksum\n");
        printf("\t%X != %X\n", sum, checksum);
    }
    return 0;
}

variable_types:
sum
unsigned int

variable_types: i int

variable_types:
checksum
unsigned short

return_type: int


decompiled_code:
int print_cartridge_info()
{
__int64 v0; // rcx
__int64 i; // rax
char v3[308]; // [rsp+0h] [rbp-144h]
char v4[16]; // [rsp+134h] [rbp-10h] BYREF

if ( !cartridge )
_assert_fail("cartridge", "cartridge.c", 0xCAu, "print_cartridge_info");
puts("---Cartridge Information---");
v4[15] = 0;
v0 = *(_QWORD *)(cartridge + 40);
for ( i = 308LL; i != 324; ++i )
v3[i] = *(_BYTE *)(v0 + i);
printf("Title: %s\n", v4);
printf("Type: %s\n", (const char *)(cartridge + 4));
printf("RAM: %i KiB\n", *(_DWORD *)(cartridge + 56) >> 10);
printf("ROM: %i KiB\n", *(_DWORD *)(cartridge + 60) >> 10);
return putchar(10);
}

canonical_decompiled_code:
int func4()
{
__int64 v0; // rcx
__int64 i; // rax
char v3[308]; // [rsp+0h] [rbp-144h]
char v4[16]; // [rsp+134h] [rbp-10h] BYREF

if ( !cartridge )
_assert_fail("cartridge", "cartridge.c", 0xCAu, "print_cartridge_info");
puts("---Cartridge Information---");
v4[15] = 0;
v0 = *(_QWORD *)(cartridge + 40);
for ( i = 308LL; i != 324; ++i )
v3[i] = *(_BYTE *)(v0 + i);
printf("Title: %s\n", v4);
printf("Type: %s\n", (const char *)(cartridge + 4));
printf("RAM: %i KiB\n", *(_DWORD *)(cartridge + 56) >> 10);
printf("ROM: %i KiB\n", *(_DWORD *)(cartridge + 60) >> 10);
return putchar(10);
}

original_code:
static void print_cartridge_info(void) {
    ((cartridge) ? (void) (0) : __assert_fail ("cartridge", "cartridge.c", 202, __extension__ __PRETTY_FUNCTION__));
    printf("---Cartridge Information---\n");
    char title[0x10];
    title[0x10 - 1] = '\0';
    for(int i = 0x134; i < 0x144; ++i) {
        title[i - 0x134] = cartridge->rom[i];
    }
    printf("Title: %s\n", title);
    printf("Type: %s\n", cartridge->name);
    printf("RAM: %i KiB\n", cartridge->ram_size / 1024);
    printf("ROM: %i KiB\n", cartridge->rom_size / 1024);
    printf("\n");
}

canonical_original_code:
static void print_cartridge_info() {
    ((cartridge) ? (void) (0) : __assert_fail ("cartridge", "cartridge.c", 202, __extension__ __PRETTY_FUNCTION__));
    printf("---Cartridge Information---\n");
    char title[16];
    title[0x10 - 1] = '\0';
    for(int i = 0x134; i < 0x144; ++i) {
        title[i - 0x134] = cartridge->rom[i];
    }
    printf("Title: %s\n", title);
    printf("Type: %s\n", cartridge->name);
    printf("RAM: %i KiB\n", cartridge->ram_size / 1024);
    printf("ROM: %i KiB\n", cartridge->rom_size / 1024);
    printf("\n");
}

variable_types:
title
char [16]

return_type: void


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

result = cartridge;
if ( !cartridge )
_assert_fail("cartridge != NULL", "cartridge.c", 0x36u, "cartridge_update_mbc");
switch ( *(_DWORD *)(cartridge + 36) )
{
case 0:
return result;
case 1:
*(_QWORD *)(cartridge + 88) = &mbc1_read;
*(_QWORD *)(result + 96) = &mbc1_write;
break;
case 2:
*(_QWORD *)(cartridge + 88) = &mbc2_read;
*(_QWORD *)(result + 96) = &mbc2_write;
break;
case 3:
*(_QWORD *)(cartridge + 88) = &mbc3_read;
*(_QWORD *)(result + 96) = &mbc3_write;
break;
case 4:
*(_QWORD *)(cartridge + 88) = &mbc4_read;
*(_QWORD *)(result + 96) = &mbc4_write;
break;
case 5:
*(_QWORD *)(cartridge + 88) = &mbc5_read;
*(_QWORD *)(result + 96) = &mbc5_write;
break;
default:
fwrite("Unsupported MBC\n", 1uLL, 0x10uLL, stderr);
_assert_fail("false", "cartridge.c", 0x51u, "cartridge_update_mbc");
}
return result;
}

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

result = cartridge;
if ( !cartridge )
_assert_fail("cartridge != NULL", "cartridge.c", 0x36u, "cartridge_update_mbc");
switch ( *(_DWORD *)(cartridge + 36) )
{
case 0:
return result;
case 1:
*(_QWORD *)(cartridge + 88) = &mbc1_read;
*(_QWORD *)(result + 96) = &mbc1_write;
break;
case 2:
*(_QWORD *)(cartridge + 88) = &mbc2_read;
*(_QWORD *)(result + 96) = &mbc2_write;
break;
case 3:
*(_QWORD *)(cartridge + 88) = &mbc3_read;
*(_QWORD *)(result + 96) = &mbc3_write;
break;
case 4:
*(_QWORD *)(cartridge + 88) = &mbc4_read;
*(_QWORD *)(result + 96) = &mbc4_write;
break;
case 5:
*(_QWORD *)(cartridge + 88) = &mbc5_read;
*(_QWORD *)(result + 96) = &mbc5_write;
break;
default:
fwrite("Unsupported MBC\n", 1uLL, 0x10uLL, stderr);
_assert_fail("false", "cartridge.c", 0x51u, "cartridge_update_mbc");
}
return result;
}

original_code:
void cartridge_update_mbc(void) {
    ((cartridge != ((void *)0)) ? (void) (0) : __assert_fail ("cartridge != NULL", "cartridge.c", 54, __extension__ __PRETTY_FUNCTION__));
    switch(cartridge->mbc) {
        case NONE:
            break;
        case MBC1:
            cartridge->read = &mbc1_read;
            cartridge->write = &mbc1_write;
            break;
        case MBC2:
            cartridge->read = &mbc2_read;
            cartridge->write = &mbc2_write;
            break;
        case MBC3:
            cartridge->read = &mbc3_read;
            cartridge->write = &mbc3_write;
            break;
        case MBC4:
            cartridge->read = &mbc4_read;
            cartridge->write = &mbc4_write;
            break;
        case MBC5:
            cartridge->read = &mbc5_read;
            cartridge->write = &mbc5_write;
            break;
        default:
            fprintf(stderr, "Unsupported MBC\n");
            ((0) ? (void) (0) : __assert_fail ("false", "cartridge.c", 81, __extension__ __PRETTY_FUNCTION__));
            break;
    }
}

canonical_original_code:
void cartridge_update_mbc() {
    ((cartridge != ((void *)0)) ? (void) (0) : __assert_fail ("cartridge != NULL", "cartridge.c", 54, __extension__ __PRETTY_FUNCTION__));
    switch(cartridge->mbc) {
        case NONE:
            break;
        case MBC1:
            cartridge->read = &mbc1_read;
            cartridge->write = &mbc1_write;
            break;
        case MBC2:
            cartridge->read = &mbc2_read;
            cartridge->write = &mbc2_write;
            break;
        case MBC3:
            cartridge->read = &mbc3_read;
            cartridge->write = &mbc3_write;
            break;
        case MBC4:
            cartridge->read = &mbc4_read;
            cartridge->write = &mbc4_write;
            break;
        case MBC5:
            cartridge->read = &mbc5_read;
            cartridge->write = &mbc5_write;
            break;
        default:
            fprintf(stderr, "Unsupported MBC\n");
            ((0) ? (void) (0) : __assert_fail ("false", "cartridge.c", 81, __extension__ __PRETTY_FUNCTION__));
            break;
    }
}


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

if ( !a1 )
_assert_fail("cartridge_type != NULL", "cartridge.c", 0x5Au, "get_has_battery");
switch ( *(_DWORD *)(a1 + 40) )
{
case 3:
case 5:
case 7:
case 0xA:
case 0xB:
case 0xC:
case 0xF:
case 0x12:
case 0x15:
case 0x18:
case 0x1C:
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

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

if ( !a1 )
_assert_fail("cartridge_type != NULL", "cartridge.c", 0x5Au, "get_has_battery");
switch ( *(_DWORD *)(a1 + 40) )
{
case 3:
case 5:
case 7:
case 0xA:
case 0xB:
case 0xC:
case 0xF:
case 0x12:
case 0x15:
case 0x18:
case 0x1C:
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
_Bool get_has_battery(CartridgeType* cartridge_type) {
    ((cartridge_type != ((void *)0)) ? (void) (0) : __assert_fail ("cartridge_type != NULL", "cartridge.c", 90, __extension__ __PRETTY_FUNCTION__));
    switch(cartridge_type->id) {
        case ID_MBC1_RAM_BATTERY:
        case ID_MBC2_BATTERY:
        case ID_ROM_RAM_BATTERY:
        case ID_MMM01_RAM_BATTERY:
        case ID_MBC3_TIMER_BATTERY:
        case ID_MBC3_TIMER_RAM_BATTERY:
        case ID_MBC3_RAM_BATTERY:
        case ID_MBC4_RAM_BATTERY:
        case ID_MBC5_RAM_BATTERY:
        case ID_MBC5_RUMBLE_RAM_BATTERY:
        case ID_HUC1_RAM_BATTERY:
            return 1;
    }
    return 0;
}

canonical_original_code:
_Bool get_has_battery(struct CartridgeType *cartridge_type) {
    ((cartridge_type != ((void *)0)) ? (void) (0) : __assert_fail ("cartridge_type != NULL", "cartridge.c", 90, __extension__ __PRETTY_FUNCTION__));
    switch(cartridge_type->id) {
        case ID_MBC1_RAM_BATTERY:
        case ID_MBC2_BATTERY:
        case ID_ROM_RAM_BATTERY:
        case ID_MMM01_RAM_BATTERY:
        case ID_MBC3_TIMER_BATTERY:
        case ID_MBC3_TIMER_RAM_BATTERY:
        case ID_MBC3_RAM_BATTERY:
        case ID_MBC4_RAM_BATTERY:
        case ID_MBC5_RAM_BATTERY:
        case ID_MBC5_RUMBLE_RAM_BATTERY:
        case ID_HUC1_RAM_BATTERY:
            return 1;
    }
    return 0;
}

variable_types: struct CartridgeType { int header_value; enum MemoryBankController { NONE=0, MBC1=1, MBC2=2, MBC3=3, MBC4=4, MBC5=5, UNSUPPORTED=6 } mbc; char name[32]; int id; } *

user_defined_types: struct CartridgeType { int header_value; enum MemoryBankController mbc; char name[32]; int id; }


decompiled_code:
char *__fastcall get_cartridge_type(int a1)
{
_DWORD *v1; // rdx
int i; // eax

v1 = &cartridge_types;
for ( i = 0; i != 29; ++i )
{
if ( *v1 == a1 )
return (char *)&cartridge_types + 44 * i;
v1 += 11;
}
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func7(int a1)
{
_DWORD *v1; // rdx
int i; // eax

v1 = &cartridge_types;
for ( i = 0; i != 29; ++i )
{
if ( *v1 == a1 )
return (char *)&cartridge_types + 44 * i;
v1 += 11;
}
return 0LL;
}

original_code:
CartridgeType* get_cartridge_type(int header_value) {
    for(int i = 0; i < (sizeof(cartridge_types) / sizeof(CartridgeType)); ++i) {
        if(cartridge_types[i].header_value == header_value) {
            return &cartridge_types[i];
        }
    }
    return ((void *)0);
}

canonical_original_code:
struct CartridgeType *get_cartridge_type(int header_value) {
    for(int i = 0; i < (sizeof(cartridge_types) / sizeof(CartridgeType)); ++i) {
        if(cartridge_types[i].header_value == header_value) {
            return &cartridge_types[i];
        }
    }
    return ((void *)0);
}

return_type: struct CartridgeType { int header_value; enum MemoryBankController { NONE=0, MBC1=1, MBC2=2, MBC3=3, MBC4=4, MBC5=5, UNSUPPORTED=6 } mbc; char name[32]; int id; } *


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

result = *(_QWORD *)(cartridge + 40) + (*(unsigned __int16 *)(cartridge + 80) << 14);
*(_QWORD *)(cartridge + 64) = result;
return result;
}

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

result = *(_QWORD *)(cartridge + 40) + (*(unsigned __int16 *)(cartridge + 80) << 14);
*(_QWORD *)(cartridge + 64) = result;
return result;
}

original_code:
void cartridge_update_selected_rom(void) {
    cartridge->selected_rom =
        &cartridge->rom[cartridge->selected_rom_bank * 0x4000];
}

canonical_original_code:
void cartridge_update_selected_rom() {
    cartridge->selected_rom =
        &cartridge->rom[cartridge->selected_rom_bank * 0x4000];
}


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

result = *(_QWORD *)(cartridge + 48) + (*(unsigned __int16 *)(cartridge + 82) << 13);
*(_QWORD *)(cartridge + 72) = result;
return result;
}

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

result = *(_QWORD *)(cartridge + 48) + (*(unsigned __int16 *)(cartridge + 82) << 13);
*(_QWORD *)(cartridge + 72) = result;
return result;
}

original_code:
void cartridge_update_selected_ram(void) {
    cartridge->selected_ram =
        &cartridge->ram[cartridge->selected_ram_bank * 0x2000];
}

canonical_original_code:
void cartridge_update_selected_ram() {
    cartridge->selected_ram =
        &cartridge->ram[cartridge->selected_ram_bank * 0x2000];
}


decompiled_code:
__int64 __fastcall initialize_cartridge(const char *a1)
{
__int64 v1; // rbx
__int64 v2; // r12
unsigned int v3; // eax
bool v4; // zf
char *v5; // rax
__int64 v6; // r12
__m128i v7; // xmm1
__int64 v8; // rax
void *v10; // rax

if ( !a1 )
_assert_fail("cartridge_filepath", "cartridge.c", 0x9Au, "initialize_cartridge");
if ( cartridge )
_assert_fail("cartridge == NULL", "cartridge.c", 0x9Bu, "initialize_cartridge");
cartridge = (__int64)calloc(0x70uLL, 1uLL);
if ( !cartridge )
_assert_fail("cartridge", "cartridge.c", 0x9Eu, "initialize_cartridge");
if ( (unsigned int)read_cartridge(a1) )
return 1LL;
v1 = cartridge;
v2 = *(_QWORD *)(cartridge + 40);
v3 = get_cartridge_ram_size(*(unsigned __int8 *)(v2 + 329));
v4 = *(_QWORD *)(v1 + 48) == 0LL;
*(_DWORD *)(v1 + 56) = v3;
if ( !v4 )
_assert_fail("cartridge->ram == NULL", "cartridge.c", 0xA8u, "initialize_cartridge");
if ( v3 )
{
v10 = malloc(v3);
*(_QWORD *)(v1 + 48) = v10;
if ( !v10 )
_assert_fail("cartridge->ram != NULL", "cartridge.c", 0xACu, "initialize_cartridge");
}
v5 = get_cartridge_type(*(unsigned __int8 *)(v2 + 327));
v6 = (__int64)v5;
if ( !v5 )
_assert_fail("cartridge_type != NULL", "cartridge.c", 0xB4u, "initialize_cartridge");
*(_DWORD *)v1 = *((_DWORD *)v5 + 10);
*(__m128i *)(v1 + 4) = _mm_loadu_si128((const __m128i *)(v5 + 8));
v7 = _mm_loadu_si128((const __m128i *)(v5 + 24));
v8 = cartridge;
*(__m128i *)(v1 + 20) = v7;
*(_DWORD *)(v8 + 36) = *(_DWORD *)(v6 + 4);
cartridge_update_mbc();
*(_BYTE *)(cartridge + 106) = get_has_battery(v6);
cartridge_update_selected_rom();
cartridge_update_selected_ram();
if ( (unsigned int)verify_cartridge() )
return 1LL;
print_cartridge_info();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1)
{
__int64 v1; // rbx
__int64 v2; // r12
unsigned int v3; // eax
bool v4; // zf
char *v5; // rax
__int64 v6; // r12
__m128i v7; // xmm1
__int64 v8; // rax
void *v10; // rax

if ( !a1 )
_assert_fail("cartridge_filepath", "cartridge.c", 0x9Au, "initialize_cartridge");
if ( cartridge )
_assert_fail("cartridge == NULL", "cartridge.c", 0x9Bu, "initialize_cartridge");
cartridge = (__int64)calloc(0x70uLL, 1uLL);
if ( !cartridge )
_assert_fail("cartridge", "cartridge.c", 0x9Eu, "initialize_cartridge");
if ( (unsigned int)func2(a1) )
return 1LL;
v1 = cartridge;
v2 = *(_QWORD *)(cartridge + 40);
v3 = func0(*(unsigned __int8 *)(v2 + 329));
v4 = *(_QWORD *)(v1 + 48) == 0LL;
*(_DWORD *)(v1 + 56) = v3;
if ( !v4 )
_assert_fail("cartridge->ram == NULL", "cartridge.c", 0xA8u, "initialize_cartridge");
if ( v3 )
{
v10 = malloc(v3);
*(_QWORD *)(v1 + 48) = v10;
if ( !v10 )
_assert_fail("cartridge->ram != NULL", "cartridge.c", 0xACu, "initialize_cartridge");
}
v5 = func7(*(unsigned __int8 *)(v2 + 327));
v6 = (__int64)v5;
if ( !v5 )
_assert_fail("cartridge_type != NULL", "cartridge.c", 0xB4u, "initialize_cartridge");
*(_DWORD *)v1 = *((_DWORD *)v5 + 10);
*(__m128i *)(v1 + 4) = _mm_loadu_si128((const __m128i *)(v5 + 8));
v7 = _mm_loadu_si128((const __m128i *)(v5 + 24));
v8 = cartridge;
*(__m128i *)(v1 + 20) = v7;
*(_DWORD *)(v8 + 36) = *(_DWORD *)(v6 + 4);
func5();
*(_BYTE *)(cartridge + 106) = func6(v6);
func8();
func9();
if ( (unsigned int)func3() )
return 1LL;
func4();
return 0LL;
}

original_code:
int initialize_cartridge(const char* cartridge_filepath) {
    ((cartridge_filepath) ? (void) (0) : __assert_fail ("cartridge_filepath", "cartridge.c", 154, __extension__ __PRETTY_FUNCTION__));
    ((cartridge == ((void *)0)) ? (void) (0) : __assert_fail ("cartridge == NULL", "cartridge.c", 155, __extension__ __PRETTY_FUNCTION__));
    cartridge = (Cartridge*)calloc(sizeof(Cartridge), 1);
    ((cartridge) ? (void) (0) : __assert_fail ("cartridge", "cartridge.c", 158, __extension__ __PRETTY_FUNCTION__));
    if(read_cartridge(cartridge_filepath) != 0) {
        return 1;
    }
    cartridge->ram_size = get_cartridge_ram_size(cartridge->rom[0x0149]);
    ((cartridge->ram_size >= 0) ? (void) (0) : __assert_fail ("cartridge->ram_size >= 0", "cartridge.c", 167, __extension__ __PRETTY_FUNCTION__));
    ((cartridge->ram == ((void *)0)) ? (void) (0) : __assert_fail ("cartridge->ram == NULL", "cartridge.c", 168, __extension__ __PRETTY_FUNCTION__));
    if(cartridge->ram_size > 0) {
        cartridge->ram = (uint8_t*)malloc(cartridge->ram_size);
        ((cartridge->ram != ((void *)0)) ? (void) (0) : __assert_fail ("cartridge->ram != NULL", "cartridge.c", 172, __extension__ __PRETTY_FUNCTION__));
    } else {
        cartridge->ram = ((void *)0);
    }
    CartridgeType* cartridge_type = get_cartridge_type(cartridge->rom[0x0147]);
    ((cartridge_type != ((void *)0)) ? (void) (0) : __assert_fail ("cartridge_type != NULL", "cartridge.c", 180, __extension__ __PRETTY_FUNCTION__));
    cartridge->id = cartridge_type->id;
    memcpy(cartridge->name, cartridge_type->name, 32);
    cartridge->mbc = cartridge_type->mbc;
    cartridge_update_mbc();
    cartridge->has_battery = get_has_battery(cartridge_type);
    cartridge_update_selected_rom();
    cartridge_update_selected_ram();
    if(verify_cartridge() != 0) {
        return 1;
    }
    print_cartridge_info();
    return 0;
}

canonical_original_code:
int initialize_cartridge(char *cartridge_filepath) {
    ((cartridge_filepath) ? (void) (0) : __assert_fail ("cartridge_filepath", "cartridge.c", 154, __extension__ __PRETTY_FUNCTION__));
    ((cartridge == ((void *)0)) ? (void) (0) : __assert_fail ("cartridge == NULL", "cartridge.c", 155, __extension__ __PRETTY_FUNCTION__));
    cartridge = (struct Cartridge *)calloc(sizeof(Cartridge), 1);
    ((cartridge) ? (void) (0) : __assert_fail ("cartridge", "cartridge.c", 158, __extension__ __PRETTY_FUNCTION__));
    if(read_cartridge(cartridge_filepath) != 0) {
        return 1;
    }
    cartridge->ram_size = get_cartridge_ram_size(cartridge->rom[0x0149]);
    ((cartridge->ram_size >= 0) ? (void) (0) : __assert_fail ("cartridge->ram_size >= 0", "cartridge.c", 167, __extension__ __PRETTY_FUNCTION__));
    ((cartridge->ram == ((void *)0)) ? (void) (0) : __assert_fail ("cartridge->ram == NULL", "cartridge.c", 168, __extension__ __PRETTY_FUNCTION__));
    if(cartridge->ram_size > 0) {
        cartridge->ram = (unsigned char *)malloc(cartridge->ram_size);
        ((cartridge->ram != ((void *)0)) ? (void) (0) : __assert_fail ("cartridge->ram != NULL", "cartridge.c", 172, __extension__ __PRETTY_FUNCTION__));
    } else {
        cartridge->ram = ((void *)0);
    }
    struct CartridgeType *cartridge_type = get_cartridge_type(cartridge->rom[0x0147]);
    ((cartridge_type != ((void *)0)) ? (void) (0) : __assert_fail ("cartridge_type != NULL", "cartridge.c", 180, __extension__ __PRETTY_FUNCTION__));
    cartridge->id = cartridge_type->id;
    memcpy(cartridge->name, cartridge_type->name, 32);
    cartridge->mbc = cartridge_type->mbc;
    cartridge_update_mbc();
    cartridge->has_battery = get_has_battery(cartridge_type);
    cartridge_update_selected_rom();
    cartridge_update_selected_ram();
    if(verify_cartridge() != 0) {
        return 1;
    }
    print_cartridge_info();
    return 0;
}

user_defined_types: struct Cartridge { enum CartridgeId id; char name[32]; enum MemoryBankController mbc; unsigned char *rom; unsigned char *ram; unsigned int ram_size; unsigned int rom_size; unsigned char *selected_rom; unsigned char *selected_ram; unsigned short selected_rom_bank; unsigned short selected_ram_bank; unsigned char (*read)(unsigned short); void (*write)(unsigned short, unsigned char); _Bool ram_enabled; unsigned char banking_mode; _Bool has_battery; unsigned char rtc_register; }

user_defined_types: enum MemoryBankController { NONE=0, MBC1=1, MBC2=2, MBC3=3, MBC4=4, MBC5=5, UNSUPPORTED=6 }

user_defined_types: enum CartridgeId { ID_ROM_ONLY=0, ID_MBC1=1, ID_MBC1_RAM=2, ID_MBC1_RAM_BATTERY=3, ID_MBC2=4, ID_MBC2_BATTERY=5, ID_ROM_RAM=6, ID_ROM_RAM_BATTERY=7, ID_MMM01=8, ID_MMM01_RAM=9, ID_MMM01_RAM_BATTERY=10, ID_MBC3_TIMER_BATTERY=11, ID_MBC3_TIMER_RAM_BATTERY=12, ID_MBC3=13, ID_MBC3_RAM=14, ID_MBC3_RAM_BATTERY=15, ID_MBC4=16, ID_MBC4_RAM=17, ID_MBC4_RAM_BATTERY=18, ID_MBC5=19, ID_MBC5_RAM=20, ID_MBC5_RAM_BATTERY=21, ID_MBC5_RUMBLE=22, ID_MBC5_RUMBLE_RAM=23, ID_MBC5_RUMBLE_RAM_BATTERY=24, ID_POCKET_CAMERA=25, ID_BANDAI_TAMA5=26, ID_HUC3=27, ID_HUC1_RAM_BATTERY=28 }


decompiled_code:
__int64 get_save_state_size()
{
return (unsigned int)(*((_DWORD *)cartridge + 14) + 52184);
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)(*((_DWORD *)cartridge + 14) + 52184);
}

original_code:
static int get_save_state_size() {
    return(sizeof(Cpu) + sizeof(Cartridge) + cartridge->ram_size + sizeof(GameboyColor));
}


swap

decompiled_code:
__int64 __fastcall swap(_BYTE *a1, _BYTE *a2)
{
__int64 result; // rax

result = (unsigned __int8)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, _BYTE *a2)
{
__int64 result; // rax

result = (unsigned __int8)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

original_code:
void swap(uint8_t* a, uint8_t* b) {
    uint8_t c = *a;
    *a = *b;
    *b = c;
}

canonical_original_code:
void swap(unsigned char *a, unsigned char *b) {
    unsigned char c = *a;
    *a = *b;
    *b = c;
}

variable_types:
a
unsigned char *

variable_types:
b
unsigned char *

variable_types:
c
unsigned char


decompiled_code:
char *enable_bios()
{
char *result; // rax
__int64 v1; // rdi
__int64 v2; // rbx
char *v3; // rsi
_BYTE *v4; // rdi
__int64 i; // rbx
_BYTE *v6; // rsi
_BYTE *v7; // rdi

result = (char *)gb;
if ( !gb )
_assert_fail("gb", "gameboy.c", 0x22u, "enable_bios");
if ( !cartridge )
_assert_fail("cartridge", "gameboy.c", 0x24u, "enable_bios");
v1 = *((_QWORD *)cartridge + 5);
if ( !v1 )
_assert_fail("cartridge->rom", "gameboy.c", 0x25u, "enable_bios");
if ( *((_BYTE *)gb + 52018) )
{
v2 = 0LL;
while ( 1 )
{
v3 = &result[v2 + 49312];
v4 = (_BYTE *)(v2 + v1);
++v2;
swap(v4, v3);
if ( v2 == 256 )
break;
result = (char *)gb;
v1 = *((_QWORD *)cartridge + 5);
}
for ( i = 49824LL; i != 51616; ++i )
{
v6 = (char *)gb + i;
v7 = (_BYTE *)(*((_QWORD *)cartridge + 5) + i - 49312);
result = (char *)swap(v7, v6);
}
}
return result;
}

canonical_decompiled_code:
char *func3()
{
char *result; // rax
__int64 v1; // rdi
__int64 v2; // rbx
char *v3; // rsi
_BYTE *v4; // rdi
__int64 i; // rbx
_BYTE *v6; // rsi
_BYTE *v7; // rdi

result = (char *)gb;
if ( !gb )
_assert_fail("gb", "gameboy.c", 0x22u, "enable_bios");
if ( !cartridge )
_assert_fail("cartridge", "gameboy.c", 0x24u, "enable_bios");
v1 = *((_QWORD *)cartridge + 5);
if ( !v1 )
_assert_fail("cartridge->rom", "gameboy.c", 0x25u, "enable_bios");
if ( *((_BYTE *)gb + 52018) )
{
v2 = 0LL;
while ( 1 )
{
v3 = &result[v2 + 49312];
v4 = (_BYTE *)(v2 + v1);
++v2;
func2(v4, v3);
if ( v2 == 256 )
break;
result = (char *)gb;
v1 = *((_QWORD *)cartridge + 5);
}
for ( i = 49824LL; i != 51616; ++i )
{
v6 = (char *)gb + i;
v7 = (_BYTE *)(*((_QWORD *)cartridge + 5) + i - 49312);
result = (char *)func2(v7, v6);
}
}
return result;
}

original_code:
static void enable_bios()
{
    ((gb) ? (void) (0) : __assert_fail ("gb", "gameboy.c", 34, __extension__ __PRETTY_FUNCTION__));
    ((gb->bios) ? (void) (0) : __assert_fail ("gb->bios", "gameboy.c", 35, __extension__ __PRETTY_FUNCTION__));
    ((cartridge) ? (void) (0) : __assert_fail ("cartridge", "gameboy.c", 36, __extension__ __PRETTY_FUNCTION__));
    ((cartridge->rom) ? (void) (0) : __assert_fail ("cartridge->rom", "gameboy.c", 37, __extension__ __PRETTY_FUNCTION__));
    if(gb->use_bios) {
        for(int i = 0; i < 0x100; ++i) {
            swap(&cartridge->rom[i], &gb->bios[i]);
        }
        for(int i = 0x200; i < 0x900; ++i) {
            swap(&cartridge->rom[i], &gb->bios[i]);
        }
    }
}


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

result = (char *)gb;
if ( !gb )
_assert_fail("gb", "gameboy.c", 0x32u, "gameboy_disable_bios");
if ( *((_BYTE *)gb + 52018) )
result = enable_bios();
return result;
}

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

result = (char *)gb;
if ( !gb )
_assert_fail("gb", "gameboy.c", 0x32u, "gameboy_disable_bios");
if ( *((_BYTE *)gb + 52018) )
result = func3();
return result;
}

original_code:
void gameboy_disable_bios() {
    ((gb) ? (void) (0) : __assert_fail ("gb", "gameboy.c", 50, __extension__ __PRETTY_FUNCTION__));
    if(gb->use_bios)
        enable_bios();
}


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

result = (char *)gb + 4096 * *((unsigned __int8 *)gb + 51999);
*((_QWORD *)gb + 6453) = result;
return result;
}

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

result = (char *)gb + 4096 * *((unsigned __int8 *)gb + 51999);
*((_QWORD *)gb + 6453) = result;
return result;
}

original_code:
void gameboy_update_selected_ram(void)
{
    u32 ram_bank = gb->hw_registers[SVBK];
    gb->selected_ram = &gb->ram[ram_bank * 0x1000];
}

canonical_original_code:
void gameboy_update_selected_ram()
{
    unsigned int ram_bank = gb->hw_registers[SVBK];
    gb->selected_ram = &gb->ram[ram_bank * 0x1000];
}


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

result = (char *)gb + 0x2000 * *((unsigned __int8 *)gb + 51966) + 0x8000;
*((_QWORD *)gb + 6452) = result;
return result;
}

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

result = (char *)gb + 0x2000 * *((unsigned __int8 *)gb + 51966) + 0x8000;
*((_QWORD *)gb + 6452) = result;
return result;
}

original_code:
void gameboy_update_selected_vram(void)
{
    u32 vram_bank = gb->hw_registers[VBK];
    gb->selected_vram = &gb->vram[vram_bank * 0x2000];
}

canonical_original_code:
void gameboy_update_selected_vram()
{
    unsigned int vram_bank = gb->hw_registers[VBK];
    gb->selected_vram = &gb->vram[vram_bank * 0x2000];
}


decompiled_code:
__int64 __fastcall initialize_gameboy(unsigned __int8 a1, char *a2)
{
char *v2; // rax
__m128i v3; // xmm0
__m128i v4; // xmm0
__m128i v5; // xmm0
__m128i v6; // xmm0
__int64 result; // rax
int v8; // er8

fprintf(stderr, "initialize_gameboy(use_bios=%i, bios_filepath=%s)\n", a1, a2);
if ( gameboy_initialized )
_assert_fail("gameboy_initialized == false", "gameboy.c", 0x5Eu, "initialize_gameboy");
v2 = (char *)calloc(0xCB38uLL, 1uLL);
gb = v2;
if ( !v2 )
_assert_fail("gb", "gameboy.c", 0x62u, "initialize_gameboy");
if ( !a1 )
{
v3 = _mm_load_si128((const __m128i *)&LC11);
*(_QWORD *)(v2 + 51903) = 0x87C1F38000LL;
*(__m128i *)(v2 + 51887) = v3;
v4 = _mm_load_si128((const __m128i *)&LC12);
*(_QWORD *)(v2 + 51911) = 0LL;
*(__m128i *)(v2 + 51935) = v4;
v5 = _mm_load_si128((const __m128i *)&LC13);
*(_QWORD *)(v2 + 51967) = 0xFFFFFFFFFF00LL;
*(__m128i *)(v2 + 51951) = v5;
v6 = _mm_load_si128((const __m128i *)&LC14);
*(_QWORD *)(v2 + 51919) = 0x80F37700000000LL;
*(_QWORD *)(v2 + 51927) = 0LL;
*(_QWORD *)(v2 + 51975) = 0LL;
*(_QWORD *)(v2 + 51999) = 1LL;
*(_QWORD *)(v2 + 52007) = 0LL;
v2[51967] = 17;
*(__m128i *)(v2 + 51983) = v6;
LABEL_5:
v2[52018] = a1;
gameboy_update_selected_ram();
gameboy_update_selected_vram();
gameboy_initialized = 1;
return 0LL;
}
v8 = read_bios(a2);
result = 1LL;
if ( !v8 )
{
*((_BYTE *)gb + 51967) = 0;
enable_bios();
v2 = (char *)gb;
goto LABEL_5;
}
return result;
}

original_code:
int initialize_gameboy(_Bool use_bios, const char* bios_filepath)
{
    fprintf(stderr, "initialize_gameboy(use_bios=%i, bios_filepath=%s)\n",use_bios, bios_filepath);
    ((gameboy_initialized == 0) ? (void) (0) : __assert_fail ("gameboy_initialized == false", "gameboy.c", 94, __extension__ __PRETTY_FUNCTION__));
    gb = (GameboyColor*)calloc(sizeof(GameboyColor), 1);
    ((gb) ? (void) (0) : __assert_fail ("gb", "gameboy.c", 98, __extension__ __PRETTY_FUNCTION__));
    if(gb == ((void *)0)) {
        return 1;
    }
    if(use_bios == 0) {
        memcpy(gb->hw_registers, hw_registers, 0x80);
    }
    if(use_bios) {
        if(read_bios(bios_filepath) != 0) {
            return 1;
        }
        gb->hw_registers[BLCK] = 0x00;
        enable_bios();
    } else {
        gb->hw_registers[BLCK] = 0x11;
    }
    gb->use_bios = use_bios;
    gameboy_update_selected_ram();
    gameboy_update_selected_vram();
    gameboy_initialized = 1;
    return 0;
}

canonical_original_code:
int initialize_gameboy(_Bool use_bios, char *bios_filepath)
{
    fprintf(stderr, "initialize_gameboy(use_bios=%i, bios_filepath=%s)\n",use_bios, bios_filepath);
    ((gameboy_initialized == 0) ? (void) (0) : __assert_fail ("gameboy_initialized == false", "gameboy.c", 94, __extension__ __PRETTY_FUNCTION__));
    gb = (struct GameboyColor *)calloc(sizeof(GameboyColor), 1);
    ((gb) ? (void) (0) : __assert_fail ("gb", "gameboy.c", 98, __extension__ __PRETTY_FUNCTION__));
    if(gb == ((void *)0)) {
        return 1;
    }
    if(use_bios == 0) {
        memcpy(gb->hw_registers, hw_registers, 0x80);
    }
    if(use_bios) {
        if(read_bios(bios_filepath) != 0) {
            return 1;
        }
        gb->hw_registers[BLCK] = 0x00;
        enable_bios();
    } else {
        gb->hw_registers[BLCK] = 0x11;
    }
    gb->use_bios = use_bios;
    gameboy_update_selected_ram();
    gameboy_update_selected_vram();
    gameboy_initialized = 1;
    return 0;
}

user_defined_types: struct GameboyColor { unsigned char ram[32768]; unsigned char vram[16384]; unsigned char oam[160]; unsigned char bios[2304]; unsigned char *selected_vram; unsigned char *selected_ram; unsigned char bg_pallete[64]; unsigned char ob_pallete[64]; unsigned char hram[127]; unsigned char hw_registers[128]; unsigned char ie_register; unsigned char ime_flag; _Bool cgb_mode; _Bool use_bios; }


decompiled_code:
void termination_handler()
{
do_exit = -1;
}

canonical_decompiled_code:
void func7()
{
do_exit = -1;
}

original_code:
void termination_handler(int signum)
{
 do_exit = -1;
}

variable_types: signum int


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "Usage: %s [-i radio][-o playback][freq(MHz)]\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
fprintf(stderr, "Usage: %s [-i radio][-o playback][freq(MHz)]\n", a1);
exit(1);
}

original_code:
void usage(char *progname)
{
 fprintf(stderr, "Usage: %s [-i radio][-o playback][freq(MHz)]\n",
  progname);
 exit(1);
}

variable_types:
progname
char *


decompiled_code:
__int64 setup_lcd_8bit()
{
__int64 v0; // rax
__int64 result; // rax

v0 = gpio;
*(_DWORD *)(gpio + 40) = 1920;
*(_DWORD *)(v0 + 28) = 384;
*(_DWORD *)(v0 + 28) = (_DWORD)&dword_400000;
usleep(0x14u);
result = gpio;
*(_DWORD *)(gpio + 40) = (_DWORD)&dword_400000;
return result;
}


decompiled_code:
int init_switch()
{
__int64 v0; // rax

v0 = gpio;
*(_DWORD *)(gpio + 4) |= 0x200000u;
*(_DWORD *)(v0 + 4) &= 0xFF1FFFFF;
return usleep(1u);
}

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

v0 = gpio;
*(_DWORD *)(gpio + 4) |= 0x200000u;
*(_DWORD *)(v0 + 4) &= 0xFF1FFFFF;
return usleep(1u);
}


decompiled_code:
__int64 get_switch()
{
return *(_DWORD *)(gpio + 52) & 0x10;
}

original_code:
int get_switch(void)
{
 return *(gpio+13) & (0x01 << (4));
}

canonical_original_code:
int get_switch()
{
 return *(gpio+13) & (0x01 << (4));
}


decompiled_code:
int init_led()
{
__int64 v0; // rax

v0 = gpio;
*(_DWORD *)(gpio + 4) &= 0xFF1FFFFF;
*(_DWORD *)(v0 + 4) |= 0x200000u;
return usleep(1u);
}

canonical_decompiled_code:
int func13()
{
__int64 v0; // rax

v0 = gpio;
*(_DWORD *)(gpio + 4) &= 0xFF1FFFFF;
*(_DWORD *)(v0 + 4) |= 0x200000u;
return usleep(1u);
}


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

result = gpio;
if ( a1 <= 0 )
*(_DWORD *)(gpio + 40) = 0x20000;
else
*(_DWORD *)(gpio + 28) = 0x20000;
return result;
}

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

result = gpio;
if ( a1 <= 0 )
*(_DWORD *)(gpio + 40) = 0x20000;
else
*(_DWORD *)(gpio + 28) = 0x20000;
return result;
}

variable_types: on int


decompiled_code:
int init_lcd()
{
_DWORD *v0; // rax

v0 = (_DWORD *)gpio;
*(_DWORD *)(gpio + 4) &= 0xFFFFFFC7;
v0[1] |= 8u;
v0[2] &= 0xFFFFFE3F;
v0[2] |= 0x40u;
*v0 &= 0xFF1FFFFF;
*v0 |= 0x200000u;
*v0 &= 0xF8FFFFFF;
*v0 |= 0x1000000u;
*v0 &= 0xC7FFFFFF;
*v0 |= 0x8000000u;
v0[1] &= 0xFFFFFFF8;
v0[1] |= 1u;
usleep(1u);
setup_lcd_4bit();
set_ctl(40);
usleep(0x32u);
set_ctl(8);
usleep(0x32u);
set_ctl(1);
usleep(0xBB8u);
set_ctl(6);
usleep(0x32u);
set_ctl(20);
usleep(0x32u);
set_ctl(12);
return usleep(0x32u);
}


decompiled_code:
int __fastcall write_str(char a1, _BYTE *a2)
{
int v3; // ebx
int result; // eax

if ( a1 == 1 )
set_ctl(128);
else
set_ctl(192);
v3 = 16;
usleep(0x32u);
do
{
while ( *a2 )
{
result = write_char((char)*a2++);
if ( !--v3 )
return result;
}
result = write_char(32);
--v3;
}
while ( v3 );
return result;
}

canonical_decompiled_code:
int __fastcall func16(char a1, _BYTE *a2)
{
int v3; // ebx
int result; // eax

if ( a1 == 1 )
func9(128);
else
func9(192);
v3 = 16;
usleep(0x32u);
do
{
while ( *a2 )
{
result = func10((char)*a2++);
if ( !--v3 )
return result;
}
result = func10(32);
--v3;
}
while ( v3 );
return result;
}

original_code:
void write_str(char line, char *str)
{
 int i;
 if (line==1) {
  set_ctl((0x80));
 } else {
  set_ctl((0xC0));
 }
 usleep(50);
 for (i=0; i<16; i++) {
  if (*str != '\0') {
   write_char(*str);
   str++;
  } else {
   write_char(' ');
  }
 }
}

variable_types: line char

variable_types:
str
char *


decompiled_code:
int __fastcall write_str_auto(_BYTE *a1)
{
int v1; // ebp
int v3; // ebp
int result; // eax

v1 = 16;
set_ctl(128);
usleep(0x32u);
do
{
while ( *a1 )
{
write_char((char)*a1++);
if ( !--v1 )
goto LABEL_5;
}
write_char(32);
--v1;
}
while ( v1 );
LABEL_5:
v3 = 16;
set_ctl(192);
usleep(0x32u);
do
{
while ( *a1 )
{
result = write_char((char)*a1++);
if ( !--v3 )
return result;
}
result = write_char(32);
--v3;
}
while ( v3 );
return result;
}

canonical_decompiled_code:
int __fastcall func17(_BYTE *a1)
{
int v1; // ebp
int v3; // ebp
int result; // eax

v1 = 16;
func9(128);
usleep(0x32u);
do
{
while ( *a1 )
{
func10((char)*a1++);
if ( !--v1 )
goto LABEL_5;
}
func10(32);
--v1;
}
while ( v1 );
LABEL_5:
v3 = 16;
func9(192);
usleep(0x32u);
do
{
while ( *a1 )
{
result = func10((char)*a1++);
if ( !--v3 )
return result;
}
result = func10(32);
--v3;
}
while ( v3 );
return result;
}

original_code:
void write_str_auto(char *str)
{
 int i;
 set_ctl((0x80));
 usleep(50);
 for (i=0; i<16; i++) {
  if (*str != '\0') {
   write_char(*str);
   str++;
  } else {
   write_char(' ');
  }
 }
 set_ctl((0xC0));
 usleep(50);
 for (; i<32; i++) {
  if (*str != '\0') {
   write_char(*str);
   str++;
  } else {
   write_char(' ');
  }
 }
}


decompiled_code:
__int64 setup_io()
{
char *v0; // rax
int v1; // eax
void *v2; // rax
__int64 result; // rax

v0 = malloc(0x1FFFuLL);
gpio_mem = v0;
if ( !v0 )
return 0xFFFFFFFFLL;
if ( ((unsigned __int16)v0 & 0xFFF) != 0 )
gpio_mem = (char *)v0 - ((unsigned __int16)v0 & 0xFFF) + 4096;
v1 = open("/dev/mem", 1052674);
mem_fd = v1;
if ( v1 < 0 )
{
printf("mem_fd %d", (unsigned int)v1);
result = 4294967294LL;
}
else
{
v2 = mmap(gpio_mem, 0x1000uLL, 3, 17, v1, 538968064LL);
gpio_map = (__int64)v2;
if ( (__int64)v2 < 0 )
{
result = 4294967293LL;
}
else
{
gpio = (__int64)v2;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func18()
{
char *v0; // rax
int v1; // eax
void *v2; // rax
__int64 result; // rax

v0 = malloc(0x1FFFuLL);
gpio_mem = v0;
if ( !v0 )
return 0xFFFFFFFFLL;
if ( ((unsigned __int16)v0 & 0xFFF) != 0 )
gpio_mem = (char *)v0 - ((unsigned __int16)v0 & 0xFFF) + 4096;
v1 = open("/dev/mem", 1052674);
mem_fd = v1;
if ( v1 < 0 )
{
printf("mem_fd %d", (unsigned int)v1);
result = 4294967294LL;
}
else
{
v2 = mmap(gpio_mem, 0x1000uLL, 3, 17, v1, 538968064LL);
gpio_map = (__int64)v2;
if ( (__int64)v2 < 0 )
{
result = 4294967293LL;
}
else
{
gpio = (__int64)v2;
result = 0LL;
}
}
return result;
}

original_code:
int setup_io(void)
{
 gpio_mem = malloc((4*1024) + ((4*1024) -1));
 if (gpio_mem == ((void *)0)) {
  return -1;
 }
 if ((unsigned long)gpio_mem % (4*1024)) {
  gpio_mem += (4*1024) - ((unsigned long)gpio_mem % (4*1024));
 }
 mem_fd = open("/dev/mem", 02|04010000);
 if ((long)mem_fd < 0) {
  printf("mem_fd %d", mem_fd);
  return -2;
 }
 gpio_map = (char *)mmap((caddr_t)gpio_mem,
        (4*1024),
        0x1|0x2,
        0x01|0x10,
        mem_fd, (0x20000000 + 0x200000));
 if ((long)gpio_map < 0) {
  return -3;
 }
 gpio = (volatile unsigned*)gpio_map;
 return 0;
}

canonical_original_code:
int setup_io()
{
 gpio_mem = malloc((4*1024) + ((4*1024) -1));
 if (gpio_mem == ((void *)0)) {
  return -1;
 }
 if ((unsigned long)gpio_mem % (4*1024)) {
  gpio_mem += (4*1024) - ((unsigned long)gpio_mem % (4*1024));
 }
 mem_fd = open("/dev/mem", 02|04010000);
 if ((long)mem_fd < 0) {
  printf("mem_fd %d", mem_fd);
  return -2;
 }
 gpio_map = (char *)mmap((char *)gpio_mem,
        (4*1024),
        0x1|0x2,
        0x01|0x10,
        mem_fd, (0x20000000 + 0x200000));
 if ((long)gpio_map < 0) {
  return -3;
 }
 gpio = (unsigned int *)gpio_map;
 return 0;
}


repo: typpo/lok

decompiled_code:
int usage()
{
return printf("lok your_sqlite.db");
}

canonical_decompiled_code:
int func0()
{
return printf("lok your_sqlite.db");
}

original_code:
void usage()
{
  printf("lok your_sqlite.db");
}


decompiled_code:
__int64 __fastcall init_db(__int64 a1)
{
int v1; // er8
__int64 result; // rax

v1 = db_start(a1, "testkey");
result = 1LL;
if ( v1 >= 0 )
{
db_create_table();
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // er8
__int64 result; // rax

v1 = db_start(a1, "testkey");
result = 1LL;
if ( v1 >= 0 )
{
db_create_table();
result = 0LL;
}
return result;
}

original_code:
int init_db(char *dbfile)
{
  if (db_start(dbfile, "testkey") < 0) {
    return 1;
  }
  db_create_table();
  return 0;
}

variable_types:
dbfile
char *


decompiled_code:
int init_curses()
{
initscr();
start_color();
cbreak();
noecho();
nonl();
return init_pair(1, 1, 0);
}

canonical_decompiled_code:
int func2()
{
initscr();
start_color();
cbreak();
noecho();
nonl();
return init_pair(1, 1, 0);
}

original_code:
void init_curses()
{
  initscr();
  start_color();
  cbreak();
  noecho();
  nonl();
  init_pair(1, 1, 0);
}


shutdown

decompiled_code:
__int64 shutdown()
{
db_free_notes(notes, (unsigned int)num_notes);
return db_shutdown();
}

canonical_decompiled_code:
__int64 func3()
{
db_free_notes(notes, (unsigned int)num_notes);
return db_shutdown();
}

original_code:
void shutdown()
{
  db_free_notes(notes, num_notes);
  db_shutdown();
}


decompiled_code:
char *input_key()
{
int v0; // ebp
char *v1; // rbx
char v2; // al
char *v3; // rax
char v5[56]; // [rsp+0h] [rbp-38h] BYREF

v0 = 0;
v1 = v5;
do
{
while ( 1 )
{
v2 = wgetch(stdscr);
if ( v2 != 7 )
break;
if ( v1 <= v5 )
goto LABEL_6;
*(v1 - 1) = 0;
--v0;
--v1;
}
if ( (unsigned __int8)(v2 - 32) <= 0x5Eu )
{
*v1 = v2;
++v0;
++v1;
}
if ( v2 == 10 )
goto LABEL_8;
LABEL_6:
;
}
while ( v0 != 30 );
puts("\nReached key maximum");
LABEL_8:
*v1 = 0;
v3 = (char *)malloc(0x1FuLL);
return strncpy(v3, v5, 0x1EuLL);
}

canonical_decompiled_code:
char *func4()
{
int v0; // ebp
char *v1; // rbx
char v2; // al
char *v3; // rax
char v5[56]; // [rsp+0h] [rbp-38h] BYREF

v0 = 0;
v1 = v5;
do
{
while ( 1 )
{
v2 = wgetch(stdscr);
if ( v2 != 7 )
break;
if ( v1 <= v5 )
goto LABEL_6;
*(v1 - 1) = 0;
--v0;
--v1;
}
if ( (unsigned __int8)(v2 - 32) <= 0x5Eu )
{
*v1 = v2;
++v0;
++v1;
}
if ( v2 == 10 )
goto LABEL_8;
LABEL_6:
;
}
while ( v0 != 30 );
puts("\nReached key maximum");
LABEL_8:
*v1 = 0;
v3 = (char *)malloc(0x1FuLL);
return strncpy(v3, v5, 0x1EuLL);
}

original_code:
char *input_key()
{
  char key;
  char plaintext[30 +1];
  char *ptr = plaintext;
  int len = 0;
  do {
    if (len >= 30) {
      printf("\nReached key maximum\n");
      break;
    }
    key = wgetch(stdscr);
    switch (key) {
      case (char) 0407:
        if (ptr > plaintext) {
          *(--ptr) = 0;
          len--;
        }
        break;
      default:
        if (key > 31 && key < 127) {
          *(ptr++) = key;
          len++;
        }
    }
  } while (key != '\n');
  *ptr = 0;
  char *ret = malloc(sizeof(char)*(30 +1));
  strncpy(ret, plaintext, 30);
  return ret;
}

canonical_original_code:
char *input_key()
{
  char key;
  char plaintext[-1];
  char *ptr = plaintext;
  int len = 0;
  do {
    if (len >= 30) {
      printf("\nReached key maximum\n");
      break;
    }
    key = wgetch(stdscr);
    switch (key) {
      case (char) 0407:
        if (ptr > plaintext) {
          *(--ptr) = 0;
          len--;
        }
        break;
      default:
        if (key > 31 && key < 127) {
          *(ptr++) = key;
          len++;
        }
    }
  } while (key != '\n');
  *ptr = 0;
  char *ret = malloc(sizeof(char)*(30 +1));
  strncpy(ret, plaintext, 30);
  return ret;
}

variable_types: key char

variable_types:
plaintext
char [-1]

variable_types:
ptr
char *

variable_types: len int

variable_types:
ret
char *

return_type: char *


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

if ( (unsigned int)db_fetch_notes(0LL, &notes, &num_notes) )
{
puts("Couldn't get notes from db.");
result = 1LL;
}
else
{
create_menu();
result = 0LL;
}
return result;
}

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

if ( (unsigned int)db_fetch_notes(0LL, &notes, &num_notes) )
{
puts("Couldn't get notes from db.");
result = 1LL;
}
else
{
func5();
result = 0LL;
}
return result;
}

original_code:
int load_notes()
{
  if (db_fetch_notes(0, &notes, &num_notes)) {
    printf("Couldn't get notes from db.\n");
    return 1;
  }
  create_menu();
  return 0;
}


decompiled_code:
__int64 reload_notes()
{
db_free_notes(notes, (unsigned int)num_notes);
clear_menu();
return load_notes();
}

canonical_decompiled_code:
__int64 func8()
{
db_free_notes(notes, (unsigned int)num_notes);
func6();
return func7();
}

original_code:
int reload_notes()
{
  db_free_notes(notes, num_notes);
  clear_menu();
  return load_notes();
}


titleFromInput

decompiled_code:
char *__fastcall titleFromInput(char *src, char *dest)
{
int v2; // eax
__int64 v3; // rbx
char *result; // rax

v2 = strcspn(src, "\n");
if ( v2 > 10 )
v2 = 10;
v3 = v2;
result = strncpy(dest, src, v2);
dest[v3] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func9(char *src, char *dest)
{
int v2; // eax
__int64 v3; // rbx
char *result; // rax

v2 = strcspn(src, "\n");
if ( v2 > 10 )
v2 = 10;
v3 = v2;
result = strncpy(dest, src, v2);
dest[v3] = 0;
return result;
}

original_code:
void titleFromInput(char *input, char *title)
{
  int newline = strcspn(input, "\n");
  int term = newline < 10 ? newline : 10;
  strncpy(title, input, term);
  title[term] = 0;
}

variable_types:
input
char *

variable_types:
title
char *

variable_types: newline int

variable_types: term int


decompiled_code:
int do_add()
{
void *ptr; // [rsp+8h] [rbp-20h] BYREF
char dest[19]; // [rsp+15h] [rbp-13h] BYREF

def_prog_mode();
endwin();
if ( (int)editor_do("tmp", &unk_7E0, &ptr) >= 0 )
{
titleFromInput((char *)ptr, dest);
db_insert_note(dest, ptr);
free(ptr);
reload_notes();
}
wrefresh(stdscr);
return reset_prog_mode();
}

canonical_decompiled_code:
int func10()
{
void *ptr; // [rsp+8h] [rbp-20h] BYREF
char dest[19]; // [rsp+15h] [rbp-13h] BYREF

def_prog_mode();
endwin();
if ( (int)editor_do("tmp", &unk_7E0, &ptr) >= 0 )
{
func9((char *)ptr, dest);
db_insert_note(dest, ptr);
free(ptr);
func8();
}
wrefresh(stdscr);
return reset_prog_mode();
}

original_code:
void do_add()
{
  def_prog_mode();
  endwin();
  char *input;
  if (editor_do("tmp", "", &input) < 0) {
    if (!input) {
      free(input);
    }
    wrefresh(stdscr);
    reset_prog_mode();
    return;
  }
  char title[10 +1];
  titleFromInput(input, title);
  db_insert_note(title, input);
  free(input);
  reload_notes();
  wrefresh(stdscr);
  reset_prog_mode();
}

canonical_original_code:
void do_add()
{
  def_prog_mode();
  endwin();
  char *input;
  if (editor_do("tmp", "", &input) < 0) {
    if (!input) {
      free(input);
    }
    wrefresh(stdscr);
    reset_prog_mode();
    return;
  }
  char title[-1];
  titleFromInput(input, title);
  db_insert_note(title, input);
  free(input);
  reload_notes();
  wrefresh(stdscr);
  reset_prog_mode();
}

variable_types:
title
char [-1]


decompiled_code:
int __fastcall do_edit(unsigned int a1)
{
int v1; // eax
void *ptr; // [rsp+8h] [rbp-20h] BYREF
char dest[19]; // [rsp+15h] [rbp-13h] BYREF

def_prog_mode();
endwin();
printf("Editing %d\n", a1);
v1 = editor_do("tmp", *(_QWORD *)(notes + 40LL * (int)a1 + 16), &ptr);
if ( v1 >= 0 )
{
if ( v1 )
{
titleFromInput((char *)ptr, dest);
db_edit_note(*(_QWORD *)(notes + 40LL * (int)a1), dest, ptr);
reload_notes();
}
free(ptr);
}
wrefresh(stdscr);
return reset_prog_mode();
}

canonical_decompiled_code:
int __fastcall func11(unsigned int a1)
{
int v1; // eax
void *ptr; // [rsp+8h] [rbp-20h] BYREF
char dest[19]; // [rsp+15h] [rbp-13h] BYREF

def_prog_mode();
endwin();
printf("Editing %d\n", a1);
v1 = editor_do("tmp", *(_QWORD *)(notes + 40LL * (int)a1 + 16), &ptr);
if ( v1 >= 0 )
{
if ( v1 )
{
func9((char *)ptr, dest);
db_edit_note(*(_QWORD *)(notes + 40LL * (int)a1), dest, ptr);
func8();
}
free(ptr);
}
wrefresh(stdscr);
return reset_prog_mode();
}

original_code:
void do_edit(int index)
{
  def_prog_mode();
  endwin();
  char *input;
  printf("Editing %d\n", index);
  int edit_result = editor_do("tmp", notes[index].text, &input);
  if (edit_result < 0) {
    goto restore;
  } else if (edit_result != 0) {
    char title[10 +1];
    titleFromInput(input, title);
    db_edit_note(notes[index].id, title, input);
    reload_notes();
  }
  free(input);
restore:
  wrefresh(stdscr);
  reset_prog_mode();
}

canonical_original_code:
void do_edit(int index)
{
  def_prog_mode();
  endwin();
  char *input;
  printf("Editing %d\n", index);
  int edit_result = editor_do("tmp", notes[index].text, &input);
  if (edit_result < 0) {
    goto restore;
  } else if (edit_result != 0) {
    char title[-1];
    titleFromInput(input, title);
    db_edit_note(notes[index].id, title, input);
    reload_notes();
  }
  free(input);
restore:
  wrefresh(stdscr);
  reset_prog_mode();
}

variable_types: index int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BOOL8 v3; // r12

if ( (unsigned int)init_db((__int64)"test.db") )
{
LODWORD(v3) = 1;
puts("db connection failed.");
}
else
{
init_curses();
v3 = (unsigned int)start_main_window(notes, (unsigned int)num_notes) != 0;
endwin();
shutdown();
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BOOL8 v3; // r12

if ( (unsigned int)func1((__int64)"test.db") )
{
LODWORD(v3) = 1;
puts("db connection failed.");
}
else
{
func2();
v3 = (unsigned int)func14(notes, (unsigned int)num_notes) != 0;
endwin();
func3();
}
return v3;
}

original_code:
int main(int argc, char **argv)
{
  if (init_db("test.db")) {
    printf("db connection failed.\n");
    return 1;
  }
  init_curses();
  int retval = 0;
  if (start_main_window(notes, num_notes))
    retval = 1;
  endwin();
  shutdown();
  return retval;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: retval int


decompiled_code:
__int64 __fastcall db_start(__int64 a1)
{
__int64 result; // rax
const char *v2; // rax

result = sqlite3_open(a1, &handle);
if ( (_DWORD)result )
{
v2 = (const char *)sqlite3_errmsg(handle);
fprintf(stderr, "Couldn't load database: %s\n", v2);
sqlite3_close(handle);
result = 0xFFFFFFFFLL;
}
return result;
}

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

result = sqlite3_open(a1, &handle);
if ( (_DWORD)result )
{
v2 = (const char *)sqlite3_errmsg(handle);
fprintf(stderr, "Couldn't load database: %s\n", v2);
sqlite3_close(handle);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int db_start(char *path, char *key)
{
 if (sqlite3_open(path, &handle)) {
  fprintf(stderr, "Couldn't load database: %s\n",
   sqlite3_errmsg(handle));
  sqlite3_close(handle);
  return -1;
 }
 return 0;
}

variable_types:
path
char *

variable_types:
key
char *


decompiled_code:
int db_shutdown()
{
int result; // eax
const char *v1; // rax

result = sqlite3_close(handle);
if ( result )
{
v1 = (const char *)sqlite3_errmsg(handle);
result = fprintf(stderr, "Couldn't close database: %s\n", v1);
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax
const char *v1; // rax

result = sqlite3_close(handle);
if ( result )
{
v1 = (const char *)sqlite3_errmsg(handle);
result = fprintf(stderr, "Couldn't close database: %s\n", v1);
}
return result;
}

original_code:
void db_shutdown()
{
 if (sqlite3_close(handle)) {
  fprintf(stderr, "Couldn't close database: %s\n",
   sqlite3_errmsg(handle));
 }
}


decompiled_code:
__int64 db_create_table()
{
return sqlite3_exec(
handle,
"CREATE TABLE IF NOT EXISTS notes(id INTEGER PRIMARY KEY,title TEXT NOT NULL,text TEXT NOT NULL, edited DATE N"
"OT NULL, added DATE NOT NULL)",
0LL,
0LL,
0LL);
}

canonical_decompiled_code:
__int64 func2()
{
return sqlite3_exec(
handle,
"CREATE TABLE IF NOT EXISTS notes(id INTEGER PRIMARY KEY,title TEXT NOT NULL,text TEXT NOT NULL, edited DATE N"
"OT NULL, added DATE NOT NULL)",
0LL,
0LL,
0LL);
}

original_code:
int db_create_table()
{
 char *query =
     "CREATE TABLE IF NOT EXISTS notes(id INTEGER PRIMARY KEY,title TEXT NOT NULL,text TEXT NOT NULL, edited DATE NOT NULL, added DATE NOT NULL)";
 return sqlite3_exec(handle, query, 0, 0, 0);
}

variable_types:
query
char *


decompiled_code:
void __fastcall db_free_notes(void *ptr, int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

v2 = ptr;
if ( a2 > 0 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 40 * (unsigned int)(a2 - 1) + 40);
do
{
v5 = *v3;
v3 += 5;
free(v5);
free(*(v3 - 4));
free(*(v3 - 2));
free(*(v3 - 1));
free(*(v3 - 3));
}
while ( v3 != v4 );
}
free(v2);
}

original_code:
void db_free_notes(lok_item_t * buf, int num_items)
{
 for (int i = 0; i < num_items; i++) {
  free(buf[i].id);
  free(buf[i].title);
  free(buf[i].edited);
  free(buf[i].added);
  free(buf[i].text);
 }
 free(buf);
}

canonical_original_code:
void db_free_notes(struct lok_item_t *buf, int num_items)
{
 for (int i = 0; i < num_items; i++) {
  free(buf[i].id);
  free(buf[i].title);
  free(buf[i].edited);
  free(buf[i].added);
  free(buf[i].text);
 }
 free(buf);
}

variable_types: struct lok_item_t { char *id; char *title; char *text; char *edited; char *added; } *

variable_types: i int


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

result = strstr(a1, "..");
if ( result )
{
while ( *result == 46 )
++result;
}
return result;
}

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

result = strstr(a1, "..");
if ( result )
{
while ( *result == 46 )
++result;
}
return result;
}

original_code:
static char *
skip_dots(const char *pos)
{
 pos = strstr(pos, "..");
 if (!pos)
  return ((void *)0);
 while (*pos == '.')
  pos++;
 return (char *) pos;
}

canonical_original_code:
static char *skip_dots(char *pos)
{
 pos = strstr(pos, "..");
 if (!pos)
  return ((void *)0);
 while (*pos == '.')
  pos++;
 return (char *) pos;
}

variable_types:
pos
char *


original_code:
int
do_ses_cmd(int fd, uint8_t cmd, uint8_t page_nr, uint8_t flags,
    uint8_t cmd_len, int dxfer_direction, void *buf, int buf_len)
{
 unsigned char scsi_cmd_buf[16] = {
  cmd,
  flags,
  page_nr,
  (buf_len >> 8) & 0xff,
  buf_len & 0xff,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 };
 struct sense_data_t sense_data;
 sg_io_hdr_t hdr;
 int i, rc;
 for (i = 0; i < 3; i++) {
  memset(&hdr, 0, sizeof(hdr));
  memset(&sense_data, 0, sizeof(struct sense_data_t));
  hdr.interface_id = 'S';
  hdr.dxfer_direction = dxfer_direction;
  hdr.cmd_len = cmd_len;
  hdr.mx_sb_len = sizeof(sense_data);
  hdr.iovec_count = 0;
  hdr.dxfer_len = buf_len;
  hdr.dxferp = buf;
  hdr.cmdp = scsi_cmd_buf;
  hdr.sbp = (unsigned char *)&sense_data;
  hdr.timeout = 120 * 1000;
  hdr.flags = 0;
  hdr.pack_id = 0;
  hdr.usr_ptr = 0;
  rc = ioctl(fd, 0x2285, &hdr);
  if ((rc == 0) && (hdr.masked_status == 0x01))
   rc = 0x01;
  else if ((rc == 0) && (hdr.host_status || hdr.driver_status))
   rc = -5;
  if (rc == 0 || hdr.host_status == 1)
   break;
 }
 return rc;
}

canonical_original_code:
int do_ses_cmd(int fd, unsigned char cmd, unsigned char page_nr, unsigned char flags, unsigned char cmd_len, int dxfer_direction, void *buf, int buf_len)
{
 unsigned char scsi_cmd_buf[16] = {
  cmd,
  flags,
  page_nr,
  (buf_len >> 8) & 0xff,
  buf_len & 0xff,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 };
 struct sense_data_t sense_data;
 struct sg_io_hdr hdr;
 int i; int rc;
 for (i = 0; i < 3; i++) {
  memset(&hdr, 0, sizeof(hdr));
  memset(&sense_data, 0, sizeof(struct sense_data_t));
  hdr.interface_id = 'S';
  hdr.dxfer_direction = dxfer_direction;
  hdr.cmd_len = cmd_len;
  hdr.mx_sb_len = sizeof(sense_data);
  hdr.iovec_count = 0;
  hdr.dxfer_len = buf_len;
  hdr.dxferp = buf;
  hdr.cmdp = scsi_cmd_buf;
  hdr.sbp = (unsigned char *)&sense_data;
  hdr.timeout = 120 * 1000;
  hdr.flags = 0;
  hdr.pack_id = 0;
  hdr.usr_ptr = 0;
  rc = ioctl(fd, 0x2285, &hdr);
  if ((rc == 0) && (hdr.masked_status == 0x01))
   rc = 0x01;
  else if ((rc == 0) && (hdr.host_status || hdr.driver_status))
   rc = -5;
  if (rc == 0 || hdr.host_status == 1)
   break;
 }
 return rc;
}

variable_types: fd int

variable_types:
cmd
unsigned char

variable_types:
flags
unsigned char

variable_types:
buf
void *

variable_types: struct sense_data_t { unsigned char error_code; unsigned char segment_numb; unsigned char sense_key; unsigned char info[4]; unsigned char add_sense_len; unsigned char cmd_spec_info[4]; unsigned char add_sense_code; unsigned char add_sense_code_qual; unsigned char field_rep_unit_code; unsigned char sense_key_spec[3]; unsigned char add_sense_bytes[]; }

variable_types: struct sg_io_hdr { int interface_id; int dxfer_direction; unsigned char cmd_len; unsigned char mx_sb_len; unsigned short iovec_count; unsigned int dxfer_len; void *dxferp; unsigned char *cmdp; unsigned char *sbp; unsigned int timeout; unsigned int flags; int pack_id; void *usr_ptr; unsigned char status; unsigned char masked_status; unsigned char msg_status; unsigned char sb_len_wr; unsigned short host_status; unsigned short driver_status; int resid; unsigned int duration; unsigned int info; }

variable_types: rc int


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

v1 = strcpy((char *)(a1 + 128), (const char *)(a1 + 256));
result = strchr(v1, 45);
if ( result && (!strcmp(result, "-P1-C1") || !strcmp(result, "-P1-C2")) )
*result = 0;
return result;
}

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

v1 = strcpy((char *)(a1 + 128), (const char *)(a1 + 256));
result = strchr(v1, 45);
if ( result && (!strcmp(result, "-P1-C1") || !strcmp(result, "-P1-C2")) )
*result = 0;
return result;
}

original_code:
void
trim_location_code(struct dev_vpd *vpd)
{
 char *hyphen;
 strcpy(vpd->location, vpd->full_loc);
 hyphen = strchr(vpd->location, '-');
 if (hyphen && (!strcmp(hyphen, "-P1-C1") || !strcmp(hyphen, "-P1-C2")))
  *hyphen = '\0';
}

variable_types: struct dev_vpd { char mtm[128]; char location[128]; char full_loc[128]; char sn[128]; char fru[128]; struct dev_vpd *next; } *

variable_types:
hyphen
char *


decompiled_code:
int __fastcall get_diagnostic_page(int a1, char a2, char a3, __int64 a4, int a5)
{
return do_ses_cmd(a1, a2, a3, 1, 16, -3, a4, a5);
}

canonical_decompiled_code:
int __fastcall func2(int a1, char a2, char a3, __int64 a4, int a5)
{
return func1(a1, a2, a3, 1, 16, -3, a4, a5);
}

original_code:
int
get_diagnostic_page(int fd, uint8_t cmd, uint8_t page_nr, void *buf,
      int buf_len)
{
 return do_ses_cmd(fd, cmd, page_nr, 0x1, 16, -3,
        buf, buf_len);
}

canonical_original_code:
int get_diagnostic_page(int fd, unsigned char cmd, unsigned char page_nr, void *buf, int buf_len)
{
 return do_ses_cmd(fd, cmd, page_nr, 0x1, 16, -3,
        buf, buf_len);
}


original_code:
int
get_vpd_page(int fd, char command, char page_nr, void *buf, int buf_len)
{
 unsigned char scsi_cmd_buf[16] =
  { command,
   0x01,
   page_nr,
   (buf_len >> 8) & 0xff,
   buf_len & 0xff,
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 struct sense_data_t sense_data;
 sg_io_hdr_t hdr;
 int i, rc;
 for (i = 0; i < 3; i++) {
  memset(&hdr, 0, sizeof(hdr));
  memset(&sense_data, 0, sizeof(struct sense_data_t));
  hdr.interface_id = 'S';
  hdr.dxfer_direction = -3;
  hdr.cmd_len = 16;
  hdr.mx_sb_len = sizeof(sense_data);
  hdr.iovec_count = 0;
  hdr.dxfer_len = buf_len;
  hdr.dxferp = buf;
  hdr.cmdp = scsi_cmd_buf;
  hdr.sbp = (unsigned char *)&sense_data;
  hdr.timeout = 120 * 1000;
  hdr.flags = 0;
  hdr.pack_id = 0;
  hdr.usr_ptr = 0;
  rc = ioctl(fd, 0x2285, &hdr);
  if ((rc == 0) && (hdr.masked_status == 0x01))
   rc = 0x01;
  else if ((rc == 0) && (hdr.host_status || hdr.driver_status))
   rc = -5;
  if (rc == 0 || hdr.host_status == 1)
   break;
 }
 return rc;
}

canonical_original_code:
int get_vpd_page(int fd, char command, char page_nr, void *buf, int buf_len)
{
 unsigned char scsi_cmd_buf[16] = { command,
   0x01,
   page_nr,
   (buf_len >> 8) & 0xff,
   buf_len & 0xff,
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 struct sense_data_t sense_data;
 struct sg_io_hdr hdr;
 int i; int rc;
 for (i = 0; i < 3; i++) {
  memset(&hdr, 0, sizeof(hdr));
  memset(&sense_data, 0, sizeof(struct sense_data_t));
  hdr.interface_id = 'S';
  hdr.dxfer_direction = -3;
  hdr.cmd_len = 16;
  hdr.mx_sb_len = sizeof(sense_data);
  hdr.iovec_count = 0;
  hdr.dxfer_len = buf_len;
  hdr.dxferp = buf;
  hdr.cmdp = scsi_cmd_buf;
  hdr.sbp = (unsigned char *)&sense_data;
  hdr.timeout = 120 * 1000;
  hdr.flags = 0;
  hdr.pack_id = 0;
  hdr.usr_ptr = 0;
  rc = ioctl(fd, 0x2285, &hdr);
  if ((rc == 0) && (hdr.masked_status == 0x01))
   rc = 0x01;
  else if ((rc == 0) && (hdr.host_status || hdr.driver_status))
   rc = -5;
  if (rc == 0 || hdr.host_status == 1)
   break;
 }
 return rc;
}

variable_types: command char

user_defined_types: struct sense_data_t { unsigned char error_code; unsigned char segment_numb; unsigned char sense_key; unsigned char info[4]; unsigned char add_sense_len; unsigned char cmd_spec_info[4]; unsigned char add_sense_code; unsigned char add_sense_code_qual; unsigned char field_rep_unit_code; unsigned char sense_key_spec[3]; unsigned char add_sense_bytes[]; }

user_defined_types: struct sg_io_hdr { int interface_id; int dxfer_direction; unsigned char cmd_len; unsigned char mx_sb_len; unsigned short iovec_count; unsigned int dxfer_len; void *dxferp; unsigned char *cmdp; unsigned char *sbp; unsigned int timeout; unsigned int flags; int pack_id; void *usr_ptr; unsigned char status; unsigned char masked_status; unsigned char msg_status; unsigned char sb_len_wr; unsigned short host_status; unsigned short driver_status; int resid; unsigned int duration; unsigned int info; }


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
int v4; // er12
unsigned int v5; // er13
const char *v6; // rax
const char *v7; // rax
const char *v8; // rax
const char *v9; // rax
const char *v10; // rax
const char *v11; // rax
const char *v12; // rax
const char *v13; // rax
unsigned int v14; // er12
const char *v15; // rax
const char *v16; // rax
const char *v17; // rax
const char *v18; // rax
const char *v19; // rax
const char *v20; // rax
char v21[32]; // [rsp+0h] [rbp-5D8h] BYREF
char v22[32]; // [rsp+20h] [rbp-5B8h] BYREF
char v23[12]; // [rsp+48h] [rbp-590h] BYREF
char v24[16]; // [rsp+54h] [rbp-584h] BYREF
char v25[8]; // [rsp+64h] [rbp-574h] BYREF
char v26[20]; // [rsp+6Ch] [rbp-56Ch] BYREF
char v27[1328]; // [rsp+80h] [rbp-558h] BYREF
int v28; // [rsp+5B0h] [rbp-28h]
char v29; // [rsp+5B4h] [rbp-24h]

if ( argc == 2 )
{
v3 = argv[1];
if ( strncmp(v3, "sg", 2uLL) || strlen(v3) > 6 )
{
fwrite("bad format of sg arg\n", 1uLL, 0x15uLL, _bss_start);
exit(2);
}
sprintf(v21, "/dev/%s", v3);
v4 = open(v21, 2);
if ( v4 >= 0 )
{
puts("ESM/ERM:");
v5 = get_vpd_page(v4);
if ( !v5 )
{
v6 = (const char *)strzcpy(v22, v23, 8LL);
printf("FN=%s\n", v6);
v7 = (const char *)strzcpy(v22, v24, 12LL);
printf("SN=%s\n", v7);
v8 = (const char *)strzcpy(v22, v25, 4LL);
printf("CC=%s\n", v8);
v9 = (const char *)strzcpy(v22, v26, 5LL);
printf("FL=%s\n", v9);
puts("\nmidplane:");
v5 = get_vpd_page(v4);
if ( !v5 )
{
v10 = (const char *)strzcpy(v22, v23, 8LL);
printf("FN=%s\n", v10);
v11 = (const char *)strzcpy(v22, v24, 12LL);
printf("SN=%s\n", v11);
v12 = (const char *)strzcpy(v22, v25, 4LL);
printf("CC=%s\n", v12);
v13 = (const char *)strzcpy(v22, v26, 5LL);
printf("FL=%s\n", v13);
memset(v27, 0, sizeof(v27));
v28 = 0;
v29 = 0;
puts("\npower supply 0:");
v14 = get_vpd_page(v4);
if ( v14 )
{
perror("get_vpd_page");
fprintf(_bss_start, "result = %d\n", v14);
exit(5);
}
v15 = (const char *)strzcpy(v22, &v27[1079], 8LL);
printf("FN=%s\n", v15);
v16 = (const char *)strzcpy(v22, &v27[1090], 12LL);
printf("SN=%s\n", v16);
v17 = (const char *)strzcpy(v22, &v27[1129], 5LL);
printf("FL=%s\n", v17);
puts("\npower supply 1:");
v18 = (const char *)strzcpy(v22, &v27[1141], 8LL);
printf("FN=%s\n", v18);
v19 = (const char *)strzcpy(v22, &v27[1152], 12LL);
printf("SN=%s\n", v19);
v20 = (const char *)strzcpy(v22, &v27[1191], 5LL);
printf("FL=%s\n", v20);
exit(0);
}
}
perror("get_vpd_page");
fprintf(_bss_start, "result = %d\n", v5);
exit(4);
}
perror(v21);
exit(3);
}
fprintf(_bss_start, "usage: %s sgN\n", *argv);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
int v4; // er12
unsigned int v5; // er13
const char *v6; // rax
const char *v7; // rax
const char *v8; // rax
const char *v9; // rax
const char *v10; // rax
const char *v11; // rax
const char *v12; // rax
const char *v13; // rax
unsigned int v14; // er12
const char *v15; // rax
const char *v16; // rax
const char *v17; // rax
const char *v18; // rax
const char *v19; // rax
const char *v20; // rax
char v21[32]; // [rsp+0h] [rbp-5D8h] BYREF
char v22[32]; // [rsp+20h] [rbp-5B8h] BYREF
char v23[12]; // [rsp+48h] [rbp-590h] BYREF
char v24[16]; // [rsp+54h] [rbp-584h] BYREF
char v25[8]; // [rsp+64h] [rbp-574h] BYREF
char v26[20]; // [rsp+6Ch] [rbp-56Ch] BYREF
char v27[1328]; // [rsp+80h] [rbp-558h] BYREF
int v28; // [rsp+5B0h] [rbp-28h]
char v29; // [rsp+5B4h] [rbp-24h]

if ( argc == 2 )
{
v3 = argv[1];
if ( strncmp(v3, "sg", 2uLL) || strlen(v3) > 6 )
{
fwrite("bad format of sg arg\n", 1uLL, 0x15uLL, _bss_start);
exit(2);
}
sprintf(v21, "/dev/%s", v3);
v4 = open(v21, 2);
if ( v4 >= 0 )
{
puts("ESM/ERM:");
v5 = func7(v4);
if ( !v5 )
{
v6 = (const char *)strzcpy(v22, v23, 8LL);
printf("FN=%s\n", v6);
v7 = (const char *)strzcpy(v22, v24, 12LL);
printf("SN=%s\n", v7);
v8 = (const char *)strzcpy(v22, v25, 4LL);
printf("CC=%s\n", v8);
v9 = (const char *)strzcpy(v22, v26, 5LL);
printf("FL=%s\n", v9);
puts("\nmidplane:");
v5 = func7(v4);
if ( !v5 )
{
v10 = (const char *)strzcpy(v22, v23, 8LL);
printf("FN=%s\n", v10);
v11 = (const char *)strzcpy(v22, v24, 12LL);
printf("SN=%s\n", v11);
v12 = (const char *)strzcpy(v22, v25, 4LL);
printf("CC=%s\n", v12);
v13 = (const char *)strzcpy(v22, v26, 5LL);
printf("FL=%s\n", v13);
memset(v27, 0, sizeof(v27));
v28 = 0;
v29 = 0;
puts("\npower supply 0:");
v14 = func7(v4);
if ( v14 )
{
perror("get_vpd_page");
fprintf(_bss_start, "result = %d\n", v14);
exit(5);
}
v15 = (const char *)strzcpy(v22, &v27[1079], 8LL);
printf("FN=%s\n", v15);
v16 = (const char *)strzcpy(v22, &v27[1090], 12LL);
printf("SN=%s\n", v16);
v17 = (const char *)strzcpy(v22, &v27[1129], 5LL);
printf("FL=%s\n", v17);
puts("\npower supply 1:");
v18 = (const char *)strzcpy(v22, &v27[1141], 8LL);
printf("FN=%s\n", v18);
v19 = (const char *)strzcpy(v22, &v27[1152], 12LL);
printf("SN=%s\n", v19);
v20 = (const char *)strzcpy(v22, &v27[1191], 5LL);
printf("FL=%s\n", v20);
exit(0);
}
}
perror("get_vpd_page");
fprintf(_bss_start, "result = %d\n", v5);
exit(4);
}
perror(v21);
exit(3);
}
fprintf(_bss_start, "usage: %s sgN\n", *argv);
exit(1);
}

original_code:
int
main(int argc, char **argv)
{
 char *sg;
 char dev_sg[20];
 int fd;
 struct vpd_page vp;
 struct element_descriptor_page edp;
 int result;
 char temp[20];
 if (argc != 2) {
  fprintf(stderr, "usage: %s sgN\n", argv[0]);
  exit(1);
 }
 sg = argv[1];
 if (strncmp(sg, "sg", 2) != 0 || strlen(sg) > 6) {
  fprintf(stderr, "bad format of sg arg\n");
  exit(2);
 }
 sprintf(dev_sg, "/dev/%s", sg);
 fd = open(dev_sg, 02);
 if (fd < 0) {
  perror(dev_sg);
  exit(3);
 }
 printf("ESM/ERM:\n");
 result = get_vpd_page(fd, 0x12, 1, &vp, sizeof(vp));
 if (result != 0) {
  perror("get_vpd_page");
  fprintf(stderr, "result = %d\n", result);
  exit(4);
 }
 printf("FN=%s\n", strzcpy(temp, vp.fru_number, 8));
 printf("SN=%s\n", strzcpy(temp, vp.serial_number, 12));
 printf("CC=%s\n", strzcpy(temp, vp.model_number, 4));
 printf("FL=%s\n", strzcpy(temp, vp.fru_label, 5));
 printf("\nmidplane:\n");
 result = get_vpd_page(fd, 0x12, 5, &vp, sizeof(vp));
 if (result != 0) {
  perror("get_vpd_page");
  fprintf(stderr, "result = %d\n", result);
  exit(4);
 }
 printf("FN=%s\n", strzcpy(temp, vp.fru_number, 8));
 printf("SN=%s\n", strzcpy(temp, vp.serial_number, 12));
 printf("CC=%s\n", strzcpy(temp, vp.model_number, 4));
 printf("FL=%s\n", strzcpy(temp, vp.fru_label, 5));
 memset(&edp, 0, sizeof(edp));
 printf("\npower supply 0:\n");
 result = get_vpd_page(fd, 0x1c, 7, &edp, sizeof(edp));
 if (result != 0) {
  perror("get_vpd_page");
  fprintf(stderr, "result = %d\n", result);
  exit(5);
 }
 printf("FN=%s\n", strzcpy(temp, edp.ps0_vpd.fru_number, 8));
 printf("SN=%s\n", strzcpy(temp, edp.ps0_vpd.serial_number, 12));
 printf("FL=%s\n", strzcpy(temp, edp.ps0_vpd.fru_label, 5));
 printf("\npower supply 1:\n");
 printf("FN=%s\n", strzcpy(temp, edp.ps1_vpd.fru_number, 8));
 printf("SN=%s\n", strzcpy(temp, edp.ps1_vpd.serial_number, 12));
 printf("FL=%s\n", strzcpy(temp, edp.ps1_vpd.fru_label, 5));
 exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
sg
char *

variable_types: struct vpd_page { unsigned char peripheral_qualifier; unsigned char page_code; unsigned char reserved1; unsigned char page_length; unsigned char ascii_length; char fn[3]; char fru_number[8]; unsigned char reserved2; char sn[3]; char serial_number[12]; unsigned char reserved3; char cc[3]; char model_number[4]; unsigned char reserved4; char fl[3]; char fru_label[5]; unsigned char reserved5; }

variable_types: struct element_descriptor_page { char ignored1[1074]; struct power_supply_descriptor { unsigned short descriptor_length; char fn[3]; char fru_number[8]; char sn[3]; char serial_number[12]; char vendor[12]; char date_of_manufacture[12]; char fl[3]; char fru_label[5]; } ps0_vpd; unsigned short reserved; struct power_supply_descriptor ps1_vpd; char ignored2[137]; }

variable_types: result int

variable_types:
temp
char [20]

user_defined_types: struct element_descriptor_page { char ignored1[1074]; struct power_supply_descriptor ps0_vpd; unsigned short reserved; struct power_supply_descriptor ps1_vpd; char ignored2[137]; }


decompiled_code:
__int64 __fastcall add_element_status(unsigned int a1, _BYTE *a2)
{
unsigned int v2; // er8
unsigned __int8 v3; // al
__int64 result; // rax

v2 = a1;
v3 = *a2 >> 4;
if ( (v3 & 0xFB) == 1 || (v2 = v3, (a1 & 0xFFFFFFFD) == 1) && v3 > 1u )
result = v2;
else
result = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, _BYTE *a2)
{
unsigned int v2; // er8
unsigned __int8 v3; // al
__int64 result; // rax

v2 = a1;
v3 = *a2 >> 4;
if ( (v3 & 0xFB) == 1 || (v2 = v3, (a1 & 0xFFFFFFFD) == 1) && v3 > 1u )
result = v2;
else
result = a1;
return result;
}

original_code:
enum element_status_code
add_element_status(enum element_status_code cur,
    const struct element_status_byte0 *byte0)
{
 enum element_status_code s = (enum element_status_code) byte0->status;
 if (s == ES_OK || s == ES_NOT_INSTALLED)
  return cur;
 if ((cur == ES_OK || cur == ES_NONCRITICAL) && s > ES_OK)
  return s;
 return cur;
}

canonical_original_code:
enum element_status_code add_element_status(enum element_status_code cur, struct element_status_byte0 *byte0)
{
 enum element_status_code s = (enum element_status_code) byte0->status;
 if (s == ES_OK || s == ES_NOT_INSTALLED)
  return cur;
 if ((cur == ES_OK || cur == ES_NONCRITICAL) && s > ES_OK)
  return s;
 return cur;
}

variable_types: enum element_status_code { ES_UNSUPPORTED=0, ES_OK=1, ES_CRITICAL=2, ES_NONCRITICAL=3, ES_UNRECOVERABLE=4, ES_NOT_INSTALLED=5, ES_UNKNOWN=6, ES_NOT_AVAILABLE=7, ES_NO_ACCESS_ALLOWED=8, ES_EOL=9 }

variable_types: struct element_status_byte0 { unsigned char reserved1; unsigned char prdfail; unsigned char disabled; unsigned char swap; unsigned char status; } *


decompiled_code:
__int64 __fastcall composite_status(_BYTE *a1, int a2)
{
unsigned int v3; // edi
_BYTE *v4; // r9

if ( a2 <= 0 )
return 1LL;
v3 = 1;
do
v3 = add_element_status(v3, a1);
while ( a1 != v4 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(_BYTE *a1, int a2)
{
unsigned int v3; // edi
_BYTE *v4; // r9

if ( a2 <= 0 )
return 1LL;
v3 = 1;
do
v3 = func8(v3, a1);
while ( a1 != v4 );
return v3;
}

original_code:
enum element_status_code
composite_status(const void* first_element, int nel)
{
 int i;
 const char *el = (const char*) first_element;
 enum element_status_code s = ES_OK;
 for (i = 0; i < nel; i++, el += 4)
  s = add_element_status(s,
   (const struct element_status_byte0*) el);
 return s;
}

canonical_original_code:
enum element_status_code composite_status(void *first_element, int nel)
{
 int i;
 char *el = (const char*) first_element;
 enum element_status_code s = ES_OK;
 for (i = 0; i < nel; i++, el += 4)
  s = add_element_status(s,
   (struct element_status_byte0 *) el);
 return s;
}

variable_types: nel int

variable_types: i int

variable_types:
el
char *

return_type: enum element_status_code { ES_UNSUPPORTED=0, ES_OK=1, ES_CRITICAL=2, ES_NONCRITICAL=3, ES_UNRECOVERABLE=4, ES_NOT_INSTALLED=5, ES_UNKNOWN=6, ES_NOT_AVAILABLE=7, ES_NO_ACCESS_ALLOWED=8, ES_EOL=9 }

user_defined_types: struct element_status_byte0 { unsigned char reserved1; unsigned char prdfail; unsigned char disabled; unsigned char swap; unsigned char status; }


decompiled_code:
__int64 __fastcall roll_up_disk_status(__int64 a1)
{
return composite_status((_BYTE *)(a1 + 12), 30);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return func9((_BYTE *)(a1 + 12), 30);
}

original_code:
enum element_status_code
roll_up_disk_status(const struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->disk_status, 30);
}

canonical_original_code:
enum element_status_code roll_up_disk_status(struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->disk_status, 30);
}

variable_types: struct bluehawk_diag_page2 { unsigned char page_code; unsigned char reserved1; unsigned char invop; unsigned char info; unsigned char non_crit; unsigned char crit; unsigned char unrecov; unsigned short page_length; unsigned int generation_code; struct disk_status { struct element_status_byte0 { unsigned char reserved1; unsigned char prdfail; unsigned char disabled; unsigned char swap; unsigned char status; } byte0; union { struct overall_disk_status_byte1 { unsigned char device_environment; unsigned char slot_address; } overall_status; struct disk_element_status_byte1 { unsigned char hot_swap; unsigned char slot_address; } element_status; } byte1; unsigned char app_client_bypassed_a; unsigned char do_not_remove; unsigned char enclosure_bypassed_a; unsigned char enclosure_bypassed_b; unsigned char ready_to_insert; unsigned char rmv; unsigned char ident; unsigned char report; unsigned char app_client_bypassed_b; unsigned char fault_sensed; unsigned char fail; unsigned char device_off; unsigned char bypassed_a; unsigned char bypassed_b; unsigned char device_bypassed_a; unsigned char device_bypassed_b; } overall_disk_status; struct disk_status disk_status[30]; struct enclosure_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char reserved3; unsigned char fail; unsigned char warning_indication; unsigned char reserved4; unsigned char failure_requested; unsigned char warning_requested; } overall_enclosure_status; struct enclosure_status enclosure_element_status; struct esm_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char report; unsigned char hot_swap; unsigned char reserved4; } overall_esm_status; struct esm_status esm_status[2]; struct temperature_sensor_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char temperature; unsigned char reserved3; unsigned char ot_failure; unsigned char ot_warning; unsigned char ut_failure; unsigned char ut_warning; } overall_temp_sensor_status; struct temperature_sensor_set { struct temperature_sensor_status croc; struct temperature_sensor_status ppc; struct temperature_sensor_status expander; struct temperature_sensor_status ambient[2]; struct temperature_sensor_status power_supply[2]; } temp_sensor_sets[2]; struct fan_status { struct element_status_byte0 byte0; unsigned short ident; unsigned short reserved2; unsigned short fan_speed; unsigned char hot_swap; unsigned char fail; unsigned char rqsted_on; unsigned char off; unsigned char reserved3; unsigned char speed_code; } overall_fan_status; struct fan_set { struct fan_status power_supply; struct fan_status fan_element[4]; } fan_sets[2]; struct power_supply_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char reserved3; unsigned char dc_over_voltage; unsigned char dc_under_voltage; unsigned char dc_over_current; unsigned char reserved4; unsigned char hot_swap; unsigned char fail; unsigned char rqsted_on; unsigned char off; unsigned char ovrtmp_fail; unsigned char temp_warn; unsigned char ac_fail; unsigned char dc_fail; } overall_power_status; struct power_supply_status ps_status[2]; struct voltage_sensor_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char warn_over; unsigned char warn_under; unsigned char crit_over; unsigned char crit_under; short voltage; } overall_voltage_status; struct voltage_sensor_set { struct voltage_sensor_status sensor_12V; struct voltage_sensor_status sensor_3_3VA; } voltage_sensor_sets[2]; struct sas_connector_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char connector_type; unsigned char connector_physical_link; unsigned char reserved2; unsigned char fail; unsigned char reserved3; } overall_sas_connector_status; struct sas_connector_status sas_connector_status[4]; struct scc_controller_overall_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char reserved4; } overall_scc_controller_status; struct scc_controller_element_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char report; unsigned char reserved4; } scc_controller_status[2]; struct midplane_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char reserved4; } overall_midplane_status; struct midplane_status midplane_element_status; } *

user_defined_types: enum element_status_code { ES_UNSUPPORTED=0, ES_OK=1, ES_CRITICAL=2, ES_NONCRITICAL=3, ES_UNRECOVERABLE=4, ES_NOT_INSTALLED=5, ES_UNKNOWN=6, ES_NOT_AVAILABLE=7, ES_NO_ACCESS_ALLOWED=8, ES_EOL=9 }

user_defined_types: struct bluehawk_diag_page2 { unsigned char page_code; unsigned char reserved1; unsigned char invop; unsigned char info; unsigned char non_crit; unsigned char crit; unsigned char unrecov; unsigned short page_length; unsigned int generation_code; struct disk_status overall_disk_status; struct disk_status disk_status[30]; struct enclosure_status overall_enclosure_status; struct enclosure_status enclosure_element_status; struct esm_status overall_esm_status; struct esm_status esm_status[2]; struct temperature_sensor_status overall_temp_sensor_status; struct temperature_sensor_set temp_sensor_sets[2]; struct fan_status overall_fan_status; struct fan_set fan_sets[2]; struct power_supply_status overall_power_status; struct power_supply_status ps_status[2]; struct voltage_sensor_status overall_voltage_status; struct voltage_sensor_set voltage_sensor_sets[2]; struct sas_connector_status overall_sas_connector_status; struct sas_connector_status sas_connector_status[4]; struct scc_controller_overall_status overall_scc_controller_status; struct scc_controller_element_status scc_controller_status[2]; struct midplane_status overall_midplane_status; struct midplane_status midplane_element_status; }

user_defined_types: struct disk_status { struct element_status_byte0 byte0; union { struct overall_disk_status_byte1 overall_status; struct disk_element_status_byte1 element_status; } byte1; unsigned char app_client_bypassed_a; unsigned char do_not_remove; unsigned char enclosure_bypassed_a; unsigned char enclosure_bypassed_b; unsigned char ready_to_insert; unsigned char rmv; unsigned char ident; unsigned char report; unsigned char app_client_bypassed_b; unsigned char fault_sensed; unsigned char fail; unsigned char device_off; unsigned char bypassed_a; unsigned char bypassed_b; unsigned char device_bypassed_a; unsigned char device_bypassed_b; }


decompiled_code:
__int64 __fastcall roll_up_esm_status(__int64 a1)
{
return composite_status((_BYTE *)(a1 + 144), 2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return func9((_BYTE *)(a1 + 144), 2);
}

original_code:
enum element_status_code
roll_up_esm_status(const struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->esm_status, 2);
}

canonical_original_code:
enum element_status_code roll_up_esm_status(struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->esm_status, 2);
}

user_defined_types: struct enclosure_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char reserved3; unsigned char fail; unsigned char warning_indication; unsigned char reserved4; unsigned char failure_requested; unsigned char warning_requested; }

user_defined_types: struct esm_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char report; unsigned char hot_swap; unsigned char reserved4; }

user_defined_types: struct temperature_sensor_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char temperature; unsigned char reserved3; unsigned char ot_failure; unsigned char ot_warning; unsigned char ut_failure; unsigned char ut_warning; }

user_defined_types: struct fan_status { struct element_status_byte0 byte0; unsigned short ident; unsigned short reserved2; unsigned short fan_speed; unsigned char hot_swap; unsigned char fail; unsigned char rqsted_on; unsigned char off; unsigned char reserved3; unsigned char speed_code; }

user_defined_types: struct power_supply_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char reserved3; unsigned char dc_over_voltage; unsigned char dc_under_voltage; unsigned char dc_over_current; unsigned char reserved4; unsigned char hot_swap; unsigned char fail; unsigned char rqsted_on; unsigned char off; unsigned char ovrtmp_fail; unsigned char temp_warn; unsigned char ac_fail; unsigned char dc_fail; }

user_defined_types: struct voltage_sensor_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char warn_over; unsigned char warn_under; unsigned char crit_over; unsigned char crit_under; short voltage; }

user_defined_types: struct sas_connector_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char connector_type; unsigned char connector_physical_link; unsigned char reserved2; unsigned char fail; unsigned char reserved3; }

user_defined_types: struct scc_controller_overall_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char reserved4; }

user_defined_types: struct midplane_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char reserved4; }

user_defined_types: struct temperature_sensor_set { struct temperature_sensor_status croc; struct temperature_sensor_status ppc; struct temperature_sensor_status expander; struct temperature_sensor_status ambient[2]; struct temperature_sensor_status power_supply[2]; }

user_defined_types: struct fan_set { struct fan_status power_supply; struct fan_status fan_element[4]; }

user_defined_types: struct voltage_sensor_set { struct voltage_sensor_status sensor_12V; struct voltage_sensor_status sensor_3_3VA; }

user_defined_types: struct scc_controller_element_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char report; unsigned char reserved4; }

user_defined_types: struct overall_disk_status_byte1 { unsigned char device_environment; unsigned char slot_address; }

user_defined_types: struct disk_element_status_byte1 { unsigned char hot_swap; unsigned char slot_address; }


decompiled_code:
__int64 __fastcall roll_up_temperature_sensor_status(__int64 a1)
{
return composite_status((_BYTE *)(a1 + 156), 14);
}

original_code:
enum element_status_code
roll_up_temperature_sensor_status(const struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->temp_sensor_sets, 2 * 7);
}

canonical_original_code:
enum element_status_code roll_up_temperature_sensor_status(struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->temp_sensor_sets, 2 * 7);
}

user_defined_types: enum element_status_code { ES_UNSUPPORTED=0, ES_OK=1, ES_CRITICAL=2, ES_NONCRITICAL=3, ES_UNRECOVERABLE=4, ES_NOT_INSTALLED=5, ES_UNKNOWN=6, ES_NOT_AVAILABLE=7, ES_NO_ACCESS_ALLOWED=8, ES_EOL=9 }

user_defined_types: struct bluehawk_diag_page2 { unsigned char page_code; unsigned char reserved1; unsigned char invop; unsigned char info; unsigned char non_crit; unsigned char crit; unsigned char unrecov; unsigned short page_length; unsigned int generation_code; struct disk_status overall_disk_status; struct disk_status disk_status[30]; struct enclosure_status overall_enclosure_status; struct enclosure_status enclosure_element_status; struct esm_status overall_esm_status; struct esm_status esm_status[2]; struct temperature_sensor_status overall_temp_sensor_status; struct temperature_sensor_set temp_sensor_sets[2]; struct fan_status overall_fan_status; struct fan_set fan_sets[2]; struct power_supply_status overall_power_status; struct power_supply_status ps_status[2]; struct voltage_sensor_status overall_voltage_status; struct voltage_sensor_set voltage_sensor_sets[2]; struct sas_connector_status overall_sas_connector_status; struct sas_connector_status sas_connector_status[4]; struct scc_controller_overall_status overall_scc_controller_status; struct scc_controller_element_status scc_controller_status[2]; struct midplane_status overall_midplane_status; struct midplane_status midplane_element_status; }

user_defined_types: struct element_status_byte0 { unsigned char reserved1; unsigned char prdfail; unsigned char disabled; unsigned char swap; unsigned char status; }


decompiled_code:
__int64 __fastcall roll_up_fan_status(__int64 a1)
{
return composite_status((_BYTE *)(a1 + 216), 10);
}

original_code:
enum element_status_code
roll_up_fan_status(const struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->fan_sets, 2 * 5);
}

canonical_original_code:
enum element_status_code roll_up_fan_status(struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->fan_sets, 2 * 5);
}

user_defined_types: struct disk_status { struct element_status_byte0 byte0; union { struct overall_disk_status_byte1 overall_status; struct disk_element_status_byte1 element_status; } byte1; unsigned char app_client_bypassed_a; unsigned char do_not_remove; unsigned char enclosure_bypassed_a; unsigned char enclosure_bypassed_b; unsigned char ready_to_insert; unsigned char rmv; unsigned char ident; unsigned char report; unsigned char app_client_bypassed_b; unsigned char fault_sensed; unsigned char fail; unsigned char device_off; unsigned char bypassed_a; unsigned char bypassed_b; unsigned char device_bypassed_a; unsigned char device_bypassed_b; }

user_defined_types: struct enclosure_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char reserved3; unsigned char fail; unsigned char warning_indication; unsigned char reserved4; unsigned char failure_requested; unsigned char warning_requested; }

user_defined_types: struct esm_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char report; unsigned char hot_swap; unsigned char reserved4; }


decompiled_code:
__int64 __fastcall roll_up_power_supply_status(__int64 a1)
{
return composite_status((_BYTE *)(a1 + 260), 2);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return func9((_BYTE *)(a1 + 260), 2);
}

original_code:
enum element_status_code
roll_up_power_supply_status(const struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->ps_status, 2);
}

canonical_original_code:
enum element_status_code roll_up_power_supply_status(struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->ps_status, 2);
}

user_defined_types: struct temperature_sensor_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char temperature; unsigned char reserved3; unsigned char ot_failure; unsigned char ot_warning; unsigned char ut_failure; unsigned char ut_warning; }

user_defined_types: struct fan_status { struct element_status_byte0 byte0; unsigned short ident; unsigned short reserved2; unsigned short fan_speed; unsigned char hot_swap; unsigned char fail; unsigned char rqsted_on; unsigned char off; unsigned char reserved3; unsigned char speed_code; }

user_defined_types: struct power_supply_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char reserved3; unsigned char dc_over_voltage; unsigned char dc_under_voltage; unsigned char dc_over_current; unsigned char reserved4; unsigned char hot_swap; unsigned char fail; unsigned char rqsted_on; unsigned char off; unsigned char ovrtmp_fail; unsigned char temp_warn; unsigned char ac_fail; unsigned char dc_fail; }


decompiled_code:
__int64 __fastcall roll_up_voltage_sensor_status(__int64 a1)
{
return composite_status((_BYTE *)(a1 + 272), 4);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return func9((_BYTE *)(a1 + 272), 4);
}

original_code:
enum element_status_code
roll_up_voltage_sensor_status(const struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->voltage_sensor_sets, 2 * 2);
}

canonical_original_code:
enum element_status_code roll_up_voltage_sensor_status(struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->voltage_sensor_sets, 2 * 2);
}

user_defined_types: struct voltage_sensor_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char reserved2; unsigned char warn_over; unsigned char warn_under; unsigned char crit_over; unsigned char crit_under; short voltage; }

user_defined_types: struct sas_connector_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char connector_type; unsigned char connector_physical_link; unsigned char reserved2; unsigned char fail; unsigned char reserved3; }

user_defined_types: struct scc_controller_overall_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char reserved4; }


decompiled_code:
__int64 __fastcall roll_up_sas_connector_status(__int64 a1)
{
return composite_status((_BYTE *)(a1 + 292), 4);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
return func9((_BYTE *)(a1 + 292), 4);
}

original_code:
enum element_status_code
roll_up_sas_connector_status(const struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->sas_connector_status, 4);
}

canonical_original_code:
enum element_status_code roll_up_sas_connector_status(struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->sas_connector_status, 4);
}

user_defined_types: struct midplane_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char reserved4; }

user_defined_types: struct temperature_sensor_set { struct temperature_sensor_status croc; struct temperature_sensor_status ppc; struct temperature_sensor_status expander; struct temperature_sensor_status ambient[2]; struct temperature_sensor_status power_supply[2]; }

user_defined_types: struct fan_set { struct fan_status power_supply; struct fan_status fan_element[4]; }


decompiled_code:
__int64 __fastcall roll_up_scc_controller_status(__int64 a1)
{
return composite_status((_BYTE *)(a1 + 312), 2);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
return func9((_BYTE *)(a1 + 312), 2);
}

original_code:
enum element_status_code
roll_up_scc_controller_status(const struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->scc_controller_status, 2);
}

canonical_original_code:
enum element_status_code roll_up_scc_controller_status(struct bluehawk_diag_page2 *pg)
{
 return composite_status(&pg->scc_controller_status, 2);
}

user_defined_types: struct voltage_sensor_set { struct voltage_sensor_status sensor_12V; struct voltage_sensor_status sensor_3_3VA; }

user_defined_types: struct scc_controller_element_status { struct element_status_byte0 byte0; unsigned char ident; unsigned char fail; unsigned char reserved2; unsigned char reserved3; unsigned char report; unsigned char reserved4; }

user_defined_types: struct overall_disk_status_byte1 { unsigned char device_environment; unsigned char slot_address; }


decompiled_code:
unsigned __int64 __fastcall mean_temperature(__int64 a1)
{
unsigned __int8 *v1; // rax
unsigned int v2; // edx
unsigned __int8 *v3; // rdi
int v4; // ecx

v1 = (unsigned __int8 *)(a1 + 158);
v2 = 0;
v3 = (unsigned __int8 *)(a1 + 214);
do
{
v4 = *v1;
v1 += 4;
v2 += v4;
}
while ( v3 != v1 );
return v2 / 0xEuLL;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func18(__int64 a1)
{
unsigned __int8 *v1; // rax
unsigned int v2; // edx
unsigned __int8 *v3; // rdi
int v4; // ecx

v1 = (unsigned __int8 *)(a1 + 158);
v2 = 0;
v3 = (unsigned __int8 *)(a1 + 214);
do
{
v4 = *v1;
v1 += 4;
v2 += v4;
}
while ( v3 != v1 );
return v2 / 0xEuLL;
}

original_code:
unsigned int
mean_temperature(const struct bluehawk_diag_page2 *pg)
{
 struct temperature_sensor_status *sensors =
    (struct temperature_sensor_status *)
    &pg->temp_sensor_sets;
 int sum = 0;
 int i;
 for (i = 0; i < 2*7; i++)
  sum += sensors[i].temperature;
 return sum / (2*7);
}

canonical_original_code:
unsigned int mean_temperature(struct bluehawk_diag_page2 *pg)
{
 struct temperature_sensor_status *sensors = (struct temperature_sensor_status *)
    &pg->temp_sensor_sets;
 int sum = 0;
 int i;
 for (i = 0; i < 2*7; i++)
  sum += sensors[i].temperature;
 return sum / (2*7);
}

variable_types: struct temperature_sensor_status { struct element_status_byte0 { unsigned char reserved1; unsigned char prdfail; unsigned char disabled; unsigned char swap; unsigned char status; } byte0; unsigned char ident; unsigned char reserved2; unsigned char temperature; unsigned char reserved3; unsigned char ot_failure; unsigned char ot_warning; unsigned char ut_failure; unsigned char ut_warning; } *

variable_types: sum int

return_type: unsigned int

user_defined_types: struct bluehawk_diag_page2 { unsigned char page_code; unsigned char reserved1; unsigned char invop; unsigned char info; unsigned char non_crit; unsigned char crit; unsigned char unrecov; unsigned short page_length; unsigned int generation_code; struct disk_status overall_disk_status; struct disk_status disk_status[30]; struct enclosure_status overall_enclosure_status; struct enclosure_status enclosure_element_status; struct esm_status overall_esm_status; struct esm_status esm_status[2]; struct temperature_sensor_status overall_temp_sensor_status; struct temperature_sensor_set temp_sensor_sets[2]; struct fan_status overall_fan_status; struct fan_set fan_sets[2]; struct power_supply_status overall_power_status; struct power_supply_status ps_status[2]; struct voltage_sensor_status overall_voltage_status; struct voltage_sensor_set voltage_sensor_sets[2]; struct sas_connector_status overall_sas_connector_status; struct sas_connector_status sas_connector_status[4]; struct scc_controller_overall_status overall_scc_controller_status; struct scc_controller_element_status scc_controller_status[2]; struct midplane_status overall_midplane_status; struct midplane_status midplane_element_status; }

user_defined_types: struct disk_element_status_byte1 { unsigned char hot_swap; unsigned char slot_address; }


decompiled_code:
int __fastcall print_usage(const char *a1)
{
return printf(
"Usage: %s --context <x> --from <y> --to <z> <value>\n"
"\t--context: currently, <x> must be cpu\n"
"\t--from and --to: allowed values for <y> and <z>:\n"
"\t\tinterrupt-server\n"
"\t\tdrc-index\n"
"\t\tdrc-name\n"
"\tif <value> is a drc-index or interrupt-server, it can be\n"
"\tspecified in decimal, hex (with a leading 0x), or octal\n"
"\t(with a leading 0); if it is a drc-name, it should be\n"
"\tspecified as a string in double quotes\n"
"\n",
a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return printf(
"Usage: %s --context <x> --from <y> --to <z> <value>\n"
"\t--context: currently, <x> must be cpu\n"
"\t--from and --to: allowed values for <y> and <z>:\n"
"\t\tinterrupt-server\n"
"\t\tdrc-index\n"
"\t\tdrc-name\n"
"\tif <value> is a drc-index or interrupt-server, it can be\n"
"\tspecified in decimal, hex (with a leading 0x), or octal\n"
"\t(with a leading 0); if it is a drc-name, it should be\n"
"\tspecified as a string in double quotes\n"
"\n",
a1);
}

original_code:
void
print_usage(char *command) {
 printf ("Usage: %s --context <x> --from <y> --to <z> <value>\n"
  "\t--context: currently, <x> must be cpu\n"
  "\t--from and --to: allowed values for <y> and <z>:\n"
  "\t\tinterrupt-server\n\t\tdrc-index\n\t\tdrc-name\n"
  "\tif <value> is a drc-index or interrupt-server, it can be\n"
  "\tspecified in decimal, hex (with a leading 0x), or octal\n"
  "\t(with a leading 0); if it is a drc-name, it should be\n"
  "\tspecified as a string in double quotes\n\n",
  command);
 return;
}

variable_types:
command
char *