// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq %rdx, 0x28(%rsp)
movl %esi, %ebp
movq %rdi, %rax
movq 0x8(%rdi), %rdi
movq 0x10(%rax), %rsi
movq 0x20(%rsi), %rcx
addq 0x20(%rdi), %rcx
movq %rcx, 0x30(%rsp)
je 0x3dfa
movq %rax, 0x10(%rsp)
callq 0x3b6e
movq %rax, 0x18(%rsp)
movslq %ebp, %rax
movq %rax, 0x20(%rsp)
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %ebx, %ebx
movl $0x0, 0x8(%rsp)
movl $0x0, 0xc(%rsp)
xorl %r12d, %r12d
movl %r14d, %r14d
cmpq %r14, 0x30(%rsp)
jbe 0x3d66
movq 0x18(%rsp), %rax
movq (%rax,%r14,8), %r13
movq %r13, %rdi
callq 0x3b4d
movl %eax, %ebp
testl %eax, %eax
setne %al
cmpl %r15d, %ebp
sete %cl
testb %cl, %al
je 0x3cae
movl %r15d, %ebp
movl %ebx, %r15d
jmp 0x3d58
testl %r15d, %r15d
je 0x3cc2
movl 0xc(%rsp), %r9d
cmpl %r12d, %r9d
jne 0x3cc7
movl %ebx, %r15d
jmp 0x3d08
xorl %r15d, %r15d
jmp 0x3d08
testl %r9d, %r9d
je 0x3d08
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x28(%rsp), %rdi
leaq 0x1378f(%rip), %rsi     # 0x17480
movl %ebx, %ecx
movl 0x8(%rsp), %r8d
xorl %eax, %eax
callq 0x3370
movq 0x18(%rsp), %rax
movq (%rax,%r14,8), %r13
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
movq %r13, %rsi
callq 0x53ad
movl %r12d, %ebx
testq %rax, %rax
je 0x3d2a
movq 0x8(%rax), %rax
movl (%rax), %ebx
addl %r12d, %ebx
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x18(%rsp), %rax
movq (%rax,%r14,8), %rsi
callq 0x53ad
testq %rax, %rax
je 0x3d4c
movq 0x8(%rax), %rax
subl (%rax), %ebx
movl %ebp, 0x8(%rsp)
movl %r12d, 0xc(%rsp)
movl %ebx, %r12d
movl %r15d, %ebx
incl %r14d
movl %ebp, %r15d
jmp 0x3c73
movl 0xc(%rsp), %r9d
testl %r9d, %r9d
movq 0x10(%rsp), %r14
movq 0x20(%rsp), %r15
je 0x3da3
movq (%r14), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax,%r15,8), %rdx
leaq 0x136f0(%rip), %rsi     # 0x17480
movq 0x28(%rsp), %rdi
movl %ebx, %ecx
movl 0x8(%rsp), %r8d
xorl %eax, %eax
callq 0x3370
movq 0x1d216(%rip), %rax     # 0x20fc0
movq (%rax), %rdi
movq (%r14), %rax
movq 0x18(%r14), %rsi
movq 0x10(%rax), %rax
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rax
movq (%rcx,%r15,8), %rdx
movl (%rax,%r15,4), %ecx
movl (%rsi,%r15,4), %r8d
movq 0x20(%r14), %rax
movq (%rax,%r15,8), %r9
leaq 0x136b2(%rip), %rsi     # 0x1748d
xorl %eax, %eax
callq 0x3370
movq 0x18(%rsp), %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3060
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq