#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();
int /*<<< orphan*/ srand(int);
float *create_rands_matrix(int rows, int columns, int max, int seed) {
  srand(seed);
  float *rands = (float *)malloc(sizeof(float) * rows * columns);
  for (int i = 0; i < rows; i++) {
    for (int j = 0; j < columns; j++) {
      rands[i * columns + j] = rand() % max;
    }
  }
  return rands;
}


x86 assembly (clang, -O0):
<create_rands_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <srand@plt>
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
movslq -0x8(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d3 <create_rands_matrix+0xa3>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c0 <create_rands_matrix+0x90>
mov    $0x0,%al
call   1050 <rand@plt>
cltd
idivl  -0xc(%rbp)
cvtsi2ss %edx,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   -0x8(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1181 <create_rands_matrix+0x51>
jmp    11c5 <create_rands_matrix+0x95>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116e <create_rands_matrix+0x3e>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_rands_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %esi,%ebp
mov    %edi,%r15d
mov    %ecx,%edi
call   1030 <srand@plt>
mov    %r15d,%edi
mov    %ebp,0x4(%rsp)
imul   %ebp,%edi
shl    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,0x8(%rsp)
test   %r15d,%r15d
jle    11d2 <create_rands_matrix+0xa2>
movslq 0x4(%rsp),%r13
mov    %r15d,%eax
mov    %rax,0x10(%rsp)
mov    %r13d,%ebp
shl    $0x2,%r13
mov    0x8(%rsp),%r14
xor    %r12d,%r12d
jmp    119e <create_rands_matrix+0x6e>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r12
add    %r13,%r14
cmp    0x10(%rsp),%r12
je     11d2 <create_rands_matrix+0xa2>
cmpl   $0x0,0x4(%rsp)
jle    1190 <create_rands_matrix+0x60>
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
cltd
idiv   %ebx
xorps  %xmm0,%xmm0
cvtsi2ss %edx,%xmm0
movss  %xmm0,(%r14,%r15,4)
add    $0x1,%r15
cmp    %r15,%rbp
jne    11b0 <create_rands_matrix+0x80>
jmp    1190 <create_rands_matrix+0x60>
mov    0x8(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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