// File: /workspace/github_c_makefile_star2_O1/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
pushq %rax
movq %rdx, %r12
movl %esi, 0x4(%rsp)
movq %rdi, %r14
movq $0x0, (%rdx)
movl 0x10(%r14), %eax
cmpl 0x8(%r14), %eax
jl 0xdc6e
movq %r14, %rdi
callq 0xae60
testl %eax, %eax
jne 0xdd8a
cmpl $0x0, 0x8(%r14)
je 0xdd91
movq 0x28(%r14), %r15
movslq 0x10(%r14), %rbx
movq %rbx, %rdi
addq %r15, %rdi
movq %r12, %r13
movl 0x8(%r14), %r12d
movl %r12d, %eax
subl %ebx, %eax
movslq %eax, %rdx
movl 0x4(%rsp), %esi
callq 0x4550
movl %eax, %ebp
subl %r15d, %ebp
testq %rax, %rax
cmovel %r12d, %ebp
xorl %ecx, %ecx
cmpl %r12d, %ebp
movq %r13, %r12
setl 0x3(%rsp)
subl %ebx, %ebp
leal 0x2(%rbp), %eax
cltq
addq (%r13), %rax
jae 0xdccb
callq 0x4050
xorl %ecx, %ecx
movl $0x4b, (%rax)
movb $0x1, %bl
jmp 0xdd17
cmpq %rax, 0x8(%r12)
jae 0xdce3
movq %rax, %rcx
shrq $0x3e, %rcx
jne 0xdce7
movq %rax, %r12
shrq %r12
jmp 0xdcea
xorl %ebx, %ebx
jmp 0xdd17
xorl %r12d, %r12d
addq %rax, %r12
movq %r13, %rbx
movq 0x10(%r13), %rdi
movq %r12, %rsi
callq 0x4840
testq %rax, %rax
je 0xdd10
movq %rax, 0x10(%rbx)
movq %r12, 0x8(%rbx)
movq %rbx, %r12
xorl %ebx, %ebx
jmp 0xdd15
movq %rbx, %r12
movb $0x1, %bl
xorl %ecx, %ecx
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
testb %bl, %bl
jne 0xdd79
movq 0x10(%r12), %rdi
addq (%r12), %rdi
movb 0x3(%rsp), %al
movb %al, %cl
movslq 0x10(%r14), %rax
addq %rax, %r15
movslq %ebp, %r12
movq %r15, %rsi
movq %r12, %rdx
movl %ecx, %r15d
callq 0x43c0
addq %r12, (%r13)
movq %r13, %r12
movl 0x10(%r14), %eax
addl %ebp, %eax
incl %eax
movl %eax, 0x10(%r14)
cmpl 0x8(%r14), %eax
jl 0xdd76
movq %r14, %rdi
callq 0xb812
movq %rax, 0x18(%r14)
xorl %eax, %eax
movl %eax, 0x10(%r14)
movl %eax, 0x8(%r14)
movl %r15d, %eax
testl %eax, %eax
sete %cl
notb %bl
testb %cl, %bl
jne 0xdc49
jmp 0xdd96
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jmp 0xdd96
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
jl 0xde09
movq (%r12), %rcx
testq %rcx, %rcx
sete %dl
cmpl $-0x1, %eax
sete %sil
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb %dl, %sil
jne 0xde09
testq %rcx, %rcx
sete %al
movq 0x20(%r14), %rdx
addq %rcx, %rdx
incq %rdx
movq %rdx, 0x20(%r14)
cmpl $0xa, 0x4(%rsp)
setne %dl
orb %al, %dl
jne 0xdde9
movq 0x10(%r12), %rax
cmpb $0xd, -0x1(%rax,%rcx)
jne 0xdde9
decq %rcx
movq %rcx, (%r12)
movq (%r12), %rax
movq 0x10(%r12), %rcx
movb $0x0, (%rcx,%rax)
movq (%r12), %rcx
testq $-0x80000000, %rcx      # imm = 0x80000000
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmovel %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq