#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 */
float *malloc(int);
int rand();
float *createRandomizedMatrix_f(int N) {
  float value;
  float *result = malloc(N * N * sizeof(float));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      value = rand() % 10;
      result[(N * i) + j] = value;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<createRandomizedMatrix_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
imul   -0x4(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11bd <createRandomizedMatrix_f+0x9d>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11aa <createRandomizedMatrix_f+0x8a>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
cvtsi2ss %edx,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
imul   -0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115d <createRandomizedMatrix_f+0x3d>
jmp    11af <createRandomizedMatrix_f+0x8f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114a <createRandomizedMatrix_f+0x2a>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createRandomizedMatrix_f>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebp
imul   %edi,%edi
shl    $0x2,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
test   %ebp,%ebp
jle    11a5 <createRandomizedMatrix_f+0x85>
mov    %ebp,%r13d
lea    0x0(,%r13,4),%r15
mov    %r14,%rbx
xor    %r12d,%r12d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <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
sub    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1160 <createRandomizedMatrix_f+0x40>
add    $0x1,%r12
add    %r15,%rbx
cmp    %r13,%r12
jne    1150 <createRandomizedMatrix_f+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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