#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 */
scalar_t__ RAND_MAX;
int pow(int, int);
double random();
void simuKimmel(int nGen, double mutRate, int *mutants) {
  int cell = 0, total, gen, j;
  total = 1;
  for (gen = 0; gen < nGen; gen++) {
    cell = total;
    total = 0;
    for (j = 0; j < (2 * cell); j++) {
      double mu = random() / ((double)RAND_MAX + 1);
      if (mu > mutRate) {
        total++;
      }
    }
  }
  *mutants = pow(2, nGen) - total;
}


x86 assembly (clang, -O0):
<simuKimmel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11e1 <simuKimmel+0xc1>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jge    11ce <simuKimmel+0xae>
mov    $0x0,%al
call   1030 <random@plt>
mov    0x2e60(%rip),%rax
cvtsi2sdq (%rax),%xmm1
movsd  0xe6b(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11bb <simuKimmel+0x9b>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c0 <simuKimmel+0xa0>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1169 <simuKimmel+0x49>
jmp    11d3 <simuKimmel+0xb3>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1149 <simuKimmel+0x29>
mov    -0x4(%rbp),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
mov    %eax,%ecx
sub    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simuKimmel>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x8(%rsp)
mov    %edi,%r12d
test   %edi,%edi
jle    11c4 <simuKimmel+0xa4>
mov    $0x1,%r15d
mov    0x2e9d(%rip),%rbx
xor    %r13d,%r13d
mov    $0x1,%ebp
movsd  %xmm0,0x10(%rsp)
jmp    116c <simuKimmel+0x4c>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13d
mov    %r14d,%ebp
cmp    %r12d,%r13d
je     11ca <simuKimmel+0xaa>
mov    $0x0,%r14d
test   %ebp,%ebp
jle    1160 <simuKimmel+0x40>
add    %ebp,%ebp
cmp    $0x2,%ebp
cmovl  %r15d,%ebp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <random@plt>
movsd  0xe61(%rip),%xmm2
xorps  %xmm1,%xmm1
cvtsi2sdq (%rbx),%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
xor    %eax,%eax
ucomisd 0x10(%rsp),%xmm0
seta   %al
add    %eax,%r14d
add    $0xffffffff,%ebp
jne    1190 <simuKimmel+0x70>
jmp    1160 <simuKimmel+0x40>
mov    $0x1,%r14d
mov    $0x2,%edi
mov    %r12d,%esi
call   1040 <pow@plt>
sub    %r14d,%eax
mov    0x8(%rsp),%rcx
mov    %eax,(%rcx)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define void @simuKimmel(i32 %0, double %1, i32* %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
store i32 %0, i32* %4
store double %1, double* %5
store i32* %2, i32** %6
store i32 0, i32* %7
store i32 1, i32* %8
store i32 0, i32* %9
br label %12
12: ; preds = %40, %3
%13 = load i32, i32* %9
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %43
16: ; preds = %12
%17 = load i32, i32* %8
store i32 %17, i32* %7
store i32 0, i32* %8
store i32 0, i32* %10
br label %18
18: ; preds = %36, %16
%19 = load i32, i32* %10
%20 = load i32, i32* %7
%21 = mul nsw i32 2, %20
%22 = icmp slt i32 %19, %21
br i1 %22, label %23, label %39
23: ; preds = %18
%24 = call double (...) @random()
%25 = load i64, i64* @RAND_MAX
%26 = sitofp i64 %25 to double
%27 = fadd double %26, 1.000000e+00
%28 = fdiv double %24, %27
store double %28, double* %11
%29 = load double, double* %11
%30 = load double, double* %5
%31 = fcmp ogt double %29, %30
br i1 %31, label %32, label %35
32: ; preds = %23
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
br label %35
35: ; preds = %32, %23
br label %36
36: ; preds = %35
%37 = load i32, i32* %10
%38 = add nsw i32 %37, 1
store i32 %38, i32* %10
br label %18
39: ; preds = %18
br label %40
40: ; preds = %39
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
br label %12
43: ; preds = %12
%44 = load i32, i32* %4
%45 = call i32 @pow(i32 2, i32 %44)
%46 = load i32, i32* %8
%47 = sub nsw i32 %45, %46
%48 = load i32*, i32** %6
store i32 %47, i32* %48
ret void
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define void @simuKimmel(i32 %0, double %1, i32* nocapture writeonly %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %29
5: ; preds = %3, %25
%6 = phi i32 [ %27, %25 ], [ 0, %3 ]
%7 = phi i32 [ %26, %25 ], [ 1, %3 ]
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %25
9: ; preds = %5
%10 = shl nuw i32 %7, 1
%11 = call i32 @llvm.smax.i32(i32 %10, i32 1)
br label %12
12: ; preds = %9, %12
%13 = phi i32 [ %23, %12 ], [ 0, %9 ]
%14 = phi i32 [ %22, %12 ], [ 0, %9 ]
%15 = tail call double (...) @random()
%16 = load i64, i64* @RAND_MAX
%17 = sitofp i64 %16 to double
%18 = fadd double %17, 1.000000e+00
%19 = fdiv double %15, %18
%20 = fcmp ogt double %19, %1
%21 = zext i1 %20 to i32
%22 = add nuw nsw i32 %14, %21
%23 = add nuw nsw i32 %13, 1
%24 = icmp eq i32 %23, %11
br i1 %24, label %25, label %12
25: ; preds = %12, %5
%26 = phi i32 [ 0, %5 ], [ %22, %12 ]
%27 = add nuw nsw i32 %6, 1
%28 = icmp eq i32 %27, %0
br i1 %28, label %29, label %5
29: ; preds = %25, %3
%30 = phi i32 [ 1, %3 ], [ %26, %25 ]
%31 = tail call i32 @pow(i32 2, i32 %0)
%32 = sub nsw i32 %31, %30
store i32 %32, i32* %2
ret void
}