// File: /workspace/github_cpp_makefile_star2_O1/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 0x40b27
movq %rdi, %rbx
movl 0x498(%rdi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x498(%rdi)
cmpl $0x1, %eax
jle 0x40b2d
popq %rbx
popq %r14
popq %r15
retq
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x40b3b
callq 0x4610
movq 0x18(%rbx), %r14
testq %r14, %r14
je 0x40b67
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 0x40b93
movq 0x18(%r14), %rdi
callq 0x4610
movq 0x10(%r14), %rdi
callq 0x4610
movq 0x20(%r14), %rdi
callq 0x4610
movq %r14, %rdi
callq 0x4610
cmpq $0x0, 0x40(%rbx)
je 0x40bd1
cmpl $0x0, 0x38(%rbx)
jle 0x40bc8
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x40(%rbx), %rax
movq (%rax,%r14), %rdi
testq %rdi, %rdi
je 0x40bb8
callq 0x4610
incq %r15
movslq 0x38(%rbx), %rax
addq $0x20, %r14
cmpq %rax, %r15
jl 0x40ba6
movq 0x40(%rbx), %rdi
callq 0x4610
movq 0x60(%rbx), %r14
testq %r14, %r14
je 0x40bfd
movq 0x18(%r14), %rdi
callq 0x4610
movq 0x10(%r14), %rdi
callq 0x4610
movq 0x20(%r14), %rdi
callq 0x4610
movq %r14, %rdi
callq 0x4610
cmpq $0x0, 0x58(%rbx)
je 0x40c3b
cmpl $0x0, 0x50(%rbx)
jle 0x40c32
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x58(%rbx), %rax
movq (%rax,%r14), %rdi
testq %rdi, %rdi
je 0x40c22
callq 0x4610
incq %r15
movslq 0x50(%rbx), %rax
addq $0x20, %r14
cmpq %rax, %r15
jl 0x40c10
movq 0x58(%rbx), %rdi
callq 0x4610
movq 0x80(%rbx), %r14
testq %r14, %r14
je 0x40c6a
movq 0x18(%r14), %rdi
callq 0x4610
movq 0x10(%r14), %rdi
callq 0x4610
movq 0x20(%r14), %rdi
callq 0x4610
movq %r14, %rdi
callq 0x4610
cmpq $0x0, 0x78(%rbx)
je 0x40ca8
cmpl $0x0, 0x68(%rbx)
jle 0x40c9f
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x78(%rbx), %rax
movq (%rax,%r14), %rdi
testq %rdi, %rdi
je 0x40c8f
callq 0x4610
incq %r15
movslq 0x68(%rbx), %rax
addq $0x28, %r14
cmpq %rax, %r15
jl 0x40c7d
movq 0x78(%rbx), %rdi
callq 0x4610
movq 0x88(%rbx), %rdi
testq %rdi, %rdi
je 0x40cb9
callq 0x4610
movq 0x28(%rbx), %rdi
testq %rdi, %rdi
je 0x40cc7
callq 0x4e141
movq 0x30(%rbx), %rdi
testq %rdi, %rdi
je 0x40cd5
callq 0x4e141
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0x40ce3
callq 0x41e2f
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x4610