#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();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void random_population(int **cells, int nx, int ny, double ratio) {
  int i, j;
  srand(time(NULL));
  for (i = 0; i < nx; i++) {
    for (j = 0; j < ny; j++) {
      if ((double)rand() / RAND_MAX < ratio)
        cells[i][j] = 1;
      else
        cells[i][j] = 0;
    }
  }
}


x86 assembly (clang, -O0):
<random_population>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11fc <random_population+0xcc>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11e9 <random_population+0xb9>
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm1
mov    0x2e58(%rip),%rax
divsd  (%rax),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11bf <random_population+0x8f>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    11d6 <random_population+0xa6>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    11db <random_population+0xab>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1171 <random_population+0x41>
jmp    11ee <random_population+0xbe>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115e <random_population+0x2e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_population>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movsd  %xmm0,0x10(%rsp)
mov    %edx,0xc(%rsp)
mov    %esi,%r14d
mov    %rdi,%r13
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
test   %r14d,%r14d
jle    11d8 <random_population+0xa8>
mov    %r14d,%r14d
mov    0xc(%rsp),%ebp
mov    0x2e79(%rip),%r12
xor    %ebx,%ebx
jmp    1189 <random_population+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
cmp    %r14,%rbx
je     11d8 <random_population+0xa8>
cmpl   $0x0,0xc(%rsp)
jle    1180 <random_population+0x50>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r12),%xmm0
xor    %eax,%eax
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
seta   %al
mov    0x0(%r13,%rbx,8),%rcx
mov    %eax,(%rcx,%r15,4)
add    $0x1,%r15
cmp    %r15,%rbp
jne    11a0 <random_population+0x70>
jmp    1180 <random_population+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define void @random_population(i32** %0, i32 %1, i32 %2, double %3) {
%5 = alloca i32**
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
store i32** %0, i32*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store double %3, double* %8
%11 = call i32 @time(i32* null)
%12 = call i32 @srand(i32 %11)
store i32 0, i32* %9
br label %13
13: ; preds = %52, %4
%14 = load i32, i32* %9
%15 = load i32, i32* %6
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %55
17: ; preds = %13
store i32 0, i32* %10
br label %18
18: ; preds = %48, %17
%19 = load i32, i32* %10
%20 = load i32, i32* %7
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %51
22: ; preds = %18
%23 = call i64 (...) @rand()
%24 = sitofp i64 %23 to double
%25 = load double, double* @RAND_MAX
%26 = fdiv double %24, %25
%27 = load double, double* %8
%28 = fcmp olt double %26, %27
br i1 %28, label %29, label %38
29: ; preds = %22
%30 = load i32**, i32*** %5
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32*, i32** %30, i64 %32
%34 = load i32*, i32** %33
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
store i32 1, i32* %37
br label %47
38: ; preds = %22
%39 = load i32**, i32*** %5
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32*, i32** %39, i64 %41
%43 = load i32*, i32** %42
%44 = load i32, i32* %10
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
store i32 0, i32* %46
br label %47
47: ; preds = %38, %29
br label %48
48: ; preds = %47
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
store i32 %50, i32* %10
br label %18
51: ; preds = %18
br label %52
52: ; preds = %51
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
store i32 %54, i32* %9
br label %13
55: ; preds = %13
ret void
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define void @random_population(i32** nocapture %0, i32 %1, i32 %2, double %3) {
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %31
8: ; preds = %4
%9 = icmp sgt i32 %2, 0
%10 = zext i32 %1 to i64
%11 = zext i32 %2 to i64
br label %12
12: ; preds = %8, %28
%13 = phi i64 [ 0, %8 ], [ %29, %28 ]
br i1 %9, label %14, label %28
14: ; preds = %12
%15 = getelementptr inbounds i32*, i32** %0, i64 %13
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 0, %14 ], [ %26, %16 ]
%18 = tail call i64 (...) @rand()
%19 = sitofp i64 %18 to double
%20 = load double, double* @RAND_MAX
%21 = fdiv double %19, %20
%22 = fcmp olt double %21, %3
%23 = load i32*, i32** %15
%24 = getelementptr inbounds i32, i32* %23, i64 %17
%25 = zext i1 %22 to i32
store i32 %25, i32* %24
%26 = add nuw nsw i64 %17, 1
%27 = icmp eq i64 %26, %11
br i1 %27, label %28, label %16
28: ; preds = %16, %12
%29 = add nuw nsw i64 %13, 1
%30 = icmp eq i64 %29, %10
br i1 %30, label %31, label %12
31: ; preds = %28, %4
ret void
}