// File: /workspace/github_c_makefile_star2_O3/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 0x41f6f
leaq 0x26bd5(%rip), %rsi     # 0x68b21
movq %r14, %rdi
callq 0x1bb46
incq %r12
movq %r12, %rdi
callq 0x4ece6
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1baf6
jmp 0x42416
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 0x41f94
movq 0x10(%r13), %rax
jmp 0x41f9e
leaq 0x1(%r12), %rdi
callq 0x4ece6
movq %rax, -0x38(%rbp)
leaq -0x100(%rbp), %rdi
movq %r14, %rsi
callq 0x1ba98
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 0x41ff1
leaq 0x1(%r12), %rdi
callq 0x4ece6
leaq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x1baf6
jmp 0x4202b
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 0x1c64f
movq 0x10(%r12), %rax
movq %rax, -0x40(%rbp)
movups (%r12), %xmm0
movaps %xmm0, -0x50(%rbp)
leaq 0x26b0c(%rip), %rcx     # 0x68b3e
leaq -0x1e0(%rbp), %rdi
xorl %r15d, %r15d
movq %r14, %rsi
xorl %edx, %edx
callq 0x1be43
movq (%r13), %rdi
leaq -0x90(%rbp), %rsi
movq %rdi, (%rsi)
movl $0x18, %edx
callq 0x43d7b
movl %eax, %r13d
testl %eax, %eax
je 0x4206d
movb $0x20, -0x2c(%rbp)
xorl %ebx, %ebx
jmp 0x42092
leaq -0x90(%rbp), %rsi
movq (%rsi), %rdi
movl $0x19, %edx
callq 0x43d7b
testl %eax, %eax
je 0x4242b
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 0x1c7be
testb $0x1, 0x12(%r12)
jne 0x421e9
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 0x21d94
movl %eax, -0x2c(%rbp)
leaq 0x26a36(%rip), %rcx     # 0x68b41
leaq -0x170(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x1be43
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 0x1c7be
movl -0x30(%rbp), %r13d
testl $0x50000, %r13d         # imm = 0x50000
jne 0x42187
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 0x217fb
movq %r14, %rdi
callq 0x1beec
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x4219c
movl -0x4(%rax), %r12d
btl $0x10, %r13d
jb 0x421d8
btl $0x12, %r13d
jae 0x421c7
movabsq $-0x800000000000, %rcx  # imm = 0xFFFF800000000000
andq -0x38(%rbp), %rcx
movabsq $-0x7800000000000, %rdx # imm = 0xFFF8800000000000
cmpq %rdx, %rcx
je 0x421d8
movq %r14, %rdi
movl $0x1c, %esi
callq 0x21728
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x4233c
movl -0x4(%rax), %ebx
jmp 0x4233e
movabsq $-0x800000000000, %r12  # imm = 0xFFFF800000000000
movq -0xc0(%rbp), %rsi
movq %rsi, %rcx
andq %r12, %rcx
movb $0x1, %al
testb %r15b, %r15b
je 0x42236
movabsq $-0x7800000000000, %rdx # imm = 0xFFF8800000000000
cmpq %rdx, %rcx
movl -0x30(%rbp), %r15d
je 0x4222f
movabsq $-0x7000000000000, %rdx # imm = 0xFFF9000000000000
cmpq %rdx, %rcx
jne 0x42231
testb $0x1, %sil
jne 0x4223d
xorl %eax, %eax
movq %rcx, %rdx
jmp 0x4223d
movq %rcx, %rdx
movl -0x30(%rbp), %r15d
testl %r13d, %r13d
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 0x268c6(%rip), %rcx     # 0x68b41
leaq -0x170(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x1be43
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 0x1c7be
testl $0x50000, %r15d         # imm = 0x50000
jne 0x422ef
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 0x217fb
movq %r14, %rdi
callq 0x1beec
andq %r13, %r12
movabsq $-0x7800000000000, %rax # imm = 0xFFF8800000000000
cmpq %rax, %r12
movq -0x58(%rbp), %rbx
je 0x4232f
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 0x1d4fc
movq %r14, %rdi
callq 0x1beec
jmp 0x42407
xorl %ebx, %ebx
leaq 0x26804(%rip), %rcx     # 0x68b49
leaq -0x170(%rbp), %rdi
xorl %r15d, %r15d
movq %r14, %rsi
xorl %edx, %edx
callq 0x1be43
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 0x1c7be
testl $0x50000, %r13d         # imm = 0x50000
jne 0x423bd
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 0x217fb
movq %r14, %rdi
callq 0x1beec
movq %r14, %rdi
callq 0x1beec
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x423da
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 0x423ff
subl %r12d, %r15d
shll $0x8, %r15d
movslq %r12d, %rcx
orl %r15d, (%rax,%rcx,4)
jmp 0x42403
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 0x42069