// File: /workspace/github_c_makefile_star2_O1/masyagin1998[P]GCI/src/bytecode-generator/bytecode-generator.c
// Function: dump_bytecode_to_xml_file
void dump_bytecode_to_xml_file(FILE*f, const bytecode_type_t bc)
{
    size_t i;
    
    fprintf(f, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    fprintf(f, "<bytecode>\n");

    fprintf(f, "\t<constant_pool>\n");
    for (i = 0; i < bc->constant_pool_len; i++) {
        switch (bc->constant_pool[i].type) {
        case CONSTANT_TYPE_INTEGER:
            fprintf(f, "\t\t<int_cnst idx=\"%zu\">%lld</int_cnst>\n", i, bc->constant_pool[i].int_cnst);
            break;
        case CONSTANT_TYPE_DOUBLE:
            fprintf(f, "\t\t<double_cnst idx=\"%zu\">%lf</double_cnst>\n", i, bc->constant_pool[i].double_cnst);
            break;
        case CONSTANT_TYPE_FIELDREF:
            fprintf(f, "\t\t<fieldref_cnst idx=\"%zu\">%s</fieldref_cnst>\n", i, bc->constant_pool[i].str_cnst);
            break;
        case CONSTANT_TYPE_FUNCTIONREF:
            fprintf(f, "\t\t<functionref_cnst idx=\"%zu\">%s</functionref_cnst>\n", i, bc->constant_pool[i].str_cnst);
            break;
        }
    }
    fprintf(f, "\t</constant_pool>\n");

    fprintf(f, "\t<op_codes>\n");
    
    i = 0;
    while (i < bc->op_codes_len) {
        size_t j, n;
        
        switch (bc->op_codes[i]) {
        case BC_OP_POP:
            fprintf(f, "\t\t<op>POP<op>\n");
            break;

        case BC_OP_CONSTANT:
            i++;
            fprintf(f, "\t\t<op>CONSTANT %zu</op>\n", bc->op_codes[i]);
            break;

        case BC_OP_GET_LOCAL:
            i++;
            fprintf(f, "\t\t<op>GET_LOCAL %zu</op>\n", bc->op_codes[i]);
            break;
        case BC_OP_SET_LOCAL:
            i++;
            fprintf(f, "\t\t<op>SET_LOCAL %zu</op>\n", bc->op_codes[i]);
            break;

        case BC_OP_CREATE_OBJ:
            i++;
            fprintf(f, "\t\t<op>CREATE_OBJ %zu</op>\n", bc->op_codes[i]);
            break;
        case BC_OP_INIT_OBJ_PROP:
            i++;
            fprintf(f, "\t\t<op>INIT_OBJ_PROP %zu</op>\n", bc->op_codes[i]);
            break;

        case BC_OP_CREATE_ARR:
            i++;
            fprintf(f, "\t\t<op>CREATE_ARR %zu</op>\n", bc->op_codes[i]);
            break;

        case BC_OP_GET_HEAP:
        case BC_OP_SET_HEAP:
            if (bc->op_codes[i] == BC_OP_GET_HEAP) {
                i++;
                fprintf(f, "\t\t<op>GET_HEAP %zu", bc->op_codes[i]);
            } else if (bc->op_codes[i] == BC_OP_SET_HEAP) {
                i++;
                fprintf(f, "\t\t<op>SET_HEAP %zu", bc->op_codes[i]);
            }

            i++;
            n = bc->op_codes[i];
            i++;
            for (j = 0; j < n; j++) {
                if (bc->op_codes[i] == BC_OBJECT_FIELD) {
                    i++;
                    fprintf(f, " field(%zu)", bc->op_codes[i]);
                } else if (bc->op_codes[i] == BC_ARRAY_INDEX) {
                    i++;
                    fprintf(f, " index(%zu)", bc->op_codes[i]);
                }
                i++;
            }
            i--;
            fprintf(f, "</op>\n");
            break;

        case BC_OP_APPEND:
        case BC_OP_DELETE:
            break;
            
        case BC_OP_LOGICAL_OR:
            fprintf(f, "\t\t<op>LOGICAL_OR</op>\n");
            break;
        case BC_OP_LOGICAL_AND:
            fprintf(f, "\t\t<op>LOGICAL_AND</op>\n");
            break;

        case BC_OP_EQ_EQEQ:
            fprintf(f, "\t\t<op>EQ_EQEQ</op>\n");
            break;
        case BC_OP_EQ_NEQ:
            fprintf(f, "\t\t<op>EQ_NEQ</op>\n");
            break;

        case BC_OP_REL_LT:
            fprintf(f, "\t\t<op>REL_LT</op>\n");            
            break;
        case BC_OP_REL_GT:
            fprintf(f, "\t\t<op>REL_GT</op>\n");            
            break;
        case BC_OP_REL_LE:
            fprintf(f, "\t\t<op>REL_LE</op>\n");            
            break;
        case BC_OP_REL_GE:
            fprintf(f, "\t\t<op>REL_GE</op>\n");            
            break;

        case BC_OP_ADDITIVE_PLUS:
            fprintf(f, "\t\t<op>ADDITIVE_PLUS</op>\n");
            break;
        case BC_OP_ADDITIVE_MINUS:
            fprintf(f, "\t\t<op>ADDITIVE_MINUS</op>\n");
            break;

        case BC_OP_MULTIPLICATIVE_MUL:
            fprintf(f, "\t\t<op>MULTIPLICATIVE_MUL</op>\n");
            break;
        case BC_OP_MULTIPLICATIVE_DIV:
            fprintf(f, "\t\t<op>MULTIPLICATIVE_DIV</op>\n");
            break;
        case BC_OP_MULTIPLICATIVE_MOD:
            fprintf(f, "\t\t<op>MULTIPLICATIVE_MOD</op>\n");
            break;

        case BC_OP_NEGATE:
            fprintf(f, "\t\t<op>NEGATE</op>\n");
            break;

        case BC_OP_LEN:
            fprintf(f, "\t\t<op>LEN</op>\n");
            break;
        case BC_OP_HAS_PROPERTY:
            i++;
            fprintf(f, "\t\t<op>HAS_PROPERTY %zu</op>\n", bc->op_codes[i]);
            break;            

        case BC_OP_JUMP_IF_FALSE:
            i++;
            fprintf(f, "\t\t<op>JUMP_IF_FALSE %d</op>\n", (int) bc->op_codes[i]);
            break;
        case BC_OP_JUMP:
            i++;
            fprintf(f, "\t\t<op>JUMP %d</op>\n", (int) bc->op_codes[i]);
            break;

        case BC_OP_RETURN:
            fprintf(f, "\t\t<op>RETURN</op>\n");
            break;
        }

        i++;
    }
    fprintf(f, "\t</op_codes>\n");    

    fprintf(f, "</bytecode>\n");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x3cd6(%rip), %rdi      # 0xf62c
movl $0x27, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x1190
leaq 0x49c9(%rip), %rdi      # 0x10338
movl $0xb, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x1190
leaq 0x49bc(%rip), %rdi      # 0x10344
movl $0x11, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x1190
cmpq $0x0, 0x20(%r14)
je 0xba26
leaq 0x4898(%rip), %r12      # 0x10244
leaq 0x4a25(%rip), %rbp      # 0x103d8
xorl %r13d, %r13d
xorl %r15d, %r15d
movq 0x18(%r14), %rcx
movl 0x20(%rcx,%r13), %eax
cmpq $0x3, %rax
ja 0xba19
addq %r13, %rcx
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movq (%rcx), %rcx
movq %rbx, %rdi
leaq 0x4975(%rip), %rsi      # 0x10356
jmp 0xb9f5
movq %rbx, %rdi
leaq 0x49bc(%rip), %rsi      # 0x103a9
jmp 0xb9f5
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x1100
jmp 0xba19
movsd (%rcx), %xmm0
movq %rbx, %rdi
leaq 0x496e(%rip), %rsi      # 0x1037d
movq %r15, %rdx
movb $0x1, %al
callq 0x1100
incq %r15
addq $0x28, %r13
cmpq 0x20(%r14), %r15
jb 0xb9b9
leaq 0x49e0(%rip), %rdi      # 0x1040d
movl $0x12, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x1190
leaq 0x49da(%rip), %rdi      # 0x10420
movl $0xc, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x1190
cmpq $0x0, 0x8(%r14)
je 0xbcc3
xorl %r15d, %r15d
leaq 0x4a70(%rip), %r12      # 0x104dd
leaq 0x47e0(%rip), %r13      # 0x10254
movq (%r14), %rax
movq (%rax,%r15,8), %rcx
cmpq $0x1e, %rcx
ja 0xbc99
movslq (%r13,%rcx,4), %rcx
addq %r13, %rcx
movq %r12, %rsi
jmpq *%rcx
leaq 0x4994(%rip), %rdi      # 0x1042d
movl $0xe, %esi
jmp 0xbc8c
leaq 0x4b2d(%rip), %rdi      # 0x105d7
movl $0x1a, %esi
jmp 0xbc8c
leaq 0x4b75(%rip), %rdi      # 0x10630
jmp 0xbc79
movl 0x8(%rax,%r15,8), %edx
incq %r15
leaq 0x4bc0(%rip), %rsi      # 0x1068f
jmp 0xbcb7
movq 0x8(%rax,%r15,8), %rdx
incq %r15
leaq 0x4b8f(%rip), %rsi      # 0x10672
jmp 0xbc38
leaq 0x4a6f(%rip), %rdi      # 0x1055e
jmp 0xbc87
leaq 0x4a4f(%rip), %rdi      # 0x1054a
movl $0x13, %esi
jmp 0xbc8c
leaq 0x4b43(%rip), %rdi      # 0x1064f
jmp 0xbc87
leaq 0x4ada(%rip), %rdi      # 0x105f2
jmp 0xbc79
movq 0x8(%rax,%r15,8), %rdx
incq %r15
leaq 0x4996(%rip), %rsi      # 0x104c2
jmp 0xbc38
movq 0x8(%rax,%r15,8), %rdx
incq %r15
leaq 0x492f(%rip), %rsi      # 0x1046f
jmp 0xbc38
movq 0x8(%rax,%r15,8), %rdx
incq %r15
leaq 0x4935(%rip), %rsi      # 0x10489
jmp 0xbc38
movq 0x8(%rax,%r15,8), %rdx
incq %r15
leaq 0x48d4(%rip), %rsi      # 0x1043c
jmp 0xbc38
leaq 0x4aee(%rip), %rdi      # 0x10662
movl $0xf, %esi
jmp 0xbc8c
leaq 0x4996(%rip), %rdi      # 0x1051b
movl $0x16, %esi
jmp 0xbc8c
leaq 0x495a(%rip), %rsi      # 0x104f0
movq 0x8(%rax,%r15,8), %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1100
movq (%r14), %rax
movq 0x10(%rax,%r15,8), %rbp
addq $0x3, %r15
testq %rbp, %rbp
je 0xbbf2
movq (%r14), %rax
movq (%rax,%r15,8), %rcx
cmpq $0x1, %rcx
je 0xbbd1
testq %rcx, %rcx
jne 0xbbea
leaq 0x4940(%rip), %rsi      # 0x1050f
jmp 0xbbd8
leaq 0x492b(%rip), %rsi      # 0x10503
movq 0x8(%rax,%r15,8), %rdx
incq %r15
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1100
incq %r15
decq %rbp
jne 0xbbb6
decq %r15
leaq 0x430a(%rip), %rdi      # 0xff06
movl $0x6, %esi
jmp 0xbc8c
leaq 0x4977(%rip), %rdi      # 0x10584
jmp 0xbc87
movq 0x8(%rax,%r15,8), %rdx
incq %r15
leaq 0x4837(%rip), %rsi      # 0x10455
jmp 0xbc38
leaq 0x4970(%rip), %rdi      # 0x10597
jmp 0xbc87
movq 0x8(%rax,%r15,8), %rdx
incq %r15
leaq 0x486c(%rip), %rsi      # 0x104a4
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1100
jmp 0xbc99
leaq 0x4972(%rip), %rdi      # 0x105bd
movl $0x19, %esi
jmp 0xbc8c
leaq 0x48d9(%rip), %rdi      # 0x10532
movl $0x17, %esi
jmp 0xbc8c
leaq 0x4943(%rip), %rdi      # 0x105aa
jmp 0xbc87
leaq 0x4901(%rip), %rdi      # 0x10571
jmp 0xbc87
leaq 0x4998(%rip), %rdi      # 0x10611
movl $0x1e, %esi
jmp 0xbc8c
leaq 0x4a39(%rip), %rdi      # 0x106c0
movl $0x12, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x1190
incq %r15
cmpq 0x8(%r14), %r15
jb 0xba74
jmp 0xbcc3
movl 0x8(%rax,%r15,8), %edx
incq %r15
leaq 0x49f5(%rip), %rsi      # 0x106ac
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1100
jmp 0xbc99
leaq 0x4a09(%rip), %rdi      # 0x106d3
movl $0xd, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x1190
leaq 0x49fe(%rip), %rdi      # 0x106e1
movl $0xc, %esi
movl $0x1, %edx
movq %rbx, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1190