#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*/ free(int *);
int *malloc(int const);
int *SafeInitialiseIntArray_m(int *output, const int mainSizeOutput,
                              const int mainSize) {
  if (output != NULL) {
    free(output);
  }
  output = malloc(mainSize * sizeof(int));
  int i = 0;
  for (i = 0; i < mainSize; i++) {
    output[i] = 0;
  }
  return output;
}


x86 assembly (clang, -O0):
<SafeInitialiseIntArray_m>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1146 <SafeInitialiseIntArray_m+0x26>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1190 <SafeInitialiseIntArray_m+0x70>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1167 <SafeInitialiseIntArray_m+0x47>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SafeInitialiseIntArray_m>:
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
test   %rdi,%rdi
je     1140 <SafeInitialiseIntArray_m+0x10>
call   1030 <free@plt>
lea    0x0(,%rbx,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %ebx,%ebx
jle    1163 <SafeInitialiseIntArray_m+0x33>
mov    %ebx,%edx
shl    $0x2,%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define noalias i32* @SafeInitialiseIntArray_m(i32* %0, i32 %1, i32 %2) {
%4 = icmp eq i32* %0, null
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = tail call i32 @free(i32* %0)
br label %7
7: ; preds = %5, %3
%8 = shl i32 %2, 2
%9 = tail call i32* @malloc(i32 %8)
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = bitcast i32* %9 to i8*
%13 = zext i32 %2 to i64
%14 = shl nuw nsw i64 %13, 2
br label %15
15: ; preds = %11, %7
ret i32* %9
}