repo: Eivindfy/Prosjekt-sanntid

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // ebp
char v6[1024]; // [rsp+0h] [rbp-818h] BYREF
char buf[1048]; // [rsp+400h] [rbp-418h] BYREF

puts("UDPTEST: starta programmet");
strcpy(v6, "melding\n");
v3 = initializetcpudpchannel("UDPTEST: starta programmet", argv);
v4 = initializetcpudpchannel("UDPTEST: starta programmet", argv);
sleep(2u);
puts("UDPTEST: Sending to socketfd");
send(v3, v6, 0x400uLL, 0);
puts("UDPTEST: Receiving from socketfd2 ");
recv(v4, buf, 0x400uLL, 0);
printf("her skal melding komme: %s \n", buf);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // ebp
char v6[1024]; // [rsp+0h] [rbp-818h] BYREF
char buf[1048]; // [rsp+400h] [rbp-418h] BYREF

puts("UDPTEST: starta programmet");
strcpy(v6, "melding\n");
v3 = func9("UDPTEST: starta programmet", argv);
v4 = func9("UDPTEST: starta programmet", argv);
sleep(2u);
puts("UDPTEST: Sending to socketfd");
send(v3, v6, 0x400uLL, 0);
puts("UDPTEST: Receiving from socketfd2 ");
recv(v4, buf, 0x400uLL, 0);
printf("her skal melding komme: %s \n", buf);
return 0;
}

original_code:
int main(){
 printf("UDPTEST: starta programmet\n");
 char send_buffer[1024];
 strcpy(send_buffer,"melding\n");
 char recv_buffer[1024];
 int socketfd = initializetcpudpchannel();
 int socketfd2 = initializetcpudpchannel();
 sleep(2);
 printf("UDPTEST: Sending to socketfd\n");
 send(socketfd, send_buffer, sizeof(send_buffer), 0);
 printf("UDPTEST: Receiving from socketfd2 \n");
 recv(socketfd2, recv_buffer, sizeof(recv_buffer), 0);
 printf("her skal melding komme: %s \n", recv_buffer);
 return 0;
}

variable_types: socketfd int


initializetcpudpchannel

decompiled_code:
__int64 initializetcpudpchannel()
{
_DWORD *v0; // rax
pthread_t v2; // [rsp+0h] [rbp-18h] BYREF
int fds[2]; // [rsp+8h] [rbp-10h] BYREF

socketpair(1, 1, 0, fds);
v0 = malloc(4uLL);
*v0 = fds[0];
pthread_create(&v2, 0LL, (void *(*)(void *))tcpudpchannel, v0);
return (unsigned int)fds[1];
}

canonical_decompiled_code:
__int64 func9()
{
_DWORD *v0; // rax
pthread_t v2; // [rsp+0h] [rbp-18h] BYREF
int fds[2]; // [rsp+8h] [rbp-10h] BYREF

socketpair(1, 1, 0, fds);
v0 = malloc(4uLL);
*v0 = fds[0];
pthread_create(&v2, 0LL, (void *(*)(void *))tcpudpchannel, v0);
return (unsigned int)fds[1];
}

original_code:
int initializetcpudpchannel(){
 int fd[2];
 socketpair(1, SOCK_STREAM, 0, fd);
 int* dynamic_int_pointer = malloc(sizeof(*dynamic_int_pointer));
 *dynamic_int_pointer = fd[0];
 void* dynamic_void_pointer;
 dynamic_void_pointer = (void*)dynamic_int_pointer;
 pthread_t channel;
 pthread_create(&channel,((void *)0), tcpudpchannel, dynamic_void_pointer);
 return fd[1];
}

canonical_original_code:
int initializetcpudpchannel(){
 int fd[2];
 socketpair(1, SOCK_STREAM, 0, fd);
 int *dynamic_int_pointer = malloc(sizeof(*dynamic_int_pointer));
 *dynamic_int_pointer = fd[0];
 void *dynamic_void_pointer;
 dynamic_void_pointer = (void *)dynamic_int_pointer;
 unsigned long channel;
 pthread_create(&channel,((void *)0), tcpudpchannel, dynamic_void_pointer);
 return fd[1];
}

variable_types:
fd
int [2]

variable_types:
channel
unsigned long

return_type: int


repo: ElFeesho/OldCProjects

decompiled_code:
int __fastcall convert_to_dec(const char *a1)
{
int v1; // eax
int v2; // esi
unsigned int v3; // er8
const char *v4; // rdx
int i; // eax
char v6; // cl

v1 = strlen(a1);
if ( v1 <= 0 )
{
v3 = 0;
}
else
{
v2 = v1;
v3 = 0;
v4 = &a1[v1 - 1];
for ( i = 0; i != v2; ++i )
{
v6 = i;
if ( *v4 != 48 )
v3 += 1 << v6;
--v4;
}
}
return printf("Binary: %s - Dec: %d\n", a1, v3);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
int v1; // eax
int v2; // esi
unsigned int v3; // er8
const char *v4; // rdx
int i; // eax
char v6; // cl

v1 = strlen(a1);
if ( v1 <= 0 )
{
v3 = 0;
}
else
{
v2 = v1;
v3 = 0;
v4 = &a1[v1 - 1];
for ( i = 0; i != v2; ++i )
{
v6 = i;
if ( *v4 != 48 )
v3 += 1 << v6;
--v4;
}
}
return printf("Binary: %s - Dec: %d\n", a1, v3);
}

original_code:
void convert_to_dec(char *binary_str)
{
 int res = 0;
 int binary_len = strlen(binary_str);
 int i = 0;
 for(i = 0; i<binary_len; i++)
 {
  res += (binary_str[binary_len-(i+1)]=='0')?(0):(1<<i);
 }
 printf("Binary: %s - Dec: %d\n",binary_str, res);
}

variable_types: res int

variable_types: i int

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc > 1 )
convert_to_dec(argv[1]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc > 1 )
func7(argv[1]);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 if(argc<2)
 {
  return 0;
 }
 convert_to_dec(argv[1]);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


original_code:
static void mimic_init(MimCtx *ctx, gint width, gint height)
{
    gint bufsize, i;
    ctx->frame_width = width;
    ctx->frame_height = height;
    ctx->y_stride = ctx->frame_width;
    ctx->y_row_count = ctx->frame_height;
    ctx->y_size = ctx->y_stride * ctx->y_row_count;
    ctx->crcb_stride = ctx->y_stride / 2;
    ctx->crcb_row_count = ctx->y_row_count / 2;
    ctx->crcb_size = ctx->crcb_stride * ctx->crcb_row_count;
    ctx->num_vblocks_y = ctx->frame_height / 8;
    ctx->num_hblocks_y = ctx->frame_width / 8;
    ctx->num_vblocks_cbcr = ctx->frame_height / 16;
    ctx->num_hblocks_cbcr = ctx->frame_width / 16;
    if (ctx->frame_height % 16 != 0)
        ctx->num_vblocks_cbcr++;
    ctx->frame_num = 0;
    ctx->ptr_index = 15;
    ctx->num_coeffs = 28;
    ctx->cur_frame_buf = ((guchar *) g_malloc_n (((320 * 240 * 3) / 2), sizeof (guchar)));
    bufsize = ctx->y_size + (ctx->crcb_size * 2);
    for (i = 0; i < 16; i++)
        ctx->buf_ptrs[i] = ((guchar *) g_malloc_n ((bufsize), sizeof (guchar)));
    _initialize_vlcdec_lookup(ctx->vlcdec_lookup);
}

canonical_original_code:
static void mimic_init(struct _MimCtx *ctx, int width, int height)
{
    int bufsize; int i;
    ctx->frame_width = width;
    ctx->frame_height = height;
    ctx->y_stride = ctx->frame_width;
    ctx->y_row_count = ctx->frame_height;
    ctx->y_size = ctx->y_stride * ctx->y_row_count;
    ctx->crcb_stride = ctx->y_stride / 2;
    ctx->crcb_row_count = ctx->y_row_count / 2;
    ctx->crcb_size = ctx->crcb_stride * ctx->crcb_row_count;
    ctx->num_vblocks_y = ctx->frame_height / 8;
    ctx->num_hblocks_y = ctx->frame_width / 8;
    ctx->num_vblocks_cbcr = ctx->frame_height / 16;
    ctx->num_hblocks_cbcr = ctx->frame_width / 16;
    if (ctx->frame_height % 16 != 0)
        ctx->num_vblocks_cbcr++;
    ctx->frame_num = 0;
    ctx->ptr_index = 15;
    ctx->num_coeffs = 28;
    ctx->cur_frame_buf = ((unsigned char *) g_malloc_n (((320 * 240 * 3) / 2), sizeof (guchar)));
    bufsize = ctx->y_size + (ctx->crcb_size * 2);
    for (i = 0; i < 16; i++)
        ctx->buf_ptrs[i] = ((unsigned char *) g_malloc_n ((bufsize), sizeof (guchar)));
    _initialize_vlcdec_lookup(ctx->vlcdec_lookup);
}

variable_types: struct _MimCtx { int encoder_initialized; int decoder_initialized; int frame_width; int frame_height; int quality; int num_coeffs; int y_stride; int y_row_count; int y_size; int crcb_stride; int crcb_row_count; int crcb_size; int num_vblocks_y; int num_hblocks_y; int num_vblocks_cbcr; int num_hblocks_cbcr; unsigned char *cur_frame_buf; unsigned char *prev_frame_buf; char vlcdec_lookup[2296]; char *data_buffer; unsigned int data_index; unsigned int cur_chunk; int cur_chunk_len; unsigned int *chunk_ptr; int read_odd; int frame_num; int ptr_index; unsigned char *buf_ptrs[16]; } *

variable_types: width int

variable_types: height int

variable_types: bufsize int


decompiled_code:
_QWORD *mimic_open()
{
_QWORD *result; // rax

result = (_QWORD *)g_malloc0(2552LL);
*result = 0LL;
return result;
}

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

result = (_QWORD *)g_malloc0(2552LL);
*result = 0LL;
return result;
}

original_code:
MimCtx *mimic_open()
{
    MimCtx *ctx;
    ctx = ((MimCtx *) g_malloc0_n ((1), sizeof (MimCtx)));
    ctx->encoder_initialized = (0);
    ctx->decoder_initialized = (0);
    return ctx;
}

canonical_original_code:
struct _MimCtx *mimic_open()
{
    struct _MimCtx *ctx;
    ctx = ((struct _MimCtx *) g_malloc0_n ((1), sizeof (MimCtx)));
    ctx->encoder_initialized = (0);
    ctx->decoder_initialized = (0);
    return ctx;
}

return_type: struct _MimCtx { int encoder_initialized; int decoder_initialized; int frame_width; int frame_height; int quality; int num_coeffs; int y_stride; int y_row_count; int y_size; int crcb_stride; int crcb_row_count; int crcb_size; int num_vblocks_y; int num_hblocks_y; int num_vblocks_cbcr; int num_hblocks_cbcr; unsigned char *cur_frame_buf; unsigned char *prev_frame_buf; char vlcdec_lookup[2296]; char *data_buffer; unsigned int data_index; unsigned int cur_chunk; int cur_chunk_len; unsigned int *chunk_ptr; int read_odd; int frame_num; int ptr_index; unsigned char *buf_ptrs[16]; } *


decompiled_code:
__int64 __fastcall mimic_close(_QWORD *a1)
{
__int64 *v3; // rbx
__int64 v4; // rdi

if ( !*a1 )
return g_free(a1);
v3 = a1 + 303;
g_free(a1[8]);
do
{
v4 = *v3++;
g_free(v4);
}
while ( v3 != a1 + 319 );
return g_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
__int64 *v3; // rbx
__int64 v4; // rdi

if ( !*a1 )
return g_free(a1);
v3 = a1 + 303;
g_free(a1[8]);
do
{
v4 = *v3++;
g_free(v4);
}
while ( v3 != a1 + 319 );
return g_free(a1);
}

original_code:
void mimic_close(MimCtx *ctx)
{
    if (ctx->encoder_initialized || ctx->decoder_initialized) {
        gint i;
        g_free(ctx->cur_frame_buf);
        for (i = 0; i < 16; i++)
            g_free(ctx->buf_ptrs[i]);
    }
    g_free(ctx);
}

canonical_original_code:
void mimic_close(struct _MimCtx *ctx)
{
    if (ctx->encoder_initialized || ctx->decoder_initialized) {
        int i;
        g_free(ctx->cur_frame_buf);
        for (i = 0; i < 16; i++)
            g_free(ctx->buf_ptrs[i]);
    }
    g_free(ctx);
}

user_defined_types: struct _MimCtx { int encoder_initialized; int decoder_initialized; int frame_width; int frame_height; int quality; int num_coeffs; int y_stride; int y_row_count; int y_size; int crcb_stride; int crcb_row_count; int crcb_size; int num_vblocks_y; int num_hblocks_y; int num_vblocks_cbcr; int num_hblocks_cbcr; unsigned char *cur_frame_buf; unsigned char *prev_frame_buf; char vlcdec_lookup[2296]; char *data_buffer; unsigned int data_index; unsigned int cur_chunk; int cur_chunk_len; unsigned int *chunk_ptr; int read_odd; int frame_num; int ptr_index; unsigned char *buf_ptrs[16]; }


