// File: /workspace/github_c_makefile_star2_O1/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 $0x98, %rsp
movq %rsi, %r14
movq %rdi, %r12
leaq 0x10(%rbp), %rbx
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
movq %rdx, -0x58(%rbp)
movq %rdx, %rsi
andq %rax, %rsi
movabsq $0x4800000000000, %rdx  # imm = 0x4800000000000
addq %rsi, %rdx
shrq $0x30, %rdx
sete %sil
andq %rcx, %rax
movabsq $-0x4800000000000, %rdx # imm = 0xFFFB800000000000
cmpq %rdx, %rax
movq %rcx, -0x38(%rbp)
movb %sil, -0x29(%rbp)
je 0x417aa
movabsq $-0x4000000000000, %rdx # imm = 0xFFFC000000000000
cmpq %rdx, %rax
jne 0x417af
movq %rcx, %rdi
callq 0x4f838
movb -0x1e(%rax), %r15b
andb $0x1, %r15b
jmp 0x417b2
movb $0x1, %r15b
jmp 0x417b2
xorl %r15d, %r15d
movl 0x20(%rbx), %ebx
leaq -0x98(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x1bbf0
movl %ebx, %eax
andl $0xfffaffff, %eax       # imm = 0xFFFAFFFF
movl %eax, 0x20(%r13)
shrl $0x12, %ebx
andl $0x1, %ebx
andb -0x29(%rbp), %bl
cmpb $0x1, %bl
jne 0x4187d
testb %r15b, %r15b
je 0x4187d
xorps %xmm0, %xmm0
leaq -0x48(%rbp), %rdx
movaps %xmm0, -0x8(%rdx)
leaq -0x68(%rbp), %r13
movaps %xmm0, -0x8(%r13)
leaq -0x50(%rbp), %rbx
movq -0x58(%rbp), %rdi
movq %rbx, %rsi
callq 0x4a23e
leaq -0x70(%rbp), %rsi
movq -0x38(%rbp), %r15
movq %r15, %rdi
movq %r13, %rdx
callq 0x4a23e
cmpl $0x0, 0x8(%rbx)
setg %bl
jle 0x4188a
movq -0x50(%rbp), %rax
movq (%rax), %rdi
leaq 0x1d767(%rip), %rsi     # 0x5efa2
callq 0x19b0b
testl %eax, %eax
jne 0x41901
movl $0x1, %r15d
leaq 0x1d74d(%rip), %r13     # 0x5efa2
movslq -0x48(%rbp), %rax
cmpq %rax, %r15
setl %bl
jge 0x41886
movq -0x50(%rbp), %rax
movq (%rax,%r15,8), %rdi
movq %r13, %rsi
callq 0x19b0b
incq %r15
testl %eax, %eax
je 0x41855
jmp 0x418fd
movq -0x38(%rbp), %r15
jmp 0x41909
movq -0x38(%rbp), %r15
cmpl $0x0, -0x48(%rbp)
jle 0x41901
xorl %r15d, %r15d
movabsq $-0x77fffffffffff, %r13 # imm = 0xFFF8800000000001
movslq -0x68(%rbp), %rax
cmpq %rax, %r15
jge 0x418b0
movq -0x70(%rbp), %rax
movq (%rax,%r15,8), %rcx
jmp 0x418bb
movq %r13, %rdi
callq 0x4f95a
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq (%rax,%r15,8), %rdx
movq -0x78(%rbp), %rax
movq %rax, 0x20(%rsp)
movups -0x98(%rbp), %xmm0
movups -0x88(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x41728
movq %rax, %r14
incq %r15
movslq -0x48(%rbp), %rax
cmpq %rax, %r15
jl 0x4189d
movq -0x38(%rbp), %r15
testb %bl, %bl
je 0x419ae
leaq 0x10(%rbp), %rcx
movq 0x18(%rcx), %rax
movq %rax, -0x80(%rbp)
movups 0x8(%rcx), %xmm0
movups %xmm0, -0x90(%rbp)
movq -0x78(%rbp), %rax
movq %rax, 0x20(%rsp)
movups -0x98(%rbp), %xmm0
movups -0x88(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1ca05
movq 0x10(%rbx), %rax
movq %rax, -0x60(%rbp)
movups (%rbx), %xmm0
movaps %xmm0, -0x70(%rbp)
testq %r14, %r14
je 0x4196f
movl -0x4(%r14), %eax
incl %eax
cmpl -0x8(%r14), %eax
jl 0x41984
movq %r14, %rdi
movl $0x1, %esi
movl $0x20, %edx
callq 0x4c0b4
movq %rax, %r14
movslq -0x4(%r14), %rax
leal 0x1(%rax), %ecx
movl %ecx, -0x4(%r14)
shlq $0x5, %rax
movq -0x58(%rbp), %rcx
movq %rcx, (%r14,%rax)
movaps -0x70(%rbp), %xmm0
movups %xmm0, 0x8(%r14,%rax)
movq -0x60(%rbp), %rcx
movq %rcx, 0x18(%r14,%rax)
movq %r14, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq