// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/htslib/cram/sam_header.c
// Function: sam_hdr_add_lines
int sam_hdr_add_lines(SAM_hdr *sh, const char *lines, int len) {
    int i, lno, text_offset;
    char *hdr;

    if (!len)
	len = strlen(lines);

    text_offset = ks_len(&sh->text);
    if (EOF == kputsn(lines, len, &sh->text))
	return -1;
    hdr = ks_str(&sh->text) + text_offset;

    for (i = 0, lno = 1; i < len && hdr[i] != '\0'; i++, lno++) {
	khint32_t type;
	khint_t k;

	int l_start = i, new;
	SAM_hdr_type *h_type;
	SAM_hdr_tag *h_tag, *last;

	if (hdr[i] != '@') {
	    int j;
	    for (j = i; j < len && hdr[j] != '\0' && hdr[j] != '\n'; j++)
		;
	    sam_hdr_error("Header line does not start with '@'",
			  &hdr[l_start], len - l_start, lno);
	    return -1;
	}

	type = (hdr[i+1]<<8) | hdr[i+2];
	if (hdr[i+1] < 'A' || hdr[i+1] > 'z' ||
	    hdr[i+2] < 'A' || hdr[i+2] > 'z') {
	    sam_hdr_error("Header line does not have a two character key",
			  &hdr[l_start], len - l_start, lno);
	    return -1;
	}

	i += 3;
	if (hdr[i] == '\n')
	    continue;

	// Add the header line type
	if (!(h_type = pool_alloc(sh->type_pool)))
	    return -1;
	if (-1 == (k = kh_put(sam_hdr, sh->h, type, &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;
	}

	// Parse the tags on this line
	last = NULL;
	if ((type>>8) == 'C' && (type&0xff) == 'O') {
	    int j;
	    if (hdr[i] != '\t') {
		sam_hdr_error("Missing tab",
			      &hdr[l_start], len - l_start, lno);
		return -1;
	    }

	    for (j = ++i; j < len && hdr[j] != '\0' && hdr[j] != '\n'; j++)
		;

	    if (!(h_type->tag = h_tag = pool_alloc(sh->tag_pool)))
		return -1;
	    h_tag->str = string_ndup(sh->str_pool, &hdr[i], j-i);
	    h_tag->len = j-i;
	    h_tag->next = NULL;
	    if (!h_tag->str)
		return -1;

	    i = j;

	} else {
	    do {
		int j;
		if (hdr[i] != '\t') {
		    sam_hdr_error("Missing tab",
				  &hdr[l_start], len - l_start, lno);
		    return -1;
		}

		for (j = ++i; j < len && hdr[j] != '\0' && hdr[j] != '\n' && hdr[j] != '\t'; j++)
		    ;
	    
		if (!(h_tag = pool_alloc(sh->tag_pool)))
		    return -1;
		h_tag->str = string_ndup(sh->str_pool, &hdr[i], j-i);
		h_tag->len = j-i;
		h_tag->next = NULL;
		if (!h_tag->str)
		    return -1;

		if (h_tag->len < 3 || h_tag->str[2] != ':') {
		    sam_hdr_error("Malformed key:value pair",
				  &hdr[l_start], len - l_start, lno);
		    return -1;
		}
	    
		if (last)
		    last->next = h_tag;
		else
		    h_type->tag = h_tag;

		last = h_tag;
		i = j;
	    } while (i < len && hdr[i] != '\0' && hdr[i] != '\n');
	}

	/* Update RG/SQ hashes */
	if (-1 == sam_hdr_update_hashes(sh, type, h_type))
	    return -1;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %rbp
testl %edx, %edx
jne 0x3d2a8
movq %r15, %rdi
callq 0x4230
movq %rax, %r14
movq (%rbp), %rbx
movslq %r14d, %r13
leaq (%rbx,%r13), %rax
addq $0x2, %rax
cmpq %rax, 0x8(%rbp)
jae 0x3d325
leaq (%rbx,%r13), %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, %r12
shrq $0x20, %r12
orq %rcx, %r12
incq %r12
movq 0x10(%rbp), %rdi
movq %r12, %rsi
callq 0x48d0
testq %rax, %rax
je 0x3d6a7
movq %rax, 0x10(%rbp)
movq %r12, 0x8(%rbp)
movq (%rbp), %rdi
jmp 0x3d32c
movq 0x10(%rbp), %rax
movq %rbx, %rdi
addq %rax, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x4420
movq (%rbp), %rax
addq %r13, %rax
movq %rax, (%rbp)
movq 0x10(%rbp), %rcx
movb $0x0, (%rcx,%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $-0x1, %r13d
je 0x3d6ac
testl %r14d, %r14d
jle 0x3d670
movslq %ebx, %rdx
addq 0x10(%rbp), %rdx
movl $0x1, %ecx
xorl %esi, %esi
movq %rbp, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movq %r13, 0x38(%rsp)
movq %rdx, 0x18(%rsp)
movslq %esi, %rbx
movb (%rdx,%rbx), %al
testb %al, %al
je 0x3d670
leaq (%rdx,%rbx), %rdi
cmpb $0x40, %al
jne 0x3d6bb
movsbl 0x1(%rdi), %r15d
leal -0x7b(%r15), %eax
cmpb $-0x3a, %al
jb 0x3d6cd
movsbl 0x2(%rdi), %r12d
leal -0x7b(%r12), %eax
cmpb $-0x3a, %al
jb 0x3d6cd
movl %ecx, (%rsp)
leaq 0x3(%rbx), %r13
cmpb $0xa, 0x3(%rdx,%rbx)
je 0x3d652
movq %rdi, 0x20(%rsp)
movl %esi, 0x4(%rsp)
movq 0x28(%rbp), %rdi
callq 0x4d08e
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x3d6a7
movl %r15d, %ebp
shll $0x8, %ebp
orl %r12d, %ebp
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
movl %ebp, %esi
leaq 0x34(%rsp), %rdx
callq 0x3d707
movq 0x18(%rsp), %rdx
cmpl $-0x1, %eax
je 0x3d6a7
cmpl $0x0, 0x34(%rsp)
movq 0x8(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq 0x20(%rcx), %rcx
movl %eax, %eax
je 0x3d44c
movq 0x28(%rsp), %rsi
movq %rsi, (%rcx,%rax,8)
movq %rsi, (%rsi)
movq %rsi, 0x8(%rsi)
xorl %eax, %eax
jmp 0x3d475
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rcx
cmpq %rax, (%rcx)
movq 0x28(%rsp), %rsi
jne 0x3d6e8
movq %rsi, (%rcx)
movq %rcx, 0x8(%rsi)
movq %rsi, 0x8(%rax)
movq %rax, (%rsi)
movl 0x18(%rcx), %eax
incl %eax
movl %eax, 0x18(%rsi)
xorb $0x43, %r15b
xorb $0x4f, %r12b
orb %r15b, %r12b
jne 0x3d4da
cmpb $0x9, (%rdx,%r13)
movq 0x10(%rsp), %r14
jne 0x3d6df
addq $0x4, %rbx
movl %ebx, %r13d
cmpl %r14d, %ebx
jge 0x3d5dc
leaq (%rdx,%rbx), %rax
movq 0x38(%rsp), %rcx
subq %rbx, %rcx
xorl %r13d, %r13d
movzbl (%rax,%r13), %edx
testl %edx, %edx
je 0x3d5d9
cmpl $0xa, %edx
je 0x3d5d9
incq %r13
cmpq %r13, %rcx
jne 0x3d4b4
movl %r14d, %r13d
jmp 0x3d5dc
addq $0x10, %rsi
movq %rsi, 0x40(%rsp)
movb (%rdx,%r13), %al
xorl %r15d, %r15d
cmpb $0x9, %al
jne 0x3d674
movslq %r13d, %rbx
incq %rbx
movl %ebx, %r13d
movq 0x10(%rsp), %rsi
cmpl %esi, %ebx
jge 0x3d537
leaq (%rdx,%rbx), %rax
movq 0x38(%rsp), %rcx
subq %rbx, %rcx
xorl %r13d, %r13d
movl $0x601, %edi            # imm = 0x601
movzbl (%rax,%r13), %edx
cmpl $0xa, %edx
ja 0x3d527
btl %edx, %edi
jb 0x3d534
incq %r13
cmpq %r13, %rcx
jne 0x3d518
movl %esi, %r13d
jmp 0x3d537
addl %ebx, %r13d
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rdi
callq 0x4d08e
movq 0x18(%rsp), %rcx
testq %rax, %rax
je 0x3d6a7
movq %rax, %r12
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rdi
movslq %ebx, %rsi
addq %rcx, %rsi
movl %r13d, %r14d
subl %ebx, %r14d
movslq %r14d, %rbx
movq %rbx, %rdx
callq 0x40f39
movq 0x18(%rsp), %rdx
movq %rax, 0x8(%r12)
movl %ebx, 0x10(%r12)
movq $0x0, (%r12)
testq %rax, %rax
je 0x3d6a7
cmpl $0x3, %r14d
jl 0x3d67d
cmpb $0x3a, 0x2(%rax)
movq 0x10(%rsp), %r14
jne 0x3d68b
testq %r15, %r15
cmoveq 0x40(%rsp), %r15
movq %r12, (%r15)
cmpl %r14d, %r13d
jge 0x3d637
movslq %r13d, %rax
movzbl (%rdx,%rax), %eax
cmpl $0xa, %eax
je 0x3d637
movq %r12, %r15
testl %eax, %eax
jne 0x3d4ea
jmp 0x3d637
addl %ebx, %r13d
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rdi
callq 0x4d08e
movq 0x18(%rsp), %rcx
movq %rax, %r15
movq 0x28(%rsp), %rax
movq %r15, 0x10(%rax)
testq %r15, %r15
je 0x3d6a7
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rdi
movslq %ebx, %rsi
addq %rcx, %rsi
movl %r13d, %eax
subl %ebx, %eax
movslq %eax, %r12
movq %r12, %rdx
callq 0x40f39
movq %rax, 0x8(%r15)
movl %r12d, 0x10(%r15)
movq $0x0, (%r15)
testq %rax, %rax
je 0x3d6a7
movq 0x8(%rsp), %rdi
movl %ebp, %esi
movq 0x28(%rsp), %rdx
callq 0x3d875
movq 0x18(%rsp), %rdx
cmpl $-0x1, %eax
je 0x3d6a7
incl %r13d
movl (%rsp), %ecx
incl %ecx
movl %r13d, %esi
movq 0x10(%rsp), %r14
cmpl %r14d, %r13d
movq 0x8(%rsp), %rbp
jl 0x3d387
xorl %eax, %eax
jmp 0x3d6ac
leaq 0x16358(%rip), %rdi     # 0x539d3
jmp 0x3d684
leaq 0x1635b(%rip), %rdi     # 0x539df
movq 0x10(%rsp), %r14
jmp 0x3d692
leaq 0x1634d(%rip), %rdi     # 0x539df
movl (%rsp), %ecx
subl 0x4(%rsp), %r14d
movq 0x20(%rsp), %rsi
movl %r14d, %edx
callq 0x5971
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, 0x20(%rsp)
movl %esi, 0x4(%rsp)
leaq 0x16263(%rip), %rdi     # 0x5392e
jmp 0x3d695
movq %rdi, 0x20(%rsp)
movl %esi, 0x4(%rsp)
leaq 0x16275(%rip), %rdi     # 0x53952
jmp 0x3d695
leaq 0x162ed(%rip), %rdi     # 0x539d3
jmp 0x3d692
leaq 0x16291(%rip), %rdi     # 0x53980
leaq 0x16297(%rip), %rsi     # 0x5398d
leaq 0x162a2(%rip), %rcx     # 0x5399f
movl $0x14f, %edx            # imm = 0x14F
callq 0x4350