// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xa8, %rsp
movq %rdi, 0x98(%rsp)
movq 0x98(%rsp), %rdi
movl $0x1, %esi
leaq 0x90(%rsp), %rdx
leaq 0xd62c(%rip), %rcx      # 0x12097
callq 0x4400
movq %rax, 0x18(%rsp)
movq 0x98(%rsp), %rdi
movl $0x2, %esi
xorl %eax, %eax
movl %eax, %edx
leaq 0x80(%rsp), %rcx
callq 0x4270
movq %rax, 0x88(%rsp)
movq 0x1253e(%rip), %rax     # 0x16fe0
cmpq $0x0, 0x120(%rax)
jne 0x4b13
movl $0x1, %edi
xorl %esi, %esi
movl $0x1a, %edx
callq 0x4440
cmpl $0x0, %eax
jne 0x4af1
movq 0x98(%rsp), %rdi
leaq 0xd62e(%rip), %rsi      # 0x120ff
movl $0x1, %edx
xorl %ecx, %ecx
movl $0x1a, %r8d
movb $0x0, %al
callq 0x46c0
movl %eax, 0xa4(%rsp)
jmp 0x4d53
movq 0x98(%rsp), %rdi
leaq 0xd63d(%rip), %rsi      # 0x1213d
movb $0x0, %al
callq 0x46c0
movl %eax, 0xa4(%rsp)
jmp 0x4d53
jmp 0x4b15
cmpq $0x0, 0x88(%rsp)
je 0x4b92
cmpq $0x0, 0x80(%rsp)
je 0x4b36
cmpq $0x40, 0x80(%rsp)
jbe 0x4b5b
movq 0x98(%rsp), %rdi
movl $0x2, %esi
leaq 0xd61b(%rip), %rdx      # 0x12165
callq 0x4100
movl %eax, 0xa4(%rsp)
jmp 0x4d53
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
movl $0x50, %edx
callq 0x4310
leaq 0x28(%rsp), %rdi
movq 0x88(%rsp), %rsi
movq 0x80(%rsp), %rdx
callq 0x44b0
movq 0x80(%rsp), %rax
movl %eax, 0x68(%rsp)
movq 0x12447(%rip), %rax     # 0x16fe0
movq 0x120(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x88(%rsp)
je 0x4bc5
leaq 0x28(%rsp), %rax
movq %rax, (%rsp)
jmp 0x4bcd
xorl %eax, %eax
movq %rax, (%rsp)
jmp 0x4bcd
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rdi
movq (%rsp), %rsi
callq *%rax
movq %rax, 0x20(%rsp)
movq 0x98(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x4220
movq $0x0, 0x78(%rsp)
cmpq $0x0, 0x20(%rsp)
je 0x4d48
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
movl $0x50, %edx
callq 0x4310
movq 0x123c0(%rip), %rax     # 0x16fe0
movq 0x130(%rax), %rax
movq 0x20(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq *%rax
cmpl $0x0, %eax
je 0x4c68
movq 0x98(%rsp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x4080
movq 0x98(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x4340
movl %eax, 0xa4(%rsp)
jmp 0x4d53
cmpl $0x0, 0x6c(%rsp)
jbe 0x4c87
movq 0x98(%rsp), %rdi
movl 0x6c(%rsp), %eax
movl %eax, %esi
callq 0x41d0
movq %rax, 0x70(%rsp)
movq 0x12352(%rip), %rax     # 0x16fe0
movq 0x138(%rax), %rax
movq 0x20(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq *%rax
cmpl $0x0, %eax
je 0x4ce5
movq 0x98(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x43a0
movq 0x98(%rsp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x4080
movq 0x98(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x4340
movl %eax, 0xa4(%rsp)
jmp 0x4d53
movq 0x98(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x4200
movq 0x98(%rsp), %rdi
movq 0x78(%rsp), %rdx
addq $0x1, %rdx
movq %rdx, 0x78(%rsp)
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x4490
movq 0x98(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x43a0
movq 0x122b0(%rip), %rax     # 0x16fe0
movq 0x128(%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
movq %rax, 0x20(%rsp)
jmp 0x4bfc
movl $0x1, 0xa4(%rsp)
movl 0xa4(%rsp), %eax
addq $0xa8, %rsp
retq
nopw %cs:(%rax,%rax)