#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__ calloc(size_t, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, size_t);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ partition(int *, size_t, size_t, int *);
int /*<<< orphan*/ stderr;
void main_merge_sort(int arr[], size_t low, size_t high) {
  int *buffer = (int *)calloc(high + 1, sizeof(int));
  if (buffer == NULL) {
    fprintf(stderr,
            "MemoryException: Can't allocate "
            "%u"
            " byte of memory.",
            (high + 1) * sizeof(int));
    free(arr);
    exit(1);
  }
  partition(arr, low, high, buffer);
  if (buffer)
    free(buffer);
}


x86 assembly (clang, -O0):
<main_merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b9 <main_merge_sort+0x69>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
shl    $0x2,%rdx
lea    0xe5f(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1040 <partition@plt>
cmpq   $0x0,-0x20(%rbp)
je     11e2 <main_merge_sort+0x92>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main_merge_sort>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r13
mov    %rsi,%r12
mov    %rdi,%r14
lea    0x1(%rdx),%r15
mov    %r15,%rdi
mov    $0x4,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     119d <main_merge_sort+0x4d>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rax,%rcx
call   1040 <partition@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
shl    $0x2,%r15
lea    0xe4f(%rip),%rsi
mov    %r15,%rdx
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [51 x i8] c"MemoryException: Can't allocate %u byte of memory.\00"
define void @main_merge_sort(i32* %0, i64 %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32*
store i32* %0, i32** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%8 = load i64, i64* %6
%9 = add i64 %8, 1
%10 = call i64 @calloc(i64 %9, i32 4)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %7
%12 = load i32*, i32** %7
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %23
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = load i64, i64* %6
%17 = add i64 %16, 1
%18 = mul i64 %17, 4
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i64 %18)
%20 = load i32*, i32** %4
%21 = call i32 @free(i32* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %3
%24 = load i32*, i32** %4
%25 = load i64, i64* %5
%26 = load i64, i64* %6
%27 = load i32*, i32** %7
%28 = call i32 @partition(i32* %24, i64 %25, i64 %26, i32* %27)
%29 = load i32*, i32** %7
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %34
31: ; preds = %23
%32 = load i32*, i32** %7
%33 = call i32 @free(i32* %32)
br label %34
34: ; preds = %31, %23
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [51 x i8] c"MemoryException: Can't allocate %u byte of memory.\00"
define void @main_merge_sort(i32* %0, i64 %1, i64 %2) {
%4 = add i64 %2, 1
%5 = tail call i64 @calloc(i64 %4, i32 4)
%6 = inttoptr i64 %5 to i32*
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %14
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = shl i64 %4, 2
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i64 %10)
%12 = tail call i32 @free(i32* %0)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %3
%15 = tail call i32 @partition(i32* %0, i64 %1, i64 %2, i32* %6)
%16 = tail call i32 @free(i32* %6)
ret void
}