#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 */
size_t *calloc(size_t, int);
int /*<<< orphan*/ free(size_t *);
int /*<<< orphan*/ memcpy(size_t *, size_t *, size_t);
int /*<<< orphan*/ merge_sort_recurse(size_t *, size_t, size_t *);
int merge_sort(size_t *A, size_t n) {
  size_t *B;
  if ((B = calloc(n, sizeof(size_t)))) {
    memcpy(B, A, n * sizeof(size_t));
    merge_sort_recurse(A, n, B);
    free(B);
  }
  return !!B;
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     119b <merge_sort+0x5b>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
shl    $0x3,%rdx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <merge_sort_recurse@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1189 <merge_sort+0x49>
lea    0x0(,%r14,8),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <memcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1060 <merge_sort_recurse@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
test   %rbx,%rbx
setne  %al
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @merge_sort(i64* %0, i64 %1) {
%3 = alloca i64*
%4 = alloca i64
%5 = alloca i64*
store i64* %0, i64** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = call i64* @calloc(i64 %6, i32 8)
store i64* %7, i64** %5
%8 = icmp ne i64* %7, null
br i1 %8, label %9, label %21
9: ; preds = %2
%10 = load i64*, i64** %5
%11 = load i64*, i64** %3
%12 = load i64, i64* %4
%13 = mul i64 %12, 8
%14 = call i32 @memcpy(i64* %10, i64* %11, i64 %13)
%15 = load i64*, i64** %3
%16 = load i64, i64* %4
%17 = load i64*, i64** %5
%18 = call i32 @merge_sort_recurse(i64* %15, i64 %16, i64* %17)
%19 = load i64*, i64** %5
%20 = call i32 @free(i64* %19)
br label %21
21: ; preds = %9, %2
%22 = load i64*, i64** %5
%23 = icmp ne i64* %22, null
%24 = xor i1 %23, true
%25 = xor i1 %24, true
%26 = zext i1 %25 to i32
ret i32 %26
}

LLVM IR (-O2):
define i32 @merge_sort(i64* %0, i64 %1) {
%3 = tail call i64* @calloc(i64 %1, i32 8)
%4 = icmp ne i64* %3, null
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = shl i64 %1, 3
%7 = tail call i32 @memcpy(i64* %3, i64* %0, i64 %6)
%8 = tail call i32 @merge_sort_recurse(i64* %0, i64 %1, i64* %3)
%9 = tail call i32 @free(i64* %3)
br label %10
10: ; preds = %5, %2
%11 = zext i1 %4 to i32
ret i32 %11
}