// File: /workspace/github_c_makefile_star2_O1/stetre[P]moonsndfile/src/chunk.c
// Function: GetChunks
static int GetChunks(lua_State *L)
/* {chunk} = get_chunks(sndfile, [id]) */
    {
    ud_t *ud;
    const char *id;
    size_t id_size, i;
    chunk_t chunk;
    chunkiter_t *iter;

    sndfile_t sndfile = checksndfile(L, 1, &ud);
    id = luaL_optlstring(L, 2, NULL, &id_size);
    CheckPfn(L, get_chunk_iterator, 1, 0, 26);

    if(id)
        {
        if((id_size == 0) || (id_size > 64))
            return luaL_argerror(L, 2, "invalid id length");
        memset(&chunk, 0, sizeof(chunk));
        memcpy(&chunk.id, id, id_size);
        chunk.id_size = id_size;
        }

    iter = sf.get_chunk_iterator(sndfile, id ? &chunk : NULL);

    lua_newtable(L);
    i = 0;
    while(iter)
        {
        memset(&chunk, 0, sizeof(chunk));
        if(sf.get_chunk_size(iter, &chunk) != 0)
            {
            lua_pop(L, 1);
            return sndfileerror(L, sndfile);
            }
        /* Now chunk.id and chunk.id_size are properly set and chunk.datalen is set
         * to the data length. We need to allocate the memory for the data field,
         * and then retrieve the data.
         */
        if(chunk.datalen > 0)
            chunk.data = Malloc(L, chunk.datalen);
        if(sf.get_chunk_data(iter, &chunk) != 0)
            { 
            Free(L, chunk.data); 
            lua_pop(L, 1);
            return sndfileerror(L, sndfile);
            }
        pushchunk(L, &chunk);
        lua_rawseti(L, -2, ++i);
        Free(L, chunk.data); 
        iter = sf.next_chunk_iterator(iter);
        }
    return 1;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
leaq 0x86ba(%rip), %rcx      # 0xd097
leaq 0x60(%rsp), %rdx
movl $0x1, %esi
callq 0x4400
movq %rax, %rbp
leaq 0x8(%rsp), %rcx
movq %rbx, %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x4270
movq 0xe5d6(%rip), %r14      # 0x12fe0
movq 0x120(%r14), %r13
testq %r13, %r13
je 0x4a44
testq %rax, %rax
je 0x4a73
movq 0x8(%rsp), %r12
leaq -0x41(%r12), %rcx
cmpq $-0x41, %rcx
ja 0x4a78
leaq 0x8733(%rip), %rdx      # 0xd165
movq %rbx, %rdi
movl $0x2, %esi
callq 0x4110
jmp 0x4bc0
movl $0x1, %edi
xorl %esi, %esi
movl $0x1a, %edx
callq 0x4440
testl %eax, %eax
je 0x4b7a
leaq 0x86d9(%rip), %rsi      # 0xd13d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x46c0
jmp 0x4bc0
xorl %r15d, %r15d
jmp 0x4aaa
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r15
movaps %xmm0, 0x40(%r15)
movaps %xmm0, 0x30(%r15)
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, (%r15)
movq %r15, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x44b0
movl %r12d, 0x40(%r15)
movq %rbp, (%rsp)
movq %rbp, %rdi
movq %r15, %rsi
callq *%r13
movq %rax, %r15
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4220
movl $0x1, %ebp
testq %r15, %r15
je 0x4bc2
movl $0x1, %r12d
leaq 0x10(%rsp), %r13
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq *0x130(%r14)
testl %eax, %eax
jne 0x4ba7
movl 0x54(%rsp), %esi
testq %rsi, %rsi
je 0x4b26
movq %rbx, %rdi
callq 0x41e0
movq %rax, 0x58(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq *0x138(%r14)
testl %eax, %eax
jne 0x4b9a
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4200
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movq %r12, %rdx
callq 0x4490
movq 0x58(%rsp), %rsi
movq %rbx, %rdi
callq 0x43a0
movq %r15, %rdi
callq *0x128(%r14)
movq %rax, %r15
incq %r12
testq %rax, %rax
jne 0x4adf
jmp 0x4bc2
leaq 0x857e(%rip), %rsi      # 0xd0ff
movq %rbx, %rdi
movl $0x1, %edx
xorl %ecx, %ecx
movl $0x1a, %r8d
xorl %eax, %eax
callq 0x46c0
jmp 0x4bc0
movq 0x58(%rsp), %rsi
movq %rbx, %rdi
callq 0x43a0
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x4080
movq %rbx, %rdi
movq (%rsp), %rsi
callq 0x4340
movl %eax, %ebp
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq