#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 */
int rand();
void fillMatrix(double **m) {
  for (int i = 0; i < 1024; i++) {
    for (int j = 0; j < 1024; j++) {
      m[i][j] = (1 + rand() % 10);
    }
  }
}


x86 assembly (clang, -O0):
<fillMatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x400,-0xc(%rbp)
jge    1190 <fillMatrix+0x80>
movl   $0x0,-0x10(%rbp)
cmpl   $0x400,-0x10(%rbp)
jge    117d <fillMatrix+0x6d>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
cvtsi2sd %edx,%xmm0
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x10(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1137 <fillMatrix+0x27>
jmp    1182 <fillMatrix+0x72>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <fillMatrix+0x13>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fillMatrix>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
add    %ecx,%eax
add    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    (%r14,%r15,8),%rax
movsd  %xmm0,(%rax,%rbx,8)
add    $0x1,%rbx
cmp    $0x400,%rbx
jne    1130 <fillMatrix+0x20>
add    $0x1,%r15
cmp    $0x400,%r15
jne    1120 <fillMatrix+0x10>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @fillMatrix(double** nocapture %0) {
br label %2
2: ; preds = %1, %6
%3 = phi i64 [ 0, %1 ], [ %7, %6 ]
%4 = getelementptr inbounds double*, double** %0, i64 %3
br label %9
5: ; preds = %6
ret void
6: ; preds = %9
%7 = add nuw nsw i64 %3, 1
%8 = icmp eq i64 %7, 1024
br i1 %8, label %5, label %2
9: ; preds = %2, %9
%10 = phi i64 [ 0, %2 ], [ %17, %9 ]
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 10
%13 = add nsw i32 %12, 1
%14 = sitofp i32 %13 to double
%15 = load double*, double** %4
%16 = getelementptr inbounds double, double* %15, i64 %10
store double %14, double* %16
%17 = add nuw nsw i64 %10, 1
%18 = icmp eq i64 %17, 1024
br i1 %18, label %6, label %9
}