#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 *create_random_matrix(int r, int s) {
  int size = r * s;
  int *matrix = (int *)malloc(size * sizeof(int));
  int i;
  for (i = 0; i < size; i++)
    matrix[i] = rand() % 11 - 5;
  return matrix;
}


x86 assembly (clang, -O0):
<create_random_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
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1189 <create_random_matrix+0x69>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0xb,%ecx
cltd
idiv   %ecx
sub    $0x5,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1152 <create_random_matrix+0x32>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_random_matrix>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%r14d
imul   %esi,%r14d
lea    0x0(,%r14,4),%edi
call   1030 <malloc@plt>
mov    %rax,%r15
test   %r14d,%r14d
jle    1187 <create_random_matrix+0x67>
mov    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x2e8ba2e9,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rcx,%rdx,2),%ecx
neg    %ecx
add    %ecx,%eax
add    $0xfffffffb,%eax
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <create_random_matrix+0x30>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @create_random_matrix(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%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
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 4
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i32*
store i32* %16, i32** %6
store i32 0, i32* %7
br label %17
17: ; preds = %29, %2
%18 = load i32, i32* %7
%19 = load i32, i32* %5
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %32
21: ; preds = %17
%22 = call i32 (...) @rand()
%23 = srem i32 %22, 11
%24 = sub nsw i32 %23, 5
%25 = load i32*, i32** %6
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
store i32 %24, i32* %28
br label %29
29: ; preds = %21
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %17
32: ; preds = %17
%33 = load i32*, i32** %6
ret i32* %33
}

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