// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/misc/wgsim.c
// Function: wgsim_mut_diref
void wgsim_mut_diref(const kseq_t *ks, 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 = ks->seq.l; ret[1]->l = ks->seq.l;
	ret[0]->m = ks->seq.m; ret[1]->m = ks->seq.m;
	ret[0]->s = (mut_t *)calloc(ks->seq.m, sizeof(mut_t));
	ret[1]->s = (mut_t *)calloc(ks->seq.m, sizeof(mut_t));
	for (i = 0; i != ks->seq.l; ++i) {
		int c;
		c = ret[0]->s[i] = ret[1]->s[i] = (mut_t)nst_nt4_table[(int)ks->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, %r13
movl %esi, 0xc(%rsp)
movq %rdi, %r15
movq %rdx, 0x20(%rsp)
movq %rcx, 0x28(%rsp)
movq 0x30(%rdi), %rbx
movl %ebx, (%rdx)
movl %ebx, (%rcx)
movq 0x38(%rdi), %r12
movl %r12d, 0x4(%rdx)
movl %r12d, 0x4(%rcx)
movl $0x2, %esi
movq %r12, %rdi
callq 0x10e0
movq %rax, 0x8(%r13)
movl $0x2, %esi
movq %r12, %rdi
callq 0x10e0
movq %rax, 0x8(%r14)
testq %rbx, %rbx
je 0x22a7
movq %r13, %rbx
xorl %r12d, %r12d
xorl %ebp, %ebp
movq %r13, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq 0x40(%r15), %rax
movsbq (%rax,%r12), %rax
leaq 0x1060(%rip), %rcx      # 0x3080
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 0x2079
callq 0x11d0
movsd 0x30b8(%rip), %xmm1     # 0x5100
ucomisd %xmm0, %xmm1
jbe 0x2079
testb $0x1, %bpl
je 0x205f
movq 0x8(%rbx), %rax
orw $0xf000, (%rax,%r12,2)  # imm = 0xF000
testb $0x2, %bpl
je 0x229a
movq 0x8(%r14), %rax
orw $0xf000, (%rax,%r12,2)  # imm = 0xF000
jmp 0x229a
xorl %ebp, %ebp
cmpb $0x3, %r13b
ja 0x229a
callq 0x11d0
movsd 0x3076(%rip), %xmm1     # 0x5108
ucomisd %xmm0, %xmm1
jbe 0x229a
callq 0x11d0
movsd %xmm0, 0x40(%rsp)
movsd 0x3061(%rip), %xmm0     # 0x5110
movsd %xmm0, 0x38(%rsp)
callq 0x11d0
movsd 0x40(%rsp), %xmm1
ucomisd 0x38(%rsp), %xmm1
jae 0x2118
movsd 0xf68(%rip), %xmm1      # 0x3038
ucomisd %xmm0, %xmm1
jbe 0x2175
cmpl $0x0, 0xc(%rsp)
jne 0x20f8
callq 0x11d0
movsd 0xf42(%rip), %xmm1      # 0x3030
ucomisd %xmm0, %xmm1
jbe 0x222d
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 0x229a
mulsd 0xf08(%rip), %xmm0      # 0x3028
addsd 0xee8(%rip), %xmm0      # 0x3010
cvttsd2si %xmm0, %ebx
addl %r13d, %ebx
andl $0x3, %ebx
cmpl $0x0, 0xc(%rsp)
jne 0x2150
callq 0x11d0
movsd 0xeea(%rip), %xmm1      # 0x3030
ucomisd %xmm0, %xmm1
jbe 0x2201
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 0x229a
xorl %ebp, %ebp
xorl %ebx, %ebx
movl %ebx, %r14d
shll $0x2, %r14d
callq 0x11d0
mulsd 0xeb3(%rip), %xmm0      # 0x3040
cvttsd2si %xmm0, %ebx
orl %r14d, %ebx
cmpl $0x3, %ebp
je 0x21b0
incl %ebp
callq 0x11d0
movsd 0x2f58(%rip), %xmm1     # 0x5100
ucomisd %xmm0, %xmm1
ja 0x2179
jmp 0x21b5
movl $0x4, %ebp
cmpl $0x0, 0xc(%rsp)
jne 0x21d3
callq 0x11d0
movsd 0xe67(%rip), %xmm1      # 0x3030
ucomisd %xmm0, %xmm1
jbe 0x225f
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 0x229a
orl $0xe000, %ebx           # imm = 0xE000
callq 0x11d0
xorl %eax, %eax
movsd 0xe22(%rip), %xmm1      # 0x3038
ucomisd %xmm0, %xmm1
setbe %al
movq 0x20(%rsp,%rax,8), %rax
movq 0x8(%rax), %rax
movw %bx, (%rax,%r12,2)
jmp 0x2295
callq 0x11d0
xorl %eax, %eax
movsd 0xdfc(%rip), %xmm1      # 0x3038
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 0x229a
shll $0xc, %ebp
shll $0x4, %ebx
orl %r13d, %ebp
orl %ebx, %ebp
callq 0x11d0
xorl %eax, %eax
movsd 0xdbf(%rip), %xmm1      # 0x3038
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
cmpq %r12, 0x30(%r15)
jne 0x2010
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq