#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, short **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;
}


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     11d8 <randomize_grid+0xa8>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11c5 <randomize_grid+0x95>
mov    $0x0,%al
call   1040 <rand_double@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11b2 <randomize_grid+0x82>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movw   $0x1,(%rax,%rcx,2)
jmp    11b7 <randomize_grid+0x87>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1177 <randomize_grid+0x47>
jmp    11ca <randomize_grid+0x9a>
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    11d7 <randomize_grid+0xa7>
lea    0x1(%r14),%ebx
add    $0x1,%r15d
mov    $0x1,%r13d
jmp    1199 <randomize_grid+0x69>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r13
cmp    %r15,%r13
je     11d7 <randomize_grid+0xa7>
test   %r14d,%r14d
jle    1190 <randomize_grid+0x60>
mov    $0x1,%ebp
jmp    11b9 <randomize_grid+0x89>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbp
cmp    %rbp,%rbx
je     1190 <randomize_grid+0x60>
xor    %eax,%eax
call   1040 <rand_double@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    11b0 <randomize_grid+0x80>
mov    (%r12,%r13,8),%rax
movw   $0x1,(%rax,%rbp,2)
jmp    11b0 <randomize_grid+0x80>
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, i16** %2, double %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i16**
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i16** %2, i16*** %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 = %41, %4
%15 = load i32, i32* %9
%16 = load i32, i32* %5
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %44
18: ; preds = %14
store i32 1, i32* %10
br label %19
19: ; preds = %37, %18
%20 = load i32, i32* %10
%21 = load i32, i32* %6
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %40
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 i16**, i16*** %7
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i16*, i16** %28, i64 %30
%32 = load i16*, i16** %31
%33 = load i32, i32* %10
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i16, i16* %32, i64 %34
store i16 1, i16* %35
br label %36
36: ; preds = %27, %23
br label %37
37: ; preds = %36
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %19
40: ; preds = %19
br label %41
41: ; preds = %40
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %14
44: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @randomize_grid(i32 %0, i32 %1, i16** 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 %32, 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, %29
%16 = phi i64 [ 1, %9 ], [ %30, %29 ]
br i1 %10, label %29, label %17
17: ; preds = %15
%18 = getelementptr inbounds i16*, i16** %2, i64 %16
br label %19
19: ; preds = %17, %26
%20 = phi i64 [ 1, %17 ], [ %27, %26 ]
%21 = tail call double (...) @rand_double()
%22 = fcmp olt double %21, %3
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i16*, i16** %18
%25 = getelementptr inbounds i16, i16* %24, i64 %20
store i16 1, i16* %25
br label %26
26: ; preds = %19, %23
%27 = add nuw nsw i64 %20, 1
%28 = icmp eq i64 %27, %14
br i1 %28, label %29, label %19
29: ; preds = %26, %15
%30 = add nuw nsw i64 %16, 1
%31 = icmp eq i64 %30, %13
br i1 %31, label %32, label %15
32: ; preds = %29, %4
ret void
}