// File: karel-brinda[P]ococo/ext/htslib/cram/sam_header.c
// Function: sam_hdr_dump
void sam_hdr_dump(SAM_hdr *hdr) {
    khint_t k;
    int i;

    printf("===DUMP===\n");
    for (k = kh_begin(hdr->h); k != kh_end(hdr->h); k++) {
	SAM_hdr_type *t1, *t2;
	char c[2];

	if (!kh_exist(hdr->h, k))
	    continue;

	t1 = t2 = kh_val(hdr->h, k);
	c[0] = kh_key(hdr->h, k)>>8;
	c[1] = kh_key(hdr->h, k)&0xff;
	printf("Type %.2s, count %d\n", c, t1->prev->order+1);

	do {
	    SAM_hdr_tag *tag;
	    printf(">>>%d ", t1->order);
	    for (tag = t1->tag; tag; tag=tag->next) {
		printf("\"%.2s\":\"%.*s\"\t",
		       tag->str, tag->len-3, tag->str+3);
	    }
	    putchar('\n');
	    t1 = t1->next;
	} while (t1 != t2);
    }

    /* Dump out PG chains */
    printf("\n@PG chains:\n");
    for (i = 0; i < hdr->npg_end; i++) {
	int j;
	printf("  %d:", i);
	for (j = hdr->pg_end[i]; j != -1; j = hdr->pg[j].prev_id) {
	    printf("%s%d(%.*s)", 
		   j == hdr->pg_end[i] ? " " : "->",
		   j, hdr->pg[j].name_len, hdr->pg[j].name);
	}
	printf("\n");
    }

    puts("===END DUMP===");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
leaq 0x22a0d(%rip), %rdi     # 0x7da20
movb $0x0, %al
callq 0x4080
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpl (%rcx), %eax
je 0x5b15f
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
movl -0xc(%rbp), %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl -0xc(%rbp), %ecx
andl $0xf, %ecx
shll %ecx
shrl %cl, %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x5b062
jmp 0x5b151
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movl -0xc(%rbp), %ecx
movl (%rax,%rcx,4), %eax
shrl $0x8, %eax
movb %al, -0x22(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movl -0xc(%rbp), %ecx
movl (%rax,%rcx,4), %eax
andl $0xff, %eax
movb %al, -0x21(%rbp)
leaq -0x22(%rbp), %rsi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x18(%rax), %edx
addl $0x1, %edx
leaq 0x22964(%rip), %rdi     # 0x7da2c
movb $0x0, %al
callq 0x4080
movq -0x18(%rbp), %rax
movl 0x18(%rax), %esi
leaq 0x22964(%rip), %rdi     # 0x7da41
movb $0x0, %al
callq 0x4080
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x5b130
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %edx
subl $0x3, %edx
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x3, %rcx
leaq 0x2292c(%rip), %rdi     # 0x7da48
movb $0x0, %al
callq 0x4080
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x5b0f0
movl $0xa, %edi
callq 0x4800
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
jne 0x5b0cf
jmp 0x5b151
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x5b021
leaq 0x228f1(%rip), %rdi     # 0x7da57
movb $0x0, %al
callq 0x4080
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x6c(%rcx), %eax
jge 0x5b254
movl -0x10(%rbp), %esi
leaq 0x228d7(%rip), %rdi     # 0x7da65
movb $0x0, %al
callq 0x4080
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
cmpl $-0x1, -0x34(%rbp)
je 0x5b238
movl -0x34(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x10(%rbp), %rdx
movl (%rax,%rdx,4), %edx
leaq 0x228a6(%rip), %rsi     # 0x7da76
leaq 0x1eaea(%rip), %rax     # 0x79cc1
cmpl %edx, %ecx
cmoveq %rax, %rsi
movl -0x34(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0x34(%rbp), %rdi
imulq $0x28, %rdi, %rdi
addq %rdi, %rax
movq (%rax), %r8
leaq 0x22858(%rip), %rdi     # 0x7da6b
movb $0x0, %al
callq 0x4080
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
movl %eax, -0x34(%rbp)
jmp 0x5b1aa
leaq 0x23c10(%rip), %rdi     # 0x7ee4f
movb $0x0, %al
callq 0x4080
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x5b174
leaq 0x2281e(%rip), %rdi     # 0x7da79
callq 0x48f0
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)