repo: rogerhil/racergame

original_code:
int main(void){
    double r = 0;
    double t = 0;
    double aceleracao = 2;
    double c_desac = 1;
    double natural_desac = .5;
    double v_max = 1.0;
    double torque = 1.5;
    int ang = 0, ttt = 0;
    MAPA mapa;
    MAPA tcmapa;
    int criar_cenario = 0;
    mapa = zerar_matriz_mapa(mapa);
    tcmapa = zerar_matriz_mapa(tcmapa);
    inicializar_allegro(criar_cenario);
    BITMAP *buffer = create_bitmap(71, 58);
    BITMAP *buffer2 = create_bitmap(71, 58);
    BITMAP *mapa_buffer = create_bitmap(640, 480);
    BITMAP *menu_buffer = create_bitmap(640, 40);
    CONSTR_MENU menu;
    menu = define_menu(menu);
    menu_buffer = desenha_constr_menu(menu_buffer, menu);
    BITMAP *intro_bmp = load_bitmap("imagens/intro_logo.bmp", ((void *)0));
    draw_sprite(screen, intro_bmp, 40, 150);
    textprintf(screen, font, 200, 300, makecol(255,255,255), "PRESSIONE ENTER PARA COMECAR");
    textprintf(screen, font, 190, 340, makecol(255,255,255), "PRESSIONE TAB PARA EDITAR FASE");
    while(!key[__allegro_KEY_ENTER])
    {
        if (key[__allegro_KEY_TAB]){
            criar_cenario = 1;
            break;
        }
    }
    if (criar_cenario)
    {
        mapa = zerar_matriz_mapa(mapa);
    }
    else
    {
        mapa = define_mapa();
    }
    BITMAP *spr_carro = load_bitmap("imagens/carro.bmp", ((void *)0));
    BITMAP *spr_img;
    BITMAP *bmp;
    BITMAP *setinha = load_bitmap("imagens/setinha.bmp", ((void *)0));
    BITMAP *limp_setinhas = create_bitmap(640, 10);
    BITMAP *limp_menu = create_bitmap(640, 40);
    carro.x = 240;
    carro.y = 40;
    carro.largura = spr_carro->w;
    carro.altura = spr_carro->h;
    carro.angulo = 0;
    carro.spr = create_bitmap(carro.largura, carro.altura);
    mapa_buffer = desenha_mapa(mapa, buffer);
    draw_sprite(screen, mapa_buffer, 0, 0);
    draw_sprite(screen, menu_buffer, 0, 480);
    blit(screen, buffer2, carro.x, carro.y, 0, 0, 71, 58);
    draw_sprite(buffer, buffer2, 0, 0);
    int cmx, cmy, ma_x, ma_y, mmx, mmy, rmx, rmy, menux;
    int obj_selec = 0, i, j;
    int smodx = 0;
    int smody = 0;
    char *arquivo_img;
    arquivo_img = malloc (100);
    arquivo_img = strdup ("imagens/estrada.bmp");
    char *img_cursor;
    img_cursor = malloc (100);
    img_cursor = strdup ("imagens/cursor.bmp");
    ma_x = mouse_x;
    ma_y = mouse_y;
    BITMAP *cursor_bmp = load_bitmap(img_cursor, ((void *)0));
    set_mouse_sprite(cursor_bmp);
    set_mouse_sprite_focus(0,0);
    show_mouse(screen);
    if (criar_cenario)
    {
        while(!key[__allegro_KEY_ESC])
        {
            if (mouse_y > 0 && mouse_y < 480)
            {
                if (mouse_b)
                {
                    mmx = mouse_x / 20;
                    mmy = mouse_y / 20;
                    rmx = mouse_x % 20;
                    rmy = mouse_y % 20;
                    tcmapa.matriz[mmy][mmx] = obj_selec;
                    arquivo_img = retorna_nome_arq_imagem (obj_selec);
                    spr_img = load_bitmap(arquivo_img, ((void *)0));
                    bmp = create_bitmap(spr_img->w, spr_img->h);
                    draw_sprite(bmp, spr_img, 0, 0);
                    scare_mouse();
                    draw_sprite(screen, bmp, mouse_x - rmx, mouse_y - rmy);
                    unscare_mouse();
                    mouse_b = 0;
                }
            }
            if (mouse_y > 490 && mouse_y < 510)
            {
                menux = mouse_x / 30;
                if (mouse_b)
                {
                    obj_selec = menu.objs[menux];
                    smodx = mouse_x % 30;
                    smody = 20 - (mouse_y % 20);
                    draw_sprite(screen, limp_setinhas, 0, 510);
                    draw_sprite(screen, setinha, mouse_x - smodx, mouse_y + smody + 10);
                    if (obj_selec == -2)
                    {
                        obj_selec = 0;
                        if (deseja_salvar())
                        {
                            salvar_fase(tcmapa);
                            mapa = define_mapa();
                            criar_cenario = 0;
                            break;
                        }
                    }
                }
            }
            ma_x = mouse_x;
            ma_y = mouse_y;
        }
    }
    if (!criar_cenario)
    {
        draw_sprite(screen, limp_menu, 0, 480);
        while(!key[__allegro_KEY_ESC]){
            ttt++;
            if (ttt > 40)
            {
                if (key[__allegro_KEY_RIGHT]){
                    carro.angulo+=torque;
                }
                if (key[__allegro_KEY_LEFT]){
                    carro.angulo-=torque;
                }
                blit(buffer2, screen, 0, 0, carro.x, carro.y, 640, 480);
                if (key[__allegro_KEY_UP]){
                    ang = carro.angulo;
                    t+=.05;
                }
                ang = carro.angulo;
                r = aceleracao*t*t;
                if (r > v_max)
                {
                    t -= .1;
                    r = v_max;
                }
                cmy = (int)(carro.y + 35 + (int)(r * sin((ang*(3.1416))/128)))/20;
                cmx = (int)(carro.x + 29 + (int)(r * cos((ang*(3.1416))/128)))/20;
                if (mapa.matriz[cmy][cmx] != 0)
                {
                    t -= .2;
                    r -= 4;
                }
                if (t < 0)
                {
                    t = 0;
                }
                if (key[__allegro_KEY_DOWN]) {
                    ang = carro.angulo;
                    t-=c_desac;
                }
                t-= natural_desac;
                carro.x+= (int)(r * cos((ang*(3.1416))/128));
                carro.y+= (int)(r * sin((ang*(3.1416))/128));
                ttt = 0;
                blit(screen, buffer2, carro.x, carro.y, 0, 0, 71, 58);
                draw_sprite(buffer, buffer2, 0, 0);
            }
            desenha_sprite(buffer2, carro.spr, spr_carro, carro.angulo);
            draw_sprite(buffer, carro.spr, 10, 10);
            blit(buffer, screen, 0, 0, carro.x, carro.y, 640, 480);
        }
    }
    return(0);
}

canonical_original_code:
int main(){
    double r = 0;
    double t = 0;
    double aceleracao = 2;
    double c_desac = 1;
    double natural_desac = .5;
    double v_max = 1.0;
    double torque = 1.5;
    int ang = 0; int ttt = 0;
    struct MAPA mapa;
    struct MAPA tcmapa;
    int criar_cenario = 0;
    mapa = zerar_matriz_mapa(mapa);
    tcmapa = zerar_matriz_mapa(tcmapa);
    inicializar_allegro(criar_cenario);
    struct BITMAP *buffer = create_bitmap(71, 58);
    struct BITMAP *buffer2 = create_bitmap(71, 58);
    struct BITMAP *mapa_buffer = create_bitmap(640, 480);
    struct BITMAP *menu_buffer = create_bitmap(640, 40);
    struct CONSTR_MENU menu;
    menu = define_menu(menu);
    menu_buffer = desenha_constr_menu(menu_buffer, menu);
    struct BITMAP *intro_bmp = load_bitmap("imagens/intro_logo.bmp", ((void *)0));
    draw_sprite(screen, intro_bmp, 40, 150);
    textprintf(screen, font, 200, 300, makecol(255,255,255), "PRESSIONE ENTER PARA COMECAR");
    textprintf(screen, font, 190, 340, makecol(255,255,255), "PRESSIONE TAB PARA EDITAR FASE");
    while(!key[__allegro_KEY_ENTER])
    {
        if (key[__allegro_KEY_TAB]){
            criar_cenario = 1;
            break;
        }
    }
    if (criar_cenario)
    {
        mapa = zerar_matriz_mapa(mapa);
    }
    else
    {
        mapa = define_mapa();
    }
    struct BITMAP *spr_carro = load_bitmap("imagens/carro.bmp", ((void *)0));
    struct BITMAP *spr_img;
    struct BITMAP *bmp;
    struct BITMAP *setinha = load_bitmap("imagens/setinha.bmp", ((void *)0));
    struct BITMAP *limp_setinhas = create_bitmap(640, 10);
    struct BITMAP *limp_menu = create_bitmap(640, 40);
    carro.x = 240;
    carro.y = 40;
    carro.largura = spr_carro->w;
    carro.altura = spr_carro->h;
    carro.angulo = 0;
    carro.spr = create_bitmap(carro.largura, carro.altura);
    mapa_buffer = desenha_mapa(mapa, buffer);
    draw_sprite(screen, mapa_buffer, 0, 0);
    draw_sprite(screen, menu_buffer, 0, 480);
    blit(screen, buffer2, carro.x, carro.y, 0, 0, 71, 58);
    draw_sprite(buffer, buffer2, 0, 0);
    int cmx; int cmy; int ma_x; int ma_y; int mmx; int mmy; int rmx; int rmy; int menux;
    int obj_selec = 0; int i; int j;
    int smodx = 0;
    int smody = 0;
    char *arquivo_img;
    arquivo_img = malloc (100);
    arquivo_img = strdup ("imagens/estrada.bmp");
    char *img_cursor;
    img_cursor = malloc (100);
    img_cursor = strdup ("imagens/cursor.bmp");
    ma_x = mouse_x;
    ma_y = mouse_y;
    struct BITMAP *cursor_bmp = load_bitmap(img_cursor, ((void *)0));
    set_mouse_sprite(cursor_bmp);
    set_mouse_sprite_focus(0,0);
    show_mouse(screen);
    if (criar_cenario)
    {
        while(!key[__allegro_KEY_ESC])
        {
            if (mouse_y > 0 && mouse_y < 480)
            {
                if (mouse_b)
                {
                    mmx = mouse_x / 20;
                    mmy = mouse_y / 20;
                    rmx = mouse_x % 20;
                    rmy = mouse_y % 20;
                    tcmapa.matriz[mmy][mmx] = obj_selec;
                    arquivo_img = retorna_nome_arq_imagem (obj_selec);
                    spr_img = load_bitmap(arquivo_img, ((void *)0));
                    bmp = create_bitmap(spr_img->w, spr_img->h);
                    draw_sprite(bmp, spr_img, 0, 0);
                    scare_mouse();
                    draw_sprite(screen, bmp, mouse_x - rmx, mouse_y - rmy);
                    unscare_mouse();
                    mouse_b = 0;
                }
            }
            if (mouse_y > 490 && mouse_y < 510)
            {
                menux = mouse_x / 30;
                if (mouse_b)
                {
                    obj_selec = menu.objs[menux];
                    smodx = mouse_x % 30;
                    smody = 20 - (mouse_y % 20);
                    draw_sprite(screen, limp_setinhas, 0, 510);
                    draw_sprite(screen, setinha, mouse_x - smodx, mouse_y + smody + 10);
                    if (obj_selec == -2)
                    {
                        obj_selec = 0;
                        if (deseja_salvar())
                        {
                            salvar_fase(tcmapa);
                            mapa = define_mapa();
                            criar_cenario = 0;
                            break;
                        }
                    }
                }
            }
            ma_x = mouse_x;
            ma_y = mouse_y;
        }
    }
    if (!criar_cenario)
    {
        draw_sprite(screen, limp_menu, 0, 480);
        while(!key[__allegro_KEY_ESC]){
            ttt++;
            if (ttt > 40)
            {
                if (key[__allegro_KEY_RIGHT]){
                    carro.angulo+=torque;
                }
                if (key[__allegro_KEY_LEFT]){
                    carro.angulo-=torque;
                }
                blit(buffer2, screen, 0, 0, carro.x, carro.y, 640, 480);
                if (key[__allegro_KEY_UP]){
                    ang = carro.angulo;
                    t+=.05;
                }
                ang = carro.angulo;
                r = aceleracao*t*t;
                if (r > v_max)
                {
                    t -= .1;
                    r = v_max;
                }
                cmy = (int)(carro.y + 35 + (int)(r * sin((ang*(3.1416))/128)))/20;
                cmx = (int)(carro.x + 29 + (int)(r * cos((ang*(3.1416))/128)))/20;
                if (mapa.matriz[cmy][cmx] != 0)
                {
                    t -= .2;
                    r -= 4;
                }
                if (t < 0)
                {
                    t = 0;
                }
                if (key[__allegro_KEY_DOWN]) {
                    ang = carro.angulo;
                    t-=c_desac;
                }
                t-= natural_desac;
                carro.x+= (int)(r * cos((ang*(3.1416))/128));
                carro.y+= (int)(r * sin((ang*(3.1416))/128));
                ttt = 0;
                blit(screen, buffer2, carro.x, carro.y, 0, 0, 71, 58);
                draw_sprite(buffer, buffer2, 0, 0);
            }
            desenha_sprite(buffer2, carro.spr, spr_carro, carro.angulo);
            draw_sprite(buffer, carro.spr, 10, 10);
            blit(buffer, screen, 0, 0, carro.x, carro.y, 640, 480);
        }
    }
    return(0);
}

variable_types: r double

variable_types: t double

variable_types: aceleracao double

variable_types: torque double

variable_types: ang int

variable_types: ttt int

variable_types: struct MAPA { int largura; int altura; int matriz[24][32]; struct BITMAP { int w; int clip; int cl; struct GFX_VTABLE { int color_depth; int mask_color; void *unwrite_bank; void (*set_clip)(struct BITMAP *bmp); void (*acquire)(struct BITMAP *bmp); void (*release)(struct BITMAP *bmp); struct BITMAP *(*create_sub_bitmap)(struct BITMAP *parent, int x, int y, int width, int height); void (*created_sub_bitmap)(struct BITMAP *bmp, struct BITMAP *parent); int (*getpixel)(struct BITMAP *bmp, int x, int y); void (*putpixel)(struct BITMAP *bmp, int x, int y, int color); void (*vline)(struct BITMAP *bmp, int x, int y_1, int y2, int color); void (*hline)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*hfill)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*line)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*fastline)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*rectfill)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*triangle)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int x3, int y3, int color); void (*draw_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_256_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_v_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_h_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_vh_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_rgba_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_lit_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); void (*draw_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE { int w; int color_depth; int size; char dat[]; } *sprite, int x, int y); void (*draw_trans_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_trans_rgba_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_lit_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y, int color); void (*draw_character)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color, int bg); void (*draw_glyph)(struct BITMAP *bmp, struct FONT_GLYPH { short w; unsigned char dat[]; } *glyph, int x, int y, int color, int bg); void (*blit_from_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_from_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_forward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_backward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_between_formats)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*masked_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*clear_to_color)(struct BITMAP *bitmap, int color); void (*pivot_scaled_sprite_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int cx, int cy, int angle, int scale, int v_flip); void (*do_stretch_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int source_width, int source_height, int dest_x, int dest_y, int dest_width, int dest_height, int masked); void (*draw_gouraud_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int c1, int c2, int c3, int c4); void (*draw_sprite_end)(); void (*blit_end)(); void (*polygon)(struct BITMAP *bmp, int vertices, int *points, int color); void (*rect)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*circle)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*circlefill)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*ellipse)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*ellipsefill)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*arc)(struct BITMAP *bmp, int x, int y, int ang1, int ang2, int r, int color); void (*spline)(struct BITMAP *bmp, int points[8], int color); void (*floodfill)(struct BITMAP *bmp, int x, int y, int color); void (*polygon3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D { int x; int u; int c; } *vtx[]); void (*polygon3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D_f { float x; float u; int c; } *vtx[]); void (*triangle3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3); void (*triangle3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3); void (*quad3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3, struct V3D *v4); void (*quad3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3, struct V3D_f *v4); void (*draw_sprite_ex)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int mode, int flip); } *vtable; void *write_bank; void *read_bank; void *dat; unsigned long id; void *extra; int x_ofs; int y_ofs; int seg; unsigned char *line[]; } *spr; }

variable_types:
menu
struct CONSTR_MENU { int objs[32]; }

variable_types: cmx int

variable_types: cmy int

variable_types: mmx int

variable_types: mmy int

variable_types: rmx int

variable_types: rmy int

variable_types: menux int

variable_types: j int

variable_types: smodx int

variable_types: smody int

user_defined_types: struct MAPA { int largura; int altura; int matriz[24][32]; struct BITMAP *spr; }

user_defined_types: struct BITMAP { int w; int clip; int cl; struct GFX_VTABLE *vtable; void *write_bank; void *read_bank; void *dat; unsigned long id; void *extra; int x_ofs; int y_ofs; int seg; unsigned char *line[]; }

user_defined_types: struct GFX_VTABLE { int color_depth; int mask_color; void *unwrite_bank; void (*set_clip)(struct BITMAP *bmp); void (*acquire)(struct BITMAP *bmp); void (*release)(struct BITMAP *bmp); struct BITMAP *(*create_sub_bitmap)(struct BITMAP *parent, int x, int y, int width, int height); void (*created_sub_bitmap)(struct BITMAP *bmp, struct BITMAP *parent); int (*getpixel)(struct BITMAP *bmp, int x, int y); void (*putpixel)(struct BITMAP *bmp, int x, int y, int color); void (*vline)(struct BITMAP *bmp, int x, int y_1, int y2, int color); void (*hline)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*hfill)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*line)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*fastline)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*rectfill)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*triangle)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int x3, int y3, int color); void (*draw_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_256_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_v_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_h_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_vh_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_rgba_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_lit_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); void (*draw_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_trans_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_trans_rgba_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_lit_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y, int color); void (*draw_character)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color, int bg); void (*draw_glyph)(struct BITMAP *bmp, struct FONT_GLYPH *glyph, int x, int y, int color, int bg); void (*blit_from_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_from_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_forward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_backward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_between_formats)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*masked_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*clear_to_color)(struct BITMAP *bitmap, int color); void (*pivot_scaled_sprite_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int cx, int cy, int angle, int scale, int v_flip); void (*do_stretch_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int source_width, int source_height, int dest_x, int dest_y, int dest_width, int dest_height, int masked); void (*draw_gouraud_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int c1, int c2, int c3, int c4); void (*draw_sprite_end)(); void (*blit_end)(); void (*polygon)(struct BITMAP *bmp, int vertices, int *points, int color); void (*rect)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*circle)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*circlefill)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*ellipse)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*ellipsefill)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*arc)(struct BITMAP *bmp, int x, int y, int ang1, int ang2, int r, int color); void (*spline)(struct BITMAP *bmp, int points[8], int color); void (*floodfill)(struct BITMAP *bmp, int x, int y, int color); void (*polygon3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D *vtx[]); void (*polygon3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D_f *vtx[]); void (*triangle3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3); void (*triangle3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3); void (*quad3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3, struct V3D *v4); void (*quad3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3, struct V3D_f *v4); void (*draw_sprite_ex)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int mode, int flip); }


yyparse

repo: rohitjha/hoc

original_code:
int
yyparse (void)
{
    int yystate;
    int yyerrstatus;
    yytype_int16 yyssa[200];
    yytype_int16 *yyss;
    yytype_int16 *yyssp;
    YYSTYPE yyvsa[200];
    YYSTYPE *yyvs;
    YYSTYPE *yyvsp;
    long unsigned int yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  YYSTYPE yyval;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (yytype_int16) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      long unsigned int yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        yytype_int16 *yyss1 = yyss;
        union yyalloc *yyptr =
          (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 2)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-59))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned) (yychar) <= 276 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 260 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
        case 4:
    { code(pop); code((Inst) 0); return 1; }
    break;
  case 5:
    { code((Inst) 0); return 1; }
    break;
  case 6:
    { code(print); code((Inst) 0); return 1; }
    break;
  case 7:
    { (yyerrstatus = 0); }
    break;
  case 8:
    { (yyval.inst)=(yyvsp[0].inst); code(varpush); code((Inst)(yyvsp[-2].sym)); code(assign); }
    break;
  case 9:
    { code(pop); }
    break;
  case 10:
    { code(prexpr); (yyval.inst)=(yyvsp[0].inst); }
    break;
  case 11:
    {
     ((yyvsp[-3].inst))[1] = (Inst)(yyvsp[-1].inst);
     ((yyvsp[-3].inst))[2] = (Inst)(yyvsp[0].inst);
    }
    break;
  case 12:
    {
     ((yyvsp[-3].inst))[1] = (Inst)(yyvsp[-1].inst);
     ((yyvsp[-3].inst))[3] = (Inst)(yyvsp[0].inst);
    }
    break;
  case 13:
    {
       ((yyvsp[-6].inst))[1] = (Inst)(yyvsp[-4].inst);
       ((yyvsp[-6].inst))[2] = (Inst)(yyvsp[-1].inst);
       ((yyvsp[-6].inst))[3] = (Inst)(yyvsp[0].inst);
      }
    break;
  case 14:
    { (yyval.inst)=(yyvsp[-1].inst); }
    break;
  case 15:
    { code((Inst) 0); (yyval.inst)=(yyvsp[-1].inst); }
    break;
  case 16:
    { (yyval.inst)=code(whilecode); code((Inst) 0); code((Inst) 0); }
    break;
  case 17:
    { (yyval.inst)=code(ifcode); code((Inst) 0); code((Inst) 0); code((Inst) 0); }
    break;
  case 18:
    { code((Inst) 0); (yyval.inst)=progp; }
    break;
  case 19:
    { (yyval.inst)=progp; }
    break;
  case 22:
    { (yyval.inst)=code(constpush); code((Inst)(yyvsp[0].sym)); }
    break;
  case 23:
    { (yyval.inst)=code(varpush); code((Inst)(yyvsp[0].sym)); code(eval); }
    break;
  case 25:
    { (yyval.inst)=(yyvsp[-1].inst); code(bltin); code((Inst)(yyvsp[-3].sym)->u.ptr); }
    break;
  case 26:
    { (yyval.inst)=(yyvsp[-1].inst); }
    break;
  case 27:
    { code(add); }
    break;
  case 28:
    { code(sub); }
    break;
  case 29:
    { code(mul); }
    break;
  case 30:
    { code(div); }
    break;
  case 31:
    { code(power); }
    break;
  case 32:
    { (yyval.inst)=(yyvsp[0].inst); code(positive); }
    break;
  case 33:
    { (yyval.inst)=(yyvsp[0].inst); code(negate); }
    break;
  case 34:
    { code(gt); }
    break;
  case 35:
    { code(ge); }
    break;
  case 36:
    { code(lt); }
    break;
  case 37:
    { code(le); }
    break;
  case 38:
    { code(eq); }
    break;
  case 39:
    { code(ne); }
    break;
  case 40:
    { code(and); }
    break;
  case 41:
    { code(or); }
    break;
  case 42:
    { (yyval.inst)=(yyvsp[0].inst); code(not); }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    const int yylhs = yyr1[yyn] - 33;
    const int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 260 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned) (yychar) <= 276 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-59))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 260 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned) (yychar) <= 276 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

