// File: /workspace/github_cpp_makefile_star2_O1/karel-brinda[P]ococo/ext/htslib/bgzf.c
// Function: bgzf_getline
int bgzf_getline(BGZF *fp, int delim, kstring_t *str)
{
    int l, state = 0;
    unsigned char *buf = (unsigned char*)fp->uncompressed_block;
    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; }
        }
        for (l = fp->block_offset; l < fp->block_length && buf[l] != delim; ++l);
        if (l < fp->block_length) state = 1;
        l -= fp->block_offset;
        if (str->l + l + 1 >= str->m) {
            str->m = str->l + l + 2;
            kroundup32(str->m);
            str->s = (char*)realloc(str->s, str->m);
        }
        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 = htell(fp->fp);
            fp->block_offset = 0;
            fp->block_length = 0;
        }
    } while (state == 0);
    if (str->l == 0 && state < 0) return state;
    fp->uncompressed_address += str->l;
    if ( delim=='\n' && str->l>0 && str->s[str->l-1]=='\r' ) str->l--;
    str->s[str->l] = 0;
    return str->l;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
movq 0x20(%rdi), %r12
movq $0x0, (%rdx)
leaq 0x1(%r12), %rax
movq %rax, (%rsp)
movl 0xc(%r14), %eax
cmpl 0x8(%r14), %eax
jl 0x45764
movq %r14, %rdi
callq 0x43e22
movb $0x1, %cl
testl %eax, %eax
jne 0x45883
cmpl $0x0, 0x8(%r14)
je 0x4588a
movl 0x8(%r14), %ecx
movl 0xc(%r14), %eax
cmpl %ecx, %eax
setl %r13b
jge 0x457be
movslq %eax, %rsi
movzbl (%r12,%rsi), %edi
movl %eax, %edx
cmpl %ebp, %edi
je 0x457d1
movslq %ecx, %rdi
movq (%rsp), %rdx
leaq (%rdx,%rsi), %r8
movl $0x1, %r9d
subl %ecx, %r9d
addq %rax, %r9
xorl %edx, %edx
movl %r9d, %r10d
addl %edx, %r10d
je 0x457c2
movzbl (%r8,%rdx), %r10d
incq %rdx
cmpl %ebp, %r10d
jne 0x4579b
addq %rdx, %rsi
cmpq %rdi, %rsi
setl %r13b
addl %eax, %edx
jmp 0x457d1
movl %eax, %edx
jmp 0x457d1
addq %rsi, %rdx
incq %rdx
cmpq %rdi, %rdx
setl %r13b
movl %ecx, %edx
subl %eax, %edx
movq (%rbx), %rax
movslq %edx, %r15
addq %r15, %rax
incq %rax
cmpq 0x8(%rbx), %rax
jb 0x4582a
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
callq 0x48d0
movq %rax, 0x10(%rbx)
movq 0x10(%rbx), %rdi
addq (%rbx), %rdi
movslq 0xc(%r14), %rsi
addq %r12, %rsi
movq %r15, %rdx
callq 0x4420
addq %r15, (%rbx)
movl 0xc(%r14), %eax
addl %r15d, %eax
incl %eax
movl %eax, 0xc(%r14)
cmpl 0x8(%r14), %eax
jl 0x45871
movq 0x38(%r14), %rax
movq 0x28(%rax), %rcx
addq 0x8(%rax), %rcx
subq (%rax), %rcx
movq %rcx, 0x10(%r14)
movq $0x0, 0x8(%r14)
testb %r13b, %r13b
je 0x4573d
movl $0x1, %eax
xorl %ecx, %ecx
jmp 0x4588f
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jmp 0x4588f
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq (%rbx), %rdx
testq %rdx, %rdx
sete %sil
testb %sil, %cl
jne 0x458d0
testq %rdx, %rdx
sete %al
addq %rdx, 0x18(%r14)
cmpl $0xa, %ebp
setne %cl
orb %al, %cl
jne 0x458c3
movq 0x10(%rbx), %rax
cmpb $0xd, -0x1(%rax,%rdx)
jne 0x458c3
decq %rdx
movq %rdx, (%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
movb $0x0, (%rcx,%rax)
movl (%rbx), %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq