// File: /workspace/github_cpp_makefile_star2_O1/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 (%rdi), %eax
movl %eax, (%rcx)
movl 0x4(%rdi), %eax
movl %eax, 0x4(%rdx)
movl 0x4(%rdi), %eax
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 0x2bd8
xorl %r12d, %r12d
xorl %ebp, %ebp
movq %rbx, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq 0x8(%r15), %rax
movzbl (%rax,%r12), %eax
leaq 0x1741(%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 0x29a8
callq 0x11f0
movsd 0x37a1(%rip), %xmm1     # 0x6118
ucomisd %xmm0, %xmm1
jbe 0x29a8
testb $0x1, %bpl
je 0x298e
movq 0x8(%rbx), %rax
orw $0xf000, (%rax,%r12,2)  # imm = 0xF000
testb $0x2, %bpl
je 0x2bc9
movq 0x8(%r14), %rax
orw $0xf000, (%rax,%r12,2)  # imm = 0xF000
jmp 0x2bc9
xorl %ebp, %ebp
cmpb $0x3, %r13b
ja 0x2bc9
callq 0x11f0
movsd 0x375f(%rip), %xmm1     # 0x6120
ucomisd %xmm0, %xmm1
jbe 0x2bc9
callq 0x11f0
movsd %xmm0, 0x40(%rsp)
movsd 0x374a(%rip), %xmm0     # 0x6128
movsd %xmm0, 0x38(%rsp)
callq 0x11f0
movsd 0x40(%rsp), %xmm1
ucomisd 0x38(%rsp), %xmm1
jae 0x2a47
movsd 0x1639(%rip), %xmm1     # 0x4038
ucomisd %xmm0, %xmm1
jbe 0x2aa4
cmpl $0x0, 0xc(%rsp)
jne 0x2a27
callq 0x11f0
movsd 0x1613(%rip), %xmm1     # 0x4030
ucomisd %xmm0, %xmm1
jbe 0x2b5c
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 0x2bc9
mulsd 0x15d9(%rip), %xmm0     # 0x4028
addsd 0x15b9(%rip), %xmm0     # 0x4010
cvttsd2si %xmm0, %ebx
addl %r13d, %ebx
andl $0x3, %ebx
cmpl $0x0, 0xc(%rsp)
jne 0x2a7f
callq 0x11f0
movsd 0x15bb(%rip), %xmm1     # 0x4030
ucomisd %xmm0, %xmm1
jbe 0x2b30
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 0x2bc9
xorl %ebp, %ebp
xorl %ebx, %ebx
movl %ebx, %r14d
shll $0x2, %r14d
callq 0x11f0
mulsd 0x1584(%rip), %xmm0     # 0x4040
cvttsd2si %xmm0, %ebx
orl %r14d, %ebx
cmpl $0x3, %ebp
je 0x2adf
incl %ebp
callq 0x11f0
movsd 0x3641(%rip), %xmm1     # 0x6118
ucomisd %xmm0, %xmm1
ja 0x2aa8
jmp 0x2ae4
movl $0x4, %ebp
cmpl $0x0, 0xc(%rsp)
jne 0x2b02
callq 0x11f0
movsd 0x1538(%rip), %xmm1     # 0x4030
ucomisd %xmm0, %xmm1
jbe 0x2b8e
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 0x2bc9
orl $0xe000, %ebx           # imm = 0xE000
callq 0x11f0
xorl %eax, %eax
movsd 0x14f3(%rip), %xmm1     # 0x4038
ucomisd %xmm0, %xmm1
setbe %al
movq 0x20(%rsp,%rax,8), %rax
movq 0x8(%rax), %rax
movw %bx, (%rax,%r12,2)
jmp 0x2bc4
callq 0x11f0
xorl %eax, %eax
movsd 0x14cd(%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 0x2bc9
shll $0xc, %ebp
shll $0x4, %ebx
orl %r13d, %ebp
orl %ebx, %ebp
callq 0x11f0
xorl %eax, %eax
movsd 0x1490(%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 0x293f
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq