// File: /workspace/github_c_makefile_star2_O1/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 0x86b29
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x8695b
movq %rax, %r14
cmpq $0x0, 0x20(%r15)
je 0x86854
cmpq $0x0, 0x10(%r15)
je 0x86854
movslq (%r15), %rax
testq %rax, %rax
jle 0x86854
cmpl $0x0, 0x28(%r14)
jle 0x86717
leaq 0x1e2f3(%rip), %rsi     # 0xa49f2
leaq 0x1e30e(%rip), %rdx     # 0xa4a14
movl $0x1, %edi
xorl %eax, %eax
callq 0x14378
jmp 0x86872
cmpl %eax, 0x2c(%r14)
jge 0x86742
movq 0x30(%r14), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
callq 0x4840
testq %rax, %rax
je 0x86872
movq %rax, 0x30(%r14)
movl (%r15), %eax
movl %eax, 0x2c(%r14)
movl (%r15), %eax
testl %eax, %eax
jle 0x86850
xorl %r13d, %r13d
xorl %ebx, %ebx
movq 0x10(%r14), %rdi
movq 0x20(%r15), %rax
movq (%rax,%rbx,8), %rsi
callq 0x5aa65
movq 0x30(%r14), %rcx
movq %rax, (%rcx,%r13)
movl $0x5, %r12d
testq %rax, %rax
je 0x86824
movq 0x10(%r15), %rdx
movq %rbx, 0x8(%rsp)
movl (%rdx,%rbx,4), %edx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
cmpq %rsi, %rdx
je 0x867d4
movq %rdx, 0x8(%rcx,%r13)
movq 0x30(%r14), %rax
movq $0x0, 0x10(%rax,%r13)
movq 0x38(%r14), %rdi
movq (%rax,%r13), %rsi
leaq 0x50(%rsp), %rdx
callq 0x89a57
cmpl $0x0, 0x50(%rsp)
movq 0x8(%rsp), %rbx
js 0x86824
je 0x867fc
movq 0x38(%r14), %rcx
movq 0x20(%rcx), %rcx
movl %eax, %eax
movl %ebx, (%rcx,%rax,4)
xorl %r12d, %r12d
jmp 0x86824
movq 0x30(%r15), %rbx
testq %rbx, %rbx
je 0x86790
movq %rbx, %rdi
movq %rax, %rsi
callq 0x11074
cmpl (%rbx), %eax
jae 0x86842
movq 0x20(%rbx), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rdx
movq 0x30(%r14), %rcx
jmp 0x86790
movq 0x30(%r14), %rax
movq (%rax,%r13), %rcx
movl $0x1, %r12d
movl $0x1, %edi
leaq 0x1e1dc(%rip), %rsi     # 0xa49f2
leaq 0x1e217(%rip), %rdx     # 0xa4a34
xorl %eax, %eax
callq 0x14378
testl %r12d, %r12d
jne 0x8696c
incq %rbx
movslq (%r15), %rax
addq $0x18, %r13
cmpq %rax, %rbx
jl 0x86752
jmp 0x86850
movq 0x30(%r14), %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
jmp 0x86790
movl %eax, 0x28(%r14)
movq 0x28(%r15), %rsi
testq %rsi, %rsi
je 0x8687f
movq 0x8(%r15), %rdx
testq %rdx, %rdx
je 0x8687f
movq %r14, %rdi
callq 0x86e21
testl %eax, %eax
je 0x8687f
movq %r14, %rdi
callq 0x86cce
jmp 0x8695b
cmpl $0x0, 0x28(%r14)
jle 0x86905
leaq 0x50(%rsp), %rbp
leaq 0x17ae3(%rip), %r13     # 0x9e375
xorl %ebx, %ebx
xorl %r12d, %r12d
movq 0x30(%r14), %rax
cmpq $0x0, 0x10(%rax,%rbx)
jne 0x868f5
movq 0x8(%rax,%rbx), %rcx
movl $0x20, %esi
movq %rbp, %rdi
leaq 0x12c5a(%rip), %rdx     # 0x99511
xorl %eax, %eax
callq 0x4800
movq 0x30(%r14), %rax
movq (%rax,%rbx), %rcx
movq $0x0, (%rsp)
movq %r14, %rdi
leaq 0x15ab1(%rip), %rdx     # 0x9c389
movq %r13, %r8
movq %rbp, %r9
xorl %eax, %eax
callq 0x8d20d
testl %eax, %eax
jne 0x8694e
movq 0x30(%r14), %rax
cmpq $0x0, 0x10(%rax,%rbx)
je 0x86928
incq %r12
movslq 0x28(%r14), %rax
addq $0x18, %rbx
cmpq %rax, %r12
jl 0x86897
movq %r14, 0x38(%r15)
cmpl $0x0, 0x94(%r14)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
js 0x86924
movq %r15, %rdi
callq 0x872c6
testl %eax, %eax
jne 0x8695b
xorl %ebp, %ebp
jmp 0x8695b
movq (%rax,%rbx), %r8
movq 0x8(%rax,%rbx), %r9
leaq 0x1e220(%rip), %rsi     # 0xa4b58
leaq 0x1e22f(%rip), %rdx     # 0xa4b6e
movl $0x1, %edi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x14378
movq %r14, %rdi
callq 0x86cce
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x5, %r12d
jne 0x86872
callq 0x4050
movl (%rax), %edi
callq 0x4150
leaq 0x1e069(%rip), %rsi     # 0xa49f2
leaq 0x14b37(%rip), %rdx     # 0x9b4c7
movl $0x1, %edi
movq %rax, %rcx
xorl %eax, %eax
callq 0x14378
testq %r13, %r13
je 0x86b1c
movq 0x30(%r14), %r8
xorl %r9d, %r9d
movq %r13, 0x38(%rsp)
movq %rbx, 0x8(%rsp)
movq %r8, 0x30(%rsp)
movq %r14, 0x28(%rsp)
leaq (%r9,%r9,2), %rax
cmpq $0x0, (%r8,%rax,8)
je 0x86b10
movq 0x38(%r14), %rax
movq %rax, 0x10(%rsp)
movl (%rax), %eax
testl %eax, %eax
je 0x86a18
movq %rax, 0x18(%rsp)
movq %r9, 0x40(%rsp)
movq (%r8,%r13), %r14
movb (%r14), %cl
testb %cl, %cl
je 0x86a20
leaq 0x1(%r14), %rax
movl $0x811c9dc5, %r12d      # imm = 0x811C9DC5
movzbl %cl, %ecx
xorl %r12d, %ecx
imull $0x1000193, %ecx, %r12d # imm = 0x1000193
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x86a00
jmp 0x86a26
xorl %r15d, %r15d
jmp 0x86ad6
movl $0x811c9dc5, %r12d      # imm = 0x811C9DC5
movq 0x18(%rsp), %rax
leal -0x1(%rax), %edx
andl %edx, %r12d
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rsi
movl $0x1, %r13d
movl %r12d, %r15d
movl %edx, 0x24(%rsp)
movq %rsi, 0x48(%rsp)
movl %r15d, %eax
shrl $0x4, %eax
movl (%rsi,%rax,4), %ebp
leal (%r15,%r15), %ebx
andl $0x1e, %ebx
movl %ebp, %eax
movl %ebx, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x86aa7
testb $0x1, %al
jne 0x86a8f
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq %r14, %rsi
callq 0x46c0
movq 0x48(%rsp), %rsi
movl 0x24(%rsp), %edx
testl %eax, %eax
je 0x86aa7
addl %r13d, %r15d
andl %edx, %r15d
incl %r13d
cmpl %r12d, %r15d
jne 0x86a4c
movq 0x18(%rsp), %rax
movl %eax, %r15d
jmp 0x86ab8
movl %ebx, %ecx
shrl %cl, %ebp
testb $0x3, %bpl
movq 0x18(%rsp), %rax
cmovnel %eax, %r15d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x38(%rsp), %r13
movq 0x8(%rsp), %rbx
movq 0x30(%rsp), %r8
movq 0x40(%rsp), %r9
movq 0x28(%rsp), %r14
cmpl %eax, %r15d
jae 0x86b10
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movl %r15d, %edx
shrl $0x4, %edx
movl (%rax,%rdx,4), %esi
addl %r15d, %r15d
andl $0x1e, %r15d
movl %esi, %edi
movl %r15d, %ecx
shrl %cl, %edi
testb $0x3, %dil
jne 0x86b10
btsl %r15d, %esi
movl %esi, (%rax,%rdx,4)
movq 0x10(%rsp), %rax
decl 0x4(%rax)
incq %r9
cmpq %r9, %rbx
jne 0x869c3
movl $0x0, 0x28(%r14)
jmp 0x86872