// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/htslib/cram/sam_header.c
// Function: sam_hdr_free
void sam_hdr_free(SAM_hdr *hdr) {
    if (!hdr)
	return;

    if (--hdr->ref_count > 0)
	return;

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

    if (hdr->h)
	kh_destroy(sam_hdr, hdr->h);

    if (hdr->ref_hash)
	kh_destroy(m_s2i, hdr->ref_hash);

    if (hdr->ref) {
	int i;
	for (i = 0; i < hdr->nref; i++)
	    if (hdr->ref[i].name)
		free(hdr->ref[i].name);
	free(hdr->ref);
    }

    if (hdr->rg_hash)
	kh_destroy(m_s2i, hdr->rg_hash);

    if (hdr->rg) {
	int i;
	for (i = 0; i < hdr->nrg; i++)
	    if (hdr->rg[i].name)
		free(hdr->rg[i].name);
	free(hdr->rg);
    }

    if (hdr->pg_hash)
	kh_destroy(m_s2i, hdr->pg_hash);

    if (hdr->pg) {
	int i;
	for (i = 0; i < hdr->npg; i++)
	    if (hdr->pg[i].name)
		free(hdr->pg[i].name);
	free(hdr->pg);
    }

    if (hdr->pg_end)
	free(hdr->pg_end);

    if (hdr->type_pool)
	pool_destroy(hdr->type_pool);

    if (hdr->tag_pool)
	pool_destroy(hdr->tag_pool);

    if (hdr->str_pool)
	string_pool_destroy(hdr->str_pool);

    free(hdr);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
testq %rdi, %rdi
je 0x3faef
movq %rdi, %rbx
movl 0x498(%rdi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x498(%rdi)
cmpl $0x1, %eax
jle 0x3faf5
popq %rbx
popq %r14
popq %r15
retq
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x3fb03
callq 0x4610
movq 0x18(%rbx), %r14
testq %r14, %r14
je 0x3fb2f
movq 0x18(%r14), %rdi
callq 0x4610
movq 0x10(%r14), %rdi
callq 0x4610
movq 0x20(%r14), %rdi
callq 0x4610
movq %r14, %rdi
callq 0x4610
movq 0x48(%rbx), %r14
testq %r14, %r14
je 0x3fb5b
movq 0x18(%r14), %rdi
callq 0x4610
movq 0x10(%r14), %rdi
callq 0x4610
movq 0x20(%r14), %rdi
callq 0x4610
movq %r14, %rdi
callq 0x4610
movq 0x40(%rbx), %rdi
testq %rdi, %rdi
je 0x3fb9e
movl 0x38(%rbx), %eax
testl %eax, %eax
jle 0x3fb99
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x40(%rbx), %rcx
movq (%rcx,%r14), %rdi
testq %rdi, %rdi
je 0x3fb86
callq 0x4610
movl 0x38(%rbx), %eax
incq %r15
movslq %eax, %rcx
addq $0x20, %r14
cmpq %rcx, %r15
jl 0x3fb71
movq 0x40(%rbx), %rdi
callq 0x4610
movq 0x60(%rbx), %r14
testq %r14, %r14
je 0x3fbca
movq 0x18(%r14), %rdi
callq 0x4610
movq 0x10(%r14), %rdi
callq 0x4610
movq 0x20(%r14), %rdi
callq 0x4610
movq %r14, %rdi
callq 0x4610
movq 0x58(%rbx), %rdi
testq %rdi, %rdi
je 0x3fc0d
movl 0x50(%rbx), %eax
testl %eax, %eax
jle 0x3fc08
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x58(%rbx), %rcx
movq (%rcx,%r14), %rdi
testq %rdi, %rdi
je 0x3fbf5
callq 0x4610
movl 0x50(%rbx), %eax
incq %r15
movslq %eax, %rcx
addq $0x20, %r14
cmpq %rcx, %r15
jl 0x3fbe0
movq 0x58(%rbx), %rdi
callq 0x4610
movq 0x80(%rbx), %r14
testq %r14, %r14
je 0x3fc3c
movq 0x18(%r14), %rdi
callq 0x4610
movq 0x10(%r14), %rdi
callq 0x4610
movq 0x20(%r14), %rdi
callq 0x4610
movq %r14, %rdi
callq 0x4610
movq 0x78(%rbx), %rdi
testq %rdi, %rdi
je 0x3fc7f
movl 0x68(%rbx), %eax
testl %eax, %eax
jle 0x3fc7a
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x78(%rbx), %rcx
movq (%rcx,%r14), %rdi
testq %rdi, %rdi
je 0x3fc67
callq 0x4610
movl 0x68(%rbx), %eax
incq %r15
movslq %eax, %rcx
addq $0x28, %r14
cmpq %rcx, %r15
jl 0x3fc52
movq 0x78(%rbx), %rdi
callq 0x4610
movq 0x88(%rbx), %rdi
testq %rdi, %rdi
je 0x3fc90
callq 0x4610
movq 0x28(%rbx), %rdi
testq %rdi, %rdi
je 0x3fc9e
callq 0x4d049
movq 0x30(%rbx), %rdi
testq %rdi, %rdi
je 0x3fcac
callq 0x4d049
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0x3fcba
callq 0x40e23
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x4610