#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();
void init_array(double **m, int dim, int value) {
  int row, col;
  for (row = 0; row < dim; row++) {
    for (col = 0; col < dim; col++) {
      m[row][col] = (value == 0) ? 0 : rand() % 10000;
    }
  }
}


x86 assembly (clang, -O0):
<init_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ab <init_array+0x9b>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1198 <init_array+0x88>
cmpl   $0x0,-0x10(%rbp)
jne    115c <init_array+0x4c>
xor    %edx,%edx
mov    %edx,-0x1c(%rbp)
jmp    116e <init_array+0x5e>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cvtsi2sd %eax,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113c <init_array+0x2c>
jmp    119d <init_array+0x8d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <init_array+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_array>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
jle    1187 <init_array+0x77>
mov    %edx,%r14d
mov    %rdi,%r15
mov    %esi,%r12d
xor    %ebx,%ebx
jmp    1139 <init_array+0x29>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %r12,%rbx
je     1187 <init_array+0x77>
xor    %ebp,%ebp
jmp    117e <init_array+0x6e>
nopl   (%rax)
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0x68db8bad,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rcx
add    %edx,%ecx
imul   $0x2710,%ecx,%ecx
sub    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    (%r15,%rbx,8),%rax
movsd  %xmm0,(%rax,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r12
je     1130 <init_array+0x20>
test   %r14d,%r14d
jne    1140 <init_array+0x30>
xor    %eax,%eax
jmp    1165 <init_array+0x55>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @init_array(double** %0, i32 %1, i32 %2) {
%4 = alloca double**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store double** %0, double*** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %40, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %43
13: ; preds = %9
store i32 0, i32* %8
br label %14
14: ; preds = %36, %13
%15 = load i32, i32* %8
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %39
18: ; preds = %14
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18
br label %25
22: ; preds = %18
%23 = call i32 (...) @rand()
%24 = srem i32 %23, 10000
br label %25
25: ; preds = %22, %21
%26 = phi i32 [ 0, %21 ], [ %24, %22 ]
%27 = sitofp i32 %26 to double
%28 = load double**, double*** %4
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double*, double** %28, i64 %30
%32 = load double*, double** %31
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
store double %27, double* %35
br label %36
36: ; preds = %25
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %14
39: ; preds = %14
br label %40
40: ; preds = %39
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %9
43: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @init_array(double** nocapture %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %26
5: ; preds = %3
%6 = icmp eq i32 %2, 0
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %23, %5
%9 = phi i64 [ 0, %5 ], [ %24, %23 ]
%10 = getelementptr inbounds double*, double** %0, i64 %9
br label %11
11: ; preds = %8, %16
%12 = phi i64 [ 0, %8 ], [ %21, %16 ]
br i1 %6, label %16, label %13
13: ; preds = %11
%14 = tail call i32 (...) @rand()
%15 = srem i32 %14, 10000
br label %16
16: ; preds = %11, %13
%17 = phi i32 [ %15, %13 ], [ 0, %11 ]
%18 = sitofp i32 %17 to double
%19 = load double*, double** %10
%20 = getelementptr inbounds double, double* %19, i64 %12
store double %18, double* %20
%21 = add nuw nsw i64 %12, 1
%22 = icmp eq i64 %21, %7
br i1 %22, label %23, label %11
23: ; preds = %16
%24 = add nuw nsw i64 %9, 1
%25 = icmp eq i64 %24, %7
br i1 %25, label %26, label %8
26: ; preds = %23, %3
ret void
}