#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*/ __merge_sort(void *, size_t, size_t, char *,
                                int (*)(void const *, void const *));
int /*<<< orphan*/ assert(int /*<<< orphan*/);
scalar_t__ calloc(size_t, size_t);
int /*<<< orphan*/ free(char *);
void merge_sort(void *base, size_t nmemb, size_t size,
                int (*cmp)(const void *, const void *)) {
  char *buf = (char *)calloc(nmemb, size);
  assert(buf != NULL);
  __merge_sort(base, nmemb, size, buf, cmp);
  free(buf);
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1030 <__merge_sort@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r12
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1050 <calloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %r14,%r8
call   1030 <__merge_sort@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <free@plt>

LLVM IR (-O0):
define void @merge_sort(i8* %0, i64 %1, i64 %2, i32 (i8*, i8*)* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32 (i8*, i8*)*
%9 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i32 (i8*, i8*)* %3, i32 (i8*, i8*)** %8
%10 = load i64, i64* %6
%11 = load i64, i64* %7
%12 = call i64 @calloc(i64 %10, i64 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %9
%14 = load i8*, i8** %9
%15 = icmp ne i8* %14, null
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i8*, i8** %5
%19 = load i64, i64* %6
%20 = load i64, i64* %7
%21 = load i8*, i8** %9
%22 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %8
%23 = call i32 @__merge_sort(i8* %18, i64 %19, i64 %20, i8* %21, i32 (i8*, i8*)* %22)
%24 = load i8*, i8** %9
%25 = call i32 @free(i8* %24)
ret void
}

LLVM IR (-O2):
define void @merge_sort(i8* %0, i64 %1, i64 %2, i32 (i8*, i8*)* %3) {
%5 = tail call i64 @calloc(i64 %1, i64 %2)
%6 = inttoptr i64 %5 to i8*
%7 = icmp ne i64 %5, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32 @__merge_sort(i8* %0, i64 %1, i64 %2, i8* %6, i32 (i8*, i8*)* %3)
%11 = tail call i32 @free(i8* %6)
ret void
}