// File: /workspace/github_c_makefile_star2_O2/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, %r12d
movq %rsi, %rbx
movq %rdi, %rcx
testl %edx, %edx
movq %rdi, 0x10(%rsp)
jne 0x57d76
movq %rbx, %rdi
callq 0x62d0
movq 0x10(%rsp), %rcx
movq %rax, %r12
movq (%rcx), %r14
movq %rbx, %rdi
movl %r12d, %esi
movq %rcx, %rbx
movq %rcx, %rdx
callq 0x580e9
pushq $-0x1
popq %rcx
cmpl $-0x1, %eax
je 0x580b9
movslq %r14d, %r15
addq 0x10(%rbx), %r15
movslq %r12d, %rax
movq %rax, 0x38(%rsp)
pushq $0x1
popq %rcx
xorl %r14d, %r14d
movq %r12, 0x28(%rsp)
movl %r12d, %esi
subl %r14d, %esi
jle 0x5806c
movslq %r14d, %rax
movb (%r15,%rax), %dl
testb %dl, %dl
je 0x5806c
leaq (%r15,%rax), %rdi
cmpb $0x40, %dl
jne 0x58086
movsbl 0x1(%rdi), %r13d
leal -0x7b(%r13), %edx
cmpb $-0x3a, %dl
jb 0x58098
movsbl 0x2(%rdi), %ebp
leal -0x7b(%rbp), %edx
cmpb $-0x3a, %dl
jb 0x58098
movl %ecx, 0x8(%rsp)
leaq 0x3(%rax), %r12
cmpb $0xa, 0x3(%r15,%rax)
je 0x58056
movq %rdi, 0x18(%rsp)
movl %esi, 0xc(%rsp)
movq 0x28(%rbx), %rdi
callq 0x75978
movq 0x10(%rsp), %rcx
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x580b6
movl %r13d, %esi
shll $0x8, %esi
orl %ebp, %esi
movq 0x18(%rcx), %rdi
movl %esi, 0x30(%rsp)
leaq 0x34(%rsp), %rdx
callq 0x581cd
movq 0x10(%rsp), %rdi
cmpl $-0x1, %eax
je 0x580b6
cmpl $0x0, 0x34(%rsp)
movq 0x18(%rdi), %rcx
movq 0x20(%rcx), %rcx
movl %eax, %eax
je 0x57e80
movq 0x20(%rsp), %rdx
movq %rdx, (%rcx,%rax,8)
movq %rdx, (%rdx)
movq %rdx, 0x8(%rdx)
xorl %eax, %eax
jmp 0x57ea9
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %rcx
cmpq %rax, (%rcx)
movq 0x20(%rsp), %rdx
jne 0x580ca
movq %rdx, (%rcx)
movq %rcx, 0x8(%rdx)
movq %rdx, 0x8(%rax)
movq %rax, (%rdx)
movl 0x18(%rcx), %eax
incl %eax
movl %eax, 0x18(%rdx)
xorb $0x43, %r13b
xorb $0x4f, %bpl
orb %r13b, %bpl
jne 0x57f06
cmpb $0x9, (%r15,%r12)
movq 0x38(%rsp), %rdx
jne 0x58079
addl $0x4, %r14d
movslq %r14d, %r14
movq 0x28(%rsp), %rax
cmpl %r14d, %eax
movl %r14d, %r12d
cmovgl %eax, %r12d
movq %r14, %rax
cmpq %rdx, %rax
jge 0x57fec
movzbl (%r15,%rax), %ecx
testl %ecx, %ecx
je 0x57fe9
cmpl $0xa, %ecx
je 0x57fe9
incq %rax
jmp 0x57ee2
addq $0x10, %rdx
movq %rdx, 0x40(%rsp)
movb (%r15,%r12), %al
xorl %ebp, %ebp
cmpb $0x9, %al
movq 0x38(%rsp), %rdx
jne 0x58079
incl %r12d
movslq %r12d, %r13
movq 0x28(%rsp), %rax
cmpl %r13d, %eax
movl %r13d, %r12d
cmovgl %eax, %r12d
movq %r13, %rax
movl $0x601, %esi            # imm = 0x601
cmpq %rdx, %rax
jge 0x57f5b
movzbl (%r15,%rax), %ecx
cmpl $0xa, %ecx
ja 0x57f53
btl %ecx, %esi
jb 0x57f58
incq %rax
jmp 0x57f3f
movl %eax, %r12d
movq 0x30(%rdi), %rdi
callq 0x75978
movq 0x10(%rsp), %rcx
testq %rax, %rax
je 0x580b6
movq %rax, %r14
movq 0x20(%rcx), %rdi
leaq (%r15,%r13), %rsi
movl %r12d, %ebx
subl %r13d, %ebx
movslq %ebx, %r13
movq %r13, %rdx
callq 0x5a5da
movq 0x10(%rsp), %rdi
movq %rax, 0x8(%r14)
movl %r13d, 0x10(%r14)
andq $0x0, (%r14)
testq %rax, %rax
je 0x580b6
cmpl $0x3, %ebx
jl 0x58070
cmpb $0x3a, 0x2(%rax)
jne 0x58070
testq %rbp, %rbp
cmoveq 0x40(%rsp), %rbp
movq %r14, (%rbp)
cmpl 0x28(%rsp), %r12d
jge 0x5803e
movslq %r12d, %rax
movzbl (%r15,%rax), %eax
cmpl $0xa, %eax
je 0x5803e
movq %r14, %rbp
testl %eax, %eax
jne 0x57f15
jmp 0x5803e
movl %eax, %r12d
movq 0x30(%rdi), %rdi
callq 0x75978
movq 0x10(%rsp), %rcx
movq %rax, %rbx
movq 0x20(%rsp), %rax
movq %rbx, 0x10(%rax)
testq %rbx, %rbx
je 0x580b6
movq 0x20(%rcx), %rdi
leaq (%r15,%r14), %rsi
movl %r12d, %eax
subl %r14d, %eax
movslq %eax, %r14
movq %r14, %rdx
callq 0x5a5da
movq 0x10(%rsp), %rdi
movq %rax, 0x8(%rbx)
movl %r14d, 0x10(%rbx)
andq $0x0, (%rbx)
testq %rax, %rax
je 0x580b6
movl 0x30(%rsp), %esi
movq 0x20(%rsp), %rdx
callq 0x5832f
movq 0x10(%rsp), %rbx
cmpl $-0x1, %eax
je 0x580b6
incl %r12d
movl 0x8(%rsp), %ecx
incl %ecx
movl %r12d, %r14d
movq 0x28(%rsp), %r12
jmp 0x57db0
xorl %ecx, %ecx
jmp 0x580b9
leaq 0x307f4(%rip), %rdi     # 0x8886b
jmp 0x58080
leaq 0x307df(%rip), %rdi     # 0x8885f
movl 0x8(%rsp), %ecx
jmp 0x580a8
movq %rdi, 0x18(%rsp)
movl %esi, 0xc(%rsp)
leaq 0x30724(%rip), %rdi     # 0x887ba
jmp 0x580a8
movq %rdi, 0x18(%rsp)
movl %esi, 0xc(%rsp)
leaq 0x30736(%rip), %rdi     # 0x887de
movq 0x18(%rsp), %rsi
movl 0xc(%rsp), %edx
callq 0x5818f
pushq $-0x1
popq %rcx
movl %ecx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3073b(%rip), %rdi     # 0x8880c
leaq 0x30741(%rip), %rsi     # 0x88819
leaq 0x3074c(%rip), %rcx     # 0x8882b
movl $0x14f, %edx            # imm = 0x14F
callq 0x6460