usage

decompiled_code:
__int64 usage()
{
startup_error(&Version);
startup_error("\nUsage: xvi { options } [ file ... ]");
startup_error(" xvi { options } -t tag");
startup_error(" xvi { options } +[num] file");
startup_error(" xvi { options } +/pat file");
startup_error("\nOptions are:");
startup_error(" -c ex-command");
startup_error(" -R (set readonly mode)");
startup_error(" -s [no]boolean-parameter");
startup_error(" -s parameter=value");
return startup_error(" -w nlines (ignored)");
}

canonical_decompiled_code:
__int64 func0()
{
startup_error(&Version);
startup_error("\nUsage: xvi { options } [ file ... ]");
startup_error(" xvi { options } -t tag");
startup_error(" xvi { options } +[num] file");
startup_error(" xvi { options } +/pat file");
startup_error("\nOptions are:");
startup_error(" -c ex-command");
startup_error(" -R (set readonly mode)");
startup_error(" -s [no]boolean-parameter");
startup_error(" -s parameter=value");
return startup_error(" -w nlines (ignored)");
}

original_code:
static void
usage()
{
    startup_error(Version);
    startup_error("\nUsage: xvi { options } [ file ... ]");
    startup_error("       xvi { options } -t tag");
    startup_error("       xvi { options } +[num] file");
    startup_error("       xvi { options } +/pat  file");
    startup_error("\nOptions are:");
    startup_error("       -c ex-command");
    startup_error("       -R (set readonly mode)");
    startup_error("       -s [no]boolean-parameter");
    startup_error("       -s parameter=value");
    startup_error("       -w nlines (ignored)");
}


repo: martinwguy/xvi

decompiled_code:
__int64 new_buffer()
{
__int64 v0; // rax
__int64 v1; // rbx

v0 = alloc(720LL);
v1 = v0;
if ( v0 )
{
if ( (unsigned int)setup_buffer(v0) )
{
*(_QWORD *)(v1 + 40) = 0LL;
*(_QWORD *)(v1 + 48) = 0LL;
*(_DWORD *)(v1 + 60) = 0;
}
else
{
free((void *)v1);
v1 = 0LL;
}
}
return v1;
}

original_code:
Buffer *
new_buffer()
{
    Buffer *newbuf;
    newbuf = alloc(sizeof(Buffer));
    if (newbuf == ((void *)0)) {
 return(((void *)0));
    }
    if (setup_buffer(newbuf) == 0) {
 free(newbuf);
 return(((void *)0));
    }
    newbuf->b_filename = ((void *)0);
    newbuf->b_tempfname = ((void *)0);
    newbuf->b_nwindows = 0;
    return(newbuf);
}

canonical_original_code:
struct buffer *new_buffer()
{
    struct buffer *newbuf;
    newbuf = alloc(sizeof(Buffer));
    if (newbuf == ((void *)0)) {
 return(((void *)0));
    }
    if (setup_buffer(newbuf) == 0) {
 free(newbuf);
 return(((void *)0));
    }
    newbuf->b_filename = ((void *)0);
    newbuf->b_tempfname = ((void *)0);
    newbuf->b_nwindows = 0;
    return(newbuf);
}

variable_types: struct buffer { struct line { struct line *l_prev; struct line *l_next; char *l_text; int l_size; unsigned long l_number; } *b_line0; struct line *b_file; struct line *b_lastline; struct line *b_prevline; char *b_Undotext; char *b_filename; char *b_tempfname; unsigned int b_flags; int b_nwindows; struct mark { struct position { struct line *p_line; int p_index; } m_posn; int m_deleted; } b_mlist[26]; struct mark b_pcmark; struct changedata { unsigned int cd_nlevels; struct cmd { struct position cmd_startpos; struct position cmd_target; unsigned char cmd_flags; int cmd_two_char; int cmd_operator; int cmd_ch1; int cmd_ch2; long cmd_prenum; long cmd_opnum; int cmd_got_yp_name; int cmd_yp_name; int cmd_buffer_name; } *cd_vi_cmd; long cd_total_lines; struct change { struct change *c_next; enum c_type_t { C_LINE=0, C_CHAR=1, C_DEL_CHAR=2, C_POSITION=3 } c_type; unsigned long c_lineno; union { struct { long cul_nlines; struct line *cul_lines; } cu_l; struct { int cuc_index; int cuc_nchars; char *cuc_chars; } cu_c; struct { long cup_line; int cup_index; } cu_p; } c_u; } *cd_undo; struct change *cd_redo; } *b_change; } *

user_defined_types: struct buffer { struct line *b_line0; struct line *b_file; struct line *b_lastline; struct line *b_prevline; char *b_Undotext; char *b_filename; char *b_tempfname; unsigned int b_flags; int b_nwindows; struct mark b_mlist[26]; struct mark b_pcmark; struct changedata *b_change; }

user_defined_types: struct mark { struct position m_posn; int m_deleted; }

user_defined_types: struct changedata { unsigned int cd_nlevels; struct cmd *cd_vi_cmd; long cd_total_lines; struct change *cd_undo; struct change *cd_redo; }

user_defined_types: struct change { struct change *c_next; enum c_type_t c_type; unsigned long c_lineno; union { struct { long cul_nlines; struct line *cul_lines; } cu_l; struct { int cuc_index; int cuc_nchars; char *cuc_chars; } cu_c; struct { long cup_line; int cup_index; } cu_p; } c_u; }


lformat

decompiled_code:
__int64 lformat(__int64 a1, char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return vformat(a1, a2, (int *)va);
}

canonical_decompiled_code:
__int64 func11(__int64 a1, char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return func10(a1, a2, (int *)va);
}

original_code:
bool_t
lformat
    (Flexbuf *f, char *format, ...)
{
    va_list argp;
    bool_t retval;
    __builtin_va_start(argp,format);
    retval = vformat(f, format, argp);
    __builtin_va_end(argp);
    return retval;
}

canonical_original_code:
int lformat(struct Flexbuf *f, char *format, ...)
{
    __builtin_va_list argp;
    int retval;
    __builtin_va_start(argp,format);
    retval = vformat(f, format, argp);
    __builtin_va_end(argp);
    return retval;
}

variable_types: struct Flexbuf { char *fxb_chars; unsigned int fxb_max; unsigned int fxb_rcnt; unsigned int fxb_wcnt; } *

variable_types:
format
char *

variable_types: retval int

return_type: int


unpreserve

decompiled_code:
void unpreserve()
{
__int64 v0; // rbx
const char *v1; // rdi

if ( params[335] != 3 )
{
v0 = curbuf;
v1 = *(const char **)(curbuf + 48LL);
if ( v1 )
{
remove(v1);
free(*(void **)(v0 + 48));
*(_QWORD *)(v0 + 48) = 0LL;
}
}
}

canonical_decompiled_code:
void func3()
{
__int64 v0; // rbx
const char *v1; // rdi

if ( params[335] != 3 )
{
v0 = curbuf;
v1 = *(const char **)(curbuf + 48LL);
if ( v1 )
{
remove(v1);
free(*(void **)(v0 + 48));
*(_QWORD *)(v0 + 48) = 0LL;
}
}
}

original_code:
void
unpreserve()
{
    Buffer *buffer = curbuf;
    if ((params[P_preserve].p_value) != 3 && buffer->b_tempfname != ((void *)0)) {
 (void) remove(buffer->b_tempfname);
 free(buffer->b_tempfname);
 buffer->b_tempfname = ((void *)0);
    }
}

canonical_original_code:
void unpreserve()
{
    struct buffer *buffer = curbuf;
    if ((params[P_preserve].p_value) != 3 && buffer->b_tempfname != ((void *)0)) {
 (void) remove(buffer->b_tempfname);
 free(buffer->b_tempfname);
 buffer->b_tempfname = ((void *)0);
    }
}

return_type: void

user_defined_types: struct line { struct line *l_prev; struct line *l_next; char *l_text; int l_size; unsigned long l_number; }

user_defined_types: struct position { struct line *p_line; int p_index; }

user_defined_types: struct cmd { struct position cmd_startpos; struct position cmd_target; unsigned char cmd_flags; int cmd_two_char; int cmd_operator; int cmd_ch1; int cmd_ch2; long cmd_prenum; long cmd_opnum; int cmd_got_yp_name; int cmd_yp_name; int cmd_buffer_name; }

user_defined_types: enum c_type_t { C_LINE=0, C_CHAR=1, C_DEL_CHAR=2, C_POSITION=3 }


repo: martolini/heisprosjekt

decompiled_code:
_BOOL8 io_init()
{
int v0; // er12
unsigned int i; // ebx
int v2; // ebp
int v3; // ebp
int v4; // ebp

it_g = comedi_open("/dev/comedi0");
if ( !it_g )
return 0LL;
v0 = 0;
for ( i = 0; i != 8; ++i )
{
v2 = comedi_dio_config(it_g, 2LL, i, 0LL);
v3 = comedi_dio_config(it_g, 3LL, i, 1LL) | v2;
v4 = comedi_dio_config(it_g, 3LL, i + 8, 1LL) | v3;
v0 |= v4 | comedi_dio_config(it_g, 3LL, i + 16, 0LL);
}
return v0 == 0;
}

canonical_decompiled_code:
_BOOL8 func0()
{
int v0; // er12
unsigned int i; // ebx
int v2; // ebp
int v3; // ebp
int v4; // ebp

it_g = comedi_open("/dev/comedi0");
if ( !it_g )
return 0LL;
v0 = 0;
for ( i = 0; i != 8; ++i )
{
v2 = comedi_dio_config(it_g, 2LL, i, 0LL);
v3 = comedi_dio_config(it_g, 3LL, i, 1LL) | v2;
v4 = comedi_dio_config(it_g, 3LL, i + 8, 1LL) | v3;
v0 |= v4 | comedi_dio_config(it_g, 3LL, i + 16, 0LL);
}
return v0 == 0;
}

original_code:
int io_init()
{
 int i, status = 0;
 it_g = comedi_open("/dev/comedi0");
 if (it_g == ((void *)0))
  return 0;
 for (i = 0; i < 8; i++) {
  status |= comedi_dio_config(it_g, 2, i, COMEDI_INPUT);
  status |= comedi_dio_config(it_g, 3, i, COMEDI_OUTPUT);
  status |= comedi_dio_config(it_g, 3, i+8, COMEDI_OUTPUT);
  status |= comedi_dio_config(it_g, 3, i+16, COMEDI_INPUT);
 }
 return (status == 0);
}

canonical_original_code:
int io_init()
{
 int i; int status = 0;
 it_g = comedi_open("/dev/comedi0");
 if (it_g == ((void *)0))
  return 0;
 for (i = 0; i < 8; i++) {
  status |= comedi_dio_config(it_g, 2, i, COMEDI_INPUT);
  status |= comedi_dio_config(it_g, 3, i, COMEDI_OUTPUT);
  status |= comedi_dio_config(it_g, 3, i+8, COMEDI_OUTPUT);
  status |= comedi_dio_config(it_g, 3, i+16, COMEDI_INPUT);
 }
 return (status == 0);
}

variable_types: i int

variable_types: status int


decompiled_code:
__int64 __fastcall io_set_bit(int a1)
{
return comedi_dio_write(it_g, (unsigned int)(a1 >> 8), (unsigned __int8)a1, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return comedi_dio_write(it_g, (unsigned int)(a1 >> 8), (unsigned __int8)a1, 1LL);
}

original_code:
void io_set_bit(int channel)
{
 comedi_dio_write(it_g, channel >> 8, channel & 0xff, 1);
}

variable_types: channel int


decompiled_code:
__int64 __fastcall io_clear_bit(int a1)
{
return comedi_dio_write(it_g, (unsigned int)(a1 >> 8), (unsigned __int8)a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return comedi_dio_write(it_g, (unsigned int)(a1 >> 8), (unsigned __int8)a1, 0LL);
}

original_code:
void io_clear_bit(int channel)
{
 comedi_dio_write(it_g, channel >> 8, channel & 0xff, 0);
}


decompiled_code:
__int64 __fastcall io_write_analog(int a1, unsigned int a2)
{
return comedi_data_write(it_g, (unsigned int)(a1 >> 8), (unsigned __int8)a1, 0LL, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, unsigned int a2)
{
return comedi_data_write(it_g, (unsigned int)(a1 >> 8), (unsigned __int8)a1, 0LL, 0LL, a2);
}

original_code:
void io_write_analog(int channel, int value)
{
 comedi_data_write(it_g, channel>>8, channel&0xff, 0, 0x00, value);
}

variable_types: value int


decompiled_code:
__int64 __fastcall io_read_bit(int a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0;
comedi_dio_read(it_g, (unsigned int)(a1 >> 8), (unsigned __int8)a1, v2);
return v2[0];
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0;
comedi_dio_read(it_g, (unsigned int)(a1 >> 8), (unsigned __int8)a1, v2);
return v2[0];
}

original_code:
int io_read_bit(int channel)
{
 unsigned int data=0;
 comedi_dio_read(it_g, channel>>8, channel&0xff, &data);
 return (int)data;
}

canonical_original_code:
int io_read_bit(int channel)
{
 unsigned int data = 0;
 comedi_dio_read(it_g, channel>>8, channel&0xff, &data);
 return (int)data;
}

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall io_read_analog(int a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0;
comedi_data_read(it_g, (unsigned int)(a1 >> 8), (unsigned __int8)a1, 0LL, 0LL, v2);
return v2[0];
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0;
comedi_data_read(it_g, (unsigned int)(a1 >> 8), (unsigned __int8)a1, 0LL, 0LL, v2);
return v2[0];
}

original_code:
int io_read_analog(int channel)
{
 lsampl_t data = 0;
 comedi_data_read(it_g, channel>>8, channel&0xff, 0, 0x00, &data);
 return (int)data;
}

canonical_original_code:
int io_read_analog(int channel)
{
 unsigned int data = 0;
 comedi_data_read(it_g, channel>>8, channel&0xff, 0, 0x00, &data);
 return (int)data;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
elev_run(argc, argv, envp);
return 0;
}

original_code:
int main()
{
    elev_run();
    return 0;
}

canonical_original_code:
int main()
{
    elev_run();
    return 0;
}


decompiled_code:
int timer_start()
{
return gettimeofday(&startTime, 0LL);
}

canonical_decompiled_code:
int func0()
{
return gettimeofday(&startTime, 0LL);
}

original_code:
void timer_start(void) {
    gettimeofday(&startTime, ((void *)0));
}

canonical_original_code:
void timer_start() {
    gettimeofday(&startTime, ((void *)0));
}


decompiled_code:
_BOOL8 __fastcall timer_timerIsFinished(double a1)
{
gettimeofday(&endTime_0, 0LL);
return (double)(int)((endTime_0.tv_usec - startTime.tv_usec) / 1000
+ 1000 * (LODWORD(endTime_0.tv_sec) - LODWORD(startTime.tv_sec)))
/ 1000.0 >= a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(double a1)
{
gettimeofday(&endTime_0, 0LL);
return (double)(int)((endTime_0.tv_usec - startTime.tv_usec) / 1000
+ 1000 * (LODWORD(endTime_0.tv_sec) - LODWORD(startTime.tv_sec)))
/ 1000.0 >= a1;
}

original_code:
int timer_timerIsFinished(double sek) {
    static struct timeval endTime;
    gettimeofday(&endTime, ((void *)0));
    double secs = (endTime.tv_sec - startTime.tv_sec) * 1000
    + (endTime.tv_usec - startTime.tv_usec) / 1000;
    if (secs/1000 >= sek)
        return 1;
    return 0;
}

variable_types: sek double

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

variable_types: secs double


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

if ( a1 )
result = io_set_bit(771LL);
else
result = io_clear_bit(771LL);
return result;
}

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

if ( a1 )
result = io_set_bit(771LL);
else
result = io_clear_bit(771LL);
return result;
}

original_code:
void panel_setDoorOpenLamp(int value) {
    if (value)
        io_set_bit((0x300+3));
    else
        io_clear_bit((0x300+3));
}


decompiled_code:
__int64 panel_getObstructionSignal()
{
return io_read_bit(791LL);
}

canonical_decompiled_code:
__int64 func1()
{
return io_read_bit(791LL);
}

original_code:
int panel_getObstructionSignal(void) {
    return io_read_bit((0x300+23));
}

canonical_original_code:
int panel_getObstructionSignal() {
    return io_read_bit((0x300+23));
}


decompiled_code:
__int64 panel_getStopSignal()
{
return io_read_bit(790LL);
}

canonical_decompiled_code:
__int64 func2()
{
return io_read_bit(790LL);
}

original_code:
int panel_getStopSignal(void) {
    return io_read_bit((0x300+22));
}

canonical_original_code:
int panel_getStopSignal() {
    return io_read_bit((0x300+22));
}


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

if ( a1 )
result = io_set_bit(782LL);
else
result = io_clear_bit(782LL);
return result;
}

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

if ( a1 )
result = io_set_bit(782LL);
else
result = io_clear_bit(782LL);
return result;
}