canonical_original_code:
int yyparse()
{
    int yystate;
    int yyerrstatus;
    short yyssa[200];
    short *yyss;
    short *yyssp;
    union YYSTYPE yyvsa[200];
    union YYSTYPE *yyvs;
    union YYSTYPE *yyvsp;
    unsigned long yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  union YYSTYPE yyval;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (short) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      unsigned long yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        short *yyss1 = yyss;
        union yyalloc *yyptr = (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 2)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-59))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned int) (yychar) <= 276 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 260 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
        case 4:
    { code(pop); code((int (*)()) 0); return 1; }
    break;
  case 5:
    { code((int (*)()) 0); return 1; }
    break;
  case 6:
    { code(print); code((int (*)()) 0); return 1; }
    break;
  case 7:
    { (yyerrstatus = 0); }
    break;
  case 8:
    { (yyval.inst)=(yyvsp[0].inst); code(varpush); code((Inst)(yyvsp[-2].sym)); code(assign); }
    break;
  case 9:
    { code(pop); }
    break;
  case 10:
    { code(prexpr); (yyval.inst)=(yyvsp[0].inst); }
    break;
  case 11:
    {
     ((yyvsp[-3].inst))[1] = (Inst)(yyvsp[-1].inst);
     ((yyvsp[-3].inst))[2] = (Inst)(yyvsp[0].inst);
    }
    break;
  case 12:
    {
     ((yyvsp[-3].inst))[1] = (Inst)(yyvsp[-1].inst);
     ((yyvsp[-3].inst))[3] = (Inst)(yyvsp[0].inst);
    }
    break;
  case 13:
    {
       ((yyvsp[-6].inst))[1] = (Inst)(yyvsp[-4].inst);
       ((yyvsp[-6].inst))[2] = (Inst)(yyvsp[-1].inst);
       ((yyvsp[-6].inst))[3] = (Inst)(yyvsp[0].inst);
      }
    break;
  case 14:
    { (yyval.inst)=(yyvsp[-1].inst); }
    break;
  case 15:
    { code((int (*)()) 0); (yyval.inst)=(yyvsp[-1].inst); }
    break;
  case 16:
    { (yyval.inst)=code(whilecode); code((int (*)()) 0); code((int (*)()) 0); }
    break;
  case 17:
    { (yyval.inst)=code(ifcode); code((int (*)()) 0); code((int (*)()) 0); code((int (*)()) 0); }
    break;
  case 18:
    { code((int (*)()) 0); (yyval.inst)=progp; }
    break;
  case 19:
    { (yyval.inst)=progp; }
    break;
  case 22:
    { (yyval.inst)=code(constpush); code((Inst)(yyvsp[0].sym)); }
    break;
  case 23:
    { (yyval.inst)=code(varpush); code((Inst)(yyvsp[0].sym)); code(eval); }
    break;
  case 25:
    { (yyval.inst)=(yyvsp[-1].inst); code(bltin); code((Inst)(yyvsp[-3].sym)->u.ptr); }
    break;
  case 26:
    { (yyval.inst)=(yyvsp[-1].inst); }
    break;
  case 27:
    { code(add); }
    break;
  case 28:
    { code(sub); }
    break;
  case 29:
    { code(mul); }
    break;
  case 30:
    { code(div); }
    break;
  case 31:
    { code(power); }
    break;
  case 32:
    { (yyval.inst)=(yyvsp[0].inst); code(positive); }
    break;
  case 33:
    { (yyval.inst)=(yyvsp[0].inst); code(negate); }
    break;
  case 34:
    { code(gt); }
    break;
  case 35:
    { code(ge); }
    break;
  case 36:
    { code(lt); }
    break;
  case 37:
    { code(le); }
    break;
  case 38:
    { code(eq); }
    break;
  case 39:
    { code(ne); }
    break;
  case 40:
    { code(and); }
    break;
  case 41:
    { code(or); }
    break;
  case 42:
    { (yyval.inst)=(yyvsp[0].inst); code(not); }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    int yylhs = yyr1[yyn] - 33;
    int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 260 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned int) (yychar) <= 276 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-59))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 260 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned int) (yychar) <= 276 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

variable_types: yystate int

variable_types: yyerrstatus int

variable_types:
yyssa
short [200]

variable_types:
yyss
short *

variable_types:
yyssp
short *

variable_types: union YYSTYPE { struct Symbol { char *name; short type; union { double val; double (*ptr)(); } u; struct Symbol *next; } *sym; int (**inst)(); } [200]

variable_types: union YYSTYPE { struct Symbol { char *name; short type; union { double val; double (*ptr)(); } u; struct Symbol *next; } *sym; int (**inst)(); } *

variable_types:
yystacksize
unsigned long

variable_types: yyn int

variable_types: yyresult int

variable_types: yytoken int

variable_types: yylen int

variable_types:
yysize
unsigned long

variable_types: union yyalloc { short yyss_alloc; union YYSTYPE { struct Symbol { char *name; short type; union { double val; double (*ptr)(); } u; struct Symbol *next; } *sym; int (**inst)(); } yyvs_alloc; } *

variable_types:
yynewbytes
unsigned long

variable_types: yylhs int

variable_types: yyi int

return_type: int

user_defined_types: union YYSTYPE { struct Symbol *sym; int (**inst)(); }

user_defined_types: union yyalloc { short yyss_alloc; union YYSTYPE yyvs_alloc; }


execerror

decompiled_code:
void __fastcall __noreturn execerror(const char *a1, const char *a2)
{
warning(a1, a2);
longjmp(begin, 0);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1, const char *a2)
{
func2(a1, a2);
longjmp(begin, 0);
}

original_code:
void execerror(char *s, char *t)
{
 warning(s, t);
 longjmp(begin, 0);
}

variable_types:
s
char *

variable_types:
t
char *

return_type: void


main

canonical_name: main

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

progname = (__int64)*argv;
init(argc, argv, envp);
setjmp(begin);
initcode();
while ( 1 )
{
result = yyparse();
if ( !result )
break;
execute(&prog);
initcode();
}
return result;
}

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

progname = (__int64)*argv;
init(argc, argv, envp);
setjmp(begin);
initcode();
while ( 1 )
{
result = func5();
if ( !result )
break;
execute(&prog);
initcode();
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 progname = argv[0];
 init();
 _setjmp (begin);
 for (initcode(); yyparse(); initcode())
  execute(prog);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


initcode

decompiled_code:
void initcode()
{
stackp = (__int64)&stack;
progp = (__int64)&prog;
}

canonical_decompiled_code:
void func0()
{
stackp = (__int64)&stack;
progp = (__int64)&prog;
}

original_code:
void initcode()
{
 stackp = stack;
 progp = prog;
}


pop

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

if ( stackp <= (unsigned __int64)&stack )
execerror("stack underflow", 0LL);
result = *(_QWORD *)(stackp - 8);
stackp -= 8LL;
return result;
}

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

if ( stackp <= (unsigned __int64)&stack )
execerror("stack underflow", 0LL);
result = *(_QWORD *)(stackp - 8);
stackp -= 8LL;
return result;
}

canonical_original_code:
union Datum pop()
{
 if (stackp <= stack)
  execerror("stack underflow", (char *) 0);
 return *--stackp;
}

return_type: union Datum { double val; struct Symbol { char *name; short type; union { double val; double (*ptr)(); } u; struct Symbol *next; } *sym; }

user_defined_types: union Datum { double val; struct Symbol *sym; }


code

decompiled_code:
__int64 __fastcall code(__int64 a1)
{
__int64 v1; // r12
_QWORD *v2; // rax

v1 = progp;
v2 = (_QWORD *)progp;
if ( progp >= (unsigned __int64)&prog + 16000 )
{
execerror("program too big", 0LL);
v2 = (_QWORD *)progp;
}
progp = (__int64)(v2 + 1);
*v2 = a1;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // r12
_QWORD *v2; // rax

v1 = progp;
v2 = (_QWORD *)progp;
if ( progp >= (unsigned __int64)&prog + 16000 )
{
execerror("program too big", 0LL);
v2 = (_QWORD *)progp;
}
progp = (__int64)(v2 + 1);
*v2 = a1;
return v1;
}

original_code:
Inst *code(Inst f)
{
 Inst *oprogp = progp;
 if (progp >= &prog[2000])
  execerror("program too big", (char *) 0);
 *progp++ = f;
 return oprogp;
}

canonical_original_code:
int (**code(int (*f)()))()
{
 int (**oprogp)() = progp;
 if (progp >= &prog[2000])
  execerror("program too big", (char *) 0);
 *progp++ = f;
 return oprogp;
}

variable_types:
oprogp
int (**)()


execute

original_code:
void execute(Inst *p)
{
 for (pc = p; *pc != (Inst) 0; )
  (*(*pc++))();
}


constpush

decompiled_code:
__int64 constpush()
{
__int64 v0; // rax

v0 = *(_QWORD *)pc;
pc += 8LL;
return push(*(_QWORD *)(v0 + 16));
}

original_code:
void constpush()
{
 Datum d;
 d.val = ((Symbol *)*pc++)->u.val;
 push(d);
}

canonical_original_code:
void constpush()
{
 union Datum d;
 d.val = ((struct Symbol *)*pc++)->u.val;
 push(d);
}

variable_types: union Datum { double val; struct Symbol { char *name; short type; union { double val; double (*ptr)(); } u; struct Symbol *next; } *sym; }


varpush

decompiled_code:
__int64 varpush()
{
__int64 v0; // rdi

v0 = *(_QWORD *)pc;
pc += 8LL;
return push(v0);
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rdi

v0 = *(_QWORD *)pc;
pc += 8LL;
return func1(v0);
}

original_code:
void varpush()
{
 Datum d;
 d.sym = (Symbol *)(*pc++);
 push(d);
}

canonical_original_code:
void varpush()
{
 union Datum d;
 d.sym = (struct Symbol *)(*pc++);
 push(d);
}

user_defined_types: struct Symbol { char *name; short type; union { double val; double (*ptr)(); } u; struct Symbol *next; }


add

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

v0 = COERCE_DOUBLE(pop());
v1 = COERCE_DOUBLE(pop());
return push(COERCE__INT64(v0 + v1));
}

canonical_decompiled_code:
__int64 func7()
{
double v0; // rbx
double v1; // rax

v0 = COERCE_DOUBLE(pop());
v1 = COERCE_DOUBLE(pop());
return func1(COERCE__INT64(v0 + v1));
}

original_code:
void add()
{
 Datum d1, d2;
 d2 = pop();
 d1 = pop();
 d1.val += d2.val;
 push(d1);
}

canonical_original_code:
void add()
{
 union Datum d1; union Datum d2;
 d2 = pop();
 d1 = pop();
 d1.val += d2.val;
 push(d1);
}


sub

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

v0 = COERCE_DOUBLE(pop());
v1 = COERCE_DOUBLE(pop());
return push(COERCE__INT64(v1 - v0));
}

canonical_decompiled_code:
__int64 func8()
{
double v0; // rbx
double v1; // rax

v0 = COERCE_DOUBLE(pop());
v1 = COERCE_DOUBLE(pop());
return func1(COERCE__INT64(v1 - v0));
}

original_code:
void sub()
{
 Datum d1, d2;
 d2 = pop();
 d1 = pop();
 d1.val -= d2.val;
 push(d1);
}

canonical_original_code:
void sub()
{
 union Datum d1; union Datum d2;
 d2 = pop();
 d1 = pop();
 d1.val -= d2.val;
 push(d1);
}


mul

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

v0 = COERCE_DOUBLE(pop());
v1 = COERCE_DOUBLE(pop());
return push(COERCE__INT64(v0 * v1));
}

canonical_decompiled_code:
__int64 func9()
{
double v0; // rbx
double v1; // rax

v0 = COERCE_DOUBLE(pop());
v1 = COERCE_DOUBLE(pop());
return func1(COERCE__INT64(v0 * v1));
}

original_code:
void mul()
{
 Datum d1, d2;
 d2 = pop();
 d1 = pop();
 d1.val *= d2.val;
 push(d1);
}

canonical_original_code:
void mul()
{
 union Datum d1; union Datum d2;
 d2 = pop();
 d1 = pop();
 d1.val *= d2.val;
 push(d1);
}


div

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

v0 = COERCE_DOUBLE(pop());
v1 = COERCE_DOUBLE(pop());
return push(COERCE__INT64(v1 / v0));
}

canonical_decompiled_code:
__int64 func10()
{
double v0; // rbx
double v1; // rax

v0 = COERCE_DOUBLE(pop());
v1 = COERCE_DOUBLE(pop());
return func1(COERCE__INT64(v1 / v0));
}

original_code:
void div()
{
 Datum d1, d2;
 d2 = pop();
 d1 = pop();
 d1.val /= d2.val;
 push(d1);
}

canonical_original_code:
void div()
{
 union Datum d1; union Datum d2;
 d2 = pop();
 d1 = pop();
 d1.val /= d2.val;
 push(d1);
}


power

decompiled_code:
__int64 power()
{
__int64 v0; // rbp
__int64 v1; // rax
int v2; // eax

v0 = pop();
v1 = pop();
v2 = Pow(v1, v0);
return push(COERCE__INT64((double)v2));
}

canonical_decompiled_code:
__int64 func11()
{
__int64 v0; // rbp
__int64 v1; // rax
int v2; // eax

v0 = func2();
v1 = func2();
v2 = Pow(v1, v0);
return func1(COERCE__INT64((double)v2));
}

original_code:
void power()
{
 Datum d1, d2;
 d2 = pop();
 d1 = pop();
 d1.val = Pow(d1, d2);
 push(d1);
}

canonical_original_code:
void power()
{
 union Datum d1; union Datum d2;
 d2 = pop();
 d1 = pop();
 d1.val = Pow(d1, d2);
 push(d1);
}


negate

decompiled_code:
__int64 negate()
{
__int64 v0; // rax

v0 = pop();
return push(v0 ^ LC3);
}

canonical_decompiled_code:
__int64 func12()
{
__int64 v0; // rax

v0 = func2();
return func1(v0 ^ LC3);
}

original_code:
void negate()
{
 Datum d;
 d = pop();
 d.val = (-1) * d.val;
 push(d);
}

canonical_original_code:
void negate()
{
 union Datum d;
 d = pop();
 d.val = (-1) * d.val;
 push(d);
}


