#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 lrand48();
void qh_randommatrix(double *buffer, int dim, double **row) {
  int i, k;
  double **rowi, *coord, realr;
  coord = buffer;
  rowi = row;
  for (i = 0; i < dim; i++) {
    *(rowi++) = coord;
    for (k = 0; k < dim; k++) {
      realr = lrand48();
      *(coord++) = 2.0 * realr / (((double)0x7fffffffUL) + 1) - 1.0;
    }
  }
  *rowi = coord;
}


x86 assembly (clang, -O0):
<qh_randommatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d4 <qh_randommatrix+0xc4>
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x28(%rbp)
mov    %rcx,(%rax)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c1 <qh_randommatrix+0xb1>
mov    $0x0,%al
call   1030 <lrand48@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  0xe8d(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  0xe78(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe64(%rip),%xmm1
subsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x30(%rbp)
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1163 <qh_randommatrix+0x53>
jmp    11c6 <qh_randommatrix+0xb6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113a <qh_randommatrix+0x2a>
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qh_randommatrix>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rdi,%rbx
test   %esi,%esi
jle    1179 <qh_randommatrix+0x69>
mov    %esi,%r15d
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
mov    %rbx,(%r14)
add    $0x8,%r14
mov    %r15d,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <lrand48@plt>
movsd  0xeb1(%rip),%xmm1
addsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xea9(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx)
add    $0x8,%rbx
add    $0xffffffff,%ebp
jne    1140 <qh_randommatrix+0x30>
add    $0x1,%r12d
cmp    %r15d,%r12d
jne    1130 <qh_randommatrix+0x20>
mov    %rbx,(%r14)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @qh_randommatrix(double* %0, i32 %1, double** %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double**
%7 = alloca i32
%8 = alloca i32
%9 = alloca double**
%10 = alloca double*
%11 = alloca double
store double* %0, double** %4
store i32 %1, i32* %5
store double** %2, double*** %6
%12 = load double*, double** %4
store double* %12, double** %10
%13 = load double**, double*** %6
store double** %13, double*** %9
store i32 0, i32* %7
br label %14
14: ; preds = %38, %3
%15 = load i32, i32* %7
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %41
18: ; preds = %14
%19 = load double*, double** %10
%20 = load double**, double*** %9
%21 = getelementptr inbounds double*, double** %20, i32 1
store double** %21, double*** %9
store double* %19, double** %20
store i32 0, i32* %8
br label %22
22: ; preds = %34, %18
%23 = load i32, i32* %8
%24 = load i32, i32* %5
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %37
26: ; preds = %22
%27 = call double (...) @lrand48()
store double %27, double* %11
%28 = load double, double* %11
%29 = fmul double 2.000000e+00, %28
%30 = fdiv double %29, 0x41E0000000000000
%31 = fsub double %30, 1.000000e+00
%32 = load double*, double** %10
%33 = getelementptr inbounds double, double* %32, i32 1
store double* %33, double** %10
store double %31, double* %32
br label %34
34: ; preds = %26
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
br label %22
37: ; preds = %22
br label %38
38: ; preds = %37
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %14
41: ; preds = %14
%42 = load double*, double** %10
%43 = load double**, double*** %9
store double* %42, double** %43
ret void
}

LLVM IR (-O2):
define void @qh_randommatrix(double* %0, i32 %1, double** nocapture writeonly %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %23
5: ; preds = %3, %20
%6 = phi i32 [ %21, %20 ], [ 0, %3 ]
%7 = phi double* [ %17, %20 ], [ %0, %3 ]
%8 = phi double** [ %9, %20 ], [ %2, %3 ]
%9 = getelementptr inbounds double*, double** %8, i64 1
store double* %7, double** %8
br label %10
10: ; preds = %5, %10
%11 = phi double* [ %17, %10 ], [ %7, %5 ]
%12 = phi i32 [ %18, %10 ], [ 0, %5 ]
%13 = tail call double (...) @lrand48()
%14 = fmul double %13, 2.000000e+00
%15 = fmul double %14, 0x3E00000000000000
%16 = fadd double %15, -1.000000e+00
%17 = getelementptr inbounds double, double* %11, i64 1
store double %16, double* %11
%18 = add nuw nsw i32 %12, 1
%19 = icmp eq i32 %18, %1
br i1 %19, label %20, label %10
20: ; preds = %10
%21 = add nuw nsw i32 %6, 1
%22 = icmp eq i32 %21, %1
br i1 %22, label %23, label %5
23: ; preds = %20, %3
%24 = phi double** [ %2, %3 ], [ %9, %20 ]
%25 = phi double* [ %0, %3 ], [ %17, %20 ]
store double* %25, double** %24
ret void
}