// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/header.c
// Function: sam_hdr_update_line
int sam_hdr_update_line(sam_hdr_t *bh, const char *type,
        const char *ID_key, const char *ID_value, ...) {
    sam_hrecs_t *hrecs;
    if (!bh)
        return -1;

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

    int ret, rename;
    sam_hrec_type_t *ty = sam_hrecs_find_type_id(hrecs, type, ID_key, ID_value);
    if (!ty)
        return -1;

    va_list args;
    const char *old_name = "?", *new_name = "?";
    char id_tag[3];
    khash_t(m_s2i) *hash = NULL;
    va_start(args, ID_value);
    rename = check_for_name_update(hrecs, ty, args,
                                   &old_name, &new_name, id_tag, &hash);
    va_end(args);
    if (rename < 0) {
        hts_log_error("Cannot rename @%s \"%s\" to \"%s\" : already exists",
                      type, old_name, new_name);
        return -1;
    }
    if (rename > 0 && TYPEKEY(type) == TYPEKEY("PG")) {
        // This is just too complicated
        hts_log_error("Renaming @PG records is not supported");
        return -1;
    }
    va_start(args, ID_value);
    ret = sam_hrecs_vupdate(hrecs, ty, args);
    va_end(args);

    if (ret)
        return ret;

    // TODO Account for @SQ-AN altnames

    if (rename) {
        // Adjust the hash table to point to the new name
        // sam_hrecs_update_hashes() should sort out everything else
        khint_t k = kh_get(m_s2i, hash, old_name);
        sam_hrec_tag_t *new_tag = sam_hrecs_find_key(ty, id_tag, NULL);
        int r, pos;
        assert(k < kh_end(hash));        // Or we wouldn't have found it earlier
        assert(new_tag && new_tag->str); // id_tag should exist
        assert(new_tag->len > 3);
        pos = kh_val(hash, k);
        kh_del(m_s2i, hash, k);
        k = kh_put(m_s2i, hash, new_tag->str + 3, &r);
        if (r < 1) {
            hts_log_error("Failed to rename item in hash table");
            return -1;
        }
        kh_val(hash, k) = pos;
    }

    ret = sam_hrecs_update_hashes(hrecs, TYPEKEY(type), ty);

    if (!ret && hrecs->refs_changed >= 0)
        ret = rebuild_target_arrays(bh);

    if (!ret && hrecs->dirty)
        redact_header_text(bh);

    return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %r8, 0xa0(%rsp)
movq %r9, 0xa8(%rsp)
testb %al, %al
je 0x6b265
movaps %xmm0, 0xb0(%rsp)
movaps %xmm1, 0xc0(%rsp)
movaps %xmm2, 0xd0(%rsp)
movaps %xmm3, 0xe0(%rsp)
movaps %xmm4, 0xf0(%rsp)
movaps %xmm5, 0x100(%rsp)
movaps %xmm6, 0x110(%rsp)
movaps %xmm7, 0x120(%rsp)
pushq $-0x1
popq %r13
testq %rdi, %rdi
je 0x6b63f
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r14
movq 0x38(%rdi), %rbp
testq %rbp, %rbp
je 0x6b2f9
movq %rbp, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x6a8fd
testq %rax, %rax
je 0x6b63f
movq %rax, %r15
movabsq $0x3000000020, %rcx     # imm = 0x3000000020
movq %rcx, 0x40(%rsp)
leaq 0x170(%rsp), %rsi
movq %rsi, 0x48(%rsp)
leaq 0x80(%rsp), %rdi
movq %rdi, 0x50(%rsp)
movl 0x28(%rax), %eax
leaq 0xed7f(%rip), %r13      # 0x7a056
cmpl $0x5047, %eax           # imm = 0x5047
movq %rbx, 0x30(%rsp)
je 0x6b31d
cmpl $0x5351, %eax           # imm = 0x5351
je 0x6b312
cmpl $0x5247, %eax           # imm = 0x5247
jne 0x6b4f2
pushq $0x50
jmp 0x6b31f
movq %r14, %rdi
callq 0x6933d
testl %eax, %eax
jne 0x6b63f
movq 0x38(%r14), %rbp
jmp 0x6b287
leaq 0x1005c(%rip), %r13     # 0x7b375
pushq $0x38
jmp 0x6b31f
pushq $0x70
popq %rax
movq (%rbp,%rax), %r12
movb 0x2(%r13), %al
movb %al, 0xe(%rsp)
movzwl (%r13), %eax
movw %ax, 0xc(%rsp)
leaq 0x78(%rsp), %rdx
movq %r15, %rdi
movq %r13, %rsi
callq 0x6b93e
testq %rax, %rax
je 0x6b4d6
movq %r12, 0x20(%rsp)
movq %rbp, 0x18(%rsp)
movq %r14, 0x68(%rsp)
cmpl $0x2, 0x10(%rax)
jle 0x6b6af
movq %rax, 0x70(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x50(%rsp), %rbp
movl 0x40(%rsp), %r12d
xorl %ecx, %ecx
leaq 0xebd0(%rip), %rax      # 0x79f5a
movq %rax, 0x60(%rsp)
movq 0x48(%rsp), %rbx
movq %r15, 0x28(%rsp)
movl %ecx, 0x3c(%rsp)
movq %rbx, %r15
cmpl $0x28, %r12d
ja 0x6b3ba
movq %r15, %r14
movl %r12d, %r15d
addq %rbp, %r15
addl $0x8, %r12d
movl %r12d, 0x40(%rsp)
jmp 0x6b3c6
leaq 0x8(%r15), %rbx
movq %rbx, 0x48(%rsp)
movq %rbx, %r14
movq (%r15), %rdi
testq %rdi, %rdi
je 0x6b45b
cmpl $0x28, %r12d
ja 0x6b3ec
movq %r14, %r15
movl %r12d, %r14d
addq %rbp, %r14
addl $0x8, %r12d
movl %r12d, 0x40(%rsp)
jmp 0x6b3f8
leaq 0x8(%r14), %rbx
movq %rbx, 0x48(%rsp)
movq %rbx, %r15
movq %r13, %rsi
callq 0x46c0
testl %eax, %eax
jne 0x6b3a0
movq (%r14), %r15
testq %r15, %r15
leaq 0xc945(%rip), %rax      # 0x77d56
cmoveq %rax, %r15
movq 0x70(%rsp), %rax
movq 0x8(%rax), %rsi
addq $0x3, %rsi
movq %r15, %rdi
callq 0x46c0
xorl %ecx, %ecx
testl %eax, %eax
je 0x6b399
movq 0x20(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x6b87d
cmpl (%r14), %eax
movl $0x0, %ecx
sbbl %ecx, %ecx
orl $0x1, %ecx
movq %r15, 0x60(%rsp)
jmp 0x6b399
movq 0x10(%rsp), %r8
addq $0x3, %r8
cmpl $0x0, 0x3c(%rsp)
movq 0x28(%rsp), %r15
js 0x6b619
movq 0x30(%rsp), %rax
je 0x6b654
movzwl (%rax), %eax
rolw $0x8, %ax
cmpw $0x5047, %ax            # imm = 0x5047
movq 0x68(%rsp), %r14
movq 0x18(%rsp), %rbp
movq 0x20(%rsp), %r12
movabsq $0x3000000020, %rcx     # imm = 0x3000000020
leaq 0x170(%rsp), %rsi
leaq 0x80(%rsp), %rdi
jne 0x6b689
leaq 0x18220(%rip), %rsi     # 0x836e0
leaq 0x1825d(%rip), %rdx     # 0x83724
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
jmp 0x6b63b
movabsq $0x3000000020, %rcx     # imm = 0x3000000020
leaq 0x170(%rsp), %rsi
leaq 0x80(%rsp), %rdi
jmp 0x6b4f5
xorl %r12d, %r12d
leaq 0xea5e(%rip), %rax      # 0x79f5a
movq %rax, 0x10(%rsp)
movb $0x1, %bl
leaq 0x40(%rsp), %rdx
movq %rdi, 0x10(%rdx)
movq %rsi, 0x8(%rdx)
movq %rcx, (%rdx)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x6b72b
pushq $-0x1
popq %r13
testl %eax, %eax
jne 0x6b63f
testb %bl, %bl
jne 0x6b5d0
movq %rbp, 0x18(%rsp)
movq %r12, %rdi
movq 0x10(%rsp), %rsi
callq 0x6b87d
movl %eax, %ebp
leaq 0xc(%rsp), %rsi
movq %r15, 0x28(%rsp)
movq %r15, %rdi
xorl %edx, %edx
callq 0x6b93e
cmpl (%r12), %ebp
jae 0x6b6ed
movq %rax, %r15
testq %rax, %rax
je 0x6b6ce
cmpq $0x0, 0x8(%r15)
je 0x6b6ce
cmpl $0x3, 0x10(%r15)
jle 0x6b70c
movq 0x20(%r12), %rax
movl %ebp, %ecx
movl (%rax,%rcx,4), %ebx
movq %r12, %rdi
movl %ebp, %esi
callq 0x6b983
movq 0x8(%r15), %rsi
addq $0x3, %rsi
leaq 0x78(%rsp), %r15
movq %r12, %rdi
movq %r15, %rdx
callq 0x6b9b4
cmpl $0x0, (%r15)
jle 0x6b695
movq 0x20(%r12), %rcx
movl %eax, %eax
movl %ebx, (%rcx,%rax,4)
movq 0x18(%rsp), %rbp
movq 0x28(%rsp), %r15
movq 0x30(%rsp), %rax
movzwl (%rax), %eax
rolw $0x8, %ax
movzwl %ax, %esi
movq %rbp, %rdi
movq %r15, %rdx
callq 0x6bb9a
testl %eax, %eax
jne 0x6b63f
cmpl $0x0, 0x94(%rbp)
js 0x6b603
movq %r14, %rdi
callq 0x69c81
testl %eax, %eax
jne 0x6b63f
xorl %r13d, %r13d
cmpl $0x0, 0x90(%rbp)
je 0x6b63f
movq %r14, %rdi
callq 0x6a1b4
jmp 0x6b63f
leaq 0x180c0(%rip), %rsi     # 0x836e0
leaq 0x180cd(%rip), %rdx     # 0x836f4
pushq $0x1
popq %rdi
movq 0x30(%rsp), %rcx
movq 0x60(%rsp), %r9
xorl %eax, %eax
callq 0x110c6
pushq $-0x1
popq %r13
movl %r13d, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r8, 0x10(%rsp)
movb $0x1, %bl
movq 0x68(%rsp), %r14
movq 0x18(%rsp), %rbp
movq 0x20(%rsp), %r12
movabsq $0x3000000020, %rcx     # imm = 0x3000000020
leaq 0x170(%rsp), %rsi
leaq 0x80(%rsp), %rdi
jmp 0x6b503
movq %r8, 0x10(%rsp)
xorl %ebx, %ebx
jmp 0x6b503
leaq 0x18044(%rip), %rsi     # 0x836e0
leaq 0x1813e(%rip), %rdx     # 0x837e1
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
jmp 0x6b63f
leaq 0x188af(%rip), %rdi     # 0x83f65
leaq 0x1809e(%rip), %rsi     # 0x8375b
leaq 0x186d2(%rip), %rcx     # 0x83d96
movl $0x5fd, %edx            # imm = 0x5FD
callq 0x42f0
leaq 0x180e3(%rip), %rdi     # 0x837b8
leaq 0x1807f(%rip), %rsi     # 0x8375b
leaq 0x18081(%rip), %rcx     # 0x83764
movl $0x63f, %edx            # imm = 0x63F
callq 0x42f0
leaq 0x18056(%rip), %rdi     # 0x8374a
leaq 0x18060(%rip), %rsi     # 0x8375b
leaq 0x18062(%rip), %rcx     # 0x83764
movl $0x63e, %edx            # imm = 0x63E
callq 0x42f0
leaq 0x180bd(%rip), %rdi     # 0x837d0
leaq 0x18041(%rip), %rsi     # 0x8375b
leaq 0x18043(%rip), %rcx     # 0x83764
movl $0x640, %edx            # imm = 0x640
callq 0x42f0