positive

decompiled_code:
void positive()
{
;
}

canonical_decompiled_code:
void func13()
{
;
}

original_code:
void positive()
{
}

canonical_original_code:
void positive()
{
}


eval

decompiled_code:
__int64 eval()
{
__int64 v0; // rax
__int64 v1; // rbp

v0 = pop();
v1 = v0;
if ( *(_WORD *)(v0 + 8) != 262 )
return push(*(_QWORD *)(v0 + 16));
execerror("undefined variable", *(_QWORD *)v0);
return push(*(_QWORD *)(v1 + 16));
}

canonical_decompiled_code:
__int64 func14()
{
__int64 v0; // rax
__int64 v1; // rbp

v0 = func2();
v1 = v0;
if ( *(_WORD *)(v0 + 8) != 262 )
return func1(*(_QWORD *)(v0 + 16));
execerror("undefined variable", *(_QWORD *)v0);
return func1(*(_QWORD *)(v1 + 16));
}

original_code:
void eval()
{
 Datum d;
 d = pop();
 if (d.sym->type == 262)
  execerror("undefined variable", d.sym->name);
 d.val = d.sym->u.val;
 push(d);
}

canonical_original_code:
void eval()
{
 union Datum d;
 d = pop();
 if (d.sym->type == 262)
  execerror("undefined variable", d.sym->name);
 d.val = d.sym->u.val;
 push(d);
}


assign

decompiled_code:
__int64 assign()
{
__int64 v0; // rbx
__int64 v1; // rbp

v0 = pop();
v1 = pop();
if ( (*(_WORD *)(v0 + 8) & 0xFFFD) != 260 )
execerror("assignment to non-variable", *(_QWORD *)v0);
*(_QWORD *)(v0 + 16) = v1;
*(_WORD *)(v0 + 8) = 260;
return push(v1);
}

original_code:
void assign()
{
 Datum d1, d2;
 d1 = pop();
 d2 = pop();
 if (d1.sym->type != 260 && d1.sym->type != 262)
  execerror("assignment to non-variable", d1.sym->name);
 d1.sym->u.val = d2.val;
 d1.sym->type = 260;
 push(d2);
}

canonical_original_code:
void assign()
{
 union Datum d1; union Datum d2;
 d1 = pop();
 d2 = pop();
 if (d1.sym->type != 260 && d1.sym->type != 262)
  execerror("assignment to non-variable", d1.sym->name);
 d1.sym->u.val = d2.val;
 d1.sym->type = 260;
 push(d2);
}


print

decompiled_code:
int print()
{
double v0; // rax

v0 = COERCE_DOUBLE(pop());
return printf("\t%.8g\n", v0);
}

canonical_decompiled_code:
int func16()
{
double v0; // rax

v0 = COERCE_DOUBLE(pop());
return printf("\t%.8g\n", v0);
}

original_code:
void print()
{
 Datum d;
 d = pop();
 printf("\t%.8g\n", d.val);
}

canonical_original_code:
void print()
{
 union Datum d;
 d = pop();
 printf("\t%.8g\n", d.val);
}


bltin

decompiled_code:
__int64 bltin()
{
double v0; // rax
double (__fastcall **v1)(double); // rdx
__int64 v2; // xmm0_8

v0 = COERCE_DOUBLE(pop());
v1 = (double (__fastcall **)(double))pc;
pc += 8LL;
*(double *)&v2 = (*v1)(v0);
return push(v2);
}

canonical_decompiled_code:
__int64 func17()
{
double v0; // rax
double (__fastcall **v1)(double); // rdx
__int64 v2; // xmm0_8

v0 = COERCE_DOUBLE(pop());
v1 = (double (__fastcall **)(double))pc;
pc += 8LL;
*(double *)&v2 = (*v1)(v0);
return func1(v2);
}

original_code:
void bltin()
{
 Datum d;
 d = pop();
 d.val = (*(double (*) ())(*pc++))(d.val);
 push(d);
}

canonical_original_code:
void bltin()
{
 union Datum d;
 d = pop();
 d.val = (*(double (*)())(*pc++))(d.val);
 push(d);
}


gt

decompiled_code:
__int64 gt()
{
double v0; // rbx
__int64 v1; // xmm0_8

v0 = COERCE_DOUBLE(pop());
v1 = LC7;
if ( COERCE_DOUBLE(pop()) <= v0 )
v1 = 0LL;
return push(v1);
}

canonical_decompiled_code:
__int64 func18()
{
double v0; // rbx
__int64 v1; // xmm0_8

v0 = COERCE_DOUBLE(pop());
v1 = LC7;
if ( COERCE_DOUBLE(pop()) <= v0 )
v1 = 0LL;
return func1(v1);
}

original_code:
void gt()
{
 Datum d1, d2;
 d2 = pop();
 d1 = pop();
 d1.val = (double)(d1.val > d2.val);
 push(d1);
}

canonical_original_code:
void gt()
{
 union Datum d1; union Datum d2;
 d2 = pop();
 d1 = pop();
 d1.val = (double)(d1.val > d2.val);
 push(d1);
}


lt

decompiled_code:
__int64 lt()
{
double v0; // rbx
__int64 v1; // xmm0_8

v0 = COERCE_DOUBLE(pop());
v1 = LC7;
if ( v0 <= COERCE_DOUBLE(pop()) )
v1 = 0LL;
return push(v1);
}

canonical_decompiled_code:
__int64 func19()
{
double v0; // rbx
__int64 v1; // xmm0_8

v0 = COERCE_DOUBLE(pop());
v1 = LC7;
if ( v0 <= COERCE_DOUBLE(pop()) )
v1 = 0LL;
return func1(v1);
}

original_code:
void lt()
{
 Datum d1, d2;
 d2 = pop();
 d1 = pop();
 d1.val = (double)(d1.val < d2.val);
 push(d1);
}

canonical_original_code:
void lt()
{
 union Datum d1; union Datum d2;
 d2 = pop();
 d1 = pop();
 d1.val = (double)(d1.val < d2.val);
 push(d1);
}


eq

decompiled_code:
__int64 eq()
{
double v0; // rbx
__int64 result; // rax

v0 = COERCE_DOUBLE(pop());
if ( v0 == COERCE_DOUBLE(pop()) )
result = push(LC7);
else
result = push(0LL);
return result;
}

canonical_decompiled_code:
__int64 func20()
{
double v0; // rbx
__int64 result; // rax

v0 = COERCE_DOUBLE(pop());
if ( v0 == COERCE_DOUBLE(pop()) )
result = func1(LC7);
else
result = func1(0LL);
return result;
}

original_code:
void eq()
{
        Datum d1, d2;
        d2 = pop();
        d1 = pop();
        d1.val = (double)(d1.val == d2.val);
        push(d1);
}

canonical_original_code:
void eq()
{
        union Datum d1; union Datum d2;
        d2 = pop();
        d1 = pop();
        d1.val = (double)(d1.val == d2.val);
        push(d1);
}


ge

decompiled_code:
__int64 ge()
{
double v0; // rbx
__int64 v1; // xmm0_8

v0 = COERCE_DOUBLE(pop());
v1 = LC7;
if ( COERCE_DOUBLE(pop()) < v0 )
v1 = 0LL;
return push(v1);
}

canonical_decompiled_code:
__int64 func21()
{
double v0; // rbx
__int64 v1; // xmm0_8

v0 = COERCE_DOUBLE(pop());
v1 = LC7;
if ( COERCE_DOUBLE(pop()) < v0 )
v1 = 0LL;
return func1(v1);
}

original_code:
void ge()
{
        Datum d1, d2;
        d2 = pop();
        d1 = pop();
        d1.val = (double)(d1.val >= d2.val);
        push(d1);
}

canonical_original_code:
void ge()
{
        union Datum d1; union Datum d2;
        d2 = pop();
        d1 = pop();
        d1.val = (double)(d1.val >= d2.val);
        push(d1);
}


le

decompiled_code:
__int64 le()
{
double v0; // rbx
__int64 v1; // xmm0_8

v0 = COERCE_DOUBLE(pop());
v1 = LC7;
if ( v0 < COERCE_DOUBLE(pop()) )
v1 = 0LL;
return push(v1);
}

canonical_decompiled_code:
__int64 func22()
{
double v0; // rbx
__int64 v1; // xmm0_8

v0 = COERCE_DOUBLE(pop());
v1 = LC7;
if ( v0 < COERCE_DOUBLE(pop()) )
v1 = 0LL;
return func1(v1);
}

original_code:
void le()
{
 Datum d1, d2;
 d2 = pop();
 d1 = pop();
 d1.val = (double)(d1.val <= d2.val);
 push(d1);
}

canonical_original_code:
void le()
{
 union Datum d1; union Datum d2;
 d2 = pop();
 d1 = pop();
 d1.val = (double)(d1.val <= d2.val);
 push(d1);
}


ne

decompiled_code:
__int64 ne()
{
double v0; // rbx
__int64 result; // rax

v0 = COERCE_DOUBLE(pop());
if ( v0 == COERCE_DOUBLE(pop()) )
result = push(0LL);
else
result = push(LC7);
return result;
}

canonical_decompiled_code:
__int64 func23()
{
double v0; // rbx
__int64 result; // rax

v0 = COERCE_DOUBLE(pop());
if ( v0 == COERCE_DOUBLE(pop()) )
result = func1(0LL);
else
result = func1(LC7);
return result;
}

original_code:
void ne()
{
        Datum d1, d2;
        d2 = pop();
        d1 = pop();
        d1.val = (double)(d1.val != d2.val);
        push(d1);
}

canonical_original_code:
void ne()
{
        union Datum d1; union Datum d2;
        d2 = pop();
        d1 = pop();
        d1.val = (double)(d1.val != d2.val);
        push(d1);
}


and

decompiled_code:
__int64 and()
{
double v0; // rbx
__int64 result; // rax

v0 = COERCE_DOUBLE(pop());
if ( COERCE_DOUBLE(pop()) == 0.0 || v0 == 0.0 )
result = push(0LL);
else
result = push(LC7);
return result;
}

canonical_decompiled_code:
__int64 func24()
{
double v0; // rbx
__int64 result; // rax

v0 = COERCE_DOUBLE(pop());
if ( COERCE_DOUBLE(pop()) == 0.0 || v0 == 0.0 )
result = func1(0LL);
else
result = func1(LC7);
return result;
}

original_code:
void and()
{
        Datum d1, d2;
        d2 = pop();
        d1 = pop();
        d1.val = (double)(d1.val && d2.val);
        push(d1);
}

canonical_original_code:
void and()
{
        union Datum d1; union Datum d2;
        d2 = pop();
        d1 = pop();
        d1.val = (double)(d1.val && d2.val);
        push(d1);
}


or

decompiled_code:
__int64 or()
{
double v0; // rbx
__int64 result; // rax

v0 = COERCE_DOUBLE(pop());
if ( COERCE_DOUBLE(pop()) == 0.0 )
result = push(COERCE__INT64((double)(v0 != 0.0)));
else
result = push(LC7);
return result;
}

canonical_decompiled_code:
__int64 func25()
{
double v0; // rbx
__int64 result; // rax

v0 = COERCE_DOUBLE(pop());
if ( COERCE_DOUBLE(pop()) == 0.0 )
result = func1(COERCE__INT64((double)(v0 != 0.0)));
else
result = func1(LC7);
return result;
}

original_code:
void or()
{
        Datum d1, d2;
        d2 = pop();
        d1 = pop();
        d1.val = (double)(d1.val || d2.val);
        push(d1);
}

canonical_original_code:
void or()
{
        union Datum d1; union Datum d2;
        d2 = pop();
        d1 = pop();
        d1.val = (double)(d1.val || d2.val);
        push(d1);
}


not

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

if ( COERCE_DOUBLE(pop()) == 0.0 )
result = push(LC7);
else
result = push(0LL);
return result;
}

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

if ( COERCE_DOUBLE(pop()) == 0.0 )
result = func1(LC7);
else
result = func1(0LL);
return result;
}

original_code:
void not()
{
        Datum d;
        d = pop();
        d.val = (double)(!d.val);
        push(d);
}

canonical_original_code:
void not()
{
        union Datum d;
        d = pop();
        d.val = (double)(!d.val);
        push(d);
}


whilecode

decompiled_code:
__int64 whilecode()
{
__int64 v0; // rbx
__int64 (**v1)(void); // rbp
__int64 result; // rax

v0 = pc;
v1 = (__int64 (**)(void))(pc + 16);
execute((__int64 (**)(void))(pc + 16));
while ( COERCE_DOUBLE(pop()) != 0.0 )
{
execute(*(__int64 (***)(void))v0);
execute(v1);
}
result = *(_QWORD *)(v0 + 8);
pc = result;
return result;
}

