// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/zlib-1.3.0.1/gzlib.c
// Function: gzseek64
z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
    unsigned n;
    z_off64_t ret;
    gz_statep state;

    /* get internal structure and check integrity */
    if (file == NULL)
        return -1;
    state = (gz_statep)file;
    if (state->mode != GZ_READ && state->mode != GZ_WRITE)
        return -1;

    /* check that there's no error */
    if (state->err != Z_OK && state->err != Z_BUF_ERROR)
        return -1;

    /* can only seek from start or relative to current position */
    if (whence != SEEK_SET && whence != SEEK_CUR)
        return -1;

    /* normalize offset to a SEEK_CUR specification */
    if (whence == SEEK_SET)
        offset -= state->x.pos;
    else if (state->seek)
        offset += state->skip;
    state->seek = 0;

    /* if within raw area while reading, just go there */
    if (state->mode == GZ_READ && state->how == COPY &&
            state->x.pos + offset >= 0) {
        ret = LSEEK(state->fd, offset - (z_off64_t)state->x.have, SEEK_CUR);
        if (ret == -1)
            return -1;
        state->x.have = 0;
        state->eof = 0;
        state->past = 0;
        state->seek = 0;
        gz_error(state, Z_OK, NULL);
        state->strm.avail_in = 0;
        state->x.pos += offset;
        return state->x.pos;
    }

    /* calculate skip amount, rewinding if needed for back seek when reading */
    if (offset < 0) {
        if (state->mode != GZ_READ)         /* writing -- can't go backwards */
            return -1;
        offset += state->x.pos;
        if (offset < 0)                     /* before start of file! */
            return -1;
        if (gzrewind(file) == -1)           /* rewind, then skip to offset */
            return -1;
    }

    /* if reading, skip what's in output buffer (one less gzgetc() check) */
    if (state->mode == GZ_READ) {
        n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
            (unsigned)offset : state->x.have;
        state->x.have -= n;
        state->x.next += n;
        state->x.pos += n;
        offset -= n;
    }

    /* request skip (if not zero) */
    if (offset) {
        state->seek = 1;
        state->skip = offset;
    }
    return state->x.pos + offset;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq $-0x1, %r15
testq %rdi, %rdi
je 0x99dea
movq %rsi, %rbx
movq %rdi, %r14
movl 0x18(%rdi), %eax
cmpl $0x79b1, %eax           # imm = 0x79B1
je 0x99cf9
cmpl $0x1c4f, %eax           # imm = 0x1C4F
jne 0x99dea
movl 0x74(%r14), %ecx
testl %ecx, %ecx
je 0x99d0a
cmpl $-0x5, %ecx
jne 0x99dea
cmpl $0x1, %edx
ja 0x99dea
testl %edx, %edx
je 0x99d24
cmpl $0x0, 0x70(%r14)
je 0x99d28
addq 0x68(%r14), %rbx
jmp 0x99d28
subq 0x10(%r14), %rbx
movl $0x0, 0x70(%r14)
cmpl $0x1c4f, %eax           # imm = 0x1C4F
jne 0x99dab
cmpl $0x1, 0x44(%r14)
jne 0x99db2
movq 0x10(%r14), %rax
addq %rbx, %rax
js 0x99db2
movl (%r14), %eax
movl 0x1c(%r14), %edi
movq %rbx, %rsi
subq %rax, %rsi
movl $0x1, %edx
callq 0xb570
cmpq $-0x1, %rax
je 0x99dea
xorl %ebp, %ebp
movl %ebp, (%r14)
movq $0x0, 0x50(%r14)
movl %ebp, 0x70(%r14)
movq 0x78(%r14), %rdi
testq %rdi, %rdi
je 0x99d96
cmpl $-0x4, 0x74(%r14)
je 0x99d8e
callq 0xb790
movq $0x0, 0x78(%r14)
movl %ebp, 0x74(%r14)
movl %ebp, 0x88(%r14)
addq 0x10(%r14), %rbx
movq %rbx, 0x10(%r14)
jmp 0x99de7
testq %rbx, %rbx
jns 0x99dd2
jmp 0x99dea
testq %rbx, %rbx
js 0x99df8
movl (%r14), %eax
cmpq %rax, %rbx
movl %ebx, %ecx
cmovael %eax, %ecx
subl %ecx, %eax
movl %eax, (%r14)
addq %rcx, 0x8(%r14)
addq %rcx, 0x10(%r14)
subq %rcx, %rbx
testq %rbx, %rbx
je 0x99de3
movl $0x1, 0x70(%r14)
movq %rbx, 0x68(%r14)
addq 0x10(%r14), %rbx
movq %rbx, %r15
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
addq 0x10(%r14), %rbx
js 0x99dea
movq %r14, %rdi
callq 0x99c14
cmpl $-0x1, %eax
je 0x99dea
cmpl $0x1c4f, 0x18(%r14)     # imm = 0x1C4F
je 0x99db7
jmp 0x99dd2