// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r13
movq 0x18(%rdi), %rax
movl (%rax), %edx
testl %edx, %edx
je 0x634af
leal -0x1(%rdx), %edi
movl %edi, %r8d
andl $0x4844, %r8d           # imm = 0x4844
movq 0x10(%rax), %r9
movl $0x1, %r10d
movl %r8d, %esi
movl %esi, %ecx
shrl $0x4, %ecx
movl (%r9,%rcx,4), %r11d
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl %r11d, %ebx
shrl %cl, %ebx
testb $0x2, %bl
jne 0x634a3
testb $0x1, %bl
jne 0x63492
movq 0x18(%rax), %rbx
movl %esi, %r14d
cmpl $0x4844, (%rbx,%r14,4)  # imm = 0x4844
je 0x634a3
addl %r10d, %esi
andl %edi, %esi
incl %r10d
cmpl %r8d, %esi
jne 0x63463
movl %edx, %esi
jmp 0x634b1
shrl %cl, %r11d
testb $0x3, %r11b
cmovnel %edx, %esi
jmp 0x634b1
xorl %esi, %esi
xorl %r8d, %r8d
movl $0x0, %r12d
movl $0x0, %r15d
cmpl %edx, %esi
movq %r13, 0x10(%rsp)
jne 0x6386f
movq 0x18(%r13), %rax
cmpl $0x0, (%rax)
je 0x63848
xorl %esi, %esi
movq 0x10(%rax), %rcx
movl %esi, %edx
shrl $0x4, %edx
movl (%rcx,%rdx,4), %edx
leal (%rsi,%rsi), %ecx
shrl %cl, %edx
movl $0x7, %ecx
testb $0x3, %dl
movq %rsi, 0x28(%rsp)
jne 0x63828
movq 0x18(%rax), %rdx
movl %esi, %esi
cmpl $0x4844, (%rdx,%rsi,4)  # imm = 0x4844
je 0x63828
movq 0x20(%rax), %rax
movq (%rax,%rsi,8), %rax
movq %rax, 0x30(%rsp)
movq %rax, 0x18(%rsp)
movq %rsi, 0x8(%rsp)
leaq 0x1(%r15), %rbx
cmpq %r12, %rbx
jbe 0x63586
movq %r15, %rax
shrq %rax
orq %r15, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %r12
shrq $0x10, %r12
orq %rcx, %r12
incq %r12
movq %r8, %rdi
movq %r12, %rsi
movq %r8, %r14
callq 0x6c80
testq %rax, %rax
je 0x63743
movq %rax, %r8
movq 0x8(%rsp), %rsi
movb $0x40, (%r8,%r15)
xorl %eax, %eax
testb %al, %al
je 0x6359b
xorl %eax, %eax
movq %rbx, %r15
jmp 0x637ff
movq 0x18(%r13), %rax
movq 0x18(%rax), %rax
movl (%rax,%rsi,4), %ebp
leaq 0x2(%rbx), %r15
cmpq %r12, %r15
jbe 0x63606
leaq 0x1(%rbx), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %r12
shrq $0x10, %r12
orq %rax, %r12
incq %r12
movq %r8, %rdi
movq %r12, %rsi
movq %r8, %r14
callq 0x6c80
testq %rax, %rax
je 0x63755
movq %rax, %r8
movq 0x8(%rsp), %rsi
movl %ebp, %eax
shrl $0x8, %eax
movb %al, (%r8,%rbx)
movb %bpl, 0x1(%r8,%rbx)
xorl %eax, %eax
testb %al, %al
je 0x63621
xorl %eax, %eax
jmp 0x637ff
movq 0x18(%rsp), %rax
leaq 0x10(%rax), %r14
movq (%r14), %r14
leaq 0x1(%r15), %r13
testq %r14, %r14
je 0x63767
cmpq %r12, %r13
jbe 0x6368d
movq %r15, %rax
shrq %rax
orq %r15, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %r12
shrq $0x10, %r12
orq %rcx, %r12
incq %r12
movq %r8, %rdi
movq %r12, %rsi
movq %r8, %rbx
callq 0x6c80
testq %rax, %rax
je 0x6372d
movq %rax, %r8
movb $0x9, (%r8,%r15)
xorl %eax, %eax
testb %al, %al
jne 0x63773
movq 0x8(%r14), %rbx
movslq 0x10(%r14), %rbp
movq %r13, %rax
addq %rbp, %rax
cmpq %r12, %rax
movq %rax, 0x20(%rsp)
jbe 0x63701
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %r8, %rdi
movq %rsi, %r12
movq %r8, %r15
callq 0x6c80
testq %rax, %rax
je 0x6373a
movq %rax, %r8
movq %r8, %r15
addq %r8, %r13
movq %r13, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x6570
cmpl $-0x1, %ebp
sete %al
testb %al, %al
movq %r15, %r8
movq 0x20(%rsp), %r15
je 0x6362a
jmp 0x6377a
movb $0x1, %al
movq %r15, %r13
movq %rbx, %r8
jmp 0x63694
movb $0x1, %al
movq %r13, 0x20(%rsp)
jmp 0x6371b
movb $0x1, %al
movq %r15, %rbx
movq %r14, %r8
movq 0x8(%rsp), %rsi
jmp 0x6358d
movb $0x1, %al
movq %rbx, %r15
movq %r14, %r8
movq 0x8(%rsp), %rsi
jmp 0x63616
cmpq %r12, %r13
jae 0x63788
movq 0x8(%rsp), %rsi
jmp 0x637d7
xorl %eax, %eax
movq %r13, %r15
jmp 0x6377c
xorl %eax, %eax
movq 0x10(%rsp), %r13
movq 0x8(%rsp), %rsi
jmp 0x637ff
movq %r13, %rax
shrq %rax
orq %r13, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %r12
shrq $0x10, %r12
orq %rcx, %r12
incq %r12
movq %r8, %rdi
movq %r12, %rsi
movq %r8, %rbx
callq 0x6c80
testq %rax, %rax
movq 0x8(%rsp), %rsi
je 0x63815
movq %rax, %r8
movw $0xa, (%r8,%r15)
xorl %eax, %eax
testb %al, %al
je 0x637e8
xorl %eax, %eax
jmp 0x637f7
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x18(%rsp)
movb $0x1, %al
movq %r13, %r15
movq 0x10(%rsp), %r13
testb %al, %al
je 0x6381f
movq 0x18(%rsp), %rax
cmpq 0x30(%rsp), %rax
jne 0x6352a
jmp 0x63826
movb $0x1, %al
movq %r15, %r13
movq %rbx, %r8
jmp 0x637e0
movl $0x1, %ecx
jmp 0x63828
xorl %ecx, %ecx
cmpl $0x7, %ecx
je 0x63835
testl %ecx, %ecx
jne 0x639ca
movq 0x28(%rsp), %rsi
incl %esi
movq 0x18(%r13), %rax
cmpl (%rax), %esi
jne 0x634dc
movq 0x10(%r13), %rdi
testq %rdi, %rdi
je 0x6385c
movq %r8, %rbx
callq 0x68a0
movq %rbx, %r8
movq %r15, (%r13)
movq %r12, 0x8(%r13)
movq %r8, 0x10(%r13)
xorl %eax, %eax
jmp 0x639cf
movq 0x20(%rax), %rax
movl %esi, %ecx
movq (%rax,%rcx,8), %rbp
movl $0x8, %edi
callq 0x69d0
testq %rax, %rax
je 0x63898
movl $0x444840, (%rax)       # imm = 0x444840
movl $0x3, %ebx
movq %rax, %r8
jmp 0x6389d
xorl %r8d, %r8d
xorl %ebx, %ebx
testq %rax, %rax
je 0x639ca
addq $0x10, %rbp
movl $0x8, %r12d
movq (%rbp), %rbp
leaq 0x1(%rbx), %r15
testq %rbp, %rbp
je 0x639de
cmpq %r12, %r15
jbe 0x63914
movq %rbx, %rax
shrq %rax
orq %rbx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %r12
shrq $0x10, %r12
orq %rcx, %r12
incq %r12
movq %r8, %rdi
movq %r12, %rsi
movq %r8, %r14
callq 0x6c80
testq %rax, %rax
je 0x639b6
movq %rax, %r8
movb $0x9, (%r8,%rbx)
xorl %eax, %eax
testb %al, %al
jne 0x639ca
movq 0x8(%rbp), %rsi
movslq 0x10(%rbp), %r13
leaq (%r15,%r13), %rbx
cmpq %r12, %rbx
jbe 0x6398c
movq %rsi, 0x20(%rsp)
leaq -0x1(%rbx), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %r12
shrq $0x10, %r12
orq %rax, %r12
incq %r12
movq %r8, %rdi
movq %r12, %rsi
movq %r8, %r14
callq 0x6c80
testq %rax, %rax
je 0x639c3
movq %rax, %r8
movq 0x20(%rsp), %rsi
movq %r8, %r14
addq %r8, %r15
movq %r15, %rdi
movq %r13, %rdx
callq 0x6570
cmpl $-0x1, %r13d
sete %al
testb %al, %al
movq 0x10(%rsp), %r13
movq %r14, %r8
je 0x638b0
jmp 0x639ca
movb $0x1, %al
movq %rbx, %r15
movq %r14, %r8
jmp 0x6391b
movb $0x1, %al
movq %r15, %rbx
jmp 0x639a4
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq %r12, %r15
jb 0x63a2d
movq %r15, %rax
shrq %rax
orq %r15, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %r12
shrq $0x10, %r12
orq %rcx, %r12
incq %r12
movq %r8, %rdi
movq %r12, %rsi
movq %r8, %r14
callq 0x6c80
testq %rax, %rax
je 0x63a45
movq %rax, %r8
movw $0xa, (%r8,%rbx)
movb $0x1, %al
testb %al, %al
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jne 0x634cd
jmp 0x639cf
xorl %eax, %eax
movq %rbx, %r15
movq %r14, %r8
jmp 0x63a36