// File: /workspace/github_c_makefile_star2_O2/janet-lang[P]janet/src/core/specials.c
// Function: dohead_destructure
SlotHeadPair *dohead_destructure(JanetCompiler *c, SlotHeadPair *into, JanetFopts opts, Janet lhs, Janet rhs) {

    /* Detect if we can do an optimization to avoid some allocations */
    int can_destructure_lhs = janet_checktype(lhs, JANET_TUPLE)
                              || janet_checktype(lhs, JANET_ARRAY);
    int rhs_is_indexed = janet_checktype(rhs, JANET_ARRAY)
                         || (janet_checktype(rhs, JANET_TUPLE) && (janet_tuple_flag(janet_unwrap_tuple(rhs)) & JANET_TUPLE_FLAG_BRACKETCTOR));
    uint32_t has_drop = opts.flags & JANET_FOPTS_DROP;

    JanetFopts subopts = janetc_fopts_default(c);
    subopts.flags = opts.flags & ~(JANET_FOPTS_TAIL | JANET_FOPTS_DROP);

    if (has_drop && can_destructure_lhs && rhs_is_indexed) {
        /* Code is of the form (def [a b] [1 2]), avoid the allocation of two tuples */
        JanetView view_lhs = {0};
        JanetView view_rhs = {0};
        janet_indexed_view(lhs, &view_lhs.items, &view_lhs.len);
        janet_indexed_view(rhs, &view_rhs.items, &view_rhs.len);
        int found_amp = 0;
        for (int32_t i = 0; i < view_lhs.len; i++) {
            if (janet_symeq(view_lhs.items[i], "&")) {
                found_amp = 1;
                /* Good error will be generated later. */
                break;
            }
        }
        if (!found_amp) {
            for (int32_t i = 0; i < view_lhs.len; i++) {
                Janet sub_rhs = view_rhs.len <= i ? janet_wrap_nil() : view_rhs.items[i];
                into = dohead_destructure(c, into, subopts, view_lhs.items[i], sub_rhs);
            }
            return into;
        }
    }

    /* No optimization, do the simple way */
    subopts.hint = opts.hint;
    JanetSlot ret = janetc_value(subopts, rhs);
    SlotHeadPair shp = {lhs, ret};
    janet_v_push(into, shp);
    return into;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x10(%rbp), %r14
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
movq %rdx, -0x40(%rbp)
movq %rdx, %rsi
andq %rax, %rsi
movabsq $0x4800000000000, %rdx  # imm = 0x4800000000000
addq %rsi, %rdx
shrq $0x30, %rdx
sete -0x29(%rbp)
andq %rcx, %rax
movabsq $-0x4800000000000, %rdx # imm = 0xFFFB800000000000
cmpq %rdx, %rax
movq %rcx, -0x38(%rbp)
je 0x3da46
movabsq $-0x4000000000000, %rdx # imm = 0xFFFC000000000000
cmpq %rdx, %rax
jne 0x3da4b
movq %rcx, %rdi
callq 0x4b1f1
movb -0x1e(%rax), %r12b
andb $0x1, %r12b
jmp 0x3da4e
movb $0x1, %r12b
jmp 0x3da4e
xorl %r12d, %r12d
movl 0x20(%r14), %r14d
leaq -0xa8(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x19f04
movl %r14d, %eax
andl $0xfffaffff, %eax       # imm = 0xFFFAFFFF
movl %eax, 0x20(%r13)
shrl $0x12, %r14d
andl $0x1, %r14d
andb -0x29(%rbp), %r14b
cmpb $0x1, %r14b
jne 0x3dae6
testb %r12b, %r12b
je 0x3dae6
xorps %xmm0, %xmm0
leaq -0x78(%rbp), %rdx
movaps %xmm0, -0x8(%rdx)
leaq -0x58(%rbp), %r13
movaps %xmm0, -0x8(%r13)
leaq -0x80(%rbp), %rsi
movq -0x40(%rbp), %rdi
callq 0x45c58
leaq -0x60(%rbp), %rsi
movq -0x38(%rbp), %rdi
movq %r13, %rdx
callq 0x45c58
xorl %r14d, %r14d
leaq 0x1c4e0(%rip), %r13     # 0x59fa2
movslq -0x78(%rbp), %rax
cmpq %rax, %r14
jge 0x3dba2
movq -0x80(%rbp), %rax
movq (%rax,%r14,8), %rdi
movq %r13, %rsi
callq 0x17fde
incq %r14
testl %eax, %eax
je 0x3dac2
leaq 0x10(%rbp), %rcx
movq 0x18(%rcx), %rax
movq %rax, -0x90(%rbp)
movups 0x8(%rcx), %xmm0
movups %xmm0, -0xa0(%rbp)
movq -0x88(%rbp), %rax
movq %rax, 0x20(%rsp)
movups -0xa8(%rbp), %xmm0
movups -0x98(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq -0x80(%rbp), %r15
movq %r15, %rdi
movq -0x38(%rbp), %rsi
callq 0x1abbf
movq 0x10(%r15), %rax
movq %rax, -0x50(%rbp)
movups (%r15), %xmm0
movaps %xmm0, -0x60(%rbp)
testq %rbx, %rbx
je 0x3db53
movl -0x4(%rbx), %eax
leal 0x1(%rax), %ecx
cmpl -0x8(%rbx), %ecx
jl 0x3db6a
pushq $0x1
popq %rsi
pushq $0x20
popq %rdx
movq %rbx, %rdi
callq 0x4799c
movq %rax, %rbx
movl -0x4(%rax), %eax
leal 0x1(%rax), %ecx
movl %ecx, -0x4(%rbx)
cltq
shlq $0x5, %rax
movq -0x40(%rbp), %rcx
movq %rcx, (%rbx,%rax)
movaps -0x60(%rbp), %xmm0
movups %xmm0, 0x8(%rbx,%rax)
movq -0x50(%rbp), %rcx
movq %rcx, 0x18(%rbx,%rax)
movq %rbx, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r12d, %r12d
movabsq $-0x77fffffffffff, %r14 # imm = 0xFFF8800000000001
cltq
cmpq %rax, %r12
jge 0x3db8d
movslq -0x58(%rbp), %rax
cmpq %rax, %r12
jge 0x3dbc9
movq -0x60(%rbp), %rax
movq (%rax,%r12,8), %rcx
jmp 0x3dbd4
movq %r14, %rdi
callq 0x4b313
movq %rax, %rcx
movq -0x80(%rbp), %rax
movq (%rax,%r12,8), %rdx
movq -0x88(%rbp), %rax
movq %rax, 0x20(%rsp)
movups -0xa8(%rbp), %xmm0
movups -0x98(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3d9c8
movq %rax, %rbx
incq %r12
movl -0x78(%rbp), %eax
jmp 0x3dbaf