// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
pushq $-0x1
popq %r15
testq %rdi, %rdi
je 0x7a50a
movq %rsi, %rbx
movq %rdi, %r14
movl 0x18(%rdi), %eax
cmpl $0x79b1, %eax           # imm = 0x79B1
je 0x7a439
cmpl $0x1c4f, %eax           # imm = 0x1C4F
jne 0x7a50a
movl 0x74(%r14), %ecx
testl %ecx, %ecx
je 0x7a44a
cmpl $-0x5, %ecx
jne 0x7a50a
cmpl $0x1, %edx
ja 0x7a50a
testl %edx, %edx
je 0x7a464
cmpl $0x0, 0x70(%r14)
je 0x7a468
addq 0x68(%r14), %rbx
jmp 0x7a468
subq 0x10(%r14), %rbx
andl $0x0, 0x70(%r14)
cmpl $0x1c4f, %eax           # imm = 0x1C4F
jne 0x7a4cb
cmpl $0x1, 0x44(%r14)
jne 0x7a4d2
movq 0x10(%r14), %rax
addq %rbx, %rax
js 0x7a4d2
movl (%r14), %eax
movl 0x1c(%r14), %edi
movq %rbx, %rsi
subq %rax, %rsi
pushq $0x1
popq %rdx
callq 0xb570
cmpq $-0x1, %rax
je 0x7a50a
andl $0x0, (%r14)
andq $0x0, 0x50(%r14)
andl $0x0, 0x70(%r14)
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x7a532
andl $0x0, 0x88(%r14)
addq 0x10(%r14), %rbx
movq %rbx, 0x10(%r14)
jmp 0x7a507
testq %rbx, %rbx
jns 0x7a4f2
jmp 0x7a50a
testq %rbx, %rbx
js 0x7a513
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 0x7a503
movl $0x1, 0x70(%r14)
movq %rbx, 0x68(%r14)
addq 0x10(%r14), %rbx
movq %rbx, %r15
movq %r15, %rax
popq %rbx
popq %r14
popq %r15
retq
addq 0x10(%r14), %rbx
js 0x7a50a
movq %r14, %rdi
callq 0x7a381
cmpl $-0x1, %eax
je 0x7a50a
cmpl $0x1c4f, 0x18(%r14)     # imm = 0x1C4F
je 0x7a4d7
jmp 0x7a4f2