// File: /workspace/github_c_makefile_star2_O2/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 0x76c9(%rip), %rcx      # 0xc097
pushq $0x1
popq %rsi
leaq 0x60(%rsp), %rdx
callq 0x4400
movq %rax, %r13
pushq $0x2
popq %rsi
leaq 0x8(%rsp), %rcx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x4270
movq 0xd5e9(%rip), %rbp      # 0x11fe0
movq 0x120(%rbp), %r12
testq %r12, %r12
je 0x4a2e
testq %rax, %rax
je 0x4a59
movq 0x8(%rsp), %r15
leaq -0x41(%r15), %rcx
cmpq $-0x41, %rcx
ja 0x4a5e
leaq 0x7747(%rip), %rdx      # 0xc165
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x4110
jmp 0x4b97
pushq $0x1
popq %rdi
pushq $0x1a
popq %rdx
xorl %esi, %esi
callq 0x4440
testl %eax, %eax
je 0x4b57
leaq 0x76f3(%rip), %rsi      # 0xc13d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x46c0
jmp 0x4b97
xorl %r14d, %r14d
jmp 0x4a90
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movaps %xmm0, 0x40(%r14)
movaps %xmm0, 0x30(%r14)
movaps %xmm0, 0x20(%r14)
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
movq %r14, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x44b0
movl %r15d, 0x40(%r14)
movq %r13, (%rsp)
movq %r13, %rdi
movq %r14, %rsi
callq *%r12
movq %rax, %r15
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4220
pushq $0x1
popq %r12
leaq 0x10(%rsp), %r13
pushq $-0x2
popq %r14
testq %r15, %r15
je 0x4b52
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(%rbp)
testl %eax, %eax
jne 0x4b80
movl 0x54(%rsp), %esi
testq %rsi, %rsi
je 0x4b08
movq %rbx, %rdi
callq 0x41e0
movq %rax, 0x58(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq *0x138(%rbp)
testl %eax, %eax
jne 0x4b73
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4200
movq %rbx, %rdi
movl %r14d, %esi
movq %r12, %rdx
callq 0x4490
movq 0x58(%rsp), %rsi
movq %rbx, %rdi
callq 0x43a0
movq %r15, %rdi
callq *0x128(%rbp)
movq %rax, %r15
incq %r12
jmp 0x4ab9
pushq $0x1
popq %rax
jmp 0x4b97
leaq 0x75a1(%rip), %rsi      # 0xc0ff
pushq $0x1
popq %rdx
pushq $0x1a
popq %r8
movq %rbx, %rdi
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x46c0
jmp 0x4b97
movq 0x58(%rsp), %rsi
movq %rbx, %rdi
callq 0x43a0
pushq $-0x2
popq %rsi
movq %rbx, %rdi
callq 0x4080
movq %rbx, %rdi
movq (%rsp), %rsi
callq 0x4340
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq