// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
addq 0x20(%rcx), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x3f8b
jmp 0x4199
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x3e40
movq %rax, -0x48(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpq -0x20(%rbp), %rax
jae 0x40f1
movq -0x48(%rbp), %rax
movl -0x24(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
callq 0x3de0
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x400f
movl -0x3c(%rbp), %eax
cmpl -0x28(%rbp), %eax
jne 0x400f
jmp 0x40e3
cmpl $0x0, -0x28(%rbp)
je 0x4063
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jne 0x4025
movl -0x2c(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x4061
cmpl $0x0, -0x34(%rbp)
je 0x405f
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movl -0x2c(%rbp), %ecx
movl -0x30(%rbp), %r8d
movl -0x34(%rbp), %r9d
leaq 0x23428(%rip), %rsi     # 0x27480
movb $0x0, %al
callq 0x3360
jmp 0x4061
jmp 0x4063
movl -0x28(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x48(%rbp), %rax
movl -0x24(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
callq 0x6910
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x40a8
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movl (%rax), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x48(%rbp), %rax
movl -0x24(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
callq 0x6910
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x40dd
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movl (%rax), %ecx
movl -0x38(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x3fdc
cmpl $0x0, -0x34(%rbp)
je 0x412b
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movl -0x2c(%rbp), %ecx
movl -0x30(%rbp), %r8d
movl -0x34(%rbp), %r9d
leaq 0x2335c(%rip), %rsi     # 0x27480
movb $0x0, %al
callq 0x3360
movq 0x2be8e(%rip), %rax     # 0x2ffc0
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0xc(%rbp), %rsi
movl (%rax,%rsi,4), %r8d
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0xc(%rbp), %rsi
movq (%rax,%rsi,8), %r9
leaq 0x23304(%rip), %rsi     # 0x2748d
movb $0x0, %al
callq 0x3360
movq -0x48(%rbp), %rdi
callq 0x3050
addq $0x50, %rsp
popq %rbp
retq
nop