#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*/ EXIT_FAILURE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int const);
int /*<<< orphan*/ mergeSortHelper(int *const, int /*<<< orphan*/, int const,
                                   int *);
void mergeSort(const int size, int *const arr) {
  assert(size >= 0);
  int *temp;
  if ((temp = (int *)malloc(size * sizeof(int))) == NULL) {
    exit(EXIT_FAILURE);
  }
  mergeSortHelper(arr, 0, size, temp);
  free(temp);
}


x86 assembly (clang, -O0):
<mergeSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    119b <mergeSort+0x4b>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    -0x18(%rbp),%rcx
xor    %esi,%esi
call   1060 <mergeSortHelper@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergeSort>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%r15d
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
lea    0x0(,%r15,4),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1197 <mergeSort+0x47>
mov    %rax,%rbx
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15d,%edx
mov    %rax,%rcx
call   1060 <mergeSortHelper@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
define void @mergeSort(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
store i32 %0, i32* %3
store i32* %1, i32** %4
%6 = load i32, i32* %3
%7 = icmp sge i32 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 4
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i32*
store i32* %15, i32** %5
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i32*, i32** %4
%22 = load i32, i32* %3
%23 = load i32*, i32** %5
%24 = call i32 @mergeSortHelper(i32* %21, i32 0, i32 %22, i32* %23)
%25 = load i32*, i32** %5
%26 = call i32 @free(i32* %25)
ret void
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
define void @mergeSort(i32 %0, i32* %1) {
%3 = xor i32 %0, -1
%4 = lshr i32 %3, 31
%5 = tail call i32 @assert(i32 %4)
%6 = shl i32 %0, 2
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = tail call i32 @mergeSortHelper(i32* %1, i32 0, i32 %0, i32* %8)
%15 = tail call i32 @free(i32* %8)
ret void
}