// File: /workspace/github_c_makefile_star2_O2/gaultier[P]lox-c/vm.c
// Function: vm_run_bytecode
Result vm_run_bytecode(Vm* vm) {
    assert(vm->frame_len > 0);
    CallFrame* frame = &vm->frames[vm->frame_len - 1];

    while (true) {
        uint8_t opcode = 0;
        read_u8(vm, &opcode);
        const Location* const loc = get_location(vm);

        LOG("opcode=%d %s\n", opcode, opcode_str[opcode]);

        switch (opcode) {
            case OP_RETURN: {
                stack_log(vm);
                Value return_value = {0};
                RETURN_IF_ERR(stack_pop(vm, &return_value));

                vm->frame_len--;
                stack_log(vm);

                if (vm->frame_len == 0) {  // End of script
                    LOG("final pop%s\n", "");
                    RETURN_IF_ERR(stack_pop(vm, &return_value));
                    return RES_OK;
                }

                vm->stack_top = frame->slots;
                RETURN_IF_ERR(stack_push(vm, return_value));

                frame = &vm->frames[vm->frame_len - 1];

                break;
            }
            case OP_NEGATE: {
                Value value = {0};
                RETURN_IF_ERR(stack_pop(vm, &value));

                if (!IS_NUMBER(value)) {
                    VM_ERROR(vm, loc, "Negation: expected a number, got: %s",
                             value_to_str_debug(value));
                }

                RETURN_IF_ERR(stack_push(vm, NUMBER_VAL(-AS_NUMBER(value))));
                break;
            }
            case OP_ADD: {
                Value rhs = {0};
                RETURN_IF_ERR(stack_pop(vm, &rhs));
                Value lhs = {0};
                RETURN_IF_ERR(stack_pop(vm, &lhs));

                if (IS_STRING(lhs) && IS_STRING(rhs)) {
                    Value v = {0};
                    str_cat(vm, lhs, rhs, &v);

                    RETURN_IF_ERR(stack_push(vm, v));
                    break;
                }

                if ((IS_STRING(lhs) && !IS_STRING(rhs))) {
                    VM_ERROR(vm, loc,
                             "Addition: cannot concatenate a non-string type, "
                             "got: %s",
                             value_to_str_debug(rhs));
                }

                if ((IS_STRING(rhs) && !IS_STRING(lhs))) {
                    VM_ERROR(vm, loc,
                             "Addition: cannot concatenate a non-string type, "
                             "got: %s",
                             value_to_str_debug(lhs));
                }

                if (!IS_NUMBER(lhs)) {
                    VM_ERROR(vm, loc, "Addition: expected a number, got: %s",
                             value_to_str_debug(lhs));
                }

                if (!IS_NUMBER(rhs)) {
                    VM_ERROR(vm, loc, "Addition: expected a number, got: %s",
                             value_to_str_debug(rhs));
                }

                // TODO: Check for underflow/overflow
                RETURN_IF_ERR(stack_push(
                    vm, NUMBER_VAL(AS_NUMBER(lhs) + AS_NUMBER(rhs))));
                break;
            }
            case OP_SUBTRACT: {
                Value rhs = {0};
                RETURN_IF_ERR(stack_pop(vm, &rhs));
                if (!IS_NUMBER(rhs)) {
                    VM_ERROR(vm, loc, "Subtraction: expected a number, got: %s",
                             value_to_str_debug(rhs));
                }

                Value lhs = {0};
                RETURN_IF_ERR(stack_pop(vm, &lhs));
                if (!IS_NUMBER(lhs)) {
                    VM_ERROR(vm, loc, "Subtraction: expected a number, got: %s",
                             value_to_str_debug(lhs));
                }

                // TODO: Check for underflow/overflow
                RETURN_IF_ERR(stack_push(
                    vm, NUMBER_VAL(AS_NUMBER(lhs) - AS_NUMBER(rhs))));
                break;
            }
            case OP_MULTIPLY: {
                Value rhs = {0};
                RETURN_IF_ERR(stack_pop(vm, &rhs));
                if (!IS_NUMBER(rhs)) {
                    VM_ERROR(vm, loc,
                             "Multiplication: expected a number, got: %s",
                             value_to_str_debug(rhs));
                }

                Value lhs = {0};
                RETURN_IF_ERR(stack_pop(vm, &lhs));
                if (!IS_NUMBER(lhs)) {
                    VM_ERROR(vm, loc,
                             "Multiplication: expected a number, got: %s",
                             value_to_str_debug(lhs));
                }

                // TODO: Check for underflow/overflow
                RETURN_IF_ERR(stack_push(
                    vm, NUMBER_VAL(AS_NUMBER(lhs) * AS_NUMBER(rhs))));
                break;
            }
            case OP_DIVIDE: {
                Value rhs = {0};
                RETURN_IF_ERR(stack_pop(vm, &rhs));
                if (!IS_NUMBER(rhs)) {
                    VM_ERROR(vm, loc, "Division: expected a number, got: %s",
                             value_to_str_debug(rhs));
                }

                Value lhs = {0};
                RETURN_IF_ERR(stack_pop(vm, &lhs));
                if (!IS_NUMBER(lhs)) {
                    VM_ERROR(vm, loc, "Division: expected a number, got: %s",
                             value_to_str_debug(lhs));
                }

                RETURN_IF_ERR(stack_push(
                    vm, NUMBER_VAL(AS_NUMBER(lhs) / AS_NUMBER(rhs))));
                break;
            }
            case OP_CONSTANT: {
                Value v = {0};
                RETURN_IF_ERR(read_constant(vm, &v));
                RETURN_IF_ERR(stack_push(vm, v));
            } break;
            case OP_NIL:
                RETURN_IF_ERR(stack_push(vm, NIL_VAL));
                break;
            case OP_TRUE:
                RETURN_IF_ERR(stack_push(vm, BOOL_VAL(true)));
                break;
            case OP_FALSE:
                RETURN_IF_ERR(stack_push(vm, BOOL_VAL(false)));
                break;
            case OP_NOT: {
                Value v = {0};
                RETURN_IF_ERR(stack_pop(vm, &v));
                RETURN_IF_ERR(stack_push(vm, BOOL_VAL(value_is_falsy(v))));
                break;
            }
            case OP_EQUAL: {
                Value rhs = {0};
                RETURN_IF_ERR(stack_pop(vm, &rhs));
                Value lhs = {0};
                RETURN_IF_ERR(stack_pop(vm, &lhs));
                RETURN_IF_ERR(stack_push(vm, BOOL_VAL(value_eq(lhs, rhs))));
                break;
            }
            case OP_LESS: {
                Value rhs = {0};
                RETURN_IF_ERR(stack_pop(vm, &rhs));
                if (!IS_NUMBER(rhs)) {
                    VM_ERROR(vm, loc, "Comparison:expected a number, got: %s",
                             value_to_str_debug(rhs));
                }

                Value lhs = {0};
                RETURN_IF_ERR(stack_pop(vm, &lhs));
                if (!IS_NUMBER(lhs)) {
                    VM_ERROR(vm, loc, "Comparison:expected a number, got: %s",
                             value_to_str_debug(lhs));
                }

                // TODO: Check for 0
                RETURN_IF_ERR(
                    stack_push(vm, BOOL_VAL(AS_NUMBER(lhs) < AS_NUMBER(rhs))));
                break;
            }
            case OP_GREATER: {
                Value rhs = {0};
                RETURN_IF_ERR(stack_pop(vm, &rhs));
                if (!IS_NUMBER(rhs)) {
                    VM_ERROR(vm, loc, "Comparison:expected a number, got: %s",
                             value_to_str_debug(rhs));
                }

                Value lhs = {0};
                RETURN_IF_ERR(stack_pop(vm, &lhs));
                if (!IS_NUMBER(lhs)) {
                    VM_ERROR(vm, loc, "Comparison:expected a number, got: %s",
                             value_to_str_debug(lhs));
                }

                // TODO: Check for 0
                RETURN_IF_ERR(
                    stack_push(vm, BOOL_VAL(AS_NUMBER(lhs) > AS_NUMBER(rhs))));
                break;
            }
            case OP_PRINT: {
                Value value = {0};
                RETURN_IF_ERR(stack_pop(vm, &value));
                printf("%s\n", value_to_str(value));
            } break;
            case OP_POP: {
                Value value = {0};
                RETURN_IF_ERR(stack_pop(vm, &value));
            } break;
            case OP_DEFINE_GLOBAL: {
                Value name = {0};
                RETURN_IF_ERR(read_constant(vm, &name));

                Value value = {0};
                RETURN_IF_ERR(stack_pop(vm, &value));

                ht_insert(vm->globals, AS_CSTRING(name), AS_STRING(name)->len,
                          &value, sizeof(value));
                LOG("def global name=%.*s value=%s\n",
                    (int)AS_STRING(name)->len, AS_CSTRING(name),
                    value_to_str_debug(value));

                LOG("stack size: %zu\n", stack_len(vm));
                break;
            }
            case OP_GET_GLOBAL: {
                Value name = {0};
                RETURN_IF_ERR(read_constant(vm, &name));

                char* const s = AS_CSTRING(name);
                const size_t s_len = AS_STRING(name)->len;
                Value* value = ht_search(vm->globals, s, s_len);

                if (!value) {
                    VM_ERROR(vm, loc, "Undefined global variable `%.*s`",
                             (int)s_len, s);
                }

                LOG("get global name=%.*s value=%s\n", (int)s_len, s,
                    value_to_str_debug(*value));
                RETURN_IF_ERR(stack_push(vm, *value));
                break;
            }
            case OP_SET_GLOBAL: {
                Value name = {0};
                RETURN_IF_ERR(read_constant(vm, &name));

                char* const s = AS_CSTRING(name);
                const size_t s_len = AS_STRING(name)->len;
                Value* const value = ht_search(vm->globals, s, s_len);
                if (!value) {
                    VM_ERROR(vm, loc, "Undefined global variable `%.*s`",
                             (int)s_len, s);
                }

                RETURN_IF_ERR(stack_peek_from_top_at(vm, value, 0));
                LOG("set global name=%.*s value=%s\n", (int)s_len, s,
                    value_to_str_debug(*value));

                break;
            }
            case OP_GET_LOCAL: {
                uint8_t slot = 0;
                RETURN_IF_ERR(read_u8(vm, &slot));

                RETURN_IF_ERR(stack_push(vm, frame->slots[slot]));
                LOG("OP_GET_LOCAL local_index=%d v=%s\n", slot,
                    value_to_str_debug(frame->slots[slot]));

                stack_log(vm);
                break;
            }
            case OP_SET_LOCAL: {
                uint8_t slot = 0;
                RETURN_IF_ERR(read_u8(vm, &slot));

                Value v = {0};
                RETURN_IF_ERR(stack_peek_from_top_at(vm, &v, 0));
                frame->slots[slot] = v;
                stack_log(vm);

                break;
            }
            case OP_JUMP_IF_FALSE: {
                uint16_t jump = 0;
                RETURN_IF_ERR(read_u16(vm, &jump));

                Value v = {0};
                RETURN_IF_ERR(stack_peek_from_top_at(vm, &v, 0));
                frame->ip += jump * (size_t)(value_is_falsy(v));
            } break;
            case OP_JUMP: {
                uint16_t jump = 0;
                RETURN_IF_ERR(read_u16(vm, &jump));
                frame->ip += jump;
            } break;
            case OP_LOOP: {
                uint16_t jump = 0;
                RETURN_IF_ERR(read_u16(vm, &jump));
                frame->ip -= jump;
            } break;
            case OP_CALL: {
                uint8_t arg_count = 0;
                RETURN_IF_ERR(read_u8(vm, &arg_count));

                Value callee = {0};
                RETURN_IF_ERR(stack_peek_from_top_at(vm, &callee, arg_count));
                RETURN_IF_ERR(value_call(vm, callee, arg_count));
                LOG("stack top after call=%s\n",
                    value_to_str_debug(*(vm->stack_top - 1)));

                frame = &vm->frames[vm->frame_len - 1];

                LOG("called f=%.*s slots[0]=%s\n", (int)frame->fn->name_len,
                    frame->fn->name, value_to_str_debug(frame->slots[0]));

                break;
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movsbq 0x40618(%rdi), %rax
testq %rax, %rax
jle 0x4c49
movq %rdi, %rbx
leaq 0x40018(%rdi), %r13
decl %eax
imulq $0x18, %rax, %rax
addq %rdi, %rax
addq $0x40018, %rax          # imm = 0x40018
movq %rax, 0x38(%rsp)
leaq 0x40008(%rdi), %rax
movq %rax, 0x50(%rsp)
leaq 0xf(%rsp), %rbp
leaq 0x2cc8(%rip), %r15      # 0x6de4
movq %r13, 0x48(%rsp)
movb $0x0, 0xf(%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3ee8
movq %rbx, %rdi
callq 0x3f7c
movq %rax, %r12
movzbl 0xf(%rsp), %eax
cmpq $0x18, %rax
ja 0x4121
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rsi
movapd %xmm0, (%rsi)
movq %rbx, %rdi
callq 0x4c68
decb 0x40618(%rbx)
je 0x498e
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x40000(%rbx)
movl 0x10(%rsp), %esi
movq 0x18(%rsp), %rdx
movq %rbx, %rdi
callq 0x4ca7
movsbq 0x40618(%rbx), %rax
imulq $0x18, %rax, %rax
addq %r13, %rax
addq $-0x18, %rax
movq %rax, 0x38(%rsp)
jmp 0x4121
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3fd4
leaq 0x20(%rsp), %r15
xorpd %xmm0, %xmm0
movapd %xmm0, (%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4c68
movq 0x40010(%rbx), %rdi
movq 0x8(%r14), %rsi
movq 0x10(%rsi), %rdx
addq $0x18, %rsi
pushq $0x10
popq %r8
movq %r15, %rcx
leaq 0x2be2(%rip), %r15      # 0x6de4
callq 0x1401
jmp 0x4121
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c68
movl (%r14), %edi
movq 0x8(%r14), %rsi
callq 0x3a8a
movq %rax, %rdi
callq 0x1060
jmp 0x4121
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c68
leaq 0x20(%rsp), %r15
xorpd %xmm0, %xmm0
movapd %xmm0, (%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4c68
movl (%r15), %edi
movq 0x8(%r15), %rsi
leaq 0x2b66(%rip), %r15      # 0x6de4
movl (%r14), %edx
movq 0x8(%r14), %rcx
callq 0x3916
jmp 0x4814
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c68
movl (%r14), %edi
cmpl $0x2, %edi
jne 0x4a1e
leaq 0x20(%rsp), %r14
xorpd %xmm0, %xmm0
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c68
movl (%r14), %edi
cmpl $0x2, %edi
jne 0x4ac1
movsd 0x28(%rsp), %xmm0
subsd 0x18(%rsp), %xmm0
jmp 0x4789
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c68
movl (%r14), %edi
cmpl $0x2, %edi
jne 0x49af
leaq 0x20(%rsp), %r14
xorpd %xmm0, %xmm0
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c68
movl (%r14), %edi
cmpl $0x2, %edi
jne 0x49f5
movsd 0x28(%rsp), %xmm0
xorl %edx, %edx
ucomisd 0x18(%rsp), %xmm0
jmp 0x472b
movq %rbx, %rdi
xorl %esi, %esi
jmp 0x453c
leaq 0x47(%rsp), %r14
movb $0x0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3ee8
xorpd %xmm0, %xmm0
leaq 0x20(%rsp), %r15
movapd %xmm0, (%r15)
movzbl (%r14), %r14d
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4d8d
movl (%r15), %ebp
movq 0x8(%r15), %r15
movq %rbx, %rdi
callq 0x3f7c
cmpl $0x3, %ebp
jne 0x4b66
movl (%r15), %ecx
cmpl $0x1, %ecx
je 0x494d
cmpl $0x2, %ecx
jne 0x49a2
movq 0x10(%r15), %rax
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rcx
movapd %xmm0, (%rcx)
movq 0x40000(%rbx), %rsi
movl %r14d, %edx
shll $0x4, %edx
subq %rdx, %rsi
movq %rbx, %rdi
movl %r14d, %edx
callq *%rax
movl %eax, %ebp
testl %eax, %eax
jne 0x495d
notq %r14
shlq $0x4, %r14
addq %r14, 0x40000(%rbx)
movl 0x10(%rsp), %esi
movq 0x18(%rsp), %rdx
movq %rbx, %rdi
callq 0x4ca7
jmp 0x495d
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c68
movl (%r14), %edi
cmpl $0x2, %edi
jne 0x4a3b
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
xorq 0x18(%rsp), %rdx
jmp 0x478e
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x4c68
jmp 0x4121
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rsi
movapd %xmm0, (%rsi)
movq %rbx, %rdi
callq 0x4c68
leaq 0x20(%rsp), %r14
xorpd %xmm0, %xmm0
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c68
movl (%r14), %ebp
movq 0x8(%r14), %r13
movl %ebp, %edi
movq %r13, %rsi
xorl %edx, %edx
callq 0x398e
testb %al, %al
je 0x48b2
movl 0x10(%rsp), %r15d
movq 0x18(%rsp), %r14
movl %r15d, %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x398e
testb %al, %al
je 0x48b2
movl %ebp, %edi
movq %r13, %rsi
xorl %edx, %edx
callq 0x398e
testb %al, %al
je 0x4c13
movl %r15d, %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x398e
testb %al, %al
je 0x4c2c
movq 0x10(%r13), %r15
addq $0x18, %r13
movq 0x10(%r14), %r12
addq $0x18, %r14
leaq (%r12,%r15), %rsi
movq 0x50(%rsp), %rdi
callq 0x399c
movq %rax, %rbp
leaq 0x18(%rax), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x1160
leaq (%r15,%rbp), %rdi
addq $0x18, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x1160
pushq $0x3
popq %rsi
movq %rbx, %rdi
movq %rbp, %rdx
jmp 0x4932
pushq $0x1
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x4ca7
jmp 0x4121
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3fd4
movl (%r14), %esi
movq 0x8(%r14), %rdx
jmp 0x487e
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3fd4
movq 0x8(%r14), %r14
movq 0x10(%r14), %r15
addq $0x18, %r14
movq 0x40010(%rbx), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1396
testq %rax, %rax
je 0x49c9
movl (%rax), %esi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x4ca7
leaq 0x2822(%rip), %r15      # 0x6de4
jmp 0x4121
leaq 0x20(%rsp), %r14
movb $0x0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3ee8
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r15
movaps %xmm0, (%r15)
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x4d8d
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movzbl (%r14), %ecx
shll $0x4, %ecx
movapd (%r15), %xmm0
leaq 0x27d4(%rip), %r15      # 0x6de4
movupd %xmm0, (%rax,%rcx)
jmp 0x4121
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c68
movl (%r14), %edi
cmpl $0x2, %edi
jne 0x4a7e
leaq 0x20(%rsp), %r14
xorpd %xmm0, %xmm0
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c68
movl (%r14), %edi
cmpl $0x2, %edi
jne 0x4aea
movsd 0x28(%rsp), %xmm0
mulsd 0x18(%rsp), %xmm0
jmp 0x4789
leaq 0x20(%rsp), %r14
andw $0x0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4071
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r15
movapd %xmm0, (%r15)
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x4d8d
movzwl (%r14), %r14d
movl (%r15), %edi
movq 0x8(%r15), %rsi
leaq 0x272a(%rip), %r15      # 0x6de4
callq 0x3900
testb %al, %al
cmoveq %r12, %r14
movq 0x38(%rsp), %rax
addq %r14, 0x8(%rax)
jmp 0x4121
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c68
movl (%r14), %edi
cmpl $0x2, %edi
jne 0x49af
leaq 0x20(%rsp), %r14
xorpd %xmm0, %xmm0
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c68
movl (%r14), %edi
cmpl $0x2, %edi
jne 0x49f5
movsd 0x18(%rsp), %xmm0
xorl %edx, %edx
ucomisd 0x28(%rsp), %xmm0
seta %dl
jmp 0x481c
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c68
movl (%r14), %edi
cmpl $0x2, %edi
jne 0x4a64
leaq 0x20(%rsp), %r14
xorpd %xmm0, %xmm0
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c68
movl (%r14), %edi
cmpl $0x2, %edi
jne 0x4a98
movsd 0x28(%rsp), %xmm0
divsd 0x18(%rsp), %xmm0
movq %xmm0, %rdx
pushq $0x2
popq %rsi
jmp 0x487e
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3fd4
movq 0x8(%r14), %r14
movq 0x10(%r14), %r15
addq $0x18, %r14
movq 0x40010(%rbx), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1396
testq %rax, %rax
je 0x49c9
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x4d8d
leaq 0x25fa(%rip), %r15      # 0x6de4
jmp 0x4121
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c68
movl (%r14), %edi
movq 0x8(%r14), %rsi
callq 0x3900
movzbl %al, %edx
jmp 0x481c
pushq $0x1
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4ca7
jmp 0x4121
leaq 0x10(%rsp), %r14
andw $0x0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4071
movzwl (%r14), %eax
movq 0x38(%rsp), %rcx
addq %rax, 0x8(%rcx)
jmp 0x4121
leaq 0x10(%rsp), %r14
movb $0x0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3ee8
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movzbl (%r14), %ecx
shll $0x4, %ecx
movl (%rax,%rcx), %esi
movq 0x8(%rax,%rcx), %rdx
movq %rbx, %rdi
callq 0x4ca7
jmp 0x4121
leaq 0x10(%rsp), %r14
andw $0x0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4071
movzwl (%r14), %eax
movq 0x38(%rsp), %rcx
subq %rax, 0x8(%rcx)
jmp 0x4121
movl %ebp, %edi
movq %r13, %rsi
xorl %edx, %edx
callq 0x398e
movl 0x10(%rsp), %r15d
movq 0x18(%rsp), %r14
testb %al, %al
je 0x48e1
movl %r15d, %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x398e
testb %al, %al
je 0x4b93
movl %r15d, %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x398e
testb %al, %al
je 0x4906
movl %ebp, %edi
movq %r13, %rsi
xorl %edx, %edx
callq 0x398e
testb %al, %al
je 0x4bc0
cmpl $0x2, %ebp
jne 0x4b13
cmpl $0x2, %r15d
jne 0x4b3c
movq %r13, %xmm0
movq %r14, %xmm1
addsd %xmm0, %xmm1
movq %xmm1, %rdx
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x4ca7
movq 0x48(%rsp), %r13
leaq 0xf(%rsp), %rbp
leaq 0x249c(%rip), %r15      # 0x6de4
jmp 0x4121
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
callq 0x52fd
movl %eax, %ebp
leaq 0x2480(%rip), %r15      # 0x6de4
testl %ebp, %ebp
jne 0x4c02
movsbq 0x40618(%rbx), %rax
imulq $0x18, %rax, %rax
addq %r13, %rax
addq $-0x18, %rax
movq %rax, 0x38(%rsp)
leaq 0xf(%rsp), %rbp
jmp 0x4121
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x4c68
xorl %ebp, %ebp
jmp 0x4c02
testl %ecx, %ecx
je 0x4b63
jmp 0x4c02
movq 0x763a(%rip), %rax      # 0xbff0
movq (%rax), %r14
movq (%r12), %r15
movq 0x8(%r12), %r12
movq 0x18(%rsp), %rsi
jmp 0x4a0d
movq 0x7620(%rip), %rax      # 0xbff0
movq (%rax), %rdi
movq (%r12), %rdx
movq 0x8(%r12), %rcx
leaq 0x379c(%rip), %rsi      # 0x817f
movl %r15d, %r8d
movq %r14, %r9
xorl %eax, %eax
callq 0x1140
jmp 0x4bf7
movq 0x75f4(%rip), %rax      # 0xbff0
movq (%rax), %r14
movq (%r12), %r15
movq 0x8(%r12), %r12
movq 0x28(%rsp), %rsi
callq 0x3b97
leaq 0x3737(%rip), %rsi      # 0x8150
jmp 0x4be4
movq 0x75cb(%rip), %rax      # 0xbff0
movq (%rax), %r14
movq (%r12), %r15
movq 0x8(%r12), %r12
movq 0x18(%rsp), %rsi
jmp 0x4ad9
movq 0x75ae(%rip), %rax      # 0xbff0
movq (%rax), %r14
movq (%r12), %r15
movq 0x8(%r12), %r12
movq 0x18(%rsp), %rsi
callq 0x3b97
leaq 0x35c1(%rip), %rsi      # 0x8020
jmp 0x4be4
movq 0x7585(%rip), %rax      # 0xbff0
movq (%rax), %r14
movq (%r12), %r15
movq 0x8(%r12), %r12
movq 0x18(%rsp), %rsi
jmp 0x4ab0
movq 0x756b(%rip), %rax      # 0xbff0
movq (%rax), %r14
movq (%r12), %r15
movq 0x8(%r12), %r12
movq 0x18(%rsp), %rsi
jmp 0x4b02
movq 0x7551(%rip), %rax      # 0xbff0
movq (%rax), %r14
movq (%r12), %r15
movq 0x8(%r12), %r12
movq 0x28(%rsp), %rsi
callq 0x3b97
leaq 0x3666(%rip), %rsi      # 0x8122
jmp 0x4be4
movq 0x7528(%rip), %rax      # 0xbff0
movq (%rax), %r14
movq (%r12), %r15
movq 0x8(%r12), %r12
movq 0x28(%rsp), %rsi
callq 0x3b97
leaq 0x35d8(%rip), %rsi      # 0x80bd
jmp 0x4be4
movq 0x74ff(%rip), %rax      # 0xbff0
movq (%rax), %r14
movq (%r12), %r15
movq 0x8(%r12), %r12
movq 0x28(%rsp), %rsi
callq 0x3b97
leaq 0x35e0(%rip), %rsi      # 0x80ee
jmp 0x4be4
movq 0x74d6(%rip), %rax      # 0xbff0
movq (%rax), %r14
movq (%r12), %r15
movq 0x8(%r12), %r12
movl %ebp, %edi
movq %r13, %rsi
callq 0x3b97
leaq 0x3558(%rip), %rsi      # 0x808f
jmp 0x4be4
movq 0x74ad(%rip), %rax      # 0xbff0
movq (%rax), %r13
movq (%r12), %rbp
movq 0x8(%r12), %r12
movl %r15d, %edi
movq %r14, %rsi
callq 0x3b97
leaq 0x352e(%rip), %rsi      # 0x808f
jmp 0x4bb8
pushq $0x3
popq %rbp
movq 0x7483(%rip), %rcx      # 0xbff0
movq (%rcx), %r14
movq (%rax), %r12
movq 0x8(%rax), %r13
movl %ebp, %edi
movq %r15, %rsi
callq 0x3b97
leaq 0x38a4(%rip), %rsi      # 0x842c
movq %r14, %rdi
movq %r12, %rdx
movq %r13, %rcx
jmp 0x4bed
movq 0x7456(%rip), %rax      # 0xbff0
movq (%rax), %r13
movq (%r12), %rbp
movq 0x8(%r12), %r12
movl %r15d, %edi
movq %r14, %rsi
callq 0x3b97
leaq 0x3496(%rip), %rsi      # 0x804e
movq %r13, %rdi
movq %rbp, %rdx
jmp 0x4bea
movq 0x7429(%rip), %rax      # 0xbff0
movq (%rax), %r14
movq (%r12), %r15
movq 0x8(%r12), %r12
movl %ebp, %edi
movq %r13, %rsi
callq 0x3b97
leaq 0x346a(%rip), %rsi      # 0x804e
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x1140
movq %rbx, %rdi
callq 0x4cea
pushq $0x2
popq %rbp
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x376c(%rip), %rdi      # 0x8386
leaq 0x3341(%rip), %rsi      # 0x7f62
leaq 0x376d(%rip), %rcx      # 0x8395
pushq $0x3e
jmp 0x4c43
leaq 0x378c(%rip), %rdi      # 0x83bf
leaq 0x3328(%rip), %rsi      # 0x7f62
leaq 0x3754(%rip), %rcx      # 0x8395
pushq $0x3f
popq %rdx
callq 0x10f0
leaq 0x3300(%rip), %rdi      # 0x7f50
leaq 0x330b(%rip), %rsi      # 0x7f62
leaq 0x33a5(%rip), %rcx      # 0x8003
movl $0x1a1, %edx            # imm = 0x1A1
callq 0x10f0