// File: /workspace/github_c_makefile_star2_O1/janet-lang[P]janet/src/core/specials.c
// Function: janetc_if
static JanetSlot janetc_if(JanetFopts opts, int32_t argn, const Janet *argv) {
    JanetCompiler *c = opts.compiler;
    int32_t labelr, labeljr, labeld, labeljd;
    JanetFopts condopts, bodyopts;
    JanetSlot cond, left, right, target;
    Janet truebody, falsebody;
    JanetScope condscope, tempscope;
    const int tail = opts.flags & JANET_FOPTS_TAIL;
    const int drop = opts.flags & JANET_FOPTS_DROP;
    uint8_t ifnjmp = JOP_JUMP_IF_NOT;

    if (argn < 2 || argn > 3) {
        janetc_cerror(c, "expected 2 or 3 arguments to if");
        return janetc_cslot(janet_wrap_nil());
    }

    /* Get the bodies of the if expression */
    truebody = argv[1];
    falsebody = argn > 2 ? argv[2] : janet_wrap_nil();

    /* Get options */
    condopts = janetc_fopts_default(c);
    bodyopts = opts;
    bodyopts.flags &= ~JANET_FOPTS_ACCEPT_SPLICE;

    /* Set target for compilation */
    target = (drop || tail)
             ? janetc_cslot(janet_wrap_nil())
             : janetc_gettarget(opts);

    /* Compile condition */
    janetc_scope(&condscope, c, 0, "if");

    Janet condform = argv[0];
    if (janetc_check_nil_form(condform, &condform, JANET_FUN_EQ)) {
        ifnjmp = JOP_JUMP_IF_NOT_NIL;
    } else if (janetc_check_nil_form(condform, &condform, JANET_FUN_NEQ)) {
        ifnjmp = JOP_JUMP_IF_NIL;
    }

    cond = janetc_value(condopts, condform);

    /* Check constant condition. */
    /* TODO: Use type info for more short circuits */
    if (cond.flags & JANET_SLOT_CONSTANT) {
        int swap_condition = 0;
        if (ifnjmp == JOP_JUMP_IF_NOT && !janet_truthy(cond.constant)) swap_condition = 1;
        if (ifnjmp == JOP_JUMP_IF_NIL && janet_checktype(cond.constant, JANET_NIL)) swap_condition = 1;
        if (ifnjmp == JOP_JUMP_IF_NOT_NIL && !janet_checktype(cond.constant, JANET_NIL)) swap_condition = 1;
        if (swap_condition) {
            /* Swap the true and false bodies */
            Janet temp = falsebody;
            falsebody = truebody;
            truebody = temp;
        }
        janetc_scope(&tempscope, c, 0, "if-true");
        right = janetc_value(bodyopts, truebody);
        if (!drop && !tail) janetc_copy(c, target, right);
        janetc_popscope(c);
        if (!janet_checktype(falsebody, JANET_NIL)) {
            janetc_throwaway(bodyopts, falsebody);
        }
        janetc_popscope(c);
        return target;
    }

    /* Compile jump to right */
    labeljr = janetc_emit_si(c, ifnjmp, cond, 0, 0);

    /* Condition left body */
    janetc_scope(&tempscope, c, 0, "if-true");
    left = janetc_value(bodyopts, truebody);
    if (!drop && !tail) janetc_copy(c, target, left);
    janetc_popscope(c);

    /* Compile jump to done */
    labeljd = janet_v_count(c->buffer);
    if (!tail && !(drop && janet_checktype(falsebody, JANET_NIL))) janetc_emit(c, JOP_JUMP);

    /* Compile right body */
    labelr = janet_v_count(c->buffer);
    janetc_scope(&tempscope, c, 0, "if-false");
    right = janetc_value(bodyopts, falsebody);
    if (!drop && !tail) janetc_copy(c, target, right);
    janetc_popscope(c);

    /* Pop main scope */
    janetc_popscope(c);

    /* Write jumps - only add jump lengths if jump actually emitted */
    labeld = janet_v_count(c->buffer);
    c->buffer[labeljr] |= (labelr - labeljr) << 16;
    if (!tail) c->buffer[labeljd] |= (labeld - labeljd) << 8;

    if (tail) target.flags |= JANET_SLOT_RETURNED;
    return target;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rdi, %rbx
movabsq $-0x7800000000000, %r12 # imm = 0xFFF8800000000000
movq 0x10(%rbp), %r14
leal -0x4(%rsi), %eax
cmpl $-0x3, %eax
ja 0x42847
leaq 0x2731d(%rip), %rsi     # 0x69b41
movq %r14, %rdi
callq 0x1bc9e
incq %r12
movq %r12, %rdi
callq 0x4f95a
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1bc4e
jmp 0x42cf1
movq %rdx, %r13
movq %rbx, -0x58(%rbp)
leaq 0x10(%rbp), %rbx
movl 0x20(%rbx), %r15d
movq 0x8(%rdx), %rax
movq %rax, -0x88(%rbp)
cmpl $0x3, %esi
jl 0x4286c
movq 0x10(%r13), %rax
jmp 0x42876
leaq 0x1(%r12), %rdi
callq 0x4f95a
movq %rax, -0x38(%rbp)
leaq -0x100(%rbp), %rdi
movq %r14, %rsi
callq 0x1bbf0
movq 0x20(%rbx), %rax
movq %rax, -0x60(%rbp)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movaps %xmm1, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
andb $-0x9, -0x5e(%rbp)
testl $0x50000, %r15d         # imm = 0x50000
movl %r15d, -0x30(%rbp)
je 0x428c9
leaq 0x1(%r12), %rdi
callq 0x4f95a
leaq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x1bc4e
jmp 0x42903
movq 0x20(%rbx), %rax
movq %rax, 0x20(%rsp)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq -0x1e0(%rbp), %r12
movq %r12, %rdi
callq 0x1c898
movq 0x10(%r12), %rax
movq %rax, -0x40(%rbp)
movups (%r12), %xmm0
movaps %xmm0, -0x50(%rbp)
leaq 0x27254(%rip), %rcx     # 0x69b5e
leaq -0x1e0(%rbp), %rdi
xorl %r15d, %r15d
movq %r14, %rsi
xorl %edx, %edx
callq 0x1bf9c
movq (%r13), %rdi
leaq -0x90(%rbp), %rsi
movq %rdi, (%rsi)
movl $0x18, %edx
callq 0x44693
movl %eax, %r13d
testl %eax, %eax
je 0x42945
movb $0x20, -0x2c(%rbp)
xorl %ebx, %ebx
jmp 0x4296a
leaq -0x90(%rbp), %rsi
movq (%rsi), %rdi
movl $0x19, %edx
callq 0x44693
testl %eax, %eax
je 0x42d06
movb $0x1f, -0x2c(%rbp)
movb $0x1, %bl
xorl %r15d, %r15d
movq -0x90(%rbp), %rsi
movq -0xe0(%rbp), %rax
movq %rax, 0x20(%rsp)
movups -0x100(%rbp), %xmm0
movups -0xf0(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq -0xc0(%rbp), %r12
movq %r12, %rdi
callq 0x1ca05
testb $0x1, 0x12(%r12)
jne 0x42ac1
movq -0xb0(%rbp), %rax
movq %rax, 0x10(%rsp)
movups -0xc0(%rbp), %xmm0
movups %xmm0, (%rsp)
movzbl -0x2c(%rbp), %esi
xorl %r12d, %r12d
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x220f0
movl %eax, -0x2c(%rbp)
leaq 0x2717e(%rip), %rcx     # 0x69b61
leaq -0x170(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x1bf9c
movq -0x60(%rbp), %rax
movq %rax, 0x20(%rsp)
movaps -0x80(%rbp), %xmm0
movaps -0x70(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq -0xd8(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x1ca05
movl -0x30(%rbp), %r13d
testl $0x50000, %r13d         # imm = 0x50000
jne 0x42a5f
movq -0xc8(%rbp), %rax
movq %rax, 0x28(%rsp)
movups -0xd8(%rbp), %xmm0
movups %xmm0, 0x18(%rsp)
movq -0x40(%rbp), %rax
movq %rax, 0x10(%rsp)
movaps -0x50(%rbp), %xmm0
movups %xmm0, (%rsp)
movq %r14, %rdi
callq 0x21b57
movq %r14, %rdi
callq 0x1c045
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x42a74
movl -0x4(%rax), %r12d
btl $0x10, %r13d
jb 0x42aac
btl $0x12, %r13d
jae 0x42a9f
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq -0x38(%rbp), %rax
movabsq $-0x7800000000000, %rcx # imm = 0xFFF8800000000000
cmpq %rcx, %rax
je 0x42aac
movq %r14, %rdi
movl $0x1c, %esi
callq 0x21a88
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x42c17
movl -0x4(%rax), %ebx
jmp 0x42c19
movb $0x1, %al
movabsq $-0x800000000000, %r12  # imm = 0xFFFF800000000000
testb %r15b, %r15b
je 0x42b0a
movq -0xc0(%rbp), %rcx
movq %rcx, %rdx
andq %r12, %rdx
movabsq $-0x7800000000000, %rsi # imm = 0xFFF8800000000000
cmpq %rsi, %rdx
movl -0x30(%rbp), %r15d
je 0x42b06
movabsq $-0x7000000000000, %rsi # imm = 0xFFF9000000000000
cmpq %rsi, %rdx
jne 0x42b0e
testb $0x1, %cl
jne 0x42b0e
xorl %eax, %eax
jmp 0x42b0e
movl -0x30(%rbp), %r15d
testl %r13d, %r13d
sete %cl
movq -0xc0(%rbp), %rdx
andq %r12, %rdx
movabsq $-0x7800000000000, %rsi # imm = 0xFFF8800000000000
cmpq %rsi, %rdx
sete %dl
andb %dl, %bl
orb %dl, %cl
xorb $0x1, %bl
andb %al, %bl
testb %bl, %cl
movq -0x88(%rbp), %rax
movq %rax, %r13
movq -0x38(%rbp), %rbx
cmovneq %rbx, %r13
cmovneq %rax, %rbx
leaq 0x2700b(%rip), %rcx     # 0x69b61
leaq -0x170(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x1bf9c
movq -0x60(%rbp), %rax
movq %rax, 0x20(%rsp)
movaps -0x80(%rbp), %xmm0
movaps -0x70(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq -0xa8(%rbp), %rdi
movq %rbx, %rsi
callq 0x1ca05
testl $0x50000, %r15d         # imm = 0x50000
jne 0x42bca
movq -0x98(%rbp), %rax
movq %rax, 0x28(%rsp)
movups -0xa8(%rbp), %xmm0
movups %xmm0, 0x18(%rsp)
movq -0x40(%rbp), %rax
movq %rax, 0x10(%rsp)
movaps -0x50(%rbp), %xmm0
movups %xmm0, (%rsp)
movq %r14, %rdi
callq 0x21b57
movq %r14, %rdi
callq 0x1c045
andq %r13, %r12
movabsq $-0x7800000000000, %rax # imm = 0xFFF8800000000000
cmpq %rax, %r12
movq -0x58(%rbp), %rbx
je 0x42c0a
movq -0x60(%rbp), %rax
movq %rax, 0x20(%rsp)
movaps -0x80(%rbp), %xmm0
movaps -0x70(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r13, %rdi
callq 0x1d768
movq %r14, %rdi
callq 0x1c045
jmp 0x42ce2
xorl %ebx, %ebx
leaq 0x26f49(%rip), %rcx     # 0x69b69
leaq -0x170(%rbp), %rdi
xorl %r15d, %r15d
movq %r14, %rsi
xorl %edx, %edx
callq 0x1bf9c
movq -0x60(%rbp), %rax
movq %rax, 0x20(%rsp)
movaps -0x80(%rbp), %xmm0
movaps -0x70(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq -0xa8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x1ca05
testl $0x50000, %r13d         # imm = 0x50000
jne 0x42c98
movq -0x98(%rbp), %rax
movq %rax, 0x28(%rsp)
movups -0xa8(%rbp), %xmm0
movups %xmm0, 0x18(%rsp)
movq -0x40(%rbp), %rax
movq %rax, 0x10(%rsp)
movaps -0x50(%rbp), %xmm0
movups %xmm0, (%rsp)
movq %r14, %rdi
callq 0x21b57
movq %r14, %rdi
callq 0x1c045
movq %r14, %rdi
callq 0x1c045
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x42cb5
movl -0x4(%rax), %r15d
movl -0x2c(%rbp), %ecx
subl %ecx, %ebx
shll $0x10, %ebx
movslq %ecx, %rcx
orl %ebx, (%rax,%rcx,4)
btl $0x10, %r13d
jb 0x42cda
subl %r12d, %r15d
shll $0x8, %r15d
movslq %r12d, %rcx
orl %r15d, (%rax,%rcx,4)
jmp 0x42cde
orb $0x10, -0x3e(%rbp)
movq -0x58(%rbp), %rbx
movq -0x40(%rbp), %rax
movq %rax, 0x10(%rbx)
movaps -0x50(%rbp), %xmm0
movups %xmm0, (%rbx)
movq %rbx, %rax
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1e, -0x2c(%rbp)
movb $0x1, %r15b
jmp 0x42941