#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 */
scalar_t__ RAND_MAX;
double rand();
void random_matrix(double *data, int N, int D) {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      data[i * D + j] = rand() / (double)RAND_MAX;
    }
  }
}


x86 assembly (clang, -O0):
<random_matrix>:
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    1196 <random_matrix+0x86>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1183 <random_matrix+0x73>
mov    $0x0,%al
call   1030 <rand@plt>
mov    0x2e92(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   -0x10(%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    113c <random_matrix+0x2c>
jmp    1188 <random_matrix+0x78>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <random_matrix+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,0xc(%rsp)
test   %esi,%esi
jle    1195 <random_matrix+0x85>
mov    %rdi,%rbx
movslq 0xc(%rsp),%r12
mov    %esi,%eax
mov    %rax,0x10(%rsp)
mov    %r12d,%ebp
shl    $0x3,%r12
mov    0x2ea5(%rip),%r13
xor    %r14d,%r14d
jmp    115e <random_matrix+0x4e>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14
add    %r12,%rbx
cmp    0x10(%rsp),%r14
je     1195 <random_matrix+0x85>
cmpl   $0x0,0xc(%rsp)
jle    1150 <random_matrix+0x40>
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq 0x0(%r13),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx,%r15,8)
add    $0x1,%r15
cmp    %r15,%rbp
jne    1170 <random_matrix+0x60>
jmp    1150 <random_matrix+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define void @random_matrix(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 = %35, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %38
13: ; preds = %9
store i32 0, i32* %8
br label %14
14: ; preds = %31, %13
%15 = load i32, i32* %8
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %34
18: ; preds = %14
%19 = call double (...) @rand()
%20 = load i64, i64* @RAND_MAX
%21 = sitofp i64 %20 to double
%22 = fdiv double %19, %21
%23 = load double*, double** %4
%24 = load i32, i32* %7
%25 = load i32, i32* %6
%26 = mul nsw i32 %24, %25
%27 = load i32, i32* %8
%28 = add nsw i32 %26, %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %23, i64 %29
store double %22, double* %30
br label %31
31: ; preds = %18
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
br label %14
34: ; preds = %14
br label %35
35: ; preds = %34
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %9
38: ; preds = %9
ret void
}

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