#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double RAND_MAX;
scalar_t__ rand();
void mutate(char genes[16]) {
  for (int i = 0; i < 16; ++i) {
    if (((double)rand() / RAND_MAX) < 0.001) {
      int x = (int)(((double)rand() / RAND_MAX) * 4);
      char gene = genes[i];
      gene ^= 1 << x;
      genes[i] = gene;
    }
  }
}


x86 assembly (clang, -O0):
<mutate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x10,-0xc(%rbp)
jge    11c4 <mutate+0xb4>
mov    $0x0,%al
call   1030 <rand@plt>
cvtsi2sd %rax,%xmm1
mov    0x2ea8(%rip),%rax
divsd  (%rax),%xmm1
movsd  0xeb4(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11b1 <mutate+0xa1>
mov    $0x0,%al
call   1030 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e7f(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xe93(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
movsbl -0x11(%rbp),%eax
xor    %ecx,%eax
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11b6 <mutate+0xa6>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <mutate+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mutate>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2ec9(%rip),%r15
xor    %ebx,%ebx
jmp    113a <mutate+0x2a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
cmp    $0x10,%rbx
je     1189 <mutate+0x79>
xor    %eax,%eax
call   1030 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r15),%xmm0
movsd  0xeaa(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1130 <mutate+0x20>
xor    %eax,%eax
call   1030 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r15),%xmm0
mulsd  0xe90(%rip),%xmm0
cvttsd2si %xmm0,%ecx
mov    $0x1,%eax
shl    %cl,%eax
xor    %al,(%r14,%rbx,1)
jmp    1130 <mutate+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define void @mutate(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i8* %0, i8** %2
store i32 0, i32* %3
br label %6
6: ; preds = %39, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 16
br i1 %8, label %9, label %42
9: ; preds = %6
%10 = call i64 (...) @rand()
%11 = sitofp i64 %10 to double
%12 = load double, double* @RAND_MAX
%13 = fdiv double %11, %12
%14 = fcmp olt double %13, 1.000000e-03
br i1 %14, label %15, label %38
15: ; preds = %9
%16 = call i64 (...) @rand()
%17 = sitofp i64 %16 to double
%18 = load double, double* @RAND_MAX
%19 = fdiv double %17, %18
%20 = fmul double %19, 4.000000e+00
%21 = fptosi double %20 to i32
store i32 %21, i32* %4
%22 = load i8*, i8** %2
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
store i8 %26, i8* %5
%27 = load i32, i32* %4
%28 = shl i32 1, %27
%29 = load i8, i8* %5
%30 = sext i8 %29 to i32
%31 = xor i32 %30, %28
%32 = trunc i32 %31 to i8
store i8 %32, i8* %5
%33 = load i8, i8* %5
%34 = load i8*, i8** %2
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 %33, i8* %37
br label %38
38: ; preds = %15, %9
br label %39
39: ; preds = %38
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %6
42: ; preds = %6
ret void
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define void @mutate(i8* nocapture %0) {
br label %3
2: ; preds = %22
ret void
3: ; preds = %1, %22
%4 = phi i64 [ 0, %1 ], [ %23, %22 ]
%5 = tail call i64 (...) @rand()
%6 = sitofp i64 %5 to double
%7 = load double, double* @RAND_MAX
%8 = fdiv double %6, %7
%9 = fcmp olt double %8, 1.000000e-03
br i1 %9, label %10, label %22
10: ; preds = %3
%11 = tail call i64 (...) @rand()
%12 = sitofp i64 %11 to double
%13 = load double, double* @RAND_MAX
%14 = fdiv double %12, %13
%15 = fmul double %14, 4.000000e+00
%16 = fptosi double %15 to i32
%17 = getelementptr inbounds i8, i8* %0, i64 %4
%18 = load i8, i8* %17
%19 = shl nuw i32 1, %16
%20 = trunc i32 %19 to i8
%21 = xor i8 %18, %20
store i8 %21, i8* %17
br label %22
22: ; preds = %3, %10
%23 = add nuw nsw i64 %4, 1
%24 = icmp eq i64 %23, 16
br i1 %24, label %2, label %3
}