original_code:
void whilecode()
{
 Datum d;
 Inst *savepc = pc;
 execute(savepc+2);
 d = pop();
 while(d.val) {
  execute(*((Inst **)(savepc)));
  execute(savepc+2);
  d = pop();
 }
 pc = *((Inst **)(savepc+1));
}

canonical_original_code:
void whilecode()
{
 union Datum d;
 int (**savepc)() = pc;
 execute(savepc+2);
 d = pop();
 while(d.val) {
  execute(*((int (***)())(savepc)));
  execute(savepc+2);
  d = pop();
 }
 pc = *((int (***)())(savepc+1));
}

variable_types:
savepc
int (**)()


ifcode

decompiled_code:
__int64 ifcode()
{
__int64 v0; // rbx
__int64 (**v1)(void); // rdi
__int64 result; // rax

v0 = pc;
execute((__int64 (**)(void))(pc + 24));
if ( COERCE_DOUBLE(pop()) == 0.0 )
{
v1 = *(__int64 (***)(void))(v0 + 8);
if ( v1 )
execute(v1);
result = *(_QWORD *)(v0 + 16);
pc = result;
}
else
{
execute(*(__int64 (***)(void))v0);
result = *(_QWORD *)(v0 + 16);
pc = result;
}
return result;
}

original_code:
void ifcode()
{
 Datum d;
 Inst *savepc = pc;
 execute(savepc+3);
 d = pop();
 if(d.val)
  execute(*((Inst **)(savepc)));
 else if (*((Inst **)(savepc+1)))
  execute(*((Inst **)(savepc+1)));
 pc = *((Inst **)(savepc+2));
}

canonical_original_code:
void ifcode()
{
 union Datum d;
 int (**savepc)() = pc;
 execute(savepc+3);
 d = pop();
 if(d.val)
  execute(*((int (***)())(savepc)));
 else if (*((int (***)())(savepc+1)))
  execute(*((int (***)())(savepc+1)));
 pc = *((int (***)())(savepc+2));
}


prexpr

decompiled_code:
int prexpr()
{
double v0; // rax

v0 = COERCE_DOUBLE(pop());
return printf("%.8g\n", v0);
}

canonical_decompiled_code:
int func29()
{
double v0; // rax

v0 = COERCE_DOUBLE(pop());
return printf("%.8g\n", v0);
}

original_code:
void prexpr()
{
 Datum d;
 d = pop();
 printf("%.8g\n", d.val);
}

canonical_original_code:
void prexpr()
{
 union Datum d;
 d = pop();
 printf("%.8g\n", d.val);
}


integer

decompiled_code:
double __fastcall integer(double a1)
{
return (double)(int)a1;
}

canonical_decompiled_code:
double __fastcall func0(double a1)
{
return (double)(int)a1;
}

original_code:
double integer(double x)
{
 return (double)(long)x;
}

variable_types: x double

return_type: double


errcheck

decompiled_code:
double __fastcall errcheck(__int64 a1, double result)
{
int *v2; // rax

v2 = _errno_location();
if ( *v2 == 33 )
{
*v2 = 0;
execerror(a1, "argument out of domain", result);
}
else if ( *v2 == 34 )
{
*v2 = 0;
execerror(a1, "result out of range", result);
}
return result;
}

canonical_decompiled_code:
double __fastcall func1(__int64 a1, double result)
{
int *v2; // rax

v2 = _errno_location();
if ( *v2 == 33 )
{
*v2 = 0;
execerror(a1, "argument out of domain", result);
}
else if ( *v2 == 34 )
{
*v2 = 0;
execerror(a1, "result out of range", result);
}
return result;
}

original_code:
double errcheck(double d, char *s)
{
 if ((*__errno_location ()) == 33) {
  (*__errno_location ()) = 0;
  execerror(s, "argument out of domain");
 } else if ((*__errno_location ()) == 34) {
  (*__errno_location ()) = 0;
  execerror(s, "result out of range");
 }
 return d;
}

variable_types: d double


Log

decompiled_code:
double __fastcall Log(double a1)
{
double v1; // xmm0_8

v1 = log(a1);
return errcheck((__int64)"log", v1);
}

canonical_decompiled_code:
double __fastcall func2(double a1)
{
double v1; // xmm0_8

v1 = log(a1);
return func1((__int64)"log", v1);
}

original_code:
double Log(double x)
{
 return errcheck(log(x), "log");
}


decompiled_code:
double __fastcall Log10(double a1)
{
double v1; // xmm0_8

v1 = log10(a1);
return errcheck((__int64)"log10", v1);
}

canonical_decompiled_code:
double __fastcall func3(double a1)
{
double v1; // xmm0_8

v1 = log10(a1);
return func1((__int64)"log10", v1);
}

original_code:
double Log10(double x)
{
 return errcheck(log10(x), "log10");
}


Exp

decompiled_code:
double __fastcall Exp(double a1)
{
double v1; // xmm0_8

v1 = exp(a1);
return errcheck((__int64)"exp", v1);
}

canonical_decompiled_code:
double __fastcall func4(double a1)
{
double v1; // xmm0_8

v1 = exp(a1);
return func1((__int64)"exp", v1);
}

original_code:
double Exp(double x)
{
 return errcheck(exp(x), "exp");
}


Sqrt

decompiled_code:
double __fastcall Sqrt(double a1)
{
double v2; // xmm0_8

if ( a1 >= 0.0 )
return errcheck((__int64)"sqrt", sqrt(a1));
v2 = sqrt(a1);
return errcheck((__int64)"sqrt", v2);
}

canonical_decompiled_code:
double __fastcall func5(double a1)
{
double v2; // xmm0_8

if ( a1 >= 0.0 )
return func1((__int64)"sqrt", sqrt(a1));
v2 = sqrt(a1);
return func1((__int64)"sqrt", v2);
}

original_code:
double Sqrt(double x)
{
 return errcheck(sqrt(x), "sqrt");
}


Pow

decompiled_code:
double __fastcall Pow(double a1, double a2)
{
double v2; // xmm0_8

v2 = pow(a1, a2);
return errcheck((__int64)"exponentiation", v2);
}

canonical_decompiled_code:
double __fastcall func6(double a1, double a2)
{
double v2; // xmm0_8

v2 = pow(a1, a2);
return func1((__int64)"exponentiation", v2);
}

original_code:
double Pow(double x, double y)
{
 return errcheck(pow(x,y), "exponentiation");
}

variable_types: y double


lookup

decompiled_code:
__int64 __fastcall lookup(char *s2)
{
__int64 i; // r12

for ( i = symlist; i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp(*(const char **)i, s2) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s2)
{
__int64 i; // r12

for ( i = symlist; i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp(*(const char **)i, s2) )
break;
}
return i;
}

original_code:
Symbol *lookup(char *s)
{
 Symbol *sp;
 for(sp = symlist; sp != (Symbol *) 0; sp = sp->next)
  if (strcmp(sp->name, s) == 0)
   return sp;
 return 0;
}

canonical_original_code:
struct Symbol *lookup(char *s)
{
 struct Symbol *sp;
 for(sp = symlist; sp != (struct Symbol *) 0; sp = sp->next)
  if (strcmp(sp->name, s) == 0)
   return sp;
 return 0;
}

variable_types: struct Symbol { char *name; short type; union { double val; double (*ptr)(); } u; struct Symbol *next; } *


emalloc

decompiled_code:
void *__fastcall emalloc(size_t size)
{
void *v1; // r12

v1 = malloc((unsigned int)size);
if ( !v1 )
execerror("out of memory", 0LL);
return v1;
}

canonical_decompiled_code:
void *__fastcall func1(size_t size)
{
void *v1; // r12

v1 = malloc((unsigned int)size);
if ( !v1 )
execerror("out of memory", 0LL);
return v1;
}

original_code:
char *emalloc(unsigned int n)
{
 char *p;
 p = (char *)malloc(n);
 if (p == 0)
  execerror("out of memory", (char *) 0);
 return p;
}

variable_types:
n
unsigned int

variable_types:
p
char *

return_type: char *


repo: rohkea/cantonese-tools

decompiled_code:
__int64 __fastcall find_written_form(char *s2, int a2, _DWORD *a3)
{
int v3; // er14
int v4; // er13
unsigned int v5; // er15
__int64 v6; // rbx
int v7; // eax
__int64 v9; // rbx
int v10; // er13
const char *v11; // r14
int v12; // er12
int v13; // eax
int v14; // [rsp+4h] [rbp-44h]

v3 = written_forms_length - 1;
if ( written_forms_length - 1 <= 1 )
{
v6 = 0LL;
v5 = 0;
}
else
{
v14 = written_forms_length - 1;
v4 = 0;
while ( 1 )
{
v3 >>= 1;
v5 = v3 + v4;
v6 = v3 + v4;
v7 = strncmp(s2, *((const char **)&written_forms + 2 * v6 + 1), a2);
if ( !v7 )
break;
if ( v7 < 0 )
{
v14 = v3 + v4;
}
else
{
v4 += v3;
v3 = v14 - v5;
}
if ( v3 <= 1 )
{
v9 = (int)(((unsigned int)v7 < 0x80000000) + v5 - 1);
do
{
v10 = v9;
v5 = v9;
v11 = (const char *)*((_QWORD *)&written_forms + 2 * v9 + 1);
v12 = strlen(v11);
v13 = strncmp(v11, s2, v12);
if ( !v13 )
{
*a3 = v12;
return v5;
}
--v9;
}
while ( v10 > 0 && v13 < 0 );
return (unsigned int)-1;
}
}
}
*a3 = strlen(*((const char **)&written_forms + 2 * v6 + 1));
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s2, int a2, _DWORD *a3)
{
int v3; // er14
int v4; // er13
unsigned int v5; // er15
__int64 v6; // rbx
int v7; // eax
__int64 v9; // rbx
int v10; // er13
const char *v11; // r14
int v12; // er12
int v13; // eax
int v14; // [rsp+4h] [rbp-44h]

v3 = written_forms_length - 1;
if ( written_forms_length - 1 <= 1 )
{
v6 = 0LL;
v5 = 0;
}
else
{
v14 = written_forms_length - 1;
v4 = 0;
while ( 1 )
{
v3 >>= 1;
v5 = v3 + v4;
v6 = v3 + v4;
v7 = strncmp(s2, *((const char **)&written_forms + 2 * v6 + 1), a2);
if ( !v7 )
break;
if ( v7 < 0 )
{
v14 = v3 + v4;
}
else
{
v4 += v3;
v3 = v14 - v5;
}
if ( v3 <= 1 )
{
v9 = (int)(((unsigned int)v7 < 0x80000000) + v5 - 1);
do
{
v10 = v9;
v5 = v9;
v11 = (const char *)*((_QWORD *)&written_forms + 2 * v9 + 1);
v12 = strlen(v11);
v13 = strncmp(v11, s2, v12);
if ( !v13 )
{
*a3 = v12;
return v5;
}
--v9;
}
while ( v10 > 0 && v13 < 0 );
return (unsigned int)-1;
}
}
}
*a3 = strlen(*((const char **)&written_forms + 2 * v6 + 1));
return v5;
}

original_code:
int
find_written_form(const char *text, int maxlen, int *len) {
 int from, to, id, compared, currlen;
 from = 0;
 to = written_forms_length -1;
 while (to - from > 1) {
  id = from + (to - from) / 2;
  compared = strncmp(text, written_forms[id].text, maxlen);
  if (compared == 0) {
   from = to = id;
  } else if (compared < 0) {
   to = id;
  } else {
   from = id;
  }
 }
 if (compared == 0) {
  *len = strlen(written_forms[id].text);
  return id;
 } else {
  if (compared < 0)
   id--;
  do {
   currlen = strlen(written_forms[id].text);
   compared = strncmp(written_forms[id].text, text, currlen);
   if (compared == 0) {
    *len = currlen;
    return id;
   }
   id--;
  } while (compared < 0 && id >= 0);
 }
 return -1;
}

canonical_original_code:
int find_written_form(char *text, int maxlen, int *len) {
 int from; int to; int id; int compared; int currlen;
 from = 0;
 to = written_forms_length -1;
 while (to - from > 1) {
  id = from + (to - from) / 2;
  compared = strncmp(text, written_forms[id].text, maxlen);
  if (compared == 0) {
   from = to = id;
  } else if (compared < 0) {
   to = id;
  } else {
   from = id;
  }
 }
 if (compared == 0) {
  *len = strlen(written_forms[id].text);
  return id;
 } else {
  if (compared < 0)
   id--;
  do {
   currlen = strlen(written_forms[id].text);
   compared = strncmp(written_forms[id].text, text, currlen);
   if (compared == 0) {
    *len = currlen;
    return id;
   }
   id--;
  } while (compared < 0 && id >= 0);
 }
 return -1;
}

variable_types:
text
char *

variable_types: maxlen int

variable_types:
len
int *

variable_types: from int

variable_types: to int

variable_types: id int

variable_types: compared int

variable_types: currlen int


original_code:
char *
parse_sentence(const char *sent, int maxlen) {
 char *result;
 int id, res_len, res_allocd, curr, unknown_start, unknown_len, known_len;
 res_allocd = 1024;
 res_len = 0;
 result = malloc(res_allocd);
 curr = 0;
 unknown_len = 0;
 if (!maxlen)
  maxlen = strlen(sent);
 if (sent[maxlen -1] == 0x0D)
  maxlen--;
 while (curr < maxlen) {
  id = find_written_form(&sent[curr], maxlen, &known_len);
  if (id == -1) {
   if (unknown_len <= 0) {
    unknown_start = curr;
    unknown_len = 1;
   }
   else {
    if ((sent[unknown_len] == '<' && sent[unknown_len + 1] == '[')
      || (sent[unknown_len] == ']'
       && sent[unknown_len + 1] == '>')) {
     append_to_result("<[", 1, &result, &res_allocd, &res_len);
     append_to_result(&sent[unknown_start], 1, &result, &res_allocd, &res_len);
     append_to_result("]> ", 3, &result, &res_allocd, &res_len);
     unknown_start = curr;
     unknown_len = 1;
    } else {
     ++unknown_len;
    }
   }
   ++curr;
  } else {
   if (unknown_len > 0) {
    append_to_result("<[", 2, &result, &res_allocd, &res_len);
    append_to_result(&sent[unknown_start], unknown_len, &result, &res_allocd, &res_len);
    append_to_result("]> ", 3, &result, &res_allocd, &res_len);
    unknown_len = 0;
   }
   append_to_result("<[", 2, &result, &res_allocd, &res_len);
   append_to_result(&sent[curr], known_len, &result, &res_allocd, &res_len);
   append_to_result("]>::", 4, &result, &res_allocd, &res_len);
   append_to_result(definitions[written_forms[id].def_id].text, 0, &result, &res_allocd, &res_len);
   append_to_result(" ", 1, &result, &res_allocd, &res_len);
   curr += known_len;
  }
 }
 if (unknown_len > 0) {
  append_to_result("<[", 2, &result, &res_allocd, &res_len);
  append_to_result(&sent[unknown_start], unknown_len, &result, &res_allocd, &res_len);
  append_to_result("]> ", 3, &result, &res_allocd, &res_len);
  unknown_len = 0;
 }
 return result;
}

canonical_original_code:
char *parse_sentence(char *sent, int maxlen) {
 char *result;
 int id; int res_len; int res_allocd; int curr; int unknown_start; int unknown_len; int known_len;
 res_allocd = 1024;
 res_len = 0;
 result = malloc(res_allocd);
 curr = 0;
 unknown_len = 0;
 if (!maxlen)
  maxlen = strlen(sent);
 if (sent[maxlen -1] == 0x0D)
  maxlen--;
 while (curr < maxlen) {
  id = find_written_form(&sent[curr], maxlen, &known_len);
  if (id == -1) {
   if (unknown_len <= 0) {
    unknown_start = curr;
    unknown_len = 1;
   }
   else {
    if ((sent[unknown_len] == '<' && sent[unknown_len + 1] == '[')
      || (sent[unknown_len] == ']'
       && sent[unknown_len + 1] == '>')) {
     append_to_result("<[", 1, &result, &res_allocd, &res_len);
     append_to_result(&sent[unknown_start], 1, &result, &res_allocd, &res_len);
     append_to_result("]> ", 3, &result, &res_allocd, &res_len);
     unknown_start = curr;
     unknown_len = 1;
    } else {
     ++unknown_len;
    }
   }
   ++curr;
  } else {
   if (unknown_len > 0) {
    append_to_result("<[", 2, &result, &res_allocd, &res_len);
    append_to_result(&sent[unknown_start], unknown_len, &result, &res_allocd, &res_len);
    append_to_result("]> ", 3, &result, &res_allocd, &res_len);
    unknown_len = 0;
   }
   append_to_result("<[", 2, &result, &res_allocd, &res_len);
   append_to_result(&sent[curr], known_len, &result, &res_allocd, &res_len);
   append_to_result("]>::", 4, &result, &res_allocd, &res_len);
   append_to_result(definitions[written_forms[id].def_id].text, 0, &result, &res_allocd, &res_len);
   append_to_result(" ", 1, &result, &res_allocd, &res_len);
   curr += known_len;
  }
 }
 if (unknown_len > 0) {
  append_to_result("<[", 2, &result, &res_allocd, &res_len);
  append_to_result(&sent[unknown_start], unknown_len, &result, &res_allocd, &res_len);
  append_to_result("]> ", 3, &result, &res_allocd, &res_len);
  unknown_len = 0;
 }
 return result;
}

variable_types:
sent
char *

variable_types:
result
char *

variable_types: curr int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char *v4; // rbp
char v6[2072]; // [rsp+0h] [rbp-818h] BYREF

do
{
while ( v6 != fgets(v6, 2048, stdin) )
{
if ( feof(stdin) )
return 0;
}
v3 = strlen(v6);
v4 = (char *)parse_sentence(v6, v3 - 1);
puts(v4);
free(v4);
}
while ( !feof(stdin) );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char *v4; // rbp
char v6[2072]; // [rsp+0h] [rbp-818h] BYREF

do
{
while ( v6 != fgets(v6, 2048, stdin) )
{
if ( feof(stdin) )
return 0;
}
v3 = strlen(v6);
v4 = (char *)func1(v6, v3 - 1);
puts(v4);
free(v4);
}
while ( !feof(stdin) );
return 0;
}

original_code:
int
main() {
 char buffer[2048], *r, *read;
 do {
  read = fgets(buffer, (sizeof(buffer)/sizeof(buffer[0])), stdin);
  if (read == buffer) {
   r = parse_sentence(buffer, strlen(buffer) -1);
   printf("%s\n", r);
   free(r);
  }
 } while (!feof(stdin));
}

canonical_original_code:
int main() {
 char buffer[2048]; char *r; char *read;
 do {
  read = fgets(buffer, (sizeof(buffer)/sizeof(buffer[0])), stdin);
  if (read == buffer) {
   r = parse_sentence(buffer, strlen(buffer) -1);
   printf("%s\n", r);
   free(r);
  }
 } while (!feof(stdin));
}

variable_types:
buffer
char [2048]

variable_types:
r
char *

variable_types:
read
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // er14
__int64 v5; // rbp
_BOOL8 v6; // r12
nfds_t v7; // rsi
__int64 v8; // r13
__int64 v9; // rdx
bool v10; // sf
__int16 v11; // ax
int v12; // eax
_BOOL8 v13; // r13
__int64 v15; // rax

