// File: /workspace/github_c_makefile_star2_O2/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 0x6a380
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 0x6a3cf
leaq 0xf527(%rip), %rsi      # 0x798c6
movq %r15, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x6a8fd
testq %rax, %rax
je 0x6a3cf
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 0x6b72b
movq 0x18(%r15), %rdi
callq 0x49174
movq %rax, %rcx
pushq $-0x1
popq %rax
testq %rcx, %rcx
je 0x6a7ce
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 0x6d916
cmpl $0x0, (%rbx)
js 0x6a7cb
movq 0x10(%rsp), %rdx
movl %ebp, 0x28(%rdx)
movq (%r15), %rcx
movq 0x20(%rcx), %rcx
movl %eax, %eax
movq %r15, %rbx
je 0x6a442
movq %rdx, (%rcx,%rax,8)
movq %rdx, (%rdx)
movq %rdx, 0x8(%rdx)
leaq 0x20(%rdx), %rax
movq %rax, 0x18(%rsp)
andq $0x0, 0x20(%rdx)
xorl %edx, %edx
jmp 0x6a473
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rcx
cmpq %rax, (%rcx)
jne 0x6a85c
movq %rdx, (%rcx)
movq %rcx, 0x8(%rdx)
movq %rdx, 0x8(%rax)
movq %rax, (%rdx)
leaq 0x20(%rdx), %rax
movq %rax, 0x18(%rsp)
andq $0x0, 0x20(%rdx)
movq 0x8(%rdx), %rdx
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x6da78
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rax
cmpq %rcx, (%rax)
jne 0x6a7e0
movq (%rcx), %rax
cmpq %rcx, 0x8(%rax)
movq 0x8(%rsp), %r8
jne 0x6a7ff
movq 0x18(%rcx), %rax
cmpq %rcx, 0x10(%rax)
jne 0x6a81e
movq 0x10(%rcx), %rax
cmpq %rcx, 0x18(%rax)
jne 0x6a83d
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 0x6a512
movq %rsi, %rdx
movl %ecx, %esi
addq %rax, %rsi
addl $0x8, %ecx
movl %ecx, 0x20(%rsp)
jmp 0x6a51b
leaq 0x8(%rsi), %rdx
movq %rdx, 0x28(%rsp)
movq (%rsi), %r13
testq %r13, %r13
je 0x6a750
cmpb $0x43, (%r8)
jne 0x6a539
cmpb $0x4f, 0x1(%r8)
jne 0x6a539
xorl %r12d, %r12d
jmp 0x6a567
cmpl $0x28, %ecx
ja 0x6a54f
movq %rdx, %rsi
movl %ecx, %edx
addq %rax, %rdx
addl $0x8, %ecx
movl %ecx, 0x20(%rsp)
jmp 0x6a558
leaq 0x8(%rdx), %rsi
movq %rsi, 0x28(%rsp)
movq (%rdx), %r12
movq %rsi, %rdx
testq %r12, %r12
je 0x6a750
cmpb $0x0, (%r12)
movq %rdx, %rsi
je 0x6a4fc
movq 0x20(%rbx), %rdi
callq 0x49174
testq %rax, %rax
je 0x6a7cb
movq %rax, %r14
movq 0x8(%rsp), %rax
cmpb $0x43, (%rax)
jne 0x6a5bf
cmpb $0x4f, 0x1(%rax)
jne 0x6a5bf
movq %r13, %rdi
callq 0x41d0
movl %eax, 0x10(%r14)
movq 0x10(%rbx), %rdi
movslq %eax, %rdx
movq %r13, %rsi
callq 0x493ba
movq %rax, 0x8(%r14)
testq %rax, %rax
jne 0x6a623
jmp 0x6a7cb
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 0x492ca
testq %rax, %rax
je 0x6a7cb
movq %rax, %rbp
movslq 0x10(%r14), %rsi
incq %rsi
movq %rax, %rdi
leaq 0x19736(%rip), %rdx     # 0x83d40
movq %r13, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x4800
testl %eax, %eax
js 0x6a7cb
movq %rbp, 0x8(%r14)
andq $0x0, (%r14)
testq %r15, %r15
cmoveq 0x18(%rsp), %r15
movq %r14, (%r15)
movq %r14, %r15
movq 0x8(%rsp), %r8
jmp 0x6a4ee
cmpb $0x43, (%r8)
jne 0x6a652
cmpb $0x4f, 0x1(%r8)
jne 0x6a652
xorl %r12d, %r12d
jmp 0x6a67c
cmpl $0x28, %eax
ja 0x6a664
movl %eax, %ecx
addq 0x10(%rsi), %rcx
addl $0x8, %eax
movl %eax, (%rsi)
jmp 0x6a670
movq 0x8(%rsi), %rcx
leaq 0x8(%rcx), %rax
movq %rax, 0x8(%rsi)
movq (%rcx), %r12
testq %r12, %r12
je 0x6a783
movq 0x20(%rbx), %rdi
callq 0x49174
testq %rax, %rax
je 0x6a7cb
movq %rax, %r13
movq %r15, %r14
movq 0x8(%rsp), %rax
cmpb $0x43, (%rax)
jne 0x6a6cd
cmpb $0x4f, 0x1(%rax)
jne 0x6a6cd
movq %rbp, %rdi
callq 0x41d0
movl %eax, 0x10(%r13)
movq 0x10(%rbx), %rdi
movslq %eax, %rdx
movq %rbp, %rsi
callq 0x493ba
movq %rax, 0x8(%r13)
testq %rax, %rax
jne 0x6a737
jmp 0x6a7cb
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 0x492ca
testq %rax, %rax
je 0x6a7cb
movq %rax, %rbx
movslq 0x10(%r13), %rsi
incq %rsi
movq %rax, %rdi
leaq 0x19625(%rip), %rdx     # 0x83d40
movq %rbp, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x4800
testl %eax, %eax
js 0x6a7cb
movq %rbx, 0x8(%r13)
movq %r15, %rbx
andq $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 0x6a76b
movq %rax, %rcx
addq 0x10(%rsi), %rcx
addl $0x8, %eax
movl %eax, (%rsi)
jmp 0x6a777
movq 0x8(%rsi), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsi)
movq (%rcx), %rbp
testq %rbp, %rbp
jne 0x6a640
movzwl (%r8), %eax
rolw $0x8, %ax
movzwl %ax, %esi
movq %rbx, %rdi
movq 0x10(%rsp), %rdx
movq %r8, %r14
callq 0x6bb9a
cmpl $-0x1, %eax
pushq $-0x1
popq %rax
je 0x6a7ce
cmpb $0x50, (%r14)
jne 0x6a7bd
cmpb $0x47, 0x1(%r14)
jne 0x6a7bd
movl $0x1, 0x98(%rbx)
movl $0x1, 0x90(%rbx)
xorl %eax, %eax
jmp 0x6a7ce
pushq $-0x1
popq %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x194c9(%rip), %rdi     # 0x83cb0
leaq 0x18f6d(%rip), %rsi     # 0x8375b
leaq 0x1946e(%rip), %rcx     # 0x83c63
movl $0x24d, %edx            # imm = 0x24D
callq 0x42f0
leaq 0x194c7(%rip), %rdi     # 0x83ccd
leaq 0x18f4e(%rip), %rsi     # 0x8375b
leaq 0x1944f(%rip), %rcx     # 0x83c63
movl $0x24e, %edx            # imm = 0x24E
callq 0x42f0
leaq 0x194c5(%rip), %rdi     # 0x83cea
leaq 0x18f2f(%rip), %rsi     # 0x8375b
leaq 0x19430(%rip), %rcx     # 0x83c63
movl $0x24f, %edx            # imm = 0x24F
callq 0x42f0
leaq 0x194d1(%rip), %rdi     # 0x83d15
leaq 0x18f10(%rip), %rsi     # 0x8375b
leaq 0x19411(%rip), %rcx     # 0x83c63
movl $0x250, %edx            # imm = 0x250
callq 0x42f0
leaq 0x192cc(%rip), %rdi     # 0x83b2f
leaq 0x18ef1(%rip), %rsi     # 0x8375b
leaq 0x193f2(%rip), %rcx     # 0x83c63
movl $0x23c, %edx            # imm = 0x23C
callq 0x42f0