#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__ calloc(int, int);
double rand();
int **initialize_state(int cols, int rows, double prob) {
  int i;
  int j;
  int **a;
  a = (int **)calloc(rows, sizeof(int *));
  for (i = 0; i < rows; i++) {
    a[i] = (int *)calloc(cols, sizeof(int));
  }
  for (i = 0; i < rows; i++) {
    for (j = 0; j < cols; j++) {
      a[i][j] = (rand() < RAND_MAX * prob) ? 1 : 0;
    }
  }
  a[rows / 2][cols / 2] = 2;
  return a;
}


x86 assembly (clang, -O0):
<initialize_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1181 <initialize_state+0x61>
mov    -0x4(%rbp),%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114b <initialize_state+0x2b>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1203 <initialize_state+0xe3>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11f0 <initialize_state+0xd0>
mov    $0x0,%al
call   1040 <rand@plt>
movaps %xmm0,%xmm1
mov    0x2e30(%rip),%rax
movsd  (%rax),%xmm0
mulsd  -0x10(%rbp),%xmm0
xor    %edx,%edx
mov    $0x1,%eax
ucomisd %xmm1,%xmm0
cmova  %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119b <initialize_state+0x7b>
jmp    11f5 <initialize_state+0xd5>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1188 <initialize_state+0x68>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
movl   $0x2,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initialize_state>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movsd  %xmm0,0x10(%rsp)
mov    %esi,%ebp
mov    %edi,%r15d
mov    %esi,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%rbx
mov    %ebp,0x4(%rsp)
test   %ebp,%ebp
jle    11f3 <initialize_state+0xd3>
mov    0x4(%rsp),%r14d
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1160 <initialize_state+0x40>
mov    %r14,0x8(%rsp)
cmpl   $0x0,0x4(%rsp)
jle    11f3 <initialize_state+0xd3>
mov    %r15d,%ebp
mov    0x2e58(%rip),%r13
xor    %r14d,%r14d
jmp    11ae <initialize_state+0x8e>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r14
cmp    0x8(%rsp),%r14
mov    %r12d,%r15d
je     11f3 <initialize_state+0xd3>
mov    %r15d,%r12d
test   %r15d,%r15d
jle    11a0 <initialize_state+0x80>
xor    %r15d,%r15d
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <rand@plt>
movsd  0x10(%rsp),%xmm2
movsd  0x0(%r13),%xmm1
mulsd  %xmm2,%xmm1
xor    %eax,%eax
ucomisd %xmm0,%xmm1
seta   %al
mov    (%rbx,%r14,8),%rcx
mov    %eax,(%rcx,%r15,4)
add    $0x1,%r15
cmp    %r15,%rbp
jne    11c0 <initialize_state+0xa0>
jmp    11a0 <initialize_state+0x80>
mov    0x4(%rsp),%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
add    %ecx,%eax
sar    %eax
cltq
mov    (%rbx,%rax,8),%rax
mov    %r15d,%ecx
shr    $0x1f,%ecx
add    %r15d,%ecx
sar    %ecx
movslq %ecx,%rcx
movl   $0x2,(%rax,%rcx,4)
mov    %rbx,%rax
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 i32** @initialize_state(i32 %0, i32 %1, double %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32**
store i32 %0, i32* %4
store i32 %1, i32* %5
store double %2, double* %6
%10 = load i32, i32* %5
%11 = call i64 @calloc(i32 %10, i32 8)
%12 = inttoptr i64 %11 to i32**
store i32** %12, i32*** %9
store i32 0, i32* %7
br label %13
13: ; preds = %25, %3
%14 = load i32, i32* %7
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = load i32, i32* %4
%19 = call i64 @calloc(i32 %18, i32 4)
%20 = inttoptr i64 %19 to i32*
%21 = load i32**, i32*** %9
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32*, i32** %21, i64 %23
store i32* %20, i32** %24
br label %25
25: ; preds = %17
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %13
28: ; preds = %13
store i32 0, i32* %7
br label %29
29: ; preds = %58, %28
%30 = load i32, i32* %7
%31 = load i32, i32* %5
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %61
33: ; preds = %29
store i32 0, i32* %8
br label %34
34: ; preds = %54, %33
%35 = load i32, i32* %8
%36 = load i32, i32* %4
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %57
38: ; preds = %34
%39 = call double (...) @rand()
%40 = load double, double* @RAND_MAX
%41 = load double, double* %6
%42 = fmul double %40, %41
%43 = fcmp olt double %39, %42
%44 = zext i1 %43 to i64
%45 = select i1 %43, i32 1, i32 0
%46 = load i32**, i32*** %9
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32*, i32** %46, i64 %48
%50 = load i32*, i32** %49
%51 = load i32, i32* %8
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %50, i64 %52
store i32 %45, i32* %53
br label %54
54: ; preds = %38
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
store i32 %56, i32* %8
br label %34
57: ; preds = %34
br label %58
58: ; preds = %57
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
br label %29
61: ; preds = %29
%62 = load i32**, i32*** %9
%63 = load i32, i32* %5
%64 = sdiv i32 %63, 2
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32*, i32** %62, i64 %65
%67 = load i32*, i32** %66
%68 = load i32, i32* %4
%69 = sdiv i32 %68, 2
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i32, i32* %67, i64 %70
store i32 2, i32* %71
%72 = load i32**, i32*** %9
ret i32** %72
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define i32** @initialize_state(i32 %0, i32 %1, double %2) {
%4 = tail call i64 @calloc(i32 %1, i32 8)
%5 = inttoptr i64 %4 to i32**
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %39
7: ; preds = %3
%8 = zext i32 %1 to i64
br label %14
9: ; preds = %14
br i1 %6, label %10, label %39
10: ; preds = %9
%11 = icmp sgt i32 %0, 0
%12 = zext i32 %1 to i64
%13 = zext i32 %0 to i64
br label %21
14: ; preds = %7, %14
%15 = phi i64 [ 0, %7 ], [ %19, %14 ]
%16 = tail call i64 @calloc(i32 %0, i32 4)
%17 = inttoptr i64 %16 to i32*
%18 = getelementptr inbounds i32*, i32** %5, i64 %15
store i32* %17, i32** %18
%19 = add nuw nsw i64 %15, 1
%20 = icmp eq i64 %19, %8
br i1 %20, label %9, label %14
21: ; preds = %10, %36
%22 = phi i64 [ 0, %10 ], [ %37, %36 ]
br i1 %11, label %23, label %36
23: ; preds = %21
%24 = getelementptr inbounds i32*, i32** %5, i64 %22
br label %25
25: ; preds = %23, %25
%26 = phi i64 [ 0, %23 ], [ %34, %25 ]
%27 = tail call double (...) @rand()
%28 = load double, double* @RAND_MAX
%29 = fmul double %28, %2
%30 = fcmp olt double %27, %29
%31 = zext i1 %30 to i32
%32 = load i32*, i32** %24
%33 = getelementptr inbounds i32, i32* %32, i64 %26
store i32 %31, i32* %33
%34 = add nuw nsw i64 %26, 1
%35 = icmp eq i64 %34, %13
br i1 %35, label %36, label %25
36: ; preds = %25, %21
%37 = add nuw nsw i64 %22, 1
%38 = icmp eq i64 %37, %12
br i1 %38, label %39, label %21
39: ; preds = %36, %3, %9
%40 = sdiv i32 %1, 2
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32*, i32** %5, i64 %41
%43 = load i32*, i32** %42
%44 = sdiv i32 %0, 2
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
store i32 2, i32* %46
ret i32** %5
}