// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/misc/wgsim.c
// Function: maq_mut_diref
void maq_mut_diref(const seq_t *seq, int is_hap, mutseq_t *hap1, mutseq_t *hap2)
{
	int i, deleting = 0;
	mutseq_t *ret[2];

	ret[0] = hap1; ret[1] = hap2;
	ret[0]->l = seq->l; ret[1]->l = seq->l;
	ret[0]->m = seq->m; ret[1]->m = seq->m;
	ret[0]->s = (mut_t *)calloc(seq->m, sizeof(mut_t));
	ret[1]->s = (mut_t *)calloc(seq->m, sizeof(mut_t));
	for (i = 0; i != seq->l; ++i) {
		int c;
		c = ret[0]->s[i] = ret[1]->s[i] = (mut_t)nst_nt4_table[(int)seq->s[i]];
        if (deleting) {
            if (drand48() < INDEL_EXTEND) {
                if (deleting & 1) ret[0]->s[i] |= DELETE;
                if (deleting & 2) ret[1]->s[i] |= DELETE;
                continue;
            } else deleting = 0;
        }
		if (c < 4 && drand48() < MUT_RATE) { // mutation
			if (drand48() >= INDEL_FRAC) { // substitution
				double r = drand48();
				c = (c + (int)(r * 3.0 + 1)) & 3;
				if (is_hap || drand48() < 0.333333) { // hom
					ret[0]->s[i] = ret[1]->s[i] = SUBSTITUTE|c;
				} else { // het
					ret[drand48()<0.5?0:1]->s[i] = SUBSTITUTE|c;
				}
			} else { // indel
				if (drand48() < 0.5) { // deletion
					if (is_hap || drand48() < 0.333333) { // hom-del
						ret[0]->s[i] = ret[1]->s[i] = DELETE;
                        deleting = 3;
					} else { // het-del
                        deleting = drand48()<0.5?1:2;
						ret[deleting-1]->s[i] = DELETE;
					}
				} else { // insertion
                    int num_ins = 0, ins = 0;
                    do {
                        num_ins++;
                        ins = (ins << 2) | (int)(drand48() * 4.0);
                    } while (num_ins < 4 && drand48() < INDEL_EXTEND);

					if (is_hap || drand48() < 0.333333) { // hom-ins
						ret[0]->s[i] = ret[1]->s[i] = (num_ins << 12) | (ins << 4) | c;
					} else { // het-ins
						ret[drand48()<0.5?0:1]->s[i] = (num_ins << 12) | (ins << 4) | c;
					}
				}
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r14
movq %rdx, %rbx
movl %esi, 0xc(%rsp)
movq %rdi, %r15
movq %rdx, 0x20(%rsp)
movq %rcx, 0x28(%rsp)
movl (%rdi), %eax
movl %eax, (%rdx)
movl %eax, (%rcx)
movl 0x4(%rdi), %eax
movl %eax, 0x4(%rdx)
movl %eax, 0x4(%rcx)
movslq 0x4(%rdi), %r12
movl $0x2, %esi
movq %r12, %rdi
callq 0x1110
movq %rax, 0x8(%rbx)
movl $0x2, %esi
movq %r12, %rdi
callq 0x1110
movq %rax, 0x8(%r14)
cmpl $0x0, (%r15)
je 0x2d3c
xorl %r12d, %r12d
xorl %ebp, %ebp
movq %rbx, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq 0x8(%r15), %rax
movzbl (%rax,%r12), %eax
leaq 0x15dd(%rip), %rcx      # 0x4090
movzbl (%rax,%rcx), %r13d
movq 0x8(%r14), %rax
movw %r13w, (%rax,%r12,2)
movq 0x8(%rbx), %rax
movw %r13w, (%rax,%r12,2)
testl %ebp, %ebp
je 0x2b0c
callq 0x11e0
movsd 0x3635(%rip), %xmm1     # 0x6110
ucomisd %xmm0, %xmm1
jbe 0x2b0c
testb $0x1, %bpl
je 0x2af2
movq 0x8(%rbx), %rax
orw $0xf000, (%rax,%r12,2)  # imm = 0xF000
testb $0x2, %bpl
je 0x2d2d
movq 0x8(%r14), %rax
orw $0xf000, (%rax,%r12,2)  # imm = 0xF000
jmp 0x2d2d
xorl %ebp, %ebp
cmpb $0x3, %r13b
ja 0x2d2d
callq 0x11e0
movsd 0x35f3(%rip), %xmm1     # 0x6118
ucomisd %xmm0, %xmm1
jbe 0x2d2d
callq 0x11e0
movsd %xmm0, 0x40(%rsp)
movsd 0x35de(%rip), %xmm0     # 0x6120
movsd %xmm0, 0x38(%rsp)
callq 0x11e0
movsd 0x40(%rsp), %xmm1
ucomisd 0x38(%rsp), %xmm1
jae 0x2bab
movsd 0x14d5(%rip), %xmm1     # 0x4038
ucomisd %xmm0, %xmm1
jbe 0x2c08
cmpl $0x0, 0xc(%rsp)
jne 0x2b8b
callq 0x11e0
movsd 0x14af(%rip), %xmm1     # 0x4030
ucomisd %xmm0, %xmm1
jbe 0x2cc0
movq 0x8(%r14), %rax
movw $0xf000, %cx            # imm = 0xF000
movw %cx, (%rax,%r12,2)
movq 0x8(%rbx), %rax
movw %cx, (%rax,%r12,2)
movl $0x3, %ebp
jmp 0x2d2d
mulsd 0x1475(%rip), %xmm0     # 0x4028
addsd 0x1455(%rip), %xmm0     # 0x4010
cvttsd2si %xmm0, %ebx
addl %r13d, %ebx
andl $0x3, %ebx
cmpl $0x0, 0xc(%rsp)
jne 0x2be3
callq 0x11e0
movsd 0x1457(%rip), %xmm1     # 0x4030
ucomisd %xmm0, %xmm1
jbe 0x2c94
orl $0xe000, %ebx           # imm = 0xE000
movq 0x8(%r14), %rax
movw %bx, (%rax,%r12,2)
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rax
movw %bx, (%rax,%r12,2)
movq %rcx, %rbx
jmp 0x2d2d
xorl %ebp, %ebp
xorl %ebx, %ebx
movl %ebx, %r14d
shll $0x2, %r14d
callq 0x11e0
mulsd 0x1420(%rip), %xmm0     # 0x4040
cvttsd2si %xmm0, %ebx
orl %r14d, %ebx
cmpl $0x3, %ebp
je 0x2c43
incl %ebp
callq 0x11e0
movsd 0x34d5(%rip), %xmm1     # 0x6110
ucomisd %xmm0, %xmm1
ja 0x2c0c
jmp 0x2c48
movl $0x4, %ebp
cmpl $0x0, 0xc(%rsp)
jne 0x2c66
callq 0x11e0
movsd 0x13d4(%rip), %xmm1     # 0x4030
ucomisd %xmm0, %xmm1
jbe 0x2cf2
shll $0xc, %ebp
shll $0x4, %ebx
orl %r13d, %ebp
orl %ebx, %ebp
movq 0x18(%rsp), %r14
movq 0x8(%r14), %rax
movw %bp, (%rax,%r12,2)
movq 0x10(%rsp), %rbx
movq 0x8(%rbx), %rax
movw %bp, (%rax,%r12,2)
xorl %ebp, %ebp
jmp 0x2d2d
orl $0xe000, %ebx           # imm = 0xE000
callq 0x11e0
xorl %eax, %eax
movsd 0x138f(%rip), %xmm1     # 0x4038
ucomisd %xmm0, %xmm1
setbe %al
movq 0x20(%rsp,%rax,8), %rax
movq 0x8(%rax), %rax
movw %bx, (%rax,%r12,2)
jmp 0x2d28
callq 0x11e0
xorl %eax, %eax
movsd 0x1369(%rip), %xmm1     # 0x4038
ucomisd %xmm0, %xmm1
seta %al
movl $0x2, %ebp
subl %eax, %ebp
xorl $0x1, %eax
movq 0x20(%rsp,%rax,8), %rax
movq 0x8(%rax), %rax
movw $0xf000, (%rax,%r12,2)  # imm = 0xF000
jmp 0x2d2d
shll $0xc, %ebp
shll $0x4, %ebx
orl %r13d, %ebp
orl %ebx, %ebp
callq 0x11e0
xorl %eax, %eax
movsd 0x132c(%rip), %xmm1     # 0x4038
ucomisd %xmm0, %xmm1
setbe %al
movq 0x20(%rsp,%rax,8), %rax
movq 0x8(%rax), %rax
movw %bp, (%rax,%r12,2)
xorl %ebp, %ebp
movq 0x18(%rsp), %r14
movq 0x10(%rsp), %rbx
incq %r12
movl (%r15), %eax
cmpq %rax, %r12
jne 0x2aa3
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq