// File: /workspace/github_c_makefile_star2_O0/stetre[P]moonsndfile/src/sndfile.c
// Function: Open
static int Open(lua_State *L, int openfd)
    {
    SF_INFO info;
    sndfile_t sndfile;
    const char *path;
    luaL_Stream *s;
    int mode, fd = -1, close_desc = 1;

    if(openfd) //@@FIXME: does this work under MINGW?
        {
        s = (luaL_Stream*)luaL_testudata(L, 1, LUA_FILEHANDLE);
        if(s)
            {
            fd = fileno(s->f); /* POSIX */
            if(fd == -1)
                return luaL_argerror(L, 1, errstring(ERR_TYPE));
            }
        else
            fd = luaL_checkinteger(L, 1);

        mode = checkopenmode(L, 2);
        close_desc = optboolean(L, 4, 0);
        }
    else
        {
        path = luaL_checkstring(L, 1);
        mode = checkopenmode(L, 2);
        }

    /* openmode="w" or format="raw" require the user to specify format, channels and samplerate.
     * openmode="r", the info is obtained from the file (provided it exists)
     * openmode="rw", the info is obtained from the file (provided it exists)
     * @@ if openmode="rw" and the file does not exist, then a new file is created
     *    but an error is raised because info.format is 0.
     */
    memset(&info, 0, sizeof(info));
    if(!lua_isnoneornil(L, 3))
        {
        checkinfo(L, 3, &info);
        if((((info.format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)) && (mode != SFM_WRITE))
            return luaL_argerror(L, 3, "info must be specified only for format='raw' or openmode ='w'");
//      if(!sf.format_check(&info))
//          return luaL_argerror(L, 3, "invalid combination of info values");
        }
    else if(mode == SFM_WRITE)
        return luaL_argerror(L, 3, "missing info, required for openmode ='w'");

    if(openfd)
        sndfile = sf.open_fd(fd, mode, &info, close_desc);
    else    
        sndfile = sf.open(path, mode, &info);

    if(!sndfile)
        return sndfileerror(L, NULL);

    return Create(L, sndfile, &info);
    }

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movl %esi, 0x54(%rsp)
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0xc(%rsp)
cmpl $0x0, 0x54(%rsp)
je 0xe404
movq 0x58(%rsp), %rdi
movl $0x1, %esi
leaq 0x51c4(%rip), %rdx      # 0x1352d
callq 0x4570
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
je 0xe3c2
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0x44f0
movl %eax, 0x10(%rsp)
cmpl $-0x1, 0x10(%rsp)
jne 0xe3c0
movq 0x58(%rsp), %rax
movq %rax, (%rsp)
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
callq 0x4660
movq (%rsp), %rdi
movq %rax, %rdx
movl $0x1, %esi
callq 0x4100
movl %eax, 0x64(%rsp)
jmp 0xe54c
jmp 0xe3d5
movq 0x58(%rsp), %rdi
movl $0x1, %esi
callq 0x4470
movl %eax, 0x10(%rsp)
movq 0x58(%rsp), %rdi
movl $0x6, %esi
movl $0x2, %edx
callq 0x4120
movl %eax, 0x14(%rsp)
movq 0x58(%rsp), %rdi
movl $0x4, %esi
xorl %edx, %edx
callq 0x41a0
movl %eax, 0xc(%rsp)
jmp 0xe434
movq 0x58(%rsp), %rdi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x4380
movq %rax, 0x20(%rsp)
movq 0x58(%rsp), %rdi
movl $0x6, %esi
movl $0x2, %edx
callq 0x4120
movl %eax, 0x14(%rsp)
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x4310
movq 0x58(%rsp), %rdi
movl $0x3, %esi
callq 0x4730
cmpl $0x0, %eax
jle 0xe4a5
movq 0x58(%rsp), %rdi
movl $0x3, %esi
leaq 0x30(%rsp), %rdx
callq 0x45f0
movl 0x40(%rsp), %eax
andl $0xfff0000, %eax        # imm = 0xFFF0000
cmpl $0x40000, %eax          # imm = 0x40000
je 0xe4a3
cmpl $0x20, 0x14(%rsp)
je 0xe4a3
movq 0x58(%rsp), %rdi
movl $0x3, %esi
leaq 0x509e(%rip), %rdx      # 0x13533
callq 0x4100
movl %eax, 0x64(%rsp)
jmp 0xe54c
jmp 0xe4cd
cmpl $0x20, 0x14(%rsp)
jne 0xe4cb
movq 0x58(%rsp), %rdi
movl $0x3, %esi
leaq 0x50b4(%rip), %rdx      # 0x13571
callq 0x4100
movl %eax, 0x64(%rsp)
jmp 0xe54c
jmp 0xe4cd
cmpl $0x0, 0x54(%rsp)
je 0xe4f9
movq 0x8b05(%rip), %rax      # 0x16fe0
movq 0x8(%rax), %rax
movl 0x10(%rsp), %edi
movl 0x14(%rsp), %esi
movl 0xc(%rsp), %ecx
leaq 0x30(%rsp), %rdx
callq *%rax
movq %rax, 0x28(%rsp)
jmp 0xe518
movq 0x8ae0(%rip), %rax      # 0x16fe0
movq (%rax), %rax
movq 0x20(%rsp), %rdi
movl 0x14(%rsp), %esi
leaq 0x30(%rsp), %rdx
callq *%rax
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0xe534
movq 0x58(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4340
movl %eax, 0x64(%rsp)
jmp 0xe54c
movq 0x58(%rsp), %rdi
movq 0x28(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0xe560
movl %eax, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)