// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/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, %ebp
movq %rsi, %r15
movq %rdi, %r14
testl %edx, %edx
jne 0x6150c
movq %r15, %rdi
callq 0x62d0
movq %rax, %rbp
movq (%r14), %rbx
movslq %ebp, %r12
leaq (%r12,%rbx), %rax
incq %rax
cmpq 0x8(%r14), %rax
jb 0x6156d
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, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
callq 0x6c80
testq %rax, %rax
je 0x61951
movq %rax, 0x10(%r14)
movl %r12d, %r13d
movq 0x10(%r14), %rdi
addq (%r14), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x6570
movq %r13, %rcx
addq (%r14), %r12
movq %r12, (%r14)
movq 0x10(%r14), %rax
movb $0x0, (%rax,%r12)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $-0x1, %ecx
je 0x61956
testl %ecx, %ecx
jle 0x6194d
movq %r14, %r15
movslq %ebx, %r12
addq 0x10(%r14), %r12
movl $0x1, (%rsp)
xorl %r13d, %r13d
movq %rbp, 0x30(%rsp)
movq %rcx, 0x8(%rsp)
movq %r14, 0x18(%rsp)
movslq %r13d, %rax
movb (%r12,%rax), %cl
testb %cl, %cl
je 0x6194d
leaq (%r12,%rax), %rsi
cmpb $0x40, %cl
jne 0x618b6
movsbl 0x1(%rsi), %r14d
leal -0x7b(%r14), %ecx
cmpb $-0x3a, %cl
jb 0x618c4
movsbl 0x2(%rsi), %ebx
leal -0x7b(%rbx), %ecx
cmpb $-0x3b, %cl
jbe 0x618c4
leaq 0x3(%rax), %rbp
cmpb $0xa, 0x3(%r12,%rax)
jne 0x61624
movl $0x4, 0x4(%rsp)
jmp 0x61910
movq %rsi, 0x20(%rsp)
movq 0x28(%r15), %rdi
callq 0x86da2
movl $0x1, 0x4(%rsp)
testq %rax, %rax
je 0x61910
movq %rax, 0x10(%rsp)
movl %r14d, %esi
shll $0x8, %esi
orl %ebx, %esi
movq 0x18(%r15), %rdi
movl %esi, 0x40(%rsp)
leaq 0x44(%rsp), %rdx
callq 0x61984
cmpl $-0x1, %eax
je 0x61910
cmpl $0x0, 0x44(%rsp)
movq 0x18(%r15), %rcx
movq 0x20(%rcx), %rcx
movl %eax, %eax
je 0x61690
movq 0x10(%rsp), %rdx
movq %rdx, (%rcx,%rax,8)
movq %rdx, (%rdx)
movq %rdx, 0x8(%rdx)
xorl %eax, %eax
jmp 0x616b9
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rcx
cmpq %rax, (%rcx)
jne 0x61965
movq 0x10(%rsp), %rdx
movq %rdx, (%rcx)
movq %rcx, 0x8(%rdx)
movq %rdx, 0x8(%rax)
movq %rax, (%rdx)
movl 0x18(%rcx), %eax
incl %eax
movq 0x8(%rsp), %rcx
movl %eax, 0x18(%rdx)
xorb $0x43, %r14b
xorb $0x4f, %bl
orb %r14b, %bl
jne 0x6175a
cmpb $0x9, (%r12,%rbp)
jne 0x61930
addl $0x4, %r13d
movslq %r13d, %rbp
movl %r13d, %ebx
cmpl 0x30(%rsp), %r13d
jge 0x61708
movq %rbp, %rbx
movzbl (%r12,%rbx), %eax
testl %eax, %eax
je 0x61708
cmpl $0xa, %eax
je 0x61708
incq %rbx
cmpq %rbx, %rcx
jne 0x616f0
movl %ecx, %ebx
movq 0x30(%r15), %rdi
callq 0x86da2
movq %rax, %r14
movq 0x10(%rsp), %rax
movq %r14, 0x10(%rax)
testq %r14, %r14
je 0x618e7
movq 0x20(%r15), %rdi
leaq (%r12,%rbp), %rsi
movl %ebx, %eax
subl %ebp, %eax
movslq %eax, %r13
movq %r13, %rdx
callq 0x651bb
movq %rax, 0x8(%r14)
movl %r13d, 0x10(%r14)
movq $0x0, (%r14)
testq %rax, %rax
setne %al
cmovnel %ebx, %ebp
jmp 0x618ec
movq 0x30(%rsp), %rax
subl %r13d, %eax
movl %eax, 0x3c(%rsp)
movl %ecx, %eax
subl %r13d, %eax
movl %eax, 0x38(%rsp)
movq $0x0, 0x28(%rsp)
movslq %ebp, %rax
cmpb $0x9, (%r12,%rax)
jne 0x6186f
incl %ebp
movslq %ebp, %r13
movl %ebp, %ebx
cmpl %ecx, %ebp
jge 0x617b2
movq %r13, %rbx
movzbl (%r12,%rbx), %eax
cmpl $0xa, %eax
ja 0x617a8
movl $0x601, %edx            # imm = 0x601
btl %eax, %edx
jb 0x617b2
incq %rbx
cmpq %rbx, %rcx
jne 0x61794
movl %ecx, %ebx
movq 0x30(%r15), %rdi
callq 0x86da2
testq %rax, %rax
je 0x6181d
movq %rax, %r14
movq 0x20(%r15), %rdi
leaq (%r12,%r13), %rsi
movl %ebx, %r15d
subl %r13d, %r15d
movslq %r15d, %r13
movq %r13, %rdx
callq 0x651bb
movq %rax, 0x8(%r14)
movl %r13d, 0x10(%r14)
movq $0x0, (%r14)
testq %rax, %rax
je 0x61821
cmpl $0x3, %r15d
movq 0x8(%rsp), %rcx
jl 0x61890
cmpb $0x3a, 0x2(%rax)
jne 0x61890
movq 0x28(%rsp), %rax
testq %rax, %rax
movq 0x18(%rsp), %r15
je 0x6182f
movq %r14, (%rax)
jmp 0x61838
xorl %eax, %eax
jmp 0x61828
xorl %eax, %eax
movq 0x18(%rsp), %r15
movq 0x8(%rsp), %rcx
jmp 0x61841
movq 0x10(%rsp), %rax
movq %r14, 0x10(%rax)
movb $0x1, %al
movl %ebx, %ebp
movq %r14, 0x28(%rsp)
testb %al, %al
je 0x61910
cmpl %ecx, %ebp
jge 0x618f3
movslq %ebp, %rax
movzbl (%r12,%rax), %eax
cmpl $0xa, %eax
je 0x618f3
testl %eax, %eax
jne 0x61778
jmp 0x618f3
leaq 0x38031(%rip), %rdi     # 0x998a7
movq 0x20(%rsp), %rsi
movl 0x3c(%rsp), %edx
movl (%rsp), %ecx
callq 0x7b6c
movq 0x8(%rsp), %rcx
xorl %eax, %eax
jmp 0x61841
leaq 0x3801c(%rip), %rdi     # 0x998b3
movq 0x20(%rsp), %rsi
movl 0x38(%rsp), %edx
movl (%rsp), %ecx
callq 0x7b6c
movq 0x8(%rsp), %rcx
xorl %eax, %eax
movq 0x18(%rsp), %r15
jmp 0x61841
movl %ebp, %edx
subl %r13d, %edx
leaq 0x37f40(%rip), %rdi     # 0x99802
jmp 0x618d5
movq 0x8(%rsp), %rax
movl %eax, %edx
subl %r13d, %edx
leaq 0x37f51(%rip), %rdi     # 0x99826
movl (%rsp), %ecx
callq 0x7b6c
movl $0x1, 0x4(%rsp)
jmp 0x61913
xorl %eax, %eax
movl %r13d, %ebp
movl %ebp, %r13d
testb %al, %al
je 0x61913
movq %r15, %rdi
movl 0x40(%rsp), %esi
movq 0x10(%rsp), %rdx
callq 0x61adf
xorl %ecx, %ecx
cmpl $-0x1, %eax
sete %cl
movl %ecx, 0x4(%rsp)
movl %ebp, %r13d
testb $0x3, 0x4(%rsp)
jne 0x61951
incl %r13d
incl (%rsp)
movq 0x30(%rsp), %rbp
cmpl %ebp, %r13d
jl 0x615cd
jmp 0x6194d
movl %ecx, %edx
subl %r13d, %edx
leaq 0x37f6b(%rip), %rdi     # 0x998a7
movq 0x20(%rsp), %rsi
movl (%rsp), %ecx
callq 0x7b6c
xorl %eax, %eax
jmp 0x618ec
xorl %eax, %eax
jmp 0x61956
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x37ee8(%rip), %rdi     # 0x99854
leaq 0x37eee(%rip), %rsi     # 0x99861
leaq 0x37ef9(%rip), %rcx     # 0x99873
movl $0x14f, %edx            # imm = 0x14F
callq 0x6460