// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/header.c
// Function: sam_hrecs_vadd
static int sam_hrecs_vadd(sam_hrecs_t *hrecs, const char *type, va_list ap, ...) {
    va_list args;
    sam_hrec_type_t *h_type;
    sam_hrec_tag_t *h_tag, *last=NULL;
    int new;
    khint32_t type_i = TYPEKEY(type), k;

    if (!strncmp(type, "HD", 2) && (h_type = sam_hrecs_find_type_id(hrecs, "HD", NULL, NULL)))
        return sam_hrecs_vupdate(hrecs, h_type, ap);

    if (!(h_type = pool_alloc(hrecs->type_pool)))
        return -1;
    k = kh_put(sam_hrecs_t, hrecs->h, type_i, &new);
    if (new < 0)
        return -1;

    h_type->type = type_i;

    // Form the ring, either with self or other lines of this type
    if (!new) {
        sam_hrec_type_t *t = kh_val(hrecs->h, k), *p;
        p = t->prev;

        assert(p->next == t);
        p->next = h_type;
        h_type->prev = p;

        t->prev = h_type;
        h_type->next = t;
    } else {
        kh_val(hrecs->h, k) = h_type;
        h_type->prev = h_type->next = h_type;
    }
    h_type->tag = NULL;

    // Add to global line ordering after any existing line of the same type,
    // or at the end if no line of this type exists yet.
    sam_hrecs_global_list_add(hrecs, h_type, !new ? h_type->prev : NULL);

    // Check linked-list invariants
    assert(h_type->prev->next == h_type);
    assert(h_type->next->prev == h_type);
    assert(h_type->global_prev->global_next == h_type);
    assert(h_type->global_next->global_prev == h_type);

    // Any ... varargs
    va_start(args, ap);
    for (;;) {
        char *key, *val = NULL, *str;

        if (!(key = (char *)va_arg(args, char *)))
            break;
        if (strncmp(type, "CO", 2) && !(val = (char *)va_arg(args, char *)))
            break;
        if (*val == '\0')
            continue;

        if (!(h_tag = pool_alloc(hrecs->tag_pool)))
            return -1;

        if (strncmp(type, "CO", 2)) {
            h_tag->len = 3 + strlen(val);
            str = string_alloc(hrecs->str_pool, h_tag->len+1);
            if (!str || snprintf(str, h_tag->len+1, "%2.2s:%s", key, val) < 0)
                return -1;
            h_tag->str = str;
        } else {
            h_tag->len = strlen(key);
            h_tag->str = string_ndup(hrecs->str_pool, key, h_tag->len);
            if (!h_tag->str)
                return -1;
        }

        h_tag->next = NULL;
        if (last)
            last->next = h_tag;
        else
            h_type->tag = h_tag;

        last = h_tag;
    }
    va_end(args);

    // Plus the specified va_list params
    for (;;) {
        char *key, *val = NULL, *str;

        if (!(key = (char *)va_arg(ap, char *)))
            break;
        if (strncmp(type, "CO", 2) && !(val = (char *)va_arg(ap, char *)))
            break;

        if (!(h_tag = pool_alloc(hrecs->tag_pool)))
            return -1;

        if (strncmp(type, "CO", 2)) {
            h_tag->len = 3 + strlen(val);
            str = string_alloc(hrecs->str_pool, h_tag->len+1);
            if (!str || snprintf(str, h_tag->len+1, "%2.2s:%s", key, val) < 0)
                return -1;
            h_tag->str = str;
        } else {
            h_tag->len = strlen(key);
            h_tag->str = string_ndup(hrecs->str_pool, key, h_tag->len);
            if (!h_tag->str)
                return -1;
        }

        h_tag->next = NULL;
        if (last)
            last->next = h_tag;
        else
            h_type->tag = h_tag;

        last = h_tag;
    }

    if (-1 == sam_hrecs_update_hashes(hrecs, TYPEKEY(type), h_type))
        return -1;

    if (!strncmp(type, "PG", 2))
        hrecs->pgs_changed = 1;

    hrecs->dirty = 1;

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdx, %r12
movq %rdi, %r15
movq %rcx, 0x68(%rsp)
movq %r8, 0x70(%rsp)
movq %r9, 0x78(%rsp)
testb %al, %al
je 0x855bf
movaps %xmm0, 0x80(%rsp)
movaps %xmm1, 0x90(%rsp)
movaps %xmm2, 0xa0(%rsp)
movaps %xmm3, 0xb0(%rsp)
movaps %xmm4, 0xc0(%rsp)
movaps %xmm5, 0xd0(%rsp)
movaps %xmm6, 0xe0(%rsp)
movaps %xmm7, 0xf0(%rsp)
movzbl (%rsi), %ebp
movq %rsi, 0x8(%rsp)
movb 0x1(%rsi), %bl
movl %ebp, %eax
xorb $0x48, %al
movl %ebx, %ecx
xorb $0x44, %cl
orb %al, %cl
jne 0x8560e
leaq 0x12393(%rip), %rsi     # 0x97971
movq %r15, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x85b55
testq %rax, %rax
je 0x8560e
movq %r15, %rdi
movq %rax, %rsi
movq %r12, %rdx
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8708d
movq 0x18(%r15), %rdi
callq 0x57daa
movq %rax, %rcx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %rcx, %rcx
je 0x85a1f
movq %rcx, 0x10(%rsp)
movzbl %bl, %eax
shll $0x8, %ebp
orl %eax, %ebp
movq (%r15), %rdi
leaq 0x4c(%rsp), %rbx
movl %ebp, %esi
movq %rbx, %rdx
callq 0x8a426
cmpl $0x0, (%rbx)
js 0x85a1a
movq 0x10(%rsp), %rdx
movl %ebp, 0x28(%rdx)
movq (%r15), %rcx
movq 0x20(%rcx), %rcx
movl %eax, %eax
movq %r15, %rbx
je 0x85686
movq %rdx, (%rcx,%rax,8)
movq %rdx, (%rdx)
movq %rdx, 0x8(%rdx)
leaq 0x20(%rdx), %rax
movq %rax, 0x18(%rsp)
movq $0x0, 0x20(%rdx)
xorl %edx, %edx
jmp 0x856ba
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rcx
cmpq %rax, (%rcx)
jne 0x85aad
movq %rdx, (%rcx)
movq %rcx, 0x8(%rdx)
movq %rdx, 0x8(%rax)
movq %rax, (%rdx)
leaq 0x20(%rdx), %rax
movq %rax, 0x18(%rsp)
movq $0x0, 0x20(%rdx)
movq 0x8(%rdx), %rdx
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x8a594
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rax
cmpq %rcx, (%rax)
jne 0x85a31
movq (%rcx), %rax
cmpq %rcx, 0x8(%rax)
movq 0x8(%rsp), %r8
jne 0x85a50
movq 0x18(%rcx), %rax
cmpq %rcx, 0x10(%rax)
jne 0x85a6f
movq 0x10(%rcx), %rax
cmpq %rcx, 0x18(%rax)
jne 0x85a8e
movq %r12, 0x40(%rsp)
leaq 0x50(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x140(%rsp), %rax
movq %rax, 0x28(%rsp)
movabsq $0x3000000018, %rax     # imm = 0x3000000018
movq %rax, 0x20(%rsp)
xorl %r15d, %r15d
movq 0x30(%rsp), %rax
movl 0x20(%rsp), %ecx
movq 0x28(%rsp), %rsi
cmpl $0x28, %ecx
ja 0x85759
movq %rsi, %rdx
movl %ecx, %esi
addq %rax, %rsi
addl $0x8, %ecx
movl %ecx, 0x20(%rsp)
jmp 0x85762
leaq 0x8(%rsi), %rdx
movq %rdx, 0x28(%rsp)
movq (%rsi), %r13
testq %r13, %r13
je 0x8599d
cmpb $0x43, (%r8)
jne 0x85780
cmpb $0x4f, 0x1(%r8)
jne 0x85780
xorl %r12d, %r12d
jmp 0x857ae
cmpl $0x28, %ecx
ja 0x85796
movq %rdx, %rsi
movl %ecx, %edx
addq %rax, %rdx
addl $0x8, %ecx
movl %ecx, 0x20(%rsp)
jmp 0x8579f
leaq 0x8(%rdx), %rsi
movq %rsi, 0x28(%rsp)
movq (%rdx), %r12
movq %rsi, %rdx
testq %r12, %r12
je 0x8599d
cmpb $0x0, (%r12)
movq %rdx, %rsi
je 0x85743
movq 0x20(%rbx), %rdi
callq 0x57daa
testq %rax, %rax
je 0x85a1a
movq %rax, %r14
movq 0x8(%rsp), %rax
cmpb $0x43, (%rax)
jne 0x85806
cmpb $0x4f, 0x1(%rax)
jne 0x85806
movq %r13, %rdi
callq 0x41d0
movl %eax, 0x10(%r14)
movq 0x10(%rbx), %rdi
movslq %eax, %rdx
movq %r13, %rsi
callq 0x5801b
movq %rax, 0x8(%r14)
testq %rax, %rax
jne 0x8586a
jmp 0x85a1a
movq %r12, %rdi
callq 0x41d0
leal 0x3(%rax), %ecx
movl %ecx, 0x10(%r14)
movq 0x10(%rbx), %rdi
shlq $0x20, %rax
movabsq $0x400000000, %rcx      # imm = 0x400000000
leaq (%rax,%rcx), %rsi
sarq $0x20, %rsi
callq 0x57f0c
testq %rax, %rax
je 0x85a1a
movq %rax, %rbp
movslq 0x10(%r14), %rsi
incq %rsi
movq %rax, %rdi
leaq 0x1cbff(%rip), %rdx     # 0xa2450
movq %r13, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x4800
testl %eax, %eax
js 0x85a1a
movq %rbp, 0x8(%r14)
movq $0x0, (%r14)
testq %r15, %r15
cmoveq 0x18(%rsp), %r15
movq %r14, (%r15)
movq %r14, %r15
movq 0x8(%rsp), %r8
jmp 0x85735
cmpb $0x43, (%r8)
jne 0x8589c
cmpb $0x4f, 0x1(%r8)
jne 0x8589c
xorl %r12d, %r12d
jmp 0x858c6
cmpl $0x28, %eax
ja 0x858ae
movl %eax, %ecx
addq 0x10(%rsi), %rcx
addl $0x8, %eax
movl %eax, (%rsi)
jmp 0x858ba
movq 0x8(%rsi), %rcx
leaq 0x8(%rcx), %rax
movq %rax, 0x8(%rsi)
movq (%rcx), %r12
testq %r12, %r12
je 0x859d0
movq 0x20(%rbx), %rdi
callq 0x57daa
testq %rax, %rax
je 0x85a1a
movq %rax, %r13
movq %r15, %r14
movq 0x8(%rsp), %rax
cmpb $0x43, (%rax)
jne 0x85917
cmpb $0x4f, 0x1(%rax)
jne 0x85917
movq %rbp, %rdi
callq 0x41d0
movl %eax, 0x10(%r13)
movq 0x10(%rbx), %rdi
movslq %eax, %rdx
movq %rbp, %rsi
callq 0x5801b
movq %rax, 0x8(%r13)
testq %rax, %rax
jne 0x85981
jmp 0x85a1a
movq %r12, %rdi
callq 0x41d0
leal 0x3(%rax), %ecx
movl %ecx, 0x10(%r13)
movq %rbx, %r15
movq 0x10(%rbx), %rdi
shlq $0x20, %rax
movabsq $0x400000000, %rcx      # imm = 0x400000000
leaq (%rax,%rcx), %rsi
sarq $0x20, %rsi
callq 0x57f0c
testq %rax, %rax
je 0x85a1a
movq %rax, %rbx
movslq 0x10(%r13), %rsi
incq %rsi
movq %rax, %rdi
leaq 0x1caeb(%rip), %rdx     # 0xa2450
movq %rbp, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x4800
testl %eax, %eax
js 0x85a1a
movq %rbx, 0x8(%r13)
movq %r15, %rbx
movq $0x0, (%r13)
testq %r14, %r14
cmoveq 0x18(%rsp), %r14
movq %r13, (%r14)
movq %r13, %r15
movq 0x8(%rsp), %r8
movq 0x40(%rsp), %rsi
movl (%rsi), %eax
cmpq $0x28, %rax
ja 0x859b8
movq %rax, %rcx
addq 0x10(%rsi), %rcx
addl $0x8, %eax
movl %eax, (%rsi)
jmp 0x859c4
movq 0x8(%rsi), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsi)
movq (%rcx), %rbp
testq %rbp, %rbp
jne 0x8588a
movzwl (%r8), %eax
rolw $0x8, %ax
movzwl %ax, %esi
movq %rbx, %rdi
movq 0x10(%rsp), %rdx
movq %r8, %r14
callq 0x8753f
cmpl $-0x1, %eax
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
je 0x85a1f
cmpb $0x50, (%r14)
jne 0x85a0c
cmpb $0x47, 0x1(%r14)
jne 0x85a0c
movl $0x1, 0x98(%rbx)
movl $0x1, 0x90(%rbx)
xorl %eax, %eax
jmp 0x85a1f
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c988(%rip), %rdi     # 0xa23c0
leaq 0x1c42c(%rip), %rsi     # 0xa1e6b
leaq 0x1c92d(%rip), %rcx     # 0xa2373
movl $0x24d, %edx            # imm = 0x24D
callq 0x42f0
leaq 0x1c986(%rip), %rdi     # 0xa23dd
leaq 0x1c40d(%rip), %rsi     # 0xa1e6b
leaq 0x1c90e(%rip), %rcx     # 0xa2373
movl $0x24e, %edx            # imm = 0x24E
callq 0x42f0
leaq 0x1c984(%rip), %rdi     # 0xa23fa
leaq 0x1c3ee(%rip), %rsi     # 0xa1e6b
leaq 0x1c8ef(%rip), %rcx     # 0xa2373
movl $0x24f, %edx            # imm = 0x24F
callq 0x42f0
leaq 0x1c990(%rip), %rdi     # 0xa2425
leaq 0x1c3cf(%rip), %rsi     # 0xa1e6b
leaq 0x1c8d0(%rip), %rcx     # 0xa2373
movl $0x250, %edx            # imm = 0x250
callq 0x42f0
leaq 0x1c78b(%rip), %rdi     # 0xa223f
leaq 0x1c3b0(%rip), %rsi     # 0xa1e6b
leaq 0x1c8b1(%rip), %rcx     # 0xa2373
movl $0x23c, %edx            # imm = 0x23C
callq 0x42f0