// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/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 = _bgzf_tell((_bgzf_file_t)fp->fp);
			fp->block_offset = 0;
			fp->block_length = 0;
		} 
	} while (state == 0);
	if (str->l == 0 && state < 0) return state;
	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 0x18(%rdi), %r12
movq $0x0, (%rdx)
movl 0x8(%rdi), %eax
movl 0xc(%rdi), %ecx
leaq 0x1(%r12), %rdx
movq %rdx, (%rsp)
cmpl %eax, %ecx
jl 0x18b50
movq %r14, %rdi
callq 0x17964
testl %eax, %eax
jne 0x18c6f
movl 0x8(%r14), %eax
testl %eax, %eax
je 0x18c76
movl 0xc(%r14), %ecx
cmpl %eax, %ecx
jge 0x18ba3
movslq %ecx, %rsi
movzbl (%r12,%rsi), %edi
movb $0x1, %r13b
movl %ecx, %edx
cmpl %ebp, %edi
je 0x18bb9
movslq %eax, %rdi
movq (%rsp), %rdx
leaq (%rdx,%rsi), %r8
movl %ecx, %edx
movl $0x1, %r9d
subl %eax, %r9d
addq %rdx, %r9
xorl %edx, %edx
movl %r9d, %r10d
addl %edx, %r10d
je 0x18baa
movzbl (%r8,%rdx), %r10d
incq %rdx
cmpl %ebp, %r10d
jne 0x18b80
addq %rdx, %rsi
cmpq %rdi, %rsi
setl %r13b
addl %ecx, %edx
jmp 0x18bb9
xorl %r13d, %r13d
movl %ecx, %edx
jmp 0x18bb9
addq %rsi, %rdx
incq %rdx
cmpq %rdi, %rdx
setl %r13b
movl %eax, %edx
subl %ecx, %edx
movq (%rbx), %rdi
movq 0x10(%rbx), %rax
movslq %edx, %r15
leaq (%r15,%rdi), %rdx
incq %rdx
cmpq 0x8(%rbx), %rdx
jb 0x18c1d
movq %rdx, %rcx
shrq %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x2, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x8, %rdx
orq %rcx, %rdx
movq %rdx, %rsi
shrq $0x10, %rsi
orq %rdx, %rsi
incq %rsi
movq %rsi, 0x8(%rbx)
movq %rax, %rdi
callq 0x3430
movq %rax, 0x10(%rbx)
movq (%rbx), %rdi
movl 0xc(%r14), %ecx
addq %rax, %rdi
movslq %ecx, %rsi
addq %r12, %rsi
movq %r15, %rdx
callq 0x3370
movq (%rbx), %rdx
addq %r15, %rdx
movq %rdx, (%rbx)
movl 0x8(%r14), %eax
movl 0xc(%r14), %ecx
addl %r15d, %ecx
incl %ecx
movl %ecx, 0xc(%r14)
cmpl %eax, %ecx
jl 0x18c64
movq 0x30(%r14), %rax
movq 0x8(%rax), %rax
movq %rax, 0x10(%r14)
movq $0x0, 0x8(%r14)
xorl %eax, %eax
xorl %ecx, %ecx
testb %r13b, %r13b
je 0x18b2c
jmp 0x18c83
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jmp 0x18c7b
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq (%rbx), %rdx
testq %rdx, %rdx
je 0x18c8d
movq 0x10(%rbx), %rax
movb $0x0, (%rax,%rdx)
movl (%rbx), %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq