// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/header.c
// Function: sam_hdr_fill_hrecs
int sam_hdr_fill_hrecs(sam_hdr_t *bh) {
    sam_hrecs_t *hrecs = sam_hrecs_new();

    if (!hrecs)
        return -1;

    if (bh->target_name && bh->target_len && bh->n_targets > 0) {
        if (sam_hrecs_refs_from_targets_array(hrecs, bh) != 0) {
            sam_hrecs_free(hrecs);
            return -1;
        }
    }

    // Parse existing header text
    if (bh->text && bh->l_text > 0) {
        if (sam_hrecs_parse_lines(hrecs, bh->text, bh->l_text) != 0) {
            sam_hrecs_free(hrecs);
            return -1;
        }
    }

    if (add_stub_ref_sq_lines(hrecs) < 0) {
        sam_hrecs_free(hrecs);
        return -1;
    }

    bh->hrecs = hrecs;

    if (hrecs->refs_changed >= 0 && rebuild_target_arrays(bh) != 0)
        return -1;

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %r15
callq 0x845c0
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x84588
movq %rax, %rdi
cmpq $0x0, 0x20(%r15)
movq %rax, 0x8(%rsp)
je 0x84470
cmpq $0x0, 0x10(%r15)
je 0x84470
movslq (%r15), %rax
testq %rax, %rax
jle 0x84470
cmpl $0x0, 0x28(%rdi)
jle 0x841b1
leaq 0x1dfd8(%rip), %rsi     # 0xa2171
leaq 0x1dff3(%rip), %rdx     # 0xa2193
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
jmp 0x84490
cmpl %eax, 0x2c(%rdi)
jge 0x841e7
movq 0x30(%rdi), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
callq 0x4840
movq 0x8(%rsp), %rdi
testq %rax, %rax
je 0x84495
movq %rax, 0x30(%rdi)
movl (%r15), %eax
movl %eax, 0x2c(%rdi)
testl %eax, %eax
jle 0x8446d
xorl %r14d, %r14d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
leaq 0x50(%rsp), %r12
xorl %ebx, %ebx
movq 0x10(%rdi), %rdi
movq 0x20(%r15), %rax
movq (%rax,%rbx,8), %rsi
callq 0x57fd5
movq 0x8(%rsp), %rsi
movq 0x30(%rsi), %rcx
movq %rax, (%rcx,%r14)
testq %rax, %rax
movq %rbx, 0x28(%rsp)
je 0x842cc
movq 0x10(%r15), %rdx
movl (%rdx,%rbx,4), %edx
cmpq %r13, %rdx
je 0x84289
movq %rdx, 0x8(%rcx,%r14)
movq $0x0, 0x10(%rcx,%r14)
movq 0x38(%rsi), %rdi
movq (%rcx,%r14), %rsi
movq %r12, %rdx
callq 0x8732d
movq 0x8(%rsp), %rdi
cmpl $0x0, 0x50(%rsp)
movq 0x28(%rsp), %rbx
js 0x842cc
je 0x84599
movq 0x38(%rdi), %rcx
movq 0x20(%rcx), %rcx
movl %eax, %eax
movl %ebx, (%rcx,%rax,4)
incq %rbx
movslq (%r15), %rax
addq $0x18, %r14
cmpq %rax, %rbx
jl 0x841f7
jmp 0x8446d
movq 0x30(%r15), %rbx
testq %rbx, %rbx
je 0x8422f
movq %rbx, %rdi
movq %rax, %rsi
callq 0x10e38
cmpl (%rbx), %eax
jae 0x842b9
movq 0x20(%rbx), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rdx
movq 0x8(%rsp), %rsi
movq 0x30(%rsi), %rcx
jmp 0x8422f
movq 0x8(%rsp), %rsi
movq 0x30(%rsi), %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
jmp 0x8422f
movq %r14, 0x30(%rsp)
callq 0x4050
movl (%rax), %edi
callq 0x4150
leaq 0x1de8d(%rip), %rsi     # 0xa2171
leaq 0x141e3(%rip), %rdx     # 0x984ce
movl $0x1, %edi
movq %rax, %rcx
xorl %eax, %eax
callq 0x13de5
testq %rbx, %rbx
je 0x8445a
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0x20(%rsp)
xorl %eax, %eax
movq %rax, 0x40(%rsp)
leaq (%rax,%rax,2), %rax
movq 0x20(%rsp), %rcx
cmpq $0x0, (%rcx,%rax,8)
je 0x84447
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rax
movq %rax, 0x10(%rsp)
movl (%rax), %edx
testl %edx, %edx
je 0x84375
movq 0x30(%rsp), %rax
movq 0x20(%rsp), %rcx
movq (%rcx,%rax), %r13
movb (%r13), %cl
testb %cl, %cl
je 0x8437d
leaq 0x1(%r13), %rax
movl $0x811c9dc5, %ebp       # imm = 0x811C9DC5
movzbl %cl, %ecx
xorl %ebp, %ecx
imull $0x1000193, %ecx, %ebp  # imm = 0x1000193
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x8435f
jmp 0x84382
xorl %r12d, %r12d
jmp 0x8440d
movl $0x811c9dc5, %ebp       # imm = 0x811C9DC5
movq %rdx, 0x38(%rsp)
decl %edx
andl %edx, %ebp
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rsi
movl $0x1, %r14d
movl %ebp, %r12d
movl %edx, 0x1c(%rsp)
movq %rsi, 0x48(%rsp)
movl %r12d, %eax
shrl $0x4, %eax
movl (%rsi,%rax,4), %r15d
leal (%r12,%r12), %ebx
andl $0x1e, %ebx
movl %r15d, %eax
movl %ebx, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x843fb
testb $0x1, %al
jne 0x843eb
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movl %r12d, %ecx
movq (%rax,%rcx,8), %rdi
movq %r13, %rsi
callq 0x46c0
movq 0x48(%rsp), %rsi
movl 0x1c(%rsp), %edx
testl %eax, %eax
je 0x843fb
addl %r14d, %r12d
andl %edx, %r12d
incl %r14d
cmpl %ebp, %r12d
jne 0x843a6
jmp 0x84447
movl %ebx, %ecx
shrl %cl, %r15d
testb $0x3, %r15b
movq 0x38(%rsp), %rdx
cmovnel %edx, %r12d
cmpl %edx, %r12d
jae 0x84447
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movl %r12d, %edx
shrl $0x4, %edx
movl (%rax,%rdx,4), %esi
addl %r12d, %r12d
andl $0x1e, %r12d
movl %esi, %edi
movl %r12d, %ecx
shrl %cl, %edi
testb $0x3, %dil
jne 0x84447
btsl %r12d, %esi
movl %esi, (%rax,%rdx,4)
movq 0x10(%rsp), %rax
decl 0x4(%rax)
movq 0x40(%rsp), %rax
incq %rax
cmpq %rax, 0x28(%rsp)
jne 0x84313
movq 0x8(%rsp), %rdi
movl $0x0, 0x28(%rdi)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x84495
movl %eax, 0x28(%rdi)
movq 0x28(%r15), %rsi
testq %rsi, %rsi
je 0x8449f
movq 0x8(%r15), %rdx
testq %rdx, %rdx
je 0x8449f
movq 0x8(%rsp), %rdi
callq 0x848b6
testl %eax, %eax
je 0x8449f
movq 0x8(%rsp), %rdi
callq 0x84763
jmp 0x84588
movq 0x8(%rsp), %r14
movl 0x28(%r14), %ecx
testl %ecx, %ecx
jle 0x84532
movq 0x30(%r14), %rax
leaq 0x50(%rsp), %rbp
leaq 0x170ad(%rip), %r13     # 0x9b56d
xorl %ebx, %ebx
xorl %r12d, %r12d
cmpq $0x0, 0x10(%rax,%rbx)
jne 0x84523
movq 0x8(%rax,%rbx), %rcx
movl $0x20, %esi
movq %rbp, %rdi
leaq 0x120d0(%rip), %rdx     # 0x965b1
xorl %eax, %eax
callq 0x4800
movq 0x30(%r14), %rax
movq (%rax,%rbx), %rcx
movq $0x0, (%rsp)
movq %r14, %rdi
leaq 0x14f03(%rip), %rdx     # 0x99405
movq %r13, %r8
movq %rbp, %r9
xorl %eax, %eax
callq 0x8a861
testl %eax, %eax
jne 0x8457b
movq 0x30(%r14), %rax
cmpq $0x0, 0x10(%rax,%rbx)
je 0x84555
movl 0x28(%r14), %ecx
incq %r12
movslq %ecx, %rdx
addq $0x18, %rbx
cmpq %rdx, %r12
jl 0x844c5
movq %r14, 0x38(%r15)
cmpl $0x0, 0x94(%r14)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
js 0x84551
movq %r15, %rdi
callq 0x84ce2
testl %eax, %eax
jne 0x84588
xorl %ebp, %ebp
jmp 0x84588
movq (%rax,%rbx), %r8
movq 0x8(%rax,%rbx), %r9
leaq 0x1dd72(%rip), %rsi     # 0xa22d7
leaq 0x1dd81(%rip), %rdx     # 0xa22ed
movl $0x1, %edi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x13de5
movq %r14, %rdi
callq 0x84763
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%rdi), %rax
movq (%rax,%r14), %rcx
leaq 0x1dbc9(%rip), %rsi     # 0xa2171
leaq 0x1dc04(%rip), %rdx     # 0xa21b3
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
jmp 0x84490