// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/sample.c
// Function: bam_smpl_add
int bam_smpl_add(bam_sample_t *sm, const char *fn, const char *txt)
{
	const char *p = txt, *q, *r;
	kstring_t buf, first_sm;
	int n = 0;
	khash_t(sm) *sm2id = (khash_t(sm)*)sm->sm2id;
	if (txt == 0) {
		add_pair(sm, sm2id, fn, fn);
		return 0;
	}
	memset(&buf, 0, sizeof(kstring_t));
    memset(&first_sm, 0, sizeof(kstring_t));
	while ((q = strstr(p, "@RG")) != 0) {
		p = q + 3;
		r = q = 0;
		if ((q = strstr(p, "\tID:")) != 0) q += 4;
		if ((r = strstr(p, "\tSM:")) != 0) r += 4;
		if (r && q) {
			char *u, *v;
			int oq, or;
			for (u = (char*)q; *u && *u != '\t' && *u != '\n'; ++u);
			for (v = (char*)r; *v && *v != '\t' && *v != '\n'; ++v);
			oq = *u; or = *v; *u = *v = '\0';
			buf.l = 0; kputs(fn, &buf); kputc('/', &buf); kputs(q, &buf);
			add_pair(sm, sm2id, buf.s, r);
            if ( !first_sm.s )
                kputs(r,&first_sm); 
			*u = oq; *v = or;
		} else break;
		p = q > r? q : r;
		++n;
	}
	if (n == 0) add_pair(sm, sm2id, fn, fn);
    // If there is only one RG tag present in the header and reads are not annotated, don't refuse to work but
    //  use the tag instead.
    else if ( n==1 && first_sm.s )
        add_pair(sm,sm2id,fn,first_sm.s);
    if ( first_sm.s )
        free(first_sm.s);

//	add_pair(sm, sm2id, fn, fn);
	free(buf.s);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %rcx
movq 0x18(%rdi), %rsi
testq %rdx, %rdx
je 0x168a4
movq %rdi, 0x30(%rsp)
movq %rsi, 0x38(%rsp)
movq %rcx, 0x40(%rsp)
leaq 0x2a7e9(%rip), %rsi     # 0x40d48
movq %rdx, %rdi
callq 0x3460
testq %rax, %rax
je 0x168ae
movq %rax, %r15
xorl %ebx, %ebx
movq $0x0, 0x18(%rsp)
movq $0x0, 0x60(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x48(%rsp)
movl %ebx, 0xc(%rsp)
addq $0x3, %r15
movq %r15, %rdi
leaq 0x28efe(%rip), %rsi     # 0x3f4b2
callq 0x3460
movq %rax, %r12
leaq 0x4(%rax), %r14
testq %rax, %rax
cmoveq %rax, %r14
movq %r15, %rdi
leaq 0x2a77b(%rip), %rsi     # 0x40d4c
callq 0x3460
leaq 0x4(%rax), %rcx
testq %rax, %rax
cmoveq %rax, %rcx
je 0x168c4
testq %r12, %r12
je 0x168c4
movq %r14, 0x50(%rsp)
movq 0x40(%rsp), %r13
movl $0x601, %eax            # imm = 0x601
movzbl (%r14), %edx
cmpl $0xa, %edx
ja 0x1660d
btl %edx, %eax
jb 0x16612
incq %r14
jmp 0x165ff
movq %rcx, %r15
movzbl (%r15), %ebp
cmpl $0xa, %ebp
ja 0x16623
btl %ebp, %eax
jb 0x16628
incq %r15
jmp 0x16615
movl %edx, 0x5c(%rsp)
movq %rcx, 0x68(%rsp)
xorl %eax, %eax
movb %al, (%r15)
movb %al, (%r14)
movq %r13, %rdi
callq 0x3360
cltq
movq %rax, 0x20(%rsp)
leaq 0x1(%rax), %r12
movq 0x48(%rsp), %rbx
cmpq %rbx, %r12
movq %r12, 0x70(%rsp)
jae 0x16662
movq 0x10(%rsp), %rax
jmp 0x166a3
movq %r12, %rax
shrq %rax
orq %r12, %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, %rbx
shrq $0x10, %rbx
orq %rcx, %rbx
incq %rbx
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x3720
movq %rax, %r12
movq %rax, %rdi
movq %r13, %rsi
movq 0x20(%rsp), %r13
movq %r13, %rdx
callq 0x37d0
movq %r12, %rdi
movb $0x0, (%r12,%r13)
movq 0x70(%rsp), %r12
cmpq %rbx, %r12
jb 0x1670a
movq %r12, %rax
shrq %rax
orq %r12, %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, %rbx
shrq $0x10, %rbx
orq %rcx, %rbx
incq %rbx
movq %rbx, %rsi
callq 0x3720
movq %rax, %rdi
movq %rdi, 0x10(%rsp)
movq 0x20(%rsp), %r13
movw $0x2f, (%rdi,%r13)
movq 0x50(%rsp), %rdi
callq 0x3360
movslq %eax, %rcx
leaq (%rcx,%r13), %rax
addq $0x2, %rax
movq %rcx, %r13
cmpq %rbx, %rax
jae 0x16744
movq %rbx, 0x48(%rsp)
movq 0x10(%rsp), %rbx
jmp 0x1678a
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 0x10(%rsp), %rdi
movq %rsi, 0x48(%rsp)
callq 0x3720
movq %rax, %rbx
leaq (%rbx,%r12), %rdi
movq 0x50(%rsp), %rsi
movq %r13, %rdx
callq 0x37d0
addq %r12, %r13
movb $0x0, (%rbx,%r13)
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq %rbx, 0x10(%rsp)
movq %rbx, %rdx
movq 0x68(%rsp), %r12
movq %r12, %rcx
callq 0x16938
cmpq $0x0, 0x18(%rsp)
jne 0x1686b
movq %r12, %rdi
callq 0x3360
movslq %eax, %r13
movq 0x28(%rsp), %rax
addq %r13, %rax
incq %rax
cmpq 0x60(%rsp), %rax
jae 0x167f2
movq 0x18(%rsp), %rax
jmp 0x16835
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 0x18(%rsp), %rdi
movq %rsi, 0x60(%rsp)
callq 0x3720
movq 0x28(%rsp), %rbx
leaq (%rax,%rbx), %rdi
movq 0x68(%rsp), %r12
movq %r12, %rsi
movq %r13, %rdx
movq %r13, 0x20(%rsp)
movq %rax, %r13
callq 0x37d0
addq 0x20(%rsp), %rbx
movq %r13, 0x18(%rsp)
movq %rbx, 0x28(%rsp)
movb $0x0, (%r13,%rbx)
movl 0xc(%rsp), %ebx
movl 0x5c(%rsp), %eax
movb %al, (%r14)
movb %bpl, (%r15)
movq 0x50(%rsp), %rax
cmpq %r12, %rax
cmovaq %rax, %r12
incl %ebx
movq %r12, %rdi
leaq 0x2a4b7(%rip), %rsi     # 0x40d48
callq 0x3460
movq %rax, %r15
testq %rax, %rax
jne 0x165a2
jmp 0x168c8
movq %rcx, %rdx
callq 0x16938
jmp 0x16927
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
xorl %ebx, %ebx
jmp 0x168c8
movl 0xc(%rsp), %ebx
testl %ebx, %ebx
je 0x168f4
cmpl $0x1, %ebx
movq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdi
movq 0x18(%rsp), %rbx
jne 0x16910
testq %rbx, %rbx
je 0x16910
movq %rbx, %rcx
callq 0x16938
jmp 0x16910
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rcx
movq %rcx, %rdx
callq 0x16938
movq 0x18(%rsp), %rbx
testq %rbx, %rbx
je 0x1691d
movq %rbx, %rdi
callq 0x3350
movq 0x10(%rsp), %rdi
callq 0x3350
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq