// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x88, %rsp
movl %edi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movl $0xfffffffe, 0x6c(%rsp) # imm = 0xFFFFFFFE
movq $0x0, 0x38(%rsp)
movq $0x0, 0x28(%rsp)
movl $0x18, 0x70(%rsp)
movl $0x0, 0x48(%rsp)
movl $0x0, 0x4c(%rsp)
movl $0x0, 0x54(%rsp)
movl $0x0, 0x50(%rsp)
movl $0x0, 0x58(%rsp)
movl $0x0, 0x5c(%rsp)
movl $0x0, 0x60(%rsp)
movb $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
leaq 0x18(%rsp), %rdi
leaq 0x84138(%rip), %rsi     # 0x4ff33b
callq 0x32b70
leaq 0x20(%rsp), %rdi
leaq 0xbcf5e(%rip), %rsi     # 0x538172
callq 0x32b70
movl 0x80(%rsp), %edi
movq 0x78(%rsp), %rsi
leaq 0xff6cd(%rip), %rdx     # 0x57a8f9
callq 0x30020
movl %eax, 0x74(%rsp)
cmpl $0x0, %eax
jl 0x47b363
movl 0x74(%rsp), %eax
addl $-0x41, %eax
movl %eax, %ecx
movq %rcx, (%rsp)
subl $0x34, %eax
ja 0x47b332
movq (%rsp), %rax
leaq 0xff551(%rip), %rcx     # 0x57a7b0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1, 0x50(%rsp)
jmp 0x47b35e
movl 0x70(%rsp), %eax
orl $0x1, %eax
movl %eax, 0x70(%rsp)
jmp 0x47b35e
movl 0x70(%rsp), %eax
orl $0x2, %eax
movl %eax, 0x70(%rsp)
jmp 0x47b35e
movl 0x70(%rsp), %eax
orl $0x4, %eax
movl %eax, 0x70(%rsp)
jmp 0x47b35e
movl 0x70(%rsp), %eax
orl $0x20, %eax
movl %eax, 0x70(%rsp)
jmp 0x47b35e
movl 0x70(%rsp), %eax
andl $-0x19, %eax
movl %eax, 0x70(%rsp)
jmp 0x47b35e
movl $0x1, 0x60(%rsp)
jmp 0x47b35e
movl $0x1, 0x60(%rsp)
movl $0x1, 0x58(%rsp)
jmp 0x47b35e
movl $0x1, 0x5c(%rsp)
jmp 0x47b35e
movq 0x180c6b(%rip), %rax    # 0x5fbf60
movq (%rax), %rdi
callq 0x31ce0
movl %eax, 0x54(%rsp)
jmp 0x47b35e
movq 0x180c56(%rip), %rax    # 0x5fbf60
movq (%rax), %rdi
callq 0x31ce0
movl %eax, 0x4c(%rsp)
jmp 0x47b35e
movl 0x48(%rsp), %eax
orl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0x47b35e
movl 0x48(%rsp), %eax
orl $0x2, %eax
movl %eax, 0x48(%rsp)
jmp 0x47b35e
movq 0x180c8f(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
movl 0x74(%rsp), %edx
leaq 0xff5c2(%rip), %rsi     # 0x57a909
movb $0x0, %al
callq 0x33960
movl $0x1, 0x84(%rsp)
jmp 0x47b755
jmp 0x47b219
cmpl $0x0, 0x5c(%rsp)
jne 0x47b37b
leaq 0x18(%rsp), %rdi
leaq 0x8038b(%rip), %rsi     # 0x4fb701
callq 0x31b00
cmpl $0x0, 0x60(%rsp)
je 0x47b395
leaq 0x20(%rsp), %rdi
leaq 0x80373(%rip), %rsi     # 0x4fb701
callq 0x31b00
jmp 0x47b3a6
leaq 0x20(%rsp), %rdi
leaq 0xdd484(%rip), %rsi     # 0x558825
callq 0x31b00
cmpl $0x0, 0x58(%rsp)
je 0x47b3be
leaq 0x20(%rsp), %rdi
leaq 0xb8a48(%rip), %rsi     # 0x533e01
callq 0x31b00
movq 0x180b53(%rip), %rax    # 0x5fbf18
movl (%rax), %eax
addl $0x1, %eax
cmpl 0x80(%rsp), %eax
jl 0x47b4bf
movq 0x180bea(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xf2c5f(%rip), %rsi     # 0x56e047
movb $0x0, %al
callq 0x33960
movq 0x180bd2(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xff531(%rip), %rsi     # 0x57a931
movb $0x0, %al
callq 0x33960
movq 0x180bba(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xff553(%rip), %rsi     # 0x57a96b
movb $0x0, %al
callq 0x33960
movq 0x180ba2(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xff56c(%rip), %rsi     # 0x57a99c
movb $0x0, %al
callq 0x33960
movq 0x180b8a(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xff58c(%rip), %rsi     # 0x57a9d4
movb $0x0, %al
callq 0x33960
movq 0x180b72(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xff59d(%rip), %rsi     # 0x57a9fd
movb $0x0, %al
callq 0x33960
movq 0x180b5a(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xff5b5(%rip), %rsi     # 0x57aa2d
movb $0x0, %al
callq 0x33960
movq 0x180b42(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xff5ca(%rip), %rsi     # 0x57aa5a
movb $0x0, %al
callq 0x33960
movq 0x180b2a(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xff603(%rip), %rsi     # 0x57aaab
movb $0x0, %al
callq 0x33960
movl $0x1, 0x84(%rsp)
jmp 0x47b755
movq 0x78(%rsp), %rax
movq 0x180a4d(%rip), %rcx    # 0x5fbf18
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x18(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x46f470
movq %rax, 0x40(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x47b4fd
movl $0x1, 0x84(%rsp)
jmp 0x47b755
cmpl $0x0, 0x5c(%rsp)
je 0x47b546
movq 0x40(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0x47b51e
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
cmpl $0x0, (%rax)
jne 0x47b546
movq 0x180aa3(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xff5ca(%rip), %rsi     # 0x57aaf9
movb $0x0, %al
callq 0x33960
movl $0x1, 0x84(%rsp)
jmp 0x47b755
leaq 0x20(%rsp), %rsi
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rdx
leaq 0xfc074(%rip), %rdi     # 0x5775cf
callq 0x46f470
movq %rax, 0x38(%rsp)
movq 0x78(%rsp), %rax
movq 0x1809a7(%rip), %rcx    # 0x5fbf18
movl (%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x47eb60
movq %rax, 0x30(%rsp)
movl $0x1, %edi
movl $0x38, %esi
callq 0x32f50
movq %rax, 0x10(%rsp)
movq 0x40(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x46fc70
movl %eax, 0x68(%rsp)
cmpl $0x0, %eax
jl 0x47b6fe
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax)
jl 0x47b6ea
movl 0x6c(%rsp), %eax
movq 0x10(%rsp), %rcx
cmpl (%rcx), %eax
je 0x47b64c
movq 0x28(%rsp), %rdi
callq 0x34078
movq 0x30(%rsp), %rdi
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq 0x10(%rsp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x64(%rsp), %rdx
callq 0x47ecb0
movq %rax, 0x28(%rsp)
movq 0x10(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x6c(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x47b64a
movq 0x1809a5(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movslq 0x6c(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0xff4eb(%rip), %rsi     # 0x57ab2e
movb $0x0, %al
callq 0x33960
jmp 0x47b64c
cmpl $0x0, 0x50(%rsp)
je 0x47b666
movq 0x10(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl 0x48(%rsp), %edx
callq 0x479ea0
cmpl $0xa, 0x4c(%rsp)
jle 0x47b6c9
movq 0x10(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl 0x4c(%rsp), %edx
callq 0x4798f0
movl %eax, 0xc(%rsp)
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
shrq $0x10, %rax
andq $0xff, %rax
cmpl 0xc(%rsp), %eax
jle 0x47b6c7
movl 0xc(%rsp), %ecx
movq 0x10(%rsp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x8(%rax), %rcx
andq $0xff, %rdx
shlq $0x10, %rdx
andq $-0xff0001, %rcx        # imm = 0xFF00FFFF
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
jmp 0x47b6c9
cmpq $0x0, 0x28(%rsp)
je 0x47b6e8
movq 0x10(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl 0x70(%rsp), %edx
movl 0x54(%rsp), %ecx
callq 0x4788b0
jmp 0x47b6ea
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x46fcf0
jmp 0x47b59b
jmp 0x47b700
cmpq $0x0, 0x10(%rsp)
je 0x47b720
movq 0x10(%rsp), %rax
movq 0x30(%rax), %rdi
callq 0x34078
movq 0x10(%rsp), %rdi
callq 0x34078
jmp 0x47b722
movq 0x28(%rsp), %rdi
callq 0x34078
movq 0x30(%rsp), %rdi
callq 0x47e570
movq 0x40(%rsp), %rdi
callq 0x46fbf0
movq 0x38(%rsp), %rdi
callq 0x46fbf0
movl $0x0, 0x84(%rsp)
movl 0x84(%rsp), %eax
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)
nop