// File: /workspace/github_c_makefile_star2_O0/ToniWestbrook[P]paladin/bwamem.c
// Function: mem_patch_reg
int mem_patch_reg(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, uint8_t *query, const mem_alnreg_t *a, const mem_alnreg_t *b, int *_w)
{
	int w, score, q_s, r_s;
	double r;
	if (bns == 0 || pac == 0 || query == 0) return 0;
	assert(a->rid == b->rid && a->rb <= b->rb);
	if (a->rb < bns->l_pac && b->rb >= bns->l_pac) return 0; // on different strands
	if (a->qb >= b->qb || a->qe >= b->qe || a->re >= b->re) return 0; // not colinear
	w = (a->re - b->rb) - (a->qe - b->qb); // required bandwidth
	w = w > 0? w : -w; // l = abs(l)
	r = (double)(a->re - b->rb) / (b->re - a->rb) - (double)(a->qe - b->qb) / (b->qe - a->qb); // relative bandwidth
	r = r > 0.? r : -r; // r = fabs(r)
	if (bwa_verbose >= 4)
		printf("* potential hit merge between [%d,%d)<=>[%ld,%ld) and [%d,%d)<=>[%ld,%ld), @ %s; w=%d, r=%.4g\n",
			   a->qb, a->qe, (long)a->rb, (long)a->re, b->qb, b->qe, (long)b->rb, (long)b->re, bns->anns[a->rid].name, w, r);
	if (a->re < b->rb || a->qe < b->qb) { // no overlap on query or on ref
		if (w > opt->w<<1 || r >= PATCH_MAX_R_BW) return 0; // the bandwidth or the relative bandwidth is too large
	} else if (w > opt->w<<2 || r >= PATCH_MAX_R_BW*2) return 0; // more permissive if overlapping on both ref and query
	// global alignment
	w += a->w + b->w;
	w = w < opt->w<<2? w : opt->w<<2;
	if (bwa_verbose >= 4) printf("* test potential hit merge with global alignment; w=%d\n", w);
	bwa_gen_cigar2(opt->mat, opt->o_del, opt->e_del, opt->o_ins, opt->e_ins, w, bns->l_pac, pac, b->qe - a->qb, query + a->qb, a->rb, b->re, &score, 0, 0);
	q_s = (int)((double)(b->qe - a->qb) / ((b->qe - b->qb) + (a->qe - a->qb)) * (b->score + a->score) + .499); // predicted score from query
	r_s = (int)((double)(b->re - a->rb) / ((b->re - b->rb) + (a->re - a->rb)) * (b->score + a->score) + .499); // predicted score from ref
	if (bwa_verbose >= 4) printf("* score=%d;(%d,%d)\n", score, q_s, r_s);
	if ((double)score / (q_s > r_s? q_s : r_s) < PATCH_MIN_SC_RATIO) return 0;
	*_w = w;
	return score;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdx, -0x48(%rbp)
movq %rcx, -0x50(%rbp)
movq %r8, -0x58(%rbp)
movq %r9, -0x60(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x26335
cmpq $0x0, -0x48(%rbp)
je 0x26335
cmpq $0x0, -0x50(%rbp)
jne 0x26341
movl $0x0, -0x2c(%rbp)
jmp 0x2684c
movq -0x58(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x60(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jne 0x26363
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq -0x60(%rbp), %rcx
cmpq (%rcx), %rax
jg 0x26363
jmp 0x26382
leaq 0x14506(%rip), %rdi     # 0x3a870
leaq 0x14347(%rip), %rsi     # 0x3a6b8
movl $0x1e9, %edx            # imm = 0x1E9
leaq 0x14516(%rip), %rcx     # 0x3a893
callq 0x3190
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
cmpq (%rcx), %rax
jge 0x263ae
movq -0x60(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
cmpq (%rcx), %rax
jl 0x263ae
movl $0x0, -0x2c(%rbp)
jmp 0x2684c
movq -0x58(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x60(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x263e0
movq -0x58(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x60(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x263e0
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x60(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jl 0x263ec
movl $0x0, -0x2c(%rbp)
jmp 0x2684c
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x60(%rbp), %rcx
subq (%rcx), %rax
movq -0x58(%rbp), %rcx
movl 0x14(%rcx), %ecx
movq -0x60(%rbp), %rdx
subl 0x10(%rdx), %ecx
movslq %ecx, %rcx
subq %rcx, %rax
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jle 0x26420
movl -0x64(%rbp), %eax
movl %eax, -0x7c(%rbp)
jmp 0x26428
xorl %eax, %eax
subl -0x64(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x60(%rbp), %rcx
subq (%rcx), %rax
cvtsi2sd %rax, %xmm0
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x58(%rbp), %rcx
subq (%rcx), %rax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movq -0x58(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x60(%rbp), %rcx
subl 0x10(%rcx), %eax
cvtsi2sd %eax, %xmm1
movq -0x60(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x58(%rbp), %rcx
subl 0x10(%rcx), %eax
cvtsi2sd %eax, %xmm2
divsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x264a8
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
jmp 0x264cc
movsd -0x78(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
leaq 0x1a950(%rip), %rax     # 0x40e30
cmpl $0x4, (%rax)
jl 0x2656d
movq -0x58(%rbp), %rax
movl 0x10(%rax), %esi
movq -0x58(%rbp), %rax
movl 0x14(%rax), %edx
movq -0x58(%rbp), %rax
movq (%rax), %rcx
movq -0x58(%rbp), %rax
movq 0x8(%rax), %r8
movq -0x60(%rbp), %rax
movl 0x10(%rax), %r9d
movq -0x60(%rbp), %rax
movl 0x14(%rax), %r14d
movq -0x60(%rbp), %rax
movq (%rax), %rbx
movq -0x60(%rbp), %rax
movq 0x8(%rax), %r11
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x58(%rbp), %rdi
movslq 0x18(%rdi), %rdi
imulq $0x28, %rdi, %rdi
addq %rdi, %rax
movq 0x18(%rax), %r10
movl -0x64(%rbp), %eax
movsd -0x78(%rbp), %xmm0
leaq 0x143ca(%rip), %rdi     # 0x3a919
movl %r14d, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movl %eax, 0x20(%rsp)
movb $0x1, %al
callq 0x3060
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x60(%rbp), %rcx
cmpq (%rcx), %rax
jl 0x2658e
movq -0x58(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x60(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x265bf
movl -0x64(%rbp), %eax
movq -0x38(%rbp), %rcx
movl 0x24(%rcx), %ecx
shll %ecx
cmpl %ecx, %eax
jg 0x265b1
movsd -0x78(%rbp), %xmm0
movsd 0x140cd(%rip), %xmm1    # 0x3a678
ucomisd %xmm1, %xmm0
jb 0x265bd
movl $0x0, -0x2c(%rbp)
jmp 0x2684c
jmp 0x265f1
movl -0x64(%rbp), %eax
movq -0x38(%rbp), %rcx
movl 0x24(%rcx), %ecx
shll $0x2, %ecx
cmpl %ecx, %eax
jg 0x265e3
movsd -0x78(%rbp), %xmm0
movsd 0x14093(%rip), %xmm1    # 0x3a670
ucomisd %xmm1, %xmm0
jb 0x265ef
movl $0x0, -0x2c(%rbp)
jmp 0x2684c
jmp 0x265f1
movq -0x58(%rbp), %rax
movl 0x34(%rax), %eax
movq -0x60(%rbp), %rcx
addl 0x34(%rcx), %eax
addl -0x64(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
movq -0x38(%rbp), %rcx
movl 0x24(%rcx), %ecx
shll $0x2, %ecx
cmpl %ecx, %eax
jge 0x26621
movl -0x64(%rbp), %eax
movl %eax, -0x8c(%rbp)
jmp 0x26631
movq -0x38(%rbp), %rax
movl 0x24(%rax), %eax
shll $0x2, %eax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x64(%rbp)
leaq 0x1a7ef(%rip), %rax     # 0x40e30
cmpl $0x4, (%rax)
jl 0x26657
movl -0x64(%rbp), %esi
leaq 0x14328(%rip), %rdi     # 0x3a978
movb $0x0, %al
callq 0x3060
movq -0x38(%rbp), %rdi
addq $0xc4, %rdi
movq -0x38(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x38(%rbp), %rax
movl 0xc(%rax), %edx
movq -0x38(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x38(%rbp), %rax
movl 0x14(%rax), %r8d
movl -0x64(%rbp), %r9d
movq -0x40(%rbp), %rax
movq (%rax), %r12
movq -0x48(%rbp), %r15
movq -0x60(%rbp), %rax
movl 0x14(%rax), %r14d
movq -0x58(%rbp), %rax
subl 0x10(%rax), %r14d
movq -0x50(%rbp), %rbx
movq -0x58(%rbp), %rax
movslq 0x10(%rax), %rax
addq %rax, %rbx
movq -0x58(%rbp), %rax
movq (%rax), %r11
movq -0x60(%rbp), %rax
movq 0x8(%rax), %r10
leaq -0x68(%rbp), %rax
xorl %r13d, %r13d
movq %r12, (%rsp)
movq %r15, 0x8(%rsp)
movl %r14d, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
movq %r11, 0x20(%rsp)
movq %r10, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x40(%rsp)
callq 0x18f60
movq -0x60(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x58(%rbp), %rcx
subl 0x10(%rcx), %eax
cvtsi2sd %eax, %xmm0
movq -0x60(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x60(%rbp), %rcx
subl 0x10(%rcx), %eax
movq -0x58(%rbp), %rcx
movl 0x14(%rcx), %ecx
movq -0x58(%rbp), %rdx
subl 0x10(%rdx), %ecx
addl %ecx, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movq -0x60(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x58(%rbp), %rcx
addl 0x1c(%rcx), %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm0
movsd 0x11056(%rip), %xmm1    # 0x377a8
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x6c(%rbp)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x58(%rbp), %rcx
subq (%rcx), %rax
cvtsi2sd %rax, %xmm0
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x60(%rbp), %rcx
subq (%rcx), %rax
movq -0x58(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x58(%rbp), %rdx
subq (%rdx), %rcx
addq %rcx, %rax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movq -0x60(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x58(%rbp), %rcx
addl 0x1c(%rcx), %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm0
movsd 0x10fef(%rip), %xmm1    # 0x377a8
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x70(%rbp)
leaq 0x1a665(%rip), %rax     # 0x40e30
cmpl $0x4, (%rax)
jl 0x267e7
movl -0x68(%rbp), %esi
movl -0x6c(%rbp), %edx
movl -0x70(%rbp), %ecx
leaq 0x141d0(%rip), %rdi     # 0x3a9b0
movb $0x0, %al
callq 0x3060
cvtsi2sdl -0x68(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x70(%rbp), %eax
jle 0x26807
movl -0x6c(%rbp), %eax
movl %eax, -0x9c(%rbp)
jmp 0x26810
movl -0x70(%rbp), %eax
movl %eax, -0x9c(%rbp)
movsd -0x98(%rbp), %xmm1
movl -0x9c(%rbp), %eax
cvtsi2sd %eax, %xmm0
divsd %xmm0, %xmm1
movsd 0x13e52(%rip), %xmm0    # 0x3a680
ucomisd %xmm1, %xmm0
jbe 0x2683d
movl $0x0, -0x2c(%rbp)
jmp 0x2684c
movl -0x64(%rbp), %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
movl -0x68(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)