// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/extended/mutate.c
// Function: mutate_seq
static char* mutate_seq(const char *seq, GtUword len,
                        GtAlphabet *alphabet, unsigned int rate)
{
  GtUword i, j, allocated, substitution_events = 0, insertion_events = 0,
                deletion_events = 0, total_events = 0;
  double rand_prob, mutate_prob;
  char *mutated_seq;
  bool was_upper;
  gt_assert(seq && alphabet);
  gt_assert(rate <= 100);
  mutate_prob = (double) rate / 100.0;
  allocated = len * 2; /* XXX: possibly reduce this memory consumption */
  mutated_seq = gt_malloc(sizeof (char) * allocated);
  for (i = 0, j = 0; i < len; /* Nothing */) {
    if (isupper(seq[i]))
      was_upper = true;
    else
      was_upper = false;
    if (gt_rand_0_to_1() <= mutate_prob) {
      /* mutate */
      rand_prob = gt_rand_0_to_1();
      if (rand_prob <= 0.8) {
        /* substitution (80% probability) */
        mutated_seq[j++] = random_character(alphabet, was_upper);
        substitution_events++;
        i++;
      }
      else if (rand_prob <= 0.9) {
        /* insertion (10% probability) */
        mutated_seq[j++] = random_character(alphabet, was_upper);
        insertion_events++;
      }
      else {
      /* deletion (10% probability) */
        i++;
        deletion_events++;
      }
      total_events++;
    }
    else
      mutated_seq[j++] = seq[i++]; /* keep original character */
  }
  mutated_seq[j] = '\0'; /* terminate */
  gt_log_log("total number of mutation events: " GT_WU, total_events);
  gt_log_log("number of substitution events: " GT_WU, substitution_events);
  gt_log_log("number of insertion events: " GT_WU, insertion_events);
  gt_log_log("number of deletion events: " GT_WU, deletion_events);
  return mutated_seq;
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movl %ecx, 0x5c(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
cmpq $0x0, 0x70(%rsp)
je 0x1b17ab
cmpq $0x0, 0x60(%rsp)
jne 0x1b17e3
movq 0x48a7ee(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x364857(%rip), %rsi    # 0x516013
leaq 0x3ae3b9(%rip), %rdx    # 0x55fb7c
leaq 0x3ae3c5(%rip), %rcx    # 0x55fb8f
leaq 0x3ae3c9(%rip), %r8     # 0x55fb9a
movl $0x41, %r9d
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x1b17e5
jmp 0x1b17e7
cmpl $0x64, 0x5c(%rsp)
jbe 0x1b1826
movq 0x48a7ab(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x364814(%rip), %rsi    # 0x516013
leaq 0x3ae3aa(%rip), %rdx    # 0x55fbb0
leaq 0x3ae382(%rip), %rcx    # 0x55fb8f
leaq 0x3ae386(%rip), %r8     # 0x55fb9a
movl $0x42, %r9d
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x1b1828
movl 0x5c(%rsp), %eax
cvtsi2sd %rax, %xmm0
movsd 0x368fff(%rip), %xmm1   # 0x51a838
divsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x68(%rsp), %rax
shlq %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rdi
shlq $0x0, %rdi
leaq 0x3ae33a(%rip), %rsi    # 0x55fb9a
movl $0x45, %edx
callq 0xe80f0
movq %rax, 0x8(%rsp)
movq $0x0, 0x50(%rsp)
movq $0x0, 0x48(%rsp)
movq 0x50(%rsp), %rax
cmpq 0x68(%rsp), %rax
jae 0x1b19f6
callq 0x197c0
movq (%rax), %rax
movq 0x70(%rsp), %rcx
movq 0x50(%rsp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x1b18bf
movb $0x1, 0x7(%rsp)
jmp 0x1b18c4
movb $0x0, 0x7(%rsp)
callq 0xec560
movaps %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x1b19bf
callq 0xec560
movsd %xmm0, 0x18(%rsp)
movsd 0x36d969(%rip), %xmm0   # 0x51f258
ucomisd 0x18(%rsp), %xmm0
jb 0x1b1943
movq 0x60(%rsp), %rdi
movb 0x7(%rsp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x1b1a60
movb %al, %dl
movq 0x8(%rsp), %rax
movq 0x48(%rsp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x48(%rsp)
movb %dl, (%rax,%rcx)
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x1b19af
movsd 0x3ae215(%rip), %xmm0   # 0x55fb60
ucomisd 0x18(%rsp), %xmm0
jb 0x1b1991
movq 0x60(%rsp), %rdi
movb 0x7(%rsp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x1b1a60
movb %al, %dl
movq 0x8(%rsp), %rax
movq 0x48(%rsp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x48(%rsp)
movb %dl, (%rax,%rcx)
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0x1b19ad
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x1b19af
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
jmp 0x1b19f1
movq 0x70(%rsp), %rax
movq 0x50(%rsp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x50(%rsp)
movb (%rax,%rcx), %dl
movq 0x8(%rsp), %rax
movq 0x48(%rsp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x48(%rsp)
movb %dl, (%rax,%rcx)
jmp 0x1b1881
movq 0x8(%rsp), %rax
movq 0x48(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x20(%rsp), %rsi
leaq 0x3ae1fb(%rip), %rdi    # 0x55fc0b
movb $0x0, %al
callq 0xe7740
movq 0x38(%rsp), %rsi
leaq 0x3ae20d(%rip), %rdi    # 0x55fc30
movb $0x0, %al
callq 0xe7740
movq 0x30(%rsp), %rsi
leaq 0x3ae21d(%rip), %rdi    # 0x55fc53
movb $0x0, %al
callq 0xe7740
movq 0x28(%rsp), %rsi
leaq 0x3ae22a(%rip), %rdi    # 0x55fc73
movb $0x0, %al
callq 0xe7740
movq 0x8(%rsp), %rax
addq $0x78, %rsp
retq
nopw (%rax,%rax)