// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x18, %rsp
movq %rdx, %r12
movl %esi, %ebp
movq %rdi, %r14
movq 0x20(%rdi), %r13
andq $0x0, (%rdx)
movl 0x8(%rdi), %edi
movl 0xc(%r14), %ecx
movq %r14, 0x10(%rsp)
movl %esi, 0xc(%rsp)
cmpl %edi, %ecx
jl 0x37cfd
movq %r14, %rdi
callq 0x365f6
testl %eax, %eax
jne 0x37dfd
movl 0x8(%r14), %edi
testl %edi, %edi
je 0x37e01
movl 0xc(%r14), %ecx
movslq %ecx, %rsi
movslq %edi, %r15
cmpl %r15d, %esi
movl %r15d, %r8d
cmovgl %esi, %r8d
movq %rsi, %rbx
cmpq %r15, %rbx
jge 0x37d27
movzbl (%r13,%rbx), %eax
cmpl %ebp, %eax
je 0x37d24
incq %rbx
jmp 0x37d10
movl %ebx, %r8d
subl %ecx, %r8d
movq (%r12), %rdi
movq 0x10(%r12), %rax
movslq %r8d, %rbp
leaq (%rdi,%rbp), %rcx
incq %rcx
cmpq 0x8(%r12), %rcx
jae 0x37d4b
movq 0x10(%rsp), %r14
jmp 0x37d9e
movq %rcx, %rsi
shrq %rsi
orq %rcx, %rsi
movq %rsi, %rcx
shrq $0x2, %rcx
orq %rsi, %rcx
movq %rcx, %rsi
shrq $0x4, %rsi
orq %rcx, %rsi
movq %rsi, %rcx
shrq $0x8, %rcx
orq %rsi, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x8(%r12)
movq %rax, %rdi
callq 0x48c0
movq %rax, 0x10(%r12)
movq (%r12), %rdi
movq 0x10(%rsp), %r14
movslq 0xc(%r14), %rsi
addq %rax, %rdi
addq %r13, %rsi
movq %rbp, %rdx
callq 0x4420
movq (%r12), %r8
addq %rbp, %r8
movq %r8, (%r12)
movl 0x8(%r14), %edi
movl 0xc(%r14), %ecx
addl %ebp, %ecx
incl %ecx
movl %ecx, 0xc(%r14)
cmpl %edi, %ecx
jl 0x37de7
movq 0x38(%r14), %rcx
movq 0x28(%rcx), %rsi
addq 0x8(%rcx), %rsi
subq (%rcx), %rsi
movq %rsi, 0x10(%r14)
andq $0x0, 0x8(%r14)
xorl %edi, %edi
xorl %ecx, %ecx
cmpq %r15, %rbx
movl 0xc(%rsp), %ebp
jge 0x37cd9
testq %r8, %r8
sete %sil
jmp 0x37e0f
pushq $-0x2
jmp 0x37e03
pushq $-0x1
popq %rax
movq (%r12), %r8
testq %r8, %r8
je 0x37e3a
xorl %esi, %esi
addq %r8, 0x18(%r14)
movq 0x10(%r12), %rcx
cmpl $0xa, %ebp
jne 0x37e31
testb %sil, %sil
jne 0x37e31
cmpb $0xd, -0x1(%rcx,%r8)
jne 0x37e31
decq %r8
movq %r8, (%r12)
movb $0x0, (%rcx,%r8)
movl (%r12), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq