// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/cram/cram_io.c
// Function: refs_from_header
static int refs_from_header(cram_fd *fd) {
    if (!fd)
        return -1;

    refs_t *r = fd->refs;
    if (!r)
        return -1;

    sam_hdr_t *h = fd->header;
    if (!h)
        return 0;

    if (!h->hrecs) {
        if (-1 == sam_hdr_fill_hrecs(h))
            return -1;
    }

    if (h->hrecs->nref == 0)
        return 0;

    //fprintf(stderr, "refs_from_header for %p mode %c\n", fd, fd->mode);

    /* Existing refs are fine, as long as they're compatible with the hdr. */
    ref_entry **new_ref_id = realloc(r->ref_id, (r->nref + h->hrecs->nref) * sizeof(*r->ref_id));
    if (!new_ref_id)
        return -1;
    r->ref_id = new_ref_id;

    int i, j;
    /* Copy info from h->ref[i] over to r */
    for (i = 0, j = r->nref; i < h->hrecs->nref; i++) {
        sam_hrec_type_t *ty;
        sam_hrec_tag_t *tag;
        khint_t k;
        int n;

        k = kh_get(refs, r->h_meta, h->hrecs->ref[i].name);
        if (k != kh_end(r->h_meta))
            // Ref already known about
            continue;

        if (!(r->ref_id[j] = calloc(1, sizeof(ref_entry))))
            return -1;

        if (!h->hrecs->ref[i].name)
            return -1;

        r->ref_id[j]->name = string_dup(r->pool, h->hrecs->ref[i].name);
        if (!r->ref_id[j]->name) return -1;
        r->ref_id[j]->length = 0; // marker for not yet loaded

        /* Initialise likely filename if known */
        if ((ty = sam_hrecs_find_type_id(h->hrecs, "SQ", "SN", h->hrecs->ref[i].name))) {
            if ((tag = sam_hrecs_find_key(ty, "M5", NULL)))
                r->ref_id[j]->fn = string_dup(r->pool, tag->str+3);

            if ((tag = sam_hrecs_find_key(ty, "LN", NULL))) {
                // LN tag used when constructing consensus reference
                r->ref_id[j]->LN_length = strtoll(tag->str+3, NULL, 0);
                // See fuzz 382922241
                if (r->ref_id[j]->LN_length < 0)
                    r->ref_id[j]->LN_length = 0;
            }
        }

        k = kh_put(refs, r->h_meta, r->ref_id[j]->name, &n);
        if (n <= 0) // already exists or error
            return -1;
        kh_val(r->h_meta, k) = r->ref_id[j];

        j++;
    }
    r->nref = j;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x71d0f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x720a0
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x71d2e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x720a0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x71d4d
movl $0x0, -0x4(%rbp)
jmp 0x720a0
movq -0x20(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x71d7a
movq -0x20(%rbp), %rdi
callq 0xd7490
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x71d78
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x720a0
jmp 0x71d7a
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
cmpl $0x0, 0x28(%rax)
jne 0x71d94
movl $0x0, -0x4(%rbp)
jmp 0x720a0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x20(%rbp), %rcx
movq 0x38(%rcx), %rcx
addl 0x28(%rcx), %eax
movslq %eax, %rsi
shlq $0x3, %rsi
callq 0x4820
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x71dd1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x720a0
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x0, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
movq 0x38(%rcx), %rcx
cmpl 0x28(%rcx), %eax
jge 0x7208f
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x30(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x71b10
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpl (%rcx), %eax
je 0x71e40
jmp 0x72081
movl $0x1, %edi
movl $0x50, %esi
callq 0x42f0
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x30(%rbp), %rdx
movq %rax, (%rcx,%rdx,8)
cmpq $0x0, %rax
jne 0x71e71
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x720a0
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x30(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
jne 0x71e9a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x720a0
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x30(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x82610
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x30(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq $0x0, (%rax)
jne 0x71ef8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x720a0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq $0x0, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x30(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
leaq 0x807b3(%rip), %rsi     # 0xf26ec
leaq 0x81a1d(%rip), %rdx     # 0xf395d
callq 0xd9960
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x7201f
movq -0x38(%rbp), %rdi
leaq 0x81a02(%rip), %rsi     # 0xf3960
xorl %eax, %eax
movl %eax, %edx
callq 0xdaf50
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x71fa0
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x3, %rsi
callq 0x82610
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x30(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rdi
leaq 0x83d95(%rip), %rsi     # 0xf5d40
xorl %eax, %eax
movl %eax, %edx
callq 0xdaf50
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x7201d
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x3, %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x40a0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x30(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq $0x0, 0x18(%rax)
jge 0x7201b
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq $0x0, 0x18(%rax)
jmp 0x7201d
jmp 0x7201f
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rsi
leaq -0x48(%rbp), %rdx
callq 0x7bd70
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x48(%rbp)
jg 0x72055
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x720a0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rax), %rax
movl -0x44(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x71dee
movl -0x30(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x18(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)