// File: /workspace/github_c_makefile_star2_O3/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 $0x68, %rsp
movq %rsi, %rcx
movq 0x18(%rdi), %rsi
testq %rdx, %rdx
je 0x16b85
movq %rdi, 0x10(%rsp)
movq %rsi, 0x18(%rsp)
movq %rcx, 0x20(%rsp)
leaq 0x2b552(%rip), %rsi     # 0x41d90
movq %rdx, %rdi
callq 0x3460
testq %rax, %rax
je 0x16b8f
movq %rax, %rbx
xorl %r15d, %r15d
movq $0x0, (%rsp)
movq $0x0, 0x48(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x8(%rsp)
movq $0x0, 0x30(%rsp)
addq $0x3, %rbx
movq %rbx, %rdi
leaq 0x29c5b(%rip), %rsi     # 0x404ea
callq 0x3460
movq %rax, %r13
leaq 0x4(%rax), %r14
testq %rax, %rax
movq %r14, %r12
cmoveq %rax, %r12
movq %rbx, %rdi
leaq 0x2b4e5(%rip), %rsi     # 0x41d94
callq 0x3460
leaq 0x4(%rax), %rcx
testq %rax, %rax
cmoveq %rax, %rcx
je 0x16ba2
testq %r13, %r13
je 0x16ba2
movq %r12, 0x38(%rsp)
movq 0x20(%rsp), %r12
movl $0x601, %eax            # imm = 0x601
movzbl (%r14), %edx
cmpl $0xa, %edx
ja 0x168eb
btl %edx, %eax
jb 0x168f0
incq %r14
jmp 0x168dd
movl %r15d, 0x44(%rsp)
movq %rcx, %r15
movzbl (%r15), %ebx
cmpl $0xa, %ebx
ja 0x16906
btl %ebx, %eax
jb 0x1690b
incq %r15
jmp 0x168f8
movl %edx, 0x40(%rsp)
movq %rcx, 0x50(%rsp)
xorl %eax, %eax
movb %al, (%r15)
movb %al, (%r14)
movq %r12, %rdi
callq 0x3360
cltq
movq %rax, 0x58(%rsp)
leaq 0x1(%rax), %r13
movq 0x30(%rsp), %rbp
cmpq %rbp, %r13
movq %r13, 0x60(%rsp)
jae 0x16945
movq 0x8(%rsp), %rax
jmp 0x16986
movq %r13, %rax
shrq %rax
orq %r13, %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, %rbp
shrq $0x10, %rbp
orq %rcx, %rbp
incq %rbp
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x3720
movq %rax, %r13
movq %rax, %rdi
movq %r12, %rsi
movq 0x58(%rsp), %r12
movq %r12, %rdx
callq 0x37d0
movq %r13, %rdi
movb $0x0, (%r13,%r12)
movq 0x60(%rsp), %r13
cmpq %rbp, %r13
jb 0x169ee
movq %r13, %rax
shrq %rax
orq %r13, %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, %rbp
shrq $0x10, %rbp
orq %rcx, %rbp
incq %rbp
movq %rbp, %rsi
callq 0x3720
movq %rax, %rdi
movq %rdi, 0x8(%rsp)
movq 0x58(%rsp), %r12
movw $0x2f, (%rdi,%r12)
movq 0x38(%rsp), %rdi
callq 0x3360
movslq %eax, %rcx
leaq (%r12,%rcx), %rax
addq $0x2, %rax
movq %rcx, %r12
cmpq %rbp, %rax
jae 0x16a28
movq %rbp, 0x30(%rsp)
movq 0x8(%rsp), %rbp
jmp 0x16a6e
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 0x8(%rsp), %rdi
movq %rsi, 0x30(%rsp)
callq 0x3720
movq %rax, %rbp
movq %rbp, %rdi
addq %r13, %rdi
movq 0x38(%rsp), %rsi
movq %r12, %rdx
callq 0x37d0
addq %r13, %r12
movb $0x0, (%rbp,%r12)
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %rbp, 0x8(%rsp)
movq %rbp, %rdx
movq 0x50(%rsp), %r13
movq %r13, %rcx
callq 0x16c10
cmpq $0x0, (%rsp)
jne 0x16b4a
movq %r13, %rdi
callq 0x3360
movslq %eax, %r12
movq 0x28(%rsp), %rax
addq %r12, %rax
incq %rax
cmpq 0x48(%rsp), %rax
jae 0x16adb
movq $0x0, (%rsp)
jmp 0x16b1d
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, %rdi
shrq $0x10, %rdi
orq %rax, %rdi
incq %rdi
movq %rdi, 0x48(%rsp)
callq 0x3240
movq %rax, (%rsp)
movq 0x28(%rsp), %rbp
movq (%rsp), %rax
leaq (%rax,%rbp), %rdi
movq 0x50(%rsp), %r13
movq %r13, %rsi
movq %r12, %rdx
callq 0x37d0
addq %r12, %rbp
movq %rbp, 0x28(%rsp)
movq (%rsp), %rax
movb $0x0, (%rax,%rbp)
movl 0x40(%rsp), %eax
movb %al, (%r14)
movb %bl, (%r15)
movq 0x38(%rsp), %rax
cmpq %r13, %rax
cmovaq %rax, %r13
movl 0x44(%rsp), %r15d
incl %r15d
movq %r13, %rdi
leaq 0x2b21e(%rip), %rsi     # 0x41d90
callq 0x3460
movq %rax, %rbx
testq %rax, %rax
jne 0x16881
jmp 0x16ba7
movq %rcx, %rdx
callq 0x16c10
jmp 0x16bff
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
jmp 0x16bce
testl %r15d, %r15d
je 0x16bce
cmpl $0x1, %r15d
jne 0x16be5
cmpq $0x0, (%rsp)
je 0x16be5
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq (%rsp), %rcx
callq 0x16c10
jmp 0x16bec
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rcx
movq %rcx, %rdx
callq 0x16c10
cmpq $0x0, (%rsp)
je 0x16bf5
movq (%rsp), %rdi
callq 0x3350
movq 0x8(%rsp), %rdi
callq 0x3350
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq