#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);
scalar_t__ rand();
int **createMatrix() {
  int i, j, **matrix;
  matrix = (int **)malloc(40 * sizeof(int *));
  for (i = 0; i < 40; i++) {
    matrix[i] = (int *)malloc(40 * sizeof(int));
  }
  for (i = 0; i < 40; i++) {
    for (j = 0; j < 40; j++) {
      matrix[i][j] = (int)rand() * 100;
    }
  }
  return matrix;
}


x86 assembly (clang, -O0):
<createMatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x140,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x28,-0x4(%rbp)
jge    116e <createMatrix+0x4e>
mov    $0xa0,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    113d <createMatrix+0x1d>
movl   $0x0,-0x4(%rbp)
cmpl   $0x28,-0x4(%rbp)
jge    11ce <createMatrix+0xae>
movl   $0x0,-0x8(%rbp)
cmpl   $0x28,-0x8(%rbp)
jge    11bb <createMatrix+0x9b>
mov    $0x0,%al
call   1040 <rand@plt>
imul   $0x64,%eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1186 <createMatrix+0x66>
jmp    11c0 <createMatrix+0xa0>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1175 <createMatrix+0x55>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createMatrix>:
push   %r15
push   %r14
push   %rbx
mov    $0x140,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0xa0,%edi
call   1030 <malloc@plt>
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    $0x28,%rbx
jne    1140 <createMatrix+0x20>
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <rand@plt>
imul   $0x64,%eax,%eax
mov    (%r14,%r15,8),%rcx
mov    %eax,(%rcx,%rbx,4)
add    $0x1,%rbx
cmp    $0x28,%rbx
jne    1170 <createMatrix+0x50>
add    $0x1,%r15
cmp    $0x28,%r15
jne    1160 <createMatrix+0x40>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32** @createMatrix() {
%1 = tail call i64 @malloc(i32 320)
%2 = inttoptr i64 %1 to i32**
br label %3
3: ; preds = %0, %3
%4 = phi i64 [ 0, %0 ], [ %8, %3 ]
%5 = tail call i64 @malloc(i32 160)
%6 = inttoptr i64 %5 to i32*
%7 = getelementptr inbounds i32*, i32** %2, i64 %4
store i32* %6, i32** %7
%8 = add nuw nsw i64 %4, 1
%9 = icmp eq i64 %8, 40
br i1 %9, label %10, label %3
10: ; preds = %3, %22
%11 = phi i64 [ %23, %22 ], [ 0, %3 ]
%12 = getelementptr inbounds i32*, i32** %2, i64 %11
br label %13
13: ; preds = %10, %13
%14 = phi i64 [ 0, %10 ], [ %20, %13 ]
%15 = tail call i64 (...) @rand()
%16 = trunc i64 %15 to i32
%17 = mul nsw i32 %16, 100
%18 = load i32*, i32** %12
%19 = getelementptr inbounds i32, i32* %18, i64 %14
store i32 %17, i32* %19
%20 = add nuw nsw i64 %14, 1
%21 = icmp eq i64 %20, 40
br i1 %21, label %22, label %13
22: ; preds = %13
%23 = add nuw nsw i64 %11, 1
%24 = icmp eq i64 %23, 40
br i1 %24, label %25, label %10
25: ; preds = %22
ret i32** %2
}