decompiled_code:
__int64 mbus_transmit()
{
__int64 result; // rax
char v1; // cl

result = (unsigned __int8)buf_pos;
if ( (mbus_status & 1) == 0 )
{
result = (unsigned int)(unsigned __int8)buf_pos + 1;
v1 = *((_BYTE *)&buf + (unsigned __int8)buf_pos);
mbus_status |= 1u;
++buf_pos;
mbus_out_byte = v1;
}
if ( buf_cnt == (_BYTE)result )
{
mb_state &= 0xFEu;
buf_pos = 0;
buf_cnt = 8;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
char v1; // cl

result = (unsigned __int8)buf_pos;
if ( (mbus_status & 1) == 0 )
{
result = (unsigned int)(unsigned __int8)buf_pos + 1;
v1 = *((_BYTE *)&buf + (unsigned __int8)buf_pos);
mbus_status |= 1u;
++buf_pos;
mbus_out_byte = v1;
}
if ( buf_cnt == (_BYTE)result )
{
mb_state &= 0xFEu;
buf_pos = 0;
buf_cnt = 8;
}
return result;
}

original_code:
static void mbus_transmit(void)
{
    uint8_t sts, bpos = buf_pos, next=buf.b_b[bpos];
    {
        sts = mbus_status;
        if(!(sts&0x01)) {
            mbus_status = sts|0x01;
            mbus_out_byte = next;
        }
    }
    if(!(sts&0x01)) {
        bpos++;
        buf_pos=bpos;
    }
    if(buf_pos==buf_cnt) {
        mb_state &= ~1;
        buf_pos = 0;
        buf_cnt = 8;
    }
}

canonical_original_code:
static void mbus_transmit()
{
    unsigned char sts; unsigned char bpos = buf_pos; unsigned char next = buf.b_b[bpos];
    {
        sts = mbus_status;
        if(!(sts&0x01)) {
            mbus_status = sts|0x01;
            mbus_out_byte = next;
        }
    }
    if(!(sts&0x01)) {
        bpos++;
        buf_pos=bpos;
    }
    if(buf_pos==buf_cnt) {
        mb_state &= ~1;
        buf_pos = 0;
        buf_cnt = 8;
    }
}

variable_types:
sts
unsigned char

variable_types:
bpos
unsigned char

variable_types:
next
unsigned char


repo: mdavidsaver/avr

decompiled_code:
void mbus_rx_clear()
{
buf_cnt = 8;
buf_pos = 0;
}

canonical_decompiled_code:
void func3()
{
buf_cnt = 8;
buf_pos = 0;
}

original_code:
void mbus_rx_clear(void)
{
    buf_cnt = 8;
    buf_pos = 0;
}

return_type: void


decompiled_code:
void mbus_reset()
{
__int16 v0; // ax

mbus_rx_clear();
mbus_status = 0;
err_cnt = 0;
mbus_out_byte = 0;
qword_3F0 = 0LL;
mbus_in_byte = 0;
word_3F8 = v0;
buf = 0LL;
}

canonical_decompiled_code:
void func4()
{
__int16 v0; // ax

func3();
mbus_status = 0;
err_cnt = 0;
mbus_out_byte = 0;
qword_3F0 = 0LL;
mbus_in_byte = 0;
word_3F8 = v0;
buf = 0LL;
}

original_code:
void mbus_reset(void)
{
    {
        mbus_rx_clear();
        mbus_status = 0;
        mbus_in_byte = mbus_out_byte = 0;
        err_cnt = 0;
        memset(buf.b_b, 0, sizeof(buf));
    }
}

canonical_original_code:
void mbus_reset()
{
    {
        mbus_rx_clear();
        mbus_status = 0;
        mbus_in_byte = mbus_out_byte = 0;
        err_cnt = 0;
        memset(buf.b_b, 0, sizeof(buf));
    }
}


decompiled_code:
__int64 __fastcall calculate_crc(unsigned __int8 *a1, unsigned __int8 a2)
{
__int64 result; // rax
unsigned __int8 *v3; // rbp
unsigned __int8 *v4; // rbx
__int64 v5; // rsi

if ( !a2 )
return 0xFFFFFFFFLL;
LOWORD(result) = -1;
v3 = &a1[a2];
v4 = a1;
do
{
v5 = *v4++;
result = crc16_update((unsigned __int16)result, v5);
}
while ( v4 != v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1, unsigned __int8 a2)
{
__int64 result; // rax
unsigned __int8 *v3; // rbp
unsigned __int8 *v4; // rbx
__int64 v5; // rsi

if ( !a2 )
return 0xFFFFFFFFLL;
LOWORD(result) = -1;
v3 = &a1[a2];
v4 = a1;
do
{
v5 = *v4++;
result = crc16_update((unsigned __int16)result, v5);
}
while ( v4 != v3 );
return result;
}

original_code:
uint16_t calculate_crc(const uint8_t* d, uint8_t c)
{
    uint16_t r=0xffff;
    while(c--)
        r=_crc16_update(r, *d++);
    return r;
}

canonical_original_code:
unsigned short calculate_crc(unsigned char *d, unsigned char c)
{
    unsigned short r = 0xffff;
    while(c--)
        r=_crc16_update(r, *d++);
    return r;
}

variable_types:
d
unsigned char *

variable_types:
c
unsigned char

variable_types:
r
unsigned short

return_type: unsigned short


decompiled_code:
__int64 __fastcall mbus_exception(int a1)
{
unsigned int v2; // edi
int v3; // edi
__int64 result; // rax

mb_state |= 1u;
BYTE2(buf) = a1;
v2 = BYTE1(buf) | 0xFFFFFF80;
++err_cnt;
BYTE1(buf) = v2;
LOBYTE(v2) = buf + v2;
buf_cnt = 4;
v3 = -(a1 + v2);
result = (unsigned __int8)mbus_status | 4u;
BYTE3(buf) = v3;
mbus_status |= 4u;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
unsigned int v2; // edi
int v3; // edi
__int64 result; // rax

mb_state |= 1u;
BYTE2(buf) = a1;
v2 = BYTE1(buf) | 0xFFFFFF80;
++err_cnt;
BYTE1(buf) = v2;
LOBYTE(v2) = buf + v2;
buf_cnt = 4;
v3 = -(a1 + v2);
result = (unsigned __int8)mbus_status | 4u;
BYTE3(buf) = v3;
mbus_status |= 4u;
return result;
}

original_code:
void mbus_exception(uint8_t code)
{
    uint8_t sum= buf.b_p.node;
    buf.b_p.function |= 0x80;
    sum += buf.b_p.function;
    buf.b_p.mb_e.code = code;
    sum += code;
    buf.b_p.mb_e.lrc = (~sum)+1;
    buf_cnt = 4;
    mb_state |= 1;
    err_cnt++;
    {
        mbus_status |= 0x04;
    }
}

canonical_original_code:
void mbus_exception(unsigned char code)
{
    unsigned char sum = buf.b_p.node;
    buf.b_p.function |= 0x80;
    sum += buf.b_p.function;
    buf.b_p.mb_e.code = code;
    sum += code;
    buf.b_p.mb_e.lrc = (~sum)+1;
    buf_cnt = 4;
    mb_state |= 1;
    err_cnt++;
    {
        mbus_status |= 0x04;
    }
}

variable_types:
code
unsigned char

variable_types:
sum
unsigned char


decompiled_code:
__int64 mbus_dispatch()
{
__int16 v0; // ax
__int16 v1; // dx
unsigned __int16 v2; // ax
unsigned __int8 v3; // bl
__int64 v4; // rsi
unsigned __int16 v5; // ax
__int64 v6; // rdx
__int16 v7; // ax
__int64 v8; // rcx
int v9; // eax
unsigned __int16 v10; // ax
__int16 v11; // ax
__int64 v12; // rsi
unsigned __int16 v13; // ax
__int64 result; // rax

calculate_crc((unsigned __int8 *)&buf, buf_cnt - 2);
v0 = _uint16_identity(WORD3(buf));
if ( v0 == v1 )
{
v2 = _bswap_16(SWORD2(buf));
v3 = v2;
if ( BYTE1(buf) == 3 )
{
if ( v2 > 0xAu )
{
mbus_exception(3);
}
else
{
v4 = (unsigned __int8)v2;
v5 = _bswap_16(SWORD1(buf));
mbus_read_holding(v5, v4);
}
v6 = 0LL;
if ( v3 )
{
do
{
v7 = _bswap_16(*(_WORD *)((char *)&buf + v6 + 3));
*(_WORD *)((char *)&buf + v6 + 1) = v7;
}
while ( v8 != v6 );
}
v9 = (unsigned __int8)mb_state;
if ( (mb_state & 1) == 0 )
{
BYTE2(buf) = 2 * v3;
v10 = calculate_crc((unsigned __int8 *)&buf, 2 * v3 + 3);
v11 = _uint16_identity(v10);
buf_cnt = 2 * v3 + 5;
*(_WORD *)((char *)&buf + 2 * v3 + 3) = v11;
v9 = (unsigned __int8)mb_state;
}
}
else
{
v12 = v2;
v13 = _bswap_16(SWORD1(buf));
mbus_write_holding(v13, v12);
v9 = (unsigned __int8)mb_state;
}
result = v9 | 1u;
mb_state = result;
}
else
{
mbus_exception(4);
result = (unsigned __int8)mb_state | 1u;
mb_state |= 1u;
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int16 v0; // ax
__int16 v1; // dx
unsigned __int16 v2; // ax
unsigned __int8 v3; // bl
__int64 v4; // rsi
unsigned __int16 v5; // ax
__int64 v6; // rdx
__int16 v7; // ax
__int64 v8; // rcx
int v9; // eax
unsigned __int16 v10; // ax
__int16 v11; // ax
__int64 v12; // rsi
unsigned __int16 v13; // ax
__int64 result; // rax

func5((unsigned __int8 *)&buf, buf_cnt - 2);
v0 = func0(WORD3(buf));
if ( v0 == v1 )
{
v2 = func2(SWORD2(buf));
v3 = v2;
if ( BYTE1(buf) == 3 )
{
if ( v2 > 0xAu )
{
func6(3);
}
else
{
v4 = (unsigned __int8)v2;
v5 = func2(SWORD1(buf));
mbus_read_holding(v5, v4);
}
v6 = 0LL;
if ( v3 )
{
do
{
v7 = func2(*(_WORD *)((char *)&buf + v6 + 3));
*(_WORD *)((char *)&buf + v6 + 1) = v7;
}
while ( v8 != v6 );
}
v9 = (unsigned __int8)mb_state;
if ( (mb_state & 1) == 0 )
{
BYTE2(buf) = 2 * v3;
v10 = func5((unsigned __int8 *)&buf, 2 * v3 + 3);
v11 = func0(v10);
buf_cnt = 2 * v3 + 5;
*(_WORD *)((char *)&buf + 2 * v3 + 3) = v11;
v9 = (unsigned __int8)mb_state;
}
}
else
{
v12 = v2;
v13 = func2(SWORD1(buf));
mbus_write_holding(v13, v12);
v9 = (unsigned __int8)mb_state;
}
result = v9 | 1u;
mb_state = result;
}
else
{
func6(4);
result = (unsigned __int8)mb_state | 1u;
mb_state |= 1u;
}
return result;
}

original_code:
static void mbus_dispatch(void)
{
    uint16_t crc=calculate_crc(buf.b_b, buf_cnt-2);
    if(__uint16_identity (buf.b_p.mb_s.crc)!=crc) {
        mbus_exception(4);
    } else if(buf.b_p.function==3) {
        uint16_t count = __bswap_16 (buf.b_p.mb_s.data);
        uint8_t cnt = count;
        if(count>20/2)
            mbus_exception(3);
        else
            mbus_read_holding(__bswap_16 (buf.b_p.mb_s.addr),
                              cnt,
                              buf.b_p.mb_m.data);
        {
            size_t i;
            for(i=0; i<cnt; i++)
                buf.b_p.mb_m.data[i] = __bswap_16 (buf.b_p.mb_m.data[i]);
        }
        if(!(mb_state&1)) {
            buf.b_p.mb_m.count = 2*cnt;
            buf.b_p.mb_m.data[cnt] = __uint16_identity (calculate_crc(buf.b_b, 3+2*cnt));
            buf_cnt = 5+2*cnt;
        }
    } else {
        mbus_write_holding(__bswap_16 (buf.b_p.mb_s.addr),
                           __bswap_16 (buf.b_p.mb_s.data));
    }
    mb_state |= 1;
}

canonical_original_code:
static void mbus_dispatch()
{
    unsigned short crc = calculate_crc(buf.b_b, buf_cnt-2);
    if(__uint16_identity (buf.b_p.mb_s.crc)!=crc) {
        mbus_exception(4);
    } else if(buf.b_p.function==3) {
        unsigned short count = __bswap_16 (buf.b_p.mb_s.data);
        unsigned char cnt = count;
        if(count>20/2)
            mbus_exception(3);
        else
            mbus_read_holding(__bswap_16 (buf.b_p.mb_s.addr),
                              cnt,
                              buf.b_p.mb_m.data);
        {
            unsigned long i;
            for(i=0; i<cnt; i++)
                buf.b_p.mb_m.data[i] = __bswap_16 (buf.b_p.mb_m.data[i]);
        }
        if(!(mb_state&1)) {
            buf.b_p.mb_m.count = 2*cnt;
            buf.b_p.mb_m.data[cnt] = __uint16_identity (calculate_crc(buf.b_b, 3+2*cnt));
            buf_cnt = 5+2*cnt;
        }
    } else {
        mbus_write_holding(__bswap_16 (buf.b_p.mb_s.addr),
                           __bswap_16 (buf.b_p.mb_s.data));
    }
    mb_state |= 1;
}

variable_types:
crc
unsigned short

variable_types:
count
unsigned short

variable_types:
cnt
unsigned char

variable_types:
i
unsigned long


decompiled_code:
void mbus_recieve()
{
char v0; // al
char v1; // bl
bool v2; // zf

v0 = mbus_status;
mbus_status &= 0xFDu;
if ( (v0 & 2) != 0 )
{
v1 = buf_pos + 1;
v2 = buf_cnt == (char)(buf_pos + 1);
*((_BYTE *)&buf + (unsigned __int8)buf_pos) = mbus_in_byte;
if ( v2 )
{
mbus_dispatch();
if ( (mb_state & 1) != 0 )
{
LABEL_5:
buf_pos = 1;
mbus_status |= 1u;
mbus_out_byte = buf;
return;
}
}
else
{
if ( v1 == 2 && BYTE1(buf) != 3 && BYTE1(buf) != 6 )
mbus_exception(1);
if ( (mb_state & 1) != 0 )
goto LABEL_5;
}
buf_pos = v1;
}
else
{
mbus_rx_clear();
}
}

canonical_decompiled_code:
void func8()
{
char v0; // al
char v1; // bl
bool v2; // zf

v0 = mbus_status;
mbus_status &= 0xFDu;
if ( (v0 & 2) != 0 )
{
v1 = buf_pos + 1;
v2 = buf_cnt == (char)(buf_pos + 1);
*((_BYTE *)&buf + (unsigned __int8)buf_pos) = mbus_in_byte;
if ( v2 )
{
func7();
if ( (mb_state & 1) != 0 )
{
LABEL_5:
buf_pos = 1;
mbus_status |= 1u;
mbus_out_byte = buf;
return;
}
}
else
{
if ( v1 == 2 && BYTE1(buf) != 3 && BYTE1(buf) != 6 )
func6(1);
if ( (mb_state & 1) != 0 )
goto LABEL_5;
}
buf_pos = v1;
}
else
{
func3();
}
}

original_code:
static void mbus_recieve(void)
{
    uint8_t next, sts;
    {
        sts = mbus_status;
        mbus_status = sts & ~0x02;
        next = mbus_in_byte;
    }
    if(!(sts&0x02)) {
        mbus_rx_clear();
        return;
    }
    uint8_t bpos = buf_pos;
    buf.b_b[bpos++] = next;
    if(bpos==buf_cnt) {
        mbus_dispatch();
    } else if(bpos==2) {
        if(buf.b_p.function!=3 && buf.b_p.function!=6) {
            mbus_exception(1);
        }
    }
    if(mb_state&1) {
        buf_pos = 1;
        {
            mbus_status |= 0x01;
            mbus_out_byte = buf.b_b[0];
        }
    }else
        buf_pos = bpos;
}

canonical_original_code:
static void mbus_recieve()
{
    unsigned char next; unsigned char sts;
    {
        sts = mbus_status;
        mbus_status = sts & ~0x02;
        next = mbus_in_byte;
    }
    if(!(sts&0x02)) {
        mbus_rx_clear();
        return;
    }
    unsigned char bpos = buf_pos;
    buf.b_b[bpos++] = next;
    if(bpos==buf_cnt) {
        mbus_dispatch();
    } else if(bpos==2) {
        if(buf.b_p.function!=3 && buf.b_p.function!=6) {
            mbus_exception(1);
        }
    }
    if(mb_state&1) {
        buf_pos = 1;
        {
            mbus_status |= 0x01;
            mbus_out_byte = buf.b_b[0];
        }
    }else
        buf_pos = bpos;
}


decompiled_code:
void mbus_process()
{
if ( (mb_state & 1) != 0 )
mbus_transmit();
else
mbus_recieve();
}

canonical_decompiled_code:
void func9()
{
if ( (mb_state & 1) != 0 )
func1();
else
func8();
}

original_code:
void mbus_process(void)
{
    if(mb_state&1)
        mbus_transmit();
    else
        mbus_recieve();
}

canonical_original_code:
void mbus_process()
{
    if(mb_state&1)
        mbus_transmit();
    else
        mbus_recieve();
}


repo: mdcja/prometheus

decompiled_code:
__int64 __fastcall generate_prime(int a1)
{
__int64 v2; // r12
_QWORD *v3; // rdi
__int64 result; // rax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = 0;
if ( (unsigned int)a1 <= 2 )
{
error_code = 5;
error_print("generate_prime");
result = 0LL;
}
else
{
v2 = 0LL;
v3 = sieve_eratosthenes_constprop_0(a1, v5);
if ( v5[0] > 0 )
{
if ( a1 > 2 )
{
v2 = a1;
while ( *((_DWORD *)v3 + v2) )
{
if ( --v2 == 2 )
{
v2 = 0LL;
free(v3);
goto LABEL_8;
}
}
}
free(v3);
}
LABEL_8:
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 v2; // r12
_QWORD *v3; // rdi
__int64 result; // rax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = 0;
if ( (unsigned int)a1 <= 2 )
{
error_code = 5;
error_print("generate_prime");
result = 0LL;
}
else
{
v2 = 0LL;
v3 = sieve_eratosthenes_constprop_0(a1, v5);
if ( v5[0] > 0 )
{
if ( a1 > 2 )
{
v2 = a1;
while ( *((_DWORD *)v3 + v2) )
{
if ( --v2 == 2 )
{
v2 = 0LL;
free(v3);
goto LABEL_8;
}
}
}
free(v3);
}
LABEL_8:
result = v2;
}
return result;
}

original_code:
unsigned long generate_prime( unsigned int limit )
{
    int largest_prime = 0;
    int prime_count = 0;
    int * sieve = ((void *)0);
    int i = 0;
    if( limit <= 2 )
    {
        error_code = ERROR_INVALID_CAPACITY;
        error_print( "generate_prime" );
        return 0;
    }
    sieve = sieve_eratosthenes( limit, &prime_count );
    if( prime_count <= 0 )
    {
        return 0;
    }
    for( i = limit; i > 2; --i )
    {
        if( sieve[ i ] == 0 )
        {
            largest_prime = i;
            break;
        }
    }
    free( sieve );
    sieve = ((void *)0);
    return (unsigned int)largest_prime;
}

canonical_original_code:
unsigned long generate_prime(unsigned int limit)
{
    int largest_prime = 0;
    int prime_count = 0;
    int *sieve = ((void *)0);
    int i = 0;
    if( limit <= 2 )
    {
        error_code = ERROR_INVALID_CAPACITY;
        error_print( "generate_prime" );
        return 0;
    }
    sieve = sieve_eratosthenes( limit, &prime_count );
    if( prime_count <= 0 )
    {
        return 0;
    }
    for( i = limit; i > 2; --i )
    {
        if( sieve[ i ] == 0 )
        {
            largest_prime = i;
            break;
        }
    }
    free( sieve );
    sieve = ((void *)0);
    return (unsigned int)largest_prime;
}

variable_types:
limit
unsigned int

variable_types:
sieve
int *

variable_types: i int

return_type: unsigned long


decompiled_code:
__int64 __fastcall random_number(int a1, int a2)
{
unsigned int v2; // eax

v2 = time(0LL);
srand(v2);
return (unsigned int)(rand() % (a2 - a1) + a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
unsigned int v2; // eax

v2 = time(0LL);
srand(v2);
return (unsigned int)(rand() % (a2 - a1) + a1);
}

original_code:
int random_number( int min, int max )
{
    static int is_seeded = 0;
    if( !is_seeded )
    {
        srand( time( ((void *)0) ) );
    }
    return (rand() % ( max - min )) + min;
}

canonical_original_code:
int random_number(int min, int max)
{
    static int is_seeded = 0;
    if( !is_seeded )
    {
        srand( time( ((void *)0) ) );
    }
    return (rand() % ( max - min )) + min;
}

variable_types: min int

variable_types: max int

return_type: int


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

switch ( a1 )
{
case 0:
result = "no error";
break;
case 2:
result = "memory allocation failed";
break;
case 3:
result = "null parameter";
break;
case 4:
result = "not found";
break;
case 5:
result = "invalid capacity";
break;
case 6:
result = "not implemented";
break;
case 7:
result = "overflow";
break;
case 8:
result = "underflow";
break;
default:
result = "unknown";
break;
}
return result;
}

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

switch ( a1 )
{
case 0:
result = "no error";
break;
case 2:
result = "memory allocation failed";
break;
case 3:
result = "null parameter";
break;
case 4:
result = "not found";
break;
case 5:
result = "invalid capacity";
break;
case 6:
result = "not implemented";
break;
case 7:
result = "overflow";
break;
case 8:
result = "underflow";
break;
default:
result = "unknown";
break;
}
return result;
}

original_code:
static char * error_name( error_t error )
{
    static char * error_names[ 256 ] = {
        "no error",
        "unknown",
        "memory allocation failed",
        "null parameter",
        "not found",
        "invalid capacity",
        "not implemented",
        "overflow",
        "underflow"
    };
    switch( error )
    {
    case ERROR_NO_ERROR:
        return error_names[ ERROR_NO_ERROR ];
    case ERROR_MEMORY_ALLOCATION_FAILED:
        return error_names[ ERROR_MEMORY_ALLOCATION_FAILED ];
    case ERROR_NULL_PARAMETER:
        return error_names[ ERROR_NULL_PARAMETER ];
    case ERROR_NOT_FOUND:
        return error_names[ ERROR_NOT_FOUND ];
    case ERROR_INVALID_CAPACITY:
        return error_names[ ERROR_INVALID_CAPACITY ];
    case ERROR_NOT_IMPLEMENTED:
        return error_names[ ERROR_NOT_IMPLEMENTED ];
    case ERROR_OVERFLOW:
        return error_names[ ERROR_OVERFLOW ];
    case ERROR_UNDERFLOW:
        return error_names[ ERROR_UNDERFLOW ];
    default:
        return error_names[ ERROR_UNKNOWN ];
    }
}

canonical_original_code:
static char *error_name(enum _errors error)
{
    static char *error_names[256] = {
        "no error",
        "unknown",
        "memory allocation failed",
        "null parameter",
        "not found",
        "invalid capacity",
        "not implemented",
        "overflow",
        "underflow"
    };
    switch( error )
    {
    case ERROR_NO_ERROR:
        return error_names[ ERROR_NO_ERROR ];
    case ERROR_MEMORY_ALLOCATION_FAILED:
        return error_names[ ERROR_MEMORY_ALLOCATION_FAILED ];
    case ERROR_NULL_PARAMETER:
        return error_names[ ERROR_NULL_PARAMETER ];
    case ERROR_NOT_FOUND:
        return error_names[ ERROR_NOT_FOUND ];
    case ERROR_INVALID_CAPACITY:
        return error_names[ ERROR_INVALID_CAPACITY ];
    case ERROR_NOT_IMPLEMENTED:
        return error_names[ ERROR_NOT_IMPLEMENTED ];
    case ERROR_OVERFLOW:
        return error_names[ ERROR_OVERFLOW ];
    case ERROR_UNDERFLOW:
        return error_names[ ERROR_UNDERFLOW ];
    default:
        return error_names[ ERROR_UNKNOWN ];
    }
}

variable_types: enum _errors { ERROR_NO_ERROR=0, ERROR_UNKNOWN=1, ERROR_MEMORY_ALLOCATION_FAILED=2, ERROR_NULL_PARAMETER=3, ERROR_NOT_FOUND=4, ERROR_INVALID_CAPACITY=5, ERROR_NOT_IMPLEMENTED=6, ERROR_OVERFLOW=7, ERROR_UNDERFLOW=8 }

return_type: char *


decompiled_code:
// attributes: thunk
const char *__fastcall error_get_message(int a1)
{
return error_name(a1);
}

canonical_decompiled_code:
const char *__fastcall func1(int a1)
{
return func0(a1);
}

original_code:
inline char * error_get_message( int error )
{
    return error_name( error );
}

canonical_original_code:
inline char *error_get_message(int error)
{
    return error_name( error );
}

variable_types: error int


decompiled_code:
int error_print()
{
const char *v0; // rax
__int64 v1; // rdx
const char *v2; // r8

v0 = error_name(error_code);
return fprintf(stderr, "ERROR: (%d) %s : %s\n", v1, v0, v2);
}

canonical_decompiled_code:
int func2()
{
const char *v0; // rax
__int64 v1; // rdx
const char *v2; // r8

v0 = func0(error_code);
return fprintf(stderr, "ERROR: (%d) %s : %s\n", v1, v0, v2);
}

original_code:
int error_print( const char * msg )
{
    int nchr = 0;
    nchr += fprintf( stderr, "ERROR: (%d) %s : %s\n", error_code, error_name( error_code), msg );
    return nchr;
}

canonical_original_code:
int error_print(char *msg)
{
    int nchr = 0;
    nchr += fprintf( stderr, "ERROR: (%d) %s : %s\n", error_code, error_name( error_code), msg );
    return nchr;
}

variable_types:
msg
char *

variable_types: nchr int


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

if ( a1 == a2 )
result = 0LL;
else
result = a1 < a2 ? -1 : 1;
return result;
}

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

if ( a1 == a2 )
result = 0LL;
else
result = a1 < a2 ? -1 : 1;
return result;
}

original_code:
static int default_compare( const void * data1, const void * data2 )
{
    if( data1 == data2 )
    {
        return 0;
    }
    else if( data1 < data2 )
    {
        return -1;
    }
    else
    {
        return 1;
    }
}

canonical_original_code:
static int default_compare(void *data1, void *data2)
{
    if( data1 == data2 )
    {
        return 0;
    }
    else if( data1 < data2 )
    {
        return -1;
    }
    else
    {
        return 1;
    }
}


decompiled_code:
__int64 __fastcall default_copy(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return a1;
}

original_code:
static void * default_copy( const void * data )
{
    return (void *)data;
}

canonical_original_code:
static void *default_copy(void *data)
{
    return (void *)data;
}

variable_types:
data
void *

return_type: void *


decompiled_code:
void default_free()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
static void default_free( void * data )
{
    return;
}

canonical_original_code:
static void default_free(void *data)
{
    return;
}


decompiled_code:
__int64 __fastcall default_hash(unsigned int *a1)
{
return (32LL * (int)*a1) ^ (*a1 >> 27) ^ 1;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1)
{
return (32LL * (int)*a1) ^ (*a1 >> 27) ^ 1;
}

original_code:
static unsigned long default_hash( const void * key )
{
    unsigned long hash = *(int*)key;
    unsigned long high_order = 0;
    high_order = hash & 0xf8000000;
    hash = hash << 5;
    hash = hash ^ ( high_order >> 27 );
    hash = hash ^ 1;
    return hash;
}

canonical_original_code:
static unsigned long default_hash(void *key)
{
    unsigned long hash = *(int*)key;
    unsigned long high_order = 0;
    high_order = hash & 0xf8000000;
    hash = hash << 5;
    hash = hash ^ ( high_order >> 27 );
    hash = hash ^ 1;
    return hash;
}

variable_types:
key
void *

variable_types:
hash
unsigned long


decompiled_code:
__int64 test_error_print()
{
tcase_fn_start("test_error_print", "tests/error_test.c", 94LL);
error_code = 0;
if ( (int)error_print(0LL) <= 0 )
{
ck_assert_failed("tests/error_test.c", 101LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_14;
}
mark_point("tests/error_test.c", 101LL);
error_code = 1;
if ( (int)error_print(0LL) > 0 )
{
mark_point("tests/error_test.c", 106LL);
error_code = 2;
if ( (int)error_print(0LL) <= 0 )
{
LABEL_22:
ck_assert_failed("tests/error_test.c", 111LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_23;
}
mark_point("tests/error_test.c", 111LL);
error_code = 3;
if ( (int)error_print(0LL) <= 0 )
{
LABEL_21:
ck_assert_failed("tests/error_test.c", 116LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_22;
}
mark_point("tests/error_test.c", 116LL);
error_code = 4;
if ( (int)error_print(0LL) <= 0 )
{
LABEL_20:
ck_assert_failed("tests/error_test.c", 121LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_21;
}
mark_point("tests/error_test.c", 121LL);
error_code = 5;
if ( (int)error_print(0LL) <= 0 )
{
LABEL_19:
ck_assert_failed("tests/error_test.c", 126LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_20;
}
mark_point("tests/error_test.c", 126LL);
error_code = 6;
if ( (int)error_print(0LL) <= 0 )
{
LABEL_18:
ck_assert_failed("tests/error_test.c", 131LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_19;
}
mark_point("tests/error_test.c", 131LL);
error_code = 7;
if ( (int)error_print(0LL) <= 0 )
{
LABEL_17:
ck_assert_failed("tests/error_test.c", 136LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_18;
}
mark_point("tests/error_test.c", 136LL);
error_code = 8;
if ( (int)error_print(0LL) <= 0 )
{
LABEL_16:
ck_assert_failed("tests/error_test.c", 141LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_17;
}
mark_point("tests/error_test.c", 141LL);
error_code = -10;
if ( (int)error_print(0LL) <= 0 )
{
LABEL_15:
ck_assert_failed("tests/error_test.c", 146LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_16;
}
mark_point("tests/error_test.c", 146LL);
error_code = 10;
if ( (int)error_print(0LL) > 0 )
return mark_point("tests/error_test.c", 151LL);
LABEL_14:
ck_assert_failed("tests/error_test.c", 151LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_15;
}
LABEL_23:
ck_assert_failed("tests/error_test.c", 106LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
return test_error_get_message();
}

canonical_decompiled_code:
__int64 func1()
{
tcase_fn_start("test_error_print", "tests/error_test.c", 94LL);
error_code = 0;
if ( (int)error_print(0LL) <= 0 )
{
ck_assert_failed("tests/error_test.c", 101LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_14;
}
mark_point("tests/error_test.c", 101LL);
error_code = 1;
if ( (int)error_print(0LL) > 0 )
{
mark_point("tests/error_test.c", 106LL);
error_code = 2;
if ( (int)error_print(0LL) <= 0 )
{
LABEL_22:
ck_assert_failed("tests/error_test.c", 111LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_23;
}
mark_point("tests/error_test.c", 111LL);
error_code = 3;
if ( (int)error_print(0LL) <= 0 )
{
LABEL_21:
ck_assert_failed("tests/error_test.c", 116LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_22;
}
mark_point("tests/error_test.c", 116LL);
error_code = 4;
if ( (int)error_print(0LL) <= 0 )
{
LABEL_20:
ck_assert_failed("tests/error_test.c", 121LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_21;
}
mark_point("tests/error_test.c", 121LL);
error_code = 5;
if ( (int)error_print(0LL) <= 0 )
{
LABEL_19:
ck_assert_failed("tests/error_test.c", 126LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_20;
}
mark_point("tests/error_test.c", 126LL);
error_code = 6;
if ( (int)error_print(0LL) <= 0 )
{
LABEL_18:
ck_assert_failed("tests/error_test.c", 131LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_19;
}
mark_point("tests/error_test.c", 131LL);
error_code = 7;
if ( (int)error_print(0LL) <= 0 )
{
LABEL_17:
ck_assert_failed("tests/error_test.c", 136LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_18;
}
mark_point("tests/error_test.c", 136LL);
error_code = 8;
if ( (int)error_print(0LL) <= 0 )
{
LABEL_16:
ck_assert_failed("tests/error_test.c", 141LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_17;
}
mark_point("tests/error_test.c", 141LL);
error_code = -10;
if ( (int)error_print(0LL) <= 0 )
{
LABEL_15:
ck_assert_failed("tests/error_test.c", 146LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_16;
}
mark_point("tests/error_test.c", 146LL);
error_code = 10;
if ( (int)error_print(0LL) > 0 )
return mark_point("tests/error_test.c", 151LL);
LABEL_14:
ck_assert_failed("tests/error_test.c", 151LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
goto LABEL_15;
}
LABEL_23:
ck_assert_failed("tests/error_test.c", 106LL, "Assertion 'nchr > 0' failed", 0LL, 0LL);
return func2();
}

original_code:
static void test_error_print (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_error_print", "tests/error_test.c", 94);
{
    int nchr = -1;
    error_code = ERROR_NO_ERROR;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 101) : _ck_assert_failed("tests/error_test.c", 101, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_UNKNOWN;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 106) : _ck_assert_failed("tests/error_test.c", 106, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_MEMORY_ALLOCATION_FAILED;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 111) : _ck_assert_failed("tests/error_test.c", 111, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_NULL_PARAMETER;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 116) : _ck_assert_failed("tests/error_test.c", 116, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_NOT_FOUND;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 121) : _ck_assert_failed("tests/error_test.c", 121, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_INVALID_CAPACITY;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 126) : _ck_assert_failed("tests/error_test.c", 126, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_NOT_IMPLEMENTED;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 131) : _ck_assert_failed("tests/error_test.c", 131, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_OVERFLOW;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 136) : _ck_assert_failed("tests/error_test.c", 136, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_UNDERFLOW;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 141) : _ck_assert_failed("tests/error_test.c", 141, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = -10;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 146) : _ck_assert_failed("tests/error_test.c", 146, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = 10;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 151) : _ck_assert_failed("tests/error_test.c", 151, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
}
}

canonical_original_code:
static void test_error_print(int _i){ tcase_fn_start ("""test_error_print", "tests/error_test.c", 94);
{
    int nchr = -1;
    error_code = ERROR_NO_ERROR;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 101) : _ck_assert_failed("tests/error_test.c", 101, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_UNKNOWN;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 106) : _ck_assert_failed("tests/error_test.c", 106, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_MEMORY_ALLOCATION_FAILED;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 111) : _ck_assert_failed("tests/error_test.c", 111, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_NULL_PARAMETER;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 116) : _ck_assert_failed("tests/error_test.c", 116, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_NOT_FOUND;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 121) : _ck_assert_failed("tests/error_test.c", 121, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_INVALID_CAPACITY;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 126) : _ck_assert_failed("tests/error_test.c", 126, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_NOT_IMPLEMENTED;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 131) : _ck_assert_failed("tests/error_test.c", 131, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_OVERFLOW;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 136) : _ck_assert_failed("tests/error_test.c", 136, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_UNDERFLOW;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 141) : _ck_assert_failed("tests/error_test.c", 141, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = -10;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 146) : _ck_assert_failed("tests/error_test.c", 146, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
    error_code = 10;
    nchr = error_print( ((void *)0) );
    (nchr > 0) ? _mark_point("tests/error_test.c", 151) : _ck_assert_failed("tests/error_test.c", 151, "Assertion '""nchr > 0""' failed" , ((void *)0), ((void *)0));
}
}


decompiled_code:
__int64 test_error_get_message()
{
tcase_fn_start("test_error_get_message", "tests/error_test.c", 26LL);
error_code = 0;
if ( strcmp((const char *)error_get_message(0LL), "no error") )
{
ck_assert_failed(
"tests/error_test.c",
33LL,
"Assertion 'strncmp( message, \"no error\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_14;
}
mark_point("tests/error_test.c", 33LL);
error_code = 1;
if ( !strcmp((const char *)error_get_message(1LL), "unknown") )
{
mark_point("tests/error_test.c", 38LL);
error_code = 2;
if ( strcmp((const char *)error_get_message(2LL), "memory allocation failed") )
{
LABEL_22:
ck_assert_failed(
"tests/error_test.c",
43LL,
"Assertion 'strncmp( message, \"memory allocation failed\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_23;
}
mark_point("tests/error_test.c", 43LL);
error_code = 3;
if ( strcmp((const char *)error_get_message(3LL), "null parameter") )
{
LABEL_21:
ck_assert_failed(
"tests/error_test.c",
48LL,
"Assertion 'strncmp( message, \"null parameter\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_22;
}
mark_point("tests/error_test.c", 48LL);
error_code = 4;
if ( strcmp((const char *)error_get_message(4LL), "not found") )
{
LABEL_20:
ck_assert_failed(
"tests/error_test.c",
53LL,
"Assertion 'strncmp( message, \"not found\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_21;
}
mark_point("tests/error_test.c", 53LL);
error_code = 5;
if ( strcmp((const char *)error_get_message(5LL), "invalid capacity") )
{
LABEL_19:
ck_assert_failed(
"tests/error_test.c",
58LL,
"Assertion 'strncmp( message, \"invalid capacity\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_20;
}
mark_point("tests/error_test.c", 58LL);
error_code = 6;
if ( strcmp((const char *)error_get_message(6LL), "not implemented") )
{
LABEL_18:
ck_assert_failed(
"tests/error_test.c",
63LL,
"Assertion 'strncmp( message, \"not implemented\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_19;
}
mark_point("tests/error_test.c", 63LL);
error_code = 7;
if ( strcmp((const char *)error_get_message(7LL), "overflow") )
{
LABEL_17:
ck_assert_failed(
"tests/error_test.c",
68LL,
"Assertion 'strncmp( message, \"overflow\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_18;
}
mark_point("tests/error_test.c", 68LL);
error_code = 8;
if ( strcmp((const char *)error_get_message(8LL), "underflow") )
{
LABEL_16:
ck_assert_failed(
"tests/error_test.c",
73LL,
"Assertion 'strncmp( message, \"underflow\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_17;
}
mark_point("tests/error_test.c", 73LL);
error_code = -10;
if ( strcmp((const char *)error_get_message(4294967286LL), "unknown") )
{
LABEL_15:
ck_assert_failed(
"tests/error_test.c",
78LL,
"Assertion 'strncmp( message, \"unknown\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_16;
}
mark_point("tests/error_test.c", 78LL);
error_code = 10;
if ( !strcmp((const char *)error_get_message(10LL), "unknown") )
return mark_point("tests/error_test.c", 83LL);
LABEL_14:
ck_assert_failed(
"tests/error_test.c",
83LL,
"Assertion 'strncmp( message, \"unknown\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_15;
}
LABEL_23:
ck_assert_failed("tests/error_test.c", 38LL, "Assertion 'strncmp( message, \"unknown\", 256 ) == 0' failed", 0LL, 0LL);
return error_suite();
}

canonical_decompiled_code:
__int64 func2()
{
tcase_fn_start("test_error_get_message", "tests/error_test.c", 26LL);
error_code = 0;
if ( strcmp((const char *)error_get_message(0LL), "no error") )
{
ck_assert_failed(
"tests/error_test.c",
33LL,
"Assertion 'strncmp( message, \"no error\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_14;
}
mark_point("tests/error_test.c", 33LL);
error_code = 1;
if ( !strcmp((const char *)error_get_message(1LL), "unknown") )
{
mark_point("tests/error_test.c", 38LL);
error_code = 2;
if ( strcmp((const char *)error_get_message(2LL), "memory allocation failed") )
{
LABEL_22:
ck_assert_failed(
"tests/error_test.c",
43LL,
"Assertion 'strncmp( message, \"memory allocation failed\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_23;
}
mark_point("tests/error_test.c", 43LL);
error_code = 3;
if ( strcmp((const char *)error_get_message(3LL), "null parameter") )
{
LABEL_21:
ck_assert_failed(
"tests/error_test.c",
48LL,
"Assertion 'strncmp( message, \"null parameter\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_22;
}
mark_point("tests/error_test.c", 48LL);
error_code = 4;
if ( strcmp((const char *)error_get_message(4LL), "not found") )
{
LABEL_20:
ck_assert_failed(
"tests/error_test.c",
53LL,
"Assertion 'strncmp( message, \"not found\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_21;
}
mark_point("tests/error_test.c", 53LL);
error_code = 5;
if ( strcmp((const char *)error_get_message(5LL), "invalid capacity") )
{
LABEL_19:
ck_assert_failed(
"tests/error_test.c",
58LL,
"Assertion 'strncmp( message, \"invalid capacity\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_20;
}
mark_point("tests/error_test.c", 58LL);
error_code = 6;
if ( strcmp((const char *)error_get_message(6LL), "not implemented") )
{
LABEL_18:
ck_assert_failed(
"tests/error_test.c",
63LL,
"Assertion 'strncmp( message, \"not implemented\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_19;
}
mark_point("tests/error_test.c", 63LL);
error_code = 7;
if ( strcmp((const char *)error_get_message(7LL), "overflow") )
{
LABEL_17:
ck_assert_failed(
"tests/error_test.c",
68LL,
"Assertion 'strncmp( message, \"overflow\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_18;
}
mark_point("tests/error_test.c", 68LL);
error_code = 8;
if ( strcmp((const char *)error_get_message(8LL), "underflow") )
{
LABEL_16:
ck_assert_failed(
"tests/error_test.c",
73LL,
"Assertion 'strncmp( message, \"underflow\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_17;
}
mark_point("tests/error_test.c", 73LL);
error_code = -10;
if ( strcmp((const char *)error_get_message(4294967286LL), "unknown") )
{
LABEL_15:
ck_assert_failed(
"tests/error_test.c",
78LL,
"Assertion 'strncmp( message, \"unknown\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_16;
}
mark_point("tests/error_test.c", 78LL);
error_code = 10;
if ( !strcmp((const char *)error_get_message(10LL), "unknown") )
return mark_point("tests/error_test.c", 83LL);
LABEL_14:
ck_assert_failed(
"tests/error_test.c",
83LL,
"Assertion 'strncmp( message, \"unknown\", 256 ) == 0' failed",
0LL,
0LL);
goto LABEL_15;
}
LABEL_23:
ck_assert_failed("tests/error_test.c", 38LL, "Assertion 'strncmp( message, \"unknown\", 256 ) == 0' failed", 0LL, 0LL);
return func3();
}

original_code:
static void test_error_get_message (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_error_get_message", "tests/error_test.c", 26);
{
    char * message = ((void *)0);
    error_code = ERROR_NO_ERROR;
    message = error_get_message( error_code );
    (strncmp( message, "no error", 256 ) == 0) ? _mark_point("tests/error_test.c", 33) : _ck_assert_failed("tests/error_test.c", 33, "Assertion '""strncmp( message, \"no error\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_UNKNOWN;
    message = error_get_message( error_code );
    (strncmp( message, "unknown", 256 ) == 0) ? _mark_point("tests/error_test.c", 38) : _ck_assert_failed("tests/error_test.c", 38, "Assertion '""strncmp( message, \"unknown\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_MEMORY_ALLOCATION_FAILED;
    message = error_get_message( error_code );
    (strncmp( message, "memory allocation failed", 256 ) == 0) ? _mark_point("tests/error_test.c", 43) : _ck_assert_failed("tests/error_test.c", 43, "Assertion '""strncmp( message, \"memory allocation failed\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_NULL_PARAMETER;
    message = error_get_message( error_code );
    (strncmp( message, "null parameter", 256 ) == 0) ? _mark_point("tests/error_test.c", 48) : _ck_assert_failed("tests/error_test.c", 48, "Assertion '""strncmp( message, \"null parameter\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_NOT_FOUND;
    message = error_get_message( error_code );
    (strncmp( message, "not found", 256 ) == 0) ? _mark_point("tests/error_test.c", 53) : _ck_assert_failed("tests/error_test.c", 53, "Assertion '""strncmp( message, \"not found\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_INVALID_CAPACITY;
    message = error_get_message( error_code );
    (strncmp( message, "invalid capacity", 256 ) == 0) ? _mark_point("tests/error_test.c", 58) : _ck_assert_failed("tests/error_test.c", 58, "Assertion '""strncmp( message, \"invalid capacity\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_NOT_IMPLEMENTED;
    message = error_get_message( error_code );
    (strncmp( message, "not implemented", 256 ) == 0) ? _mark_point("tests/error_test.c", 63) : _ck_assert_failed("tests/error_test.c", 63, "Assertion '""strncmp( message, \"not implemented\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_OVERFLOW;
    message = error_get_message( error_code );
    (strncmp( message, "overflow", 256 ) == 0) ? _mark_point("tests/error_test.c", 68) : _ck_assert_failed("tests/error_test.c", 68, "Assertion '""strncmp( message, \"overflow\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_UNDERFLOW;
    message = error_get_message( error_code );
    (strncmp( message, "underflow", 256 ) == 0) ? _mark_point("tests/error_test.c", 73) : _ck_assert_failed("tests/error_test.c", 73, "Assertion '""strncmp( message, \"underflow\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = -10;
    message = error_get_message( error_code );
    (strncmp( message, "unknown", 256 ) == 0) ? _mark_point("tests/error_test.c", 78) : _ck_assert_failed("tests/error_test.c", 78, "Assertion '""strncmp( message, \"unknown\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = 10;
    message = error_get_message( error_code );
    (strncmp( message, "unknown", 256 ) == 0) ? _mark_point("tests/error_test.c", 83) : _ck_assert_failed("tests/error_test.c", 83, "Assertion '""strncmp( message, \"unknown\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
}
}

canonical_original_code:
static void test_error_get_message(int _i){ tcase_fn_start ("""test_error_get_message", "tests/error_test.c", 26);
{
    char *message = ((void *)0);
    error_code = ERROR_NO_ERROR;
    message = error_get_message( error_code );
    (strncmp( message, "no error", 256 ) == 0) ? _mark_point("tests/error_test.c", 33) : _ck_assert_failed("tests/error_test.c", 33, "Assertion '""strncmp( message, \"no error\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_UNKNOWN;
    message = error_get_message( error_code );
    (strncmp( message, "unknown", 256 ) == 0) ? _mark_point("tests/error_test.c", 38) : _ck_assert_failed("tests/error_test.c", 38, "Assertion '""strncmp( message, \"unknown\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_MEMORY_ALLOCATION_FAILED;
    message = error_get_message( error_code );
    (strncmp( message, "memory allocation failed", 256 ) == 0) ? _mark_point("tests/error_test.c", 43) : _ck_assert_failed("tests/error_test.c", 43, "Assertion '""strncmp( message, \"memory allocation failed\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_NULL_PARAMETER;
    message = error_get_message( error_code );
    (strncmp( message, "null parameter", 256 ) == 0) ? _mark_point("tests/error_test.c", 48) : _ck_assert_failed("tests/error_test.c", 48, "Assertion '""strncmp( message, \"null parameter\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_NOT_FOUND;
    message = error_get_message( error_code );
    (strncmp( message, "not found", 256 ) == 0) ? _mark_point("tests/error_test.c", 53) : _ck_assert_failed("tests/error_test.c", 53, "Assertion '""strncmp( message, \"not found\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_INVALID_CAPACITY;
    message = error_get_message( error_code );
    (strncmp( message, "invalid capacity", 256 ) == 0) ? _mark_point("tests/error_test.c", 58) : _ck_assert_failed("tests/error_test.c", 58, "Assertion '""strncmp( message, \"invalid capacity\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_NOT_IMPLEMENTED;
    message = error_get_message( error_code );
    (strncmp( message, "not implemented", 256 ) == 0) ? _mark_point("tests/error_test.c", 63) : _ck_assert_failed("tests/error_test.c", 63, "Assertion '""strncmp( message, \"not implemented\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_OVERFLOW;
    message = error_get_message( error_code );
    (strncmp( message, "overflow", 256 ) == 0) ? _mark_point("tests/error_test.c", 68) : _ck_assert_failed("tests/error_test.c", 68, "Assertion '""strncmp( message, \"overflow\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = ERROR_UNDERFLOW;
    message = error_get_message( error_code );
    (strncmp( message, "underflow", 256 ) == 0) ? _mark_point("tests/error_test.c", 73) : _ck_assert_failed("tests/error_test.c", 73, "Assertion '""strncmp( message, \"underflow\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = -10;
    message = error_get_message( error_code );
    (strncmp( message, "unknown", 256 ) == 0) ? _mark_point("tests/error_test.c", 78) : _ck_assert_failed("tests/error_test.c", 78, "Assertion '""strncmp( message, \"unknown\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
    error_code = 10;
    message = error_get_message( error_code );
    (strncmp( message, "unknown", 256 ) == 0) ? _mark_point("tests/error_test.c", 83) : _ck_assert_failed("tests/error_test.c", 83, "Assertion '""strncmp( message, \"unknown\", 256 ) == 0""' failed" , ((void *)0), ((void *)0));
}
}

variable_types:
message
char *


decompiled_code:
__int64 test_random_number()
{
int v0; // er12
int v1; // ebp
unsigned int v2; // ebx
unsigned int v3; // er13

v0 = 0;
v1 = 100;
v2 = 0;
tcase_fn_start("test_random_number", "tests/math_test.c", 43LL);
do
{
v3 = v2;
v2 = random_number(0LL, 100LL);
if ( v2 > 0x64 )
{
ck_assert_failed("tests/math_test.c", 53LL, "Assertion 'n >= 0 && n <= 100' failed", 0LL, 0LL);
goto LABEL_7;
}
mark_point("tests/math_test.c", 53LL);
v0 += v2 == v3;
--v1;
}
while ( v1 );
if ( v0 <= 99 )
return mark_point("tests/math_test.c", 64LL);
LABEL_7:
ck_assert_failed("tests/math_test.c", 64LL, "Assertion 'same < 100' failed", 0LL, 0LL);
return test_generate_prime();
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // er12
int v1; // ebp
unsigned int v2; // ebx
unsigned int v3; // er13

v0 = 0;
v1 = 100;
v2 = 0;
tcase_fn_start("test_random_number", "tests/math_test.c", 43LL);
do
{
v3 = v2;
v2 = random_number(0LL, 100LL);
if ( v2 > 0x64 )
{
ck_assert_failed("tests/math_test.c", 53LL, "Assertion 'n >= 0 && n <= 100' failed", 0LL, 0LL);
goto LABEL_7;
}
mark_point("tests/math_test.c", 53LL);
v0 += v2 == v3;
--v1;
}
while ( v1 );
if ( v0 <= 99 )
return mark_point("tests/math_test.c", 64LL);
LABEL_7:
ck_assert_failed("tests/math_test.c", 64LL, "Assertion 'same < 100' failed", 0LL, 0LL);
return func1();
}

original_code:
static void test_random_number (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_random_number", "tests/math_test.c", 43);
{
    int same = 0;
    int i = 0;
    int n = 0;
    int t = 0;
    for( t = 0, i = 0; i < 100; ++i )
    {
        n = random_number( 0, 100 );
        (n >= 0 && n <= 100) ? _mark_point("tests/math_test.c", 53) : _ck_assert_failed("tests/math_test.c", 53, "Assertion '""n >= 0 && n <= 100""' failed" , ((void *)0), ((void *)0));
        if( t == n )
        {
            ++same;
        }
        t = n;
    }
    (same < 100) ? _mark_point("tests/math_test.c", 64) : _ck_assert_failed("tests/math_test.c", 64, "Assertion '""same < 100""' failed" , ((void *)0), ((void *)0));
}
}

canonical_original_code:
static void test_random_number(int _i){ tcase_fn_start ("""test_random_number", "tests/math_test.c", 43);
{
    int same = 0;
    int i = 0;
    int n = 0;
    int t = 0;
    for( t = 0, i = 0; i < 100; ++i )
    {
        n = random_number( 0, 100 );
        (n >= 0 && n <= 100) ? _mark_point("tests/math_test.c", 53) : _ck_assert_failed("tests/math_test.c", 53, "Assertion '""n >= 0 && n <= 100""' failed" , ((void *)0), ((void *)0));
        if( t == n )
        {
            ++same;
        }
        t = n;
    }
    (same < 100) ? _mark_point("tests/math_test.c", 64) : _ck_assert_failed("tests/math_test.c", 64, "Assertion '""same < 100""' failed" , ((void *)0), ((void *)0));
}
}

variable_types: same int

variable_types: n int

variable_types: t int


decompiled_code:
__int64 test_generate_prime()
{
tcase_fn_start("test_generate_prime", "tests/math_test.c", 24LL);
if ( (unsigned int)generate_prime(100LL) != 97 )
{
ck_assert_failed("tests/math_test.c", 30LL, "Assertion 'prime == 97' failed", 0LL, 0LL);
LABEL_6:
ck_assert_failed("tests/math_test.c", 36LL, "Assertion 'prime == 67' failed", 0LL, 0LL);
goto LABEL_7;
}
mark_point("tests/math_test.c", 30LL);
if ( (unsigned int)generate_prime(20LL) == 19 )
{
mark_point("tests/math_test.c", 33LL);
if ( (unsigned int)generate_prime(70LL) == 67 )
return mark_point("tests/math_test.c", 36LL);
goto LABEL_6;
}
LABEL_7:
ck_assert_failed("tests/math_test.c", 33LL, "Assertion 'prime == 19' failed", 0LL, 0LL);
return math_suite();
}

canonical_decompiled_code:
__int64 func1()
{
tcase_fn_start("test_generate_prime", "tests/math_test.c", 24LL);
if ( (unsigned int)generate_prime(100LL) != 97 )
{
ck_assert_failed("tests/math_test.c", 30LL, "Assertion 'prime == 97' failed", 0LL, 0LL);
LABEL_6:
ck_assert_failed("tests/math_test.c", 36LL, "Assertion 'prime == 67' failed", 0LL, 0LL);
goto LABEL_7;
}
mark_point("tests/math_test.c", 30LL);
if ( (unsigned int)generate_prime(20LL) == 19 )
{
mark_point("tests/math_test.c", 33LL);
if ( (unsigned int)generate_prime(70LL) == 67 )
return mark_point("tests/math_test.c", 36LL);
goto LABEL_6;
}
LABEL_7:
ck_assert_failed("tests/math_test.c", 33LL, "Assertion 'prime == 19' failed", 0LL, 0LL);
return func2();
}

original_code:
static void test_generate_prime (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_generate_prime", "tests/math_test.c", 24);
{
    int prime = 0;
    prime = generate_prime( 100 );
    (prime == 97) ? _mark_point("tests/math_test.c", 30) : _ck_assert_failed("tests/math_test.c", 30, "Assertion '""prime == 97""' failed" , ((void *)0), ((void *)0));
    prime = generate_prime( 20 );
    (prime == 19) ? _mark_point("tests/math_test.c", 33) : _ck_assert_failed("tests/math_test.c", 33, "Assertion '""prime == 19""' failed" , ((void *)0), ((void *)0));
    prime = generate_prime( 70 );
    (prime == 67) ? _mark_point("tests/math_test.c", 36) : _ck_assert_failed("tests/math_test.c", 36, "Assertion '""prime == 67""' failed" , ((void *)0), ((void *)0));
}
}

canonical_original_code:
static void test_generate_prime(int _i){ tcase_fn_start ("""test_generate_prime", "tests/math_test.c", 24);
{
    int prime = 0;
    prime = generate_prime( 100 );
    (prime == 97) ? _mark_point("tests/math_test.c", 30) : _ck_assert_failed("tests/math_test.c", 30, "Assertion '""prime == 97""' failed" , ((void *)0), ((void *)0));
    prime = generate_prime( 20 );
    (prime == 19) ? _mark_point("tests/math_test.c", 33) : _ck_assert_failed("tests/math_test.c", 33, "Assertion '""prime == 19""' failed" , ((void *)0), ((void *)0));
    prime = generate_prime( 70 );
    (prime == 67) ? _mark_point("tests/math_test.c", 36) : _ck_assert_failed("tests/math_test.c", 36, "Assertion '""prime == 67""' failed" , ((void *)0), ((void *)0));
}
}

variable_types: prime int


usage

repo: mdelbra/psf-estim

decompiled_code:
int __fastcall usage(const char *a1)
{
puts("Point Spread Function Estimation from a Random Target");
printf("Copyright M.Delbracio, P.Muse, A.Almansa. ");
puts("Version 1.3 - 26 December 2011\n");
printf("Usage: %s [options] <input file> <output file>\n\nOnly PGM 16/8 bits images are supported.\n\n", a1);
puts("Options:");
printf(" -s <number> The super-resolution factor, positive integer");
puts(" (default 4)");
puts(" -k <number> PSF support size (default 4s + 1)");
puts(" -o <file> Estimated PSF save to a 8bits PGM image ");
puts(" -p <file> Noise Pattern PGM image ");
printf(" -d <file> Save the input image with detected pattern marked");
puts(" (24bits PPM)");
puts(" -t <0,1,2> Least Squares solver:");
puts(" 0 - Least Squares");
puts(" 1 - Least Squares + thresholding (default)");
return puts(" 2 - Non-negative least Squares (slowest)");
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
puts("Point Spread Function Estimation from a Random Target");
printf("Copyright M.Delbracio, P.Muse, A.Almansa. ");
puts("Version 1.3 - 26 December 2011\n");
printf("Usage: %s [options] <input file> <output file>\n\nOnly PGM 16/8 bits images are supported.\n\n", a1);
puts("Options:");
printf(" -s <number> The super-resolution factor, positive integer");
puts(" (default 4)");
puts(" -k <number> PSF support size (default 4s + 1)");
puts(" -o <file> Estimated PSF save to a 8bits PGM image ");
puts(" -p <file> Noise Pattern PGM image ");
printf(" -d <file> Save the input image with detected pattern marked");
puts(" (24bits PPM)");
puts(" -t <0,1,2> Least Squares solver:");
puts(" 0 - Least Squares");
puts(" 1 - Least Squares + thresholding (default)");
return puts(" 2 - Non-negative least Squares (slowest)");
}

original_code:
static void usage(const char* name)
{
    printf("Point Spread Function Estimation from a Random Target\n");
    printf("Copyright M.Delbracio, P.Muse, A.Almansa. ");
    printf("Version 1.3 - 26 December 2011\n\n");
    printf("Usage: %s [options] <input file> <output file>\n\n"
           "Only  PGM 16/8 bits images are supported.\n\n",name);
    printf("Options:\n");
    printf("  -s <number>  The super-resolution factor, positive integer");
    printf("  (default 4)\n");
    printf("  -k <number>  PSF support size (default 4s + 1)\n");
    printf("  -o <file>    Estimated PSF save to a 8bits PGM image \n");
    printf("  -p <file>    Noise Pattern PGM image \n");
    printf("  -d <file>    Save the input image with detected pattern marked");
    printf("  (24bits PPM)\n");
    printf("  -t <0,1,2>   Least Squares solver:\n");
    printf("                    0 - Least Squares\n");
    printf("                    1 - Least Squares + thresholding (default)\n");
    printf("                    2 - Non-negative least Squares (slowest)\n");
}

canonical_original_code:
static void usage(char *name)
{
    printf("Point Spread Function Estimation from a Random Target\n");
    printf("Copyright M.Delbracio, P.Muse, A.Almansa. ");
    printf("Version 1.3 - 26 December 2011\n\n");
    printf("Usage: %s [options] <input file> <output file>\n\n"
           "Only  PGM 16/8 bits images are supported.\n\n",name);
    printf("Options:\n");
    printf("  -s <number>  The super-resolution factor, positive integer");
    printf("  (default 4)\n");
    printf("  -k <number>  PSF support size (default 4s + 1)\n");
    printf("  -o <file>    Estimated PSF save to a 8bits PGM image \n");
    printf("  -p <file>    Noise Pattern PGM image \n");
    printf("  -d <file>    Save the input image with detected pattern marked");
    printf("  (24bits PPM)\n");
    printf("  -t <0,1,2>   Least Squares solver:\n");
    printf("                    0 - Least Squares\n");
    printf("                    1 - Least Squares + thresholding (default)\n");
    printf("                    2 - Non-negative least Squares (slowest)\n");
}

variable_types:
name
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
void *v4; // rbp
__int64 v5; // rax
void *v6; // r12
void *v7; // r13
int result; // eax
unsigned int v9; // [rsp+0h] [rbp-68h] BYREF
unsigned int v10; // [rsp+4h] [rbp-64h] BYREF
unsigned int v11; // [rsp+8h] [rbp-60h] BYREF
unsigned int v12; // [rsp+Ch] [rbp-5Ch] BYREF
__int64 v13; // [rsp+10h] [rbp-58h] BYREF
unsigned int v14; // [rsp+18h] [rbp-50h]
__int64 v15; // [rsp+20h] [rbp-48h]
__int64 v16; // [rsp+28h] [rbp-40h]
__int64 v17; // [rsp+30h] [rbp-38h]
__int64 v18; // [rsp+38h] [rbp-30h]
__int64 v19; // [rsp+40h] [rbp-28h]
unsigned int v20; // [rsp+48h] [rbp-20h]

v13 = -1LL;
v14 = -1;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = -1;
parse_arguments_constprop_0((int *)&v13, argc, argv);
v3 = read_pgm_float(v17, &v9, &v10);
if ( v3 )
{
v4 = (void *)v3;
v5 = read_pgm_float(v15, &v11, &v12);
v6 = (void *)v5;
if ( v5 )
{
v7 = (void *)psf_estim(v4, v9, v10, v5, v11, v12, (unsigned int)v13, HIDWORD(v13), v14, v20, v19);
write_ascii_matrix(v7, HIDWORD(v13), v14, v18);
if ( v16 )
write_pgm_normalize_float(v16, v7, HIDWORD(v13), v14);
free(v7);
free(v4);
free(v6);
result = 0;
}
else
{
fwrite("the pattern image could not be properly read\n", 1uLL, 0x2DuLL, stderr);
result = 1;
}
}
else
{
fwrite("the image could not be properly read\n", 1uLL, 0x25uLL, stderr);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
void *v4; // rbp
__int64 v5; // rax
void *v6; // r12
void *v7; // r13
int result; // eax
unsigned int v9; // [rsp+0h] [rbp-68h] BYREF
unsigned int v10; // [rsp+4h] [rbp-64h] BYREF
unsigned int v11; // [rsp+8h] [rbp-60h] BYREF
unsigned int v12; // [rsp+Ch] [rbp-5Ch] BYREF
__int64 v13; // [rsp+10h] [rbp-58h] BYREF
unsigned int v14; // [rsp+18h] [rbp-50h]
__int64 v15; // [rsp+20h] [rbp-48h]
__int64 v16; // [rsp+28h] [rbp-40h]
__int64 v17; // [rsp+30h] [rbp-38h]
__int64 v18; // [rsp+38h] [rbp-30h]
__int64 v19; // [rsp+40h] [rbp-28h]
unsigned int v20; // [rsp+48h] [rbp-20h]

v13 = -1LL;
v14 = -1;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = -1;
func2((int *)&v13, argc, argv);
v3 = read_pgm_float(v17, &v9, &v10);
if ( v3 )
{
v4 = (void *)v3;
v5 = read_pgm_float(v15, &v11, &v12);
v6 = (void *)v5;
if ( v5 )
{
v7 = (void *)psf_estim(v4, v9, v10, v5, v11, v12, (unsigned int)v13, HIDWORD(v13), v14, v20, v19);
write_ascii_matrix(v7, HIDWORD(v13), v14, v18);
if ( v16 )
write_pgm_normalize_float(v16, v7, HIDWORD(v13), v14);
free(v7);
free(v4);
free(v6);
result = 0;
}
else
{
fwrite("the pattern image could not be properly read\n", 1uLL, 0x2DuLL, stderr);
result = 1;
}
}
else
{
fwrite("the image could not be properly read\n", 1uLL, 0x25uLL, stderr);
result = 1;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
    int nx,ny, pat_nx,pat_ny;
    float *in, *img_pattern, *x;
    program_argums param = {-1, -1, -1, ((void *)0), ((void *)0), ((void *)0), ((void *)0), ((void *)0), -1};
    parse_arguments(&param,argc,argv);
    if (((void *)0) == (in = read_pgm_float(param.input, &nx, &ny))) {
        fprintf(stderr, "the image could not be properly read\n");
        return 1;
    }
    if (((void *)0) ==
        (img_pattern = read_pgm_float(param.pattern_pgm, &pat_nx, &pat_ny)))
    {
    fprintf(stderr, "the pattern image could not be properly read\n");
    return 1;
    }
    x = psf_estim(in, nx, ny, img_pattern, pat_nx, pat_ny,
                  param.s, param.psf_nx, param.psf_ny, param.solver,
                  param.detected_ppm);
    write_ascii_matrix(x, param.psf_nx, param.psf_ny, param.output);
    if(param.out_pgm)
    {
        write_pgm_normalize_float(param.out_pgm, x, param.psf_nx,
                                  param.psf_ny);
    }
    free(x);
    free(in);
    free(img_pattern);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int nx; int ny; int pat_nx; int pat_ny;
    float *in; float *img_pattern; float *x;
    struct program_argums param = {-1, -1, -1, ((void *)0), ((void *)0), ((void *)0), ((void *)0), ((void *)0), -1};
    parse_arguments(&param,argc,argv);
    if (((void *)0) == (in = read_pgm_float(param.input, &nx, &ny))) {
        fprintf(stderr, "the image could not be properly read\n");
        return 1;
    }
    if (((void *)0) ==
        (img_pattern = read_pgm_float(param.pattern_pgm, &pat_nx, &pat_ny)))
    {
    fprintf(stderr, "the pattern image could not be properly read\n");
    return 1;
    }
    x = psf_estim(in, nx, ny, img_pattern, pat_nx, pat_ny,
                  param.s, param.psf_nx, param.psf_ny, param.solver,
                  param.detected_ppm);
    write_ascii_matrix(x, param.psf_nx, param.psf_ny, param.output);
    if(param.out_pgm)
    {
        write_pgm_normalize_float(param.out_pgm, x, param.psf_nx,
                                  param.psf_ny);
    }
    free(x);
    free(in);
    free(img_pattern);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: nx int

variable_types: ny int

variable_types:
in
float *

variable_types:
x
float *

variable_types: struct program_argums { int s; int psf_nx; int psf_ny; char *pattern_pgm; char *out_pgm; char *input; char *output; char *detected_ppm; int solver; }


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
fprintf(stderr, "PSF_ESTIM Error: %s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "PSF_ESTIM Error: %s\n", a1);
exit(1);
}

original_code:
static void error(char *msg)
{
    fprintf(stderr, "PSF_ESTIM Error: %s\n", msg);
    exit(1);
}

variable_types:
msg
char *


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

if ( !ptr
|| (v2 = (void *)*((_QWORD *)ptr + 1)) == 0LL
|| !*((_QWORD *)ptr + 2)
|| !*((_QWORD *)ptr + 3)
|| !*((_QWORD *)ptr + 4) )
{
error("free_pointList: invalid pointList input.");
}
free(v2);
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(ptr);
}

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

if ( !ptr
|| (v2 = (void *)*((_QWORD *)ptr + 1)) == 0LL
|| !*((_QWORD *)ptr + 2)
|| !*((_QWORD *)ptr + 3)
|| !*((_QWORD *)ptr + 4) )
{
func0("free_pointList: invalid pointList input.");
}
free(v2);
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(ptr);
}

original_code:
void free_thinPlate(ThinPlate tp)
{
    if (tp == ((void *)0) || tp->xc == ((void *)0) || tp->yc == ((void *)0)
        || tp->coef_x == ((void *)0) || tp->coef_y == ((void *)0))
        error("free_pointList: invalid pointList input.");
    free((void *) tp->xc);
    free((void *) tp->yc);
    free((void *) tp->coef_x);
    free((void *) tp->coef_y);
    free((void *) tp);
}

canonical_original_code:
void free_thinPlate(struct thinPlateStruct *tp)
{
    if (tp == ((void *)0) || tp->xc == ((void *)0) || tp->yc == ((void *)0)
        || tp->coef_x == ((void *)0) || tp->coef_y == ((void *)0))
        error("free_pointList: invalid pointList input.");
    free((void *) tp->xc);
    free((void *) tp->yc);
    free((void *) tp->coef_x);
    free((void *) tp->coef_y);
    free((void *) tp);
}

variable_types: struct thinPlateStruct { int nc; float *xc; float *yc; float *coef_x; float *coef_y; float affine[6]; float lambda; } *


original_code:
int evaluate_thinPlate(ThinPlate tp, float *Pin, float *Pout, int np)
{
    int i, j;
    float xPo, yPo, xP, yP, r2;
    for (i = 0; i < np; i++)
    {
        xP = Pin[2 * i];
        yP = Pin[2 * i + 1];
        xPo = tp->affine[0] * xP + tp->affine[1] * yP + tp->affine[2];
        yPo = tp->affine[3] * xP + tp->affine[4] * yP + tp->affine[5];
        for (j = 0; j < tp->nc; j++)
        {
            r2 = (xP - tp->xc[j]) * (xP - tp->xc[j])
                + (yP - tp->yc[j]) * (yP -tp->yc[j]);
            if (r2 > 0.00000000001)
            {
                xPo += tp->coef_x[j] * r2 * log(r2);
                yPo += tp->coef_y[j] * r2 * log(r2);
            }
        }
        Pout[2 * i] = xPo;
        Pout[2 * i + 1] = yPo;
    }
    return 0;
}

canonical_original_code:
int evaluate_thinPlate(struct thinPlateStruct *tp, float *Pin, float *Pout, int np)
{
    int i; int j;
    float xPo; float yPo; float xP; float yP; float r2;
    for (i = 0; i < np; i++)
    {
        xP = Pin[2 * i];
        yP = Pin[2 * i + 1];
        xPo = tp->affine[0] * xP + tp->affine[1] * yP + tp->affine[2];
        yPo = tp->affine[3] * xP + tp->affine[4] * yP + tp->affine[5];
        for (j = 0; j < tp->nc; j++)
        {
            r2 = (xP - tp->xc[j]) * (xP - tp->xc[j])
                + (yP - tp->yc[j]) * (yP -tp->yc[j]);
            if (r2 > 0.00000000001)
            {
                xPo += tp->coef_x[j] * r2 * log(r2);
                yPo += tp->coef_y[j] * r2 * log(r2);
            }
        }
        Pout[2 * i] = xPo;
        Pout[2 * i + 1] = yPo;
    }
    return 0;
}

variable_types:
Pin
float *

variable_types:
Pout
float *

variable_types: np int

variable_types: i int

variable_types: j int

variable_types: xPo float

variable_types: yPo float

variable_types: xP float

variable_types: yP float

user_defined_types: struct thinPlateStruct { int nc; float *xc; float *yc; float *coef_x; float *coef_y; float affine[6]; float lambda; }


decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
fprintf(stderr, "ThinPlate Error: %s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "ThinPlate Error: %s\n", a1);
exit(1);
}

original_code:
static void error(char *msg)
{
    fprintf(stderr, "ThinPlate Error: %s\n", msg);
    exit(1);
}


repo: mdsteele/milestone

canonical_decompiled_code:
void func0(void)
{
az_clear_highscore_list(&highscore_list);
}

original_code:
static void clear_highscore_list(void) {
  az_clear_highscore_list(&highscore_list);
}

canonical_original_code:
static void clear_highscore_list() {
  az_clear_highscore_list(&highscore_list);
}


decompiled_code:
__int64 load_highscore_list()
{
const char *v0; // rax
const char *v1; // r12
void *v2; // rsp
__int64 result; // rax
char v4[16]; // [rsp+0h] [rbp-10h] BYREF

v0 = (const char *)az_get_app_data_directory();
if ( !v0
|| (v1 = v0,
v2 = alloca(strlen(v0) + 16),
sprintf(v4, "%s/highscores.txt", v1),
result = az_load_highscore_list(v4, &highscore_list),
!(_BYTE)result) )
{
result = az_clear_highscore_list(&highscore_list);
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
const char *v0; // rax
const char *v1; // r12
void *v2; // rsp
__int64 result; // rax
char v4[16]; // [rsp+0h] [rbp-10h] BYREF

v0 = (const char *)az_get_app_data_directory();
if ( !v0
|| (v1 = v0,
v2 = alloca(strlen(v0) + 16),
sprintf(v4, "%s/highscores.txt", v1),
result = az_load_highscore_list(v4, &highscore_list),
!(_BYTE)result) )
{
result = az_clear_highscore_list(&highscore_list);
}
return result;
}

original_code:
static void load_highscore_list(void) {
  const char *data_dir = az_get_app_data_directory();
  if (data_dir != ((void *)0)) {
    char path_buffer[strlen(data_dir) + 16u];
    sprintf(path_buffer, "%s/highscores.txt", data_dir);
    if (az_load_highscore_list(path_buffer, &highscore_list)) return;
  }
  az_clear_highscore_list(&highscore_list);
}

canonical_original_code:
static void load_highscore_list() {
  char *data_dir = az_get_app_data_directory();
  if (data_dir != ((void *)0)) {
    char path_buffer[-1];
    sprintf(path_buffer, "%s/highscores.txt", data_dir);
    if (az_load_highscore_list(path_buffer, &highscore_list)) return;
  }
  az_clear_highscore_list(&highscore_list);
}


decompiled_code:
__int64 run_title_mode()
{
int v1[10]; // [rsp+0h] [rbp-28h] BYREF

az_init_title_state(&title_state, &highscore_list, last_game);
LABEL_2:
az_tick_title_state(&title_state, 0.01666666666666667);
az_tick_audio_mixer(&unk_23568);
az_start_screen_redraw();
az_draw_title_screen(&title_state);
az_finish_screen_redraw();
do
{
while ( 1 )
{
if ( !(unsigned __int8)az_poll_event(v1) )
goto LABEL_2;
if ( !v1[0] )
break;
if ( v1[0] == 2 )
return 1LL;
}
}
while ( v1[1] != 12 );
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
int v1[10]; // [rsp+0h] [rbp-28h] BYREF

az_init_title_state(&title_state, &highscore_list, last_game);
LABEL_2:
az_tick_title_state(&title_state, 0.01666666666666667);
az_tick_audio_mixer(&unk_23568);
az_start_screen_redraw();
az_draw_title_screen(&title_state);
az_finish_screen_redraw();
do
{
while ( 1 )
{
if ( !(unsigned __int8)az_poll_event(v1) )
goto LABEL_2;
if ( !v1[0] )
break;
if ( v1[0] == 2 )
return 1LL;
}
}
while ( v1[1] != 12 );
return 1LL;
}

original_code:
static az_mode_t run_title_mode(void) {
  az_init_title_state(&title_state, &highscore_list, last_game);
  while (1) {
    az_tick_title_state(&title_state, 1.0 / 60.0);
    az_tick_audio_mixer(&title_state.soundboard);
    az_start_screen_redraw(); {
      az_draw_title_screen(&title_state);
    } az_finish_screen_redraw();
    az_event_t event;
    while (az_poll_event(&event)) {
      switch (event.kind) {
        case AZ_EVENT_KEY_DOWN:
          if (event.key.id == AZ_KEY_RETURN) return PLAY_MODE;
          break;
        case AZ_EVENT_MOUSE_DOWN:
          return PLAY_MODE;
        default: break;
      }
    }
  }
}

canonical_original_code:
static enum az_mode_t run_title_mode() {
  az_init_title_state(&title_state, &highscore_list, last_game);
  while (1) {
    az_tick_title_state(&title_state, 1.0 / 60.0);
    az_tick_audio_mixer(&title_state.soundboard);
    az_start_screen_redraw(); {
      az_draw_title_screen(&title_state);
    } az_finish_screen_redraw();
    union az_event_t event;
    while (az_poll_event(&event)) {
      switch (event.kind) {
        case AZ_EVENT_KEY_DOWN:
          if (event.key.id == AZ_KEY_RETURN) return PLAY_MODE;
          break;
        case AZ_EVENT_MOUSE_DOWN:
          return PLAY_MODE;
        default: break;
      }
    }
  }
}

variable_types: union az_event_t { enum az_event_kind_t { AZ_EVENT_KEY_DOWN=0, AZ_EVENT_KEY_UP=1, AZ_EVENT_MOUSE_DOWN=2, AZ_EVENT_MOUSE_UP=3, AZ_EVENT_MOUSE_MOVE=4 } kind; struct { enum az_event_kind_t { AZ_EVENT_KEY_DOWN=0, AZ_EVENT_KEY_UP=1, AZ_EVENT_MOUSE_DOWN=2, AZ_EVENT_MOUSE_UP=3, AZ_EVENT_MOUSE_MOVE=4 } kind; enum az_key_id_t { AZ_KEY_UNKNOWN=0, AZ_KEY_ESCAPE=1, AZ_KEY_BACKTICK=2, AZ_KEY_HYPHEN=3, AZ_KEY_EQUALS=4, AZ_KEY_BACKSPACE=5, AZ_KEY_TAB=6, AZ_KEY_LEFT_BRACKET=7, AZ_KEY_RIGHT_BRACKET=8, AZ_KEY_BACKSLASH=9, AZ_KEY_SEMICOLON=10, AZ_KEY_QUOTE=11, AZ_KEY_RETURN=12, AZ_KEY_COMMA=13, AZ_KEY_PERIOD=14, AZ_KEY_SLASH=15, AZ_KEY_SPACE=16, AZ_KEY_UP_ARROW=17, AZ_KEY_DOWN_ARROW=18, AZ_KEY_RIGHT_ARROW=19, AZ_KEY_LEFT_ARROW=20, AZ_KEY_0=21, AZ_KEY_1=22, AZ_KEY_2=23, AZ_KEY_3=24, AZ_KEY_4=25, AZ_KEY_5=26, AZ_KEY_6=27, AZ_KEY_7=28, AZ_KEY_8=29, AZ_KEY_9=30, AZ_KEY_A=31, AZ_KEY_B=32, AZ_KEY_C=33, AZ_KEY_D=34, AZ_KEY_E=35, AZ_KEY_F=36, AZ_KEY_G=37, AZ_KEY_H=38, AZ_KEY_I=39, AZ_KEY_J=40, AZ_KEY_K=41, AZ_KEY_L=42, AZ_KEY_M=43, AZ_KEY_N=44, AZ_KEY_O=45, AZ_KEY_P=46, AZ_KEY_Q=47, AZ_KEY_R=48, AZ_KEY_S=49, AZ_KEY_T=50, AZ_KEY_U=51, AZ_KEY_V=52, AZ_KEY_W=53, AZ_KEY_X=54, AZ_KEY_Y=55, AZ_KEY_Z=56 } id; _Bool command; _Bool shift; int character; } key; struct { enum az_event_kind_t { AZ_EVENT_KEY_DOWN=0, AZ_EVENT_KEY_UP=1, AZ_EVENT_MOUSE_DOWN=2, AZ_EVENT_MOUSE_UP=3, AZ_EVENT_MOUSE_MOVE=4 } kind; int x; int dx; _Bool pressed; } mouse; }

return_type: enum az_mode_t { TITLE_MODE=0, PLAY_MODE=1, GAMEOVER_MODE=2 }

user_defined_types: union az_event_t { enum az_event_kind_t kind; struct { enum az_event_kind_t kind; enum az_key_id_t id; _Bool command; _Bool shift; int character; } key; struct { enum az_event_kind_t kind; int x; int dx; _Bool pressed; } mouse; }


decompiled_code:
__int64 run_play_mode()
{
int v1; // [rsp+0h] [rbp-28h] BYREF
int v2; // [rsp+4h] [rbp-24h]
int v3; // [rsp+8h] [rbp-20h]

az_init_play_state(&play_state);
az_set_mouse_position(400LL, 250LL);
while ( 1 )
{
az_tick_play_state(&play_state, 0.01666666666666667);
az_tick_audio_mixer(&unk_4C8);
if ( dword_554 < 0 )
break;
az_start_screen_redraw();
az_draw_play_screen(&play_state);
az_finish_screen_redraw();
while ( (unsigned __int8)az_poll_event(&v1) )
{
switch ( v1 )
{
case 2:
az_play_apply_mouse_click(&play_state);
break;
case 4:
az_play_apply_mouse_motion(&play_state, (unsigned int)(v2 - 400), (unsigned int)(v3 - 250));
az_set_mouse_position(400LL, 250LL);
break;
case 0:
if ( v2 == 1 )
return 2LL;
if ( v2 == 16 )
az_play_apply_spacebar(&play_state);
break;
}
}
}
return 2LL;
}

canonical_decompiled_code:
__int64 func3()
{
int v1; // [rsp+0h] [rbp-28h] BYREF
int v2; // [rsp+4h] [rbp-24h]
int v3; // [rsp+8h] [rbp-20h]

az_init_play_state(&play_state);
az_set_mouse_position(400LL, 250LL);
while ( 1 )
{
az_tick_play_state(&play_state, 0.01666666666666667);
az_tick_audio_mixer(&unk_4C8);
if ( dword_554 < 0 )
break;
az_start_screen_redraw();
az_draw_play_screen(&play_state);
az_finish_screen_redraw();
while ( (unsigned __int8)az_poll_event(&v1) )
{
switch ( v1 )
{
case 2:
az_play_apply_mouse_click(&play_state);
break;
case 4:
az_play_apply_mouse_motion(&play_state, (unsigned int)(v2 - 400), (unsigned int)(v3 - 250));
az_set_mouse_position(400LL, 250LL);
break;
case 0:
if ( v2 == 1 )
return 2LL;
if ( v2 == 16 )
az_play_apply_spacebar(&play_state);
break;
}
}
}
return 2LL;
}

original_code:
static az_mode_t run_play_mode(void) {
  az_init_play_state(&play_state);
  az_set_mouse_position((800 / 2), (500 / 2));
  while (1) {
    az_tick_play_state(&play_state, 1.0 / 60.0);
    az_tick_audio_mixer(&play_state.soundboard);
    if (play_state.num_lives < 0) return GAMEOVER_MODE;
    az_start_screen_redraw(); {
      az_draw_play_screen(&play_state);
    } az_finish_screen_redraw();
    az_event_t event;
    while (az_poll_event(&event)) {
      switch (event.kind) {
        case AZ_EVENT_KEY_DOWN:
          if (event.key.id == AZ_KEY_ESCAPE) return GAMEOVER_MODE;
          else if (event.key.id == AZ_KEY_SPACE) {
            az_play_apply_spacebar(&play_state);
          }
          break;
        case AZ_EVENT_MOUSE_DOWN:
          az_play_apply_mouse_click(&play_state);
          break;
        case AZ_EVENT_MOUSE_MOVE:
          az_play_apply_mouse_motion(&play_state,
                                     event.mouse.x - (800 / 2),
                                     event.mouse.y - (500 / 2));
          az_set_mouse_position((800 / 2), (500 / 2));
          break;
        default: break;
      }
    }
  }
}

canonical_original_code:
static enum az_mode_t run_play_mode() {
  az_init_play_state(&play_state);
  az_set_mouse_position((800 / 2), (500 / 2));
  while (1) {
    az_tick_play_state(&play_state, 1.0 / 60.0);
    az_tick_audio_mixer(&play_state.soundboard);
    if (play_state.num_lives < 0) return GAMEOVER_MODE;
    az_start_screen_redraw(); {
      az_draw_play_screen(&play_state);
    } az_finish_screen_redraw();
    union az_event_t event;
    while (az_poll_event(&event)) {
      switch (event.kind) {
        case AZ_EVENT_KEY_DOWN:
          if (event.key.id == AZ_KEY_ESCAPE) return GAMEOVER_MODE;
          else if (event.key.id == AZ_KEY_SPACE) {
            az_play_apply_spacebar(&play_state);
          }
          break;
        case AZ_EVENT_MOUSE_DOWN:
          az_play_apply_mouse_click(&play_state);
          break;
        case AZ_EVENT_MOUSE_MOVE:
          az_play_apply_mouse_motion(&play_state,
                                     event.mouse.x - (800 / 2),
                                     event.mouse.y - (500 / 2));
          az_set_mouse_position((800 / 2), (500 / 2));
          break;
        default: break;
      }
    }
  }
}

user_defined_types: enum az_mode_t { TITLE_MODE=0, PLAY_MODE=1, GAMEOVER_MODE=2 }

user_defined_types: enum az_event_kind_t { AZ_EVENT_KEY_DOWN=0, AZ_EVENT_KEY_UP=1, AZ_EVENT_MOUSE_DOWN=2, AZ_EVENT_MOUSE_UP=3, AZ_EVENT_MOUSE_MOVE=4 }

user_defined_types: enum az_key_id_t { AZ_KEY_UNKNOWN=0, AZ_KEY_ESCAPE=1, AZ_KEY_BACKTICK=2, AZ_KEY_HYPHEN=3, AZ_KEY_EQUALS=4, AZ_KEY_BACKSPACE=5, AZ_KEY_TAB=6, AZ_KEY_LEFT_BRACKET=7, AZ_KEY_RIGHT_BRACKET=8, AZ_KEY_BACKSLASH=9, AZ_KEY_SEMICOLON=10, AZ_KEY_QUOTE=11, AZ_KEY_RETURN=12, AZ_KEY_COMMA=13, AZ_KEY_PERIOD=14, AZ_KEY_SLASH=15, AZ_KEY_SPACE=16, AZ_KEY_UP_ARROW=17, AZ_KEY_DOWN_ARROW=18, AZ_KEY_RIGHT_ARROW=19, AZ_KEY_LEFT_ARROW=20, AZ_KEY_0=21, AZ_KEY_1=22, AZ_KEY_2=23, AZ_KEY_3=24, AZ_KEY_4=25, AZ_KEY_5=26, AZ_KEY_6=27, AZ_KEY_7=28, AZ_KEY_8=29, AZ_KEY_9=30, AZ_KEY_A=31, AZ_KEY_B=32, AZ_KEY_C=33, AZ_KEY_D=34, AZ_KEY_E=35, AZ_KEY_F=36, AZ_KEY_G=37, AZ_KEY_H=38, AZ_KEY_I=39, AZ_KEY_J=40, AZ_KEY_K=41, AZ_KEY_L=42, AZ_KEY_M=43, AZ_KEY_N=44, AZ_KEY_O=45, AZ_KEY_P=46, AZ_KEY_Q=47, AZ_KEY_R=48, AZ_KEY_S=49, AZ_KEY_T=50, AZ_KEY_U=51, AZ_KEY_V=52, AZ_KEY_W=53, AZ_KEY_X=54, AZ_KEY_Y=55, AZ_KEY_Z=56 }


decompiled_code:
size_t save_highscore_list()
{
const char *v0; // rax
const char *v1; // r12
void *v2; // rsp
size_t result; // rax
char v4[16]; // [rsp+0h] [rbp-10h] BYREF

v0 = (const char *)az_get_app_data_directory();
if ( !v0
|| (v1 = v0,
v2 = alloca(strlen(v0) + 16),
sprintf(v4, "%s/highscores.txt", v1),
result = az_save_highscore_list(&highscore_list, v4),
!(_BYTE)result) )
{
result = fwrite("WARNING: Failed to save high scores.\n", 1uLL, 0x25uLL, stderr);
}
return result;
}

canonical_decompiled_code:
size_t func4()
{
const char *v0; // rax
const char *v1; // r12
void *v2; // rsp
size_t result; // rax
char v4[16]; // [rsp+0h] [rbp-10h] BYREF

v0 = (const char *)az_get_app_data_directory();
if ( !v0
|| (v1 = v0,
v2 = alloca(strlen(v0) + 16),
sprintf(v4, "%s/highscores.txt", v1),
result = az_save_highscore_list(&highscore_list, v4),
!(_BYTE)result) )
{
result = fwrite("WARNING: Failed to save high scores.\n", 1uLL, 0x25uLL, stderr);
}
return result;
}

original_code:
static void save_highscore_list(void) {
  const char *data_dir = az_get_app_data_directory();
  if (data_dir != ((void *)0)) {
    char path_buffer[strlen(data_dir) + 16u];
    sprintf(path_buffer, "%s/highscores.txt", data_dir);
    if (az_save_highscore_list(&highscore_list, path_buffer)) return;
  }
  fprintf(stderr, "WARNING: Failed to save high scores.\n");
}

canonical_original_code:
static void save_highscore_list() {
  char *data_dir = az_get_app_data_directory();
  if (data_dir != ((void *)0)) {
    char path_buffer[-1];
    sprintf(path_buffer, "%s/highscores.txt", data_dir);
    if (az_save_highscore_list(&highscore_list, path_buffer)) return;
  }
  fprintf(stderr, "WARNING: Failed to save high scores.\n");
}


decompiled_code:
__int64 run_gameover_mode()
{
_QWORD *v0; // rbp
char v1; // bl
char v2; // al
char *v3; // rdi
__int64 v5; // r12
char v6; // r13
int v7; // [rsp+0h] [rbp-48h] BYREF
int v8; // [rsp+4h] [rbp-44h]
int c; // [rsp+Ch] [rbp-3Ch]

az_init_gameover_state(&gameover_state);
dword_494 = dword_568;
qword_498 = qword_560;
v0 = (_QWORD *)az_submit_highscore(&highscore_list);
byte_4A0 = v0 != 0LL;
do
{
v1 = 0;
az_tick_audio_mixer(&unk_408);
az_start_screen_redraw();
az_draw_gameover_screen(&gameover_state);
az_finish_screen_redraw();
LABEL_3:
while ( 1 )
{
v2 = az_poll_event(&v7);
if ( !v2 )
break;
while ( v7 )
{
if ( v7 != 2 )
goto LABEL_3;
if ( !byte_4A0 )
v1 = v2;
v2 = az_poll_event(&v7);
if ( !v2 )
goto LABEL_9;
}
if ( v8 == 12 )
{
v1 = v2;
}
else
{
v5 = dword_4A4;
if ( v8 == 5 )
{
if ( dword_4A4 > 0 )
{
--dword_4A4;
byte_4A8[(int)v5 - 1] = 0;
}
}
else if ( dword_4A4 <= 19 )
{
v6 = c;
if ( c > 0 )
{
if ( strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 -_.,?/!@#$%^&*()|~", c) )
{
byte_4A8[v5] = v6;
dword_4A4 = v5 + 1;
}
}
}
}
}
LABEL_9:
;
}
while ( !v1 );
if ( v0 )
{
v3 = "Mysterious Stranger";
if ( dword_4A4 )
v3 = byte_4A8;
*v0 = az_strdup(v3);
save_highscore_list();
}
last_game = (__int64)v0;
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
_QWORD *v0; // rbp
char v1; // bl
char v2; // al
char *v3; // rdi
__int64 v5; // r12
char v6; // r13
int v7; // [rsp+0h] [rbp-48h] BYREF
int v8; // [rsp+4h] [rbp-44h]
int c; // [rsp+Ch] [rbp-3Ch]

az_init_gameover_state(&gameover_state);
dword_494 = dword_568;
qword_498 = qword_560;
v0 = (_QWORD *)az_submit_highscore(&highscore_list);
byte_4A0 = v0 != 0LL;
do
{
v1 = 0;
az_tick_audio_mixer(&unk_408);
az_start_screen_redraw();
az_draw_gameover_screen(&gameover_state);
az_finish_screen_redraw();
LABEL_3:
while ( 1 )
{
v2 = az_poll_event(&v7);
if ( !v2 )
break;
while ( v7 )
{
if ( v7 != 2 )
goto LABEL_3;
if ( !byte_4A0 )
v1 = v2;
v2 = az_poll_event(&v7);
if ( !v2 )
goto LABEL_9;
}
if ( v8 == 12 )
{
v1 = v2;
}
else
{
v5 = dword_4A4;
if ( v8 == 5 )
{
if ( dword_4A4 > 0 )
{
--dword_4A4;
byte_4A8[(int)v5 - 1] = 0;
}
}
else if ( dword_4A4 <= 19 )
{
v6 = c;
if ( c > 0 )
{
if ( strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 -_.,?/!@#$%^&*()|~", c) )
{
byte_4A8[v5] = v6;
dword_4A4 = v5 + 1;
}
}
}
}
}
LABEL_9:
;
}
while ( !v1 );
if ( v0 )
{
v3 = "Mysterious Stranger";
if ( dword_4A4 )
v3 = byte_4A8;
*v0 = az_strdup(v3);
func4();
}
last_game = (__int64)v0;
return 0LL;
}

original_code:
static az_mode_t run_gameover_mode(void) {
  az_init_gameover_state(&gameover_state);
  gameover_state.last_wave = play_state.current_wave;
  gameover_state.score = play_state.score;
  az_highscore_t *entry = az_submit_highscore(
      &highscore_list, gameover_state.score, gameover_state.last_wave);
  gameover_state.is_high_score = (entry != ((void *)0));
  _Bool done = 0;
  while (!done) {
    az_tick_audio_mixer(&gameover_state.soundboard);
    az_start_screen_redraw(); {
      az_draw_gameover_screen(&gameover_state);
    } az_finish_screen_redraw();
    az_event_t event;
    while (az_poll_event(&event)) {
      switch (event.kind) {
        case AZ_EVENT_KEY_DOWN:
          if (event.key.id == AZ_KEY_RETURN) done = 1;
          else if (event.key.id == AZ_KEY_BACKSPACE) {
            if (gameover_state.cursor > 0) {
              gameover_state.name_buffer[--gameover_state.cursor] = '\0';
            }
          } else if (gameover_state.cursor < 20 &&
                     event.key.character > '\0' &&
                     strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                            "abcdefghijklmnopqrstuvwxyz"
                            "0123456789 -_.,?/!@#$%^&*()|~",
                            event.key.character) != ((void *)0)) {
            gameover_state.name_buffer[gameover_state.cursor++] =
              event.key.character;
          }
          break;
        case AZ_EVENT_MOUSE_DOWN:
          if (!gameover_state.is_high_score) done = 1;
          break;
        default: break;
      }
    }
  }
  if (entry != ((void *)0)) {
    entry->name = az_strdup(gameover_state.cursor == 0 ?
                            "Mysterious Stranger" :
                            gameover_state.name_buffer);
    save_highscore_list();
  }
  last_game = entry;
  return TITLE_MODE;
}

canonical_original_code:
static enum az_mode_t run_gameover_mode() {
  az_init_gameover_state(&gameover_state);
  gameover_state.last_wave = play_state.current_wave;
  gameover_state.score = play_state.score;
  struct az_highscore_t *entry = az_submit_highscore(
      &highscore_list, gameover_state.score, gameover_state.last_wave);
  gameover_state.is_high_score = (entry != ((void *)0));
  _Bool done = 0;
  while (!done) {
    az_tick_audio_mixer(&gameover_state.soundboard);
    az_start_screen_redraw(); {
      az_draw_gameover_screen(&gameover_state);
    } az_finish_screen_redraw();
    union az_event_t event;
    while (az_poll_event(&event)) {
      switch (event.kind) {
        case AZ_EVENT_KEY_DOWN:
          if (event.key.id == AZ_KEY_RETURN) done = 1;
          else if (event.key.id == AZ_KEY_BACKSPACE) {
            if (gameover_state.cursor > 0) {
              gameover_state.name_buffer[--gameover_state.cursor] = '\0';
            }
          } else if (gameover_state.cursor < 20 &&
                     event.key.character > '\0' &&
                     strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                            "abcdefghijklmnopqrstuvwxyz"
                            "0123456789 -_.,?/!@#$%^&*()|~",
                            event.key.character) != ((void *)0)) {
            gameover_state.name_buffer[gameover_state.cursor++] =
              event.key.character;
          }
          break;
        case AZ_EVENT_MOUSE_DOWN:
          if (!gameover_state.is_high_score) done = 1;
          break;
        default: break;
      }
    }
  }
  if (entry != ((void *)0)) {
    entry->name = az_strdup(gameover_state.cursor == 0 ?
                            "Mysterious Stranger" :
                            gameover_state.name_buffer);
    save_highscore_list();
  }
  last_game = entry;
  return TITLE_MODE;
}

variable_types: struct az_highscore_t { char *name; long score; int wave; } *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int i; // eax

atexit(clear_highscore_list);
az_init_random(clear_highscore_list, argv);
load_highscore_list();
az_init_gui(0LL);
for ( i = 0; ; i = run_gameover_mode() )
{
LABEL_2:
while ( i == 1 )
LABEL_6:
i = run_play_mode();
while ( i != 2 )
{
if ( i )
goto LABEL_2;
i = run_title_mode();
if ( i == 1 )
goto LABEL_6;
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int i; // eax

atexit(clear_highscore_list);
az_init_random(clear_highscore_list, argv);
func1();
az_init_gui(0LL);
for ( i = 0; ; i = func5() )
{
LABEL_2:
while ( i == 1 )
LABEL_6:
i = func3();
while ( i != 2 )
{
if ( i )
goto LABEL_2;
i = func2();
if ( i == 1 )
goto LABEL_6;
}
}
}

original_code:
int main(int argc, char **argv) {
  atexit(clear_highscore_list);
  az_init_random();
  load_highscore_list();
  az_init_gui(0);
  az_mode_t mode = TITLE_MODE;
  while (1) {
    switch (mode) {
      case TITLE_MODE: mode = run_title_mode(); break;
      case PLAY_MODE: mode = run_play_mode(); break;
      case GAMEOVER_MODE: mode = run_gameover_mode(); break;
    }
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  atexit(clear_highscore_list);
  az_init_random();
  load_highscore_list();
  az_init_gui(0);
  enum az_mode_t mode = TITLE_MODE;
  while (1) {
    switch (mode) {
      case TITLE_MODE: mode = run_title_mode(); break;
      case PLAY_MODE: mode = run_play_mode(); break;
      case GAMEOVER_MODE: mode = run_gameover_mode(); break;
    }
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: enum az_mode_t { TITLE_MODE=0, PLAY_MODE=1, GAMEOVER_MODE=2 }


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

if ( sdl_initialized )
_assert_fail("!sdl_initialized", "src/milestone/gui/screen.c", 0x33u, "az_register_gl_init_func");
result = num_gl_init_funcs;
if ( num_gl_init_funcs > 7 )
{
az_fatal("az_register_gl_init_func", "gl_init_funcs array is full.\n");
result = az_is_fullscreen();
}
else
{
gl_init_funcs[num_gl_init_funcs] = a1;
num_gl_init_funcs = result + 1;
}
return result;
}

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

if ( sdl_initialized )
_assert_fail("!sdl_initialized", "src/milestone/gui/screen.c", 0x33u, "az_register_gl_init_func");
result = num_gl_init_funcs;
if ( num_gl_init_funcs > 7 )
{
az_fatal("az_register_gl_init_func", "gl_init_funcs array is full.\n");
result = func1();
}
else
{
gl_init_funcs[num_gl_init_funcs] = a1;
num_gl_init_funcs = result + 1;
}
return result;
}

original_code:
void az_register_gl_init_func(az_init_func_t func) {
  ((!sdl_initialized) ? (void) (0) : __assert_fail ("!sdl_initialized", "src/milestone/gui/screen.c", 51, __extension__ __PRETTY_FUNCTION__));
  if (num_gl_init_funcs >= ((int)((sizeof(gl_init_funcs) / sizeof(*(gl_init_funcs))) / !(sizeof(gl_init_funcs) % sizeof(*(gl_init_funcs)))))) {
    _az_fatal(__func__, "gl_init_funcs array is full.\n");
  } else {
    gl_init_funcs[num_gl_init_funcs++] = func;
  }
}

canonical_original_code:
void az_register_gl_init_func(void (*func)()) {
  ((!sdl_initialized) ? (void) (0) : __assert_fail ("!sdl_initialized", "src/milestone/gui/screen.c", 51, __extension__ __PRETTY_FUNCTION__));
  if (num_gl_init_funcs >= ((int)((sizeof(gl_init_funcs) / sizeof(*(gl_init_funcs))) / !(sizeof(gl_init_funcs) % sizeof(*(gl_init_funcs)))))) {
    _az_fatal(__func__, "gl_init_funcs array is full.\n");
  } else {
    gl_init_funcs[num_gl_init_funcs++] = func;
  }
}

variable_types:
func
void (*)()


decompiled_code:
__int64 az_is_fullscreen()
{
if ( !sdl_initialized )
_assert_fail("sdl_initialized", "src/milestone/gui/screen.c", 0x4Au, "az_is_fullscreen");
if ( !display_initialized )
_assert_fail("display_initialized", "src/milestone/gui/screen.c", 0x4Bu, "az_is_fullscreen");
return (unsigned __int8)currently_fullscreen;
}

canonical_decompiled_code:
__int64 func1()
{
if ( !sdl_initialized )
_assert_fail("sdl_initialized", "src/milestone/gui/screen.c", 0x4Au, "az_is_fullscreen");
if ( !display_initialized )
_assert_fail("display_initialized", "src/milestone/gui/screen.c", 0x4Bu, "az_is_fullscreen");
return (unsigned __int8)currently_fullscreen;
}

original_code:
_Bool az_is_fullscreen(void) {
  ((sdl_initialized) ? (void) (0) : __assert_fail ("sdl_initialized", "src/milestone/gui/screen.c", 74, __extension__ __PRETTY_FUNCTION__));
  ((display_initialized) ? (void) (0) : __assert_fail ("display_initialized", "src/milestone/gui/screen.c", 75, __extension__ __PRETTY_FUNCTION__));
  return currently_fullscreen;
}

canonical_original_code:
_Bool az_is_fullscreen() {
  ((sdl_initialized) ? (void) (0) : __assert_fail ("sdl_initialized", "src/milestone/gui/screen.c", 74, __extension__ __PRETTY_FUNCTION__));
  ((display_initialized) ? (void) (0) : __assert_fail ("display_initialized", "src/milestone/gui/screen.c", 75, __extension__ __PRETTY_FUNCTION__));
  return currently_fullscreen;
}


decompiled_code:
void __fastcall az_set_fullscreen(char a1)
{
__int64 v1; // rbx
int v2; // [rsp+8h] [rbp-10h] BYREF
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( !sdl_initialized )
_assert_fail("sdl_initialized", "src/milestone/gui/screen.c", 0x50u, "az_set_fullscreen");
if ( !display_initialized || currently_fullscreen != a1 )
{
currently_fullscreen = a1;
az_pause_all_audio();
SDL_GL_SetAttribute(5LL, 1LL);
SDL_GL_SetAttribute(16LL, 1LL);
SDL_GL_SetAttribute(13LL, 1LL);
SDL_GL_SetAttribute(14LL, 2LL);
v2 = 0;
v3[0] = 0;
if ( display_initialized )
SDL_GetMouseState(&v2, v3);
if ( SDL_SetVideoMode(800LL, 500LL, 32LL, a1 == 0 ? 7 : -2147483641) )
{
if ( display_initialized )
SDL_WarpMouse((unsigned __int16)v2, LOWORD(v3[0]));
SDL_EnableUNICODE(1LL);
glDisable(2929LL);
glDepthMask(0LL);
glEnable(3042LL);
glBlendEquation(32774LL);
glBlendFunc(770LL, 771LL);
glEnable(2832LL);
glHint(3153LL, 4354LL);
glEnable(2848LL);
glHint(3154LL, 4354LL);
glEnable(2881LL);
glHint(3155LL, 4354LL);
glClearColor(0.0, 0.0, 0.0);
glClearDepth(1.0);
glViewport(0LL, 0LL, 800LL, 500LL);
glMatrixMode(5889LL);
glLoadIdentity();
glOrtho(0.0, 800.0, 500.0, 0.0, 1.0, -1.0);
glMatrixMode(5888LL);
glLoadIdentity();
if ( num_gl_init_funcs > 0 )
{
v1 = 0LL;
do
((void (*)(void))gl_init_funcs[v1++])();
while ( num_gl_init_funcs > (int)v1 );
}
display_initialized = 1;
az_unpause_all_audio();
}
else
{
az_fatal("az_set_fullscreen", "SDL_SetVideoMode failed.\n");
az_init_gui();
}
}
}

canonical_decompiled_code:
void __fastcall func2(char a1)
{
__int64 v1; // rbx
int v2; // [rsp+8h] [rbp-10h] BYREF
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( !sdl_initialized )
_assert_fail("sdl_initialized", "src/milestone/gui/screen.c", 0x50u, "az_set_fullscreen");
if ( !display_initialized || currently_fullscreen != a1 )
{
currently_fullscreen = a1;
az_pause_all_audio();
SDL_GL_SetAttribute(5LL, 1LL);
SDL_GL_SetAttribute(16LL, 1LL);
SDL_GL_SetAttribute(13LL, 1LL);
SDL_GL_SetAttribute(14LL, 2LL);
v2 = 0;
v3[0] = 0;
if ( display_initialized )
SDL_GetMouseState(&v2, v3);
if ( SDL_SetVideoMode(800LL, 500LL, 32LL, a1 == 0 ? 7 : -2147483641) )
{
if ( display_initialized )
SDL_WarpMouse((unsigned __int16)v2, LOWORD(v3[0]));
SDL_EnableUNICODE(1LL);
glDisable(2929LL);
glDepthMask(0LL);
glEnable(3042LL);
glBlendEquation(32774LL);
glBlendFunc(770LL, 771LL);
glEnable(2832LL);
glHint(3153LL, 4354LL);
glEnable(2848LL);
glHint(3154LL, 4354LL);
glEnable(2881LL);
glHint(3155LL, 4354LL);
glClearColor(0.0, 0.0, 0.0);
glClearDepth(1.0);
glViewport(0LL, 0LL, 800LL, 500LL);
glMatrixMode(5889LL);
glLoadIdentity();
glOrtho(0.0, 800.0, 500.0, 0.0, 1.0, -1.0);
glMatrixMode(5888LL);
glLoadIdentity();
if ( num_gl_init_funcs > 0 )
{
v1 = 0LL;
do
((void (*)(void))gl_init_funcs[v1++])();
while ( num_gl_init_funcs > (int)v1 );
}
display_initialized = 1;
az_unpause_all_audio();
}
else
{
az_fatal("az_set_fullscreen", "SDL_SetVideoMode failed.\n");
func3();
}
}
}

original_code:
void az_set_fullscreen(_Bool fullscreen) {
  ((sdl_initialized) ? (void) (0) : __assert_fail ("sdl_initialized", "src/milestone/gui/screen.c", 80, __extension__ __PRETTY_FUNCTION__));
  if (display_initialized && fullscreen == currently_fullscreen) return;
  currently_fullscreen = fullscreen;
  az_pause_all_audio();
  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
  SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
  SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2);
  int x = 0, y = 0;
  if (display_initialized) {
    SDL_GetMouseState(&x, &y);
  }
  if (!SDL_SetVideoMode(800, 500, 32,
                        (0x00000001 | SDL_GL_DOUBLEBUFFER | 0x00000002) | (fullscreen ? 0x80000000 : 0))) {
    _az_fatal(__func__, "SDL_SetVideoMode failed.\n");
  }
  if (display_initialized) {
    SDL_WarpMouse(x, y);
  }
  SDL_EnableUNICODE(1);
  glDisable(0x0B71);
  glDepthMask(0);
  glEnable(0x0BE2);
  glBlendEquation(0x8006);
  glBlendFunc(0x0302, 0x0303);
  glEnable(0x0B10);
  glHint(0x0C51, 0x1102);
  glEnable(0x0B20);
  glHint(0x0C52, 0x1102);
  glEnable(0x0B41);
  glHint(0x0C53, 0x1102);
  glClearColor(0, 0, 0, 0);
  glClearDepth(1.0f);
  glViewport(0, 0, 800, 500);
  glMatrixMode(0x1701);
  glLoadIdentity();
  glOrtho(0, 800, 500, 0, 1, -1);
  glMatrixMode(0x1700);
  glLoadIdentity();
  for (int i = 0; i < num_gl_init_funcs; ++i) {
    gl_init_funcs[i]();
  }
  display_initialized = 1;
  az_unpause_all_audio();
}

canonical_original_code:
void az_set_fullscreen(_Bool fullscreen) {
  ((sdl_initialized) ? (void) (0) : __assert_fail ("sdl_initialized", "src/milestone/gui/screen.c", 80, __extension__ __PRETTY_FUNCTION__));
  if (display_initialized && fullscreen == currently_fullscreen) return;
  currently_fullscreen = fullscreen;
  az_pause_all_audio();
  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
  SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
  SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2);
  int x = 0; int y = 0;
  if (display_initialized) {
    SDL_GetMouseState(&x, &y);
  }
  if (!SDL_SetVideoMode(800, 500, 32,
                        (0x00000001 | SDL_GL_DOUBLEBUFFER | 0x00000002) | (fullscreen ? 0x80000000 : 0))) {
    _az_fatal(__func__, "SDL_SetVideoMode failed.\n");
  }
  if (display_initialized) {
    SDL_WarpMouse(x, y);
  }
  SDL_EnableUNICODE(1);
  glDisable(0x0B71);
  glDepthMask(0);
  glEnable(0x0BE2);
  glBlendEquation(0x8006);
  glBlendFunc(0x0302, 0x0303);
  glEnable(0x0B10);
  glHint(0x0C51, 0x1102);
  glEnable(0x0B20);
  glHint(0x0C52, 0x1102);
  glEnable(0x0B41);
  glHint(0x0C53, 0x1102);
  glClearColor(0, 0, 0, 0);
  glClearDepth(1.0f);
  glViewport(0, 0, 800, 500);
  glMatrixMode(0x1701);
  glLoadIdentity();
  glOrtho(0, 800, 500, 0, 1, -1);
  glMatrixMode(0x1700);
  glLoadIdentity();
  for (int i = 0; i < num_gl_init_funcs; ++i) {
    gl_init_funcs[i]();
  }
  display_initialized = 1;
  az_unpause_all_audio();
}

variable_types: x int

variable_types: y int


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

if ( sdl_initialized )
_assert_fail("!sdl_initialized", "src/milestone/gui/screen.c", 0x3Cu, "az_init_gui");
if ( (unsigned int)SDL_Init(48LL) )
{
az_fatal("az_init_gui", "SDL_Init failed.\n");
result = az_start_screen_redraw();
}
else
{
atexit((void (*)(void))&SDL_Quit);
az_init_audio_mixer();
SDL_WM_SetCaption("Milestone (press Ctrl-M to run full-screen)", "Milestone");
sdl_initialized = 1;
az_set_fullscreen(a1);
result = SDL_ShowCursor(0LL);
}
return result;
}

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

if ( sdl_initialized )
_assert_fail("!sdl_initialized", "src/milestone/gui/screen.c", 0x3Cu, "az_init_gui");
if ( (unsigned int)SDL_Init(48LL) )
{
az_fatal("az_init_gui", "SDL_Init failed.\n");
result = func4();
}
else
{
atexit((void (*)(void))&SDL_Quit);
az_init_audio_mixer();
SDL_WM_SetCaption("Milestone (press Ctrl-M to run full-screen)", "Milestone");
sdl_initialized = 1;
func2(a1);
result = SDL_ShowCursor(0LL);
}
return result;
}

original_code:
void az_init_gui(_Bool fullscreen) {
  ((!sdl_initialized) ? (void) (0) : __assert_fail ("!sdl_initialized", "src/milestone/gui/screen.c", 60, __extension__ __PRETTY_FUNCTION__));
  if (SDL_Init(0x00000020 | 0x00000010) != 0) {
    _az_fatal(__func__, "SDL_Init failed.\n");
  }
  atexit(SDL_Quit);
  az_init_audio_mixer();
  SDL_WM_SetCaption("Milestone (press " "Ctrl" "-M to run full-screen)",
                    "Milestone");
  sdl_initialized = 1;
  az_set_fullscreen(fullscreen);
  SDL_ShowCursor(0);
}