#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 */
int rand();
double rand_double();
int /*<<< orphan*/ random_initByTime(int);
void randomize_grid(int nrows, int ncols, double **grid, double prob) {
  int i, j;
  random_initByTime(rand() % 100);
  for (i = 1; i <= nrows; i++)
    for (j = 1; j <= ncols; j++)
      if (rand_double() < prob)
        grid[i][j] = 1.0;
      else
        grid[i][j] = 0.0;
}


x86 assembly (clang, -O0):
<randomize_grid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <random_initByTime@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11fc <randomize_grid+0xcc>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11e9 <randomize_grid+0xb9>
mov    $0x0,%al
call   1040 <rand_double@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11be <randomize_grid+0x8e>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movsd  0xe4c(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    11d6 <randomize_grid+0xa6>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    11db <randomize_grid+0xab>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1177 <randomize_grid+0x47>
jmp    11ee <randomize_grid+0xbe>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1164 <randomize_grid+0x34>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomize_grid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movsd  %xmm0,(%rsp)
mov    %rdx,%r12
mov    %esi,%r14d
mov    %edi,%r15d
xor    %eax,%eax
call   1050 <rand@plt>
movslq %eax,%rdi
imul   $0x51eb851f,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%edi
call   1030 <random_initByTime@plt>
test   %r15d,%r15d
jle    11e1 <randomize_grid+0xb1>
lea    0x1(%r14),%r13d
add    $0x1,%r15d
mov    $0x1,%ebx
jmp    1199 <randomize_grid+0x69>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
cmp    %r15,%rbx
je     11e1 <randomize_grid+0xb1>
test   %r14d,%r14d
jle    1190 <randomize_grid+0x60>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <rand_double@plt>
movsd  (%rsp),%xmm2
movsd  0xe3c(%rip),%xmm1
mov    (%r12,%rbx,8),%rax
cmpltsd %xmm2,%xmm0
andpd  %xmm1,%xmm0
movlpd %xmm0,(%rax,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r13
jne    11b0 <randomize_grid+0x80>
jmp    1190 <randomize_grid+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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