decompiled_code:
__int64 __fastcall mimic_encoder_init(_DWORD *a1, int a2)
{
__int64 result; // rax
int v3; // edx
int v4; // esi

result = 0LL;
if ( !*(_QWORD *)a1 )
{
if ( a2 )
{
if ( a2 != 1 )
return result;
v3 = 240;
v4 = 320;
}
else
{
v3 = 120;
v4 = 160;
}
mimic_init((__int64)a1, v4, v3);
*a1 = 1;
result = 1LL;
a1[4] = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1, int a2)
{
__int64 result; // rax
int v3; // edx
int v4; // esi

result = 0LL;
if ( !*(_QWORD *)a1 )
{
if ( a2 )
{
if ( a2 != 1 )
return result;
v3 = 240;
v4 = 320;
}
else
{
v3 = 120;
v4 = 160;
}
func0((__int64)a1, v4, v3);
*a1 = 1;
result = 1LL;
a1[4] = 0;
}
return result;
}

original_code:
gboolean mimic_encoder_init(MimCtx *ctx, const MimicResEnum resolution)
{
    gint width, height;
    if (ctx->encoder_initialized || ctx->decoder_initialized)
        return (0);
    if (resolution == MIMIC_RES_LOW) {
        width = 160;
        height = 120;
    } else if (resolution == MIMIC_RES_HIGH) {
        width = 320;
        height = 240;
    } else {
        return (0);
    }
    mimic_init(ctx, width, height);
    ctx->quality = 0;
    ctx->encoder_initialized = (!(0));
    return (!(0));
}

canonical_original_code:
int mimic_encoder_init(struct _MimCtx *ctx, enum MimicResEnum resolution)
{
    int width; int height;
    if (ctx->encoder_initialized || ctx->decoder_initialized)
        return (0);
    if (resolution == MIMIC_RES_LOW) {
        width = 160;
        height = 120;
    } else if (resolution == MIMIC_RES_HIGH) {
        width = 320;
        height = 240;
    } else {
        return (0);
    }
    mimic_init(ctx, width, height);
    ctx->quality = 0;
    ctx->encoder_initialized = (!(0));
    return (!(0));
}

variable_types: enum MimicResEnum { MIMIC_RES_LOW=0, MIMIC_RES_HIGH=1 }


original_code:
gboolean mimic_decoder_init(MimCtx *ctx, const guchar *frame_buffer)
{
    gint width, height;
    gboolean is_keyframe;
    if (ctx->encoder_initialized || ctx->decoder_initialized ||
        frame_buffer == ((void *)0))
    {
        return (0);
    }
    width = (((guint16) (*((guint16 *) (frame_buffer + 4)))));
    height = (((guint16) (*((guint16 *) (frame_buffer + 6)))));
    if (!(width == 160 && height == 120) && !(width == 320 && height == 240))
        return (0);
    is_keyframe = ((((guint32) (*((guint32 *) (frame_buffer + 12))))) == 0);
    if (!is_keyframe)
        return (0);
    ctx->quality = (((guint16) (*((guint16 *) (frame_buffer + 2)))));
    mimic_init(ctx, width, height);
    ctx->decoder_initialized = (!(0));
    return (!(0));
}

canonical_original_code:
int mimic_decoder_init(struct _MimCtx *ctx, unsigned char *frame_buffer)
{
    int width; int height;
    int is_keyframe;
    if (ctx->encoder_initialized || ctx->decoder_initialized ||
        frame_buffer == ((void *)0))
    {
        return (0);
    }
    width = (((guint16) (*((unsigned short *) (frame_buffer + 4)))));
    height = (((guint16) (*((unsigned short *) (frame_buffer + 6)))));
    if (!(width == 160 && height == 120) && !(width == 320 && height == 240))
        return (0);
    is_keyframe = ((((guint32) (*((unsigned int *) (frame_buffer + 12))))) == 0);
    if (!is_keyframe)
        return (0);
    ctx->quality = (((guint16) (*((unsigned short *) (frame_buffer + 2)))));
    mimic_init(ctx, width, height);
    ctx->decoder_initialized = (!(0));
    return (!(0));
}


decompiled_code:
__int64 __fastcall mimic_get_property(__int64 a1, const char *a2, _DWORD *a3)
{
unsigned int v3; // er9
bool v4; // zf

v3 = 0;
if ( !*(_QWORD *)a1 )
return v3;
v4 = strcmp(a2, "buffer_size") == 0;
if ( *(_DWORD *)a1 )
{
if ( v4 )
{
*a3 = 0x4000;
return 1LL;
}
}
else if ( v4 )
{
*a3 = 3 * *(_DWORD *)(a1 + 12) * *(_DWORD *)(a1 + 8);
return 1LL;
}
if ( strcmp(a2, "width") )
{
if ( !strcmp(a2, "height") )
{
v3 = 1;
*a3 = *(_DWORD *)(a1 + 12);
}
else
{
v3 = 0;
if ( !strcmp(a2, "quality") )
{
v3 = 1;
*a3 = *(_DWORD *)(a1 + 16);
}
}
return v3;
}
*a3 = *(_DWORD *)(a1 + 8);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char *a2, _DWORD *a3)
{
unsigned int v3; // er9
bool v4; // zf

v3 = 0;
if ( !*(_QWORD *)a1 )
return v3;
v4 = strcmp(a2, "buffer_size") == 0;
if ( *(_DWORD *)a1 )
{
if ( v4 )
{
*a3 = 0x4000;
return 1LL;
}
}
else if ( v4 )
{
*a3 = 3 * *(_DWORD *)(a1 + 12) * *(_DWORD *)(a1 + 8);
return 1LL;
}
if ( strcmp(a2, "width") )
{
if ( !strcmp(a2, "height") )
{
v3 = 1;
*a3 = *(_DWORD *)(a1 + 12);
}
else
{
v3 = 0;
if ( !strcmp(a2, "quality") )
{
v3 = 1;
*a3 = *(_DWORD *)(a1 + 16);
}
}
return v3;
}
*a3 = *(_DWORD *)(a1 + 8);
return 1LL;
}

original_code:
gboolean mimic_get_property(MimCtx *ctx, const gchar *name, gpointer data)
{
    if (!ctx->encoder_initialized && !ctx->decoder_initialized)
        return (0);
    if (ctx->encoder_initialized) {
        if (strcmp(name, "buffer_size") == 0) {
            *((gint *) data) = 16384;
            return (!(0));
        }
    } else {
        if (strcmp(name, "buffer_size") == 0) {
            *((gint *) data) = ctx->frame_width * ctx->frame_height * 3;
            return (!(0));
        }
    }
    if (strcmp(name, "width") == 0) {
        *((gint *) data) = ctx->frame_width;
        return (!(0));
    } else if (strcmp(name, "height") == 0) {
        *((gint *) data) = ctx->frame_height;
        return (!(0));
    } else if (strcmp(name, "quality") == 0) {
        *((gint *) data) = ctx->quality;
        return (!(0));
    }
    return (0);
}

canonical_original_code:
int mimic_get_property(struct _MimCtx *ctx, char *name, void *data)
{
    if (!ctx->encoder_initialized && !ctx->decoder_initialized)
        return (0);
    if (ctx->encoder_initialized) {
        if (strcmp(name, "buffer_size") == 0) {
            *((int *) data) = 16384;
            return (!(0));
        }
    } else {
        if (strcmp(name, "buffer_size") == 0) {
            *((int *) data) = ctx->frame_width * ctx->frame_height * 3;
            return (!(0));
        }
    }
    if (strcmp(name, "width") == 0) {
        *((int *) data) = ctx->frame_width;
        return (!(0));
    } else if (strcmp(name, "height") == 0) {
        *((int *) data) = ctx->frame_height;
        return (!(0));
    } else if (strcmp(name, "quality") == 0) {
        *((int *) data) = ctx->quality;
        return (!(0));
    }
    return (0);
}

variable_types:
name
char *

variable_types:
data
void *


decompiled_code:
__int64 __fastcall mimic_set_property(unsigned int *a1, const char *a2, unsigned int *a3)
{
__int64 result; // rax
bool v4; // zf
unsigned int v5; // edx

result = 0LL;
if ( *(_QWORD *)a1 )
{
result = *a1;
if ( (_DWORD)result )
{
v4 = strcmp(a2, "quality") == 0;
result = !v4;
if ( v4 )
{
v5 = *a3;
if ( v5 <= 0x2710 )
{
a1[4] = v5;
result = 1LL;
}
}
else
{
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1, const char *a2, unsigned int *a3)
{
__int64 result; // rax
bool v4; // zf
unsigned int v5; // edx

result = 0LL;
if ( *(_QWORD *)a1 )
{
result = *a1;
if ( (_DWORD)result )
{
v4 = strcmp(a2, "quality") == 0;
result = !v4;
if ( v4 )
{
v5 = *a3;
if ( v5 <= 0x2710 )
{
a1[4] = v5;
result = 1LL;
}
}
else
{
result = 0LL;
}
}
}
return result;
}

original_code:
gboolean mimic_set_property(MimCtx *ctx, const gchar *name, gpointer data)
{
    if (!ctx->encoder_initialized && !ctx->decoder_initialized)
        return (0);
    if (ctx->encoder_initialized) {
        if (strcmp(name, "quality") == 0) {
            gint new_quality = *((gint *) data);
            if (new_quality < 0 ||
                new_quality > 10000)
            {
                return (0);
            }
            ctx->quality = new_quality;
            return (!(0));
        }
    } else { }
    return (0);
}

canonical_original_code:
int mimic_set_property(struct _MimCtx *ctx, char *name, void *data)
{
    if (!ctx->encoder_initialized && !ctx->decoder_initialized)
        return (0);
    if (ctx->encoder_initialized) {
        if (strcmp(name, "quality") == 0) {
            int new_quality = *((gint *) data);
            if (new_quality < 0 ||
                new_quality > 10000)
            {
                return (0);
            }
            ctx->quality = new_quality;
            return (!(0));
        }
    } else { }
    return (0);
}


decompiled_code:
int __fastcall log_file_open(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
char *v8; // rbp
struct tm *v9; // rax
double v10; // xmm4_8
double v11; // xmm5_8
time_t timer; // [rsp+8h] [rbp-10h] BYREF

v8 = (char *)malloc(0x40uLL);
timer = time(0LL);
v9 = localtime(&timer);
sprintf(
v8,
"logs/nlpad-%.2d-%.2d-%.2d.log",
(unsigned int)v9->tm_mday,
(unsigned int)v9->tm_mon,
(unsigned int)v9->tm_year);
log_file = fopen(v8, "w");
return log_writef(0, "Nonlogic Pad Logging Started\n", a1, a2, a3, a4, v10, v11, a7, a8);
}

canonical_decompiled_code:
int __fastcall func1(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
char *v8; // rbp
struct tm *v9; // rax
double v10; // xmm4_8
double v11; // xmm5_8
time_t timer; // [rsp+8h] [rbp-10h] BYREF

v8 = (char *)malloc(0x40uLL);
timer = time(0LL);
v9 = localtime(&timer);
sprintf(
v8,
"logs/nlpad-%.2d-%.2d-%.2d.log",
(unsigned int)v9->tm_mday,
(unsigned int)v9->tm_mon,
(unsigned int)v9->tm_year);
log_file = fopen(v8, "w");
return func0(0, "Nonlogic Pad Logging Started\n", a1, a2, a3, a4, v10, v11, a7, a8);
}

original_code:
void log_file_open()
{
 char *filename = malloc(64);
 time_t current_time = time(((void *)0));
 struct tm *now = localtime(&current_time);
 sprintf(filename,"logs/nlpad-%.2d-%.2d-%.2d.log",now->tm_mday,now->tm_mon,now->tm_year);
 log_file = fopen(filename,"w");
 log_writef(0,"Nonlogic Pad Logging Started\n");
}

canonical_original_code:
void log_file_open()
{
 char *filename = malloc(64);
 long current_time = time(((void *)0));
 struct tm *now = localtime(&current_time);
 sprintf(filename,"logs/nlpad-%.2d-%.2d-%.2d.log",now->tm_mday,now->tm_mon,now->tm_year);
 log_file = fopen(filename,"w");
 log_writef(0,"Nonlogic Pad Logging Started\n");
}

variable_types:
filename
char *

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


decompiled_code:
int __fastcall log_file_close(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
log_writef(0, "Nonlogic Pad Logging Stopped\n", a1, a2, a3, a4, a5, a6, a7, a8);
return fclose(log_file);
}

canonical_decompiled_code:
int __fastcall func2(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
func0(0, "Nonlogic Pad Logging Stopped\n", a1, a2, a3, a4, a5, a6, a7, a8);
return fclose(log_file);
}

original_code:
void log_file_close()
{
 log_writef(0,"Nonlogic Pad Logging Stopped\n");
 fclose(log_file);
}


decompiled_code:
struct hostent *network_init()
{
socket(2, 1, 0);
return gethostbyname("localhost");
}

canonical_decompiled_code:
struct hostent *func0()
{
socket(2, 1, 0);
return gethostbyname("localhost");
}

original_code:
void network_init(short port)
{
 network_listen_sock = socket(2, SOCK_STREAM,0);
 struct sockaddr_in network_host;
 struct hostent *network_hent = gethostbyname("localhost");
 network_host.sin_family = 2;
 network_host.sin_port = htons(port);
}

variable_types: port short

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

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

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


decompiled_code:
__int64 __fastcall con_new(const char *a1)
{
struct hostent *v1; // rax
__int64 v2; // rdx
int v3; // eax
unsigned int v4; // er12
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

v1 = gethostbyname(a1);
if ( v1 )
{
v6.sa_family = 2;
*(_WORD *)v6.sa_data = _bswap_16_constprop_0(2LL, 1LL, v1);
v3 = ***(_DWORD ***)(v2 + 24);
*(_QWORD *)&v6.sa_data[6] = 0LL;
*(_DWORD *)&v6.sa_data[2] = v3;
v4 = socket(2, 1, 0);
if ( connect(v4, &v6, 0x10u) < 0 )
{
v4 = -1;
fprintf(stderr, "Failed to connect to %s.\n", a1);
}
}
else
{
v4 = -1;
fprintf(stderr, "Failed resolving %s - check network status\n", a1);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
struct hostent *v1; // rax
__int64 v2; // rdx
int v3; // eax
unsigned int v4; // er12
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

v1 = gethostbyname(a1);
if ( v1 )
{
v6.sa_family = 2;
*(_WORD *)v6.sa_data = func7(2LL, 1LL, v1);
v3 = ***(_DWORD ***)(v2 + 24);
*(_QWORD *)&v6.sa_data[6] = 0LL;
*(_DWORD *)&v6.sa_data[2] = v3;
v4 = socket(2, 1, 0);
if ( connect(v4, &v6, 0x10u) < 0 )
{
v4 = -1;
fprintf(stderr, "Failed to connect to %s.\n", a1);
}
}
else
{
v4 = -1;
fprintf(stderr, "Failed resolving %s - check network status\n", a1);
}
return v4;
}

original_code:
int con_new(char *host)
{
 struct hostent *host_resolv = gethostbyname(host);
 if(!host_resolv)
 {
  fprintf(stderr, "Failed resolving %s - check network status\n",host);
  return -1;
 }
 struct sockaddr_in g_addr;
 g_addr.sin_family = 2;
 g_addr.sin_port = htons(80);
 g_addr.sin_addr = *((struct in_addr*)host_resolv->h_addr_list[0]);
 memset(g_addr.sin_zero, '\0', 8);
 int sock = socket(2,SOCK_STREAM,0);
 if(connect(sock, (struct sockaddr*)&g_addr,sizeof(struct sockaddr))<0)
 {
  fprintf(stderr, "Failed to connect to %s.\n",host);
  return -1;
 }
 return sock;
}

canonical_original_code:
int con_new(char *host)
{
 struct hostent *host_resolv = gethostbyname(host);
 if(!host_resolv)
 {
  fprintf(stderr, "Failed resolving %s - check network status\n",host);
  return -1;
 }
 struct sockaddr_in g_addr;
 g_addr.sin_family = 2;
 g_addr.sin_port = htons(80);
 g_addr.sin_addr = *((struct in_addr *)host_resolv->h_addr_list[0]);
 memset(g_addr.sin_zero, '\0', 8);
 int sock = socket(2,SOCK_STREAM,0);
 if(connect(sock, (struct sockaddr *)&g_addr,sizeof(struct sockaddr))<0)
 {
  fprintf(stderr, "Failed to connect to %s.\n",host);
  return -1;
 }
 return sock;
}

variable_types:
host
char *

variable_types: sock int

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

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


decompiled_code:
size_t __fastcall con_send_data(int a1, const void *a2, int a3)
{
__int64 v3; // rbx
size_t result; // rax

v3 = a3;
result = send(a1, a2, a3, 0);
if ( result != v3 )
result = fwrite("Failed sending data - byte count mismatch\n", 1uLL, 0x2AuLL, stderr);
return result;
}

canonical_decompiled_code:
size_t __fastcall func9(int a1, const void *a2, int a3)
{
__int64 v3; // rbx
size_t result; // rax

v3 = a3;
result = send(a1, a2, a3, 0);
if ( result != v3 )
result = fwrite("Failed sending data - byte count mismatch\n", 1uLL, 0x2AuLL, stderr);
return result;
}

original_code:
void con_send_data(int con, void *data, int len)
{
 if(send(con,data,len,0)!=len)
 {
  fprintf(stderr,"Failed sending data - byte count mismatch\n");
 }
}

variable_types: con int

variable_types: len int


decompiled_code:
char *__fastcall con_recv_data(int fd)
{
int v1; // ebx
char *v2; // r12
void *v3; // rbp

v1 = 11;
v2 = (char *)malloc(0x8000uLL);
v3 = calloc(0x400uLL, 1uLL);
do
{
recv(fd, v3, 0x400uLL, 0);
sprintf(v2, "%s%s", v2, (const char *)v3);
memset(v3, 0, 0x400uLL);
--v1;
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
char *__fastcall func10(int fd)
{
int v1; // ebx
char *v2; // r12
void *v3; // rbp

v1 = 11;
v2 = (char *)malloc(0x8000uLL);
v3 = calloc(0x400uLL, 1uLL);
do
{
recv(fd, v3, 0x400uLL, 0);
sprintf(v2, "%s%s", v2, (const char *)v3);
memset(v3, 0, 0x400uLL);
--v1;
}
while ( v1 );
return v2;
}

original_code:
char *con_recv_data(int con)
{
 char *data = malloc(32768);
 char *chunk = malloc(1024);
 int chunks = 0;
 memset(chunk,'\0', 1024);
 while(chunks<11)
 {
  recv(con,chunk,1024,0);
  sprintf(data,"%s%s",data,chunk);
  chunks++;
  memset(chunk,'\0',1024);
 }
 return data;
}

variable_types:
data
char *

variable_types:
chunk
char *

variable_types: chunks int

return_type: char *


decompiled_code:
__int64 __fastcall parse_check_char(char a1)
{
return (unsigned __int8)(a1 - 65) < 0x3Au ? 1 : 3;
}

canonical_decompiled_code:
__int64 __fastcall func11(char a1)
{
return (unsigned __int8)(a1 - 65) < 0x3Au ? 1 : 3;
}

original_code:
static int parse_check_char(char letter)
{
 if(letter<'A' || letter >'z')
 {
  return 3;
 }
 return 1;
}

variable_types: letter char


decompiled_code:
char *__fastcall parse_query(char *s)
{
int v1; // ebx
size_t v2; // rax
char *v4; // rcx
char *v5; // rax
size_t v6; // rdx
size_t v7; // rbx
char *v8; // r12
const char *v9; // rdx
__int64 v10; // rcx

v1 = 10;
v2 = strlen(s);
v4 = &s[v2];
while ( s != v4 )
v1 += parse_check_char(*s);
v5 = (char *)malloc(v1 + 1);
v6 = v1;
v7 = 0LL;
v8 = v5;
memset(v5, 0, v6);
strcpy(v8, "/search?q=");
while ( strlen(s) > v7 )
{
if ( (unsigned int)parse_check_char(s[v7]) == 3 )
sprintf(v8, "%s%%%X", v9, v10);
else
sprintf(v8, "%s%c", v9, v10);
++v7;
}
return v8;
}

canonical_decompiled_code:
char *__fastcall func12(char *s)
{
int v1; // ebx
size_t v2; // rax
char *v4; // rcx
char *v5; // rax
size_t v6; // rdx
size_t v7; // rbx
char *v8; // r12
const char *v9; // rdx
__int64 v10; // rcx

v1 = 10;
v2 = strlen(s);
v4 = &s[v2];
while ( s != v4 )
v1 += func11(*s);
v5 = (char *)malloc(v1 + 1);
v6 = v1;
v7 = 0LL;
v8 = v5;
memset(v5, 0, v6);
strcpy(v8, "/search?q=");
while ( strlen(s) > v7 )
{
if ( (unsigned int)func11(s[v7]) == 3 )
sprintf(v8, "%s%%%X", v9, v10);
else
sprintf(v8, "%s%c", v9, v10);
++v7;
}
return v8;
}

original_code:
char *parse_query(char *query)
{
 char *result_str;
 int result_len = 10;
 int i = 0;
 for(;i<strlen(query);i++)
 {
  result_len += parse_check_char(query[i]);
 }
 result_str = malloc(result_len+1);
 memset(result_str, '\0', result_len);
 strcpy(result_str, "/search?q=");
 for(i=0;i<strlen(query);i++)
 {
  if(parse_check_char(query[i])==3)
   sprintf(result_str, "%s%%%X",result_str, query[i]);
  else
  sprintf(result_str, "%s%c",result_str, query[i]);
 }
 return result_str;
}

variable_types:
query
char *

variable_types: i int


decompiled_code:
char *__fastcall interp_google_count(const char *a1)
{
char *v1; // rax
const char *v2; // rbp

v1 = strstr(a1, " of about ");
if ( !v1 )
return strdup("None found");
v2 = v1 + 17;
*strstr(v1 + 17, "") = 0;
return strdup(v2);
}

canonical_decompiled_code:
char *__fastcall func13(const char *a1)
{
char *v1; // rax
const char *v2; // rbp

v1 = strstr(a1, " of about ");
if ( !v1 )
return strdup("None found");
v2 = v1 + 17;
*strstr(v1 + 17, "") = 0;
return strdup(v2);
}

original_code:
char *interp_google_count(char *html_data)
{
 char *result = ((void *)0);
 html_data = strstr(html_data," of about ");
 if(html_data == ((void *)0))
 {
  result = strdup("None found");
  return result;
 }
 html_data+=17;
 char *end_point = strstr(html_data, "");
 end_point[0] = '\0';
 result = strdup(html_data);
 return result;
}

variable_types:
result
char *


decompiled_code:
void *__fastcall http_create_request(const char *a1, const char *a2)
{
size_t v2; // r12
size_t v3; // r15
void *v4; // r12

v2 = strlen(a1);
v3 = v2 + strlen(a2) + 69;
v4 = malloc(v3);
memset(v4, 0, v3);
sprintf((char *)v4, "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Linux: X11:UTF-8)\r\n\r\n", a2, a1);
return v4;
}

canonical_decompiled_code:
void *__fastcall func14(const char *a1, const char *a2)
{
size_t v2; // r12
size_t v3; // r15
void *v4; // r12

v2 = strlen(a1);
v3 = v2 + strlen(a2) + 69;
v4 = malloc(v3);
memset(v4, 0, v3);
sprintf((char *)v4, "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Linux: X11:UTF-8)\r\n\r\n", a2, a1);
return v4;
}

original_code:
char *http_create_request(char *address, char *file)
{
 char *http_header = malloc(strlen(address)+strlen(file)+69);
 memset(http_header, '\0', strlen(address)+strlen(file)+69);
 sprintf(http_header,"GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Linux: X11:UTF-8)\r\n\r\n",file, address);
 return http_header;
}

variable_types:
address
char *

variable_types:
file
char *


decompiled_code:
void __fastcall fill_audio(__int64 a1, __int64 a2, unsigned int a3)
{
int v3; // ebx

v3 = audio_len;
if ( audio_len )
{
if ( a3 <= audio_len )
v3 = a3;
SDL_MixAudio(a2, audio_pos, (unsigned int)v3, 128LL);
audio_pos += v3;
if ( audio_len == v3 )
{
audio_len = 512;
audio_pos = audio_chunk;
}
else
{
audio_len -= v3;
}
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, __int64 a2, unsigned int a3)
{
int v3; // ebx

v3 = audio_len;
if ( audio_len )
{
if ( a3 <= audio_len )
v3 = a3;
SDL_MixAudio(a2, audio_pos, (unsigned int)v3, 128LL);
audio_pos += v3;
if ( audio_len == v3 )
{
audio_len = 512;
audio_pos = audio_chunk;
}
else
{
audio_len -= v3;
}
}
}

original_code:
static void fill_audio(void *udata, Uint8 *stream, int len)
{
 if (audio_len == 0)
 {
  return;
 }
    len = ( len > audio_len ? audio_len : len );
    SDL_MixAudio(stream, audio_pos, len, 128);
    audio_pos += len;
    audio_len -= len;
    if(audio_len == 0)
    {
     audio_len = 512;
     audio_pos = audio_chunk;
    }
}

canonical_original_code:
static void fill_audio(void *udata, unsigned char *stream, int len)
{
 if (audio_len == 0)
 {
  return;
 }
    len = ( len > audio_len ? audio_len : len );
    SDL_MixAudio(stream, audio_pos, len, 128);
    audio_pos += len;
    audio_len -= len;
    if(audio_len == 0)
    {
     audio_len = 512;
     audio_pos = audio_chunk;
    }
}

variable_types:
udata
void *

variable_types:
stream
unsigned char *


decompiled_code:
__int64 sound_init()
{
double v0; // xmm0_8
__int64 v1; // rbx
double v2; // xmm1_8
__int64 v3; // rbp
__int64 result; // rax
const char *v5; // rax
int v6; // [rsp+10h] [rbp-38h] BYREF
__int16 v7; // [rsp+14h] [rbp-34h]
char v8; // [rsp+16h] [rbp-32h]
__int16 v9; // [rsp+18h] [rbp-30h]
void (__fastcall *v10)(__int64, __int64, unsigned int); // [rsp+20h] [rbp-28h]
__int64 v11; // [rsp+28h] [rbp-20h]

SDL_Init(16LL);
v6 = 22050;
v7 = -32752;
v8 = 2;
v9 = 1024;
v10 = fill_audio;
v11 = 0LL;
if ( (int)SDL_OpenAudio(&v6, 0LL) < 0 )
{
v5 = (const char *)SDL_GetError();
fprintf(stderr, "Couldn't open audio: %s\n", v5);
}
v0 = 0.0;
audio_chunk = (__int64)malloc(0x400uLL);
v1 = audio_chunk;
v2 = 0.0;
v3 = audio_chunk + 512;
audio_pos = audio_chunk;
while ( 1 )
{
++v1;
v2 = v2 + 0.05711986642890533;
result = (unsigned int)(int)(v0 * 128.0);
*(_BYTE *)(v1 - 1) = result;
if ( v3 == v1 )
break;
v0 = sin(v2);
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
double v0; // xmm0_8
__int64 v1; // rbx
double v2; // xmm1_8
__int64 v3; // rbp
__int64 result; // rax
const char *v5; // rax
int v6; // [rsp+10h] [rbp-38h] BYREF
__int16 v7; // [rsp+14h] [rbp-34h]
char v8; // [rsp+16h] [rbp-32h]
__int16 v9; // [rsp+18h] [rbp-30h]
void (__fastcall *v10)(__int64, __int64, unsigned int); // [rsp+20h] [rbp-28h]
__int64 v11; // [rsp+28h] [rbp-20h]

SDL_Init(16LL);
v6 = 22050;
v7 = -32752;
v8 = 2;
v9 = 1024;
v10 = fill_audio;
v11 = 0LL;
if ( (int)SDL_OpenAudio(&v6, 0LL) < 0 )
{
v5 = (const char *)SDL_GetError();
fprintf(stderr, "Couldn't open audio: %s\n", v5);
}
v0 = 0.0;
audio_chunk = (__int64)malloc(0x400uLL);
v1 = audio_chunk;
v2 = 0.0;
v3 = audio_chunk + 512;
audio_pos = audio_chunk;
while ( 1 )
{
++v1;
v2 = v2 + 0.05711986642890533;
result = (unsigned int)(int)(v0 * 128.0);
*(_BYTE *)(v1 - 1) = result;
if ( v3 == v1 )
break;
v0 = sin(v2);
}
return result;
}

original_code:
void sound_init()
{
 SDL_Init(0x00000010);
 SDL_AudioSpec wanted;
    wanted.freq = 22050;
    wanted.format = 0x8010;
    wanted.channels = 2;
    wanted.samples = 1024;
    wanted.callback = fill_audio;
    wanted.userdata = ((void *)0);
    if ( SDL_OpenAudio(&wanted, ((void *)0)) < 0 ) {
        fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
    }
    audio_chunk = malloc(1024);
    audio_pos = audio_chunk;
    double it = 0.0;
    double inc = (3.14159265358979323846*8.0f)/440.0f;
    for(int i = 0; i < 512; i++)
    {
     audio_chunk[i] = sin(it)*128.0;
     it+=inc;
    }
}

canonical_original_code:
void sound_init()
{
 SDL_Init(0x00000010);
 struct SDL_AudioSpec wanted;
    wanted.freq = 22050;
    wanted.format = 0x8010;
    wanted.channels = 2;
    wanted.samples = 1024;
    wanted.callback = fill_audio;
    wanted.userdata = ((void *)0);
    if ( SDL_OpenAudio(&wanted, ((void *)0)) < 0 ) {
        fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
    }
    audio_chunk = malloc(1024);
    audio_pos = audio_chunk;
    double it = 0.0;
    double inc = (3.14159265358979323846*8.0f)/440.0f;
    for(int i = 0; i < 512; i++)
    {
     audio_chunk[i] = sin(it)*128.0;
     it+=inc;
    }
}

variable_types: struct SDL_AudioSpec { int freq; unsigned short format; unsigned char channels; unsigned char silence; unsigned short samples; unsigned short padding; unsigned int size; void (*callback)(void *userdata, unsigned char *stream, int len); void *userdata; }

variable_types: it double

variable_types: inc double


decompiled_code:
__int64 sound_start()
{
audio_len = 512;
return SDL_PauseAudio(0LL);
}

canonical_decompiled_code:
__int64 func2()
{
audio_len = 512;
return SDL_PauseAudio(0LL);
}

original_code:
void sound_start()
{
 audio_len = 512;
 SDL_PauseAudio(0);
}


decompiled_code:
__int64 sound_stop()
{
audio_len = 0;
return SDL_PauseAudio(1LL);
}

canonical_decompiled_code:
__int64 func3()
{
audio_len = 0;
return SDL_PauseAudio(1LL);
}

original_code:
void sound_stop()
{
 audio_len = 0;
 SDL_PauseAudio(1);
}


decompiled_code:
int __fastcall joy_open(const char *a1)
{
int v1; // eax
unsigned int v2; // eax
int result; // eax

v1 = open(a1, 0);
fd = v1;
if ( v1 < 0 )
{
fwrite("Failed openning joystick device\n", 1uLL, 0x20uLL, stderr);
exit(0);
}
v2 = fcntl(v1, 3, 0LL);
BYTE1(v2) |= 8u;
result = fcntl(fd, 4, v2);
if ( result )
{
fwrite("Failed to set nonblocking\n", 1uLL, 0x1AuLL, stderr);
exit(0);
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(const char *a1)
{
int v1; // eax
unsigned int v2; // eax
int result; // eax

v1 = open(a1, 0);
fd = v1;
if ( v1 < 0 )
{
fwrite("Failed openning joystick device\n", 1uLL, 0x20uLL, stderr);
exit(0);
}
v2 = fcntl(v1, 3, 0LL);
BYTE1(v2) |= 8u;
result = fcntl(fd, 4, v2);
if ( result )
{
fwrite("Failed to set nonblocking\n", 1uLL, 0x1AuLL, stderr);
exit(0);
}
return result;
}

original_code:
void joy_open(char *device)
{
 fd = open(device,00);
 if(fd<0)
 {
  fprintf(stderr, "Failed openning joystick device\n");
  exit(0);
 }
 int opts = fcntl(fd,3,0);
 opts |= 04000;
 if(fcntl(fd,4,opts)!=0)
 {
  fprintf(stderr, "Failed to set nonblocking\n");
  exit(0);
 }
}

variable_types:
device
char *

variable_types: opts int


decompiled_code:
int *joy_get_axis()
{
return joy_axis;
}

canonical_decompiled_code:
int *func12()
{
return joy_axis;
}

return_type: int *


decompiled_code:
int *joy_get_button()
{
return joy_button;
}

canonical_decompiled_code:
int *func13()
{
return joy_button;
}


decompiled_code:
void __fastcall __noreturn errno_exit(const char *a1)
{
int *v1; // rbx
char *v2; // rax

v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stderr, "%s error %d, %s\n", a1, (unsigned int)*v1, v2);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
int *v1; // rbx
char *v2; // rax

v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stderr, "%s error %d, %s\n", a1, (unsigned int)*v1, v2);
exit(1);
}

original_code:
static void errno_exit(const char *s)
{
  fprintf (stderr, "%s error %d, %s\n", s, (*__errno_location ()), strerror ((*__errno_location ())));
  exit (1);
}

canonical_original_code:
static void errno_exit(char *s)
{
  fprintf (stderr, "%s error %d, %s\n", s, (*__errno_location ()), strerror ((*__errno_location ())));
  exit (1);
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall camera_process_image(__int64 a1)
{
manip_decompress(320LL, 240LL, a1, uncompressed_src);
bayer2rgb24(rgb, uncompressed_src, 320LL, 240LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
manip_decompress(320LL, 240LL, a1, uncompressed_src);
bayer2rgb24(rgb, uncompressed_src, 320LL, 240LL);
return 1LL;
}

original_code:
gboolean camera_process_image(unsigned char *p)
{
 unsigned char *src = (unsigned char *) p;
 unsigned char *reader = src;
 manip_decompress(320, 240, src, uncompressed_src);
 reader = uncompressed_src;
 bayer2rgb24(rgb ,reader ,320, 240);
 return (!(0));
}

canonical_original_code:
int camera_process_image(unsigned char *p)
{
 unsigned char *src = (unsigned char *) p;
 unsigned char *reader = src;
 manip_decompress(320, 240, src, uncompressed_src);
 reader = uncompressed_src;
 bayer2rgb24(rgb ,reader ,320, 240);
 return (!(0));
}

variable_types:
p
unsigned char *

variable_types:
src
unsigned char *

variable_types:
reader
unsigned char *


decompiled_code:
__int64 camera_stop_capturing()
{
int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1[0] = 1;
if ( (unsigned int)xioctl(fd, 1074026003, (__int64)v1) == -1 )
errno_exit("VIDIOC_STREAMOFF");
return 1LL;
}

canonical_decompiled_code:
__int64 func5()
{
int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1[0] = 1;
if ( (unsigned int)func0(fd, 1074026003, (__int64)v1) == -1 )
func1("VIDIOC_STREAMOFF");
return 1LL;
}

original_code:
gboolean camera_stop_capturing(void)
{
  capturing = (0);
  enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  if (-1 == xioctl (fd, (((1U) << (((0 +8)+8)+14)) | ((('V')) << (0 +8)) | (((19)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &type))
    errno_exit ("VIDIOC_STREAMOFF");
  return (!(0));
}

canonical_original_code:
int camera_stop_capturing()
{
  capturing = (0);
  enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  if (-1 == xioctl (fd, (((1U) << (((0 +8)+8)+14)) | ((('V')) << (0 +8)) | (((19)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &type))
    errno_exit ("VIDIOC_STREAMOFF");
  return (!(0));
}

variable_types: enum v4l2_buf_type { V4L2_BUF_TYPE_VIDEO_CAPTURE=1, V4L2_BUF_TYPE_VIDEO_OUTPUT=2, V4L2_BUF_TYPE_VIDEO_OVERLAY=3, V4L2_BUF_TYPE_VBI_CAPTURE=4, V4L2_BUF_TYPE_VBI_OUTPUT=5, V4L2_BUF_TYPE_SLICED_VBI_CAPTURE=6, V4L2_BUF_TYPE_SLICED_VBI_OUTPUT=7, V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY=8, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE=9, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE=10, V4L2_BUF_TYPE_SDR_CAPTURE=11, V4L2_BUF_TYPE_SDR_OUTPUT=12, V4L2_BUF_TYPE_META_CAPTURE=13, V4L2_BUF_TYPE_PRIVATE=128 }


decompiled_code:
int camera_shutdown()
{
void *v0; // r12
char *v1; // rbx
char *v2; // rbp
int result; // eax

v0 = buffers;
if ( n_buffers )
{
v1 = (char *)buffers;
v2 = (char *)buffers + 16 * (unsigned int)(n_buffers - 1) + 16;
do
{
if ( munmap(*(void **)v1, *((_QWORD *)v1 + 1)) == -1 )
errno_exit("munmap");
v1 += 16;
}
while ( v2 != v1 );
}
free(v0);
free(rgb);
free(uncompressed_src);
result = close(fd);
if ( result == -1 )
errno_exit("close");
fd = -1;
return result;
}

canonical_decompiled_code:
int func7()
{
void *v0; // r12
char *v1; // rbx
char *v2; // rbp
int result; // eax

v0 = buffers;
if ( n_buffers )
{
v1 = (char *)buffers;
v2 = (char *)buffers + 16 * (unsigned int)(n_buffers - 1) + 16;
do
{
if ( munmap(*(void **)v1, *((_QWORD *)v1 + 1)) == -1 )
func1("munmap");
v1 += 16;
}
while ( v2 != v1 );
}
free(v0);
free(rgb);
free(uncompressed_src);
result = close(fd);
if ( result == -1 )
func1("close");
fd = -1;
return result;
}

original_code:
void camera_shutdown()
{
  unsigned int i;
  for (i = 0; i < n_buffers; ++i)
    if (-1 == munmap (buffers[i].start, buffers[i].length))
      errno_exit ("munmap");
  free (buffers);
  free(rgb);
  free(uncompressed_src);
  if (-1 == close (fd))
    errno_exit ("close");
  fd = -1;
}

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall camera_set_gain(double a1)
{
int v1; // eax
float v2; // xmm1_4

v1 = max_0;
v2 = *(float *)&a1;
if ( !max_0 )
{
v1 = controls_get_max_gain((unsigned int)fd, a1, a1);
v2 = *(float *)&a1;
max_0 = v1;
}
controls_set_gain((unsigned int)fd, (unsigned __int8)(int)(float)((float)v1 * v2));
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(double a1)
{
int v1; // eax
float v2; // xmm1_4

v1 = max_0;
v2 = *(float *)&a1;
if ( !max_0 )
{
v1 = controls_get_max_gain((unsigned int)fd, a1, a1);
v2 = *(float *)&a1;
max_0 = v1;
}
controls_set_gain((unsigned int)fd, (unsigned __int8)(int)(float)((float)v1 * v2));
return 1LL;
}

original_code:
gboolean camera_set_gain(float v)
{
 static int max = 0;
 if(max == 0)
  max = controls_get_max_gain(fd);
  gain = v;
  unsigned char val = (unsigned char)(max*v);
  controls_set_gain(fd, val);
  return (!(0));
}

canonical_original_code:
int camera_set_gain(float v)
{
 static int max = 0;
 if(max == 0)
  max = controls_get_max_gain(fd);
  gain = v;
  unsigned char val = (unsigned char)(max*v);
  controls_set_gain(fd, val);
  return (!(0));
}

variable_types: v float

variable_types: max int

variable_types:
val
unsigned char


xioctl

decompiled_code:
__int64 __fastcall xioctl(int fd, int a2, __int64 a3)
{
int i; // eax
unsigned int v5; // er12

for ( i = ioctl(fd, a2, a3); ; i = ioctl(fd, a2, a3) )
{
v5 = i;
if ( i != -1 || *_errno_location() != 4 )
break;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, int a2, __int64 a3)
{
int i; // eax
unsigned int v5; // er12

for ( i = ioctl(fd, a2, a3); ; i = ioctl(fd, a2, a3) )
{
v5 = i;
if ( i != -1 || *_errno_location() != 4 )
break;
}
return v5;
}

original_code:
static int xioctl
(
  int fd,
  int request,
  void *arg
)
{
  int r;
  do
  {
    r = ioctl (fd, request, arg);
  } while (-1 == r && 4 == (*__errno_location ()));
  return r;
}

canonical_original_code:
static int xioctl(int fd, int request, void *arg)
{
  int r;
  do
  {
    r = ioctl (fd, request, arg);
  } while (-1 == r && 4 == (*__errno_location ()));
  return r;
}

variable_types: fd int

variable_types: request int

variable_types:
arg
void *

variable_types: r int


decompiled_code:
__int64 gfx_cls()
{
__int64 v0; // rcx
__int64 result; // rax
__int64 v2; // rdi

SDL_FillRect(screen, 0LL, 0LL);
v0 = screenBuffer;
result = 0LL;
v2 = screenBuffer + 8;
*(_QWORD *)screenBuffer = 0LL;
*(_QWORD *)(v0 + 2040) = 0LL;
memset(
(void *)(v2 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)v0 - (v2 & 0xFFFFFFF8) + 2048) >> 3));
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rcx
__int64 result; // rax
__int64 v2; // rdi

SDL_FillRect(screen, 0LL, 0LL);
v0 = screenBuffer;
result = 0LL;
v2 = screenBuffer + 8;
*(_QWORD *)screenBuffer = 0LL;
*(_QWORD *)(v0 + 2040) = 0LL;
memset(
(void *)(v2 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)v0 - (v2 & 0xFFFFFFF8) + 2048) >> 3));
return result;
}

original_code:
void gfx_cls()
{
 SDL_FillRect(screen, ((void *)0), 0);
 memset(screenBuffer, 0, 64*32);
}


decompiled_code:
__int64 gfx_init()
{
SDL_Init(32LL);
screen = SDL_SetVideoMode(640LL, 320LL, 24LL, 0LL);
screenBuffer = (__int64)malloc(0x800uLL);
return gfx_cls();
}

canonical_decompiled_code:
__int64 func1()
{
SDL_Init(32LL);
screen = SDL_SetVideoMode(640LL, 320LL, 24LL, 0LL);
screenBuffer = (__int64)malloc(0x800uLL);
return func0();
}

original_code:
void gfx_init()
{
 SDL_Init(0x00000020);
 screen = SDL_SetVideoMode(640, 320, 24, 0x00000000);
 screenBuffer = malloc(64*32);
 gfx_cls();
}


decompiled_code:
__int64 __fastcall gfx_get_pixel(int a1, int a2)
{
return *(unsigned __int8 *)(screenBuffer + a1 + (a2 << 6));
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
return *(unsigned __int8 *)(screenBuffer + a1 + (a2 << 6));
}

original_code:
int gfx_get_pixel(int x, int y)
{
 return screenBuffer[y*64 + x];
}

variable_types: x int

variable_types: y int


decompiled_code:
_BOOL8 __fastcall gfx_draw_pixel_on(char a1, char a2)
{
int v2; // edi
int v3; // eax
int v4; // edx

v2 = a1 & 0x3F;
v3 = gfx_get_pixel(v2, a2 & 0x1F);
*(_BYTE *)(screenBuffer + v2 + (v4 << 6)) = v3 == 0;
return v3 != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(char a1, char a2)
{
int v2; // edi
int v3; // eax
int v4; // edx

v2 = a1 & 0x3F;
v3 = func2(v2, a2 & 0x1F);
*(_BYTE *)(screenBuffer + v2 + (v4 << 6)) = v3 == 0;
return v3 != 0;
}

original_code:
int gfx_draw_pixel_on(int x, int y)
{
 int colour = 1;
 x &= 63;
 y &= 31;
 if(gfx_get_pixel(x, y))
 {
  colour = 0;
 }
 screenBuffer[y*64 + x] = colour;
 return colour != 1;
}

variable_types: colour int


original_code:
int gfx_draw(int x, int y, unsigned char *mem, int count)
{
 int shouldFlip = 0;
 for(int j = 0; j < count; j++)
 {
  unsigned char byte = mem[j];
  for(int i = 0; i < 8; i++)
  {
   int pixelOn = byte & (1 << (8-(i+1)));
   if(pixelOn)
   {
    shouldFlip |= gfx_draw_pixel_on(x+i, y + j);
   }
  }
 }
 return shouldFlip;
}

variable_types:
mem
unsigned char *

variable_types: count int

variable_types: shouldFlip int

variable_types: j int

variable_types:
byte
unsigned char

variable_types: i int

variable_types: pixelOn int


original_code:
void gfx_flip()
{
 SDL_Rect brush = { 0, 0, 10, 10 };
 for(int y = 0; y < 32; y++)
 {
  for(int x = 0; x < 64; x++)
  {
   brush.x = x*10;
   brush.y = y*10;
   SDL_FillRect(screen, &brush, screenBuffer[y*64 + x] * 0xffffffff);
  }
 }
 SDL_Flip(screen);
}

canonical_original_code:
void gfx_flip()
{
 struct SDL_Rect brush = { 0, 0, 10, 10 };
 for(int y = 0; y < 32; y++)
 {
  for(int x = 0; x < 64; x++)
  {
   brush.x = x*10;
   brush.y = y*10;
   SDL_FillRect(screen, &brush, screenBuffer[y*64 + x] * 0xffffffff);
  }
 }
 SDL_Flip(screen);
}

variable_types: struct SDL_Rect { short x; unsigned short w; }


decompiled_code:
void asm_var_list_clear()
{
variable_list = 0LL;
mem_offset = 0;
}

canonical_decompiled_code:
void func0()
{
variable_list = 0LL;
mem_offset = 0;
}

original_code:
static void asm_var_list_clear()
{
 variable_list = ((void *)0);
 mem_offset = 0;
}


decompiled_code:
__int16 __fastcall asm_lookup_reg(char *s1, _DWORD *a2)
{
__int16 result; // ax

if ( !strcasecmp(s1, "ax") )
return word_52CE;
if ( !strcasecmp(s1, "bx") )
return word_52CC;
if ( !strcasecmp(s1, "cx") )
return word_52CA;
if ( !strcasecmp(s1, "dx") )
return word_52C8;
if ( !strcasecmp(s1, "ah") )
return SHIBYTE(word_52CE);
if ( !strcasecmp(s1, "bh") )
return SHIBYTE(word_52CC);
if ( !strcasecmp(s1, "ch") )
return SHIBYTE(word_52CA);
if ( !strcasecmp(s1, "dh") )
return SHIBYTE(word_52C8);
if ( !strcasecmp(s1, "al") )
return (unsigned __int8)word_52CE;
if ( !strcasecmp(s1, "bl") )
return (unsigned __int8)word_52CC;
if ( !strcasecmp(s1, "cl") )
return (unsigned __int8)word_52CA;
if ( !strcasecmp(s1, "dl") )
return (unsigned __int8)word_52C8;
result = 0;
if ( a2 )
*a2 = 1;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func1(char *s1, _DWORD *a2)
{
__int16 result; // ax

if ( !strcasecmp(s1, "ax") )
return word_52CE;
if ( !strcasecmp(s1, "bx") )
return word_52CC;
if ( !strcasecmp(s1, "cx") )
return word_52CA;
if ( !strcasecmp(s1, "dx") )
return word_52C8;
if ( !strcasecmp(s1, "ah") )
return SHIBYTE(word_52CE);
if ( !strcasecmp(s1, "bh") )
return SHIBYTE(word_52CC);
if ( !strcasecmp(s1, "ch") )
return SHIBYTE(word_52CA);
if ( !strcasecmp(s1, "dh") )
return SHIBYTE(word_52C8);
if ( !strcasecmp(s1, "al") )
return (unsigned __int8)word_52CE;
if ( !strcasecmp(s1, "bl") )
return (unsigned __int8)word_52CC;
if ( !strcasecmp(s1, "cl") )
return (unsigned __int8)word_52CA;
if ( !strcasecmp(s1, "dl") )
return (unsigned __int8)word_52C8;
result = 0;
if ( a2 )
*a2 = 1;
return result;
}

original_code:
static short asm_lookup_reg(char *name, int *not_found)
{
 if(strcasecmp(name,"ax")==0)
 {
  return ax;
 }
 if(strcasecmp(name,"bx")==0)
 {
  return bx;
 }
 if(strcasecmp(name,"cx")==0)
 {
  return cx;
 }
 if(strcasecmp(name,"dx")==0)
 {
  return dx;
 }
 if(strcasecmp(name,"ah")==0)
 {
  return ax>>8;
 }
 if(strcasecmp(name,"bh")==0)
 {
  return bx>>8;
 }
 if(strcasecmp(name,"ch")==0)
 {
  return cx>>8;
 }
 if(strcasecmp(name,"dh")==0)
 {
  return dx>>8;
 }
 if(strcasecmp(name,"al")==0)
 {
  return ax&0xff;
 }
 if(strcasecmp(name,"bl")==0)
 {
  return bx&0xff;
 }
 if(strcasecmp(name,"cl")==0)
 {
  return cx&0xff;
 }
 if(strcasecmp(name,"dl")==0)
 {
  return dx&0xff;
 }
 if(not_found)
  *not_found = 1;
 return 0;
}

variable_types:
name
char *

return_type: short


decompiled_code:
__int64 __fastcall asm_convert_number(char *nptr, _DWORD *a2)
{
size_t v2; // rax
char v3; // bl
int v4; // er12
unsigned int v5; // er12
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v2 = strlen(nptr);
printf("End char is %c\n", (unsigned int)nptr[v2 - 1]);
v3 = nptr[strlen(nptr) - 1];
if ( isalpha(v3) )
{
if ( v3 == 98 )
{
v4 = 2;
}
else if ( v3 > 98 )
{
v4 = 10;
if ( v3 == 104 )
v4 = 16;
}
else
{
v4 = 2;
if ( v3 != 66 )
{
v4 = 10;
if ( v3 == 72 )
v4 = 16;
}
}
printf("Converting: %s to a number\n", nptr);
nptr[strlen(nptr)] = 0;
v5 = strtol(nptr, &endptr, v4);
if ( endptr == nptr )
{
fwrite("Failed parsing number\n", 1uLL, 0x16uLL, stderr);
*a2 = 1;
}
result = v5;
}
else if ( v3 == 36 )
{
*a2 = 1;
result = 0LL;
}
else
{
result = (unsigned int)atoi(nptr);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *nptr, _DWORD *a2)
{
size_t v2; // rax
char v3; // bl
int v4; // er12
unsigned int v5; // er12
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v2 = strlen(nptr);
printf("End char is %c\n", (unsigned int)nptr[v2 - 1]);
v3 = nptr[strlen(nptr) - 1];
if ( isalpha(v3) )
{
if ( v3 == 98 )
{
v4 = 2;
}
else if ( v3 > 98 )
{
v4 = 10;
if ( v3 == 104 )
v4 = 16;
}
else
{
v4 = 2;
if ( v3 != 66 )
{
v4 = 10;
if ( v3 == 72 )
v4 = 16;
}
}
printf("Converting: %s to a number\n", nptr);
nptr[strlen(nptr)] = 0;
v5 = strtol(nptr, &endptr, v4);
if ( endptr == nptr )
{
fwrite("Failed parsing number\n", 1uLL, 0x16uLL, stderr);
*a2 = 1;
}
result = v5;
}
else if ( v3 == 36 )
{
*a2 = 1;
result = 0LL;
}
else
{
result = (unsigned int)atoi(nptr);
}
return result;
}

original_code:
static short asm_convert_number(char *string, int *not_num)
{
 short return_val;
 printf("End char is %c\n",string[strlen(string)-1]);
 if(isalpha(string[strlen(string)-1]))
 {
  int base = 0;
  switch(string[strlen(string)-1])
  {
   case 'b':
   case 'B':
    base = 2;
    break;
   case 'h':
   case 'H':
    base = 16;
    break;
   default:
    base = 10;
    break;
  }
  printf("Converting: %s to a number\n",string);
  char *endptr;
  string[strlen(string)]='\0';
  return_val = strtol(string,&endptr,base);
  if(endptr==string)
  {
   fprintf(stderr, "Failed parsing number\n");
   *not_num = 1;
  }
 }
 else
 {
  if(string[strlen(string)-1]=='$')
  {
   *not_num = 1;
   return 0;
  }
  return_val = atoi(string);
 }
 return return_val;
}

variable_types:
string
char *

variable_types: base int

variable_types:
endptr
char *


decompiled_code:
void *__fastcall memory_add_var(char a1, __int64 a2, unsigned __int16 a3, const void *a4)
{
int v7; // er13
__int64 v8; // rbx
int v9; // eax
__int64 v10; // rdi
__int64 v11; // rax
int v12; // ebp
char *v13; // rdi
void *result; // rax
int v15; // eax
__int64 v16; // rdi
__int64 v17; // rcx
__int64 v18; // rax
size_t n; // [rsp+8h] [rbp-40h]

v7 = a3;
n = a3;
if ( variable_list )
{
v8 = (int)g_malloc0(8LL);
v9 = g_strdup(a2);
v10 = (unsigned int)mem_offset;
*(_WORD *)(v8 + 10) = a3;
*(_BYTE *)(v8 + 8) = a1;
*(_QWORD *)v8 = v9;
v11 = variable_list;
v12 = v10;
v13 = (char *)&memory + v10;
*(_QWORD *)(v8 + 16) = v13;
*(_DWORD *)(v8 + 24) = v12;
*(_QWORD *)(v8 + 32) = v11;
variable_list = v8;
}
else
{
variable_list = (int)g_malloc0(8LL);
v15 = g_strdup(a2);
v16 = (unsigned int)mem_offset;
v17 = v15;
v18 = variable_list;
*(_WORD *)(variable_list + 10) = a3;
v12 = v16;
v13 = (char *)&memory + v16;
*(_QWORD *)v18 = v17;
*(_BYTE *)(v18 + 8) = a1;
*(_QWORD *)(v18 + 16) = v13;
*(_DWORD *)(v18 + 24) = v12;
*(_QWORD *)(v18 + 32) = 0LL;
}
result = memcpy(v13, a4, n);
mem_offset = v7 + v12;
return result;
}

canonical_decompiled_code:
void *__fastcall func3(char a1, __int64 a2, unsigned __int16 a3, const void *a4)
{
int v7; // er13
__int64 v8; // rbx
int v9; // eax
__int64 v10; // rdi
__int64 v11; // rax
int v12; // ebp
char *v13; // rdi
void *result; // rax
int v15; // eax
__int64 v16; // rdi
__int64 v17; // rcx
__int64 v18; // rax
size_t n; // [rsp+8h] [rbp-40h]

v7 = a3;
n = a3;
if ( variable_list )
{
v8 = (int)g_malloc0(8LL);
v9 = g_strdup(a2);
v10 = (unsigned int)mem_offset;
*(_WORD *)(v8 + 10) = a3;
*(_BYTE *)(v8 + 8) = a1;
*(_QWORD *)v8 = v9;
v11 = variable_list;
v12 = v10;
v13 = (char *)&memory + v10;
*(_QWORD *)(v8 + 16) = v13;
*(_DWORD *)(v8 + 24) = v12;
*(_QWORD *)(v8 + 32) = v11;
variable_list = v8;
}
else
{
variable_list = (int)g_malloc0(8LL);
v15 = g_strdup(a2);
v16 = (unsigned int)mem_offset;
v17 = v15;
v18 = variable_list;
*(_WORD *)(variable_list + 10) = a3;
v12 = v16;
v13 = (char *)&memory + v16;
*(_QWORD *)v18 = v17;
*(_BYTE *)(v18 + 8) = a1;
*(_QWORD *)(v18 + 16) = v13;
*(_DWORD *)(v18 + 24) = v12;
*(_QWORD *)(v18 + 32) = 0LL;
}
result = memcpy(v13, a4, n);
mem_offset = v7 + v12;
return result;
}

original_code:
static void memory_add_var(char type, char *name, unsigned short size, void *data)
{
 if(variable_list == ((void *)0))
 {
  variable_list = (asm_var*)g_malloc0(sizeof(variable_list));
  variable_list->name = (char*)g_strdup(name);
  variable_list->type = type;
  variable_list->size = size;
  variable_list->ptr = (void*)(memory+mem_offset);
  variable_list->sptr = mem_offset;
  variable_list->next = 0;
  memcpy(memory+mem_offset,data,size);
  mem_offset+=size;
 }
 else
 {
  asm_var *tmp = (asm_var*)g_malloc0(sizeof(variable_list));
  tmp->name = (char*)g_strdup(name);
  tmp->type = type;
  tmp->size = size;
  tmp->ptr = (void*)(memory+mem_offset);
  tmp->sptr = mem_offset;
  tmp->next = variable_list;
  variable_list = tmp;
  memcpy(memory+mem_offset,data,size);
  mem_offset+=size;
 }
}

canonical_original_code:
static void memory_add_var(char type, char *name, unsigned short size, void *data)
{
 if(variable_list == ((void *)0))
 {
  variable_list = (struct asm_var *)g_malloc0(sizeof(variable_list));
  variable_list->name = (char *)g_strdup(name);
  variable_list->type = type;
  variable_list->size = size;
  variable_list->ptr = (void *)(memory+mem_offset);
  variable_list->sptr = mem_offset;
  variable_list->next = 0;
  memcpy(memory+mem_offset,data,size);
  mem_offset+=size;
 }
 else
 {
  struct asm_var *tmp = (asm_var*)g_malloc0(sizeof(variable_list));
  tmp->name = (char *)g_strdup(name);
  tmp->type = type;
  tmp->size = size;
  tmp->ptr = (void *)(memory+mem_offset);
  tmp->sptr = mem_offset;
  tmp->next = variable_list;
  variable_list = tmp;
  memcpy(memory+mem_offset,data,size);
  mem_offset+=size;
 }
}

variable_types: type char

variable_types:
size
unsigned short

variable_types:
data
void *

variable_types: struct asm_var { char *name; char type; unsigned short size; void *ptr; int sptr; void *next; } *


decompiled_code:
__int64 __fastcall asm_find_label(char *s2)
{
__int64 v1; // rbx
unsigned int v2; // er12
size_t v3; // rax

if ( prog_length )
{
v1 = 0LL;
while ( 1 )
{
while ( 1 )
{
v2 = v1;
printf("%s == %s?\n", *((const char **)prog + v1), s2);
v3 = strlen(s2);
if ( !strncmp(*((const char **)prog + v1), s2, v3) )
break;
if ( prog_length <= (unsigned int)++v1 )
goto LABEL_7;
}
puts("found the label!");
if ( *(_BYTE *)(*((_QWORD *)prog + v1) + strlen(s2)) == 58 )
break;
++v1;
puts("Didn't find the semi-colon :(");
if ( prog_length <= (unsigned int)v1 )
goto LABEL_7;
}
}
else
{
LABEL_7:
v2 = 1;
puts("Couldn't find loop!");
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s2)
{
__int64 v1; // rbx
unsigned int v2; // er12
size_t v3; // rax

if ( prog_length )
{
v1 = 0LL;
while ( 1 )
{
while ( 1 )
{
v2 = v1;
printf("%s == %s?\n", *((const char **)prog + v1), s2);
v3 = strlen(s2);
if ( !strncmp(*((const char **)prog + v1), s2, v3) )
break;
if ( prog_length <= (unsigned int)++v1 )
goto LABEL_7;
}
puts("found the label!");
if ( *(_BYTE *)(*((_QWORD *)prog + v1) + strlen(s2)) == 58 )
break;
++v1;
puts("Didn't find the semi-colon :(");
if ( prog_length <= (unsigned int)v1 )
goto LABEL_7;
}
}
else
{
LABEL_7:
v2 = 1;
puts("Couldn't find loop!");
}
return v2;
}

original_code:
static unsigned int asm_find_label(char *label)
{
 int i = 0;
 for(i = 0;i<prog_length;i++)
 {
  printf("%s == %s?\n",prog[i], label);
  if(strncmp(prog[i],label,strlen(label)) == 0)
  {
   printf("found the label!\n");
   if(prog[i][strlen(label)]==':')
   {
    return i;
   }
   printf("Didn't find the semi-colon :(\n");
  }
 }
 printf("Couldn't find loop!\n");
 return 1;
}

variable_types:
label
char *

return_type: unsigned int


decompiled_code:
__int64 asm_get_var_list()
{
return variable_list;
}

canonical_decompiled_code:
__int64 func6()
{
return variable_list;
}

original_code:
asm_var *asm_get_var_list(void)
{
 return variable_list;
}

canonical_original_code:
struct asm_var *asm_get_var_list()
{
 return variable_list;
}

return_type: struct asm_var { char *name; char type; unsigned short size; void *ptr; int sptr; void *next; } *


decompiled_code:
__int64 asm_reset_vm()
{
word_52CE = 0;
word_52CC = 0;
word_52CA = 0;
word_52C8 = 0;
word_52C6 = 0;
word_52C4 = 0;
word_52C2 = 0;
word_52C0 = -2;
pc = 0;
return gui_update();
}

original_code:
void asm_reset_vm(void)
{
 ax = 0;
 bx = 0;
 cx = 0;
 dx = 0;
 di = 0;
 bp = 0;
 si = 0;
 sp = 0xfffe;
 pc = 0;
 gui_update();
}

canonical_original_code:
void asm_reset_vm()
{
 ax = 0;
 bx = 0;
 cx = 0;
 dx = 0;
 di = 0;
 bp = 0;
 si = 0;
 sp = 0xfffe;
 pc = 0;
 gui_update();
}


decompiled_code:
void __fastcall asm_set_prog(char *a1, int a2)
{
void *v3; // r14
void **v4; // rbx
void **v5; // r12
void *v6; // rdi
__int64 i; // rbx
const char **v8; // r12
const char *v9; // rax
const char *v10; // rbp
size_t v11; // rax
const char *v12; // r12
size_t v13; // rax
const char *v14; // r12
size_t v15; // r15
size_t v16; // rax
char *v17; // r15
size_t v18; // rax
__int16 v19; // [rsp+Ah] [rbp-3Eh] BYREF
int v20[15]; // [rsp+Ch] [rbp-3Ch] BYREF

memset(&memory, 48, 0x4000uLL);
asm_var_list_clear();
v3 = prog;
if ( prog )
{
if ( prog_length )
{
v4 = (void **)prog;
v5 = (void **)((char *)prog + 8 * (unsigned int)(prog_length - 1) + 8);
do
{
v6 = *v4++;
free(v6);
}
while ( v4 != v5 );
}
free(v3);
}
prog = a1;
prog_length = a2;
if ( a2 )
{
for ( i = 0LL; ; i += 8LL )
{
printf("Examining %s\n", *(const char **)&a1[i]);
v8 = (const char **)((char *)prog + i);
v9 = asm_get_operand(*(const char **)((char *)prog + i));
v10 = v9;
if ( !strcmp(v9, "add")
|| !strcmp(v9, "sub")
|| !strcmp(v9, "inc")
|| !strcmp(v9, "dec")
|| !strcmp(v9, "mul")
|| !strcmp(v9, "div")
|| !strcmp(v9, "mov")
|| !strcmp(v9, "jmp")
|| !strcmp(v9, "hlt") )
{
printf("Op1: %s\n", v9);
}
else
{
v11 = strlen(v9);
v12 = *v8;
if ( v11 == strlen(v12) )
{
printf("Found a label? %s\n", v12);
}
else
{
printf("Found a possible variable :O! %s\n", v10);
v13 = strlen(v10);
v14 = asm_get_operand((const char *)(*(_QWORD *)((char *)prog + i) + v13 + 1));
printf("Type: %s\n", v14);
v15 = strlen(v10);
v16 = strlen(v14);
v17 = asm_get_operand((const char *)(*(_QWORD *)((char *)prog + i) + v15 + v16 + 1));
printf("Value: %s\n", v17);
v20[0] = 0;
if ( !strcasecmp(v14, "db") )
{
LOBYTE(v19) = 0;
LOBYTE(v19) = asm_convert_number(v17, v20);
printf("BVALUE: %d and NOTNUM: %d\n", (unsigned int)(char)v19, (unsigned int)v20[0]);
if ( v20[0] )
{
puts("Adding string");
v18 = strlen(v17);
if ( v17[v18 - 1] == 36 )
memory_add_var(0, (__int64)v10, v18 + 1, v17);
else
fwrite("8086 spec doesn't allow non dollar terminated strings!\n", 1uLL, 0x37uLL, stderr);
}
else
{
puts("Adding byte");
memory_add_var(0, (__int64)v10, 1u, &v19);
}
}
if ( !strcasecmp(v14, "dw") )
{
v19 = 0;
v19 = asm_convert_number(v17, v20);
if ( v20[0] )
fwrite("Unrecognized dw number\n", 1uLL, 0x17uLL, stderr);
memory_add_var(1, (__int64)v10, 2u, &v19);
}
}
}
if ( 8LL * (unsigned int)(a2 - 1) == i )
break;
a1 = (char *)prog;
}
}
}

canonical_decompiled_code:
void __fastcall func8(char *a1, int a2)
{
void *v3; // r14
void **v4; // rbx
void **v5; // r12
void *v6; // rdi
__int64 i; // rbx
const char **v8; // r12
const char *v9; // rax
const char *v10; // rbp
size_t v11; // rax
const char *v12; // r12
size_t v13; // rax
const char *v14; // r12
size_t v15; // r15
size_t v16; // rax
char *v17; // r15
size_t v18; // rax
__int16 v19; // [rsp+Ah] [rbp-3Eh] BYREF
int v20[15]; // [rsp+Ch] [rbp-3Ch] BYREF

memset(&memory, 48, 0x4000uLL);
func0();
v3 = prog;
if ( prog )
{
if ( prog_length )
{
v4 = (void **)prog;
v5 = (void **)((char *)prog + 8 * (unsigned int)(prog_length - 1) + 8);
do
{
v6 = *v4++;
free(v6);
}
while ( v4 != v5 );
}
free(v3);
}
prog = a1;
prog_length = a2;
if ( a2 )
{
for ( i = 0LL; ; i += 8LL )
{
printf("Examining %s\n", *(const char **)&a1[i]);
v8 = (const char **)((char *)prog + i);
v9 = asm_get_operand(*(const char **)((char *)prog + i));
v10 = v9;
if ( !strcmp(v9, "add")
|| !strcmp(v9, "sub")
|| !strcmp(v9, "inc")
|| !strcmp(v9, "dec")
|| !strcmp(v9, "mul")
|| !strcmp(v9, "div")
|| !strcmp(v9, "mov")
|| !strcmp(v9, "jmp")
|| !strcmp(v9, "hlt") )
{
printf("Op1: %s\n", v9);
}
else
{
v11 = strlen(v9);
v12 = *v8;
if ( v11 == strlen(v12) )
{
printf("Found a label? %s\n", v12);
}
else
{
printf("Found a possible variable :O! %s\n", v10);
v13 = strlen(v10);
v14 = asm_get_operand((const char *)(*(_QWORD *)((char *)prog + i) + v13 + 1));
printf("Type: %s\n", v14);
v15 = strlen(v10);
v16 = strlen(v14);
v17 = asm_get_operand((const char *)(*(_QWORD *)((char *)prog + i) + v15 + v16 + 1));
printf("Value: %s\n", v17);
v20[0] = 0;
if ( !strcasecmp(v14, "db") )
{
LOBYTE(v19) = 0;
LOBYTE(v19) = func2(v17, v20);
printf("BVALUE: %d and NOTNUM: %d\n", (unsigned int)(char)v19, (unsigned int)v20[0]);
if ( v20[0] )
{
puts("Adding string");
v18 = strlen(v17);
if ( v17[v18 - 1] == 36 )
func3(0, (__int64)v10, v18 + 1, v17);
else
fwrite("8086 spec doesn't allow non dollar terminated strings!\n", 1uLL, 0x37uLL, stderr);
}
else
{
puts("Adding byte");
func3(0, (__int64)v10, 1u, &v19);
}
}
if ( !strcasecmp(v14, "dw") )
{
v19 = 0;
v19 = func2(v17, v20);
if ( v20[0] )
fwrite("Unrecognized dw number\n", 1uLL, 0x17uLL, stderr);
func3(1, (__int64)v10, 2u, &v19);
}
}
}
if ( 8LL * (unsigned int)(a2 - 1) == i )
break;
a1 = (char *)prog;
}
}
}

original_code:
void asm_set_prog(char **aprog, unsigned int lines)
{
 memset(memory, '0', 16384);
 asm_var_list_clear();
 if(prog!=((void *)0))
 {
  int i;
  for(i = 0;i<prog_length;i++)
  {
   free(prog[i]);
  }
  free(prog);
 }
 prog = aprog;
 prog_length = lines;
 int i;
 for(i = 0;i<lines;i++)
 {
  printf("Examining %s\n",prog[i]);
  char *op1 = asm_get_operand(prog[i]);
  if(strcmp(op1,"add")==0)
  {
   printf("Op1: %s\n",op1);
  }
  else if(strcmp(op1,"sub")==0)
  {
   printf("Op1: %s\n",op1);
  }
  else if(strcmp(op1,"inc")==0)
  {
   printf("Op1: %s\n",op1);
  }
  else if(strcmp(op1,"dec")==0)
  {
   printf("Op1: %s\n",op1);
  }
  else if(strcmp(op1,"mul")==0)
  {
   printf("Op1: %s\n",op1);
  }
  else if(strcmp(op1,"div")==0)
  {
   printf("Op1: %s\n",op1);
  }
  else if(strcmp(op1,"mov")==0)
  {
   printf("Op1: %s\n",op1);
  }
  else if(strcmp(op1,"jmp")==0)
  {
   printf("Op1: %s\n",op1);
  }
  else if(strcmp(op1,"hlt")==0)
  {
   printf("Op1: %s\n",op1);
  }
  else if(strlen(op1)==strlen(prog[i]))
  {
   printf("Found a label? %s\n",prog[i]);
  }
  else
  {
   printf("Found a possible variable :O! %s\n",op1);
   char *type = asm_get_operand(prog[i]+strlen(op1)+1);
   printf("Type: %s\n",type);
   char *value = asm_get_operand(prog[i]+strlen(op1)+strlen(type)+1);
   printf("Value: %s\n",value);
   int not_num = 0;
   if(strcasecmp(type,"db")==0)
   {
    char bvalue = 0;
    bvalue = asm_convert_number(value, &not_num);
    printf("BVALUE: %d and NOTNUM: %d\n",bvalue, not_num);
    if(not_num)
    {
     printf("Adding string\n");
     if(value[strlen(value)-1]=='$')
      memory_add_var(0, op1, strlen(value)+1, value);
     else
      fprintf(stderr,"8086 spec doesn't allow non dollar terminated strings!\n");
    }
    else
    {
     printf("Adding byte\n");
     memory_add_var(0, op1, 1, &bvalue);
    }
   }
   if(strcasecmp(type,"dw")==0)
   {
    short wvalue = 0;
    wvalue = asm_convert_number(value, &not_num);
    if(not_num)
    {
     fprintf(stderr, "Unrecognized dw number\n");
    }
    memory_add_var(1, op1, 2, &wvalue);
   }
  }
 }
}

variable_types:
aprog
char **

variable_types:
lines
unsigned int

variable_types:
type
char *

variable_types:
value
char *

variable_types: bvalue char

variable_types: wvalue short


decompiled_code:
int __fastcall asm_set_reg(char *s1, __int16 a2)
{
char v2; // bl
__int16 v3; // ax
__int16 v4; // ax
__int16 v5; // ax
int result; // eax
__int16 v7; // si

v2 = a2;
printf("Setting %s to %d\n", s1, (unsigned int)a2);
if ( !strcasecmp(s1, "ax") )
word_52CE = a2;
if ( !strcasecmp(s1, "bx") )
word_52CC = a2;
if ( !strcasecmp(s1, "cx") )
word_52CA = a2;
if ( !strcasecmp(s1, "dx") )
word_52C8 = a2;
if ( !strcasecmp(s1, "ah") )
word_52CE = (a2 << 8) + (unsigned __int8)word_52CE;
if ( !strcasecmp(s1, "bh") )
word_52CC = (a2 << 8) + (unsigned __int8)word_52CC;
if ( !strcasecmp(s1, "ch") )
word_52CA = (a2 << 8) + (unsigned __int8)word_52CA;
if ( !strcasecmp(s1, "dh") )
word_52C8 = (a2 << 8) + (unsigned __int8)word_52C8;
if ( !strcasecmp(s1, "al") )
{
HIBYTE(v3) = HIBYTE(word_52CE);
LOBYTE(v3) = 0;
word_52CE = (char)a2 + v3;
}
if ( !strcasecmp(s1, "bl") )
{
HIBYTE(v4) = HIBYTE(word_52CC);
LOBYTE(v4) = 0;
word_52CC = (char)a2 + v4;
}
if ( !strcasecmp(s1, "cl") )
{
HIBYTE(v5) = HIBYTE(word_52CA);
LOBYTE(v5) = 0;
word_52CA = (char)a2 + v5;
}
result = strcasecmp(s1, "dl");
if ( !result )
{
HIBYTE(v7) = HIBYTE(word_52C8);
LOBYTE(v7) = 0;
word_52C8 = v7 + v2;
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(char *s1, __int16 a2)
{
char v2; // bl
__int16 v3; // ax
__int16 v4; // ax
__int16 v5; // ax
int result; // eax
__int16 v7; // si

v2 = a2;
printf("Setting %s to %d\n", s1, (unsigned int)a2);
if ( !strcasecmp(s1, "ax") )
word_52CE = a2;
if ( !strcasecmp(s1, "bx") )
word_52CC = a2;
if ( !strcasecmp(s1, "cx") )
word_52CA = a2;
if ( !strcasecmp(s1, "dx") )
word_52C8 = a2;
if ( !strcasecmp(s1, "ah") )
word_52CE = (a2 << 8) + (unsigned __int8)word_52CE;
if ( !strcasecmp(s1, "bh") )
word_52CC = (a2 << 8) + (unsigned __int8)word_52CC;
if ( !strcasecmp(s1, "ch") )
word_52CA = (a2 << 8) + (unsigned __int8)word_52CA;
if ( !strcasecmp(s1, "dh") )
word_52C8 = (a2 << 8) + (unsigned __int8)word_52C8;
if ( !strcasecmp(s1, "al") )
{
HIBYTE(v3) = HIBYTE(word_52CE);
LOBYTE(v3) = 0;
word_52CE = (char)a2 + v3;
}
if ( !strcasecmp(s1, "bl") )
{
HIBYTE(v4) = HIBYTE(word_52CC);
LOBYTE(v4) = 0;
word_52CC = (char)a2 + v4;
}
if ( !strcasecmp(s1, "cl") )
{
HIBYTE(v5) = HIBYTE(word_52CA);
LOBYTE(v5) = 0;
word_52CA = (char)a2 + v5;
}
result = strcasecmp(s1, "dl");
if ( !result )
{
HIBYTE(v7) = HIBYTE(word_52C8);
LOBYTE(v7) = 0;
word_52C8 = v7 + v2;
}
return result;
}

original_code:
void asm_set_reg(char *name, short data)
{
 printf("Setting %s to %d\n",name, data);
 if(strcasecmp(name,"ax")==0)
 {
  ax = data;
 }
 if(strcasecmp(name,"bx")==0)
 {
  bx = data;
 }
 if(strcasecmp(name,"cx")==0)
 {
  cx = data;
 }
 if(strcasecmp(name,"dx")==0)
 {
  dx = data;
 }
 if(strcasecmp(name,"ah")==0)
 {
  ax = ax&0x00ff;
  ax += ((char)data)<<8;
 }
 if(strcasecmp(name,"bh")==0)
 {
  bx = bx&0x00ff;
  bx += ((char)data)<<8;
 }
 if(strcasecmp(name,"ch")==0)
 {
  cx = cx&0x00ff;
  cx += ((char)data)<<8;
 }
 if(strcasecmp(name,"dh")==0)
 {
  dx = dx&0x00ff;
  dx += ((char)data)<<8;
 }
 if(strcasecmp(name,"al")==0)
 {
  ax = ax&0xff00;
  ax += ((char)data);
 }
 if(strcasecmp(name,"bl")==0)
 {
  bx = bx&0xff00;
  bx += ((char)data);
 }
 if(strcasecmp(name,"cl")==0)
 {
  cx = cx&0xff00;
  cx += ((char)data);
 }
 if(strcasecmp(name,"dl")==0)
 {
  dx = dx&0xff00;
  dx += ((char)data);
 }
}

variable_types: data short


decompiled_code:
__int64 asm_step()
{
unsigned __int8 **v0; // rbx
int v1; // eax
__int64 v2; // rdi
int v3; // edx
char *v4; // rbp
size_t v5; // rax
char *v6; // rax
char *v7; // r12
__int16 v8; // bx
__int16 v9; // ax
__int64 result; // rax
char *v11; // rbp
__int16 v12; // ax
char *v13; // rbp
size_t v14; // rax
char *v15; // rax
char *v16; // r12
__int16 v17; // bx
__int16 v18; // dx
char *v19; // rbp
__int16 v20; // ax
char *v21; // rbp
__int16 v22; // bx
__int16 v23; // si
char *v24; // rbp
unsigned __int16 v25; // bx
unsigned __int16 v26; // bp
char *v27; // rax
char *v28; // rbp
size_t v29; // rax
char *v30; // rax
char *v31; // r12
__int16 v32; // ax
__int16 v33; // si
__int16 v34; // bx
int v35; // [rsp+8h] [rbp-20h] BYREF
int v36[7]; // [rsp+Ch] [rbp-1Ch] BYREF

gui_update();
v0 = (unsigned __int8 **)((char *)prog + 8 * (unsigned int)pc);
v1 = pc;
v2 = (__int64)*v0;
v3 = **v0;
if ( v3 == 97 && *(_BYTE *)(v2 + 1) == 100 && *(_BYTE *)(v2 + 2) == 100 )
{
v4 = asm_get_operand((const char *)(v2 + 4));
v5 = strlen(v4);
v6 = asm_get_operand((const char *)&(*v0)[v5 + 4]);
v35 = 0;
v36[0] = 0;
v7 = v6;
v8 = asm_lookup_reg(v4, &v35);
if ( v35 )
{
fwrite("Couldn't find register to add to\n", 1uLL, 0x21uLL, stderr);
return 0xFFFFFFFFLL;
}
v9 = asm_lookup_reg(v7, &v35);
if ( v35 )
{
v9 = asm_convert_number(v7, v36);
if ( v36[0] )
goto LABEL_33;
}
asm_set_reg(v4, v8 + v9);
v1 = pc;
goto LABEL_7;
}
if ( v3 == 115 && *(_BYTE *)(v2 + 1) == 117 && *(_BYTE *)(v2 + 2) == 98 )
{
v13 = asm_get_operand((const char *)(v2 + 4));
v14 = strlen(v13);
v15 = asm_get_operand((const char *)&(*v0)[v14 + 4]);
v35 = 0;
v36[0] = 0;
v16 = v15;
v17 = asm_lookup_reg(v13, &v35);
if ( v35 )
{
fwrite("Couldn't find register to subtract from\n", 1uLL, 0x28uLL, stderr);
return 0xFFFFFFFFLL;
}
v18 = asm_lookup_reg(v16, &v35);
if ( v35 )
{
v18 = asm_convert_number(v16, v36);
if ( v36[0] )
{
LABEL_33:
fwrite("Second operand is not a numeric or variable value\n", 1uLL, 0x32uLL, stderr);
return 0xFFFFFFFFLL;
}
}
asm_set_reg(v13, v17 - v18);
v1 = pc;
goto LABEL_7;
}
if ( v3 == 105 && *(_BYTE *)(v2 + 1) == 110 && *(_BYTE *)(v2 + 2) == 99 )
{
v36[0] = 0;
v11 = asm_get_operand((const char *)(v2 + 4));
v12 = asm_lookup_reg(v11, v36);
if ( v36[0] )
{
fwrite("Failed to find register/variable to increment\n", 1uLL, 0x2EuLL, stderr);
return 0xFFFFFFFFLL;
}
asm_set_reg(v11, v12 + 1);
v1 = pc;
goto LABEL_7;
}
if ( v3 == 100 && *(_BYTE *)(v2 + 1) == 101 && *(_BYTE *)(v2 + 2) == 99 )
{
v36[0] = 0;
v19 = asm_get_operand((const char *)(v2 + 4));
v20 = asm_lookup_reg(v19, v36);
if ( v36[0] )
{
fwrite("Failed to find register/variable to decrement\n", 1uLL, 0x2EuLL, stderr);
return 0xFFFFFFFFLL;
}
asm_set_reg(v19, v20 - 1);
v1 = pc;
goto LABEL_7;
}
if ( v3 != 109 )
{
LABEL_35:
if ( v3 == 100 && *(_BYTE *)(v2 + 1) == 105 && *(_BYTE *)(v2 + 2) == 118 )
{
v36[0] = 0;
v24 = asm_get_operand((const char *)(v2 + 4));
v25 = asm_lookup_reg("ax", 0LL);
v26 = asm_lookup_reg(v24, v36);
if ( v36[0] )
fwrite("Failed to find register to divide by\n", 1uLL, 0x25uLL, stderr);
asm_set_reg("al", v25 / v26);
asm_set_reg("ah", v25 % v26);
v1 = pc;
}
else if ( v3 == 106 && *(_BYTE *)(v2 + 1) == 109 && *(_BYTE *)(v2 + 2) == 112
|| v3 == 105 && *(_BYTE *)(v2 + 1) == 110 && *(_BYTE *)(v2 + 2) == 116 )
{
v27 = asm_get_operand((const char *)(v2 + 4));
v1 = asm_find_label(v27);
}
else if ( v3 == 104 && *(_BYTE *)(v2 + 1) == 108 && *(_BYTE *)(v2 + 2) == 116 )
{
pc = 0;
return 0xFFFFFFFFLL;
}
goto LABEL_7;
}
if ( *(_BYTE *)(v2 + 1) != 111 || *(_BYTE *)(v2 + 2) != 118 )
{
if ( *(_BYTE *)(v2 + 1) == 117 && *(_BYTE *)(v2 + 2) == 108 )
{
v36[0] = 0;
v21 = asm_get_operand((const char *)(v2 + 4));
v22 = asm_lookup_reg("al", 0LL);
v23 = asm_lookup_reg(v21, v36);
if ( v36[0] )
{
fwrite("Failed to find register to multiply by\n", 1uLL, 0x27uLL, stderr);
return 0xFFFFFFFFLL;
}
asm_set_reg("ax", v23 * v22);
v1 = pc;
goto LABEL_7;
}
goto LABEL_35;
}
v28 = asm_get_operand((const char *)(v2 + 4));
v29 = strlen(v28);
v30 = asm_get_operand((const char *)&(*v0)[v29 + 4]);
v35 = 0;
v31 = v30;
if ( !isalpha(*v30) || (v34 = asm_lookup_reg(v31, &v35), !isalpha(*v31)) || (v33 = v34, v35) )
{
v36[0] = 0;
v32 = asm_convert_number(v31, v36);
if ( v36[0] )
{
fwrite("Failed to find a value to move into register\n", 1uLL, 0x2DuLL, stderr);
return 0xFFFFFFFFLL;
}
v33 = v32;
}
asm_set_reg(v28, v33);
v1 = pc;
LABEL_7:
result = (unsigned int)(v1 + 1);
pc = result;
if ( (unsigned int)result >= prog_length )
{
puts("Shouldn't of got this far!");
return 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
unsigned __int8 **v0; // rbx
int v1; // eax
__int64 v2; // rdi
int v3; // edx
char *v4; // rbp
size_t v5; // rax
char *v6; // rax
char *v7; // r12
__int16 v8; // bx
__int16 v9; // ax
__int64 result; // rax
char *v11; // rbp
__int16 v12; // ax
char *v13; // rbp
size_t v14; // rax
char *v15; // rax
char *v16; // r12
__int16 v17; // bx
__int16 v18; // dx
char *v19; // rbp
__int16 v20; // ax
char *v21; // rbp
__int16 v22; // bx
__int16 v23; // si
char *v24; // rbp
unsigned __int16 v25; // bx
unsigned __int16 v26; // bp
char *v27; // rax
char *v28; // rbp
size_t v29; // rax
char *v30; // rax
char *v31; // r12
__int16 v32; // ax
__int16 v33; // si
__int16 v34; // bx
int v35; // [rsp+8h] [rbp-20h] BYREF
int v36[7]; // [rsp+Ch] [rbp-1Ch] BYREF

gui_update();
v0 = (unsigned __int8 **)((char *)prog + 8 * (unsigned int)pc);
v1 = pc;
v2 = (__int64)*v0;
v3 = **v0;
if ( v3 == 97 && *(_BYTE *)(v2 + 1) == 100 && *(_BYTE *)(v2 + 2) == 100 )
{
v4 = asm_get_operand((const char *)(v2 + 4));
v5 = strlen(v4);
v6 = asm_get_operand((const char *)&(*v0)[v5 + 4]);
v35 = 0;
v36[0] = 0;
v7 = v6;
v8 = func1(v4, &v35);
if ( v35 )
{
fwrite("Couldn't find register to add to\n", 1uLL, 0x21uLL, stderr);
return 0xFFFFFFFFLL;
}
v9 = func1(v7, &v35);
if ( v35 )
{
v9 = func2(v7, v36);
if ( v36[0] )
goto LABEL_33;
}
func9(v4, v8 + v9);
v1 = pc;
goto LABEL_7;
}
if ( v3 == 115 && *(_BYTE *)(v2 + 1) == 117 && *(_BYTE *)(v2 + 2) == 98 )
{
v13 = asm_get_operand((const char *)(v2 + 4));
v14 = strlen(v13);
v15 = asm_get_operand((const char *)&(*v0)[v14 + 4]);
v35 = 0;
v36[0] = 0;
v16 = v15;
v17 = func1(v13, &v35);
if ( v35 )
{
fwrite("Couldn't find register to subtract from\n", 1uLL, 0x28uLL, stderr);
return 0xFFFFFFFFLL;
}
v18 = func1(v16, &v35);
if ( v35 )
{
v18 = func2(v16, v36);
if ( v36[0] )
{
LABEL_33:
fwrite("Second operand is not a numeric or variable value\n", 1uLL, 0x32uLL, stderr);
return 0xFFFFFFFFLL;
}
}
func9(v13, v17 - v18);
v1 = pc;
goto LABEL_7;
}
if ( v3 == 105 && *(_BYTE *)(v2 + 1) == 110 && *(_BYTE *)(v2 + 2) == 99 )
{
v36[0] = 0;
v11 = asm_get_operand((const char *)(v2 + 4));
v12 = func1(v11, v36);
if ( v36[0] )
{
fwrite("Failed to find register/variable to increment\n", 1uLL, 0x2EuLL, stderr);
return 0xFFFFFFFFLL;
}
func9(v11, v12 + 1);
v1 = pc;
goto LABEL_7;
}
if ( v3 == 100 && *(_BYTE *)(v2 + 1) == 101 && *(_BYTE *)(v2 + 2) == 99 )
{
v36[0] = 0;
v19 = asm_get_operand((const char *)(v2 + 4));
v20 = func1(v19, v36);
if ( v36[0] )
{
fwrite("Failed to find register/variable to decrement\n", 1uLL, 0x2EuLL, stderr);
return 0xFFFFFFFFLL;
}
func9(v19, v20 - 1);
v1 = pc;
goto LABEL_7;
}
if ( v3 != 109 )
{
LABEL_35:
if ( v3 == 100 && *(_BYTE *)(v2 + 1) == 105 && *(_BYTE *)(v2 + 2) == 118 )
{
v36[0] = 0;
v24 = asm_get_operand((const char *)(v2 + 4));
v25 = func1("ax", 0LL);
v26 = func1(v24, v36);
if ( v36[0] )
fwrite("Failed to find register to divide by\n", 1uLL, 0x25uLL, stderr);
func9("al", v25 / v26);
func9("ah", v25 % v26);
v1 = pc;
}
else if ( v3 == 106 && *(_BYTE *)(v2 + 1) == 109 && *(_BYTE *)(v2 + 2) == 112
|| v3 == 105 && *(_BYTE *)(v2 + 1) == 110 && *(_BYTE *)(v2 + 2) == 116 )
{
v27 = asm_get_operand((const char *)(v2 + 4));
v1 = func4(v27);
}
else if ( v3 == 104 && *(_BYTE *)(v2 + 1) == 108 && *(_BYTE *)(v2 + 2) == 116 )
{
pc = 0;
return 0xFFFFFFFFLL;
}
goto LABEL_7;
}
if ( *(_BYTE *)(v2 + 1) != 111 || *(_BYTE *)(v2 + 2) != 118 )
{
if ( *(_BYTE *)(v2 + 1) == 117 && *(_BYTE *)(v2 + 2) == 108 )
{
v36[0] = 0;
v21 = asm_get_operand((const char *)(v2 + 4));
v22 = func1("al", 0LL);
v23 = func1(v21, v36);
if ( v36[0] )
{
fwrite("Failed to find register to multiply by\n", 1uLL, 0x27uLL, stderr);
return 0xFFFFFFFFLL;
}
func9("ax", v23 * v22);
v1 = pc;
goto LABEL_7;
}
goto LABEL_35;
}
v28 = asm_get_operand((const char *)(v2 + 4));
v29 = strlen(v28);
v30 = asm_get_operand((const char *)&(*v0)[v29 + 4]);
v35 = 0;
v31 = v30;
if ( !isalpha(*v30) || (v34 = func1(v31, &v35), !isalpha(*v31)) || (v33 = v34, v35) )
{
v36[0] = 0;
v32 = func2(v31, v36);
if ( v36[0] )
{
fwrite("Failed to find a value to move into register\n", 1uLL, 0x2DuLL, stderr);
return 0xFFFFFFFFLL;
}
v33 = v32;
}
func9(v28, v33);
v1 = pc;
LABEL_7:
result = (unsigned int)(v1 + 1);
pc = result;
if ( (unsigned int)result >= prog_length )
{
puts("Shouldn't of got this far!");
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
int asm_step()
{
 gui_update();
 if(strncmp(prog[pc],"add",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  char *op2 = asm_get_operand(((prog[pc])+4)+strlen(op1));
  int not_found = 0, not_number = 0;
  short cval = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Couldn't find register to add to\n");
   return -1;
  }
  short cval2 = asm_lookup_reg(op2, &not_found);
  if(not_found)
  {
   cval2 = asm_convert_number(op2,&not_number);
   if(not_number)
   {
    fprintf(stderr, "Second operand is not a numeric or variable value\n");
    return -1;
   }
  }
  cval += cval2;
  asm_set_reg(op1, cval);
 }
 else if(strncmp(prog[pc],"sub",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  char *op2 = asm_get_operand(((prog[pc])+4)+strlen(op1));
  int not_found = 0, not_number = 0;
  short cval = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Couldn't find register to subtract from\n");
   return -1;
  }
  short cval2 = asm_lookup_reg(op2, &not_found);
  if(not_found)
  {
   cval2 = asm_convert_number(op2,&not_number);
   if(not_number)
   {
    fprintf(stderr, "Second operand is not a numeric or variable value\n");
    return -1;
   }
  }
  cval -= cval2;
  asm_set_reg(op1, cval);
 }
 else if(strncmp(prog[pc],"inc",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int not_found = 0;
  short cval = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Failed to find register/variable to increment\n");
   return -1;
  }
  cval++;
  asm_set_reg(op1, cval);
 }
 else if(strncmp(prog[pc],"dec",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int not_found = 0;
  short cval = asm_lookup_reg(op1, &not_found);
  if(not_found)
  {
   fprintf(stderr, "Failed to find register/variable to decrement\n");
   return -1;
  }
  cval--;
  asm_set_reg(op1, cval);
 }
 else if(strncmp(prog[pc],"mov",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  char *op2 = asm_get_operand(((prog[pc])+4)+strlen(op1));
  int data = 0;
  int not_found = 0;
  if(isalpha(op2[0]))
  {
   data = asm_lookup_reg(op2,&not_found);
  }
  if(!isalpha(op2[0])||not_found)
  {
   int not_number = 0;
   data = asm_convert_number(op2, &not_number);
   if(not_number)
   {
    fprintf(stderr, "Failed to find a value to move into register\n");
    return -1;
   }
  }
  asm_set_reg(op1, data);
 }
 else if(strncmp(prog[pc],"mul",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int not_found = 0;
  unsigned short val = asm_lookup_reg("al",((void *)0));
  unsigned short val2 = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Failed to find register to multiply by\n");
   return -1;
  }
  asm_set_reg("ax",val*val2);
 }
 else if(strncmp(prog[pc],"div",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int not_found = 0;
  unsigned short val = asm_lookup_reg("ax",((void *)0));
  unsigned short val2 = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Failed to find register to divide by\n");
  }
  asm_set_reg("al",val/val2);
  asm_set_reg("ah",val%val2);
 }
 else if(strncmp(prog[pc],"jmp",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  pc = asm_find_label(op1);
 }
 else if(strncmp(prog[pc],"int",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int int_num = atoi(op1);
  pc = asm_find_label(op1);
 }
 else if(strncmp(prog[pc],"hlt",3)==0)
 {
  pc = 0;
  return -1;
 }
 pc++;
 if(pc>=prog_length)
 {
  printf("Shouldn't of got this far!\n");
  return -1;
 }
 return pc;
}

canonical_original_code:
int asm_step()
{
 gui_update();
 if(strncmp(prog[pc],"add",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  char *op2 = asm_get_operand(((prog[pc])+4)+strlen(op1));
  int not_found = 0; int not_number = 0;
  short cval = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Couldn't find register to add to\n");
   return -1;
  }
  short cval2 = asm_lookup_reg(op2, &not_found);
  if(not_found)
  {
   cval2 = asm_convert_number(op2,&not_number);
   if(not_number)
   {
    fprintf(stderr, "Second operand is not a numeric or variable value\n");
    return -1;
   }
  }
  cval += cval2;
  asm_set_reg(op1, cval);
 }
 else if(strncmp(prog[pc],"sub",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  char *op2 = asm_get_operand(((prog[pc])+4)+strlen(op1));
  int not_found = 0; int not_number = 0;
  short cval = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Couldn't find register to subtract from\n");
   return -1;
  }
  short cval2 = asm_lookup_reg(op2, &not_found);
  if(not_found)
  {
   cval2 = asm_convert_number(op2,&not_number);
   if(not_number)
   {
    fprintf(stderr, "Second operand is not a numeric or variable value\n");
    return -1;
   }
  }
  cval -= cval2;
  asm_set_reg(op1, cval);
 }
 else if(strncmp(prog[pc],"inc",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int not_found = 0;
  short cval = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Failed to find register/variable to increment\n");
   return -1;
  }
  cval++;
  asm_set_reg(op1, cval);
 }
 else if(strncmp(prog[pc],"dec",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int not_found = 0;
  short cval = asm_lookup_reg(op1, &not_found);
  if(not_found)
  {
   fprintf(stderr, "Failed to find register/variable to decrement\n");
   return -1;
  }
  cval--;
  asm_set_reg(op1, cval);
 }
 else if(strncmp(prog[pc],"mov",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  char *op2 = asm_get_operand(((prog[pc])+4)+strlen(op1));
  int data = 0;
  int not_found = 0;
  if(isalpha(op2[0]))
  {
   data = asm_lookup_reg(op2,&not_found);
  }
  if(!isalpha(op2[0])||not_found)
  {
   int not_number = 0;
   data = asm_convert_number(op2, &not_number);
   if(not_number)
   {
    fprintf(stderr, "Failed to find a value to move into register\n");
    return -1;
   }
  }
  asm_set_reg(op1, data);
 }
 else if(strncmp(prog[pc],"mul",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int not_found = 0;
  unsigned short val = asm_lookup_reg("al",((void *)0));
  unsigned short val2 = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Failed to find register to multiply by\n");
   return -1;
  }
  asm_set_reg("ax",val*val2);
 }
 else if(strncmp(prog[pc],"div",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int not_found = 0;
  unsigned short val = asm_lookup_reg("ax",((void *)0));
  unsigned short val2 = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Failed to find register to divide by\n");
  }
  asm_set_reg("al",val/val2);
  asm_set_reg("ah",val%val2);
 }
 else if(strncmp(prog[pc],"jmp",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  pc = asm_find_label(op1);
 }
 else if(strncmp(prog[pc],"int",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int int_num = atoi(op1);
  pc = asm_find_label(op1);
 }
 else if(strncmp(prog[pc],"hlt",3)==0)
 {
  pc = 0;
  return -1;
 }
 pc++;
 if(pc>=prog_length)
 {
  printf("Shouldn't of got this far!\n");
  return -1;
 }
 return pc;
}

variable_types: cval short

variable_types: data int

variable_types:
val
unsigned short


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

if ( (*(_BYTE *)(a1 + 36) & 0x10) != 0 )
{
result = *(unsigned __int16 *)(a1 + 364);
if ( (result & 0x10) == 0 || (*(_BYTE *)(a1 + 366) & 0x10) != 0 )
{
if ( (result & 0x1000) != 0 && (*(_BYTE *)(a1 + 367) & 0x10) == 0 )
return wiiuse_motion_sensing(a1, 1LL);
}
else
{
wiiuse_motion_sensing(a1, 0LL);
result = *(unsigned __int16 *)(a1 + 364);
if ( (result & 0x1000) != 0 && (*(_BYTE *)(a1 + 367) & 0x10) == 0 )
return wiiuse_motion_sensing(a1, 1LL);
}
}
return result;
}

variable_types: struct wiimote_t { int unid; struct bdaddr_t { unsigned char b[6]; } bdaddr; char bdaddr_str[18]; int out_sock; int in_sock; int state; int leds; int flags; void (*event_cb)(struct wiimote_t *wm); void (*dis_cb)(struct wiimote_t *wm); void (*stat_cb)(struct wiimote_t *wm, int attachment, int speaker, int ir, int led[4], float battery_level); unsigned char handshake_state; struct read_req_t { void (*cb)(struct wiimote_t *wm, unsigned char *data, unsigned short len); unsigned char *buf; unsigned int addr; unsigned short size; unsigned short wait; struct read_req_t *next; } *read_req; struct accel_t { struct vec3b_t { unsigned char x; } cal_zero; struct vec3b_t cal_g; float st_roll; float st_pitch; float st_alpha; } accel_calib; struct expansion_t { enum { EXP_NONE=0, EXP_NUNCHUK=1, EXP_CLASSIC=2 } type; union { struct nunchuk_t { struct accel_t accel_calib; struct joystick_t { struct vec2b_t { unsigned char x; } max; struct vec2b_t min; struct vec2b_t center; float ang; float mag; } js; int *flags; unsigned char btns; unsigned char btns_held; unsigned char btns_released; struct vec3b_t accel; struct orient_t { float roll; float pitch; float yaw; } orient; struct gforce_t { float x; } gforce; } nunchuk; struct classic_ctrl_t { short btns; short btns_held; short btns_released; float r_shoulder; float l_shoulder; struct joystick_t ljs; struct joystick_t rjs; } classic; }; } exp; struct vec3b_t accel; struct orient_t orient; struct gforce_t gforce; struct ir_t { struct ir_dot_t { unsigned char visible; unsigned int x; unsigned int y; short rx; short ry; unsigned char order; unsigned char size; } dot[4]; unsigned char num_dots; enum aspect_t { WIIUSE_ASPECT_4_3=0, WIIUSE_ASPECT_16_9=1 } aspect; enum ir_position_t { WIIUSE_IR_ABOVE=0, WIIUSE_IR_BELOW=1 } pos; unsigned int vres[2]; int offset[2]; int state; int ax; int ay; int x; int y; float distance; float z; } ir; unsigned short btns; unsigned short btns_held; unsigned short btns_released; float orient_threshold; struct wiimote_state_t { float exp_ljs_ang; float exp_rjs_ang; float exp_ljs_mag; float exp_rjs_mag; unsigned char exp_btns; struct orient_t exp_orient; float exp_r_shoulder; float exp_l_shoulder; int ir_ax; int ir_ay; float ir_distance; struct orient_t orient; unsigned short btns; } lstate; unsigned char event[32]; } *

user_defined_types: struct wiimote_t { int unid; struct bdaddr_t bdaddr; char bdaddr_str[18]; int out_sock; int in_sock; int state; int leds; int flags; void (*event_cb)(struct wiimote_t *wm); void (*dis_cb)(struct wiimote_t *wm); void (*stat_cb)(struct wiimote_t *wm, int attachment, int speaker, int ir, int led[4], float battery_level); unsigned char handshake_state; struct read_req_t *read_req; struct accel_t accel_calib; struct expansion_t exp; struct vec3b_t accel; struct orient_t orient; struct gforce_t gforce; struct ir_t ir; unsigned short btns; unsigned short btns_held; unsigned short btns_released; float orient_threshold; struct wiimote_state_t lstate; unsigned char event[32]; }

user_defined_types: struct accel_t { struct vec3b_t cal_zero; struct vec3b_t cal_g; float st_roll; float st_pitch; float st_alpha; }

user_defined_types: struct expansion_t { enum { EXP_NONE=0, EXP_NUNCHUK=1, EXP_CLASSIC=2 } type; union { struct nunchuk_t nunchuk; struct classic_ctrl_t classic; }; }

user_defined_types: struct ir_t { struct ir_dot_t dot[4]; unsigned char num_dots; enum aspect_t aspect; enum ir_position_t pos; unsigned int vres[2]; int offset[2]; int state; int ax; int ay; int x; int y; float distance; float z; }

user_defined_types: struct nunchuk_t { struct accel_t accel_calib; struct joystick_t js; int *flags; unsigned char btns; unsigned char btns_held; unsigned char btns_released; struct vec3b_t accel; struct orient_t orient; struct gforce_t gforce; }

user_defined_types: struct joystick_t { struct vec2b_t max; struct vec2b_t min; struct vec2b_t center; float ang; float mag; }


decompiled_code:
int __fastcall handle_read(unsigned int *a1, __int64 a2, unsigned __int16 a3)
{
int v4; // ebp
__int64 v5; // rbx
__int64 v6; // rsi

v4 = a3;
printf("\n\n--- DATA READ [wiimote id %i] ---\n", *a1);
printf("finished read of size %i\n", (unsigned int)v4);
if ( v4 )
{
v5 = 0LL;
do
{
if ( (v5 & 0xF) == 0 )
putchar(10);
v6 = *(unsigned __int8 *)(a2 + v5++);
printf("%x ", v6);
}
while ( v4 > (int)v5 );
}
return puts("\n");
}

canonical_decompiled_code:
int __fastcall func6(unsigned int *a1, __int64 a2, unsigned __int16 a3)
{
int v4; // ebp
__int64 v5; // rbx
__int64 v6; // rsi

v4 = a3;
printf("\n\n--- DATA READ [wiimote id %i] ---\n", *a1);
printf("finished read of size %i\n", (unsigned int)v4);
if ( v4 )
{
v5 = 0LL;
do
{
if ( (v5 & 0xF) == 0 )
putchar(10);
v6 = *(unsigned __int8 *)(a2 + v5++);
printf("%x ", v6);
}
while ( v4 > (int)v5 );
}
return puts("\n");
}

original_code:
void handle_read(struct wiimote_t* wm, byte* data, unsigned short len) {
 int i = 0;
 printf("\n\n--- DATA READ [wiimote id %i] ---\n", wm->unid);
 printf("finished read of size %i\n", len);
 for (; i < len; ++i) {
  if (!(i%16))
   printf("\n");
  printf("%x ", data[i]);
 }
 printf("\n\n");
}

canonical_original_code:
void handle_read(struct wiimote_t *wm, unsigned char *data, unsigned short len) {
 int i = 0;
 printf("\n\n--- DATA READ [wiimote id %i] ---\n", wm->unid);
 printf("finished read of size %i\n", len);
 for (; i < len; ++i) {
  if (!(i%16))
   printf("\n");
  printf("%x ", data[i]);
 }
 printf("\n\n");
}

variable_types:
data
unsigned char *

variable_types:
len
unsigned short

variable_types: i int

user_defined_types: struct wiimote_state_t { float exp_ljs_ang; float exp_rjs_ang; float exp_ljs_mag; float exp_rjs_mag; unsigned char exp_btns; struct orient_t exp_orient; float exp_r_shoulder; float exp_l_shoulder; int ir_ax; int ir_ay; float ir_distance; struct orient_t orient; unsigned short btns; }

user_defined_types: struct read_req_t { void (*cb)(struct wiimote_t *wm, unsigned char *data, unsigned short len); unsigned char *buf; unsigned int addr; unsigned short size; unsigned short wait; struct read_req_t *next; }

user_defined_types: enum aspect_t { WIIUSE_ASPECT_4_3=0, WIIUSE_ASPECT_16_9=1 }

user_defined_types: enum ir_position_t { WIIUSE_IR_ABOVE=0, WIIUSE_IR_BELOW=1 }

user_defined_types: struct classic_ctrl_t { short btns; short btns_held; short btns_released; float r_shoulder; float l_shoulder; struct joystick_t ljs; struct joystick_t rjs; }

user_defined_types: struct ir_dot_t { unsigned char visible; unsigned int x; unsigned int y; short rx; short ry; unsigned char order; unsigned char size; }

user_defined_types: struct orient_t { float roll; float pitch; float yaw; }


decompiled_code:
int __fastcall handle_ctrl_status(unsigned int *a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int *a5, float a6)
{
printf("\n\n--- CONTROLLER STATUS [wiimote id %i] ---\n", *a1);
printf("attachment: %i\n", a2);
printf("speaker: %i\n", a3);
printf("ir: %i\n", a4);
printf("leds: %i %i %i %i\n", *a5, a5[1], a5[2], a5[3]);
return printf("battery: %f %%\n", a6);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int *a5, float a6)
{
printf("\n\n--- CONTROLLER STATUS [wiimote id %i] ---\n", *a1);
printf("attachment: %i\n", a2);
printf("speaker: %i\n", a3);
printf("ir: %i\n", a4);
printf("leds: %i %i %i %i\n", *a5, a5[1], a5[2], a5[3]);
return printf("battery: %f %%\n", a6);
}

original_code:
void handle_ctrl_status(struct wiimote_t* wm, int attachment, int speaker, int ir, int led[4], float battery_level) {
 printf("\n\n--- CONTROLLER STATUS [wiimote id %i] ---\n", wm->unid);
 printf("attachment:      %i\n", attachment);
 printf("speaker:         %i\n", speaker);
 printf("ir:              %i\n", ir);
 printf("leds:            %i %i %i %i\n", led[0], led[1], led[2], led[3]);
 printf("battery:         %f %%\n", battery_level);
}

canonical_original_code:
void handle_ctrl_status(struct wiimote_t *wm, int attachment, int speaker, int ir, int led[4], float battery_level) {
 printf("\n\n--- CONTROLLER STATUS [wiimote id %i] ---\n", wm->unid);
 printf("attachment:      %i\n", attachment);
 printf("speaker:         %i\n", speaker);
 printf("ir:              %i\n", ir);
 printf("leds:            %i %i %i %i\n", led[0], led[1], led[2], led[3]);
 printf("battery:         %f %%\n", battery_level);
}

variable_types: attachment int

variable_types: speaker int

variable_types: ir int

variable_types:
led
int [4]


decompiled_code:
int __fastcall handle_disconnect(unsigned int *a1)
{
return printf("\n\n--- DISCONNECTED [wiimote id %i] ---\n", *a1);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int *a1)
{
return printf("\n\n--- DISCONNECTED [wiimote id %i] ---\n", *a1);
}

original_code:
void handle_disconnect(wiimote* wm) {
 printf("\n\n--- DISCONNECTED [wiimote id %i] ---\n", wm->unid);
}

canonical_original_code:
void handle_disconnect(struct wiimote_t *wm) {
 printf("\n\n--- DISCONNECTED [wiimote id %i] ---\n", wm->unid);
}


decompiled_code:
int vid_open_device()
{
return open("/dev/video0", 2);
}

canonical_decompiled_code:
int func2()
{
return open("/dev/video0", 2);
}

original_code:
int vid_open_device(char *device)
{
 int handle = open("/dev/video0",02);
 return handle;
}

variable_types:
device
char *

variable_types: handle int