// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/header.c
// Function: sam_hrecs_refs_from_targets_array
static int sam_hrecs_refs_from_targets_array(sam_hrecs_t *hrecs,
                                             const sam_hdr_t *bh) {
    int32_t tid = 0;

    if (!hrecs || !bh)
        return -1;

    // This should always be called before parsing the text header
    // so the ref array should start off empty, and we don't have to try
    // to reconcile any existing data.
    if (hrecs->nref > 0) {
        hts_log_error("Called with non-empty ref array");
        return -1;
    }

    if (hrecs->ref_sz < bh->n_targets) {
        sam_hrec_sq_t *new_ref = realloc(hrecs->ref,
                                         bh->n_targets * sizeof(*new_ref));
        if (!new_ref)
            return -1;

        hrecs->ref = new_ref;
        hrecs->ref_sz = bh->n_targets;
    }

    for (tid = 0; tid < bh->n_targets; tid++) {
        khint_t k;
        int r;
        hrecs->ref[tid].name = string_dup(hrecs->str_pool, bh->target_name[tid]);
        if (!hrecs->ref[tid].name) goto fail;
        if (bh->target_len[tid] < UINT32_MAX || !bh->sdict) {
            hrecs->ref[tid].len  = bh->target_len[tid];
        } else {
            khash_t(s2i) *long_refs = (khash_t(s2i) *) bh->sdict;
            k = kh_get(s2i, long_refs, hrecs->ref[tid].name);
            if (k < kh_end(long_refs)) {
                hrecs->ref[tid].len = kh_val(long_refs, k);
            } else {
                hrecs->ref[tid].len = UINT32_MAX;
            }
        }
        hrecs->ref[tid].ty   = NULL;
        k = kh_put(m_s2i, hrecs->ref_hash, hrecs->ref[tid].name, &r);
        if (r < 0) goto fail;
        if (r == 0) {
            hts_log_error("Duplicate entry \"%s\" in target list",
                            hrecs->ref[tid].name);
            return -1;
        } else {
            kh_val(hrecs->ref_hash, k) = tid;
        }
    }
    hrecs->nref = bh->n_targets;
    return 0;

 fail: {
        int32_t i;
        hts_log_error("%s", strerror(errno));
        for (i = 0; i < tid; i++) {
            khint_t k;
            if (!hrecs->ref[i].name) continue;
            k = kh_get(m_s2i, hrecs->ref_hash, hrecs->ref[tid].name);
            if (k < kh_end(hrecs->ref_hash)) kh_del(m_s2i, hrecs->ref_hash, k);
        }
        hrecs->nref = 0;
        return -1;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xd77f5
cmpq $0x0, -0x18(%rbp)
jne 0xd7801
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd7b3f
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
jle 0xd7831
movl $0x1, %edi
leaq 0x20c36(%rip), %rsi     # 0xf844d
leaq 0x20c51(%rip), %rdx     # 0xf846f
movb $0x0, %al
callq 0x1b030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd7b3f
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jge 0xd7888
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x18(%rbp), %rax
movslq (%rax), %rax
imulq $0x18, %rax, %rsi
callq 0x4820
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xd786f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd7b3f
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2c(%rax)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jge 0xd7a6f
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x82610
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x1c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
jne 0xd78f2
jmp 0xd7a88
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x1c(%rbp), %rcx
cmpl $-0x1, (%rax,%rcx,4)
jb 0xd790f
movq -0x18(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0xd7939
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x1c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0xd79b8
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x17480
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl (%rcx), %eax
jae 0xd799a
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x2c(%rbp), %ecx
movq (%rax,%rcx,8), %rcx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x1c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0xd79b6
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0x8(%rax)
jmp 0xd79b8
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rsi
leaq -0x30(%rbp), %rdx
callq 0xdb090
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x30(%rbp)
jge 0xd7a08
jmp 0xd7a88
cmpl $0x0, -0x30(%rbp)
jne 0xd7a4a
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movl $0x1, %edi
leaq 0x20a1d(%rip), %rsi     # 0xf844d
leaq 0x20a58(%rip), %rdx     # 0xf848f
movb $0x0, %al
callq 0x1b030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd7b3f
movl -0x1c(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x20(%rax), %rax
movl -0x2c(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
jmp 0xd7a61
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xd788f
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x28(%rax)
movl $0x0, -0x4(%rbp)
jmp 0xd7b3f
callq 0x4050
movl (%rax), %edi
callq 0x4130
movq %rax, %rcx
movl $0x1, %edi
leaq 0x209aa(%rip), %rsi     # 0xf844d
leaq 0x1af4a(%rip), %rdx     # 0xf29f4
movb $0x0, %al
callq 0x1b030
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xd7b2d
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
jne 0xd7adb
jmp 0xd7b22
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0xdae00
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rcx
cmpl (%rcx), %eax
jae 0xd7b20
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movl -0x40(%rbp), %esi
callq 0xdb010
jmp 0xd7b22
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xd7ab8
movq -0x10(%rbp), %rax
movl $0x0, 0x28(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)