// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/htslib/cram/sam_header.c
// Function: sam_hdr_rebuild
int sam_hdr_rebuild(SAM_hdr *hdr) {
    /* Order: HD then others */
    kstring_t ks = KS_INITIALIZER;
    khint_t k;


    k = kh_get(sam_hdr, hdr->h, K("HD"));
    if (k != kh_end(hdr->h)) {
	SAM_hdr_type *ty = kh_val(hdr->h, k);
	SAM_hdr_tag *tag;
	if (EOF == kputs("@HD", &ks))
	    return -1;
	for (tag = ty->tag; tag; tag = tag->next) {
	    if (EOF == kputc_('\t', &ks))
		return -1;
	    if (EOF == kputsn_(tag->str, tag->len, &ks))
		return -1;
	}
	if (EOF == kputc('\n', &ks))
	    return -1;
    }

    for (k = kh_begin(hdr->h); k != kh_end(hdr->h); k++) {
	SAM_hdr_type *t1, *t2;

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

	if (kh_key(hdr->h, k) == K("HD"))
	    continue;

	t1 = t2 = kh_val(hdr->h, k);
	do {
	    SAM_hdr_tag *tag;
	    char c[2];

	    if (EOF == kputc_('@', &ks))
		return -1;
	    c[0] = kh_key(hdr->h, k)>>8;
	    c[1] = kh_key(hdr->h, k)&0xff;
	    if (EOF == kputsn_(c, 2, &ks))
		return -1;
	    for (tag = t1->tag; tag; tag=tag->next) {
		if (EOF == kputc_('\t', &ks))
		    return -1;
		if (EOF == kputsn_(tag->str, tag->len, &ks))
		    return -1;
	    }
	    if (EOF == kputc('\n', &ks))
		return -1;
	    t1 = t1->next;
	} while (t1 != t2);
    }

    if (ks_str(&hdr->text))
	KS_FREE(&hdr->text);

    hdr->text = ks;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x63a0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movsbl 0x4dbe8(%rip), %esi     # 0xe3903
shll $0x8, %esi
movsbl 0x4dbdf(%rip), %eax     # 0xe3904
orl %eax, %esi
callq 0x95710
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpl (%rcx), %eax
je 0x95e1d
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl -0x2c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
leaq 0x4dba2(%rip), %rdi     # 0xe3902
leaq -0x28(%rbp), %rsi
callq 0x95090
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x95d80
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9603e
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x95df6
movl $0x9, %edi
leaq -0x28(%rbp), %rsi
callq 0x94f50
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x95db8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9603e
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x40(%rbp), %rax
movl 0x10(%rax), %esi
leaq -0x28(%rbp), %rdx
callq 0x96050
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x95de7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9603e
jmp 0x95de9
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x95d8c
movl $0xa, %edi
leaq -0x28(%rbp), %rsi
callq 0x950d0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x95e1b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9603e
jmp 0x95e1d
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpl (%rcx), %eax
je 0x95fef
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl -0x2c(%rbp), %ecx
andl $0xf, %ecx
shll %ecx
shrl %cl, %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x95e65
jmp 0x95fe1
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movl -0x2c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movsbl 0x4da85(%rip), %ecx     # 0xe3903
shll $0x8, %ecx
movsbl 0x4da7c(%rip), %edx     # 0xe3904
orl %edx, %ecx
cmpl %ecx, %eax
jne 0x95e93
jmp 0x95fe1
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl -0x2c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
movq %rax, -0x48(%rbp)
movl $0x40, %edi
leaq -0x28(%rbp), %rsi
callq 0x94f50
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x95ed3
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9603e
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movl -0x2c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
shrl $0x8, %eax
movb %al, -0x5a(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movl -0x2c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
andl $0xff, %eax
movb %al, -0x59(%rbp)
leaq -0x5a(%rbp), %rdi
movl $0x2, %esi
leaq -0x28(%rbp), %rdx
callq 0x96050
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x95f2e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9603e
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x95fa4
movl $0x9, %edi
leaq -0x28(%rbp), %rsi
callq 0x94f50
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x95f66
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9603e
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x58(%rbp), %rax
movl 0x10(%rax), %esi
leaq -0x28(%rbp), %rdx
callq 0x96050
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x95f95
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9603e
jmp 0x95f97
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x95f3a
movl $0xa, %edi
leaq -0x28(%rbp), %rsi
callq 0x950d0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x95fc6
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9603e
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jne 0x95eae
jmp 0x95fe1
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x95e24
movq -0x10(%rbp), %rdi
callq 0x938c0
cmpq $0x0, %rax
je 0x9601c
jmp 0x96000
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x96018
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x6880
jmp 0x9601a
jmp 0x9601c
movq -0x10(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)