// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/samtools-0.1.18/bam_md.c
// Function: bam_fillmd
int bam_fillmd(int argc, char *argv[])
{
	int c, flt_flag, tid = -2, ret, len, is_bam_out, is_sam_in, is_uncompressed, max_nm, is_realn, capQ, baq_flag;
	samfile_t *fp, *fpout = 0;
	faidx_t *fai;
	char *ref = 0, mode_w[8], mode_r[8];
	bam1_t *b;

	flt_flag = UPDATE_NM | UPDATE_MD;
	is_bam_out = is_sam_in = is_uncompressed = is_realn = max_nm = capQ = baq_flag = 0;
	mode_w[0] = mode_r[0] = 0;
	strcpy(mode_r, "r"); strcpy(mode_w, "w");
	while ((c = getopt(argc, argv, "EqreuNhbSC:n:Ad")) >= 0) {
		switch (c) {
		case 'r': is_realn = 1; break;
		case 'e': flt_flag |= USE_EQUAL; break;
		case 'd': flt_flag |= DROP_TAG; break;
		case 'q': flt_flag |= BIN_QUAL; break;
		case 'h': flt_flag |= HASH_QNM; break;
		case 'N': flt_flag &= ~(UPDATE_MD|UPDATE_NM); break;
		case 'b': is_bam_out = 1; break;
		case 'u': is_uncompressed = is_bam_out = 1; break;
		case 'S': is_sam_in = 1; break;
		case 'n': max_nm = atoi(optarg); break;
		case 'C': capQ = atoi(optarg); break;
		case 'A': baq_flag |= 1; break;
		case 'E': baq_flag |= 2; break;
		default: fprintf(stderr, "[bam_fillmd] unrecognized option '-%c'\n", c); return 1;
		}
	}
	if (!is_sam_in) strcat(mode_r, "b");
	if (is_bam_out) strcat(mode_w, "b");
	else strcat(mode_w, "h");
	if (is_uncompressed) strcat(mode_w, "u");
	if (optind + 1 >= argc) {
		fprintf(stderr, "\n");
		fprintf(stderr, "Usage:   samtools fillmd [-eubrS] <aln.bam> <ref.fasta>\n\n");
		fprintf(stderr, "Options: -e       change identical bases to '='\n");
		fprintf(stderr, "         -u       uncompressed BAM output (for piping)\n");
		fprintf(stderr, "         -b       compressed BAM output\n");
		fprintf(stderr, "         -S       the input is SAM with header\n");
		fprintf(stderr, "         -A       modify the quality string\n");
		fprintf(stderr, "         -r       compute the BQ tag (without -A) or cap baseQ by BAQ (with -A)\n");
		fprintf(stderr, "         -E       extended BAQ for better sensitivity but lower specificity\n\n");
		return 1;
	}
	fp = samopen(argv[optind], mode_r, 0);
	if (fp == 0) return 1;
	if (is_sam_in && (fp->header == 0 || fp->header->n_targets == 0)) {
		fprintf(stderr, "[bam_fillmd] input SAM does not have header. Abort!\n");
		return 1;
	}
	fpout = samopen("-", mode_w, fp->header);
	fai = fai_load(argv[optind+1]);

	b = bam_init1();
	while ((ret = samread(fp, b)) >= 0) {
		if (b->core.tid >= 0) {
			if (tid != b->core.tid) {
				free(ref);
				ref = fai_fetch(fai, fp->header->target_name[b->core.tid], &len);
				tid = b->core.tid;
				if (ref == 0)
					fprintf(stderr, "[bam_fillmd] fail to find sequence '%s' in the reference.\n",
							fp->header->target_name[tid]);
			}
			if (is_realn) bam_prob_realn_core(b, ref, baq_flag);
			if (capQ > 10) {
				int q = bam_cap_mapQ(b, ref, capQ);
				if (b->core.qual > q) b->core.qual = q;
			}
			if (ref) bam_fillmd1_core(b, ref, flt_flag, max_nm);
		}
		samwrite(fpout, b);
	}
	bam_destroy1(b);

	free(ref);
	fai_destroy(fai);
	samclose(fp); samclose(fpout);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r12
movl %edi, %r13d
movw $0x72, 0x2c(%rsp)
movw $0x77, 0x20(%rsp)
pushq $0x18
popq %rbx
movl $0x0, 0x14(%rsp)
leaq 0xbdfd8(%rip), %r14     # 0x35b7fd
leaq 0xbdef8(%rip), %rbp     # 0x35b724
movl $0x0, 0x18(%rsp)
movl $0x0, 0x1c(%rsp)
xorl %ecx, %ecx
movl $0x0, 0x4(%rsp)
movl $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
movl %ecx, %r15d
movl %r13d, %edi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2f020
testl %eax, %eax
js 0x29d94b
leal -0x62(%rax), %ecx
cmpl $0x13, %ecx
ja 0x29d88f
movslq (%rbp,%rcx,4), %rdx
addq %rbp, %rdx
pushq $0x1
popq %rcx
jmpq *%rdx
movl %r15d, %ecx
pushq $0x1
popq %rax
movl %eax, 0x8(%rsp)
jmp 0x29d855
cmpl $0x41, %eax
je 0x29d90d
cmpl $0x43, %eax
je 0x29d930
cmpl $0x45, %eax
je 0x29d919
cmpl $0x4e, %eax
je 0x29d925
cmpl $0x53, %eax
jne 0x29dc59
pushq $0x1
popq %rax
movl %eax, 0x14(%rsp)
movl %r15d, %ecx
jmp 0x29d855
orl $0x4, %ebx
movl %r15d, %ecx
jmp 0x29d855
orl $0x20, %ebx
movl %r15d, %ecx
jmp 0x29d855
orl $0x1, %ebx
movl %r15d, %ecx
jmp 0x29d855
orl $0x2, %ebx
movl %r15d, %ecx
jmp 0x29d855
movq 0x16d652(%rip), %rax    # 0x40af38
movq (%rax), %rdi
callq 0x30cd0
movl %eax, 0x1c(%rsp)
movl %r15d, %ecx
jmp 0x29d855
pushq $0x1
popq %rax
movl %eax, 0x18(%rsp)
movl %r15d, %ecx
movl %eax, 0x8(%rsp)
jmp 0x29d855
orl $0x1, (%rsp)
movl %r15d, %ecx
jmp 0x29d855
orl $0x2, (%rsp)
movl %r15d, %ecx
jmp 0x29d855
andl $-0x19, %ebx
movl %r15d, %ecx
jmp 0x29d855
movq 0x16d601(%rip), %rax    # 0x40af38
movq (%rax), %rdi
callq 0x30cd0
movl %eax, 0x4(%rsp)
movl %r15d, %ecx
jmp 0x29d855
movl 0x14(%rsp), %r14d
testl %r14d, %r14d
jne 0x29d966
leaq 0x2c(%rsp), %rdi
callq 0x2fe60
movw $0x62, 0x2c(%rsp,%rax)
movl %ebx, 0x28(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x2fe60
cmpl $0x0, 0x8(%rsp)
pushq $0x68
popq %rcx
pushq $0x62
popq %rdx
cmovel %ecx, %edx
movw %dx, 0x20(%rsp,%rax)
cmpl $0x0, 0x18(%rsp)
je 0x29d99f
leaq 0x20(%rsp), %rdi
callq 0x2fe60
movw $0x75, 0x20(%rsp,%rax)
movq 0x16d542(%rip), %rbx    # 0x40aee8
movslq (%rbx), %rax
leal 0x1(%rax), %ecx
cmpl %r13d, %ecx
jge 0x29db73
movq (%r12,%rax,8), %rdi
leaq 0x2c(%rsp), %rsi
xorl %edx, %edx
callq 0x297dc8
pushq $0x1
popq %rbp
testq %rax, %rax
je 0x29db62
movq %rax, %r13
movq 0x10(%rax), %rdx
testl %r14d, %r14d
je 0x29d9ef
testq %rdx, %rdx
je 0x29dc38
cmpl $0x0, (%rdx)
je 0x29dc38
leaq 0xba754(%rip), %rdi     # 0x35814a
leaq 0x20(%rsp), %rsi
callq 0x297dc8
movq %rax, %r14
movslq (%rbx), %rax
movq 0x8(%r12,%rax,8), %rdi
callq 0x29f8d1
movq %rax, 0x8(%rsp)
pushq $0x1
popq %rdi
pushq $0x38
popq %rsi
callq 0x31f40
movq %rax, %r12
pushq $-0x2
popq %rbx
xorl %ebp, %ebp
movq %r13, %rdi
movq %r12, %rsi
callq 0x29828b
testl %eax, %eax
js 0x29db27
movl (%r12), %eax
testl %eax, %eax
js 0x29dae9
cmpl %eax, %ebx
je 0x29da7e
movq %rbp, %rdi
callq 0x33058
movq 0x10(%r13), %rax
movq 0x8(%rax), %rax
movslq (%r12), %rcx
movq (%rax,%rcx,8), %rsi
movq 0x8(%rsp), %rdi
leaq 0x34(%rsp), %rdx
callq 0x29f9da
movl (%r12), %ebx
testq %rax, %rax
je 0x29daf9
movq %rax, %rbp
testl %r15d, %r15d
je 0x29da91
movq %r12, %rdi
movq %rbp, %rsi
movl (%rsp), %edx
callq 0x29d0bb
cmpl $0xb, 0x4(%rsp)
jl 0x29dacd
movq %r12, %rdi
movq %rbp, %rsi
movl 0x4(%rsp), %edx
callq 0x29ce15
movq 0x8(%r12), %rcx
movl %ecx, %edx
shrl $0x10, %edx
movzbl %dl, %edx
cmpl %eax, %edx
jle 0x29dacd
movzbl %al, %eax
shll $0x10, %eax
andq $-0xff0001, %rcx        # imm = 0xFF00FFFF
orq %rax, %rcx
movq %rcx, 0x8(%r12)
testq %rbp, %rbp
je 0x29dae7
movq %r12, %rdi
movq %rbp, %rsi
movl 0x28(%rsp), %edx
movl 0x1c(%rsp), %ecx
callq 0x29c67c
jmp 0x29dae9
xorl %ebp, %ebp
movq %r14, %rdi
movq %r12, %rsi
callq 0x2982be
jmp 0x29da28
movslq %ebx, %rax
movq 0x16d4ad(%rip), %rcx    # 0x40afb0
movq (%rcx), %rdi
movq 0x10(%r13), %rcx
movq 0x8(%rcx), %rcx
movq (%rcx,%rax,8), %rdx
leaq 0xbdf19(%rip), %rsi     # 0x35ba32
xorl %eax, %eax
callq 0x32960
xorl %ebp, %ebp
jmp 0x29da7e
testq %r12, %r12
je 0x29db3e
movq 0x30(%r12), %rdi
callq 0x33058
movq %r12, %rdi
callq 0x33058
movq %rbp, %rdi
callq 0x33058
movq 0x8(%rsp), %rdi
callq 0x29f53d
movq %r13, %rdi
callq 0x298245
movq %r14, %rdi
callq 0x298245
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x16d436(%rip), %r14    # 0x40afb0
movq (%r14), %rsi
pushq $0xa
popq %rdi
callq 0x2fcd0
movq (%r14), %rcx
leaq 0xbdca6(%rip), %rdi     # 0x35b835
pushq $0x39
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x32760
movq (%r14), %rcx
leaq 0xbdcc8(%rip), %rdi     # 0x35b86f
pushq $0x30
popq %rsi
movq %rbx, %rdx
callq 0x32760
movq (%r14), %rcx
leaq 0xbdce4(%rip), %rdi     # 0x35b8a0
pushq $0x37
popq %rsi
movq %rbx, %rdx
callq 0x32760
movq (%r14), %rcx
leaq 0xbdd07(%rip), %rdi     # 0x35b8d8
pushq $0x28
popq %rsi
movq %rbx, %rdx
callq 0x32760
movq (%r14), %rcx
leaq 0xbdd1b(%rip), %rdi     # 0x35b901
pushq $0x2f
popq %rsi
movq %rbx, %rdx
callq 0x32760
movq (%r14), %rcx
leaq 0xbdd36(%rip), %rdi     # 0x35b931
pushq $0x2c
popq %rsi
movq %rbx, %rdx
callq 0x32760
movq (%r14), %rcx
leaq 0xbdd4e(%rip), %rdi     # 0x35b95e
pushq $0x50
popq %rsi
movq %rbx, %rdx
callq 0x32760
movq (%r14), %rcx
leaq 0xbdd8a(%rip), %rdi     # 0x35b9af
pushq $0x4d
popq %rsi
movq %rbx, %rdx
callq 0x32760
pushq $0x1
popq %rbp
jmp 0x29db62
movq 0x16d371(%rip), %rax    # 0x40afb0
movq (%rax), %rcx
leaq 0xbddb4(%rip), %rdi     # 0x35b9fd
pushq $0x34
popq %rsi
pushq $0x1
popq %rdx
callq 0x32760
jmp 0x29db62
movq 0x16d350(%rip), %rcx    # 0x40afb0
movq (%rcx), %rdi
leaq 0xbdba3(%rip), %rsi     # 0x35b80d
movl %eax, %edx
xorl %eax, %eax
callq 0x32960
jmp 0x29dc30
nopl (%rax)