// File: /workspace/github_c_makefile_star2_O2/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 0x3e9cc
leaq 0x26198(%rip), %rsi     # 0x64b41
movq %r14, %rdi
callq 0x19fa9
incq %r12
movq %r12, %rdi
callq 0x4b313
movq %rbx, %rdi
movq %rax, %rsi
callq 0x19f5c
jmp 0x3ee6c
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
jb 0x3e9f1
movq 0x10(%r13), %rax
jmp 0x3e9fb
leaq 0x1(%r12), %rdi
callq 0x4b313
movq %rax, -0x38(%rbp)
leaq -0x100(%rbp), %rdi
movq %r14, %rsi
callq 0x19f04
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 0x3ea4e
leaq 0x1(%r12), %rdi
callq 0x4b313
leaq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x19f5c
jmp 0x3ea88
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 0x1aa9e
movq 0x10(%r12), %rax
movq %rax, -0x40(%rbp)
movups (%r12), %xmm0
movaps %xmm0, -0x50(%rbp)
leaq 0x260cf(%rip), %rcx     # 0x64b5e
leaq -0x1e0(%rbp), %rdi
xorl %r15d, %r15d
movq %r14, %rsi
xorl %edx, %edx
callq 0x1a294
movq (%r13), %rdi
leaq -0x90(%rbp), %rsi
movq %rdi, (%rsi)
pushq $0x18
popq %rdx
callq 0x40766
movl %eax, -0x2c(%rbp)
testl %eax, %eax
je 0x3eac7
movb $0x20, %r13b
xorl %ebx, %ebx
jmp 0x3eae9
leaq -0x90(%rbp), %rsi
movq (%rsi), %rdi
pushq $0x19
popq %rdx
callq 0x40766
testl %eax, %eax
je 0x3ee81
movb $0x1f, %r13b
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 0x1abbf
testb $0x1, 0x12(%r12)
jne 0x3ec3e
movq -0xb0(%rbp), %rax
movq %rax, 0x10(%rsp)
movups -0xc0(%rbp), %xmm0
movups %xmm0, (%rsp)
movzbl %r13b, %esi
xorl %r12d, %r12d
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1fe75
movl %eax, -0x2c(%rbp)
leaq 0x25fff(%rip), %rcx     # 0x64b61
leaq -0x170(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x1a294
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 0x1abbf
movl -0x30(%rbp), %r13d
testl $0x50000, %r13d         # imm = 0x50000
jne 0x3ebde
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 0x1f88f
movq %r14, %rdi
callq 0x1a338
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x3ebf3
movl -0x4(%rax), %r12d
btl $0x10, %r13d
jb 0x3ec2d
btl $0x12, %r13d
jae 0x3ec1e
movabsq $-0x800000000000, %rcx  # imm = 0xFFFF800000000000
andq -0x38(%rbp), %rcx
movabsq $-0x7800000000000, %rdx # imm = 0xFFF8800000000000
cmpq %rdx, %rcx
je 0x3ec2d
pushq $0x1c
popq %rsi
movq %r14, %rdi
callq 0x1f7c4
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x3ed92
movl -0x4(%rax), %ebx
jmp 0x3ed94
movabsq $-0x800000000000, %r12  # imm = 0xFFFF800000000000
movq -0xc0(%rbp), %rsi
movq %rsi, %rcx
andq %r12, %rcx
movb $0x1, %al
testb %r15b, %r15b
je 0x3ec8b
movabsq $-0x7800000000000, %rdx # imm = 0xFFF8800000000000
cmpq %rdx, %rcx
movl -0x30(%rbp), %r15d
je 0x3ec84
movabsq $-0x7000000000000, %rdx # imm = 0xFFF9000000000000
cmpq %rdx, %rcx
jne 0x3ec86
testb $0x1, %sil
jne 0x3ec92
xorl %eax, %eax
movq %rcx, %rdx
jmp 0x3ec92
movq %rcx, %rdx
movl -0x30(%rbp), %r15d
cmpl $0x0, -0x2c(%rbp)
sete %cl
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 0x25e90(%rip), %rcx     # 0x64b61
leaq -0x170(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x1a294
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 0x1abbf
testl $0x50000, %r15d         # imm = 0x50000
jne 0x3ed45
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 0x1f88f
movq %r14, %rdi
callq 0x1a338
andq %r13, %r12
movabsq $-0x7800000000000, %rax # imm = 0xFFF8800000000000
cmpq %rax, %r12
movq -0x58(%rbp), %rbx
je 0x3ed85
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 0x1bb55
movq %r14, %rdi
callq 0x1a338
jmp 0x3ee5d
xorl %ebx, %ebx
leaq 0x25dce(%rip), %rcx     # 0x64b69
leaq -0x170(%rbp), %rdi
xorl %r15d, %r15d
movq %r14, %rsi
xorl %edx, %edx
callq 0x1a294
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 0x1abbf
testl $0x50000, %r13d         # imm = 0x50000
jne 0x3ee13
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 0x1f88f
movq %r14, %rdi
callq 0x1a338
movq %r14, %rdi
callq 0x1a338
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x3ee30
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 0x3ee55
subl %r12d, %r15d
shll $0x8, %r15d
movslq %r12d, %rcx
orl %r15d, (%rax,%rcx,4)
jmp 0x3ee59
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, %r13b
movb $0x1, %r15b
jmp 0x3eac3