// File: /workspace/github_c_makefile_star2_O0/janet-lang[P]janet/src/core/specials.c
// Function: janetc_while
static JanetSlot janetc_while(JanetFopts opts, int32_t argn, const Janet *argv) {
    JanetCompiler *c = opts.compiler;
    JanetSlot cond;
    JanetFopts subopts = janetc_fopts_default(c);
    JanetScope tempscope;
    int32_t labelwt, labeld, labeljt, labelc, i;
    int infinite = 0;
    int is_nil_form = 0;
    int is_notnil_form = 0;
    uint8_t ifjmp = JOP_JUMP_IF;
    uint8_t ifnjmp = JOP_JUMP_IF_NOT;

    if (argn < 1) {
        janetc_cerror(c, "expected at least 1 argument to while");
        return janetc_cslot(janet_wrap_nil());
    }

    labelwt = janet_v_count(c->buffer);

    janetc_scope(&tempscope, c, JANET_SCOPE_WHILE, "while");

    /* Check for `(= nil _)` or `(not= nil _)` in condition, and if so, use the
     * jmpnl or jmpnn instructions. This let's us implement `(each ...)`
     * more efficiently. */
    Janet condform = argv[0];
    if (janetc_check_nil_form(condform, &condform, JANET_FUN_EQ)) {
        is_nil_form = 1;
        ifjmp = JOP_JUMP_IF_NIL;
        ifnjmp = JOP_JUMP_IF_NOT_NIL;
    }
    if (janetc_check_nil_form(condform, &condform, JANET_FUN_NEQ)) {
        is_notnil_form = 1;
        ifjmp = JOP_JUMP_IF_NOT_NIL;
        ifnjmp = JOP_JUMP_IF_NIL;
    }

    /* Compile condition */
    cond = janetc_value(subopts, condform);

    /* Check for constant condition */
    if (cond.flags & JANET_SLOT_CONSTANT) {
        /* Loop never executes */
        int never_executes = is_nil_form
                             ? !janet_checktype(cond.constant, JANET_NIL)
                             : is_notnil_form
                             ? janet_checktype(cond.constant, JANET_NIL)
                             : !janet_truthy(cond.constant);
        if (never_executes) {
            janetc_popscope(c);
            return janetc_cslot(janet_wrap_nil());
        }
        /* Infinite loop */
        infinite = 1;
    }

    /* Infinite loop does not need to check condition */
    labelc = infinite
             ? 0
             : janetc_emit_si(c, ifnjmp, cond, 0, 0);

    /* Compile body */
    for (i = 1; i < argn; i++) {
        subopts.flags = JANET_FOPTS_DROP;
        janetc_freeslot(c, janetc_value(subopts, argv[i]));
    }

    /* Check if closure created in while scope. If so,
     * recompile in a function scope. */
    if (tempscope.flags & JANET_SCOPE_CLOSURE) {
        subopts = janetc_fopts_default(c);
        tempscope.flags |= JANET_SCOPE_UNUSED;
        janetc_popscope(c);
        if (c->buffer) janet_v__cnt(c->buffer) = labelwt;
        if (c->mapbuffer) janet_v__cnt(c->mapbuffer) = labelwt;

        janetc_scope(&tempscope, c, JANET_SCOPE_FUNCTION, "while-iife");

        /* Recompile in the function scope */
        cond = janetc_value(subopts, condform);
        if (!(cond.flags & JANET_SLOT_CONSTANT)) {
            /* If not an infinite loop, return nil when condition false */
            janetc_emit_si(c, ifjmp, cond, 2, 0);
            janetc_emit(c, JOP_RETURN_NIL);
        }
        for (i = 1; i < argn; i++) {
            subopts.flags = JANET_FOPTS_DROP;
            janetc_freeslot(c, janetc_value(subopts, argv[i]));
        }
        /* But now add tail recursion */
        int32_t tempself = janetc_regalloc_temp(&tempscope.ra, JANETC_REGTEMP_0);
        janetc_emit(c, JOP_LOAD_SELF | (tempself << 8));
        janetc_emit(c, JOP_TAILCALL | (tempself << 8));
        janetc_regalloc_freetemp(&c->scope->ra, tempself, JANETC_REGTEMP_0);
        /* Compile function */
        JanetFuncDef *def = janetc_pop_funcdef(c);
        def->name = janet_cstring("_while");
        janet_def_addflags(def);
        int32_t defindex = janetc_addfuncdef(c, def);
        /* And then load the closure and call it. */
        int32_t cloreg = janetc_regalloc_temp(&c->scope->ra, JANETC_REGTEMP_0);
        janetc_emit(c, JOP_CLOSURE | (cloreg << 8) | (defindex << 16));
        janetc_emit(c, JOP_CALL | (cloreg << 8) | (cloreg << 16));
        janetc_regalloc_freetemp(&c->scope->ra, cloreg, JANETC_REGTEMP_0);
        c->scope->flags |= JANET_SCOPE_CLOSURE;
        return janetc_cslot(janet_wrap_nil());
    }

    /* Compile jump to :whiletop */
    labeljt = janet_v_count(c->buffer);
    janetc_emit(c, JOP_JUMP);

    /* Calculate jumps */
    labeld = janet_v_count(c->buffer);
    if (!infinite) c->buffer[labelc] |= (uint32_t)(labeld - labelc) << 16;
    c->buffer[labeljt] |= (uint32_t)(labelwt - labeljt) << 8;

    /* Calculate breaks */
    for (int32_t i = labelwt; i < labeld; i++) {
        if (c->buffer[i] == (0x80 | JOP_JUMP)) {
            c->buffer[i] = JOP_JUMP | ((labeld - i) << 8);
        }
    }

    /* Pop scope and return nil slot */
    janetc_popscope(c);

    return janetc_cslot(janet_wrap_nil());
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movq %rdi, -0x1d8(%rbp)
movq %rdi, -0x1d0(%rbp)
leaq 0x10(%rbp), %rax
movl %esi, -0x4(%rbp)
movq %rdx, -0x10(%rbp)
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x1fed0
movl $0x0, -0xe0(%rbp)
movl $0x0, -0xe4(%rbp)
movl $0x0, -0xe8(%rbp)
movb $0x1d, -0xe9(%rbp)
movb $0x1e, -0xea(%rbp)
cmpl $0x1, -0x4(%rbp)
jge 0x617e8
movq -0x18(%rbp), %rdi
leaq 0x349a3(%rip), %rsi     # 0x96158
callq 0x1fff0
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq -0x1d8(%rbp), %rdi
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rsi
callq 0x1ff40
jmp 0x6205e
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x61806
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x4(%rax), %eax
movl %eax, -0x1dc(%rbp)
jmp 0x61810
xorl %eax, %eax
movl %eax, -0x1dc(%rbp)
jmp 0x61810
movl -0x1dc(%rbp), %eax
movl %eax, -0xcc(%rbp)
movq -0x18(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
movl $0x20, %edx
leaq 0x34945(%rip), %rcx     # 0x96178
callq 0x204d0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rdi
leaq -0x100(%rbp), %rsi
movl $0x18, %edx
callq 0x63790
cmpl $0x0, %eax
je 0x6187b
movl $0x1, -0xe4(%rbp)
movb $0x1f, -0xe9(%rbp)
movb $0x20, -0xea(%rbp)
movq -0x100(%rbp), %rdi
leaq -0x100(%rbp), %rsi
movl $0x19, %edx
callq 0x63790
cmpl $0x0, %eax
je 0x618b0
movl $0x1, -0xe8(%rbp)
movb $0x20, -0xe9(%rbp)
movb $0x1f, -0xea(%rbp)
movq -0x100(%rbp), %rsi
movq -0x38(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x20(%rax)
movups -0x58(%rbp), %xmm0
movups -0x48(%rbp), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0x118(%rbp), %rdi
callq 0x21590
movq -0x118(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0x20(%rbp)
movl -0x20(%rbp), %eax
andl $0x10000, %eax          # imm = 0x10000
cmpl $0x0, %eax
je 0x61adb
cmpl $0x0, -0xe4(%rbp)
je 0x61948
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq -0x30(%rbp), %rax
movabsq $-0x7800000000000, %rcx # imm = 0xFFF8800000000000
cmpq %rcx, %rax
sete %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x1e0(%rbp)
jmp 0x61a85
cmpl $0x0, -0xe8(%rbp)
je 0x6197f
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq -0x30(%rbp), %rax
movabsq $-0x7800000000000, %rcx # imm = 0xFFF8800000000000
cmpq %rcx, %rax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x1e4(%rbp)
jmp 0x61a79
xorl %eax, %eax
testb $0x1, %al
jne 0x61987
jmp 0x619c5
movsd -0x30(%rbp), %xmm0
ucomisd %xmm0, %xmm0
setp %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x1e5(%rbp)
jne 0x619a5
jmp 0x61a66
movq -0x30(%rbp), %rcx
shrq $0x2f, %rcx
andq $0xf, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x1e5(%rbp)
je 0x61a66
jmp 0x619ea
movabsq $-0x800000000000, %rcx  # imm = 0xFFFF800000000000
andq -0x30(%rbp), %rcx
xorl %eax, %eax
movabsq $-0x7800000000000, %rdx # imm = 0xFFF8800000000000
cmpq %rdx, %rcx
movb %al, -0x1e5(%rbp)
je 0x61a66
xorl %eax, %eax
testb $0x1, %al
jne 0x619f2
jmp 0x61a20
movsd -0x30(%rbp), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x61a04
jmp 0x61a45
movq -0x30(%rbp), %rcx
shrq $0x2f, %rcx
andq $0xf, %rcx
movb $0x1, %al
cmpq $0x0, %rcx
movb %al, -0x1e6(%rbp)
je 0x61a45
jmp 0x61a5a
movabsq $-0x800000000000, %rcx  # imm = 0xFFFF800000000000
andq -0x30(%rbp), %rcx
movb $0x1, %al
movabsq $-0x7000000000000, %rdx # imm = 0xFFF9000000000000
cmpq %rdx, %rcx
movb %al, -0x1e6(%rbp)
jne 0x61a5a
movq -0x30(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
setne %al
movb %al, -0x1e6(%rbp)
movb -0x1e6(%rbp), %al
movb %al, -0x1e5(%rbp)
movb -0x1e5(%rbp), %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x1e4(%rbp)
movl -0x1e4(%rbp), %eax
movl %eax, -0x1e0(%rbp)
movl -0x1e0(%rbp), %eax
movl %eax, -0x11c(%rbp)
cmpl $0x0, -0x11c(%rbp)
je 0x61ad1
movq -0x18(%rbp), %rdi
callq 0x20600
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq -0x1d8(%rbp), %rdi
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rsi
callq 0x1ff40
jmp 0x6205e
movl $0x1, -0xe0(%rbp)
cmpl $0x0, -0xe0(%rbp)
je 0x61aee
xorl %eax, %eax
movl %eax, -0x1ec(%rbp)
jmp 0x61b25
movq -0x18(%rbp), %rdi
leaq -0x30(%rbp), %rax
xorl %ecx, %ecx
movzbl -0xea(%rbp), %esi
movq (%rax), %rdx
movq %rdx, (%rsp)
movq 0x8(%rax), %rdx
movq %rdx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
movl %ecx, %edx
callq 0x29dd0
movl %eax, -0x1ec(%rbp)
movl -0x1ec(%rbp), %eax
movl %eax, -0xd8(%rbp)
movl $0x1, -0xdc(%rbp)
movl -0xdc(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x61bd1
movl $0x40000, -0x38(%rbp)   # imm = 0x40000
movq -0x18(%rbp), %rax
movq %rax, -0x1f8(%rbp)
movq -0x10(%rbp), %rax
movslq -0xdc(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x38(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x20(%rax)
movups -0x58(%rbp), %xmm0
movups -0x48(%rbp), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0x140(%rbp), %rdi
callq 0x21590
movq -0x1f8(%rbp), %rdi
leaq -0x140(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x202e0
movl -0xdc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xdc(%rbp)
jmp 0x61b3b
movl -0x5c(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x61efc
movq -0x18(%rbp), %rsi
leaq -0x168(%rbp), %rdi
callq 0x1fed0
leaq -0x58(%rbp), %rdi
leaq -0x168(%rbp), %rsi
movl $0x28, %edx
callq 0x12680
movl -0x5c(%rbp), %eax
orl $0x8, %eax
movl %eax, -0x5c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x20600
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x61c33
movl -0xcc(%rbp), %ecx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl %ecx, -0x4(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x61c4f
movl -0xcc(%rbp), %ecx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl %ecx, -0x4(%rax)
movq -0x18(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
movl $0x1, %edx
leaq 0x34518(%rip), %rcx     # 0x9617e
callq 0x204d0
movq -0x100(%rbp), %rsi
movq -0x38(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x20(%rax)
movups -0x58(%rbp), %xmm0
movups -0x48(%rbp), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0x180(%rbp), %rdi
callq 0x21590
movq -0x180(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x178(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x170(%rbp), %rax
movq %rax, -0x20(%rbp)
movl -0x20(%rbp), %eax
andl $0x10000, %eax          # imm = 0x10000
cmpl $0x0, %eax
jne 0x61d08
movq -0x18(%rbp), %rdi
leaq -0x30(%rbp), %rax
movl $0x2, %edx
xorl %ecx, %ecx
movzbl -0xe9(%rbp), %esi
movq (%rax), %r8
movq %r8, (%rsp)
movq 0x8(%rax), %r8
movq %r8, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x29dd0
movq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x29410
movl $0x1, -0xdc(%rbp)
movl -0xdc(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x61da8
movl $0x40000, -0x38(%rbp)   # imm = 0x40000
movq -0x18(%rbp), %rax
movq %rax, -0x200(%rbp)
movq -0x10(%rbp), %rax
movslq -0xdc(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x38(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x20(%rax)
movups -0x58(%rbp), %xmm0
movups -0x48(%rbp), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0x198(%rbp), %rdi
callq 0x21590
movq -0x200(%rbp), %rdi
leaq -0x198(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x202e0
movl -0xdc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xdc(%rbp)
jmp 0x61d12
leaq -0xc8(%rbp), %rdi
addq $0x30, %rdi
xorl %esi, %esi
callq 0x5e180
movl %eax, -0x19c(%rbp)
movq -0x18(%rbp), %rdi
movl -0x19c(%rbp), %esi
shll $0x8, %esi
orl $0x2e, %esi
callq 0x29410
movq -0x18(%rbp), %rdi
movl -0x19c(%rbp), %esi
shll $0x8, %esi
orl $0x36, %esi
callq 0x29410
movq -0x18(%rbp), %rax
movq (%rax), %rdi
addq $0x30, %rdi
movl -0x19c(%rbp), %esi
xorl %edx, %edx
callq 0x5e250
movq -0x18(%rbp), %rdi
callq 0x23340
movq %rax, -0x1a8(%rbp)
leaq 0x34370(%rip), %rdi     # 0x96189
callq 0x64a70
movq %rax, %rcx
movq -0x1a8(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x1a8(%rbp), %rdi
callq 0x23200
movq -0x18(%rbp), %rdi
movq -0x1a8(%rbp), %rsi
callq 0x63670
movl %eax, -0x1ac(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
addq $0x30, %rdi
xorl %esi, %esi
callq 0x5e180
movl %eax, -0x1b0(%rbp)
movq -0x18(%rbp), %rdi
movl -0x1b0(%rbp), %esi
shll $0x8, %esi
orl $0x30, %esi
movl -0x1ac(%rbp), %eax
shll $0x10, %eax
orl %eax, %esi
callq 0x29410
movq -0x18(%rbp), %rdi
movl -0x1b0(%rbp), %esi
shll $0x8, %esi
orl $0x35, %esi
movl -0x1b0(%rbp), %eax
shll $0x10, %eax
orl %eax, %esi
callq 0x29410
movq -0x18(%rbp), %rax
movq (%rax), %rdi
addq $0x30, %rdi
movl -0x1b0(%rbp), %esi
xorl %edx, %edx
callq 0x5e250
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl 0x6c(%rax), %ecx
orl $0x10, %ecx
movl %ecx, 0x6c(%rax)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq -0x1d8(%rbp), %rdi
movq %rax, -0x1b8(%rbp)
movq -0x1b8(%rbp), %rsi
callq 0x1ff40
jmp 0x6205e
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x61f1a
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x4(%rax), %eax
movl %eax, -0x204(%rbp)
jmp 0x61f24
xorl %eax, %eax
movl %eax, -0x204(%rbp)
jmp 0x61f24
movl -0x204(%rbp), %eax
movl %eax, -0xd4(%rbp)
movq -0x18(%rbp), %rdi
movl $0x1c, %esi
callq 0x29410
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x61f5c
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x4(%rax), %eax
movl %eax, -0x208(%rbp)
jmp 0x61f66
xorl %eax, %eax
movl %eax, -0x208(%rbp)
jmp 0x61f66
movl -0x208(%rbp), %eax
movl %eax, -0xd0(%rbp)
cmpl $0x0, -0xe0(%rbp)
jne 0x61f9f
movl -0xd0(%rbp), %edx
subl -0xd8(%rbp), %edx
shll $0x10, %edx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xd8(%rbp), %rcx
orl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl -0xcc(%rbp), %edx
subl -0xd4(%rbp), %edx
shll $0x8, %edx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xd4(%rbp), %rcx
orl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl -0xcc(%rbp), %eax
movl %eax, -0x1bc(%rbp)
movl -0x1bc(%rbp), %eax
cmpl -0xd0(%rbp), %eax
jge 0x6202c
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1bc(%rbp), %rcx
cmpl $0x9c, (%rax,%rcx,4)
jne 0x62019
movl -0xd0(%rbp), %edx
subl -0x1bc(%rbp), %edx
shll $0x8, %edx
orl $0x1c, %edx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1bc(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x6201b
movl -0x1bc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1bc(%rbp)
jmp 0x61fcf
movq -0x18(%rbp), %rdi
callq 0x20600
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq -0x1d8(%rbp), %rdi
movq %rax, -0x1c8(%rbp)
movq -0x1c8(%rbp), %rsi
callq 0x1ff40
movq -0x1d0(%rbp), %rax
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
nop