original_code:
void panel_setStopLamp(int value) {
    if (value)
        io_set_bit((0x300+14));
    else
        io_clear_bit((0x300+14));
}


decompiled_code:
__int64 panel_getFloorSensorSignal()
{
int v0; // edx
__int64 result; // rax
int v2; // edx
int v3; // edx

v0 = io_read_bit(516LL);
result = 0LL;
if ( !v0 )
{
v2 = io_read_bit(517LL);
result = 1LL;
if ( !v2 )
{
v3 = io_read_bit(518LL);
result = 2LL;
if ( !v3 )
result = (unsigned int)io_read_bit(519LL) == 0 ? -1 : 3;
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // edx
__int64 result; // rax
int v2; // edx
int v3; // edx

v0 = io_read_bit(516LL);
result = 0LL;
if ( !v0 )
{
v2 = io_read_bit(517LL);
result = 1LL;
if ( !v2 )
{
v3 = io_read_bit(518LL);
result = 2LL;
if ( !v3 )
result = (unsigned int)io_read_bit(519LL) == 0 ? -1 : 3;
}
}
return result;
}

original_code:
int panel_getFloorSensorSignal(void) {
    if (io_read_bit((0x200+4)))
        return 0;
    else if (io_read_bit((0x200+5)))
        return 1;
    else if (io_read_bit((0x200+6)))
        return 2;
    else if (io_read_bit((0x200+7)))
        return 3;
    else
        return -1;
}

canonical_original_code:
int panel_getFloorSensorSignal() {
    if (io_read_bit((0x200+4)))
        return 0;
    else if (io_read_bit((0x200+5)))
        return 1;
    else if (io_read_bit((0x200+6)))
        return 2;
    else if (io_read_bit((0x200+7)))
        return 3;
    else
        return -1;
}


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

if ( a1 < 0 )
_assert_fail("floor >= 0", "panel.c", 0x89u, "panel_setFloorIndicator");
if ( a1 > 3 )
_assert_fail("floor < N_FLOORS", "panel.c", 0x8Au, "panel_setFloorIndicator");
if ( (a1 & 2) != 0 )
io_set_bit(768LL);
else
io_clear_bit(768LL);
if ( (a1 & 1) != 0 )
result = io_set_bit(769LL);
else
result = io_clear_bit(769LL);
return result;
}

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

if ( a1 < 0 )
_assert_fail("floor >= 0", "panel.c", 0x89u, "panel_setFloorIndicator");
if ( a1 > 3 )
_assert_fail("floor < N_FLOORS", "panel.c", 0x8Au, "panel_setFloorIndicator");
if ( (a1 & 2) != 0 )
io_set_bit(768LL);
else
io_clear_bit(768LL);
if ( (a1 & 1) != 0 )
result = io_set_bit(769LL);
else
result = io_clear_bit(769LL);
return result;
}

