#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 *alloc_matrix(int);
double drand48();
double *random_matrix(int n) {
  double *res = alloc_matrix(n);
  int i, j;
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n; ++j) {
      res[i * n + j] = drand48();
    }
  }
  return res;
}


x86 assembly (clang, -O0):
<random_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <alloc_matrix@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119b <random_matrix+0x7b>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1188 <random_matrix+0x68>
mov    $0x0,%al
call   1040 <drand48@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   -0x4(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1151 <random_matrix+0x31>
jmp    118d <random_matrix+0x6d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <random_matrix+0x1e>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebp
call   1030 <alloc_matrix@plt>
mov    %rax,%r14
test   %ebp,%ebp
jle    1181 <random_matrix+0x61>
mov    %ebp,%r13d
lea    0x0(,%r13,8),%r15
mov    %r14,%rbx
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <drand48@plt>
movsd  %xmm0,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1160 <random_matrix+0x40>
add    $0x1,%r12
add    %r15,%rbx
cmp    %r13,%r12
jne    1150 <random_matrix+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double* @random_matrix(i32 %0) {
%2 = alloca i32
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = call double* @alloc_matrix(i32 %6)
store double* %7, double** %3
store i32 0, i32* %4
br label %8
8: ; preds = %31, %1
%9 = load i32, i32* %4
%10 = load i32, i32* %2
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %34
12: ; preds = %8
store i32 0, i32* %5
br label %13
13: ; preds = %27, %12
%14 = load i32, i32* %5
%15 = load i32, i32* %2
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %30
17: ; preds = %13
%18 = call double (...) @drand48()
%19 = load double*, double** %3
%20 = load i32, i32* %4
%21 = load i32, i32* %2
%22 = mul nsw i32 %20, %21
%23 = load i32, i32* %5
%24 = add nsw i32 %22, %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %19, i64 %25
store double %18, double* %26
br label %27
27: ; preds = %17
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %13
30: ; preds = %13
br label %31
31: ; preds = %30
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %8
34: ; preds = %8
%35 = load double*, double** %3
ret double* %35
}

LLVM IR (-O2):
define double* @random_matrix(i32 %0) {
%2 = tail call double* @alloc_matrix(i32 %0)
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %20
4: ; preds = %1
%5 = zext i32 %0 to i64
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %17, %4
%8 = phi i64 [ 0, %4 ], [ %18, %17 ]
%9 = mul nsw i64 %8, %5
br label %10
10: ; preds = %7, %10
%11 = phi i64 [ 0, %7 ], [ %15, %10 ]
%12 = tail call double (...) @drand48()
%13 = add nuw nsw i64 %11, %9
%14 = getelementptr inbounds double, double* %2, i64 %13
store double %12, double* %14
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, %6
br i1 %16, label %17, label %10
17: ; preds = %10
%18 = add nuw nsw i64 %8, 1
%19 = icmp eq i64 %18, %6
br i1 %19, label %20, label %7
20: ; preds = %17, %1
ret double* %2
}