// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/bgzf.c
// Function: bgzf_getline
int bgzf_getline(BGZF *fp, int delim, kstring_t *str)
{
    int l, state = 0;
    str->l = 0;
    do {
        if (fp->block_offset >= fp->block_length) {
            if (bgzf_read_block(fp) != 0) { state = -2; break; }
            if (fp->block_length == 0) { state = -1; break; }
        }
        unsigned char *buf = fp->uncompressed_block;

        // Equivalent to a naive byte by byte search from
        // buf + block_offset to buf + block_length.
        void *e = memchr(&buf[fp->block_offset], delim,
                         fp->block_length - fp->block_offset);
        l = e ? (unsigned char *)e - buf : fp->block_length;

        if (l < fp->block_length) state = 1;
        l -= fp->block_offset;
        if (ks_expand(str, l + 2) < 0) { state = -3; break; }
        memcpy(str->s + str->l, buf + fp->block_offset, l);
        str->l += l;
        fp->block_offset += l + 1;
        if (fp->block_offset >= fp->block_length) {
            fp->block_address = bgzf_htell(fp);
            fp->block_offset = 0;
            fp->block_length = 0;
        }
    } while (state == 0);
    if (state < -1) return state;
    if (str->l == 0 && state < 0) return state;
    fp->uncompressed_address += str->l + 1;
    if ( delim=='\n' && str->l>0 && str->s[str->l-1]=='\r' ) str->l--;
    str->s[str->l] = 0;
    return str->l <= INT_MAX ? (int) str->l : INT_MAX;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, 0xc(%rsp)
movq %rdi, %rbx
movq $0x0, (%rdx)
movl 0x8(%rdi), %r13d
movl 0x10(%rdi), %eax
movq %rdx, 0x10(%rsp)
movq %rdi, 0x20(%rsp)
cmpl %r13d, %eax
jl 0xdbc2
movq %rbx, %rdi
callq 0xae59
testl %eax, %eax
jne 0xdcd9
movl 0x8(%rbx), %r13d
testl %r13d, %r13d
je 0xdce0
movl 0x10(%rbx), %eax
movq 0x28(%rbx), %r15
movslq %eax, %r12
leaq (%r15,%r12), %rdi
movl %r13d, %eax
subl %r12d, %eax
movslq %eax, %rdx
movl 0xc(%rsp), %esi
callq 0x4550
movl %eax, %ebp
subl %r15d, %ebp
testq %rax, %rax
cmovel %r13d, %ebp
movl %ebp, %ebx
subl %r12d, %ebx
leal 0x2(%rbx), %eax
movslq %eax, %rcx
movq 0x10(%rsp), %r14
movq (%r14), %rdi
addq %rdi, %rcx
jb 0xdcc7
movq 0x10(%r14), %rax
cmpq %rcx, 0x8(%r14)
movl %r13d, 0x1c(%rsp)
jae 0xdc61
movq %rcx, %rdx
shrq $0x3e, %rdx
movq %rcx, %r12
shrq %r12
testq %rdx, %rdx
movl $0x0, %edx
cmovneq %rdx, %r12
addq %rcx, %r12
movq %rax, %rdi
movq %r12, %rsi
callq 0x4840
testq %rax, %rax
je 0xdcd2
movq 0x10(%rsp), %r14
movq %rax, 0x10(%r14)
movq %r12, 0x8(%r14)
movq (%r14), %rdi
movq 0x20(%rsp), %r13
movslq 0x10(%r13), %r12
jmp 0xdc66
movq 0x20(%rsp), %r13
addq %rax, %rdi
addq %r12, %r15
movslq %ebx, %r12
movq %r15, %rsi
movq %r12, %rdx
callq 0x43c0
addq %r12, (%r14)
movl 0x8(%r13), %ecx
movl 0x10(%r13), %eax
addl %ebx, %eax
incl %eax
movl %eax, 0x10(%r13)
cmpl %ecx, %eax
movq %r13, %rbx
jl 0xdcaf
movq %rbx, %rdi
callq 0xb7a5
movq 0x10(%rsp), %r14
movq %rax, 0x18(%rbx)
xorl %ecx, %ecx
movl %ecx, 0x10(%rbx)
movl %ecx, 0x8(%rbx)
xorl %eax, %eax
cmpl 0x1c(%rsp), %ebp
movl %ecx, %r13d
jge 0xdb9d
movq (%r14), %rax
testq %rax, %rax
sete %cl
jmp 0xdcef
callq 0x4050
movl $0x4b, (%rax)
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
jmp 0xdd36
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jmp 0xdd36
movq 0x10(%rsp), %r14
movq (%r14), %rax
testq %rax, %rax
je 0xdd45
xorl %ecx, %ecx
movq 0x20(%rbx), %rsi
addq %rax, %rsi
incq %rsi
movq %rsi, 0x20(%rbx)
cmpl $0xa, 0xc(%rsp)
setne %sil
orb %cl, %sil
movq 0x10(%r14), %rcx
testb $0x1, %sil
jne 0xdd20
cmpb $0xd, -0x1(%rcx,%rax)
jne 0xdd20
decq %rax
movq %rax, (%r14)
movb $0x0, (%rcx,%rax)
movq (%r14), %rcx
testq $-0x80000000, %rcx      # imm = 0x80000000
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmovel %ecx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xdd36