#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 */
int /*<<< orphan*/ assert(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int *create_matrix(int size) {
  int *mat;
  int i;
  mat = (int *)malloc(sizeof(int *) * size * size);
  assert(mat);
  for (i = 0; i < size; i++) {
    memset(mat, 0, sizeof(int) * size * size);
  }
  return mat;
}


x86 assembly (clang, -O0):
<create_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
movslq -0x4(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119d <create_matrix+0x6d>
mov    -0x10(%rbp),%rdi
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
movslq -0x4(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1166 <create_matrix+0x36>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_matrix>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%ebx
mov    %edi,%r14d
imul   %r14d,%r14d
lea    0x0(,%r14,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <assert@plt>
test   %ebx,%ebx
jle    1172 <create_matrix+0x42>
shl    $0x2,%r14d
xchg   %ax,%ax
mov    %r15,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1030 <memset@plt>
add    $0xffffffff,%ebx
jne    1160 <create_matrix+0x30>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @create_matrix(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = sext i32 %5 to i64
%7 = mul i64 8, %6
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = mul i64 %7, %9
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %3
%14 = load i32*, i32** %3
%15 = call i32 @assert(i32* %14)
store i32 0, i32* %4
br label %16
16: ; preds = %30, %1
%17 = load i32, i32* %4
%18 = load i32, i32* %2
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %33
20: ; preds = %16
%21 = load i32*, i32** %3
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = mul i64 4, %23
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = mul i64 %24, %26
%28 = trunc i64 %27 to i32
%29 = call i32 @memset(i32* %21, i32 0, i32 %28)
br label %30
30: ; preds = %20
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %16
33: ; preds = %16
%34 = load i32*, i32** %3
ret i32* %34
}

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