#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__ malloc(int);
int rand();
float *new_matrix(int rows, int cols) {
  float *m = (float *)malloc(rows * cols * sizeof(float));
  for (int i = 0; i < rows; i++) {
    for (int j = 0; j < cols; j++) {
      m[i * cols + j] = rand() % 100;
    }
  }
  return m;
}


x86 assembly (clang, -O0):
<new_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
imul   -0x8(%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    11b6 <new_matrix+0x96>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a3 <new_matrix+0x83>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
cvtsi2ss %edx,%xmm0
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   -0x8(%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    1160 <new_matrix+0x40>
jmp    11a8 <new_matrix+0x88>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114d <new_matrix+0x2d>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r15d
mov    %esi,0xc(%rsp)
imul   %esi,%edi
shl    $0x2,%edi
call   1030 <malloc@plt>
mov    %rax,0x10(%rsp)
test   %r15d,%r15d
jle    11cb <new_matrix+0xab>
movslq 0xc(%rsp),%r13
mov    %r15d,%r15d
mov    %r13d,%ebx
shl    $0x2,%r13
mov    0x10(%rsp),%rbp
xor    %r14d,%r14d
jmp    117c <new_matrix+0x5c>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
add    %r13,%rbp
cmp    %r15,%r14
je     11cb <new_matrix+0xab>
cmpl   $0x0,0xc(%rsp)
jle    1170 <new_matrix+0x50>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x0(%rbp,%r12,4)
add    $0x1,%r12
cmp    %r12,%rbx
jne    1190 <new_matrix+0x70>
jmp    1170 <new_matrix+0x50>
mov    0x10(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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