// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/zlib-1.3.0.1/gzlib.c
// Function: gz_open
local gzFile gz_open(const void *path, int fd, const char *mode) {
    gz_statep state;
    z_size_t len;
    int oflag;
#ifdef O_CLOEXEC
    int cloexec = 0;
#endif
#ifdef O_EXCL
    int exclusive = 0;
#endif

    /* check input */
    if (path == NULL)
        return NULL;

    /* allocate gzFile structure to return */
    state = (gz_statep)malloc(sizeof(gz_state));
    if (state == NULL)
        return NULL;
    state->size = 0;            /* no buffers allocated yet */
    state->want = GZBUFSIZE;    /* requested buffer size */
    state->msg = NULL;          /* no error message yet */

    /* interpret mode */
    state->mode = GZ_NONE;
    state->level = Z_DEFAULT_COMPRESSION;
    state->strategy = Z_DEFAULT_STRATEGY;
    state->direct = 0;
    while (*mode) {
        if (*mode >= '0' && *mode <= '9')
            state->level = *mode - '0';
        else
            switch (*mode) {
            case 'r':
                state->mode = GZ_READ;
                break;
#ifndef NO_GZCOMPRESS
            case 'w':
                state->mode = GZ_WRITE;
                break;
            case 'a':
                state->mode = GZ_APPEND;
                break;
#endif
            case '+':       /* can't read and write at the same time */
                free(state);
                return NULL;
            case 'b':       /* ignore -- will request binary anyway */
                break;
#ifdef O_CLOEXEC
            case 'e':
                cloexec = 1;
                break;
#endif
#ifdef O_EXCL
            case 'x':
                exclusive = 1;
                break;
#endif
            case 'f':
                state->strategy = Z_FILTERED;
                break;
            case 'h':
                state->strategy = Z_HUFFMAN_ONLY;
                break;
            case 'R':
                state->strategy = Z_RLE;
                break;
            case 'F':
                state->strategy = Z_FIXED;
                break;
            case 'T':
                state->direct = 1;
                break;
            default:        /* could consider as an error, but just ignore */
                ;
            }
        mode++;
    }

    /* must provide an "r", "w", or "a" */
    if (state->mode == GZ_NONE) {
        free(state);
        return NULL;
    }

    /* can't force transparent read */
    if (state->mode == GZ_READ) {
        if (state->direct) {
            free(state);
            return NULL;
        }
        state->direct = 1;      /* for empty file */
    }

    /* save the path name for error messages */
#ifdef WIDECHAR
    if (fd == -2) {
        len = wcstombs(NULL, path, 0);
        if (len == (z_size_t)-1)
            len = 0;
    }
    else
#endif
        len = strlen((const char *)path);
    state->path = (char *)malloc(len + 1);
    if (state->path == NULL) {
        free(state);
        return NULL;
    }
#ifdef WIDECHAR
    if (fd == -2)
        if (len)
            wcstombs(state->path, path, len + 1);
        else
            *(state->path) = 0;
    else
#endif
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
        (void)snprintf(state->path, len + 1, "%s", (const char *)path);
#else
        strcpy(state->path, path);
#endif

    /* compute the flags for open() */
    oflag =
#ifdef O_LARGEFILE
        O_LARGEFILE |
#endif
#ifdef O_BINARY
        O_BINARY |
#endif
#ifdef O_CLOEXEC
        (cloexec ? O_CLOEXEC : 0) |
#endif
        (state->mode == GZ_READ ?
         O_RDONLY :
         (O_WRONLY | O_CREAT |
#ifdef O_EXCL
          (exclusive ? O_EXCL : 0) |
#endif
          (state->mode == GZ_WRITE ?
           O_TRUNC :
           O_APPEND)));

    /* open the file with the appropriate flags (or just use fd) */
    state->fd = fd > -1 ? fd : (
#ifdef WIDECHAR
        fd == -2 ? _wopen(path, oflag, 0666) :
#endif
        open((const char *)path, oflag, 0666));
    if (state->fd == -1) {
        free(state->path);
        free(state);
        return NULL;
    }
    if (state->mode == GZ_APPEND) {
        LSEEK(state->fd, 0, SEEK_END);  /* so gzoffset() is correct */
        state->mode = GZ_WRITE;         /* simplify later checks */
    }

    /* save the current position for rewinding (only if reading) */
    if (state->mode == GZ_READ) {
        state->start = LSEEK(state->fd, 0, SEEK_CUR);
        if (state->start == -1) state->start = 0;
    }

    /* initialize stream */
    gz_reset(state);

    /* return stream */
    return (gzFile)state;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x99b5f
movq %rdx, %r15
movl %esi, %r12d
movq %rdi, %r14
movl $0xf0, %edi
callq 0xb810
movq %rax, %rbx
xorl %eax, %eax
testq %rbx, %rbx
je 0x99b5f
movabsq $0x200000000000, %rcx   # imm = 0x200000000000
movq %rcx, 0x28(%rbx)
movq $0x0, 0x78(%rbx)
movl %eax, 0x18(%rbx)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0x58(%rbx)
movl %eax, 0x40(%rbx)
movb (%r15), %dil
testb %dil, %dil
je 0x99b57
incq %r15
xorl %eax, %eax
leaq 0x5e420(%rip), %rcx     # 0xf7d4c
xorl %r13d, %r13d
xorl %edx, %edx
xorl %esi, %esi
leal -0x30(%rdi), %r8d
cmpb $0x9, %r8b
ja 0x99954
movzbl %r8b, %edi
movl %edi, 0x58(%rbx)
movb (%r15), %dil
incq %r15
testb %dil, %dil
jne 0x99933
jmp 0x99a26
movzbl %dil, %edi
cmpl $0x60, %edi
jle 0x99982
cmpl $0x71, %edi
jg 0x9999f
addl $-0x61, %edi
cmpl $0x7, %edi
ja 0x99944
movslq (%rcx,%rdi,4), %rdi
addq %rcx, %rdi
jmpq *%rdi
movl $0x1, 0x18(%rbx)
movl $0x1, %r13d
jmp 0x99944
cmpl $0x51, %edi
jle 0x999bd
cmpl $0x52, %edi
je 0x999f0
cmpl $0x54, %edi
jne 0x99944
movl $0x1, 0x40(%rbx)
movl $0x1, %eax
jmp 0x99944
cmpl $0x78, %edi
je 0x99a0e
cmpl $0x77, %edi
je 0x999fc
cmpl $0x72, %edi
jne 0x99944
movl $0x1c4f, 0x18(%rbx)     # imm = 0x1C4F
movl $0x1c4f, %r13d          # imm = 0x1C4F
jmp 0x99944
cmpl $0x46, %edi
jne 0x99a18
movl $0x4, 0x5c(%rbx)
jmp 0x99944
movl $0x2, 0x5c(%rbx)
jmp 0x99944
movl $0x1, 0x5c(%rbx)
jmp 0x99944
movl $0x1, %esi
jmp 0x99944
movl $0x3, 0x5c(%rbx)
jmp 0x99944
movl $0x79b1, 0x18(%rbx)     # imm = 0x79B1
movl $0x79b1, %r13d          # imm = 0x79B1
jmp 0x99944
movl $0x1, %edx
jmp 0x99944
cmpl $0x2b, %edi
jne 0x99944
jmp 0x99b57
testl %esi, %esi
setne %sil
xorl %ebp, %ebp
testl %edx, %edx
setne %cl
cmpl $0x1c4f, %r13d          # imm = 0x1C4F
je 0x99a47
testl %r13d, %r13d
je 0x99b57
jmp 0x99a56
testl %eax, %eax
jne 0x99b57
movl $0x1, 0x40(%rbx)
movb %sil, 0x2(%rsp)
movb %cl, 0x3(%rsp)
movl %r12d, 0x4(%rsp)
movq %r14, %rdi
callq 0xb260
movq %rax, %r12
incq %r12
movq %r12, %rdi
callq 0xb810
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x99b57
movq %rax, %r15
leaq 0x55070(%rip), %rdx     # 0xeeb01
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rcx
xorl %eax, %eax
callq 0xba10
movl 0x4(%rsp), %edi
testl %edi, %edi
js 0x99aae
movl %edi, 0x1c(%rbx)
jmp 0x99b06
xorl %ecx, %ecx
movb 0x2(%rsp), %al
movb %al, %cl
shll $0x13, %ecx
movb 0x3(%rsp), %al
movb %al, %bpl
shll $0x7, %ebp
orl $0x41, %ebp
xorl %eax, %eax
cmpl $0x79b1, %r13d          # imm = 0x79B1
setne %al
shll $0x9, %eax
cmpl $0x1c4f, %r13d          # imm = 0x1C4F
leal 0x200(%rax,%rbp), %esi
movl $0x0, %eax
cmovel %eax, %esi
orl %ecx, %esi
movq %r14, %rdi
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0xb450
movl %eax, %edi
movl %eax, 0x1c(%rbx)
cmpl $-0x1, %eax
je 0x99b4f
cmpl $0x1, %r13d
jne 0x99b21
xorl %esi, %esi
movl $0x2, %edx
callq 0xb570
movl $0x79b1, 0x18(%rbx)     # imm = 0x79B1
jmp 0x99b45
cmpl $0x1c4f, %r13d          # imm = 0x1C4F
jne 0x99b45
xorl %r14d, %r14d
xorl %esi, %esi
movl $0x1, %edx
callq 0xb570
cmpq $-0x1, %rax
cmoveq %r14, %rax
movq %rax, 0x48(%rbx)
movq %rbx, %rdi
callq 0x99c64
jmp 0x99b61
movq %r15, %rdi
callq 0xb790
movq %rbx, %rdi
callq 0xb790
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq