// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/bam2bedGraph.c
// Function: hash2BedGraph
void hash2BedGraph(DataBuf *databuf,int ref,FILE *stream){
	unsigned long all_keys_count = databuf->Start->used + databuf->End->used;
	if (!all_keys_count) return;
	uint32_t i=0,prevkey=0,last_start=0,last_end=0,last_depth=0,Count=0,pos=0;
	sds *all_keys=union_hashed_keys(databuf->Start,databuf->End);
	for (i = 0; i < all_keys_count; ++i) {
		pos=sds2int(all_keys[i]);
		if (pos && pos==prevkey) continue;
		if (prevkey) {
			if (last_depth==Count) {
				prevkey=last_start;
			}
			else{
				if (last_depth) fprintf(stream,"%s\t%u\t%u\t%u\n",databuf->fp->header->target_name[ref],last_start,last_end,last_depth);
			}
		}
		last_start=prevkey;
		last_end=pos;
		last_depth=Count;
		dictEntry *data=dictFind(databuf->Start,all_keys[i]);
		if (data!=NULL) Count+= *((int*)data->val);
		data=dictFind(databuf->End,all_keys[i]);
		if (data!=NULL) Count-= *((int*)data->val);
		prevkey=pos;
	}
	if (last_depth){
		fprintf(stream,"%s\t%u\t%u\t%u\n",databuf->fp->header->target_name[ref],last_start,last_end,last_depth);
	}
	fprintf(stdout,"%s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu64 "\n",databuf->fp->header->target_name[ref],databuf->fp->header->target_len[ref],databuf->chrRC[ref],databuf->chrReadLen[ref]);
	free(all_keys);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, 0x18(%rsp)
movl %esi, %ebp
movq %rdi, %rax
movq 0x8(%rdi), %rdi
movq %rax, (%rsp)
movq 0x10(%rax), %rsi
movq 0x20(%rsi), %rax
addq 0x20(%rdi), %rax
movq %rax, 0x20(%rsp)
je 0x501d
callq 0x4d8a
movq %rax, 0x8(%rsp)
movslq %ebp, %rax
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
xorl %ebx, %ebx
xorl %r9d, %r9d
xorl %r8d, %r8d
xorl %ecx, %ecx
xorl %r12d, %r12d
xorl %r15d, %r15d
movq (%rsp), %rbp
movq 0x8(%rsp), %rax
movq (%rax,%r14,8), %rsi
movb -0x8(%rsi), %al
decb %al
movl $0x0, %r13d
js 0x4ef3
movzbl %al, %eax
xorl %r13d, %r13d
movl %r13d, %edx
shll $0x8, %edx
movzbl (%rsi,%rax), %r13d
orl %edx, %r13d
addq $-0x1, %rax
jb 0x4ec7
testl %r13d, %r13d
setne %al
cmpl %r12d, %r13d
sete %dl
testb %dl, %al
je 0x4ef3
movl %r12d, %r13d
jmp 0x4f85
testl %r12d, %r12d
je 0x4f02
cmpl %ebx, %r9d
jne 0x4f07
movl %ecx, %r12d
jmp 0x4f3d
xorl %r12d, %r12d
jmp 0x4f3d
testl %r9d, %r9d
je 0x4f3d
movq (%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq 0x10(%rsp), %rdx
movq (%rax,%rdx,8), %rdx
movq 0x18(%rsp), %rdi
leaq 0x16553(%rip), %rsi     # 0x1b480
xorl %eax, %eax
callq 0x3370
movq 0x8(%rsp), %rax
movq (%rax,%r14,8), %rsi
movq 0x8(%rbp), %rdi
callq 0x6a2d
movl %ebx, %ebp
testq %rax, %rax
je 0x4f55
movq 0x8(%rax), %rax
movl (%rax), %ebp
addl %ebx, %ebp
movq (%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x8(%rsp), %rax
movq (%rax,%r14,8), %rsi
callq 0x6a2d
testq %rax, %rax
je 0x4f76
movq 0x8(%rax), %rax
subl (%rax), %ebp
movl %r12d, %ecx
movl %r13d, %r8d
movl %ebx, %r9d
movl %ebp, %ebx
movq (%rsp), %rbp
incl %r15d
movq %r15, %r14
movl %r13d, %r12d
cmpq %r15, 0x20(%rsp)
ja 0x4eab
testl %r9d, %r9d
movq 0x10(%rsp), %rbx
je 0x4fc6
movq (%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax,%rbx,8), %rdx
leaq 0x164c6(%rip), %rsi     # 0x1b480
movq 0x18(%rsp), %rdi
xorl %eax, %eax
callq 0x3370
movq 0x1eff3(%rip), %rax     # 0x23fc0
movq (%rax), %rdi
movq (%rbp), %rax
movq 0x18(%rbp), %rsi
movq 0x10(%rax), %rax
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rax
movq (%rcx,%rbx,8), %rdx
movl (%rax,%rbx,4), %ecx
movl (%rsi,%rbx,4), %r8d
movq 0x20(%rbp), %rax
movq (%rax,%rbx,8), %r9
leaq 0x1648f(%rip), %rsi     # 0x1b48d
xorl %eax, %eax
callq 0x3370
movq 0x8(%rsp), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3060
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq