#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();
int /*<<< orphan*/ srand(int);
void random_matrix(double *I, long rows, long cols) {
  long i, j;
  srand(7);
  for (i = 0; i < rows; i = i + 1) {
    for (j = 0; j < cols; j = j + 1) {
      I[i * cols + j] = (double)(rand()) / 0xFFFFFFFFFFFFFFFF;
    }
  }
}


x86 assembly (clang, -O0):
<random_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x7,%edi
call   1030 <srand@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11bf <random_matrix+0x9f>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11a9 <random_matrix+0x89>
mov    $0x0,%al
call   1040 <rand@plt>
cvtsi2sd %rax,%xmm0
movsd  0xe82(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
imul   -0x18(%rbp),%rcx
add    -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    115c <random_matrix+0x3c>
jmp    11ae <random_matrix+0x8e>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1146 <random_matrix+0x26>
add    $0x30,%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    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x7,%edi
call   1030 <srand@plt>
test   %r14,%r14
jle    119b <random_matrix+0x7b>
lea    0x0(,%r15,8),%r12
xor    %r13d,%r13d
jmp    115c <random_matrix+0x3c>
add    $0x1,%r13
add    %r12,%rbx
cmp    %r14,%r13
je     119b <random_matrix+0x7b>
test   %r15,%r15
jle    1150 <random_matrix+0x30>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <rand@plt>
movsd  0xe81(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1170 <random_matrix+0x50>
jmp    1150 <random_matrix+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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