parse_cli(argc, argv, envp);
if ( (unsigned int)dtbuf_init(&dtbuf, dtbufsize) )
{
fwrite("dtbuf initialization failed\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
v3 = 0;
v4 = 0;
v5 = 0LL;
while ( 1 )
{
while ( 1 )
{
LODWORD(v6) = 0;
v7 = 1LL;
v8 = get_time_ms();
if ( !v3 )
{
v6 = (unsigned int)dtbuf_is_full(&dtbuf, 1LL) == 0;
v7 = (int)v6 + 1;
}
if ( v4 )
{
v9 = v5 + delay - v8;
v10 = v9 < 0;
if ( v9 <= 0 )
LODWORD(v9) = -1;
v11 = 4 * (v10 || v5 + delay == v8);
}
else
{
LODWORD(v9) = -1;
v11 = 0;
}
fds_all.events = v11;
v12 = poll(&fds_all, v7, v9);
if ( v12 == -1 )
{
perror("poll()");
exit(3);
}
if ( !v12 )
break;
LODWORD(v13) = 0;
if ( fds_all.revents )
{
LODWORD(v13) = 1;
if ( (fds_all.revents & 0x14) != 0 )
v13 = dtbuf_read_chunk(&dtbuf, 1LL) <= 0;
}
if ( v6 )
{
if ( word_4040AE )
{
if ( (word_4040AE & 0x11) == 0 || (v15 = get_time_ms(), dtbuf_write_chunk(&dtbuf, 0LL, v15) <= 0) )
v3 = v6;
}
}
if ( !(unsigned int)dtbuf_is_empty(&dtbuf) )
{
v5 = dtbuf_next_timestamp(&dtbuf);
if ( v13 )
goto LABEL_31;
goto LABEL_26;
}
if ( v13 )
goto LABEL_31;
LABEL_20:
if ( v3 == 1 )
goto LABEL_31;
v4 = v3;
}
if ( dtbuf_read_chunk(&dtbuf, 1LL) <= 0 )
break;
if ( (unsigned int)dtbuf_is_empty(&dtbuf) )
goto LABEL_20;
v5 = dtbuf_next_timestamp(&dtbuf);
LABEL_26:
v4 = 1;
}
if ( !(unsigned int)dtbuf_is_empty(&dtbuf) )
dtbuf_next_timestamp(&dtbuf);
LABEL_31:
dtbuf_free(&dtbuf);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // er14
__int64 v5; // rbp
_BOOL8 v6; // r12
nfds_t v7; // rsi
__int64 v8; // r13
__int64 v9; // rdx
bool v10; // sf
__int16 v11; // ax
int v12; // eax
_BOOL8 v13; // r13
__int64 v15; // rax

func8(argc, argv, envp);
if ( (unsigned int)func9(&dtbuf, dtbufsize) )
{
fwrite("dtbuf initialization failed\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
v3 = 0;
v4 = 0;
v5 = 0LL;
while ( 1 )
{
while ( 1 )
{
LODWORD(v6) = 0;
v7 = 1LL;
v8 = func16();
if ( !v3 )
{
v6 = (unsigned int)func12(&dtbuf, 1LL) == 0;
v7 = (int)v6 + 1;
}
if ( v4 )
{
v9 = v5 + delay - v8;
v10 = v9 < 0;
if ( v9 <= 0 )
LODWORD(v9) = -1;
v11 = 4 * (v10 || v5 + delay == v8);
}
else
{
LODWORD(v9) = -1;
v11 = 0;
}
fds_all.events = v11;
v12 = poll(&fds_all, v7, v9);
if ( v12 == -1 )
{
perror("poll()");
exit(3);
}
if ( !v12 )
break;
LODWORD(v13) = 0;
if ( fds_all.revents )
{
LODWORD(v13) = 1;
if ( (fds_all.revents & 0x14) != 0 )
v13 = func15(&dtbuf, 1LL) <= 0;
}
if ( v6 )
{
if ( word_4040AE )
{
if ( (word_4040AE & 0x11) == 0 || (v15 = func16(), func14(&dtbuf, 0LL, v15) <= 0) )
v3 = v6;
}
}
if ( !(unsigned int)func11(&dtbuf) )
{
v5 = func13(&dtbuf);
if ( v13 )
goto LABEL_31;
goto LABEL_26;
}
if ( v13 )
goto LABEL_31;
LABEL_20:
if ( v3 == 1 )
goto LABEL_31;
v4 = v3;
}
if ( func15(&dtbuf, 1LL) <= 0 )
break;
if ( (unsigned int)func11(&dtbuf) )
goto LABEL_20;
v5 = func13(&dtbuf);
LABEL_26:
v4 = 1;
}
if ( !(unsigned int)func11(&dtbuf) )
func13(&dtbuf);
LABEL_31:
func10(&dtbuf);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    int r;
    int fds_count;
    int has_next_chunk = 0;
    time_ms next_chunk_timestamp = 0;
    time_ms now;
    time_ms wait_delay;
    int poll_stdin;
    int pollout_stdout;
    int timeout;
    int in_closed = 0;
    int out_closed = 0;
    parse_cli(argc, argv);
    if (dtbuf_init(&dtbuf, dtbufsize)) {
        fprintf(stderr, "dtbuf initialization failed\n");
        exit(1);
    }
    do {
        now = get_time_ms();
        poll_stdin = !in_closed && !dtbuf_is_full(&dtbuf);
        if (has_next_chunk) {
            wait_delay = next_chunk_timestamp + delay - now;
            if (wait_delay <= 0) {
                pollout_stdout = 1;
                timeout = -1;
            } else {
                pollout_stdout = 0;
                timeout = wait_delay;
            }
        } else {
            pollout_stdout = 0;
            timeout = -1;
        }
        fds_count = poll_stdin ? 2 : 1;
        fds_all[0].events = pollout_stdout ? 0x004 : 0;
        if ((r = poll(fds_all, fds_count, timeout)) == -1) {
            perror("poll()");
            exit(3);
        }
        if (r == 0) {
            if (dtbuf_read_chunk(&dtbuf, 1 ) <= 0) {
                out_closed = 1;
            }
        } else {
            if (fds_all[0].revents) {
                if (fds_all[0].revents & (0x004 | 0x010)) {
                    if (dtbuf_read_chunk(&dtbuf, 1 ) <= 0) {
                        out_closed = 1;
                    }
                } else {
                    out_closed = 1;
                }
            }
            if (poll_stdin && fds_all[1].revents) {
                if (fds_all[1].revents & (0x001 | 0x010)) {
                    now = get_time_ms();
                    if (dtbuf_write_chunk(&dtbuf, 0 , now) <= 0) {
                        in_closed = 1;
                    }
                } else {
                    in_closed = 1;
                }
            }
        }
        has_next_chunk = !dtbuf_is_empty(&dtbuf);
        if (has_next_chunk) {
            next_chunk_timestamp = dtbuf_next_timestamp(&dtbuf);
        }
    } while (!out_closed && (!in_closed || has_next_chunk));
    dtbuf_free(&dtbuf);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int r;
    int fds_count;
    int has_next_chunk = 0;
    long next_chunk_timestamp = 0;
    long now;
    long wait_delay;
    int poll_stdin;
    int pollout_stdout;
    int timeout;
    int in_closed = 0;
    int out_closed = 0;
    parse_cli(argc, argv);
    if (dtbuf_init(&dtbuf, dtbufsize)) {
        fprintf(stderr, "dtbuf initialization failed\n");
        exit(1);
    }
    do {
        now = get_time_ms();
        poll_stdin = !in_closed && !dtbuf_is_full(&dtbuf);
        if (has_next_chunk) {
            wait_delay = next_chunk_timestamp + delay - now;
            if (wait_delay <= 0) {
                pollout_stdout = 1;
                timeout = -1;
            } else {
                pollout_stdout = 0;
                timeout = wait_delay;
            }
        } else {
            pollout_stdout = 0;
            timeout = -1;
        }
        fds_count = poll_stdin ? 2 : 1;
        fds_all[0].events = pollout_stdout ? 0x004 : 0;
        if ((r = poll(fds_all, fds_count, timeout)) == -1) {
            perror("poll()");
            exit(3);
        }
        if (r == 0) {
            if (dtbuf_read_chunk(&dtbuf, 1 ) <= 0) {
                out_closed = 1;
            }
        } else {
            if (fds_all[0].revents) {
                if (fds_all[0].revents & (0x004 | 0x010)) {
                    if (dtbuf_read_chunk(&dtbuf, 1 ) <= 0) {
                        out_closed = 1;
                    }
                } else {
                    out_closed = 1;
                }
            }
            if (poll_stdin && fds_all[1].revents) {
                if (fds_all[1].revents & (0x001 | 0x010)) {
                    now = get_time_ms();
                    if (dtbuf_write_chunk(&dtbuf, 0 , now) <= 0) {
                        in_closed = 1;
                    }
                } else {
                    in_closed = 1;
                }
            }
        }
        has_next_chunk = !dtbuf_is_empty(&dtbuf);
        if (has_next_chunk) {
            next_chunk_timestamp = dtbuf_next_timestamp(&dtbuf);
        }
    } while (!out_closed && (!in_closed || has_next_chunk));
    dtbuf_free(&dtbuf);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: r int

variable_types: now long

variable_types: timeout int


decompiled_code:
int __fastcall print_syntax(const char *a1)
{
return fprintf(stderr, "Syntax: %s [-b <dtbufsize>] <delay>\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return fprintf(stderr, "Syntax: %s [-b <dtbufsize>] <delay>\n", a1);
}

original_code:
void print_syntax(char *arg0)
{
    fprintf(stderr, "Syntax: %s [-b <dtbufsize>] <delay>\n", arg0);
}


decompiled_code:
void __fastcall parse_cli(int a1, const char **a2)
{
__int64 *v2; // rbx
int v3; // er15
int v4; // edx
__int64 v5; // r12
__int64 v6; // rbp
int *v7; // rax
int *v8; // r14
__int64 v9; // rax
int v10; // ecx
int *v11; // rax
int *v12; // r14
int v13; // eax
int v14; // ecx
char *endptr[8]; // [rsp+18h] [rbp-40h] BYREF

if ( a1 > 1 )
{
v2 = (__int64 *)(a2 + 1);
v3 = 0;
v4 = 0;
v5 = (__int64)&a2[(unsigned int)(a1 - 2) + 2];
while ( 1 )
{
v6 = *v2;
if ( v4 == 1 )
goto LABEL_8;
if ( *(_BYTE *)v6 == 45 && *(_BYTE *)(v6 + 1) == 98 )
{
v4 = 1;
if ( !*(_BYTE *)(v6 + 2) )
goto LABEL_6;
v6 += 2LL;
LABEL_8:
if ( (v3 & 2) != 0 )
goto LABEL_39;
v7 = __errno_location();
*v7 = 0;
v8 = v7;
v9 = strtol((const char *)v6, endptr, 0);
v4 = *v8;
dtbufsize = v9;
if ( v4 )
goto LABEL_40;
v10 = (unsigned __int8)*endptr[0];
if ( v10 != 107 || endptr[0][1] )
{
if ( v10 != 109 || endptr[0][1] )
{
if ( v10 != 103 || endptr[0][1] )
{
if ( *endptr[0] )
{
fprintf(stderr, "dtbufsize value contains garbage: %s\n", endptr[0]);
goto LABEL_38;
}
}
else
{
dtbufsize = v9 << 30;
}
}
else
{
dtbufsize = v9 << 20;
}
}
else
{
dtbufsize = v9 << 10;
}
++v2;
v3 |= 2u;
if ( v2 == (__int64 *)v5 )
return;
}
else
{
if ( (v3 & 1) != 0 )
{
LABEL_39:
print_syntax(*a2);
exit(9);
}
v11 = __errno_location();
*v11 = 0;
v12 = v11;
v13 = strtol((const char *)v6, endptr, 0);
delay = v13;
v4 = *v12;
if ( *v12 )
{
LABEL_40:
perror("strtol()");
exit(10);
}
v14 = (unsigned __int8)*endptr[0];
if ( v14 != 115 || endptr[0][1] )
{
if ( v14 != 109 || endptr[0][1] )
{
if ( v14 != 104 || endptr[0][1] )
{
if ( *endptr[0] )
{
fprintf(stderr, "delay value contains garbage: %s\n", endptr[0]);
LABEL_38:
exit(9);
}
}
else
{
delay = 3600000 * v13;
}
}
else
{
delay = 60000 * v13;
}
}
else
{
delay = 1000 * v13;
}
v3 |= 1u;
LABEL_6:
if ( ++v2 == (__int64 *)v5 )
return;
}
}
}
}

canonical_decompiled_code:
void __fastcall func8(int a1, const char **a2)
{
__int64 *v2; // rbx
int v3; // er15
int v4; // edx
__int64 v5; // r12
__int64 v6; // rbp
int *v7; // rax
int *v8; // r14
__int64 v9; // rax
int v10; // ecx
int *v11; // rax
int *v12; // r14
int v13; // eax
int v14; // ecx
char *endptr[8]; // [rsp+18h] [rbp-40h] BYREF

if ( a1 > 1 )
{
v2 = (__int64 *)(a2 + 1);
v3 = 0;
v4 = 0;
v5 = (__int64)&a2[(unsigned int)(a1 - 2) + 2];
while ( 1 )
{
v6 = *v2;
if ( v4 == 1 )
goto LABEL_8;
if ( *(_BYTE *)v6 == 45 && *(_BYTE *)(v6 + 1) == 98 )
{
v4 = 1;
if ( !*(_BYTE *)(v6 + 2) )
goto LABEL_6;
v6 += 2LL;
LABEL_8:
if ( (v3 & 2) != 0 )
goto LABEL_39;
v7 = __errno_location();
*v7 = 0;
v8 = v7;
v9 = strtol((const char *)v6, endptr, 0);
v4 = *v8;
dtbufsize = v9;
if ( v4 )
goto LABEL_40;
v10 = (unsigned __int8)*endptr[0];
if ( v10 != 107 || endptr[0][1] )
{
if ( v10 != 109 || endptr[0][1] )
{
if ( v10 != 103 || endptr[0][1] )
{
if ( *endptr[0] )
{
fprintf(stderr, "dtbufsize value contains garbage: %s\n", endptr[0]);
goto LABEL_38;
}
}
else
{
dtbufsize = v9 << 30;
}
}
else
{
dtbufsize = v9 << 20;
}
}
else
{
dtbufsize = v9 << 10;
}
++v2;
v3 |= 2u;
if ( v2 == (__int64 *)v5 )
return;
}
else
{
if ( (v3 & 1) != 0 )
{
LABEL_39:
func7(*a2);
exit(9);
}
v11 = __errno_location();
*v11 = 0;
v12 = v11;
v13 = strtol((const char *)v6, endptr, 0);
delay = v13;
v4 = *v12;
if ( *v12 )
{
LABEL_40:
perror("strtol()");
exit(10);
}
v14 = (unsigned __int8)*endptr[0];
if ( v14 != 115 || endptr[0][1] )
{
if ( v14 != 109 || endptr[0][1] )
{
if ( v14 != 104 || endptr[0][1] )
{
if ( *endptr[0] )
{
fprintf(stderr, "delay value contains garbage: %s\n", endptr[0]);
LABEL_38:
exit(9);
}
}
else
{
delay = 3600000 * v13;
}
}
else
{
delay = 60000 * v13;
}
}
else
{
delay = 1000 * v13;
}
v3 |= 1u;
LABEL_6:
if ( ++v2 == (__int64 *)v5 )
return;
}
}
}
}

original_code:
void parse_cli(int argc, char *argv[])
{
    int ctx = 0;
    char *arg;
    int args_handled = 0;
    char *garbage;
    int i;
    for (i = 1; i < argc; i++) {
        arg = argv[i];
 handle_arg:
        if (ctx == 1) {
            if (args_handled & (1 << 1)) {
                print_syntax(argv[0]);
                exit(9);
            }
            (*__errno_location ()) = 0;
            dtbufsize = strtol(arg, &garbage, 0);
            if ((*__errno_location ())) {
                perror("strtol()");
                exit(10);
            }
            if (strcmp("k", garbage) == 0) {
                dtbufsize <<= 10;
            } else if (strcmp("m", garbage) == 0) {
                dtbufsize <<= 20;
            } else if (strcmp("g", garbage) == 0) {
                dtbufsize <<= 30;
            } else if (garbage[0] != '\0') {
                fprintf(stderr, "dtbufsize value contains garbage: %s\n",
                        garbage);
                exit(9);
            }
            args_handled |= (1 << 1);
            ctx = 0;
        } else if (strncmp("-b", arg, 2) == 0) {
            ctx = 1;
            if (strlen(&arg[2]) > 0) {
                arg = &arg[2];
                goto handle_arg;
            }
        } else {
            if (args_handled & 1) {
                print_syntax(argv[0]);
                exit(9);
            }
            (*__errno_location ()) = 0;
            delay = strtol(arg, &garbage, 0);
            if ((*__errno_location ())) {
                perror("strtol()");
                exit(10);
            }
            if (strcmp("s", garbage) == 0) {
                delay *= 1000;
            } else if (strcmp("m", garbage) == 0) {
                delay *= 60 * 1000;
            } else if (strcmp("h", garbage) == 0) {
                delay *= 60 * 60 * 1000;
            } else if (garbage[0] != '\0') {
                fprintf(stderr, "delay value contains garbage: %s\n", garbage);
                exit(9);
            }
            args_handled |= 1;
        }
    }
}

variable_types: ctx int

variable_types:
arg
char *

variable_types:
garbage
char *

variable_types: i int


decompiled_code:
__int64 __fastcall dtbuf_init(_QWORD *a1, __int64 a2)
{
void *v2; // rax
__int64 result; // rax

a1[2] = a2 + 4015;
v2 = malloc(a2 + 4015);
*a1 = v2;
if ( !v2 )
return 1LL;
a1[1] = a2;
result = 0LL;
a1[3] = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, __int64 a2)
{
void *v2; // rax
__int64 result; // rax

a1[2] = a2 + 4015;
v2 = malloc(a2 + 4015);
*a1 = v2;
if ( !v2 )
return 1LL;
a1[1] = a2;
result = 0LL;
a1[3] = 0LL;
return result;
}

original_code:
int dtbuf_init(struct dtbuf *dtbuf, size_t capacity)
{
    dtbuf->real_capacity = capacity + (sizeof (struct header) + 4000) - 1;
    if (!(dtbuf->data = malloc(dtbuf->real_capacity))) {
        return 1;
    }
    dtbuf->capacity = capacity;
    dtbuf->head = 0;
    dtbuf->tail = 0;
    return 0;
}

canonical_original_code:
int dtbuf_init(struct dtbuf *dtbuf, unsigned long capacity)
{
    dtbuf->real_capacity = capacity + (sizeof (struct header) + 4000) - 1;
    if (!(dtbuf->data = malloc(dtbuf->real_capacity))) {
        return 1;
    }
    dtbuf->capacity = capacity;
    dtbuf->head = 0;
    dtbuf->tail = 0;
    return 0;
}

variable_types: struct dtbuf { char *data; unsigned long capacity; unsigned long real_capacity; int head; int tail; } *

variable_types:
capacity
unsigned long

user_defined_types: struct header { long timestamp; unsigned short data_length; }


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

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

original_code:
void dtbuf_free(struct dtbuf *dtbuf)
{
    free(dtbuf->data);
}

user_defined_types: struct dtbuf { char *data; unsigned long capacity; unsigned long real_capacity; int head; int tail; }


decompiled_code:
_BOOL8 __fastcall dtbuf_is_empty(__int64 a1)
{
return *(_DWORD *)(a1 + 24) == *(_DWORD *)(a1 + 28);
}

original_code:
int dtbuf_is_empty(struct dtbuf *dtbuf)
{
    return dtbuf->head == dtbuf->tail;
}


decompiled_code:
_BOOL8 __fastcall dtbuf_is_full(__int64 a1)
{
_BOOL8 result; // rax
unsigned __int64 v2; // rdx
int v3; // ecx

result = 1LL;
v2 = *(int *)(a1 + 24);
if ( v2 < *(_QWORD *)(a1 + 8) )
{
v3 = *(_DWORD *)(a1 + 28);
result = 0LL;
if ( (int)v2 < v3 )
result = v3 - (int)v2 <= 4016;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(__int64 a1)
{
_BOOL8 result; // rax
unsigned __int64 v2; // rdx
int v3; // ecx

result = 1LL;
v2 = *(int *)(a1 + 24);
if ( v2 < *(_QWORD *)(a1 + 8) )
{
v3 = *(_DWORD *)(a1 + 28);
result = 0LL;
if ( (int)v2 < v3 )
result = v3 - (int)v2 <= 4016;
}
return result;
}

original_code:
int dtbuf_is_full(struct dtbuf *dtbuf)
{
    return dtbuf->head >= dtbuf->capacity || (dtbuf->head < dtbuf->tail
                                              && dtbuf->tail - dtbuf->head <=
                                              (sizeof (struct header) + 4000));
}


decompiled_code:
__int64 __fastcall dtbuf_next_timestamp(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)a1 + *(int *)(a1 + 28));
}

original_code:
time_ms dtbuf_next_timestamp(struct dtbuf *dtbuf)
{
    struct header *header = (struct header *) &dtbuf->data[dtbuf->tail];
    return header->timestamp;
}

canonical_original_code:
long dtbuf_next_timestamp(struct dtbuf *dtbuf)
{
    struct header *header = (struct header *) &dtbuf->data[dtbuf->tail];
    return header->timestamp;
}

variable_types: struct header { long timestamp; unsigned short data_length; } *

return_type: long


decompiled_code:
ssize_t __fastcall dtbuf_write_chunk(__int64 *a1, int a2, __int64 a3)
{
int v4; // ebp
ssize_t result; // rax
__int64 v6; // rdx
__int64 v7; // rcx
int v8; // ebp

v4 = *((_DWORD *)a1 + 6) + 16;
result = read(a2, (void *)(*a1 + v4), 0xFA0uLL);
if ( result <= 0 )
{
if ( result == -1 )
{
perror("read()");
result = -1LL;
}
}
else
{
v6 = *((int *)a1 + 6);
v7 = *a1;
v8 = result + v4;
*(_QWORD *)(v7 + v6) = a3;
*(_QWORD *)(v7 + v6 + 8) = (unsigned __int16)result;
*((_DWORD *)a1 + 6) = v8;
if ( v8 >= (unsigned __int64)a1[1] && *((_DWORD *)a1 + 7) > 0xFAFu )
*((_DWORD *)a1 + 6) = 0;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func14(__int64 *a1, int a2, __int64 a3)
{
int v4; // ebp
ssize_t result; // rax
__int64 v6; // rdx
__int64 v7; // rcx
int v8; // ebp

v4 = *((_DWORD *)a1 + 6) + 16;
result = read(a2, (void *)(*a1 + v4), 0xFA0uLL);
if ( result <= 0 )
{
if ( result == -1 )
{
perror("read()");
result = -1LL;
}
}
else
{
v6 = *((int *)a1 + 6);
v7 = *a1;
v8 = result + v4;
*(_QWORD *)(v7 + v6) = a3;
*(_QWORD *)(v7 + v6 + 8) = (unsigned __int16)result;
*((_DWORD *)a1 + 6) = v8;
if ( v8 >= (unsigned __int64)a1[1] && *((_DWORD *)a1 + 7) > 0xFAFu )
*((_DWORD *)a1 + 6) = 0;
}
return result;
}

original_code:
ssize_t dtbuf_write_chunk(struct dtbuf *dtbuf, int fd_in, time_ms timestamp)
{
    ssize_t r;
    struct header header;
    int payload_index = dtbuf->head + sizeof(struct header);
    if ((r = read(fd_in, &dtbuf->data[payload_index],
                  4000)) > 0) {
        header.timestamp = timestamp;
        header.data_length = (chunk_length) r;
        memcpy(&dtbuf->data[dtbuf->head], &header, sizeof(header));
        dtbuf->head = payload_index + r;
        if (dtbuf->head >= dtbuf->capacity && dtbuf->tail >= (sizeof (struct header) + 4000)) {
            dtbuf->head = 0;
        }
    } else if (r == -1) {
        perror("read()");
    }
    return r;
}

canonical_original_code:
long dtbuf_write_chunk(struct dtbuf *dtbuf, int fd_in, long timestamp)
{
    long r;
    struct header header;
    int payload_index = dtbuf->head + sizeof(struct header);
    if ((r = read(fd_in, &dtbuf->data[payload_index],
                  4000)) > 0) {
        header.timestamp = timestamp;
        header.data_length = (unsigned short) r;
        memcpy(&dtbuf->data[dtbuf->head], &header, sizeof(header));
        dtbuf->head = payload_index + r;
        if (dtbuf->head >= dtbuf->capacity && dtbuf->tail >= (sizeof (struct header) + 4000)) {
            dtbuf->head = 0;
        }
    } else if (r == -1) {
        perror("read()");
    }
    return r;
}

variable_types: timestamp long

variable_types: r long

variable_types: struct header { long timestamp; unsigned short data_length; }


decompiled_code:
ssize_t __fastcall dtbuf_read_chunk(__int64 *a1, int a2)
{
__int64 *v3; // r13
size_t v4; // r12
int v5; // ebp
ssize_t result; // rax
__int64 v7; // rdi
int v8; // ecx
__int64 v9; // rdx
__int64 v10; // rcx
unsigned __int64 v11; // rcx
unsigned __int64 v12; // rdx

v3 = (__int64 *)(*a1 + *((int *)a1 + 7));
v4 = *((unsigned __int16 *)v3 + 4);
v5 = *((_DWORD *)a1 + 7) + 16;
result = write(a2, (const void *)(*a1 + v5), v4);
if ( result <= 0 )
{
if ( result == -1 )
{
perror("write()");
result = -1LL;
}
return result;
}
if ( v4 != result )
{
v7 = *v3;
v8 = result + *((_DWORD *)a1 + 7);
*((_DWORD *)a1 + 7) = v8;
v9 = v8;
v10 = *a1;
*(_QWORD *)(v10 + v9) = v7;
*(_QWORD *)(v10 + v9 + 8) = (unsigned __int16)(v4 - result);
v11 = a1[1];
LABEL_4:
if ( *((int *)a1 + 6) >= v11 && *((_DWORD *)a1 + 7) > 0xFAFu )
goto LABEL_6;
return result;
}
v11 = a1[1];
*((_DWORD *)a1 + 7) = v5 + result;
if ( v5 + (int)result < v11 )
goto LABEL_4;
v12 = *((int *)a1 + 6);
*((_DWORD *)a1 + 7) = 0;
if ( v11 <= v12 )
LABEL_6:
*((_DWORD *)a1 + 6) = 0;
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func15(__int64 *a1, int a2)
{
__int64 *v3; // r13
size_t v4; // r12
int v5; // ebp
ssize_t result; // rax
__int64 v7; // rdi
int v8; // ecx
__int64 v9; // rdx
__int64 v10; // rcx
unsigned __int64 v11; // rcx
unsigned __int64 v12; // rdx

v3 = (__int64 *)(*a1 + *((int *)a1 + 7));
v4 = *((unsigned __int16 *)v3 + 4);
v5 = *((_DWORD *)a1 + 7) + 16;
result = write(a2, (const void *)(*a1 + v5), v4);
if ( result <= 0 )
{
if ( result == -1 )
{
perror("write()");
result = -1LL;
}
return result;
}
if ( v4 != result )
{
v7 = *v3;
v8 = result + *((_DWORD *)a1 + 7);
*((_DWORD *)a1 + 7) = v8;
v9 = v8;
v10 = *a1;
*(_QWORD *)(v10 + v9) = v7;
*(_QWORD *)(v10 + v9 + 8) = (unsigned __int16)(v4 - result);
v11 = a1[1];
LABEL_4:
if ( *((int *)a1 + 6) >= v11 && *((_DWORD *)a1 + 7) > 0xFAFu )
goto LABEL_6;
return result;
}
v11 = a1[1];
*((_DWORD *)a1 + 7) = v5 + result;
if ( v5 + (int)result < v11 )
goto LABEL_4;
v12 = *((int *)a1 + 6);
*((_DWORD *)a1 + 7) = 0;
if ( v11 <= v12 )
LABEL_6:
*((_DWORD *)a1 + 6) = 0;
return result;
}

original_code:
ssize_t dtbuf_read_chunk(struct dtbuf *dtbuf, int fd_out)
{
    ssize_t w;
    struct header *pheader = (struct header *) &dtbuf->data[dtbuf->tail];
    struct header header;
    chunk_length length = pheader->data_length;
    int payload_index = dtbuf->tail + sizeof(struct header);
    if ((w = write(fd_out, &dtbuf->data[payload_index], length)) > 0) {
        if (w == length) {
            dtbuf->tail = payload_index + w;
            if (dtbuf->tail >= dtbuf->capacity) {
                dtbuf->tail = 0;
                if (dtbuf->head >= dtbuf->capacity) {
                    dtbuf->head = 0;
                }
            }
        } else {
            dtbuf->tail += w;
            header.timestamp = pheader->timestamp;
            header.data_length = length - w;
            memcpy(&dtbuf->data[dtbuf->tail], &header, sizeof(header));
        }
        if (dtbuf->head >= dtbuf->capacity && dtbuf->tail >= (sizeof (struct header) + 4000)) {
            dtbuf->head = 0;
        }
    } else if (w == -1) {
        perror("write()");
    }
    return w;
}

canonical_original_code:
long dtbuf_read_chunk(struct dtbuf *dtbuf, int fd_out)
{
    long w;
    struct header *pheader = (struct header *) &dtbuf->data[dtbuf->tail];
    struct header header;
    unsigned short length = pheader->data_length;
    int payload_index = dtbuf->tail + sizeof(struct header);
    if ((w = write(fd_out, &dtbuf->data[payload_index], length)) > 0) {
        if (w == length) {
            dtbuf->tail = payload_index + w;
            if (dtbuf->tail >= dtbuf->capacity) {
                dtbuf->tail = 0;
                if (dtbuf->head >= dtbuf->capacity) {
                    dtbuf->head = 0;
                }
            }
        } else {
            dtbuf->tail += w;
            header.timestamp = pheader->timestamp;
            header.data_length = length - w;
            memcpy(&dtbuf->data[dtbuf->tail], &header, sizeof(header));
        }
        if (dtbuf->head >= dtbuf->capacity && dtbuf->tail >= (sizeof (struct header) + 4000)) {
            dtbuf->head = 0;
        }
    } else if (w == -1) {
        perror("write()");
    }
    return w;
}

variable_types: w long

variable_types:
length
unsigned short