// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movl %esi, 0x44(%rsp)
movq %rdx, 0x38(%rsp)
movl $0x0, 0x20(%rsp)
movl $0x0, 0x1c(%rsp)
cmpq $0x0, 0x48(%rsp)
jne 0xcc7f8
movq $0x0, 0x50(%rsp)
jmp 0xccbd3
movl $0xf0, %edi
callq 0xbcb8
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0xcc81d
movq $0x0, 0x50(%rsp)
jmp 0xccbd3
movq 0x30(%rsp), %rax
movl $0x0, 0x28(%rax)
movq 0x30(%rsp), %rax
movl $0x2000, 0x2c(%rax)     # imm = 0x2000
movq 0x30(%rsp), %rax
movq $0x0, 0x78(%rax)
movq 0x30(%rsp), %rax
movl $0x0, 0x18(%rax)
movq 0x30(%rsp), %rax
movl $0xffffffff, 0x58(%rax) # imm = 0xFFFFFFFF
movq 0x30(%rsp), %rax
movl $0x0, 0x5c(%rax)
movq 0x30(%rsp), %rax
movl $0x0, 0x40(%rax)
movq 0x38(%rsp), %rax
cmpb $0x0, (%rax)
je 0xcc99d
movq 0x38(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
jl 0xcc8b2
movq 0x38(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x39, %eax
jg 0xcc8b2
movq 0x38(%rsp), %rax
movsbl (%rax), %ecx
subl $0x30, %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x58(%rax)
jmp 0xcc98a
movq 0x38(%rsp), %rax
movsbl (%rax), %eax
addl $-0x2b, %eax
movl %eax, %ecx
movq %rcx, 0x10(%rsp)
subl $0x4d, %eax
ja 0xcc986
movq 0x10(%rsp), %rax
leaq 0xa9807(%rip), %rcx     # 0x1760e0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x30(%rsp), %rax
movl $0x1c4f, 0x18(%rax)     # imm = 0x1C4F
jmp 0xcc988
movq 0x30(%rsp), %rax
movl $0x79b1, 0x18(%rax)     # imm = 0x79B1
jmp 0xcc988
movq 0x30(%rsp), %rax
movl $0x1, 0x18(%rax)
jmp 0xcc988
movq 0x30(%rsp), %rdi
callq 0xb760
movq $0x0, 0x50(%rsp)
jmp 0xccbd3
jmp 0xcc988
movl $0x1, 0x20(%rsp)
jmp 0xcc988
movl $0x1, 0x1c(%rsp)
jmp 0xcc988
movq 0x30(%rsp), %rax
movl $0x1, 0x5c(%rax)
jmp 0xcc988
movq 0x30(%rsp), %rax
movl $0x2, 0x5c(%rax)
jmp 0xcc988
movq 0x30(%rsp), %rax
movl $0x3, 0x5c(%rax)
jmp 0xcc988
movq 0x30(%rsp), %rax
movl $0x4, 0x5c(%rax)
jmp 0xcc988
movq 0x30(%rsp), %rax
movl $0x1, 0x40(%rax)
jmp 0xcc988
jmp 0xcc988
jmp 0xcc98a
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0xcc872
movq 0x30(%rsp), %rax
cmpl $0x0, 0x18(%rax)
jne 0xcc9c0
movq 0x30(%rsp), %rdi
callq 0xb760
movq $0x0, 0x50(%rsp)
jmp 0xccbd3
movq 0x30(%rsp), %rax
cmpl $0x1c4f, 0x18(%rax)     # imm = 0x1C4F
jne 0xcc9fd
movq 0x30(%rsp), %rax
cmpl $0x0, 0x40(%rax)
je 0xcc9f1
movq 0x30(%rsp), %rdi
callq 0xb760
movq $0x0, 0x50(%rsp)
jmp 0xccbd3
movq 0x30(%rsp), %rax
movl $0x1, 0x40(%rax)
movq 0x48(%rsp), %rdi
callq 0xb240
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
addq $0x1, %rdi
callq 0xbcb8
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x30(%rsp), %rax
cmpq $0x0, 0x20(%rax)
jne 0xcca4a
movq 0x30(%rsp), %rdi
callq 0xb760
movq $0x0, 0x50(%rsp)
jmp 0xccbd3
movq 0x30(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0x28(%rsp), %rsi
addq $0x1, %rsi
movq 0x48(%rsp), %rcx
leaq 0x9f445(%rip), %rdx     # 0x16bead
movb $0x0, %al
callq 0xb9d0
movl 0x20(%rsp), %edx
xorl %eax, %eax
movl $0x80000, %ecx          # imm = 0x80000
cmpl $0x0, %edx
cmovnel %ecx, %eax
orl $0x0, %eax
movl %eax, 0xc(%rsp)
movq 0x30(%rsp), %rax
cmpl $0x1c4f, 0x18(%rax)     # imm = 0x1C4F
jne 0xcca9d
xorl %eax, %eax
movl %eax, 0x8(%rsp)
jmp 0xccad2
movl 0x1c(%rsp), %edx
xorl %eax, %eax
movl $0x80, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
orl $0x41, %eax
movq 0x30(%rsp), %rcx
movl 0x18(%rcx), %esi
movl $0x400, %ecx            # imm = 0x400
movl $0x200, %edx            # imm = 0x200
cmpl $0x79b1, %esi           # imm = 0x79B1
cmovel %edx, %ecx
orl %ecx, %eax
movl %eax, 0x8(%rsp)
movl 0xc(%rsp), %eax
movl 0x8(%rsp), %ecx
orl %ecx, %eax
movl %eax, 0x24(%rsp)
cmpl $-0x1, 0x44(%rsp)
jle 0xccaf1
movl 0x44(%rsp), %eax
movl %eax, 0x4(%rsp)
jmp 0xccb0a
movq 0x48(%rsp), %rdi
movl 0x24(%rsp), %esi
movl $0x1b6, %edx            # imm = 0x1B6
movb $0x0, %al
callq 0xb430
movl %eax, 0x4(%rsp)
movl 0x4(%rsp), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x1c(%rax)
movq 0x30(%rsp), %rax
cmpl $-0x1, 0x1c(%rax)
jne 0xccb47
movq 0x30(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0xb760
movq 0x30(%rsp), %rdi
callq 0xb760
movq $0x0, 0x50(%rsp)
jmp 0xccbd3
movq 0x30(%rsp), %rax
cmpl $0x1, 0x18(%rax)
jne 0xccb74
movq 0x30(%rsp), %rax
movl 0x1c(%rax), %edi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0xb550
movq 0x30(%rsp), %rax
movl $0x79b1, 0x18(%rax)     # imm = 0x79B1
movq 0x30(%rsp), %rax
cmpl $0x1c4f, 0x18(%rax)     # imm = 0x1C4F
jne 0xccbbf
movq 0x30(%rsp), %rax
movl 0x1c(%rax), %edi
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0xb550
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x48(%rax)
movq 0x30(%rsp), %rax
cmpq $-0x1, 0x48(%rax)
jne 0xccbbd
movq 0x30(%rsp), %rax
movq $0x0, 0x48(%rax)
jmp 0xccbbf
movq 0x30(%rsp), %rdi
callq 0xccdd0
movq 0x30(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
addq $0x58, %rsp
retq
nopl (%rax)