// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/header.c
// Function: sam_hdr_update_target_arrays
int sam_hdr_update_target_arrays(sam_hdr_t *bh, const sam_hrecs_t *hrecs,
                                 int refs_changed) {
    if (!bh || !hrecs)
        return -1;

    if (refs_changed < 0)
        return 0;

    // Grow arrays if necessary
    if (bh->n_targets < hrecs->nref) {
        char **new_names = realloc(bh->target_name,
                                   hrecs->nref * sizeof(*new_names));
        if (!new_names)
            return -1;
        bh->target_name = new_names;
        uint32_t *new_lens = realloc(bh->target_len,
                                     hrecs->nref * sizeof(*new_lens));
        if (!new_lens)
            return -1;
        bh->target_len = new_lens;
    }

    // Update names and lengths where changed
    // hrecs->refs_changed is the first ref that has been updated, so ones
    // before that can be skipped.
    int i;
    khint_t k;
    khash_t(s2i) *long_refs = (khash_t(s2i) *) bh->sdict;
    for (i = refs_changed; i < hrecs->nref; i++) {
        if (i >= bh->n_targets
            || strcmp(bh->target_name[i], hrecs->ref[i].name) != 0) {
            if (i < bh->n_targets)
                free(bh->target_name[i]);
            bh->target_name[i] = strdup(hrecs->ref[i].name);
            if (!bh->target_name[i])
                return -1;
        }
        if (hrecs->ref[i].len < UINT32_MAX) {
            bh->target_len[i] = hrecs->ref[i].len;

            if (!long_refs)
                continue;

            // Check if we have an old length, if so remove it.
            k = kh_get(s2i, long_refs, bh->target_name[i]);
            if (k < kh_end(long_refs))
                kh_del(s2i, long_refs, k);
        } else {
            bh->target_len[i] = UINT32_MAX;
            if (bh->hrecs != hrecs) {
                // Called from sam_hdr_dup; need to add sdict entries
                if (!long_refs) {
                    if (!(bh->sdict = long_refs = kh_init(s2i)))
                        return -1;
                }

                // Add / update length
                int absent;
                k = kh_put(s2i, long_refs, bh->target_name[i], &absent);
                if (absent < 0)
                    return -1;
                kh_val(long_refs, k) = hrecs->ref[i].len;
            }
        }
    }

    // Free up any names that have been removed
    for (; i < bh->n_targets; i++) {
        if (long_refs) {
            k = kh_get(s2i, long_refs, bh->target_name[i]);
            if (k < kh_end(long_refs))
                kh_del(s2i, long_refs, k);
        }
        free(bh->target_name[i]);
    }

    bh->n_targets = hrecs->nref;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xd7151
cmpq $0x0, -0x18(%rbp)
jne 0xd715d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd7484
cmpl $0x0, -0x1c(%rbp)
jge 0xd716f
movl $0x0, -0x4(%rbp)
jmp 0xd7484
movq -0x10(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0xd71f6
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rax
movslq 0x28(%rax), %rsi
shlq $0x3, %rsi
callq 0x4820
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xd71ae
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd7484
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movslq 0x28(%rax), %rsi
shlq $0x2, %rsi
callq 0x4820
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xd71ea
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd7484
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x40(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0xd7407
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0xd7253
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x4690
cmpl $0x0, %eax
je 0xd72c2
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0xd7273
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x45a0
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x4920
movq %rax, %rdx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x34(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x34(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0xd72c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd7484
jmp 0xd72c2
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, 0x8(%rax)
jge 0xd734c
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x34(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
cmpq $0x0, -0x40(%rbp)
jne 0xd7314
jmp 0xd73f9
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x17480
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl (%rcx), %eax
jae 0xd7347
movq -0x40(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0x17e90
jmp 0xd73f7
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x34(%rbp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
cmpq -0x18(%rbp), %rax
je 0xd73f5
cmpq $0x0, -0x40(%rbp)
jne 0xd739d
callq 0x17390
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rcx
movq %rax, 0x30(%rcx)
cmpq $0x0, %rax
jne 0xd739b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd7484
jmp 0xd739d
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq -0x44(%rbp), %rdx
callq 0x17b30
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x44(%rbp)
jge 0xd73cf
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd7484
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdx
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x38(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
jmp 0xd73f7
jmp 0xd73f9
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xd7208
jmp 0xd7409
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0xd7470
cmpq $0x0, -0x40(%rbp)
je 0xd7450
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x17480
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl (%rcx), %eax
jae 0xd744e
movq -0x40(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0x17e90
jmp 0xd7450
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x45a0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xd7409
movq -0x18(%rbp), %rax
movl 0x28(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)