// File: /workspace/github_c_makefile_star2_O3/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 $0x68, %rsp
movsbq 0x40618(%rdi), %rax
testq %rax, %rax
jle 0x5aab
movq %rdi, %rbx
leaq 0x40018(%rdi), %r13
decl %eax
leaq (%rax,%rax,2), %rax
leaq (%rdi,%rax,8), %rax
addq $0x40018, %rax          # imm = 0x40018
movq %rax, 0x8(%rsp)
leaq 0x40008(%rdi), %rax
movq %rax, 0x58(%rsp)
leaq 0x7(%rsp), %rbp
leaq 0x3022(%rip), %r15      # 0x7e24
movq %r13, 0x30(%rsp)
movb $0x0, 0x7(%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4bca
movq %rbx, %rdi
callq 0x4c5f
movq %rax, %r12
movzbl 0x7(%rsp), %eax
cmpq $0x18, %rax
ja 0x4e07
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movq 0x40000(%rbx), %rax
cmpq %rbx, %rax
je 0x5a2f
leaq -0x10(%rax), %rsi
movq %rsi, 0x40000(%rbx)
movl -0x10(%rax), %ecx
movq -0x8(%rax), %rdx
decb 0x40618(%rbx)
je 0x58a0
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x40000(%rbx)
movq %rax, %rsi
subq %rbx, %rsi
cmpq $0x3fff0, %rsi          # imm = 0x3FFF0
jae 0x5a4e
movl %ecx, (%rax)
movq %rdx, 0x8(%rax)
addq $0x10, 0x40000(%rbx)
jmp 0x587f
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rsi
movaps %xmm0, (%rsi)
movq %rbx, %rdi
callq 0x4cb9
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq 0x40000(%rbx), %rax
cmpq %rbx, %rax
je 0x5a2f
leaq -0x10(%rax), %rcx
movq %rcx, 0x40000(%rbx)
movupd -0x10(%rax), %xmm0
leaq 0x40(%rsp), %rcx
movapd %xmm0, (%rcx)
movq 0x40010(%rbx), %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsi), %rdx
addq $0x18, %rsi
movl $0x10, %r8d
callq 0x1eae
jmp 0x4e07
movq 0x40000(%rbx), %rax
cmpq %rbx, %rax
je 0x5a2f
leaq -0x10(%rax), %rcx
movq %rcx, 0x40000(%rbx)
movl -0x10(%rax), %edi
movq -0x8(%rax), %rsi
callq 0x4743
movq %rax, %rdi
callq 0x1060
jmp 0x4e07
movq 0x40000(%rbx), %rax
cmpq %rbx, %rax
je 0x5a2f
leaq -0x10(%rax), %rcx
movq %rcx, 0x40000(%rbx)
cmpq %rbx, %rcx
je 0x5a2f
movq -0x8(%rax), %rcx
movl -0x10(%rax), %edx
leaq -0x20(%rax), %rsi
movq %rsi, 0x40000(%rbx)
movl -0x20(%rax), %edi
movq -0x18(%rax), %rsi
callq 0x45be
jmp 0x569f
movq 0x40000(%rbx), %rax
cmpq %rbx, %rax
je 0x5a2f
leaq -0x10(%rax), %rcx
movq %rcx, 0x40000(%rbx)
movl -0x10(%rax), %esi
movsd -0x8(%rax), %xmm0
cmpl $0x2, %esi
jne 0x592c
cmpq %rbx, %rcx
je 0x5a2f
leaq -0x20(%rax), %rcx
movq %rcx, 0x40000(%rbx)
movl -0x20(%rax), %esi
movsd -0x18(%rax), %xmm1
cmpl $0x2, %esi
jne 0x5984
subq %rbx, %rcx
cmpq $0x3fff0, %rcx          # imm = 0x3FFF0
jae 0x5a4e
subsd %xmm0, %xmm1
jmp 0x5606
movq 0x40000(%rbx), %rax
cmpq %rbx, %rax
je 0x5a2f
leaq -0x10(%rax), %rcx
movq %rcx, 0x40000(%rbx)
movl -0x10(%rax), %esi
movsd -0x8(%rax), %xmm0
cmpl $0x2, %esi
jne 0x58fc
cmpq %rbx, %rcx
je 0x5a2f
leaq -0x20(%rax), %rcx
movq %rcx, 0x40000(%rbx)
movl -0x20(%rax), %esi
movsd -0x18(%rax), %xmm1
cmpl $0x2, %esi
jne 0x5998
subq %rbx, %rcx
cmpq $0x3fff0, %rcx          # imm = 0x3FFF0
jae 0x5a4e
xorl %ecx, %ecx
ucomisd %xmm0, %xmm1
jmp 0x5586
movq 0x40000(%rbx), %rax
movq %rax, %rcx
subq %rbx, %rcx
cmpq $0x3fff0, %rcx          # imm = 0x3FFF0
jae 0x5a4e
movl $0x0, (%rax)
jmp 0x5315
leaq 0x2f(%rsp), %r14
movb $0x0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4bca
xorpd %xmm0, %xmm0
leaq 0x40(%rsp), %r15
movapd %xmm0, (%r15)
movzbl (%r14), %r14d
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x5b04
movl (%r15), %ebp
movq 0x8(%r15), %r15
movq %rbx, %rdi
callq 0x4c5f
cmpl $0x3, %ebp
jne 0x59e5
movl (%r15), %ecx
cmpl $0x1, %ecx
je 0x585d
cmpl $0x2, %ecx
jne 0x58bb
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
testl %eax, %eax
leaq 0x7(%rsp), %rbp
leaq 0x2d14(%rip), %r15      # 0x7e24
jne 0x5877
notq %r14
shlq $0x4, %r14
addq 0x40000(%rbx), %r14
movq %r14, 0x40000(%rbx)
movq %r14, %rcx
subq %rbx, %rcx
cmpq $0x3fff0, %rcx          # imm = 0x3FFF0
jae 0x5a4e
movq 0x18(%rsp), %rcx
movl 0x10(%rsp), %edx
movl %edx, (%r14)
movq %rcx, 0x8(%r14)
addq $0x10, 0x40000(%rbx)
jmp 0x5877
movq 0x40000(%rbx), %rax
cmpq %rbx, %rax
je 0x5a2f
leaq -0x10(%rax), %rcx
movq %rcx, 0x40000(%rbx)
movl -0x10(%rax), %esi
movsd -0x8(%rax), %xmm0
cmpl $0x2, %esi
jne 0x590c
subq %rbx, %rcx
cmpq $0x3fff0, %rcx          # imm = 0x3FFF0
jae 0x5a4e
xorpd 0x2c11(%rip), %xmm0     # 0x7db0
movl $0x2, -0x10(%rax)
movlpd %xmm0, -0x8(%rax)
addq $0x10, 0x40000(%rbx)
jmp 0x4e07
movq 0x40000(%rbx), %rax
cmpq %rbx, %rax
je 0x5a2f
addq $-0x10, %rax
movq %rax, 0x40000(%rbx)
jmp 0x4e07
movq 0x40000(%rbx), %rax
cmpq %rbx, %rax
je 0x5a2f
leaq -0x10(%rax), %rcx
movq %rcx, 0x40000(%rbx)
cmpq %rbx, %rcx
je 0x5a2f
movl -0x10(%rax), %r14d
movsd -0x8(%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
leaq -0x20(%rax), %rcx
movq %rcx, 0x40000(%rbx)
movl -0x20(%rax), %r15d
movq -0x18(%rax), %xmm0
movq %xmm0, 0x60(%rsp)
movq %xmm0, %rbp
movl %r15d, %edi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x4636
movq 0x38(%rsp), %xmm0
movq %xmm0, %r13
testb %al, %al
je 0x57ae
movl %r14d, %edi
movq %r13, %rsi
xorl %edx, %edx
callq 0x4636
testb %al, %al
je 0x57ae
movl %r15d, %edi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x4636
testb %al, %al
je 0x5a6d
movl %r14d, %edi
movq %r13, %rsi
xorl %edx, %edx
callq 0x4636
testb %al, %al
je 0x5a8c
movq 0x10(%rbp), %r15
addq $0x18, %rbp
movq 0x10(%r13), %r12
addq $0x18, %r13
leaq (%r12,%r15), %rsi
movq 0x58(%rsp), %rdi
callq 0x4644
movq %rax, %r14
leaq 0x18(%rax), %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x1160
leaq (%r14,%r15), %rdi
addq $0x18, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x1160
movq 0x40000(%rbx), %rax
movq %rax, %rcx
subq %rbx, %rcx
cmpq $0x3fff0, %rcx          # imm = 0x3FFF0
jae 0x5a4e
movl $0x3, (%rax)
movq %r14, 0x8(%rax)
jmp 0x583f
movq 0x40000(%rbx), %rax
movq %rax, %rcx
subq %rbx, %rcx
cmpq $0x3fff0, %rcx          # imm = 0x3FFF0
jae 0x5a4e
movl $0x1, (%rax)
movq $0x0, 0x8(%rax)
addq $0x10, 0x40000(%rbx)
jmp 0x4e07
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rsi
movapd %xmm0, (%rsi)
movq %rbx, %rdi
callq 0x4cb9
movq 0x40000(%rbx), %rax
movq %rax, %rcx
subq %rbx, %rcx
cmpq $0x3fff0, %rcx          # imm = 0x3FFF0
jae 0x5a4e
movq 0x18(%rsp), %rcx
movl 0x10(%rsp), %edx
movl %edx, (%rax)
movq %rcx, 0x8(%rax)
addq $0x10, 0x40000(%rbx)
jmp 0x4e07
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4cb9
movq 0x8(%r14), %r14
movq 0x10(%r14), %r15
addq $0x18, %r14
movq 0x40010(%rbx), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1e27
testq %rax, %rax
je 0x58c8
movq 0x40000(%rbx), %rcx
movq %rcx, %rdx
subq %rbx, %rdx
cmpq $0x3fff0, %rdx          # imm = 0x3FFF0
jae 0x5a4e
movq 0x8(%rax), %rdx
movl (%rax), %eax
movl %eax, (%rcx)
movq %rdx, 0x8(%rcx)
addq $0x10, 0x40000(%rbx)
leaq 0x2a3a(%rip), %r15      # 0x7e24
jmp 0x4e07
leaq 0x40(%rsp), %r14
movb $0x0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4bca
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r15
movaps %xmm0, (%r15)
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x5b04
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movzbl (%r14), %ecx
shll $0x4, %ecx
movapd (%r15), %xmm0
leaq 0x29ec(%rip), %r15      # 0x7e24
movupd %xmm0, (%rax,%rcx)
jmp 0x4e07
movq 0x40000(%rbx), %rax
cmpq %rbx, %rax
je 0x5a2f
leaq -0x10(%rax), %rcx
movq %rcx, 0x40000(%rbx)
movl -0x10(%rax), %esi
movsd -0x8(%rax), %xmm0
cmpl $0x2, %esi
jne 0x594c
cmpq %rbx, %rcx
je 0x5a2f
leaq -0x20(%rax), %rcx
movq %rcx, 0x40000(%rbx)
movl -0x20(%rax), %esi
movsd -0x18(%rax), %xmm1
cmpl $0x2, %esi
jne 0x595c
subq %rbx, %rcx
cmpq $0x3fff0, %rcx          # imm = 0x3FFF0
jae 0x5a4e
mulsd %xmm1, %xmm0
movl $0x2, -0x20(%rax)
movsd %xmm0, -0x18(%rax)
addq $0x10, 0x40000(%rbx)
jmp 0x4e07
leaq 0x40(%rsp), %r14
movw $0x0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4d56
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r15
movapd %xmm0, (%r15)
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x5b04
movzwl (%r14), %r14d
movl (%r15), %edi
movq 0x8(%r15), %rsi
leaq 0x291e(%rip), %r15      # 0x7e24
callq 0x45a8
testb %al, %al
cmoveq %r12, %r14
movq 0x8(%rsp), %rax
addq %r14, 0x8(%rax)
jmp 0x4e07
movq 0x40000(%rbx), %rax
cmpq %rbx, %rax
je 0x5a2f
leaq -0x10(%rax), %rcx
movq %rcx, 0x40000(%rbx)
movl -0x10(%rax), %esi
movsd -0x8(%rax), %xmm0
cmpl $0x2, %esi
jne 0x591c
cmpq %rbx, %rcx
je 0x5a2f
leaq -0x20(%rax), %rcx
movq %rcx, 0x40000(%rbx)
movl -0x20(%rax), %esi
movsd -0x18(%rax), %xmm1
cmpl $0x2, %esi
jne 0x59a9
subq %rbx, %rcx
cmpq $0x3fff0, %rcx          # imm = 0x3FFF0
jae 0x5a4e
xorl %ecx, %ecx
ucomisd %xmm1, %xmm0
seta %cl
movl $0x0, -0x20(%rax)
movq %rcx, -0x18(%rax)
addq $0x10, 0x40000(%rbx)
jmp 0x4e07
movq 0x40000(%rbx), %rax
cmpq %rbx, %rax
je 0x5a2f
leaq -0x10(%rax), %rcx
movq %rcx, 0x40000(%rbx)
movl -0x10(%rax), %esi
movsd -0x8(%rax), %xmm0
cmpl $0x2, %esi
jne 0x593c
cmpq %rbx, %rcx
je 0x5a2f
leaq -0x20(%rax), %rcx
movq %rcx, 0x40000(%rbx)
movl -0x20(%rax), %esi
movsd -0x18(%rax), %xmm1
cmpl $0x2, %esi
jne 0x5970
subq %rbx, %rcx
cmpq $0x3fff0, %rcx          # imm = 0x3FFF0
jae 0x5a4e
divsd %xmm0, %xmm1
movl $0x2, -0x20(%rax)
movsd %xmm1, -0x18(%rax)
addq $0x10, 0x40000(%rbx)
jmp 0x4e07
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movapd %xmm0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4cb9
movq 0x8(%r14), %r14
movq 0x10(%r14), %r15
addq $0x18, %r14
movq 0x40010(%rbx), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1e27
testq %rax, %rax
je 0x58c8
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x5b04
leaq 0x27b1(%rip), %r15      # 0x7e24
jmp 0x4e07
movq 0x40000(%rbx), %rax
cmpq %rbx, %rax
je 0x5a2f
leaq -0x10(%rax), %rcx
movq %rcx, 0x40000(%rbx)
movl -0x10(%rax), %edi
movq -0x8(%rax), %rsi
callq 0x45a8
movq 0x40000(%rbx), %rcx
movq %rcx, %rdx
subq %rbx, %rdx
cmpq $0x3fff0, %rdx          # imm = 0x3FFF0
jae 0x5a4e
movzbl %al, %eax
movl $0x0, (%rcx)
movq %rax, 0x8(%rcx)
addq $0x10, 0x40000(%rbx)
jmp 0x4e07
movq 0x40000(%rbx), %rax
movq %rax, %rcx
subq %rbx, %rcx
cmpq $0x3fff0, %rcx          # imm = 0x3FFF0
jae 0x5a4e
movl $0x0, (%rax)
movq $0x1, 0x8(%rax)
addq $0x10, 0x40000(%rbx)
jmp 0x4e07
leaq 0x10(%rsp), %r14
movw $0x0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4d56
movzwl (%r14), %eax
movq 0x8(%rsp), %rcx
addq %rax, 0x8(%rcx)
jmp 0x4e07
leaq 0x10(%rsp), %rsi
movb $0x0, (%rsi)
movq %rbx, %rdi
callq 0x4bca
movq 0x40000(%rbx), %rax
movq %rax, %rcx
subq %rbx, %rcx
cmpq $0x3fff0, %rcx          # imm = 0x3FFF0
jae 0x5a4e
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rcx
movzbl 0x10(%rsp), %edx
shll $0x4, %edx
movq 0x8(%rcx,%rdx), %rsi
movl (%rcx,%rdx), %ecx
movl %ecx, (%rax)
movq %rsi, 0x8(%rax)
addq $0x10, 0x40000(%rbx)
jmp 0x4e07
leaq 0x10(%rsp), %r14
movw $0x0, (%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4d56
movzwl (%r14), %eax
movq 0x8(%rsp), %rcx
subq %rax, 0x8(%rcx)
jmp 0x4e07
movl %r15d, %edi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x4636
testb %al, %al
je 0x57d4
movl %r14d, %edi
movq %r13, %rsi
xorl %edx, %edx
callq 0x4636
testb %al, %al
je 0x59f7
movl %r14d, %edi
movq %r13, %rsi
xorl %edx, %edx
callq 0x4636
testb %al, %al
je 0x57fa
movl %r15d, %edi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x4636
testb %al, %al
je 0x5a0a
cmpl $0x2, %r15d
jne 0x59ba
cmpl $0x2, %r14d
jne 0x59cd
movq 0x40000(%rbx), %rax
movq %rax, %rcx
subq %rbx, %rcx
cmpq $0x3fff0, %rcx          # imm = 0x3FFF0
jae 0x5a4e
movsd 0x38(%rsp), %xmm0
addsd 0x60(%rsp), %xmm0
movl $0x2, (%rax)
movsd %xmm0, 0x8(%rax)
addq $0x10, 0x40000(%rbx)
movq 0x30(%rsp), %r13
leaq 0x7(%rsp), %rbp
leaq 0x25cc(%rip), %r15      # 0x7e24
jmp 0x4e07
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
callq 0x5fbe
leaq 0x7(%rsp), %rbp
leaq 0x25ad(%rip), %r15      # 0x7e24
testl %eax, %eax
jne 0x5a20
movsbq 0x40618(%rbx), %rax
leaq (%rax,%rax,2), %rax
leaq -0x18(,%rax,8), %rax
addq %r13, %rax
movq %rax, 0x8(%rsp)
jmp 0x4e07
cmpq %rbx, %rsi
je 0x5a2f
addq $-0x20, %rax
movq %rax, 0x40000(%rbx)
xorl %eax, %eax
jmp 0x5a20
testl %ecx, %ecx
je 0x59e0
jmp 0x5a20
movq 0x7721(%rip), %rax      # 0xcff0
movq (%rax), %rdi
movq (%r12), %rdx
movq 0x8(%r12), %rcx
leaq 0x38dd(%rip), %rsi      # 0x91bf
movl %r15d, %r8d
movq %r14, %r9
xorl %eax, %eax
callq 0x1140
movq %rbx, %rdi
callq 0x5aca
jmp 0x5a1b
movq %r12, %rdi
movq %rbx, %rdx
callq 0x13f6
jmp 0x5a1b
movq %r12, %rdi
movq %rbx, %rdx
callq 0x18b6
jmp 0x5a1b
movq %r12, %rdi
movq %rbx, %rdx
callq 0x14a6
jmp 0x5a1b
movq %r12, %rdi
movq %rbx, %rdx
callq 0x16b6
jmp 0x5a1b
movq %r12, %rdi
movq %rbx, %rdx
callq 0x1556
jmp 0x5a1b
movq %r12, %rdi
movq %rbx, %rdx
callq 0x1606
jmp 0x5a1b
movq %r12, %rdi
movapd %xmm1, %xmm0
movq %rbx, %rdx
callq 0x165e
jmp 0x5a1b
movq %r12, %rdi
movapd %xmm1, %xmm0
movq %rbx, %rdx
callq 0x15ae
jmp 0x5a1b
movq %r12, %rdi
movapd %xmm1, %xmm0
movq %rbx, %rdx
callq 0x170e
jmp 0x5a1b
movq %r12, %rdi
movapd %xmm1, %xmm0
movq %rbx, %rdx
callq 0x144e
jmp 0x5a1b
movq %r12, %rdi
movapd %xmm1, %xmm0
movq %rbx, %rdx
callq 0x14fe
jmp 0x5a1b
movq %r12, %rdi
movl %r15d, %esi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x180e
jmp 0x5a1b
movq %r12, %rdi
movl %r14d, %esi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x1862
jmp 0x5a1b
movl $0x3, %ebp
movq %rax, %rdi
movl %ebp, %esi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x13a2
jmp 0x5a1b
movq %r12, %rdi
movl %r14d, %esi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x1766
jmp 0x5a1b
movq %r12, %rdi
movl %r15d, %esi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x17ba
movl $0x2, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x38ea(%rip), %rdi      # 0x9320
leaq 0x3565(%rip), %rsi      # 0x8fa2
leaq 0x38ee(%rip), %rcx      # 0x9332
movl $0x86, %edx
callq 0x10f0
leaq 0x38fd(%rip), %rdi      # 0x9352
leaq 0x3546(%rip), %rsi      # 0x8fa2
leaq 0x390d(%rip), %rcx      # 0x9370
movl $0x6f, %edx
callq 0x10f0
leaq 0x3952(%rip), %rdi      # 0x93c6
leaq 0x3527(%rip), %rsi      # 0x8fa2
leaq 0x3953(%rip), %rcx      # 0x93d5
movl $0x3e, %edx
callq 0x10f0
leaq 0x396c(%rip), %rdi      # 0x93ff
leaq 0x3508(%rip), %rsi      # 0x8fa2
leaq 0x3934(%rip), %rcx      # 0x93d5
movl $0x3f, %edx
callq 0x10f0
leaq 0x34de(%rip), %rdi      # 0x8f90
leaq 0x34e9(%rip), %rsi      # 0x8fa2
leaq 0x3583(%rip), %rcx      # 0x9043
movl $0x1a1, %edx            # imm = 0x1A1
callq 0x10f0