#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 random_double();
double **safeMatrixAlloc(int, int);
double **uniformRandomAlloc(int n, double density) {
  int i, j;
  double **a = safeMatrixAlloc(n, n);
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (random_double() < density) {
        a[i][j] = 1.0 - (2 * random_double());
      }
    }
  }
  return a;
}


x86 assembly (clang, -O0):
<uniformRandomAlloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1030 <safeMatrixAlloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d4 <uniformRandomAlloc+0xb4>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c1 <uniformRandomAlloc+0xa1>
mov    $0x0,%al
call   1040 <random_double@plt>
cvtsi2sd %eax,%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ae <uniformRandomAlloc+0x8e>
mov    $0x0,%al
call   1040 <random_double@plt>
shl    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe6b(%rip),%xmm0
subsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    11b3 <uniformRandomAlloc+0x93>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1159 <uniformRandomAlloc+0x39>
jmp    11c6 <uniformRandomAlloc+0xa6>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1146 <uniformRandomAlloc+0x26>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uniformRandomAlloc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movsd  %xmm0,(%rsp)
mov    %edi,%ebp
mov    %edi,%esi
call   1030 <safeMatrixAlloc@plt>
mov    %rax,%r14
test   %ebp,%ebp
jle    11a9 <uniformRandomAlloc+0x89>
mov    %ebp,%ebp
xor    %r15d,%r15d
jmp    1159 <uniformRandomAlloc+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r15
cmp    %rbp,%r15
je     11a9 <uniformRandomAlloc+0x89>
xor    %ebx,%ebx
jmp    1169 <uniformRandomAlloc+0x49>
nopl   (%rax)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1150 <uniformRandomAlloc+0x30>
xor    %eax,%eax
call   1040 <random_double@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  (%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    1160 <uniformRandomAlloc+0x40>
xor    %eax,%eax
call   1040 <random_double@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xe66(%rip),%xmm1
subsd  %xmm0,%xmm1
mov    (%r14,%r15,8),%rax
movsd  %xmm1,(%rax,%rbx,8)
jmp    1160 <uniformRandomAlloc+0x40>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double** @uniformRandomAlloc(i32 %0, double %1) {
%3 = tail call double** @safeMatrixAlloc(i32 %0, i32 %0)
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %28
5: ; preds = %2
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %25, %5
%8 = phi i64 [ 0, %5 ], [ %26, %25 ]
%9 = getelementptr inbounds double*, double** %3, i64 %8
br label %10
10: ; preds = %7, %22
%11 = phi i64 [ 0, %7 ], [ %23, %22 ]
%12 = tail call i32 (...) @random_double()
%13 = sitofp i32 %12 to double
%14 = fcmp olt double %13, %1
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = tail call i32 (...) @random_double()
%17 = shl nsw i32 %16, 1
%18 = sitofp i32 %17 to double
%19 = fsub double 1.000000e+00, %18
%20 = load double*, double** %9
%21 = getelementptr inbounds double, double* %20, i64 %11
store double %19, double* %21
br label %22
22: ; preds = %10, %15
%23 = add nuw nsw i64 %11, 1
%24 = icmp eq i64 %23, %6
br i1 %24, label %25, label %10
25: ; preds = %22
%26 = add nuw nsw i64 %8, 1
%27 = icmp eq i64 %26, %6
br i1 %27, label %28, label %7
28: ; preds = %25, %2
ret double** %3
}