// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/htslib/cram/sam_header.c
// Function: sam_hdr_vadd
int sam_hdr_vadd(SAM_hdr *sh, const char *type, va_list ap, ...) {
    va_list args;
    SAM_hdr_type *h_type;
    SAM_hdr_tag *h_tag, *last;
    int new;
    khint32_t type_i = (type[0]<<8) | type[1], k;

    if (EOF == kputc_('@', &sh->text))
	return -1;
    if (EOF == kputsn(type, 2, &sh->text))
	return -1;

    if (!(h_type = pool_alloc(sh->type_pool)))
	return -1;
    if (-1 == (k = kh_put(sam_hdr, sh->h, type_i, &new)))
	return -1;

    // Form the ring, either with self or other lines of this type
    if (!new) {
	SAM_hdr_type *t = kh_val(sh->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;
	h_type->order = p->order + 1;
    } else {
	kh_val(sh->h, k) = h_type;
	h_type->prev = h_type->next = h_type;
	h_type->order = 0;
    }

    last = NULL;

    // Any ... varargs
    va_start(args, ap);
    for (;;) {
	char *k, *v;
	int idx;
	
	if (!(k = (char *)va_arg(args, char *)))
	    break;
	v = va_arg(args, char *);

	if (EOF == kputc_('\t', &sh->text))
	    return -1;

	if (!(h_tag = pool_alloc(sh->tag_pool)))
	    return -1;
	idx = ks_len(&sh->text);
	
	if (EOF == kputs(k, &sh->text))
	    return -1;
	if (EOF == kputc_(':', &sh->text))
	    return -1;
	if (EOF == kputs(v, &sh->text))
	    return -1;

	h_tag->len = ks_len(&sh->text) - idx;
	h_tag->str = string_ndup(sh->str_pool,
				 ks_str(&sh->text) + idx,
				 h_tag->len);
	h_tag->next = NULL;
	if (!h_tag->str)
	    return -1;

	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 *k, *v;
	int idx;
	
	if (!(k = (char *)va_arg(ap, char *)))
	    break;
	v = va_arg(ap, char *);

	if (EOF == kputc_('\t', &sh->text))
	    return -1;

	if (!(h_tag = pool_alloc(sh->tag_pool)))
	    return -1;
	idx = ks_len(&sh->text);
	
	if (EOF == kputs(k, &sh->text))
	    return -1;
	if (EOF == kputc_(':', &sh->text))
	    return -1;
	if (EOF == kputs(v, &sh->text))
	    return -1;

	h_tag->len = ks_len(&sh->text) - idx;
	h_tag->str = string_ndup(sh->str_pool,
				 ks_str(&sh->text) + idx,
				 h_tag->len);
	h_tag->next = NULL;
	if (!h_tag->str)
	    return -1;

	if (last)
	    last->next = h_tag;
	else
	    h_type->tag = h_tag;
	
	last = h_tag;
    }
    va_end(ap);

    if (EOF == kputc('\n', &sh->text))
	return -1;

    int itype = (type[0]<<8) | type[1];
    if (-1 == sam_hdr_update_hashes(sh, itype, h_type))
	return -1;

    return h_type->order;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdx, 0x30(%rsp)
movq %rsi, %r13
movq %rdi, %rbx
movq %rcx, 0x78(%rsp)
movq %r8, 0x80(%rsp)
movq %r9, 0x88(%rsp)
testb %al, %al
je 0x3dfae
movaps %xmm0, 0x90(%rsp)
movaps %xmm1, 0xa0(%rsp)
movaps %xmm2, 0xb0(%rsp)
movaps %xmm3, 0xc0(%rsp)
movaps %xmm4, 0xd0(%rsp)
movaps %xmm5, 0xe0(%rsp)
movaps %xmm6, 0xf0(%rsp)
movaps %xmm7, 0x100(%rsp)
movsbl (%rsi), %ebp
movsbl 0x1(%rsi), %r15d
movq (%rdi), %rcx
leaq 0x1(%rcx), %rdx
cmpq %rdx, 0x8(%rdi)
jae 0x3e027
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
movq %rax, %r14
shrq $0x20, %r14
orq %rax, %r14
incq %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3e85f
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
jmp 0x3e02b
movq 0x10(%rbx), %rax
movq %rdx, (%rbx)
movb $0x40, (%rax,%rcx)
movq (%rbx), %rcx
leaq 0x4(%rcx), %rax
cmpq %rax, 0x8(%rbx)
jae 0x3e0a3
addq $0x3, %rcx
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
movq %rax, %r14
shrq $0x20, %r14
orq %rax, %r14
incq %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3e85f
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rcx
jmp 0x3e0a7
movq 0x10(%rbx), %rax
movzwl (%r13), %edx
movw %dx, (%rax,%rcx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x2(%rax), %rdx
movq %rdx, (%rbx)
movb $0x0, 0x2(%rcx,%rax)
movq 0x28(%rbx), %rdi
callq 0x4d08e
movq %rax, %rcx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %rcx, %rcx
je 0x3e864
movq %rcx, 0x28(%rsp)
shll $0x8, %ebp
orl %r15d, %ebp
movq 0x18(%rbx), %rdi
leaq 0x4c(%rsp), %rdx
movl %ebp, %esi
callq 0x3d707
cmpl $-0x1, %eax
je 0x3e85f
cmpl $0x0, 0x4c(%rsp)
movq 0x18(%rbx), %rcx
movq 0x20(%rcx), %rcx
movl %eax, %eax
je 0x3e129
movq 0x28(%rsp), %rdx
movq %rdx, (%rcx,%rax,8)
movq %rdx, %rcx
movq %rdx, (%rdx)
movq %rdx, 0x8(%rdx)
xorl %eax, %eax
jmp 0x3e155
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rcx
cmpq %rax, (%rcx)
jne 0x3e8be
movq 0x28(%rsp), %rdx
movq %rdx, (%rcx)
movq %rcx, 0x8(%rdx)
movq %rdx, 0x8(%rax)
movq %rax, (%rdx)
movl 0x18(%rcx), %eax
movq %rdx, %rcx
incl %eax
movl %eax, 0x18(%rcx)
leaq 0x60(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x150(%rsp), %rax
movq %rax, 0x18(%rsp)
movabsq $0x3000000018, %rax     # imm = 0x3000000018
movq %rax, 0x10(%rsp)
addq $0x10, %rcx
movq %rcx, 0x58(%rsp)
xorl %r12d, %r12d
movq %r13, 0x50(%rsp)
movl 0x10(%rsp), %eax
cmpq $0x28, %rax
ja 0x3e1aa
movq %rax, %rcx
addq 0x20(%rsp), %rcx
addl $0x8, %eax
movl %eax, 0x10(%rsp)
jmp 0x3e1b8
movq 0x18(%rsp), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x18(%rsp)
movq (%rcx), %r15
testq %r15, %r15
je 0x3e7c0
cmpl $0x28, %eax
ja 0x3e1d9
movl %eax, %ecx
addq 0x20(%rsp), %rcx
addl $0x8, %eax
movl %eax, 0x10(%rsp)
jmp 0x3e1e7
movq 0x18(%rsp), %rcx
leaq 0x8(%rcx), %rax
movq %rax, 0x18(%rsp)
movq (%rcx), %rax
movq %rax, 0x8(%rsp)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
cmpq %rdx, 0x8(%rbx)
jae 0x3e260
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
movq %rax, %r14
shrq $0x20, %r14
orq %rax, %r14
incq %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3e85f
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
jmp 0x3e264
movq 0x10(%rbx), %rax
movq %rdx, (%rbx)
movb $0x9, (%rax,%rcx)
movq 0x30(%rbx), %rdi
callq 0x4d08e
testq %rax, %rax
je 0x3e85f
movq %rax, %rbp
movq %r12, 0x40(%rsp)
movq (%rbx), %r14
movq %r15, %rdi
callq 0x4230
movq %r14, %rdi
movq %rax, %r12
movslq %r12d, %r14
leaq (%r14,%rdi), %rax
addq $0x2, %rax
cmpq %rax, 0x8(%rbx)
movq %rdi, 0x38(%rsp)
jae 0x3e318
leaq (%r14,%rdi), %rax
incq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
movq %rcx, %r13
shrq $0x20, %r13
orq %rcx, %r13
incq %r13
movq 0x10(%rbx), %rdi
movq %r13, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3e85f
movq %rax, 0x10(%rbx)
movq %r13, 0x8(%rbx)
movq (%rbx), %rdi
movq 0x50(%rsp), %r13
jmp 0x3e31c
movq 0x10(%rbx), %rax
addq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4420
addq (%rbx), %r14
movq %r14, (%rbx)
movq 0x10(%rbx), %rax
movb $0x0, (%rax,%r14)
cmpl $-0x1, %r12d
je 0x3e85f
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
cmpq %rdx, 0x8(%rbx)
jae 0x3e3b4
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
movq %rax, %r14
shrq $0x20, %r14
orq %rax, %r14
incq %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3e85f
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
jmp 0x3e3b8
movq 0x10(%rbx), %rax
movq %rdx, (%rbx)
movb $0x3a, (%rax,%rcx)
movq 0x8(%rsp), %rdi
callq 0x4230
movq %rax, %r15
movq (%rbx), %rdi
movslq %r15d, %r12
leaq (%r12,%rdi), %rax
addq $0x2, %rax
cmpq %rax, 0x8(%rbx)
jae 0x3e446
addq %r12, %rdi
incq %rdi
movq %rdi, %rax
shrq %rax
orq %rdi, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
movq %rax, %r14
shrq $0x20, %r14
orq %rax, %r14
incq %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3e85f
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rdi
jmp 0x3e44a
movq 0x10(%rbx), %rax
addq %rax, %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
callq 0x4420
addq (%rbx), %r12
movq %r12, (%rbx)
movq 0x10(%rbx), %rax
movb $0x0, (%rax,%r12)
cmpl $-0x1, %r15d
je 0x3e85f
movq (%rbx), %rax
movq 0x38(%rsp), %rcx
movslq %ecx, %rsi
subq %rcx, %rax
movl %eax, 0x10(%rbp)
movq 0x20(%rbx), %rdi
addq 0x10(%rbx), %rsi
movslq %eax, %rdx
callq 0x40f39
movq %rax, 0x8(%rbp)
movq $0x0, (%rbp)
testq %rax, %rax
je 0x3e85f
movq 0x40(%rsp), %rax
testq %rax, %rax
cmoveq 0x58(%rsp), %rax
movq %rbp, (%rax)
movq %rbp, %r12
jmp 0x3e18f
cmpl $0x28, %eax
ja 0x3e4d9
movl %eax, %ecx
movq 0x30(%rsp), %rdx
addq 0x10(%rdx), %rcx
addl $0x8, %eax
movl %eax, (%rdx)
jmp 0x3e4ea
movq 0x30(%rsp), %rdx
movq 0x8(%rdx), %rcx
leaq 0x8(%rcx), %rax
movq %rax, 0x8(%rdx)
movq (%rcx), %rax
movq %rax, 0x8(%rsp)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
cmpq %rdx, 0x8(%rbx)
jae 0x3e563
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
movq %rax, %r14
shrq $0x20, %r14
orq %rax, %r14
incq %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3e85f
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
jmp 0x3e567
movq 0x10(%rbx), %rax
movq %rdx, (%rbx)
movb $0x9, (%rax,%rcx)
movq 0x30(%rbx), %rdi
callq 0x4d08e
testq %rax, %rax
je 0x3e85f
movq %rax, %rbp
movq %r12, 0x40(%rsp)
movq (%rbx), %r14
movq %r15, %rdi
callq 0x4230
movq %r14, %rdi
movq %rax, %r12
movslq %r12d, %r14
leaq (%r14,%rdi), %rax
addq $0x2, %rax
cmpq %rax, 0x8(%rbx)
movq %rdi, 0x38(%rsp)
jae 0x3e61b
leaq (%r14,%rdi), %rax
incq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
movq %rcx, %r13
shrq $0x20, %r13
orq %rcx, %r13
incq %r13
movq 0x10(%rbx), %rdi
movq %r13, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3e85f
movq %rax, 0x10(%rbx)
movq %r13, 0x8(%rbx)
movq (%rbx), %rdi
movq 0x50(%rsp), %r13
jmp 0x3e61f
movq 0x10(%rbx), %rax
addq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4420
addq (%rbx), %r14
movq %r14, (%rbx)
movq 0x10(%rbx), %rax
movb $0x0, (%rax,%r14)
cmpl $-0x1, %r12d
je 0x3e85f
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
cmpq %rdx, 0x8(%rbx)
jae 0x3e6b7
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
movq %rax, %r14
shrq $0x20, %r14
orq %rax, %r14
incq %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3e85f
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
jmp 0x3e6bb
movq 0x10(%rbx), %rax
movq %rdx, (%rbx)
movb $0x3a, (%rax,%rcx)
movq 0x8(%rsp), %rdi
callq 0x4230
movq %rax, %r15
movq (%rbx), %rdi
movslq %r15d, %r12
leaq (%r12,%rdi), %rax
addq $0x2, %rax
cmpq %rax, 0x8(%rbx)
jae 0x3e749
addq %r12, %rdi
incq %rdi
movq %rdi, %rax
shrq %rax
orq %rdi, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
movq %rax, %r14
shrq $0x20, %r14
orq %rax, %r14
incq %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3e85f
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rdi
jmp 0x3e74d
movq 0x10(%rbx), %rax
addq %rax, %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
callq 0x4420
addq (%rbx), %r12
movq %r12, (%rbx)
movq 0x10(%rbx), %rax
movb $0x0, (%rax,%r12)
cmpl $-0x1, %r15d
je 0x3e85f
movq (%rbx), %rax
movq 0x38(%rsp), %rcx
movslq %ecx, %rsi
subq %rcx, %rax
movl %eax, 0x10(%rbp)
movq 0x20(%rbx), %rdi
addq 0x10(%rbx), %rsi
movslq %eax, %rdx
callq 0x40f39
movq %rax, 0x8(%rbp)
movq $0x0, (%rbp)
testq %rax, %rax
je 0x3e85f
movq 0x40(%rsp), %rax
testq %rax, %rax
cmoveq 0x58(%rsp), %rax
movq %rbp, (%rax)
movq %rbp, %r12
movq 0x30(%rsp), %rsi
movl (%rsi), %eax
cmpq $0x28, %rax
ja 0x3e7db
movq %rax, %rcx
addq 0x10(%rsi), %rcx
addl $0x8, %eax
movl %eax, (%rsi)
jmp 0x3e7e7
movq 0x8(%rsi), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsi)
movq (%rcx), %r15
testq %r15, %r15
jne 0x3e4c2
movq (%rbx), %rcx
leaq 0x2(%rcx), %rax
cmpq %rax, 0x8(%rbx)
jae 0x3e876
incq %rcx
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
movq %rax, %r14
shrq $0x20, %r14
orq %rax, %r14
incq %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3e85f
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rcx
jmp 0x3e87a
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rbx), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
movb $0xa, (%rax,%rcx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
movb $0x0, (%rcx,%rax)
movsbl (%r13), %eax
shll $0x8, %eax
movsbl 0x1(%r13), %esi
orl %eax, %esi
movq %rbx, %rdi
movq 0x28(%rsp), %rbx
movq %rbx, %rdx
callq 0x3d875
cmpl $-0x1, %eax
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
je 0x3e864
movl 0x18(%rbx), %eax
jmp 0x3e864
leaq 0x150bb(%rip), %rdi     # 0x53980
leaq 0x150c1(%rip), %rsi     # 0x5398d
leaq 0x15125(%rip), %rcx     # 0x539f8
movl $0x1ca, %edx            # imm = 0x1CA
callq 0x4350