#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;
int /*<<< orphan*/ assert(int);
double *malloc(int);
double random();
int /*<<< orphan*/ srandom(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
double *init(int n) {
  assert(n > 0);
  double *res = malloc(n * n * sizeof(double));
  srandom(time(NULL));
  int i, j;
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      res[i * n + j] = 1.0 * random() / RAND_MAX;
  return res;
}


x86 assembly (clang, -O0):
<init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x4(%rbp),%eax
imul   -0x4(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1030 <srandom@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1212 <init+0xc2>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ff <init+0xaf>
mov    $0x0,%al
call   1060 <random@plt>
movaps %xmm0,%xmm1
movsd  0xe34(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2e11(%rip),%rax
divsd  (%rax),%xmm0
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    11ae <init+0x5e>
jmp    1204 <init+0xb4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119b <init+0x4b>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %edi,%edi
test   %ebp,%ebp
setg   %dil
call   1040 <assert@plt>
mov    %ebp,%edi
imul   %ebp,%edi
shl    $0x3,%edi
call   1070 <malloc@plt>
mov    %rax,(%rsp)
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1030 <srandom@plt>
test   %ebp,%ebp
jle    11e8 <init+0x98>
mov    %ebp,%ebp
lea    0x0(,%rbp,8),%r15
mov    0x2e4a(%rip),%r12
mov    (%rsp),%rbx
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nop
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1060 <random@plt>
divsd  (%r12),%xmm0
movsd  %xmm0,(%rbx,%r14,8)
add    $0x1,%r14
cmp    %r14,%rbp
jne    11c0 <init+0x70>
add    $0x1,%r13
add    %r15,%rbx
cmp    %rbp,%r13
jne    11b0 <init+0x60>
mov    (%rsp),%rax
add    $0x8,%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 double* @init(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 = icmp sgt i32 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* %2
%11 = load i32, i32* %2
%12 = mul nsw i32 %10, %11
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 8
%15 = trunc i64 %14 to i32
%16 = call double* @malloc(i32 %15)
store double* %16, double** %3
%17 = call i32 @time(i32* null)
%18 = call i32 @srandom(i32 %17)
store i32 0, i32* %4
br label %19
19: ; preds = %45, %1
%20 = load i32, i32* %4
%21 = load i32, i32* %2
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %48
23: ; preds = %19
store i32 0, i32* %5
br label %24
24: ; preds = %41, %23
%25 = load i32, i32* %5
%26 = load i32, i32* %2
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %44
28: ; preds = %24
%29 = call double (...) @random()
%30 = fmul double 1.000000e+00, %29
%31 = load double, double* @RAND_MAX
%32 = fdiv double %30, %31
%33 = load double*, double** %3
%34 = load i32, i32* %4
%35 = load i32, i32* %2
%36 = mul nsw i32 %34, %35
%37 = load i32, i32* %5
%38 = add nsw i32 %36, %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %33, i64 %39
store double %32, double* %40
br label %41
41: ; preds = %28
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %24
44: ; preds = %24
br label %45
45: ; preds = %44
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %19
48: ; preds = %19
%49 = load double*, double** %3
ret double* %49
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define noalias double* @init(i32 %0) {
%2 = icmp sgt i32 %0, 0
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = shl i32 %0, 3
%6 = mul i32 %5, %0
%7 = tail call double* @malloc(i32 %6)
%8 = tail call i32 @time(i32* null)
%9 = tail call i32 @srandom(i32 %8)
br i1 %2, label %10, label %28
10: ; preds = %1
%11 = zext i32 %0 to i64
%12 = zext i32 %0 to i64
br label %13
13: ; preds = %25, %10
%14 = phi i64 [ 0, %10 ], [ %26, %25 ]
%15 = mul nsw i64 %14, %11
br label %16
16: ; preds = %13, %16
%17 = phi i64 [ 0, %13 ], [ %23, %16 ]
%18 = tail call double (...) @random()
%19 = load double, double* @RAND_MAX
%20 = fdiv double %18, %19
%21 = add nuw nsw i64 %17, %15
%22 = getelementptr inbounds double, double* %7, i64 %21
store double %20, double* %22
%23 = add nuw nsw i64 %17, 1
%24 = icmp eq i64 %23, %12
br i1 %24, label %25, label %16
25: ; preds = %16
%26 = add nuw nsw i64 %14, 1
%27 = icmp eq i64 %26, %12
br i1 %27, label %28, label %13
28: ; preds = %25, %1
ret double* %7
}