// File: /workspace/github_c_makefile_star2_O3/janet-lang[P]janet/src/core/emit.c
// Function: janetc_loadconst
static void janetc_loadconst(JanetCompiler *c, Janet k, int32_t reg) {
    switch (janet_type(k)) {
        case JANET_NIL:
            janetc_emit(c, (reg << 8) | JOP_LOAD_NIL);
            break;
        case JANET_BOOLEAN:
            janetc_emit(c, (reg << 8) |
                        (janet_unwrap_boolean(k) ? JOP_LOAD_TRUE : JOP_LOAD_FALSE));
            break;
        case JANET_NUMBER: {
            double dval = janet_unwrap_number(k);
            if (dval < INT16_MIN || dval > INT16_MAX)
                goto do_constant;
            int32_t i = (int32_t) dval;
            if (dval != i)
                goto do_constant;
            uint32_t iu = (uint32_t)i;
            janetc_emit(c,
                        (iu << 16) |
                        (reg << 8) |
                        JOP_LOAD_INTEGER);
            break;
        }
        default:
        do_constant: {
                int32_t cindex = janetc_const(c, k);
                janetc_emit(c,
                            (cindex << 16) |
                            (reg << 8) |
                            JOP_LOAD_CONSTANT);
                break;
            }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebx
movq %rsi, %r15
movq %rsi, %xmm0
movq %rsi, %rcx
shrq $0x2f, %rcx
andl $0xf, %ecx
xorl %eax, %eax
ucomisd %xmm0, %xmm0
movq %rdi, %r12
cmovpl %ecx, %eax
testl %eax, %eax
je 0x22230
cmpl $0x2, %eax
je 0x2221e
cmpl $0x1, %eax
jne 0x22258
shll $0x8, %ebx
orl $0x28, %ebx
jmp 0x22337
shll $0x8, %ebx
andl $0x1, %r15d
subl %r15d, %ebx
addl $0x2a, %ebx
jmp 0x22337
movsd 0x36cc8(%rip), %xmm1    # 0x58f00
ucomisd %xmm0, %xmm1
ja 0x22258
ucomisd 0x36cc2(%rip), %xmm0    # 0x58f08
ja 0x22258
cvttpd2dq %xmm0, %xmm1
cvtdq2pd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x22258
jnp 0x222d7
movq (%r12), %r13
xorl %r14d, %r14d
testq %r13, %r13
je 0x22271
testb $0x1, 0x6c(%r13)
jne 0x22274
movq 0x8(%r13), %r13
jmp 0x2225f
xorl %r13d, %r13d
movq 0x18(%r13), %rax
testq %rax, %rax
je 0x22302
movl -0x4(%rax), %r14d
testl %r14d, %r14d
jle 0x222f5
movq %r12, -0x30(%rbp)
xorl %r12d, %r12d
movq 0x18(%r13), %rax
movq (%rax,%r12,8), %rsi
movq %r15, %rdi
callq 0x4a1bd
testl %eax, %eax
jne 0x222ce
incq %r12
cmpq %r12, %r14
jne 0x22291
cmpl $0xffff, %r14d          # imm = 0xFFFF
jl 0x222e8
leaq 0x36cb3(%rip), %rsi     # 0x58f70
movq -0x30(%rbp), %r12
movq %r12, %rdi
callq 0x1bb46
xorl %r14d, %r14d
jmp 0x2232a
movl %r12d, %r14d
movq -0x30(%rbp), %r12
jmp 0x2232a
cvttsd2si %xmm0, %eax
shll $0x10, %eax
shll $0x8, %ebx
orl %eax, %ebx
orl $0x2b, %ebx
jmp 0x22337
movq 0x18(%r13), %rax
testq %rax, %rax
movq -0x30(%rbp), %r12
je 0x22302
movl -0x4(%rax), %ecx
leal 0x1(%rcx), %edx
cmpl -0x8(%rax), %edx
jge 0x22304
jmp 0x22320
xorl %eax, %eax
movq %rax, %rdi
movl $0x1, %esi
movl $0x8, %edx
callq 0x4b4e8
movq %rax, 0x18(%r13)
movl -0x4(%rax), %ecx
leal 0x1(%rcx), %edx
movl %edx, -0x4(%rax)
movslq %ecx, %rcx
movq %r15, (%rax,%rcx,8)
shll $0x10, %r14d
shll $0x8, %ebx
orl %r14d, %ebx
orl $0x2c, %ebx
movq %r12, %rdi
movl %ebx, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21728
nop