// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq %rdi, %rbx
callq 0x69644
pushq $-0x1
popq %rbp
testq %rax, %rax
je 0x6960b
movq %rax, %r14
cmpq $0x0, 0x20(%rbx)
je 0x6950a
cmpq $0x0, 0x10(%rbx)
je 0x6950a
movslq (%rbx), %rax
testq %rax, %rax
jle 0x6950a
cmpl $0x0, 0x28(%r14)
jle 0x693a8
leaq 0x1a6cf(%rip), %rsi     # 0x83a61
leaq 0x1a6ea(%rip), %rdx     # 0x83a83
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
jmp 0x69528
cmpl %eax, 0x2c(%r14)
jge 0x693ce
movq 0x30(%r14), %rdi
imulq $0x18, %rax, %rsi
callq 0x4840
testq %rax, %rax
je 0x69528
movq %rax, 0x30(%r14)
movl (%rbx), %eax
movl %eax, 0x2c(%r14)
xorl %r15d, %r15d
leaq 0x10(%rsp), %r12
xorl %r13d, %r13d
movslq %eax, %rcx
cmpq %rcx, %r13
jge 0x69503
movq 0x10(%r14), %rdi
movq 0x20(%rbx), %rax
movq (%rax,%r13,8), %rsi
callq 0x49393
movq 0x30(%r14), %rcx
movq %rax, (%rcx,%r15)
testq %rax, %rax
je 0x6949a
movq 0x10(%rbx), %rdx
movl (%rdx,%r13,4), %edx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
cmpq %rsi, %rdx
je 0x69464
movq %rbx, %rbp
movq %rdx, 0x8(%rcx,%r15)
andq $0x0, 0x10(%rcx,%r15)
movq 0x38(%r14), %rdi
movq (%rcx,%r15), %rsi
movq %r12, %rdx
callq 0x6b9b4
cmpl $0x0, 0x10(%rsp)
js 0x6949a
je 0x6961c
movq %rbp, %rbx
movq 0x38(%r14), %rcx
movq 0x20(%rcx), %rcx
movl %eax, %eax
movl %r13d, (%rcx,%rax,4)
incq %r13
movl (%rbp), %eax
addq $0x18, %r15
jmp 0x693d9
movq %rbx, %rbp
movq 0x30(%rbx), %rbx
testq %rbx, %rbx
je 0x6941c
movq %rbx, %rdi
movq %rax, %rsi
callq 0xefef
cmpl (%rbx), %eax
jae 0x6948f
movq 0x20(%rbx), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rdx
movq 0x30(%r14), %rcx
jmp 0x6941c
movq 0x30(%r14), %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
jmp 0x6941c
callq 0x4050
movl (%rax), %edi
callq 0x4150
leaq 0x1a5b4(%rip), %rsi     # 0x83a61
leaq 0x10f75(%rip), %rdx     # 0x7a429
xorl %r12d, %r12d
pushq $0x1
popq %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x110c6
pushq $-0x1
popq %rbp
subq $0x1, %r13
jb 0x694fc
movq 0x30(%r14), %rax
cmpq $0x0, (%rax,%r12)
je 0x694f6
movq 0x38(%r14), %rbx
movq (%rax,%r15), %rsi
movq %rbx, %rdi
callq 0x6b87d
cmpl (%rbx), %eax
jae 0x694f6
movq %rbx, %rdi
movl %eax, %esi
callq 0x6b983
addq $0x18, %r12
jmp 0x694c7
andl $0x0, 0x28(%r14)
jmp 0x69528
movl %eax, 0x28(%r14)
pushq $-0x1
popq %rbp
movq 0x28(%rbx), %rsi
testq %rsi, %rsi
je 0x69535
movq 0x8(%rbx), %rdx
testq %rdx, %rdx
je 0x69535
movq %r14, %rdi
callq 0x6984d
testl %eax, %eax
je 0x69535
movq %r14, %rdi
callq 0x69799
jmp 0x6960b
movq %rbx, 0x8(%rsp)
leaq 0x10(%rsp), %rbp
leaq 0x11e2f(%rip), %r15     # 0x7b375
leaq 0x13e1b(%rip), %r13     # 0x7d368
xorl %ebx, %ebx
xorl %r12d, %r12d
movslq 0x28(%r14), %rax
cmpq %rax, %r12
jge 0x695b9
movq 0x30(%r14), %rax
cmpq $0x0, 0x10(%rax,%rbx)
jne 0x695b0
movq 0x8(%rax,%rbx), %rcx
movq %rbp, %rdi
pushq $0x20
popq %rsi
leaq 0xf029(%rip), %rdx      # 0x785a2
xorl %eax, %eax
callq 0x4800
movq 0x30(%r14), %rax
movq (%rax,%rbx), %rcx
andq $0x0, (%rsp)
movq %r14, %rdi
movq %r15, %rdx
movq %r13, %r8
movq %rbp, %r9
xorl %eax, %eax
callq 0x6dd34
testl %eax, %eax
jne 0x69600
movq 0x30(%r14), %rax
cmpq $0x0, 0x10(%rax,%rbx)
je 0x695dc
incq %r12
addq $0x18, %rbx
jmp 0x69552
movq 0x8(%rsp), %rdi
movq %r14, 0x38(%rdi)
cmpl $0x0, 0x94(%r14)
pushq $-0x1
popq %rbp
js 0x695d8
callq 0x69c81
testl %eax, %eax
jne 0x6960b
xorl %ebp, %ebp
jmp 0x6960b
movq (%rax,%rbx), %r8
movq 0x8(%rax,%rbx), %r9
leaq 0x1a5db(%rip), %rsi     # 0x83bc7
leaq 0x1a5ea(%rip), %rdx     # 0x83bdd
pushq $0x1
popq %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x110c6
movq %r14, %rdi
callq 0x69799
pushq $-0x1
popq %rbp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%r14), %rax
movq (%rax,%r15), %rcx
leaq 0x1a436(%rip), %rsi     # 0x83a61
leaq 0x1a471(%rip), %rdx     # 0x83aa3
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
pushq $-0x1
popq %rbp
jmp 0x69528