#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 RAND_MAX;
float *calloc(int, int);
scalar_t__ rand();
float *random_matrix(int rows, int cols) {
  int i;
  float *m = calloc(rows * cols, sizeof(float));
  for (i = 0; i < rows * cols; ++i) {
    m[i] = (float)rand() / RAND_MAX;
  }
  return m;
}


x86 assembly (clang, -O0):
<random_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
imul   -0x8(%rbp),%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x4(%rbp),%ecx
imul   -0x8(%rbp),%ecx
cmp    %ecx,%eax
jge    118e <random_matrix+0x6e>
mov    $0x0,%al
call   1040 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2e79(%rip),%rax
divss  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114a <random_matrix+0x2a>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_matrix>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
imul   %esi,%ebp
mov    %ebp,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,%r15
test   %ebp,%ebp
jle    1173 <random_matrix+0x53>
mov    %ebp,%ebp
mov    0x2ea0(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
divss  (%r14),%xmm0
movss  %xmm0,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <random_matrix+0x30>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global float 0.000000e+00
define float* @random_matrix(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca float*
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = load i32, i32* %4
%9 = mul nsw i32 %7, %8
%10 = call float* @calloc(i32 %9, i32 4)
store float* %10, float** %6
store i32 0, i32* %5
br label %11
11: ; preds = %26, %2
%12 = load i32, i32* %5
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = mul nsw i32 %13, %14
%16 = icmp slt i32 %12, %15
br i1 %16, label %17, label %29
17: ; preds = %11
%18 = call i64 (...) @rand()
%19 = sitofp i64 %18 to float
%20 = load float, float* @RAND_MAX
%21 = fdiv float %19, %20
%22 = load float*, float** %6
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds float, float* %22, i64 %24
store float %21, float* %25
br label %26
26: ; preds = %17
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %11
29: ; preds = %11
%30 = load float*, float** %6
ret float* %30
}

LLVM IR (-O2):
@RAND_MAX = global float 0.000000e+00
define noalias float* @random_matrix(i32 %0, i32 %1) {
%3 = mul nsw i32 %1, %0
%4 = tail call float* @calloc(i32 %3, i32 4)
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %17
6: ; preds = %2
%7 = zext i32 %3 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %15, %8 ]
%10 = tail call i64 (...) @rand()
%11 = sitofp i64 %10 to float
%12 = load float, float* @RAND_MAX
%13 = fdiv float %11, %12
%14 = getelementptr inbounds float, float* %4, i64 %9
store float %13, float* %14
%15 = add nuw nsw i64 %9, 1
%16 = icmp eq i64 %15, %7
br i1 %16, label %17, label %8
17: ; preds = %8, %2
ret float* %4
}