#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__ malloc(int);
int /*<<< orphan*/ printf(char *, int, int, int, double);
int rand();
double rand_double();
int /*<<< orphan*/ random_initByTime(int);
void init_grid(int nrows, int rmin, int rmax, int ncols, double ***grid,
               double prob) {
  int i, j;
  random_initByTime(rand() % 100);
  if (rmin == 1)
    rmin = 0;
  if (rmax == nrows)
    rmax = nrows + 1;
  printf("init-grid %d-%d %d %f\n", rmin, rmax, ncols, prob);
  for (i = rmin; i < rmax + 1; i++) {
    (*grid)[i] = (double *)malloc(sizeof(double) * (ncols + 2));
    if (prob)
      for (j = 0; j <= ncols + 1; j++)
        if (rand_double() < prob)
          (*grid)[i][j] = 1;
        else
          (*grid)[i][j] = 0;
  }
}


x86 assembly (clang, -O0):
<init_grid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1040 <random_initByTime@plt>
cmpl   $0x1,-0x8(%rbp)
jne    1194 <init_grid+0x44>
movl   $0x0,-0x8(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    11a9 <init_grid+0x59>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
movsd  -0x20(%rbp),%xmm0
lea    0xe4a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    12b8 <init_grid+0x168>
mov    -0x10(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    121c <init_grid+0xcc>
jp     121c <init_grid+0xcc>
jmp    12a5 <init_grid+0x155>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jg     12a0 <init_grid+0x150>
mov    $0x0,%al
call   1050 <rand_double@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1272 <init_grid+0x122>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  0xd98(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    128d <init_grid+0x13d>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    1292 <init_grid+0x142>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1223 <init_grid+0xd3>
jmp    12a5 <init_grid+0x155>
jmp    12aa <init_grid+0x15a>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c9 <init_grid+0x79>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_grid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %r8,%rbx
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%ebp
mov    %edi,%r13d
xor    %r12d,%r12d
xor    %eax,%eax
call   1070 <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   1040 <random_initByTime@plt>
cmp    $0x1,%ebp
cmove  %r12d,%ebp
lea    0x1(%r13),%r12d
cmp    %r13d,%r15d
cmovne %r15d,%r12d
lea    0xe52(%rip),%rdi
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r14d,%ecx
movsd  0x8(%rsp),%xmm0
call   1030 <printf@plt>
cmp    %r12d,%ebp
jle    11dd <init_grid+0x8d>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(,%r14,8),%eax
mov    %eax,0x14(%rsp)
xorpd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
setnp  %al
sete   %cl
and    %al,%cl
cmp    $0xffffffff,%r14d
setl   %r13b
add    $0x2,%r14d
movslq %ebp,%rbp
add    $0x1,%r12d
or     %cl,%r13b
jmp    1229 <init_grid+0xd9>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %ebp,%r12d
je     11ce <init_grid+0x7e>
mov    0x14(%rsp),%edi
call   1060 <malloc@plt>
mov    (%rbx),%rcx
mov    %rax,(%rcx,%rbp,8)
test   %r13b,%r13b
jne    1220 <init_grid+0xd0>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand_double@plt>
movsd  0xda1(%rip),%xmm2
movsd  0x8(%rsp),%xmm1
mov    (%rbx),%rax
mov    (%rax,%rbp,8),%rax
cmpltsd %xmm1,%xmm0
andpd  %xmm2,%xmm0
movlpd %xmm0,(%rax,%r15,8)
add    $0x1,%r15
cmp    %r15,%r14
jne    1250 <init_grid+0x100>
jmp    1220 <init_grid+0xd0>

LLVM IR (-O0):
@.str = [23 x i8] c"init-grid %d-%d %d %f\0A\00"
define void @init_grid(i32 %0, i32 %1, i32 %2, i32 %3, double*** %4, double %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double***
%12 = alloca double
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store double*** %4, double**** %11
store double %5, double* %12
%15 = call i32 (...) @rand()
%16 = srem i32 %15, 100
%17 = call i32 @random_initByTime(i32 %16)
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %21
20: ; preds = %6
store i32 0, i32* %8
br label %21
21: ; preds = %20, %6
%22 = load i32, i32* %9
%23 = load i32, i32* %7
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %9
br label %28
28: ; preds = %25, %21
%29 = load i32, i32* %8
%30 = load i32, i32* %9
%31 = load i32, i32* %10
%32 = load double, double* %12
%33 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %29, i32 %30, i32 %31, double %32)
%34 = load i32, i32* %8
store i32 %34, i32* %13
br label %35
35: ; preds = %91, %28
%36 = load i32, i32* %13
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
%39 = icmp slt i32 %36, %38
br i1 %39, label %40, label %94
40: ; preds = %35
%41 = load i32, i32* %10
%42 = add nsw i32 %41, 2
%43 = sext i32 %42 to i64
%44 = mul i64 8, %43
%45 = trunc i64 %44 to i32
%46 = call i64 @malloc(i32 %45)
%47 = inttoptr i64 %46 to double*
%48 = load double***, double**** %11
%49 = load double**, double*** %48
%50 = load i32, i32* %13
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double*, double** %49, i64 %51
store double* %47, double** %52
%53 = load double, double* %12
%54 = fcmp une double %53, 0.000000e+00
br i1 %54, label %55, label %90
55: ; preds = %40
store i32 0, i32* %14
br label %56
56: ; preds = %86, %55
%57 = load i32, i32* %14
%58 = load i32, i32* %10
%59 = add nsw i32 %58, 1
%60 = icmp sle i32 %57, %59
br i1 %60, label %61, label %89
61: ; preds = %56
%62 = call double (...) @rand_double()
%63 = load double, double* %12
%64 = fcmp olt double %62, %63
br i1 %64, label %65, label %75
65: ; preds = %61
%66 = load double***, double**** %11
%67 = load double**, double*** %66
%68 = load i32, i32* %13
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds double*, double** %67, i64 %69
%71 = load double*, double** %70
%72 = load i32, i32* %14
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds double, double* %71, i64 %73
store double 1.000000e+00, double* %74
br label %85
75: ; preds = %61
%76 = load double***, double**** %11
%77 = load double**, double*** %76
%78 = load i32, i32* %13
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds double*, double** %77, i64 %79
%81 = load double*, double** %80
%82 = load i32, i32* %14
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds double, double* %81, i64 %83
store double 0.000000e+00, double* %84
br label %85
85: ; preds = %75, %65
br label %86
86: ; preds = %85
%87 = load i32, i32* %14
%88 = add nsw i32 %87, 1
store i32 %88, i32* %14
br label %56
89: ; preds = %56
br label %90
90: ; preds = %89, %40
br label %91
91: ; preds = %90
%92 = load i32, i32* %13
%93 = add nsw i32 %92, 1
store i32 %93, i32* %13
br label %35
94: ; preds = %35
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"init-grid %d-%d %d %f\0A\00"
define void @init_grid(i32 %0, i32 %1, i32 %2, i32 %3, double*** nocapture %4, double %5) {
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 100
%9 = tail call i32 @random_initByTime(i32 %8)
%10 = icmp eq i32 %1, 1
%11 = select i1 %10, i32 0, i32 %1
%12 = icmp eq i32 %2, %0
%13 = add nsw i32 %0, 1
%14 = select i1 %12, i32 %13, i32 %2
%15 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %14, i32 %3, double %5)
%16 = icmp sgt i32 %11, %14
br i1 %16, label %48, label %17
17: ; preds = %6
%18 = shl i32 %3, 3
%19 = add i32 %18, 16
%20 = fcmp oeq double %5, 0.000000e+00
%21 = icmp slt i32 %3, -1
%22 = add i32 %3, 2
%23 = sext i32 %11 to i64
%24 = add i32 %14, 1
%25 = or i1 %20, %21
%26 = zext i32 %22 to i64
br label %27
27: ; preds = %17, %44
%28 = phi i64 [ %23, %17 ], [ %45, %44 ]
%29 = tail call i64 @malloc(i32 %19)
%30 = inttoptr i64 %29 to double*
%31 = load double**, double*** %4
%32 = getelementptr inbounds double*, double** %31, i64 %28
store double* %30, double** %32
br i1 %25, label %44, label %33
33: ; preds = %27, %33
%34 = phi i64 [ %42, %33 ], [ 0, %27 ]
%35 = tail call double (...) @rand_double()
%36 = fcmp olt double %35, %5
%37 = load double**, double*** %4
%38 = getelementptr inbounds double*, double** %37, i64 %28
%39 = load double*, double** %38
%40 = getelementptr inbounds double, double* %39, i64 %34
%41 = select i1 %36, double 1.000000e+00, double 0.000000e+00
store double %41, double* %40
%42 = add nuw nsw i64 %34, 1
%43 = icmp eq i64 %42, %26
br i1 %43, label %44, label %33
44: ; preds = %33, %27
%45 = add nsw i64 %28, 1
%46 = trunc i64 %45 to i32
%47 = icmp eq i32 %24, %46
br i1 %47, label %48, label %27
48: ; preds = %44, %6
ret void
}