original_code:
void panel_setFloorIndicator(int floor) {
    ((void) sizeof ((floor >= 0) ? 1 : 0), __extension__ ({ if (floor >= 0) ; else __assert_fail ("floor >= 0", "panel.c", 137, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((floor < 4) ? 1 : 0), __extension__ ({ if (floor < 4) ; else __assert_fail ("floor < N_FLOORS", "panel.c", 138, __extension__ __PRETTY_FUNCTION__); }));
    if (floor & 0x02)
        io_set_bit((0x300+0));
    else
        io_clear_bit((0x300+0));
    if (floor & 0x01)
        io_set_bit((0x300+1));
    else
        io_clear_bit((0x300+1));
}

variable_types: floor int


decompiled_code:
_BOOL8 __fastcall panel_getButtonSignal(unsigned int a1, int a2)
{
if ( a2 < 0 )
_assert_fail("floor >= 0", "panel.c", 0x9Cu, "panel_getButtonSignal");
if ( a2 > 3 )
_assert_fail("floor < N_FLOORS", "panel.c", 0x9Du, "panel_getButtonSignal");
if ( !a1 && a2 == 3 )
_assert_fail("!(button == BUTTON_CALL_UP && floor == N_FLOORS-1)", "panel.c", 0x9Eu, "panel_getButtonSignal");
if ( a1 == 1 && !a2 )
_assert_fail("!(button == BUTTON_CALL_DOWN && floor == 0)", "panel.c", 0x9Fu, "panel_getButtonSignal");
if ( a1 > 2 )
_assert_fail(
"button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND",
"panel.c",
0xA0u,
"panel_getButtonSignal");
return (unsigned int)io_read_bit((unsigned int)button_channel_matrix[3 * a2 + a1]) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(unsigned int a1, int a2)
{
if ( a2 < 0 )
_assert_fail("floor >= 0", "panel.c", 0x9Cu, "panel_getButtonSignal");
if ( a2 > 3 )
_assert_fail("floor < N_FLOORS", "panel.c", 0x9Du, "panel_getButtonSignal");
if ( !a1 && a2 == 3 )
_assert_fail("!(button == BUTTON_CALL_UP && floor == N_FLOORS-1)", "panel.c", 0x9Eu, "panel_getButtonSignal");
if ( a1 == 1 && !a2 )
_assert_fail("!(button == BUTTON_CALL_DOWN && floor == 0)", "panel.c", 0x9Fu, "panel_getButtonSignal");
if ( a1 > 2 )
_assert_fail(
"button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND",
"panel.c",
0xA0u,
"panel_getButtonSignal");
return (unsigned int)io_read_bit((unsigned int)button_channel_matrix[3 * a2 + a1]) != 0;
}

original_code:
int panel_getButtonSignal(elev_button_type_t button, int floor) {
    ((void) sizeof ((floor >= 0) ? 1 : 0), __extension__ ({ if (floor >= 0) ; else __assert_fail ("floor >= 0", "panel.c", 156, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((floor < 4) ? 1 : 0), __extension__ ({ if (floor < 4) ; else __assert_fail ("floor < N_FLOORS", "panel.c", 157, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((!(button == BUTTON_CALL_UP && floor == 4 -1)) ? 1 : 0), __extension__ ({ if (!(button == BUTTON_CALL_UP && floor == 4 -1)) ; else __assert_fail ("!(button == BUTTON_CALL_UP && floor == N_FLOORS-1)", "panel.c", 158, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((!(button == BUTTON_CALL_DOWN && floor == 0)) ? 1 : 0), __extension__ ({ if (!(button == BUTTON_CALL_DOWN && floor == 0)) ; else __assert_fail ("!(button == BUTTON_CALL_DOWN && floor == 0)", "panel.c", 159, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND) ? 1 : 0), __extension__ ({ if (button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND) ; else __assert_fail ("button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND", "panel.c", 160, __extension__ __PRETTY_FUNCTION__); }));
    if (io_read_bit(button_channel_matrix[floor][button]))
        return 1;
    else
        return 0;
}

canonical_original_code:
int panel_getButtonSignal(enum tag_elev_lamp_type button, int floor) {
    ((void) sizeof ((floor >= 0) ? 1 : 0), __extension__ ({ if (floor >= 0) ; else __assert_fail ("floor >= 0", "panel.c", 156, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((floor < 4) ? 1 : 0), __extension__ ({ if (floor < 4) ; else __assert_fail ("floor < N_FLOORS", "panel.c", 157, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((!(button == BUTTON_CALL_UP && floor == 4 -1)) ? 1 : 0), __extension__ ({ if (!(button == BUTTON_CALL_UP && floor == 4 -1)) ; else __assert_fail ("!(button == BUTTON_CALL_UP && floor == N_FLOORS-1)", "panel.c", 158, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((!(button == BUTTON_CALL_DOWN && floor == 0)) ? 1 : 0), __extension__ ({ if (!(button == BUTTON_CALL_DOWN && floor == 0)) ; else __assert_fail ("!(button == BUTTON_CALL_DOWN && floor == 0)", "panel.c", 159, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND) ? 1 : 0), __extension__ ({ if (button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND) ; else __assert_fail ("button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND", "panel.c", 160, __extension__ __PRETTY_FUNCTION__); }));
    if (io_read_bit(button_channel_matrix[floor][button]))
        return 1;
    else
        return 0;
}

variable_types: enum tag_elev_lamp_type { BUTTON_CALL_UP=0, BUTTON_CALL_DOWN=1, BUTTON_COMMAND=2 }


decompiled_code:
__int64 __fastcall panel_setButtonLamp(unsigned int a1, int a2, int a3)
{
__int64 result; // rax

if ( a2 < 0 )
_assert_fail("floor >= 0", "panel.c", 0xAEu, "panel_setButtonLamp");
if ( a2 > 3 )
_assert_fail("floor < N_FLOORS", "panel.c", 0xAFu, "panel_setButtonLamp");
if ( !a1 && a2 == 3 )
_assert_fail("!(button == BUTTON_CALL_UP && floor == N_FLOORS-1)", "panel.c", 0xB0u, "panel_setButtonLamp");
if ( a1 == 1 && !a2 )
_assert_fail("!(button == BUTTON_CALL_DOWN && floor == 0)", "panel.c", 0xB1u, "panel_setButtonLamp");
if ( a1 > 2 )
_assert_fail(
"button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND",
"panel.c",
0xB2u,
"panel_setButtonLamp");
if ( a3 == 1 )
result = io_set_bit((unsigned int)lamp_channel_matrix[3 * a2 + a1]);
else
result = io_clear_bit((unsigned int)lamp_channel_matrix[3 * a2 + a1]);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, int a2, int a3)
{
__int64 result; // rax

if ( a2 < 0 )
_assert_fail("floor >= 0", "panel.c", 0xAEu, "panel_setButtonLamp");
if ( a2 > 3 )
_assert_fail("floor < N_FLOORS", "panel.c", 0xAFu, "panel_setButtonLamp");
if ( !a1 && a2 == 3 )
_assert_fail("!(button == BUTTON_CALL_UP && floor == N_FLOORS-1)", "panel.c", 0xB0u, "panel_setButtonLamp");
if ( a1 == 1 && !a2 )
_assert_fail("!(button == BUTTON_CALL_DOWN && floor == 0)", "panel.c", 0xB1u, "panel_setButtonLamp");
if ( a1 > 2 )
_assert_fail(
"button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND",
"panel.c",
0xB2u,
"panel_setButtonLamp");
if ( a3 == 1 )
result = io_set_bit((unsigned int)lamp_channel_matrix[3 * a2 + a1]);
else
result = io_clear_bit((unsigned int)lamp_channel_matrix[3 * a2 + a1]);
return result;
}

original_code:
void panel_setButtonLamp(elev_button_type_t button, int floor, int value) {
    ((void) sizeof ((floor >= 0) ? 1 : 0), __extension__ ({ if (floor >= 0) ; else __assert_fail ("floor >= 0", "panel.c", 174, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((floor < 4) ? 1 : 0), __extension__ ({ if (floor < 4) ; else __assert_fail ("floor < N_FLOORS", "panel.c", 175, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((!(button == BUTTON_CALL_UP && floor == 4 -1)) ? 1 : 0), __extension__ ({ if (!(button == BUTTON_CALL_UP && floor == 4 -1)) ; else __assert_fail ("!(button == BUTTON_CALL_UP && floor == N_FLOORS-1)", "panel.c", 176, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((!(button == BUTTON_CALL_DOWN && floor == 0)) ? 1 : 0), __extension__ ({ if (!(button == BUTTON_CALL_DOWN && floor == 0)) ; else __assert_fail ("!(button == BUTTON_CALL_DOWN && floor == 0)", "panel.c", 177, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND) ? 1 : 0), __extension__ ({ if (button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND) ; else __assert_fail ("button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND", "panel.c", 178, __extension__ __PRETTY_FUNCTION__); }));
    if (value == 1)
        io_set_bit(lamp_channel_matrix[floor][button]);
    else
        io_clear_bit(lamp_channel_matrix[floor][button]);
}

canonical_original_code:
void panel_setButtonLamp(enum tag_elev_lamp_type button, int floor, int value) {
    ((void) sizeof ((floor >= 0) ? 1 : 0), __extension__ ({ if (floor >= 0) ; else __assert_fail ("floor >= 0", "panel.c", 174, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((floor < 4) ? 1 : 0), __extension__ ({ if (floor < 4) ; else __assert_fail ("floor < N_FLOORS", "panel.c", 175, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((!(button == BUTTON_CALL_UP && floor == 4 -1)) ? 1 : 0), __extension__ ({ if (!(button == BUTTON_CALL_UP && floor == 4 -1)) ; else __assert_fail ("!(button == BUTTON_CALL_UP && floor == N_FLOORS-1)", "panel.c", 176, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((!(button == BUTTON_CALL_DOWN && floor == 0)) ? 1 : 0), __extension__ ({ if (!(button == BUTTON_CALL_DOWN && floor == 0)) ; else __assert_fail ("!(button == BUTTON_CALL_DOWN && floor == 0)", "panel.c", 177, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND) ? 1 : 0), __extension__ ({ if (button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND) ; else __assert_fail ("button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND", "panel.c", 178, __extension__ __PRETTY_FUNCTION__); }));
    if (value == 1)
        io_set_bit(lamp_channel_matrix[floor][button]);
    else
        io_clear_bit(lamp_channel_matrix[floor][button]);
}

user_defined_types: enum tag_elev_lamp_type { BUTTON_CALL_UP=0, BUTTON_CALL_DOWN=1, BUTTON_COMMAND=2 }


decompiled_code:
__int64 panel_init()
{
int v0; // ebx

v0 = 0;
while ( 1 )
{
while ( !v0 )
{
panel_setButtonLamp(0, 0, 0);
panel_setButtonLamp(2u, 0, 0);
v0 = 1;
}
panel_setButtonLamp(1u, v0, 0);
if ( v0 == 3 )
break;
panel_setButtonLamp(0, v0, 0);
panel_setButtonLamp(2u, v0++, 0);
if ( v0 == 4 )
goto LABEL_4;
}
panel_setButtonLamp(2u, 3, 0);
LABEL_4:
panel_setStopLamp(0);
panel_setDoorOpenLamp(0);
panel_setFloorIndicator(1);
return 1LL;
}

original_code:
int panel_init(void) {
    int i;
    for (i = 0; i < 4; ++i) {
        if (i != 0)
            panel_setButtonLamp(BUTTON_CALL_DOWN, i, LAMP_OFF);
        if (i != 4 -1)
            panel_setButtonLamp(BUTTON_CALL_UP, i, LAMP_OFF);
        panel_setButtonLamp(BUTTON_COMMAND, i, LAMP_OFF);
    }
    panel_setStopLamp(LAMP_OFF);
    panel_setDoorOpenLamp(LAMP_OFF);
    panel_setFloorIndicator(LAMP_ON);
    return 1;
}

canonical_original_code:
int panel_init() {
    int i;
    for (i = 0; i < 4; ++i) {
        if (i != 0)
            panel_setButtonLamp(BUTTON_CALL_DOWN, i, LAMP_OFF);
        if (i != 4 -1)
            panel_setButtonLamp(BUTTON_CALL_UP, i, LAMP_OFF);
        panel_setButtonLamp(BUTTON_COMMAND, i, LAMP_OFF);
    }
    panel_setStopLamp(LAMP_OFF);
    panel_setDoorOpenLamp(LAMP_OFF);
    panel_setFloorIndicator(LAMP_ON);
    return 1;
}


decompiled_code:
void __fastcall panel_checkForOrders(_DWORD *a1)
{
unsigned int i; // ebp
unsigned int j; // ebx
unsigned int v3; // er12

for ( i = 0; i != 4; ++i )
{
v3 = 1;
for ( j = 0; ; ++j )
{
if ( j == 1 && !i || !j && i == 3 )
goto LABEL_6;
if ( (j == 2 || *a1 != 4) && ((unsigned int)(*a1 - 2) > 1 || a1[3] != i) && panel_getButtonSignal(j, i) )
break;
LABEL_16:
if ( v3 > 2 )
goto LABEL_17;
LABEL_6:
++v3;
}
panel_setButtonLamp(j, i, 1);
if ( j == 1 )
{
oq_addOuterOrder(0LL, i);
goto LABEL_6;
}
if ( j != 2 )
{
if ( !j )
{
oq_addOuterOrder(1LL, i);
goto LABEL_6;
}
goto LABEL_16;
}
oq_addInnerOrder(i, (unsigned int)a1[3]);
LABEL_17:
;
}
}

canonical_decompiled_code:
void __fastcall func9(_DWORD *a1)
{
unsigned int i; // ebp
unsigned int j; // ebx
unsigned int v3; // er12

for ( i = 0; i != 4; ++i )
{
v3 = 1;
for ( j = 0; ; ++j )
{
if ( j == 1 && !i || !j && i == 3 )
goto LABEL_6;
if ( (j == 2 || *a1 != 4) && ((unsigned int)(*a1 - 2) > 1 || a1[3] != i) && func6(j, i) )
break;
LABEL_16:
if ( v3 > 2 )
goto LABEL_17;
LABEL_6:
++v3;
}
func7(j, i, 1);
if ( j == 1 )
{
oq_addOuterOrder(0LL, i);
goto LABEL_6;
}
if ( j != 2 )
{
if ( !j )
{
oq_addOuterOrder(1LL, i);
goto LABEL_6;
}
goto LABEL_16;
}
oq_addInnerOrder(i, (unsigned int)a1[3]);
LABEL_17:
;
}
}

original_code:
void panel_checkForOrders(const elevatorParameters_t *param) {
    int floor;
    elev_button_type_t buttonType;
    for (floor=0; floor<4; floor++) {
        for (buttonType = BUTTON_CALL_UP; buttonType <= BUTTON_COMMAND; buttonType++) {
            if ((buttonType == BUTTON_CALL_DOWN && floor == 0) || (buttonType == BUTTON_CALL_UP && floor == 4 -1))
                continue;
            else if (buttonType != BUTTON_COMMAND && param->currentState == STATE_EMERGENCYSTOP)
                continue;
            else if ((param->currentState == STATE_OPENDOOR || param->currentState == STATE_CLOSEDOOR) && floor == param->currentFloor)
                continue;
            int buttonPushed = panel_getButtonSignal(buttonType, floor);
            if (buttonPushed) {
                panel_setButtonLamp(buttonType, floor, LAMP_ON);
                switch(buttonType) {
                    case BUTTON_CALL_UP:
                        oq_addOuterOrder(DIR_UP, floor);
                        break;
                    case BUTTON_CALL_DOWN:
                        oq_addOuterOrder(DIR_DOWN, floor);
                        break;
                    case BUTTON_COMMAND:
                        oq_addInnerOrder(floor, param->currentFloor);
                        break;
                }
            }
        }
    }
}

canonical_original_code:
void panel_checkForOrders(struct tag_elevatorParameters_t *param) {
    int floor;
    enum tag_elev_lamp_type buttonType;
    for (floor=0; floor<4; floor++) {
        for (buttonType = BUTTON_CALL_UP; buttonType <= BUTTON_COMMAND; buttonType++) {
            if ((buttonType == BUTTON_CALL_DOWN && floor == 0) || (buttonType == BUTTON_CALL_UP && floor == 4 -1))
                continue;
            else if (buttonType != BUTTON_COMMAND && param->currentState == STATE_EMERGENCYSTOP)
                continue;
            else if ((param->currentState == STATE_OPENDOOR || param->currentState == STATE_CLOSEDOOR) && floor == param->currentFloor)
                continue;
            int buttonPushed = panel_getButtonSignal(buttonType, floor);
            if (buttonPushed) {
                panel_setButtonLamp(buttonType, floor, LAMP_ON);
                switch(buttonType) {
                    case BUTTON_CALL_UP:
                        oq_addOuterOrder(DIR_UP, floor);
                        break;
                    case BUTTON_CALL_DOWN:
                        oq_addOuterOrder(DIR_DOWN, floor);
                        break;
                    case BUTTON_COMMAND:
                        oq_addInnerOrder(floor, param->currentFloor);
                        break;
                }
            }
        }
    }
}

variable_types: struct tag_elevatorParameters_t { enum elevatorState_t { STATE_IDLE=0, STATE_DRIVE=1, STATE_OPENDOOR=2, STATE_CLOSEDOOR=3, STATE_EMERGENCYSTOP=4 } currentState; enum elevatorState_t { STATE_IDLE=0, STATE_DRIVE=1, STATE_OPENDOOR=2, STATE_CLOSEDOOR=3, STATE_EMERGENCYSTOP=4 } nextState; enum elevatorDirection_t { DIR_DOWN=0, DIR_UP=1 } directionUp; int currentFloor; int signals[-1]; } *

variable_types: buttonPushed int

user_defined_types: struct tag_elevatorParameters_t { enum elevatorState_t currentState; enum elevatorState_t nextState; enum elevatorDirection_t directionUp; int currentFloor; int signals[-1]; }


decompiled_code:
__int64 __fastcall panel_turnOffLightsInFloor(int a1)
{
unsigned int i; // ebx
__int64 result; // rax

for ( i = 0; ; ++i )
{
if ( (i != 1 || a1) && (i || a1 != 3) )
{
panel_setButtonLamp(i, a1, 0);
result = i + 1;
if ( (unsigned int)result > 2 )
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
unsigned int i; // ebx
__int64 result; // rax

for ( i = 0; ; ++i )
{
if ( (i != 1 || a1) && (i || a1 != 3) )
{
func7(i, a1, 0);
result = i + 1;
if ( (unsigned int)result > 2 )
break;
}
}
return result;
}

original_code:
void panel_turnOffLightsInFloor(int floor) {
    elev_button_type_t buttonType;
    for (buttonType = BUTTON_CALL_UP; buttonType <= BUTTON_COMMAND; buttonType++) {
        if ((buttonType == BUTTON_CALL_DOWN && floor == 0) || (buttonType == BUTTON_CALL_UP && floor == 4 -1))
            continue;
        panel_setButtonLamp(buttonType, floor, LAMP_OFF);
    }
}

canonical_original_code:
void panel_turnOffLightsInFloor(int floor) {
    enum tag_elev_lamp_type buttonType;
    for (buttonType = BUTTON_CALL_UP; buttonType <= BUTTON_COMMAND; buttonType++) {
        if ((buttonType == BUTTON_CALL_DOWN && floor == 0) || (buttonType == BUTTON_CALL_UP && floor == 4 -1))
            continue;
        panel_setButtonLamp(buttonType, floor, LAMP_OFF);
    }
}


decompiled_code:
__int64 panel_turnOffAllLights()
{
panel_turnOffLightsInFloor(0);
panel_turnOffLightsInFloor(1);
panel_turnOffLightsInFloor(2);
return panel_turnOffLightsInFloor(3);
}

original_code:
void panel_turnOffAllLights(void) {
    int floor;
    for (floor = 0; floor<4; floor++)
        panel_turnOffLightsInFloor(floor);
}

canonical_original_code:
void panel_turnOffAllLights() {
    int floor;
    for (floor = 0; floor<4; floor++)
        panel_turnOffLightsInFloor(floor);
}


decompiled_code:
__int64 oq_init()
{
if ( !isInitialized_0 )
{
orders = 0;
dword_184 = 0;
dword_188 = 0;
dword_18C = 0;
dword_190 = 0;
dword_194 = 0;
dword_198 = 0;
dword_19C = 0;
isInitialized_0 = 1;
}
return (unsigned int)isInitialized_0;
}

canonical_decompiled_code:
__int64 func0()
{
if ( !isInitialized_0 )
{
orders = 0;
dword_184 = 0;
dword_188 = 0;
dword_18C = 0;
dword_190 = 0;
dword_194 = 0;
dword_198 = 0;
dword_19C = 0;
isInitialized_0 = 1;
}
return (unsigned int)isInitialized_0;
}

original_code:
int oq_init(void) {
    static int isInitialized = 0;
    if (!isInitialized) {
        int dir, floor;
        for (dir=DIR_DOWN; dir<= DIR_UP; dir++) {
            for (floor=0; floor<4; floor++)
                orders[dir][floor] = 0;
        }
        isInitialized = 1;
    }
    return isInitialized;
}

canonical_original_code:
int oq_init() {
    static int isInitialized = 0;
    if (!isInitialized) {
        int dir; int floor;
        for (dir=DIR_DOWN; dir<= DIR_UP; dir++) {
            for (floor=0; floor<4; floor++)
                orders[dir][floor] = 0;
        }
        isInitialized = 1;
    }
    return isInitialized;
}

variable_types: isInitialized int

variable_types: dir int


decompiled_code:
__int64 oq_hasOrders()
{
int *v0; // rax
unsigned int v1; // edx

v0 = &orders;
while ( 1 )
{
if ( *v0 )
return 1;
v1 = v0[4];
if ( v1 )
break;
if ( ++v0 == &dword_190 )
return v1;
}
return 1;
}

canonical_decompiled_code:
__int64 func1()
{
int *v0; // rax
unsigned int v1; // edx

v0 = &orders;
while ( 1 )
{
if ( *v0 )
return 1;
v1 = v0[4];
if ( v1 )
break;
if ( ++v0 == &dword_190 )
return v1;
}
return 1;
}

original_code:
int oq_hasOrders(void) {
    int floor;
    for (floor = 0; floor<4; floor++) {
        if (orders[DIR_DOWN][floor] || orders[DIR_UP][floor])
            return 1;
    }
    return 0;
}

canonical_original_code:
int oq_hasOrders() {
    int floor;
    for (floor = 0; floor<4; floor++) {
        if (orders[DIR_DOWN][floor] || orders[DIR_UP][floor])
            return 1;
    }
    return 0;
}


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

result = a2 + 4LL * a1;
orders[result] = 1;
return result;
}

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

result = a2 + 4LL * a1;
orders[result] = 1;
return result;
}

original_code:
void oq_addOuterOrder(elevatorDirection_t direction, int floor) {
    orders[direction][floor] = 1;
}

canonical_original_code:
void oq_addOuterOrder(enum elevatorDirection_t direction, int floor) {
    orders[direction][floor] = 1;
}

variable_types: enum elevatorDirection_t { DIR_DOWN=0, DIR_UP=1 }


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

result = a1 + 4LL * (a1 > a2);
orders[result] = 1;
return result;
}

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

result = a1 + 4LL * (a1 > a2);
orders[result] = 1;
return result;
}

original_code:
void oq_addInnerOrder(int floor, int currentFloor) {
    int direction = DIR_DOWN;
    if (floor > currentFloor)
        direction = DIR_UP;
    orders[direction][floor] = 1;
}

variable_types: currentFloor int

variable_types: direction int


decompiled_code:
void __fastcall oq_deleteOrderInFloor(int a1)
{
orders[a1] = 0;
dword_190[a1] = 0;
}

canonical_decompiled_code:
void __fastcall func4(int a1)
{
orders[a1] = 0;
dword_190[a1] = 0;
}

original_code:
void oq_deleteOrderInFloor(int floor) {
    int dir;
    for (dir=DIR_DOWN; dir<= DIR_UP; dir++)
        orders[dir][floor] = 0;
}


decompiled_code:
__int64 __fastcall oq_hasOrderInFloor(int a1, int a2)
{
return (unsigned int)orders[4 * a1 + a2];
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2)
{
return (unsigned int)orders[4 * a1 + a2];
}

original_code:
int oq_hasOrderInFloor(elevatorDirection_t direction, int floor) {
    return orders[direction][floor];
}

canonical_original_code:
int oq_hasOrderInFloor(enum elevatorDirection_t direction, int floor) {
    return orders[direction][floor];
}

user_defined_types: enum elevatorDirection_t { DIR_DOWN=0, DIR_UP=1 }


decompiled_code:
void oq_deleteAllOrders()
{
orders[0] = 0;
dword_184 = 0;
dword_188 = 0;
dword_18C = 0;
dword_190[0] = 0;
dword_194 = 0;
dword_198 = 0;
dword_19C = 0;
}

original_code:
void oq_deleteAllOrders(void) {
    int dir, floor;
    for (dir=DIR_DOWN; dir<=DIR_UP; dir++) {
        for (floor=0; floor<4; floor++)
            orders[dir][floor] = 0;
    }
}

canonical_original_code:
void oq_deleteAllOrders() {
    int dir; int floor;
    for (dir=DIR_DOWN; dir<=DIR_UP; dir++) {
        for (floor=0; floor<4; floor++)
            orders[dir][floor] = 0;
    }
}


decompiled_code:
__int64 __fastcall elev_findDirection(int a1, int a2)
{
__int64 result; // rax
unsigned int v3; // ebx
unsigned int v4; // ebx

if ( a2 == 1 )
{
v4 = a1 + 1;
if ( a1 + 1 > 3 )
{
result = 0LL;
}
else
{
while ( 1 )
{
if ( (unsigned int)oq_hasOrderInFloor(1LL, v4) )
return 1LL;
result = oq_hasOrderInFloor(0LL, v4);
if ( (_DWORD)result )
break;
if ( ++v4 == 4 )
return result;
}
result = 1LL;
}
}
else
{
result = 1LL;
if ( !a2 )
{
v3 = a1 - 1;
if ( a1 - 1 < 0 )
{
result = 1LL;
}
else
{
while ( 1 )
{
if ( (unsigned int)oq_hasOrderInFloor(1LL, v3) )
return 0LL;
if ( (unsigned int)oq_hasOrderInFloor(0LL, v3) )
break;
if ( --v3 == -1 )
return 1LL;
}
result = 0LL;
}
}
}
return result;
}

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

if ( a2 == 1 )
{
v4 = a1 + 1;
if ( a1 + 1 > 3 )
{
result = 0LL;
}
else
{
while ( 1 )
{
if ( (unsigned int)oq_hasOrderInFloor(1LL, v4) )
return 1LL;
result = oq_hasOrderInFloor(0LL, v4);
if ( (_DWORD)result )
break;
if ( ++v4 == 4 )
return result;
}
result = 1LL;
}
}
else
{
result = 1LL;
if ( !a2 )
{
v3 = a1 - 1;
if ( a1 - 1 < 0 )
{
result = 1LL;
}
else
{
while ( 1 )
{
if ( (unsigned int)oq_hasOrderInFloor(1LL, v3) )
return 0LL;
if ( (unsigned int)oq_hasOrderInFloor(0LL, v3) )
break;
if ( --v3 == -1 )
return 1LL;
}
result = 0LL;
}
}
}
return result;
}

canonical_original_code:
enum elevatorDirection_t elev_findDirection(int currentFloor, int direction) {
    int floor = currentFloor;
    if (direction == DIR_UP) {
        for (floor = floor+1; floor<4; floor++) {
            if (oq_hasOrderInFloor(DIR_UP, floor) || oq_hasOrderInFloor(DIR_DOWN, floor))
                return DIR_UP;
        }
        return DIR_DOWN;
    }
    else if (direction == DIR_DOWN) {
        for (floor = floor-1; floor>=0; floor--) {
            if (oq_hasOrderInFloor(DIR_UP, floor) || oq_hasOrderInFloor(DIR_DOWN, floor))
                return DIR_DOWN;
        }
        return DIR_UP;
    }
    return DIR_UP;
}

return_type: enum elevatorDirection_t { DIR_DOWN=0, DIR_UP=1 }


decompiled_code:
__int64 __fastcall elev_updateSignals(_DWORD *a1)
{
int v1; // edx
_BOOL4 v2; // eax
__int64 result; // rax
unsigned int v4; // eax
unsigned int v5; // eax

switch ( *a1 )
{
case 0:
a1[4] = oq_hasOrders();
v1 = oq_hasOrderInFloor(1LL, (unsigned int)a1[3]);
v2 = 1;
if ( !v1 )
v2 = oq_hasOrderInFloor(0LL, (unsigned int)a1[3]) != 0;
a1[5] = v2;
break;
case 1:
v4 = panel_getFloorSensorSignal();
if ( v4 == -1 )
{
a1[5] = 0;
}
else
{
a1[3] = v4;
panel_setFloorIndicator(v4);
a1[5] = (unsigned int)oq_hasOrderInFloor((unsigned int)a1[2], (unsigned int)a1[3])
|| (unsigned int)elev_findDirection(a1[3], a1[2]) == (a1[2] == 0);
}
break;
case 2:
a1[7] = timer_timerIsFinished(3.0);
break;
case 3:
a1[4] = oq_hasOrders();
a1[8] = panel_getObstructionSignal();
break;
case 4:
v5 = panel_getFloorSensorSignal();
if ( v5 != -1 )
{
a1[3] = v5;
panel_setFloorIndicator(v5);
}
a1[4] = oq_hasOrders();
break;
default:
break;
}
result = panel_getStopSignal();
a1[6] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1)
{
int v1; // edx
_BOOL4 v2; // eax
__int64 result; // rax
unsigned int v4; // eax
unsigned int v5; // eax

switch ( *a1 )
{
case 0:
a1[4] = oq_hasOrders();
v1 = oq_hasOrderInFloor(1LL, (unsigned int)a1[3]);
v2 = 1;
if ( !v1 )
v2 = oq_hasOrderInFloor(0LL, (unsigned int)a1[3]) != 0;
a1[5] = v2;
break;
case 1:
v4 = panel_getFloorSensorSignal();
if ( v4 == -1 )
{
a1[5] = 0;
}
else
{
a1[3] = v4;
panel_setFloorIndicator(v4);
a1[5] = (unsigned int)oq_hasOrderInFloor((unsigned int)a1[2], (unsigned int)a1[3])
|| (unsigned int)func0(a1[3], a1[2]) == (a1[2] == 0);
}
break;
case 2:
a1[7] = timer_timerIsFinished(3.0);
break;
case 3:
a1[4] = oq_hasOrders();
a1[8] = panel_getObstructionSignal();
break;
case 4:
v5 = panel_getFloorSensorSignal();
if ( v5 != -1 )
{
a1[3] = v5;
panel_setFloorIndicator(v5);
}
a1[4] = oq_hasOrders();
break;
default:
break;
}
result = panel_getStopSignal();
a1[6] = result;
return result;
}

original_code:
void elev_updateSignals(elevatorParameters_t *param) {
    switch(param->currentState) {
        case STATE_IDLE:
            param->signals[SIG_HAS_ORDERS] = oq_hasOrders();
            param->signals[SIG_SHOULD_STOP] = (oq_hasOrderInFloor(DIR_UP, param->currentFloor) || oq_hasOrderInFloor(DIR_DOWN, param->currentFloor));
            break;
        case STATE_DRIVE:;
            int tempFloor = panel_getFloorSensorSignal();
            if (tempFloor != -1) {
                param->currentFloor = tempFloor;
                panel_setFloorIndicator(param->currentFloor);
                if (oq_hasOrderInFloor(param->directionUp, param->currentFloor) || (elev_findDirection(param->currentFloor, param->directionUp) == !param->directionUp))
                    param->signals[SIG_SHOULD_STOP] = 1;
                else param->signals[SIG_SHOULD_STOP] = 0;
            }
            else param->signals[SIG_SHOULD_STOP] = 0;
            break;
        case STATE_OPENDOOR:
            param->signals[SIG_TIMER_FINISHED] = timer_timerIsFinished(3);
            break;
        case STATE_CLOSEDOOR:
            param->signals[SIG_HAS_ORDERS] = oq_hasOrders();
            param->signals[SIG_OBSTRUCTION] = panel_getObstructionSignal();
            break;
        case STATE_EMERGENCYSTOP:;
            tempFloor = panel_getFloorSensorSignal();
            if (tempFloor != -1) {
                param->currentFloor = tempFloor;
                panel_setFloorIndicator(param->currentFloor);
            }
            param->signals[SIG_HAS_ORDERS] = oq_hasOrders();
            break;
    }
    param->signals[SIG_EMERGENCY_STOP] = panel_getStopSignal();
}

canonical_original_code:
void elev_updateSignals(struct tag_elevatorParameters_t *param) {
    switch(param->currentState) {
        case STATE_IDLE:
            param->signals[SIG_HAS_ORDERS] = oq_hasOrders();
            param->signals[SIG_SHOULD_STOP] = (oq_hasOrderInFloor(DIR_UP, param->currentFloor) || oq_hasOrderInFloor(DIR_DOWN, param->currentFloor));
            break;
        case STATE_DRIVE:;
            int tempFloor = panel_getFloorSensorSignal();
            if (tempFloor != -1) {
                param->currentFloor = tempFloor;
                panel_setFloorIndicator(param->currentFloor);
                if (oq_hasOrderInFloor(param->directionUp, param->currentFloor) || (elev_findDirection(param->currentFloor, param->directionUp) == !param->directionUp))
                    param->signals[SIG_SHOULD_STOP] = 1;
                else param->signals[SIG_SHOULD_STOP] = 0;
            }
            else param->signals[SIG_SHOULD_STOP] = 0;
            break;
        case STATE_OPENDOOR:
            param->signals[SIG_TIMER_FINISHED] = timer_timerIsFinished(3);
            break;
        case STATE_CLOSEDOOR:
            param->signals[SIG_HAS_ORDERS] = oq_hasOrders();
            param->signals[SIG_OBSTRUCTION] = panel_getObstructionSignal();
            break;
        case STATE_EMERGENCYSTOP:;
            tempFloor = panel_getFloorSensorSignal();
            if (tempFloor != -1) {
                param->currentFloor = tempFloor;
                panel_setFloorIndicator(param->currentFloor);
            }
            param->signals[SIG_HAS_ORDERS] = oq_hasOrders();
            break;
    }
    param->signals[SIG_EMERGENCY_STOP] = panel_getStopSignal();
}

variable_types: tempFloor int

user_defined_types: enum elevatorState_t { STATE_IDLE=0, STATE_DRIVE=1, STATE_OPENDOOR=2, STATE_CLOSEDOOR=3, STATE_EMERGENCYSTOP=4 }


printStatus

decompiled_code:
int __fastcall printStatus(unsigned int *a1)
{
unsigned int v1; // er13
unsigned int v2; // er12
unsigned int v3; // ebp
unsigned int v4; // eax

v1 = a1[1];
v2 = *a1;
v3 = a1[2];
v4 = oq_hasOrders();
return printf(
"Current Floor: %i, HasOrders: %i, directionUP: %i, currentState = %i, elevParam->nextState = %i\n",
a1[3],
v4,
v3,
v2,
v1);
}

canonical_decompiled_code:
int __fastcall func2(unsigned int *a1)
{
unsigned int v1; // er13
unsigned int v2; // er12
unsigned int v3; // ebp
unsigned int v4; // eax

v1 = a1[1];
v2 = *a1;
v3 = a1[2];
v4 = oq_hasOrders();
return printf(
"Current Floor: %i, HasOrders: %i, directionUP: %i, currentState = %i, elevParam->nextState = %i\n",
a1[3],
v4,
v3,
v2,
v1);
}

original_code:
void printStatus (const elevatorParameters_t *param) {
    printf("Current Floor: %i, HasOrders: %i, directionUP: %i, currentState = %i, elevParam->nextState = %i\n", param->currentFloor, oq_hasOrders(), param->directionUp, param->currentState, param->nextState);
}

canonical_original_code:
void printStatus(struct tag_elevatorParameters_t *param) {
    printf("Current Floor: %i, HasOrders: %i, directionUP: %i, currentState = %i, elevParam->nextState = %i\n", param->currentFloor, oq_hasOrders(), param->directionUp, param->currentState, param->nextState);
}


decompiled_code:
__int64 __fastcall elev_setSpeed(int a1)
{
if ( a1 > 0 )
goto LABEL_6;
if ( a1 < 0 )
goto LABEL_5;
if ( last_speed_0 < 0 )
{
LABEL_6:
io_clear_bit(783LL);
goto LABEL_7;
}
if ( last_speed_0 > 0 )
LABEL_5:
io_set_bit(783LL);
LABEL_7:
last_speed_0 = a1;
return io_write_analog(256LL, 4 * abs32(a1) + 2048);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
if ( a1 > 0 )
goto LABEL_6;
if ( a1 < 0 )
goto LABEL_5;
if ( last_speed_0 < 0 )
{
LABEL_6:
io_clear_bit(783LL);
goto LABEL_7;
}
if ( last_speed_0 > 0 )
LABEL_5:
io_set_bit(783LL);
LABEL_7:
last_speed_0 = a1;
return io_write_analog(256LL, 4 * abs32(a1) + 2048);
}

original_code:
void elev_setSpeed(int speed)
{
    static int last_speed = 0;
    if (speed > 0)
        io_clear_bit((0x300+15));
    else if (speed < 0)
        io_set_bit((0x300+15));
    else if (last_speed < 0)
        io_clear_bit((0x300+15));
    else if (last_speed > 0)
        io_set_bit((0x300+15));
    last_speed = speed ;
    io_write_analog((0x100+0), 2048 + 4*abs(speed));
}

variable_types: speed int


decompiled_code:
__int64 __fastcall elev_stop(int a1)
{
if ( a1 == 1 )
elev_setSpeed(-100);
else
elev_setSpeed(100);
timer_start();
while ( !(unsigned int)timer_timerIsFinished(0.02) )
;
return elev_setSpeed(0);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
if ( a1 == 1 )
func3(-100);
else
func3(100);
timer_start();
while ( !(unsigned int)timer_timerIsFinished(0.02) )
;
return func3(0);
}

original_code:
void elev_stop(elevatorDirection_t direction){
    if (direction == DIR_UP) elev_setSpeed(-100);
    else elev_setSpeed(100);
    timer_start();
    while (!timer_timerIsFinished(0.02)) {;}
    elev_setSpeed(0);
}

canonical_original_code:
void elev_stop(enum elevatorDirection_t direction){
    if (direction == DIR_UP) elev_setSpeed(-100);
    else elev_setSpeed(100);
    timer_start();
    while (!timer_timerIsFinished(0.02)) {;}
    elev_setSpeed(0);
}


decompiled_code:
__int64 __fastcall elev_init(_DWORD *a1)
{
__int64 result; // rax
unsigned int v2; // eax

result = io_init();
if ( (_DWORD)result )
{
result = oq_init();
if ( (_DWORD)result )
{
result = panel_init();
if ( (_DWORD)result )
{
elev_setSpeed(100);
while ( (unsigned int)panel_getFloorSensorSignal() == -1 )
;
elev_stop(1);
*a1 = 0;
a1[1] = 0;
a1[4] = 0;
a1[5] = 0;
a1[6] = 0;
a1[7] = 0;
a1[8] = 0;
a1[2] = 1;
v2 = panel_getFloorSensorSignal();
a1[3] = v2;
panel_setFloorIndicator(v2);
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1)
{
__int64 result; // rax
unsigned int v2; // eax

result = io_init();
if ( (_DWORD)result )
{
result = oq_init();
if ( (_DWORD)result )
{
result = panel_init();
if ( (_DWORD)result )
{
func3(100);
while ( (unsigned int)panel_getFloorSensorSignal() == -1 )
;
func4(1);
*a1 = 0;
a1[1] = 0;
a1[4] = 0;
a1[5] = 0;
a1[6] = 0;
a1[7] = 0;
a1[8] = 0;
a1[2] = 1;
v2 = panel_getFloorSensorSignal();
a1[3] = v2;
panel_setFloorIndicator(v2);
result = 1LL;
}
}
}
return result;
}

original_code:
int elev_init(elevatorParameters_t *param) {
    if (!io_init())
        return 0;
    if (!oq_init())
        return 0;
    if (!panel_init())
        return 0;
    elev_setSpeed(100);
    while (panel_getFloorSensorSignal()== -1) {
        ;
    }
    elev_stop(DIR_UP);
    param->currentState = STATE_IDLE;
    param->nextState = STATE_IDLE;
    int i;
    for (i=0; i<SIG_NUMBER_OF_SIGNALS; i++)
        param->signals[i] = 0;
    param->directionUp = DIR_UP;
    param->currentFloor = panel_getFloorSensorSignal();
    panel_setFloorIndicator(param->currentFloor);
    return 1;
}

canonical_original_code:
int elev_init(struct tag_elevatorParameters_t *param) {
    if (!io_init())
        return 0;
    if (!oq_init())
        return 0;
    if (!panel_init())
        return 0;
    elev_setSpeed(100);
    while (panel_getFloorSensorSignal()== -1) {
        ;
    }
    elev_stop(DIR_UP);
    param->currentState = STATE_IDLE;
    param->nextState = STATE_IDLE;
    int i;
    for (i=0; i<SIG_NUMBER_OF_SIGNALS; i++)
        param->signals[i] = 0;
    param->directionUp = DIR_UP;
    param->currentFloor = panel_getFloorSensorSignal();
    panel_setFloorIndicator(param->currentFloor);
    return 1;
}

variable_types: i int


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

v1 = elev_findDirection(*(_DWORD *)(a1 + 12), *(_DWORD *)(a1 + 8));
*(_DWORD *)(a1 + 8) = v1;
if ( v1 == 1 )
result = elev_setSpeed(300);
else
result = elev_setSpeed(-300);
return result;
}

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

v1 = func0(*(_DWORD *)(a1 + 12), *(_DWORD *)(a1 + 8));
*(_DWORD *)(a1 + 8) = v1;
if ( v1 == 1 )
result = func3(300);
else
result = func3(-300);
return result;
}

original_code:
void elev_setDirectionAndSpeed(elevatorParameters_t *param) {
    param->directionUp = elev_findDirection(param->currentFloor, param->directionUp);
    if (param->directionUp == DIR_UP)
        elev_setSpeed(300);
    else elev_setSpeed(-300);
}

canonical_original_code:
void elev_setDirectionAndSpeed(struct tag_elevatorParameters_t *param) {
    param->directionUp = elev_findDirection(param->currentFloor, param->directionUp);
    if (param->directionUp == DIR_UP)
        elev_setSpeed(300);
    else elev_setSpeed(-300);
}


decompiled_code:
void elev_run()
{
int v0; // [rsp+0h] [rbp-38h] BYREF
int v1; // [rsp+4h] [rbp-34h]
int v2; // [rsp+8h] [rbp-30h]
unsigned int v3; // [rsp+Ch] [rbp-2Ch]
int v4; // [rsp+10h] [rbp-28h]
int v5; // [rsp+14h] [rbp-24h]
int v6; // [rsp+18h] [rbp-20h]
int v7; // [rsp+1Ch] [rbp-1Ch]
int v8; // [rsp+20h] [rbp-18h]

elev_init(&v0);
while ( 2 )
{
switch ( v0 )
{
case 0:
if ( v4 )
{
if ( v5 )
{
v1 = 2;
LABEL_23:
if ( !v6 )
goto LABEL_24;
}
else
{
v1 = 1;
LABEL_6:
if ( !v6 )
{
LABEL_7:
elev_setDirectionAndSpeed((__int64)&v0);
goto LABEL_11;
}
}
LABEL_10:
v1 = 4;
if ( v0 == 4 )
goto LABEL_11;
LABEL_45:
if ( v0 == 1 )
elev_stop(v2);
LABEL_47:
oq_deleteAllOrders();
panel_turnOffAllLights();
panel_setStopLamp(1LL);
goto LABEL_11;
}
v1 = 0;
break;
case 1:
if ( v5 )
{
v1 = 2;
if ( !v6 )
goto LABEL_15;
goto LABEL_10;
}
v1 = 1;
break;
case 2:
if ( v7 )
{
v1 = 3;
if ( !v6 )
goto LABEL_44;
goto LABEL_10;
}
v1 = 2;
break;
case 3:
if ( v8 )
{
v1 = 2;
goto LABEL_23;
}
if ( v4 )
{
v1 = 1;
goto LABEL_6;
}
v1 = 0;
if ( v6 )
{
v1 = 4;
if ( v0 != 4 )
goto LABEL_47;
}
LABEL_11:
v0 = v1;
elev_updateSignals(&v0);
panel_checkForOrders(&v0);
continue;
case 4:
if ( v4 )
{
v1 = 3;
if ( !v6 )
goto LABEL_32;
goto LABEL_10;
}
v1 = 4;
break;
default:
if ( v6 )
goto LABEL_10;
if ( v0 == v1 )
goto LABEL_11;
switch ( v1 )
{
case 1:
goto LABEL_7;
case 0:
goto LABEL_11;
case 3:
if ( v0 == 4 )
LABEL_32:
panel_setStopLamp(0LL);
LABEL_44:
panel_setDoorOpenLamp(0LL);
goto LABEL_11;
case 4:
goto LABEL_45;
case 2:
if ( v0 == 1 )
LABEL_15:
elev_stop(v2);
LABEL_24:
oq_deleteOrderInFloor(v3);
panel_turnOffLightsInFloor(v3);
panel_setDoorOpenLamp(1LL);
timer_start();
goto LABEL_11;
}
goto LABEL_11;
}
break;
}
if ( !v6 )
goto LABEL_11;
goto LABEL_10;
}

canonical_decompiled_code:
void func7()
{
int v0; // [rsp+0h] [rbp-38h] BYREF
int v1; // [rsp+4h] [rbp-34h]
int v2; // [rsp+8h] [rbp-30h]
unsigned int v3; // [rsp+Ch] [rbp-2Ch]
int v4; // [rsp+10h] [rbp-28h]
int v5; // [rsp+14h] [rbp-24h]
int v6; // [rsp+18h] [rbp-20h]
int v7; // [rsp+1Ch] [rbp-1Ch]
int v8; // [rsp+20h] [rbp-18h]

func5(&v0);
while ( 2 )
{
switch ( v0 )
{
case 0:
if ( v4 )
{
if ( v5 )
{
v1 = 2;
LABEL_23:
if ( !v6 )
goto LABEL_24;
}
else
{
v1 = 1;
LABEL_6:
if ( !v6 )
{
LABEL_7:
func6((__int64)&v0);
goto LABEL_11;
}
}
LABEL_10:
v1 = 4;
if ( v0 == 4 )
goto LABEL_11;
LABEL_45:
if ( v0 == 1 )
func4(v2);
LABEL_47:
oq_deleteAllOrders();
panel_turnOffAllLights();
panel_setStopLamp(1LL);
goto LABEL_11;
}
v1 = 0;
break;
case 1:
if ( v5 )
{
v1 = 2;
if ( !v6 )
goto LABEL_15;
goto LABEL_10;
}
v1 = 1;
break;
case 2:
if ( v7 )
{
v1 = 3;
if ( !v6 )
goto LABEL_44;
goto LABEL_10;
}
v1 = 2;
break;
case 3:
if ( v8 )
{
v1 = 2;
goto LABEL_23;
}
if ( v4 )
{
v1 = 1;
goto LABEL_6;
}
v1 = 0;
if ( v6 )
{
v1 = 4;
if ( v0 != 4 )
goto LABEL_47;
}
LABEL_11:
v0 = v1;
func1(&v0);
panel_checkForOrders(&v0);
continue;
case 4:
if ( v4 )
{
v1 = 3;
if ( !v6 )
goto LABEL_32;
goto LABEL_10;
}
v1 = 4;
break;
default:
if ( v6 )
goto LABEL_10;
if ( v0 == v1 )
goto LABEL_11;
switch ( v1 )
{
case 1:
goto LABEL_7;
case 0:
goto LABEL_11;
case 3:
if ( v0 == 4 )
LABEL_32:
panel_setStopLamp(0LL);
LABEL_44:
panel_setDoorOpenLamp(0LL);
goto LABEL_11;
case 4:
goto LABEL_45;
case 2:
if ( v0 == 1 )
LABEL_15:
func4(v2);
LABEL_24:
oq_deleteOrderInFloor(v3);
panel_turnOffLightsInFloor(v3);
panel_setDoorOpenLamp(1LL);
timer_start();
goto LABEL_11;
}
goto LABEL_11;
}
break;
}
if ( !v6 )
goto LABEL_11;
goto LABEL_10;
}

original_code:
void elev_run(void) {
    elevatorParameters_t l_elevParam;
    elevatorParameters_t *elevParam = &l_elevParam;
    elev_init(elevParam);
    while (1) {
        switch (elevParam->currentState) {
            case STATE_IDLE:
                if (elevParam->signals[SIG_HAS_ORDERS]) {
                    if (elevParam->signals[SIG_SHOULD_STOP])
                        elevParam->nextState = STATE_OPENDOOR;
                    else elevParam->nextState = STATE_DRIVE;
                }
                else elevParam->nextState = STATE_IDLE;
                break;
            case STATE_DRIVE:
                if (elevParam->signals[SIG_SHOULD_STOP]) elevParam->nextState = STATE_OPENDOOR;
                else elevParam->nextState = STATE_DRIVE;
                break;
            case STATE_OPENDOOR:
                if (elevParam->signals[SIG_TIMER_FINISHED]) elevParam->nextState = STATE_CLOSEDOOR;
                else elevParam->nextState = STATE_OPENDOOR;
                break;
            case STATE_CLOSEDOOR:
                if (elevParam->signals[SIG_OBSTRUCTION]) elevParam->nextState = STATE_OPENDOOR;
                else if (elevParam->signals[SIG_HAS_ORDERS]) elevParam->nextState = STATE_DRIVE;
                else elevParam->nextState = STATE_IDLE;
                break;
            case STATE_EMERGENCYSTOP:
                if (elevParam->signals[SIG_HAS_ORDERS]) elevParam->nextState = STATE_CLOSEDOOR;
                else elevParam->nextState = STATE_EMERGENCYSTOP;
                break;
        }
        if (elevParam->signals[SIG_EMERGENCY_STOP]) elevParam->nextState = STATE_EMERGENCYSTOP;
        if (elevParam->nextState != elevParam->currentState) {
            switch (elevParam->nextState) {
                case STATE_IDLE:
                    break;
                case STATE_DRIVE:
                    elev_setDirectionAndSpeed(elevParam);
                    break;
                case STATE_OPENDOOR:
                    if (elevParam->currentState == STATE_DRIVE) elev_stop(elevParam->directionUp);
                    oq_deleteOrderInFloor(elevParam->currentFloor);
                    panel_turnOffLightsInFloor(elevParam->currentFloor);
                    panel_setDoorOpenLamp(LAMP_ON);
                    timer_start();
                    break;
                case STATE_CLOSEDOOR:
                    if (elevParam->currentState == STATE_EMERGENCYSTOP) panel_setStopLamp(LAMP_OFF);
                    panel_setDoorOpenLamp(LAMP_OFF);
                    break;
                case STATE_EMERGENCYSTOP:
                    if (elevParam->currentState == STATE_DRIVE)
                        elev_stop(elevParam->directionUp);
                    oq_deleteAllOrders();
                    panel_turnOffAllLights();
                    panel_setStopLamp(LAMP_ON);
                    break;
            }
        }
        elevParam->currentState = elevParam->nextState;
        elev_updateSignals(elevParam);
        panel_checkForOrders(elevParam);
    }
}

canonical_original_code:
void elev_run() {
    struct tag_elevatorParameters_t l_elevParam;
    struct tag_elevatorParameters_t *elevParam = &l_elevParam;
    elev_init(elevParam);
    while (1) {
        switch (elevParam->currentState) {
            case STATE_IDLE:
                if (elevParam->signals[SIG_HAS_ORDERS]) {
                    if (elevParam->signals[SIG_SHOULD_STOP])
                        elevParam->nextState = STATE_OPENDOOR;
                    else elevParam->nextState = STATE_DRIVE;
                }
                else elevParam->nextState = STATE_IDLE;
                break;
            case STATE_DRIVE:
                if (elevParam->signals[SIG_SHOULD_STOP]) elevParam->nextState = STATE_OPENDOOR;
                else elevParam->nextState = STATE_DRIVE;
                break;
            case STATE_OPENDOOR:
                if (elevParam->signals[SIG_TIMER_FINISHED]) elevParam->nextState = STATE_CLOSEDOOR;
                else elevParam->nextState = STATE_OPENDOOR;
                break;
            case STATE_CLOSEDOOR:
                if (elevParam->signals[SIG_OBSTRUCTION]) elevParam->nextState = STATE_OPENDOOR;
                else if (elevParam->signals[SIG_HAS_ORDERS]) elevParam->nextState = STATE_DRIVE;
                else elevParam->nextState = STATE_IDLE;
                break;
            case STATE_EMERGENCYSTOP:
                if (elevParam->signals[SIG_HAS_ORDERS]) elevParam->nextState = STATE_CLOSEDOOR;
                else elevParam->nextState = STATE_EMERGENCYSTOP;
                break;
        }
        if (elevParam->signals[SIG_EMERGENCY_STOP]) elevParam->nextState = STATE_EMERGENCYSTOP;
        if (elevParam->nextState != elevParam->currentState) {
            switch (elevParam->nextState) {
                case STATE_IDLE:
                    break;
                case STATE_DRIVE:
                    elev_setDirectionAndSpeed(elevParam);
                    break;
                case STATE_OPENDOOR:
                    if (elevParam->currentState == STATE_DRIVE) elev_stop(elevParam->directionUp);
                    oq_deleteOrderInFloor(elevParam->currentFloor);
                    panel_turnOffLightsInFloor(elevParam->currentFloor);
                    panel_setDoorOpenLamp(LAMP_ON);
                    timer_start();
                    break;
                case STATE_CLOSEDOOR:
                    if (elevParam->currentState == STATE_EMERGENCYSTOP) panel_setStopLamp(LAMP_OFF);
                    panel_setDoorOpenLamp(LAMP_OFF);
                    break;
                case STATE_EMERGENCYSTOP:
                    if (elevParam->currentState == STATE_DRIVE)
                        elev_stop(elevParam->directionUp);
                    oq_deleteAllOrders();
                    panel_turnOffAllLights();
                    panel_setStopLamp(LAMP_ON);
                    break;
            }
        }
        elevParam->currentState = elevParam->nextState;
        elev_updateSignals(elevParam);
        panel_checkForOrders(elevParam);
    }
}

variable_types: struct tag_elevatorParameters_t { enum elevatorState_t { STATE_IDLE=0, STATE_DRIVE=1, STATE_OPENDOOR=2, STATE_CLOSEDOOR=3, STATE_EMERGENCYSTOP=4 } currentState; enum elevatorState_t { STATE_IDLE=0, STATE_DRIVE=1, STATE_OPENDOOR=2, STATE_CLOSEDOOR=3, STATE_EMERGENCYSTOP=4 } nextState; enum elevatorDirection_t { DIR_DOWN=0, DIR_UP=1 } directionUp; int currentFloor; int signals[-1]; }


repo: maryheintz/vme

decompiled_code:
__int64 __fastcall test_data_bus(int fd, void *buf)
{
char v2; // al
char bufa[25]; // [rsp+Fh] [rbp-19h] BYREF

*(_BYTE *)buf = 1;
while ( 1 )
{
lseek(fd, 0LL, 0);
write(fd, buf, 1uLL);
lseek(fd, -1LL, 1);
read(fd, bufa, 1uLL);
if ( *(_BYTE *)buf != bufa[0] )
break;
v2 = 2 * *(_BYTE *)buf;
*(_BYTE *)buf = v2;
if ( !v2 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, void *buf)
{
char v2; // al
char bufa[25]; // [rsp+Fh] [rbp-19h] BYREF

*(_BYTE *)buf = 1;
while ( 1 )
{
lseek(fd, 0LL, 0);
write(fd, buf, 1uLL);
lseek(fd, -1LL, 1);
read(fd, bufa, 1uLL);
if ( *(_BYTE *)buf != bufa[0] )
break;
v2 = 2 * *(_BYTE *)buf;
*(_BYTE *)buf = v2;
if ( !v2 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int test_data_bus(int fd, unsigned char *data)
{
 unsigned char rval;
 for (*data = 1; 0 != *data; *data <<= 1) {
  lseek(fd, 0, 0);
  write(fd, data, sizeof (*data));
  lseek(fd, -(sizeof (*data)), 1);
  read(fd, &rval, sizeof (rval));
  if (rval != *data)
   return -1;
 }
 return 0;
}

variable_types: fd int

variable_types:
data
unsigned char *

variable_types:
rval
unsigned char


decompiled_code:
__int64 __fastcall test_address_bus(int fd, __int64 a2, __off_t *a3)
{
__int64 v4; // r12
__off_t v5; // r13
__off_t v6; // rsi
__off_t v7; // rsi
__off_t v8; // r14
__off_t v9; // rsi
__int64 result; // rax
char v11; // [rsp+Dh] [rbp-2Bh] BYREF
char v12; // [rsp+Eh] [rbp-2Ah] BYREF
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

buf[0] = -86;
v12 = 85;
*a3 = 1LL;
v4 = a2 - 1;
v5 = ((_BYTE)a2 - 1) & 1;
if ( (((_BYTE)a2 - 1) & 1) != 0 )
{
v6 = ((_BYTE)a2 - 1) & 1;
do
{
lseek(fd, v6, 0);
write(fd, buf, 1uLL);
v6 = 2 * *a3;
*a3 = v6;
}
while ( (v4 & v6) != 0 );
lseek(fd, 0LL, 0);
write(fd, &v12, 1uLL);
*a3 = 1LL;
v7 = v5;
do
{
lseek(fd, v7, 0);
read(fd, &v11, 1uLL);
if ( v11 != buf[0] )
return 0xFFFFFFFFLL;
v7 = 2 * *a3;
*a3 = v7;
}
while ( (v4 & v7) != 0 );
v8 = v5;
do
{
lseek(fd, v8, 0);
write(fd, &v12, 1uLL);
*a3 = 1LL;
v9 = v5;
do
{
lseek(fd, v9, 0);
read(fd, &v11, 1uLL);
if ( v11 != buf[0] && *a3 != v8 )
return 0xFFFFFFFFLL;
lseek(fd, -1LL, 1);
write(fd, buf, 1uLL);
v9 = 2 * *a3;
*a3 = v9;
}
while ( (v4 & v9) != 0 );
v8 *= 2LL;
}
while ( (v4 & v8) != 0 );
result = 0LL;
}
else
{
lseek(fd, 0LL, 0);
write(fd, &v12, 1uLL);
*a3 = 1LL;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, __int64 a2, __off_t *a3)
{
__int64 v4; // r12
__off_t v5; // r13
__off_t v6; // rsi
__off_t v7; // rsi
__off_t v8; // r14
__off_t v9; // rsi
__int64 result; // rax
char v11; // [rsp+Dh] [rbp-2Bh] BYREF
char v12; // [rsp+Eh] [rbp-2Ah] BYREF
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

buf[0] = -86;
v12 = 85;
*a3 = 1LL;
v4 = a2 - 1;
v5 = ((_BYTE)a2 - 1) & 1;
if ( (((_BYTE)a2 - 1) & 1) != 0 )
{
v6 = ((_BYTE)a2 - 1) & 1;
do
{
lseek(fd, v6, 0);
write(fd, buf, 1uLL);
v6 = 2 * *a3;
*a3 = v6;
}
while ( (v4 & v6) != 0 );
lseek(fd, 0LL, 0);
write(fd, &v12, 1uLL);
*a3 = 1LL;
v7 = v5;
do
{
lseek(fd, v7, 0);
read(fd, &v11, 1uLL);
if ( v11 != buf[0] )
return 0xFFFFFFFFLL;
v7 = 2 * *a3;
*a3 = v7;
}
while ( (v4 & v7) != 0 );
v8 = v5;
do
{
lseek(fd, v8, 0);
write(fd, &v12, 1uLL);
*a3 = 1LL;
v9 = v5;
do
{
lseek(fd, v9, 0);
read(fd, &v11, 1uLL);
if ( v11 != buf[0] && *a3 != v8 )
return 0xFFFFFFFFLL;
lseek(fd, -1LL, 1);
write(fd, buf, 1uLL);
v9 = 2 * *a3;
*a3 = v9;
}
while ( (v4 & v9) != 0 );
v8 *= 2LL;
}
while ( (v4 & v8) != 0 );
result = 0LL;
}
else
{
lseek(fd, 0LL, 0);
write(fd, &v12, 1uLL);
*a3 = 1LL;
result = 0LL;
}
return result;
}

original_code:
int test_address_bus(int fd, off_t size, off_t * offset)
{
 unsigned char pattern = 0xaa;
 unsigned char antipattern = 0x55;
 unsigned char data;
 off_t ii;
 for (*offset = 1; *offset & (size - 1); *offset <<= 1) {
  lseek(fd, *offset, 0);
  write(fd, &pattern, sizeof (pattern));
 }
 lseek(fd, 0, 0);
 write(fd, &antipattern, sizeof (antipattern));
 for (*offset = 1; *offset & (size - 1); *offset <<= 1) {
  lseek(fd, *offset, 0);
  read(fd, &data, sizeof (data));
  if (data != pattern)
   return -1;
 }
 for (ii = 1; ii & (size - 1); ii <<= 1) {
  lseek(fd, ii, 0);
  write(fd, &antipattern, sizeof (antipattern));
  for (*offset = 1; *offset & (size - 1); *offset <<= 1) {
   lseek(fd, *offset, 0);
   read(fd, &data, sizeof (data));
   if ((data != pattern) && (*offset != ii))
    return -1;
   lseek(fd, -(sizeof (data)), 1);
   write(fd, &pattern, sizeof (pattern));
  }
 }
 return 0;
}

canonical_original_code:
int test_address_bus(int fd, long size, long *offset)
{
 unsigned char pattern = 0xaa;
 unsigned char antipattern = 0x55;
 unsigned char data;
 long ii;
 for (*offset = 1; *offset & (size - 1); *offset <<= 1) {
  lseek(fd, *offset, 0);
  write(fd, &pattern, sizeof (pattern));
 }
 lseek(fd, 0, 0);
 write(fd, &antipattern, sizeof (antipattern));
 for (*offset = 1; *offset & (size - 1); *offset <<= 1) {
  lseek(fd, *offset, 0);
  read(fd, &data, sizeof (data));
  if (data != pattern)
   return -1;
 }
 for (ii = 1; ii & (size - 1); ii <<= 1) {
  lseek(fd, ii, 0);
  write(fd, &antipattern, sizeof (antipattern));
  for (*offset = 1; *offset & (size - 1); *offset <<= 1) {
   lseek(fd, *offset, 0);
   read(fd, &data, sizeof (data));
   if ((data != pattern) && (*offset != ii))
    return -1;
   lseek(fd, -(sizeof (data)), 1);
   write(fd, &pattern, sizeof (pattern));
  }
 }
 return 0;
}

variable_types: size long

variable_types:
offset
long *

variable_types:
pattern
unsigned char

variable_types:
antipattern
unsigned char

variable_types:
data
unsigned char

variable_types: ii long


decompiled_code:
__int64 __fastcall test_memory(int fd, __int64 a2, __off_t *a3)
{
__off_t v5; // rsi
__off_t v6; // rsi
__off_t v7; // rsi
char v9; // [rsp+Dh] [rbp-1Bh] BYREF
char v10; // [rsp+Eh] [rbp-1Ah] BYREF
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

buf[0] = 1;
*a3 = 0LL;
if ( a2 <= 0 )
return 0LL;
v5 = 0LL;
do
{
lseek(fd, v5, 0);
write(fd, buf, 1uLL);
++buf[0];
v5 = *a3 + 1;
*a3 = v5;
}
while ( v5 < a2 );
buf[0] = 1;
*a3 = 0LL;
v6 = 0LL;
do
{
lseek(fd, v6, 0);
read(fd, &v9, 1uLL);
if ( v9 != buf[0] )
return 0xFFFFFFFFLL;
v10 = ~buf[0];
lseek(fd, -1LL, 1);
write(fd, &v10, 1uLL);
++buf[0];
v6 = *a3 + 1;
*a3 = v6;
}
while ( v6 < a2 );
buf[0] = 1;
*a3 = 0LL;
v7 = 0LL;
while ( 1 )
{
lseek(fd, v7, 0);
read(fd, &v9, 1uLL);
if ( v9 != ~buf[0] )
break;
v9 = 0;
lseek(fd, -1LL, 1);
write(fd, &v9, 1uLL);
++buf[0];
v7 = *a3 + 1;
*a3 = v7;
if ( v7 >= a2 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, __int64 a2, __off_t *a3)
{
__off_t v5; // rsi
__off_t v6; // rsi
__off_t v7; // rsi
char v9; // [rsp+Dh] [rbp-1Bh] BYREF
char v10; // [rsp+Eh] [rbp-1Ah] BYREF
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

buf[0] = 1;
*a3 = 0LL;
if ( a2 <= 0 )
return 0LL;
v5 = 0LL;
do
{
lseek(fd, v5, 0);
write(fd, buf, 1uLL);
++buf[0];
v5 = *a3 + 1;
*a3 = v5;
}
while ( v5 < a2 );
buf[0] = 1;
*a3 = 0LL;
v6 = 0LL;
do
{
lseek(fd, v6, 0);
read(fd, &v9, 1uLL);
if ( v9 != buf[0] )
return 0xFFFFFFFFLL;
v10 = ~buf[0];
lseek(fd, -1LL, 1);
write(fd, &v10, 1uLL);
++buf[0];
v6 = *a3 + 1;
*a3 = v6;
}
while ( v6 < a2 );
buf[0] = 1;
*a3 = 0LL;
v7 = 0LL;
while ( 1 )
{
lseek(fd, v7, 0);
read(fd, &v9, 1uLL);
if ( v9 != ~buf[0] )
break;
v9 = 0;
lseek(fd, -1LL, 1);
write(fd, &v9, 1uLL);
++buf[0];
v7 = *a3 + 1;
*a3 = v7;
if ( v7 >= a2 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int test_memory(int fd, off_t size, off_t * offset)
{
 unsigned char pattern;
 unsigned char antipattern;
 unsigned char data;
 for (pattern = 1, *offset = 0; *offset < size; ++pattern, ++(*offset)) {
  lseek(fd, *offset, 0);
  write(fd, &pattern, sizeof (pattern));
 }
 for (pattern = 1, *offset = 0; *offset < size; ++pattern, ++(*offset)) {
  lseek(fd, *offset, 0);
  read(fd, &data, sizeof (data));
  if (data != pattern)
   return -1;
  antipattern = ~pattern;
  lseek(fd, -(sizeof (data)), 1);
  write(fd, &antipattern, sizeof (antipattern));
 }
 for (pattern = 1, *offset = 0; *offset < size; ++pattern, ++(*offset)) {
  lseek(fd, *offset, 0);
  read(fd, &data, sizeof (data));
  if ((data & 0xff) != (~pattern & 0xff))
   return -1;
  data = 0;
  lseek(fd, -(sizeof (data)), 1);
  write(fd, &data, sizeof (data));
 }
 return 0;
}

canonical_original_code:
int test_memory(int fd, long size, long *offset)
{
 unsigned char pattern;
 unsigned char antipattern;
 unsigned char data;
 for (pattern = 1, *offset = 0; *offset < size; ++pattern, ++(*offset)) {
  lseek(fd, *offset, 0);
  write(fd, &pattern, sizeof (pattern));
 }
 for (pattern = 1, *offset = 0; *offset < size; ++pattern, ++(*offset)) {
  lseek(fd, *offset, 0);
  read(fd, &data, sizeof (data));
  if (data != pattern)
   return -1;
  antipattern = ~pattern;
  lseek(fd, -(sizeof (data)), 1);
  write(fd, &antipattern, sizeof (antipattern));
 }
 for (pattern = 1, *offset = 0; *offset < size; ++pattern, ++(*offset)) {
  lseek(fd, *offset, 0);
  read(fd, &data, sizeof (data));
  if ((data & 0xff) != (~pattern & 0xff))
   return -1;
  data = 0;
  lseek(fd, -(sizeof (data)), 1);
  write(fd, &data, sizeof (data));
 }
 return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
__off_t v5; // rax
__int64 v6; // rbp
__off_t v8; // [rsp+0h] [rbp-28h] BYREF
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v3 = open("/dev/nvram", 2, envp);
v4 = v3;
if ( v3 == -1 )
{
perror("open");
return v4;
}
v5 = lseek(v3, 0LL, 2);
v6 = v5;
if ( v5 <= 0 )
{
perror("lseek");
LABEL_12:
close(v4);
return -1;
}
fprintf(stderr, "NVRAM size is 0x%x bytes\n", (unsigned int)v5);
fwrite("Testing data bus: ", 1uLL, 0x12uLL, stdout);
if ( (unsigned int)test_data_bus(v4, buf) )
{
fwrite("FAILED\n", 1uLL, 7uLL, stdout);
fprintf(stderr, "Data bus test failed with pattern 0x%x\n", (unsigned int)buf[0]);
goto LABEL_12;
}
fwrite("PASSED\n", 1uLL, 7uLL, stdout);
fwrite("Testing address bus: ", 1uLL, 0x15uLL, stdout);
if ( (unsigned int)test_address_bus(v4, v6, &v8) )
{
fwrite("FAILED\n", 1uLL, 7uLL, stdout);
fprintf(stderr, "Address bus test failed at offset 0x%x\n", (unsigned int)v8);
goto LABEL_12;
}
fwrite("PASSED\n", 1uLL, 7uLL, stdout);
fwrite("Testing memory: ", 1uLL, 0x10uLL, stdout);
if ( (unsigned int)test_memory(v4, v6, &v8) )
{
fwrite("FAILED\n", 1uLL, 7uLL, stdout);
fprintf(stderr, "Memory test failed at offset 0x%x\n", (unsigned int)v8);
goto LABEL_12;
}
fwrite("PASSED\n", 1uLL, 7uLL, stdout);
v4 = close(v4);
if ( v4 )
{
perror("close");
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
__off_t v5; // rax
__int64 v6; // rbp
__off_t v8; // [rsp+0h] [rbp-28h] BYREF
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v3 = open("/dev/nvram", 2, envp);
v4 = v3;
if ( v3 == -1 )
{
perror("open");
return v4;
}
v5 = lseek(v3, 0LL, 2);
v6 = v5;
if ( v5 <= 0 )
{
perror("lseek");
LABEL_12:
close(v4);
return -1;
}
fprintf(stderr, "NVRAM size is 0x%x bytes\n", (unsigned int)v5);
fwrite("Testing data bus: ", 1uLL, 0x12uLL, stdout);
if ( (unsigned int)func7(v4, buf) )
{
fwrite("FAILED\n", 1uLL, 7uLL, stdout);
fprintf(stderr, "Data bus test failed with pattern 0x%x\n", (unsigned int)buf[0]);
goto LABEL_12;
}
fwrite("PASSED\n", 1uLL, 7uLL, stdout);
fwrite("Testing address bus: ", 1uLL, 0x15uLL, stdout);
if ( (unsigned int)func8(v4, v6, &v8) )
{
fwrite("FAILED\n", 1uLL, 7uLL, stdout);
fprintf(stderr, "Address bus test failed at offset 0x%x\n", (unsigned int)v8);
goto LABEL_12;
}
fwrite("PASSED\n", 1uLL, 7uLL, stdout);
fwrite("Testing memory: ", 1uLL, 0x10uLL, stdout);
if ( (unsigned int)func9(v4, v6, &v8) )
{
fwrite("FAILED\n", 1uLL, 7uLL, stdout);
fprintf(stderr, "Memory test failed at offset 0x%x\n", (unsigned int)v8);
goto LABEL_12;
}
fwrite("PASSED\n", 1uLL, 7uLL, stdout);
v4 = close(v4);
if ( v4 )
{
perror("close");
v4 = -1;
}
return v4;
}

original_code:
int main()
{
 off_t size;
 int fd;
 char error_data;
 off_t error_offset;
 fd = open("/dev/nvram", 02);
 if (-1 == fd) {
  perror("open");
  return -1;
 }
 size = lseek(fd, 0, 2);
 if (0 >= size) {
  perror("lseek");
  goto err_out;
 }
 fprintf(stderr, "NVRAM size is 0x%x bytes\n", (int) size);
 fprintf(stdout, "Testing data bus: ");
 if (test_data_bus(fd, &error_data)) {
  fprintf(stdout, "FAILED\n");
  fprintf(stderr, "Data bus test failed with pattern 0x%x\n",
   error_data);
  goto err_out;
 }
 fprintf(stdout, "PASSED\n");
 fprintf(stdout, "Testing address bus: ");
 if (test_address_bus(fd, size, &error_offset)) {
  fprintf(stdout, "FAILED\n");
  fprintf(stderr, "Address bus test failed at offset 0x%x\n",
   (int) error_offset);
  goto err_out;
 }
 fprintf(stdout, "PASSED\n");
 fprintf(stdout, "Testing memory: ");
 if (test_memory(fd, size, &error_offset)) {
  fprintf(stdout, "FAILED\n");
  fprintf(stderr, "Memory test failed at offset 0x%x\n",
   (int) error_offset);
  goto err_out;
 }
 fprintf(stdout, "PASSED\n");
 if (close(fd)) {
  perror("close");
  return -1;
 }
 return 0;
      err_out:
 close(fd);
 return -1;
}

canonical_original_code:
int main()
{
 long size;
 int fd;
 char error_data;
 long error_offset;
 fd = open("/dev/nvram", 02);
 if (-1 == fd) {
  perror("open");
  return -1;
 }
 size = lseek(fd, 0, 2);
 if (0 >= size) {
  perror("lseek");
  goto err_out;
 }
 fprintf(stderr, "NVRAM size is 0x%x bytes\n", (int) size);
 fprintf(stdout, "Testing data bus: ");
 if (test_data_bus(fd, &error_data)) {
  fprintf(stdout, "FAILED\n");
  fprintf(stderr, "Data bus test failed with pattern 0x%x\n",
   error_data);
  goto err_out;
 }
 fprintf(stdout, "PASSED\n");
 fprintf(stdout, "Testing address bus: ");
 if (test_address_bus(fd, size, &error_offset)) {
  fprintf(stdout, "FAILED\n");
  fprintf(stderr, "Address bus test failed at offset 0x%x\n",
   (int) error_offset);
  goto err_out;
 }
 fprintf(stdout, "PASSED\n");
 fprintf(stdout, "Testing memory: ");
 if (test_memory(fd, size, &error_offset)) {
  fprintf(stdout, "FAILED\n");
  fprintf(stderr, "Memory test failed at offset 0x%x\n",
   (int) error_offset);
  goto err_out;
 }
 fprintf(stdout, "PASSED\n");
 if (close(fd)) {
  perror("close");
  return -1;
 }
 return 0;
      err_out:
 close(fd);
 return -1;
}


decompiled_code:
char *__fastcall vme_mmap_phys(int fd, unsigned __int64 a2, __int64 a3)
{
int v5; // eax
unsigned __int64 v6; // rbx
unsigned __int64 v7; // r13
unsigned __int64 v8; // rt2
unsigned __int64 v9; // rsi
char *result; // rax
char *v11; // rbx

v5 = getpagesize();
v6 = a2 % v5;
v7 = v6 + a3;
v8 = v7 % v5;
v9 = v5 - v8;
if ( !v8 )
v9 = 0LL;
result = (char *)mmap(0LL, v7 + v9, 3, 1, fd, a2 - v6);
v11 = &result[v6];
if ( result )
result = v11;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(int fd, unsigned __int64 a2, __int64 a3)
{
int v5; // eax
unsigned __int64 v6; // rbx
unsigned __int64 v7; // r13
unsigned __int64 v8; // rt2
unsigned __int64 v9; // rsi
char *result; // rax
char *v11; // rbx

v5 = getpagesize();
v6 = a2 % v5;
v7 = v6 + a3;
v8 = v7 % v5;
v9 = v5 - v8;
if ( !v8 )
v9 = 0LL;
result = (char *)mmap(0LL, v7 + v9, 3, 1, fd, a2 - v6);
v11 = &result[v6];
if ( result )
result = v11;
return result;
}

original_code:
void *vme_mmap_phys(int fd, unsigned long paddr, size_t size)
{
 unsigned long mapaddr, off, mapsize;
 size_t ps = getpagesize();
 char *ptr;
 off = paddr % ps;
 mapaddr = paddr - off;
 mapsize = size + off;
 mapsize += (mapsize % ps) ? ps - (mapsize % ps) : 0;
 ptr = mmap(0, mapsize, 0x1 | 0x2, 0x01, fd, mapaddr);
 if (!ptr)
  return ((void *)0);
 return ptr + off;
}

canonical_original_code:
void *vme_mmap_phys(int fd, unsigned long paddr, unsigned long size)
{
 unsigned long mapaddr; unsigned long off; unsigned long mapsize;
 unsigned long ps = getpagesize();
 char *ptr;
 off = paddr % ps;
 mapaddr = paddr - off;
 mapsize = size + off;
 mapsize += (mapsize % ps) ? ps - (mapsize % ps) : 0;
 ptr = mmap(0, mapsize, 0x1 | 0x2, 0x01, fd, mapaddr);
 if (!ptr)
  return ((void *)0);
 return ptr + off;
}

variable_types:
paddr
unsigned long

variable_types:
size
unsigned long

variable_types:
mapaddr
unsigned long

variable_types:
off
unsigned long

variable_types:
mapsize
unsigned long

variable_types:
ps
unsigned long

variable_types:
ptr
char *

return_type: void *


decompiled_code:
int __fastcall vme_unmap_phys(unsigned __int64 a1, __int64 a2)
{
int v2; // eax
unsigned __int64 v3; // rdx
void *v4; // rdi
__int64 v5; // rbp
unsigned __int64 v6; // rt2
unsigned __int64 v7; // rsi

v2 = getpagesize();
v3 = a1 % v2;
v4 = (void *)(a1 - v3);
v5 = v3 + a2;
v6 = (v3 + a2) % v2;
v7 = v2 - v6;
if ( !v6 )
v7 = 0LL;
return munmap(v4, v5 + v7);
}

canonical_decompiled_code:
int __fastcall func1(unsigned __int64 a1, __int64 a2)
{
int v2; // eax
unsigned __int64 v3; // rdx
void *v4; // rdi
__int64 v5; // rbp
unsigned __int64 v6; // rt2
unsigned __int64 v7; // rsi

v2 = getpagesize();
v3 = a1 % v2;
v4 = (void *)(a1 - v3);
v5 = v3 + a2;
v6 = (v3 + a2) % v2;
v7 = v2 - v6;
if ( !v6 )
v7 = 0LL;
return munmap(v4, v5 + v7);
}

original_code:
int vme_unmap_phys(unsigned long vaddr, size_t size)
{
 unsigned long mapaddr, off, mapsize;
 size_t ps = getpagesize();
 off = vaddr % ps;
 mapaddr = vaddr - off;
 mapsize = size + off;
 mapsize += (mapsize % ps) ? ps - (mapsize % ps) : 0;
 return munmap((void *) mapaddr, mapsize);
}

canonical_original_code:
int vme_unmap_phys(unsigned long vaddr, unsigned long size)
{
 unsigned long mapaddr; unsigned long off; unsigned long mapsize;
 unsigned long ps = getpagesize();
 off = vaddr % ps;
 mapaddr = vaddr - off;
 mapsize = size + off;
 mapsize += (mapsize % ps) ? ps - (mapsize % ps) : 0;
 return munmap((void *) mapaddr, mapsize);
}

variable_types:
vaddr
unsigned long


strtoam

decompiled_code:
int __fastcall strtoam(char *s1, _DWORD *a2)
{
__int64 i; // rbx
const char *v4; // rsi
int result; // eax
char *s2[69]; // [rsp+0h] [rbp-228h] BYREF

qmemcpy(s2, &unk_F20, 0x200uLL);
for ( i = 0LL; i != 64; ++i )
{
v4 = s2[i];
if ( v4 )
{
result = strcmp(s1, v4);
if ( !result )
{
*a2 = i;
return result;
}
}
}
return -1;
}

canonical_decompiled_code:
int __fastcall func0(char *s1, _DWORD *a2)
{
__int64 i; // rbx
const char *v4; // rsi
int result; // eax
char *s2[69]; // [rsp+0h] [rbp-228h] BYREF

qmemcpy(s2, &unk_F20, 0x200uLL);
for ( i = 0LL; i != 64; ++i )
{
v4 = s2[i];
if ( v4 )
{
result = strcmp(s1, v4);
if ( !result )
{
*a2 = i;
return result;
}
}
}
return -1;
}

variable_types:
str
char *

variable_types:
am
int *

variable_types:
table
char *[]

variable_types: ii int


strtoas

decompiled_code:
int __fastcall strtoas(char *s1, _DWORD *a2)
{
__int64 i; // rbx
const char *v4; // rsi
int result; // eax
char *s2[9]; // [rsp+0h] [rbp-48h]

s2[0] = "VME_A16";
s2[1] = "VME_A24";
s2[2] = "VME_A32";
for ( i = 0LL; i != 3; ++i )
{
v4 = s2[i];
if ( v4 )
{
result = strcmp(s1, v4);
if ( !result )
{
*a2 = i;
return result;
}
}
}
return -1;
}

canonical_decompiled_code:
int __fastcall func1(char *s1, _DWORD *a2)
{
__int64 i; // rbx
const char *v4; // rsi
int result; // eax
char *s2[9]; // [rsp+0h] [rbp-48h]

s2[0] = "VME_A16";
s2[1] = "VME_A24";
s2[2] = "VME_A32";
for ( i = 0LL; i != 3; ++i )
{
v4 = s2[i];
if ( v4 )
{
result = strcmp(s1, v4);
if ( !result )
{
*a2 = i;
return result;
}
}
}
return -1;
}

original_code:
int strtoas(const char *str, int *as)
{
 char *table[] = {
  "VME_A16", "VME_A24", "VME_A32"
 };
 int ii;
 for (ii = 0; ii <= VME_A32; ++ii)
  if (table[ii]) {
   if (0 == strcmp(str, table[ii])) {
    *as = ii;
    return 0;
   }
  }
 return -1;
}

canonical_original_code:
int strtoas(char *str, int *as)
{
 char *table[] = {
  "VME_A16", "VME_A24", "VME_A32"
 };
 int ii;
 for (ii = 0; ii <= VME_A32; ++ii)
  if (table[ii]) {
   if (0 == strcmp(str, table[ii])) {
    *as = ii;
    return 0;
   }
  }
 return -1;
}

variable_types:
as
int *


strtodw

original_code:
int strtodw(const char *str, int *dw)
{
 char *table[] = {
  ((void *)0), "VME_D8", "VME_D16", ((void *)0), "VME_D32", ((void *)0), ((void *)0), ((void *)0),
  "VME_D64"
 };
 int ii;
 for (ii = 0; ii <= VME_D64; ++ii)
  if (table[ii]) {
   if (0 == strcmp(str, table[ii])) {
    *dw = ii;
    return 0;
   }
  }
 return -1;
}

canonical_original_code:
int strtodw(char *str, int *dw)
{
 char *table[] = {
  ((void *)0), "VME_D8", "VME_D16", ((void *)0), "VME_D32", ((void *)0), ((void *)0), ((void *)0),
  "VME_D64"
 };
 int ii;
 for (ii = 0; ii <= VME_D64; ++ii)
  if (table[ii]) {
   if (0 == strcmp(str, table[ii])) {
    *dw = ii;
    return 0;
   }
  }
 return -1;
}

variable_types:
dw
int *


strtolvl

decompiled_code:
int __fastcall strtolvl(char *s1, _DWORD *a2)
{
__int64 i; // rbx
const char *v4; // rsi
int result; // eax
char *s2[29]; // [rsp+0h] [rbp-E8h]

s2[0] = "VME_INTERRUPT_VOWN";
s2[1] = "VME_INTERRUPT_VIRQ1";
s2[2] = "VME_INTERRUPT_VIRQ2";
s2[3] = "VME_INTERRUPT_VIRQ3";
s2[4] = "VME_INTERRUPT_VIRQ4";
s2[5] = "VME_INTERRUPT_VIRQ5";
s2[6] = "VME_INTERRUPT_VIRQ6";
s2[7] = "VME_INTERRUPT_VIRQ7";
s2[8] = "VME_INTERRUPT_DMA";
s2[9] = "VME_INTERRUPT_LERR";
s2[10] = "VME_INTERRUPT_BERR";
s2[11] = 0LL;
s2[12] = "VME_INTERRUPT_SW_IACK";
s2[13] = "VME_INTERRUPT_SW_INT";
s2[14] = "VME_INTERRUPT_SYSFAIL";
s2[15] = "VME_INTERRUPT_ACFAIL";
s2[16] = "VME_INTERRUPT_MBOX0";
s2[17] = "VME_INTERRUPT_MBOX1";
s2[18] = "VME_INTERRUPT_MBOX2";
s2[19] = "VME_INTERRUPT_MBOX3";
s2[20] = "VME_INTERRUPT_LM0";
s2[21] = "VME_INTERRUPT_LM1";
s2[22] = "VME_INTERRUPT_LM2";
s2[23] = "VME_INTERRUPT_LM3";
for ( i = 0LL; i != 24; ++i )
{
v4 = s2[i];
if ( v4 )
{
result = strcmp(s1, v4);
if ( !result )
{
*a2 = i;
return result;
}
}
}
return -1;
}

canonical_decompiled_code:
int __fastcall func3(char *s1, _DWORD *a2)
{
__int64 i; // rbx
const char *v4; // rsi
int result; // eax
char *s2[29]; // [rsp+0h] [rbp-E8h]

s2[0] = "VME_INTERRUPT_VOWN";
s2[1] = "VME_INTERRUPT_VIRQ1";
s2[2] = "VME_INTERRUPT_VIRQ2";
s2[3] = "VME_INTERRUPT_VIRQ3";
s2[4] = "VME_INTERRUPT_VIRQ4";
s2[5] = "VME_INTERRUPT_VIRQ5";
s2[6] = "VME_INTERRUPT_VIRQ6";
s2[7] = "VME_INTERRUPT_VIRQ7";
s2[8] = "VME_INTERRUPT_DMA";
s2[9] = "VME_INTERRUPT_LERR";
s2[10] = "VME_INTERRUPT_BERR";
s2[11] = 0LL;
s2[12] = "VME_INTERRUPT_SW_IACK";
s2[13] = "VME_INTERRUPT_SW_INT";
s2[14] = "VME_INTERRUPT_SYSFAIL";
s2[15] = "VME_INTERRUPT_ACFAIL";
s2[16] = "VME_INTERRUPT_MBOX0";
s2[17] = "VME_INTERRUPT_MBOX1";
s2[18] = "VME_INTERRUPT_MBOX2";
s2[19] = "VME_INTERRUPT_MBOX3";
s2[20] = "VME_INTERRUPT_LM0";
s2[21] = "VME_INTERRUPT_LM1";
s2[22] = "VME_INTERRUPT_LM2";
s2[23] = "VME_INTERRUPT_LM3";
for ( i = 0LL; i != 24; ++i )
{
v4 = s2[i];
if ( v4 )
{
result = strcmp(s1, v4);
if ( !result )
{
*a2 = i;
return result;
}
}
}
return -1;
}

original_code:
int strtolvl(const char *str, int *level)
{
 char *table[] = {
  "VME_INTERRUPT_VOWN", "VME_INTERRUPT_VIRQ1",
  "VME_INTERRUPT_VIRQ2", "VME_INTERRUPT_VIRQ3",
  "VME_INTERRUPT_VIRQ4", "VME_INTERRUPT_VIRQ5",
  "VME_INTERRUPT_VIRQ6", "VME_INTERRUPT_VIRQ7",
  "VME_INTERRUPT_DMA", "VME_INTERRUPT_LERR",
  "VME_INTERRUPT_BERR", ((void *)0), "VME_INTERRUPT_SW_IACK",
  "VME_INTERRUPT_SW_INT", "VME_INTERRUPT_SYSFAIL",
  "VME_INTERRUPT_ACFAIL", "VME_INTERRUPT_MBOX0",
  "VME_INTERRUPT_MBOX1", "VME_INTERRUPT_MBOX2",
  "VME_INTERRUPT_MBOX3", "VME_INTERRUPT_LM0",
  "VME_INTERRUPT_LM1", "VME_INTERRUPT_LM2",
  "VME_INTERRUPT_LM3"
 };
 int ii;
 for (ii = 0; ii <= VME_INTERRUPT_LM3; ++ii)
  if (table[ii]) {
   if (0 == strcmp(str, table[ii])) {
    *level = ii;
    return 0;
   }
  }
 return -1;
}

canonical_original_code:
int strtolvl(char *str, int *level)
{
 char *table[] = {
  "VME_INTERRUPT_VOWN", "VME_INTERRUPT_VIRQ1",
  "VME_INTERRUPT_VIRQ2", "VME_INTERRUPT_VIRQ3",
  "VME_INTERRUPT_VIRQ4", "VME_INTERRUPT_VIRQ5",
  "VME_INTERRUPT_VIRQ6", "VME_INTERRUPT_VIRQ7",
  "VME_INTERRUPT_DMA", "VME_INTERRUPT_LERR",
  "VME_INTERRUPT_BERR", ((void *)0), "VME_INTERRUPT_SW_IACK",
  "VME_INTERRUPT_SW_INT", "VME_INTERRUPT_SYSFAIL",
  "VME_INTERRUPT_ACFAIL", "VME_INTERRUPT_MBOX0",
  "VME_INTERRUPT_MBOX1", "VME_INTERRUPT_MBOX2",
  "VME_INTERRUPT_MBOX3", "VME_INTERRUPT_LM0",
  "VME_INTERRUPT_LM1", "VME_INTERRUPT_LM2",
  "VME_INTERRUPT_LM3"
 };
 int ii;
 for (ii = 0; ii <= VME_INTERRUPT_LM3; ++ii)
  if (table[ii]) {
   if (0 == strcmp(str, table[ii])) {
    *level = ii;
    return 0;
   }
  }
 return -1;
}

variable_types:
level
int *


decompiled_code:
_DWORD *syck_alloc_map()
{
_QWORD *v0; // rbx
_DWORD *result; // rax

v0 = malloc(0x28uLL);
*(_DWORD *)v0 = 0;
v0[4] = 0LL;
v0[3] = 8LL;
v0[1] = malloc(0x40uLL);
v0[2] = malloc(0x40uLL);
result = syck_alloc_node(0);
*((_QWORD *)result + 4) = v0;
return result;
}

canonical_decompiled_code:
_DWORD *func0()
{
_QWORD *v0; // rbx
_DWORD *result; // rax

v0 = malloc(0x28uLL);
*(_DWORD *)v0 = 0;
v0[4] = 0LL;
v0[3] = 8LL;
v0[1] = malloc(0x40uLL);
v0[2] = malloc(0x40uLL);
result = syck_alloc_node(0);
*((_QWORD *)result + 4) = v0;
return result;
}

original_code:
SyckNode *
syck_alloc_map(void)
{
    SyckNode *n;
    struct SyckMap *m;
    m = (struct SyckMap*)malloc(sizeof(struct SyckMap));
    m->style = map_none;
    m->idx = 0;
    m->capa = 8;
    m->keys = (unsigned long*)malloc(sizeof(unsigned long)*(m->capa));
    m->values = (unsigned long*)malloc(sizeof(unsigned long)*(m->capa));
    n = syck_alloc_node( syck_map_kind );
    n->data.pairs = m;
    return n;
}

canonical_original_code:
struct _syck_node *syck_alloc_map()
{
    struct _syck_node *n;
    struct SyckMap *m;
    m = (struct SyckMap *)malloc(sizeof(struct SyckMap));
    m->style = map_none;
    m->idx = 0;
    m->capa = 8;
    m->keys = (unsigned long *)malloc(sizeof(unsigned long)*(m->capa));
    m->values = (unsigned long *)malloc(sizeof(unsigned long)*(m->capa));
    n = syck_alloc_node( syck_map_kind );
    n->data.pairs = m;
    return n;
}

variable_types: struct _syck_node { unsigned long id; enum syck_kind_tag { syck_map_kind=0, syck_seq_kind=1, syck_str_kind=2 } kind; char *type_id; char *anchor; union { struct SyckMap { enum map_style { map_none=0, map_inline=1 } style; unsigned long *keys; unsigned long *values; long capa; long idx; } *pairs; struct SyckSeq { enum seq_style { seq_none=0, seq_inline=1 } style; unsigned long *items; long capa; long idx; } *list; struct SyckStr { enum scalar_style { scalar_none=0, scalar_1quote=1, scalar_2quote=2, scalar_fold=3, scalar_literal=4, scalar_plain=5 } style; char *ptr; long len; } *str; } data; void *shortcut; } *

user_defined_types: struct SyckMap { enum map_style style; unsigned long *keys; unsigned long *values; long capa; long idx; }

user_defined_types: struct _syck_node { unsigned long id; enum syck_kind_tag kind; char *type_id; char *anchor; union { struct SyckMap *pairs; struct SyckSeq *list; struct SyckStr *str; } data; void *shortcut; }

user_defined_types: struct SyckSeq { enum seq_style style; unsigned long *items; long capa; long idx; }

user_defined_types: struct SyckStr { enum scalar_style style; char *ptr; long len; }


decompiled_code:
_DWORD *syck_alloc_seq()
{
_QWORD *v0; // rbx
_DWORD *result; // rax

v0 = malloc(0x20uLL);
*(_DWORD *)v0 = 0;
v0[3] = 0LL;
v0[2] = 8LL;
v0[1] = malloc(0x40uLL);
result = syck_alloc_node(1);
*((_QWORD *)result + 4) = v0;
return result;
}

canonical_decompiled_code:
_DWORD *func1()
{
_QWORD *v0; // rbx
_DWORD *result; // rax

v0 = malloc(0x20uLL);
*(_DWORD *)v0 = 0;
v0[3] = 0LL;
v0[2] = 8LL;
v0[1] = malloc(0x40uLL);
result = syck_alloc_node(1);
*((_QWORD *)result + 4) = v0;
return result;
}

original_code:
SyckNode *
syck_alloc_seq(void)
{
    SyckNode *n;
    struct SyckSeq *s;
    s = (struct SyckSeq*)malloc(sizeof(struct SyckSeq));
    s->style = seq_none;
    s->idx = 0;
    s->capa = 8;
    s->items = (unsigned long*)malloc(sizeof(unsigned long)*(s->capa));
    n = syck_alloc_node( syck_seq_kind );
    n->data.list = s;
    return n;
}

canonical_original_code:
struct _syck_node *syck_alloc_seq()
{
    struct _syck_node *n;
    struct SyckSeq *s;
    s = (struct SyckSeq *)malloc(sizeof(struct SyckSeq));
    s->style = seq_none;
    s->idx = 0;
    s->capa = 8;
    s->items = (unsigned long *)malloc(sizeof(unsigned long)*(s->capa));
    n = syck_alloc_node( syck_seq_kind );
    n->data.list = s;
    return n;
}

return_type: struct _syck_node { unsigned long id; enum syck_kind_tag { syck_map_kind=0, syck_seq_kind=1, syck_str_kind=2 } kind; char *type_id; char *anchor; union { struct SyckMap { enum map_style { map_none=0, map_inline=1 } style; unsigned long *keys; unsigned long *values; long capa; long idx; } *pairs; struct SyckSeq { enum seq_style { seq_none=0, seq_inline=1 } style; unsigned long *items; long capa; long idx; } *list; struct SyckStr { enum scalar_style { scalar_none=0, scalar_1quote=1, scalar_2quote=2, scalar_fold=3, scalar_literal=4, scalar_plain=5 } style; char *ptr; long len; } *str; } data; void *shortcut; } *


decompiled_code:
_DWORD *syck_alloc_str()
{
_QWORD *v0; // rbx
_DWORD *result; // rax

v0 = malloc(0x18uLL);
v0[2] = 0LL;
v0[1] = 0LL;
*(_DWORD *)v0 = 0;
result = syck_alloc_node(2);
*((_QWORD *)result + 4) = v0;
return result;
}

canonical_decompiled_code:
_DWORD *func2()
{
_QWORD *v0; // rbx
_DWORD *result; // rax

v0 = malloc(0x18uLL);
v0[2] = 0LL;
v0[1] = 0LL;
*(_DWORD *)v0 = 0;
result = syck_alloc_node(2);
*((_QWORD *)result + 4) = v0;
return result;
}

original_code:
SyckNode *
syck_alloc_str(void)
{
    SyckNode *n;
    struct SyckStr *s;
    s = (struct SyckStr*)malloc(sizeof(struct SyckStr));
    s->len = 0;
    s->ptr = ((void *)0);
    s->style = scalar_none;
    n = syck_alloc_node( syck_str_kind );
    n->data.str = s;
    return n;
}

canonical_original_code:
struct _syck_node *syck_alloc_str()
{
    struct _syck_node *n;
    struct SyckStr *s;
    s = (struct SyckStr *)malloc(sizeof(struct SyckStr));
    s->len = 0;
    s->ptr = ((void *)0);
    s->style = scalar_none;
    n = syck_alloc_node( syck_str_kind );
    n->data.str = s;
    return n;
}

variable_types: struct SyckStr { enum scalar_style { scalar_none=0, scalar_1quote=1, scalar_2quote=2, scalar_fold=3, scalar_literal=4, scalar_plain=5 } style; char *ptr; long len; } *

user_defined_types: enum syck_kind_tag { syck_map_kind=0, syck_seq_kind=1, syck_str_kind=2 }

user_defined_types: enum map_style { map_none=0, map_inline=1 }

user_defined_types: enum seq_style { seq_none=0, seq_inline=1 }


decompiled_code:
__int64 __fastcall syck_replace_str(__int64 a1, const char *a2, int a3)
{
size_t v4; // rax

v4 = strlen(a2);
return syck_replace_str2(a1, a2, v4, a3);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2, int a3)
{
size_t v4; // rax

v4 = strlen(a2);
return func3(a1, a2, v4, a3);
}

original_code:
void
syck_replace_str( SyckNode *n, char *str, enum scalar_style style )
{
    syck_replace_str2( n, str, strlen( str ), style );
}

canonical_original_code:
void syck_replace_str(struct _syck_node *n, char *str, enum scalar_style style)
{
    syck_replace_str2( n, str, strlen( str ), style );
}

variable_types: enum scalar_style { scalar_none=0, scalar_1quote=1, scalar_2quote=2, scalar_fold=3, scalar_literal=4, scalar_plain=5 }


decompiled_code:
__int64 __fastcall syck_str_blow_away_commas(__int64 a1)
{
__int64 v1; // rdx
__int64 v2; // rbp
unsigned __int8 *v3; // rbx
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 32);
v2 = *(_QWORD *)(v1 + 16) + *(_QWORD *)(v1 + 8);
v3 = (unsigned __int8 *)(*(_QWORD *)(v1 + 8) + 1LL);
for ( result = *v3; (_BYTE)result; result = *v3 )
{
if ( (_BYTE)result == 44 )
{
--*(_QWORD *)(*(_QWORD *)(a1 + 32) + 16LL);
memmove(v3, v3 + 1, v2 - (_QWORD)v3);
--v2;
}
++v3;
}
return result;
}

original_code:
void
syck_str_blow_away_commas( SyckNode *n )
{
    char *go, *end;
    go = n->data.str->ptr;
    end = go + n->data.str->len;
    while ( *(++go) != '\0' )
    {
        if ( *go == ',' )
        {
            n->data.str->len -= 1;
            memmove( go, go + 1, end - go );
            end -= 1;
        }
    }
}

canonical_original_code:
void syck_str_blow_away_commas(struct _syck_node *n)
{
    char *go; char *end;
    go = n->data.str->ptr;
    end = go + n->data.str->len;
    while ( *(++go) != '\0' )
    {
        if ( *go == ',' )
        {
            n->data.str->len -= 1;
            memmove( go, go + 1, end - go );
            end -= 1;
        }
    }
}

variable_types:
go
char *

variable_types:
end
char *

user_defined_types: enum scalar_style { scalar_none=0, scalar_1quote=1, scalar_2quote=2, scalar_fold=3, scalar_literal=4, scalar_plain=5 }


decompiled_code:
__int64 __fastcall syck_str_read(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 32) + 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 32) + 8LL);
}

original_code:
char *
syck_str_read( SyckNode *n )
{
    ((void)0);
    return n->data.str->ptr;
}

canonical_original_code:
char *syck_str_read(struct _syck_node *n)
{
    ((void)0);
    return n->data.str->ptr;
}

return_type: char *


original_code:
void
syck_map_update( SyckNode *map1, SyckNode *map2 )
{
    struct SyckMap *m1, *m2;
    long new_idx, new_capa;
    ((void)0);
    ((void)0);
    m1 = map1->data.pairs;
    m2 = map2->data.pairs;
    if ( m2->idx < 1 ) return;
    new_idx = m1->idx;
    new_idx += m2->idx;
    new_capa = m1->capa;
    while ( new_idx > new_capa )
    {
        new_capa += 8;
    }
    if ( new_capa > m1->capa )
    {
        m1->capa = new_capa;
        (m1->keys)=(unsigned long*)realloc((char*)(m1->keys),sizeof(unsigned long)*(m1->capa));
        (m1->values)=(unsigned long*)realloc((char*)(m1->values),sizeof(unsigned long)*(m1->capa));
    }
    for ( new_idx = 0; new_idx < m2->idx; m1->idx++, new_idx++ )
    {
        m1->keys[m1->idx] = m2->keys[new_idx];
        m1->values[m1->idx] = m2->values[new_idx];
    }
}

canonical_original_code:
void syck_map_update(struct _syck_node *map1, struct _syck_node *map2)
{
    struct SyckMap *m1; struct SyckMap *m2;
    long new_idx; long new_capa;
    ((void)0);
    ((void)0);
    m1 = map1->data.pairs;
    m2 = map2->data.pairs;
    if ( m2->idx < 1 ) return;
    new_idx = m1->idx;
    new_idx += m2->idx;
    new_capa = m1->capa;
    while ( new_idx > new_capa )
    {
        new_capa += 8;
    }
    if ( new_capa > m1->capa )
    {
        m1->capa = new_capa;
        (m1->keys)=(unsigned long *)realloc((char *)(m1->keys),sizeof(unsigned long)*(m1->capa));
        (m1->values)=(unsigned long *)realloc((char *)(m1->values),sizeof(unsigned long)*(m1->capa));
    }
    for ( new_idx = 0; new_idx < m2->idx; m1->idx++, new_idx++ )
    {
        m1->keys[m1->idx] = m2->keys[new_idx];
        m1->values[m1->idx] = m2->values[new_idx];
    }
}

variable_types: struct SyckMap { enum map_style { map_none=0, map_inline=1 } style; unsigned long *keys; unsigned long *values; long capa; long idx; } *


decompiled_code:
__int64 __fastcall syck_map_count(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 32) + 32LL);
}

original_code:
long
syck_map_count( SyckNode *map )
{
    ((void)0);
    ((void)0);
    return map->data.pairs->idx;
}

canonical_original_code:
long syck_map_count(struct _syck_node *map)
{
    ((void)0);
    ((void)0);
    return map->data.pairs->idx;
}

return_type: long