// File: /workspace/github_c_makefile_star2_O2/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
andq $0x0, (%rdx)
movl 0x8(%rdi), %r15d
movl 0x10(%rdi), %eax
movq %rdx, 0x10(%rsp)
movq %rdi, 0x20(%rsp)
cmpl %r15d, %eax
jl 0xc2fa
movq %rbx, %rdi
callq 0x9d84
testl %eax, %eax
jne 0xc410
movl 0x8(%rbx), %r15d
testl %r15d, %r15d
je 0xc414
movl 0x10(%rbx), %eax
movq 0x28(%rbx), %r12
movslq %eax, %r13
leaq (%r12,%r13), %rdi
movl %r15d, %eax
subl %r13d, %eax
movslq %eax, %rdx
movl 0xc(%rsp), %esi
callq 0x4550
movl %eax, %ebp
subl %r12d, %ebp
testq %rax, %rax
cmovel %r15d, %ebp
movl %ebp, %ebx
subl %r13d, %ebx
leal 0x2(%rbx), %eax
movslq %eax, %rcx
movq 0x10(%rsp), %r14
movq (%r14), %rdi
addq %rdi, %rcx
jb 0xc401
movq 0x10(%r14), %rax
cmpq %rcx, 0x8(%r14)
movl %r15d, 0x1c(%rsp)
jae 0xc399
movq %rcx, %rdx
shrq $0x3e, %rdx
movq %rcx, %r13
shrq %r13
testq %rdx, %rdx
movl $0x0, %edx
cmovneq %rdx, %r13
addq %rcx, %r13
movq %rax, %rdi
movq %r13, %rsi
callq 0x4840
testq %rax, %rax
je 0xc40c
movq 0x10(%rsp), %r14
movq %rax, 0x10(%r14)
movq %r13, 0x8(%r14)
movq (%r14), %rdi
movq 0x20(%rsp), %r15
movslq 0x10(%r15), %r13
jmp 0xc39e
movq 0x20(%rsp), %r15
addq %rax, %rdi
addq %r13, %r12
movslq %ebx, %r13
movq %r12, %rsi
movq %r13, %rdx
callq 0x43c0
addq %r13, (%r14)
movl 0x8(%r15), %ecx
movl 0x10(%r15), %eax
addl %ebx, %eax
incl %eax
movl %eax, 0x10(%r15)
cmpl %ecx, %eax
movq %r15, %rbx
jl 0xc3e9
movq %rbx, %rdi
callq 0xa7e5
movq 0x10(%rsp), %r14
movq %rax, 0x18(%rbx)
andl $0x0, 0x10(%rbx)
andl $0x0, 0x8(%rbx)
xorl %ecx, %ecx
xorl %eax, %eax
cmpl 0x1c(%rsp), %ebp
movl %ecx, %r15d
jge 0xc2d5
movq (%r14), %rax
testq %rax, %rax
sete %cl
jmp 0xc424
callq 0x4050
movl $0x4b, (%rax)
pushq $-0x3
jmp 0xc46b
pushq $-0x2
jmp 0xc46b
movq 0x10(%rsp), %r14
movq (%r14), %rax
testq %rax, %rax
sete %cl
je 0xc469
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
jne 0xc451
cmpb $0xd, -0x1(%rcx,%rax)
jne 0xc451
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
jmp 0xc46c
pushq $-0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq