// File: /workspace/github_c_makefile_star2_O3/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
leaq 0x10(%rbp), %r15
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
movq %rdx, %r8
andq %rax, %r8
movabsq $0x4800000000000, %rsi  # imm = 0x4800000000000
addq %r8, %rsi
shrq $0x30, %rsi
sete %r8b
andq %rcx, %rax
movabsq $-0x4800000000000, %rsi # imm = 0xFFFB800000000000
cmpq %rsi, %rax
movq %rdi, -0x38(%rbp)
movq %rcx, -0x40(%rbp)
movb %r8b, -0x29(%rbp)
je 0x41032
movabsq $-0x4000000000000, %rsi # imm = 0xFFFC000000000000
movq %rdx, %r14
cmpq %rsi, %rax
jne 0x4103a
movq %rcx, %rdi
callq 0x4ebc4
movb -0x1e(%rax), %r12b
andb $0x1, %r12b
jmp 0x4103d
movq %rdx, %r14
movb $0x1, %r12b
jmp 0x4103d
xorl %r12d, %r12d
movl 0x20(%r15), %r15d
leaq -0xa8(%rbp), %r13
movq %r13, %rdi
movq -0x38(%rbp), %rsi
callq 0x1ba98
movl %r15d, %eax
andl $0xfffaffff, %eax       # imm = 0xFFFAFFFF
movl %eax, 0x20(%r13)
shrl $0x12, %r15d
andl $0x1, %r15d
andb -0x29(%rbp), %r15b
cmpb $0x1, %r15b
movq %r14, %r15
jne 0x4116f
testb %r12b, %r12b
je 0x4116f
xorps %xmm0, %xmm0
leaq -0x78(%rbp), %rdx
movaps %xmm0, -0x8(%rdx)
leaq -0x58(%rbp), %r13
movaps %xmm0, -0x8(%r13)
leaq -0x80(%rbp), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x49726
leaq -0x60(%rbp), %rsi
movq -0x40(%rbp), %rdi
movq %r13, %rdx
callq 0x49726
cmpl $0x0, 0x8(%r14)
jle 0x41216
xorl %r14d, %r14d
leaq 0x1ced8(%rip), %r13     # 0x5dfa2
movq -0x80(%rbp), %rax
movq (%rax,%r14,8), %rdi
movq %r13, %rsi
callq 0x19a45
testl %eax, %eax
jne 0x4116f
incq %r14
movslq -0x78(%rbp), %rax
cmpq %rax, %r14
jl 0x410ca
testl %eax, %eax
jle 0x41216
xorl %r12d, %r12d
movabsq $-0x77fffffffffff, %r14 # imm = 0xFFF8800000000001
movq -0x38(%rbp), %r15
movslq -0x58(%rbp), %rax
cmpq %rax, %r12
jge 0x4111a
movq -0x60(%rbp), %rax
movq (%rax,%r12,8), %rcx
jmp 0x41125
movq %r14, %rdi
callq 0x4ece6
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 0x40fb0
movq %rax, %rbx
incq %r12
movslq -0x78(%rbp), %rax
cmpq %rax, %r12
jl 0x41107
jmp 0x41216
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), %r14
movq %r14, %rdi
movq -0x40(%rbp), %rsi
callq 0x1c7be
movq 0x10(%r14), %rax
movq %rax, -0x50(%rbp)
movups (%r14), %xmm0
movaps %xmm0, -0x60(%rbp)
testq %rbx, %rbx
je 0x411dc
movl -0x4(%rbx), %eax
leal 0x1(%rax), %ecx
cmpl -0x8(%rbx), %ecx
jl 0x411f7
movq %rbx, %rdi
movl $0x1, %esi
movl $0x20, %edx
callq 0x4b4e8
movq %rax, %rbx
movl -0x4(%rax), %eax
leal 0x1(%rax), %ecx
movl %ecx, -0x4(%rbx)
cltq
shlq $0x5, %rax
movq %r15, (%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