// File: /workspace/github_c_makefile_star2_O1/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, %rbx
movl %esi, 0xc(%rsp)
movq %rdi, %r15
movq %rdx, 0x20(%rsp)
movq %rcx, 0x28(%rsp)
movl 0x30(%rdi), %eax
movl %eax, (%rdx)
movl %eax, (%rcx)
movq 0x38(%rdi), %r12
movl %r12d, 0x4(%rdx)
movl %r12d, 0x4(%rcx)
movl $0x2, %esi
movq %r12, %rdi
callq 0x10e0
movq %rax, 0x8(%rbx)
movl $0x2, %esi
movq %r12, %rdi
callq 0x10e0
movq %rax, 0x8(%r14)
cmpq $0x0, 0x30(%r15)
je 0x2285
xorl %r12d, %r12d
xorl %ebp, %ebp
movq %rbx, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq 0x40(%r15), %rax
movsbq (%rax,%r12), %rax
leaq 0x1082(%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 0x2057
callq 0x11d0
movsd 0x30da(%rip), %xmm1     # 0x5100
ucomisd %xmm0, %xmm1
jbe 0x2057
testb $0x1, %bpl
je 0x203d
movq 0x8(%rbx), %rax
orw $0xf000, (%rax,%r12,2)  # imm = 0xF000
testb $0x2, %bpl
je 0x2278
movq 0x8(%r14), %rax
orw $0xf000, (%rax,%r12,2)  # imm = 0xF000
jmp 0x2278
xorl %ebp, %ebp
cmpb $0x3, %r13b
ja 0x2278
callq 0x11d0
movsd 0x3098(%rip), %xmm1     # 0x5108
ucomisd %xmm0, %xmm1
jbe 0x2278
callq 0x11d0
movsd %xmm0, 0x40(%rsp)
movsd 0x3083(%rip), %xmm0     # 0x5110
movsd %xmm0, 0x38(%rsp)
callq 0x11d0
movsd 0x40(%rsp), %xmm1
ucomisd 0x38(%rsp), %xmm1
jae 0x20f6
movsd 0xf8a(%rip), %xmm1      # 0x3038
ucomisd %xmm0, %xmm1
jbe 0x2153
cmpl $0x0, 0xc(%rsp)
jne 0x20d6
callq 0x11d0
movsd 0xf64(%rip), %xmm1      # 0x3030
ucomisd %xmm0, %xmm1
jbe 0x220b
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 0x2278
mulsd 0xf2a(%rip), %xmm0      # 0x3028
addsd 0xf0a(%rip), %xmm0      # 0x3010
cvttsd2si %xmm0, %ebx
addl %r13d, %ebx
andl $0x3, %ebx
cmpl $0x0, 0xc(%rsp)
jne 0x212e
callq 0x11d0
movsd 0xf0c(%rip), %xmm1      # 0x3030
ucomisd %xmm0, %xmm1
jbe 0x21df
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 0x2278
xorl %ebp, %ebp
xorl %ebx, %ebx
movl %ebx, %r14d
shll $0x2, %r14d
callq 0x11d0
mulsd 0xed5(%rip), %xmm0      # 0x3040
cvttsd2si %xmm0, %ebx
orl %r14d, %ebx
cmpl $0x3, %ebp
je 0x218e
incl %ebp
callq 0x11d0
movsd 0x2f7a(%rip), %xmm1     # 0x5100
ucomisd %xmm0, %xmm1
ja 0x2157
jmp 0x2193
movl $0x4, %ebp
cmpl $0x0, 0xc(%rsp)
jne 0x21b1
callq 0x11d0
movsd 0xe89(%rip), %xmm1      # 0x3030
ucomisd %xmm0, %xmm1
jbe 0x223d
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 0x2278
orl $0xe000, %ebx           # imm = 0xE000
callq 0x11d0
xorl %eax, %eax
movsd 0xe44(%rip), %xmm1      # 0x3038
ucomisd %xmm0, %xmm1
setbe %al
movq 0x20(%rsp,%rax,8), %rax
movq 0x8(%rax), %rax
movw %bx, (%rax,%r12,2)
jmp 0x2273
callq 0x11d0
xorl %eax, %eax
movsd 0xe1e(%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 0x2278
shll $0xc, %ebp
shll $0x4, %ebx
orl %r13d, %ebp
orl %ebx, %ebp
callq 0x11d0
xorl %eax, %eax
movsd 0xde1(%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 0x1fee
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq