#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(unsigned int);
int /*<<< orphan*/ memcpy(int *, int *, unsigned int);
int /*<<< orphan*/ merge_sort_recurse_impl(int *, int *, int /*<<< orphan*/,
                                           unsigned int, int (*)(int *, int *));
int /*<<< orphan*/ printf(char *, unsigned int);
void merge_sort_recurse(int objs[], unsigned int n,
                        bool (*cmp)(int *x, int *y)) {
  int *tmp = malloc(n * sizeof(int));
  if (tmp == NULL) {
    printf("Error: merge_sort(%d) -- malloc() failed\n", n);
    return;
  }
  memcpy(tmp, objs, (n * sizeof(int)));
  merge_sort_recurse_impl(objs, tmp, 0, n - 1, cmp);
  free(tmp);
}


x86 assembly (clang, -O0):
<merge_sort_recurse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1194 <merge_sort_recurse+0x44>
mov    -0xc(%rbp),%esi
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
jmp    11cc <merge_sort_recurse+0x7c>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x18(%rbp),%r8
xor    %edx,%edx
call   1070 <merge_sort_recurse_impl@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort_recurse>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %esi,%r12d
mov    %rdi,%r15
lea    0x0(,%r12,4),%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11ac <merge_sort_recurse+0x5c>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
add    $0xffffffff,%r12d
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    %r12d,%ecx
mov    %r14,%r8
call   1070 <merge_sort_recurse_impl@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
lea    0xe4d(%rip),%rdi
mov    %r12d,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"Error: merge_sort(%d) -- malloc() failed\0A\00"
define void @merge_sort_recurse(i32* %0, i32 %1, i32 (i32*, i32*)* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32 (i32*, i32*)*
%7 = alloca i32*
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 (i32*, i32*)* %2, i32 (i32*, i32*)** %6
%8 = load i32, i32* %5
%9 = zext i32 %8 to i64
%10 = mul i64 %9, 4
%11 = trunc i64 %10 to i32
%12 = call i32* @malloc(i32 %11)
store i32* %12, i32** %7
%13 = load i32*, i32** %7
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i32, i32* %5
%17 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %34
18: ; preds = %3
%19 = load i32*, i32** %7
%20 = load i32*, i32** %4
%21 = load i32, i32* %5
%22 = zext i32 %21 to i64
%23 = mul i64 %22, 4
%24 = trunc i64 %23 to i32
%25 = call i32 @memcpy(i32* %19, i32* %20, i32 %24)
%26 = load i32*, i32** %4
%27 = load i32*, i32** %7
%28 = load i32, i32* %5
%29 = sub i32 %28, 1
%30 = load i32 (i32*, i32*)*, i32 (i32*, i32*)** %6
%31 = call i32 @merge_sort_recurse_impl(i32* %26, i32* %27, i32 0, i32 %29, i32 (i32*, i32*)* %30)
%32 = load i32*, i32** %7
%33 = call i32 @free(i32* %32)
br label %34
34: ; preds = %18, %15
ret void
}

LLVM IR (-O2):
@.str = [42 x i8] c"Error: merge_sort(%d) -- malloc() failed\0A\00"
define void @merge_sort_recurse(i32* %0, i32 %1, i32 (i32*, i32*)* %2) {
%4 = shl i32 %1, 2
%5 = tail call i32* @malloc(i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %14
9: ; preds = %3
%10 = tail call i32 @memcpy(i32* %5, i32* %0, i32 %4)
%11 = add i32 %1, -1
%12 = tail call i32 @merge_sort_recurse_impl(i32* %0, i32* %5, i32 0, i32 %11, i32 (i32*, i32*)* %2)
%13 = tail call i32 @free(i32* %5)
br label %14
14: ; preds = %9, %7
ret void
}