#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 *generate_empty_matrix(int);
double rand();
float *generate_and_fill_matrix(int size) {
  float *matrix = generate_empty_matrix(size);
  if (matrix == NULL) {
    return NULL;
  }
  for (int i = 0; i < size; ++i) {
    for (int j = 0; j < size; ++j) {
      *(matrix + i * size + j) = rand() / 100000000.0;
    }
  }
  return matrix;
}


x86 assembly (clang, -O0):
<generate_and_fill_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <generate_empty_matrix@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    114f <generate_and_fill_matrix+0x2f>
movq   $0x0,-0x8(%rbp)
jmp    11d3 <generate_and_fill_matrix+0xb3>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11cb <generate_and_fill_matrix+0xab>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b8 <generate_and_fill_matrix+0x98>
mov    $0x0,%al
call   1040 <rand@plt>
movsd  0xe7c(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   -0xc(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1169 <generate_and_fill_matrix+0x49>
jmp    11bd <generate_and_fill_matrix+0x9d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1156 <generate_and_fill_matrix+0x36>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_and_fill_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebp
call   1030 <generate_empty_matrix@plt>
mov    %rax,%r14
test   %rax,%rax
je     1191 <generate_and_fill_matrix+0x71>
test   %ebp,%ebp
jle    1191 <generate_and_fill_matrix+0x71>
mov    %ebp,%r13d
lea    0x0(,%r13,4),%r15
mov    %r14,%rbx
xor    %r12d,%r12d
nop
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <rand@plt>
movsd  0xe91(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1160 <generate_and_fill_matrix+0x40>
add    $0x1,%r12
add    %r15,%rbx
cmp    %r13,%r12
jne    1150 <generate_and_fill_matrix+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* @generate_and_fill_matrix(i32 %0) {
%2 = alloca float*
%3 = alloca i32
%4 = alloca float*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = call float* @generate_empty_matrix(i32 %7)
store float* %8, float** %4
%9 = load float*, float** %4
%10 = icmp eq float* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store float* null, float** %2
br label %44
12: ; preds = %1
store i32 0, i32* %5
br label %13
13: ; preds = %39, %12
%14 = load i32, i32* %5
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %42
17: ; preds = %13
store i32 0, i32* %6
br label %18
18: ; preds = %35, %17
%19 = load i32, i32* %6
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %38
22: ; preds = %18
%23 = call double (...) @rand()
%24 = fdiv double %23, 1.000000e+08
%25 = fptrunc double %24 to float
%26 = load float*, float** %4
%27 = load i32, i32* %5
%28 = load i32, i32* %3
%29 = mul nsw i32 %27, %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds float, float* %26, i64 %30
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds float, float* %31, i64 %33
store float %25, float* %34
br label %35
35: ; preds = %22
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %18
38: ; preds = %18
br label %39
39: ; preds = %38
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %13
42: ; preds = %13
%43 = load float*, float** %4
store float* %43, float** %2
br label %44
44: ; preds = %42, %11
%45 = load float*, float** %2
ret float* %45
}

LLVM IR (-O2):
define float* @generate_and_fill_matrix(i32 %0) {
%2 = tail call float* @generate_empty_matrix(i32 %0)
%3 = icmp ne float* %2, null
%4 = icmp sgt i32 %0, 0
%5 = and i1 %3, %4
br i1 %5, label %6, label %24
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
%12 = getelementptr inbounds float, float* %2, i64 %11
br label %16
13: ; preds = %16
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, %8
br i1 %15, label %24, label %9
16: ; preds = %9, %16
%17 = phi i64 [ 0, %9 ], [ %22, %16 ]
%18 = tail call double (...) @rand()
%19 = fdiv double %18, 1.000000e+08
%20 = fptrunc double %19 to float
%21 = getelementptr inbounds float, float* %12, i64 %17
store float %20, float* %21
%22 = add nuw nsw i64 %17, 1
%23 = icmp eq i64 %22, %8
br i1 %23, label %13, label %16
24: ; preds = %13, %1
ret float* %2
}