#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(int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ inverseArray(int *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ mergeSort_partition(int *, int /*<<< orphan*/, int, int *);
void mergeSort(int *array, int n, bool isOrderASC) {
  int *dummyArray = (int *)malloc(sizeof(int) * n);
  if (dummyArray == NULL) {
    exit(1);
  }
  mergeSort_partition(array, 0, n, dummyArray);
  if (!isOrderASC) {
    inverseArray(array, n);
  }
  free(dummyArray);
}


x86 assembly (clang, -O0):
<mergeSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118a <mergeSort+0x3a>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
xor    %esi,%esi
call   1040 <mergeSort_partition@plt>
cmpl   $0x0,-0x10(%rbp)
jne    11b2 <mergeSort+0x62>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <inverseArray@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergeSort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%r15d
mov    %rdi,%r14
lea    0x0(,%r15,4),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11a5 <mergeSort+0x55>
mov    %rax,%rbx
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15d,%edx
mov    %rax,%rcx
call   1040 <mergeSort_partition@plt>
test   %ebp,%ebp
jne    1193 <mergeSort+0x43>
mov    %r14,%rdi
mov    %r15d,%esi
call   1050 <inverseArray@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
define void @mergeSort(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* %5
%9 = sext i32 %8 to i64
%10 = mul i64 4, %9
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %7
%14 = load i32*, i32** %7
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %3
%19 = load i32*, i32** %4
%20 = load i32, i32* %5
%21 = load i32*, i32** %7
%22 = call i32 @mergeSort_partition(i32* %19, i32 0, i32 %20, i32* %21)
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %18
%26 = load i32*, i32** %4
%27 = load i32, i32* %5
%28 = call i32 @inverseArray(i32* %26, i32 %27)
br label %29
29: ; preds = %25, %18
%30 = load i32*, i32** %7
%31 = call i32 @free(i32* %30)
ret void
}

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