#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*/ sort(int *, int, int, int,
                        int (*)(void const *, void const *));
void merge(int n, int *A, int start, int end,
           int cmp(const void *, const void *)) {
  if ((end - start) < 1) {
    return;
  }
  int middle = (start + end) / 2;
  merge(n, A, start, middle, cmp);
  merge(n, A, middle + 1, end, cmp);
  sort(A, start, middle, end, cmp);
}


x86 assembly (clang, -O0):
<merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
cmp    $0x1,%eax
jge    114d <merge+0x2d>
jmp    11a3 <merge+0x83>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%r8
call   1040 <merge@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%r8
call   1040 <merge@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%r8
call   1030 <sort@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge>:
cmp    %edx,%ecx
jle    1185 <merge+0x65>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %ecx,%r15d
mov    %edx,%ebx
mov    %rsi,%r12
mov    %edi,%r13d
lea    (%r15,%rbx,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %ebp,%ecx
call   1040 <merge@plt>
lea    0x1(%rbp),%edx
mov    %r13d,%edi
mov    %r12,%rsi
mov    %r15d,%ecx
mov    %r14,%r8
call   1040 <merge@plt>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r15d,%ecx
mov    %r14,%r8
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <sort@plt>
ret

LLVM IR (-O0):
define void @merge(i32 %0, i32* %1, i32 %2, i32 %3, i32 (i8*, i8*)* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32 (i8*, i8*)*
%11 = alloca i32
store i32 %0, i32* %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 (i8*, i8*)* %4, i32 (i8*, i8*)** %10
%12 = load i32, i32* %9
%13 = load i32, i32* %8
%14 = sub nsw i32 %12, %13
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %5
br label %39
17: ; preds = %5
%18 = load i32, i32* %8
%19 = load i32, i32* %9
%20 = add nsw i32 %18, %19
%21 = sdiv i32 %20, 2
store i32 %21, i32* %11
%22 = load i32, i32* %6
%23 = load i32*, i32** %7
%24 = load i32, i32* %8
%25 = load i32, i32* %11
%26 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %10
%27 = load i32, i32* %6
%28 = load i32*, i32** %7
%29 = load i32, i32* %11
%30 = add nsw i32 %29, 1
%31 = load i32, i32* %9
%32 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %10
%33 = load i32*, i32** %7
%34 = load i32, i32* %8
%35 = load i32, i32* %11
%36 = load i32, i32* %9
%37 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %10
%38 = call i32 @sort(i32* %33, i32 %34, i32 %35, i32 %36, i32 (i8*, i8*)* %37)
br label %39
39: ; preds = %17, %16
ret void
}

LLVM IR (-O2):
define void @merge(i32 %0, i32* %1, i32 %2, i32 %3, i32 (i8*, i8*)* %4) {
%6 = icmp sgt i32 %3, %2
br i1 %6, label %8, label %7
7: ; preds = %5, %8
ret void
8: ; preds = %5
%9 = add nsw i32 %3, %2
%10 = sdiv i32 %9, 2
tail call void @merge(i32 %0, i32* %1, i32 %2, i32 %10, i32 (i8*, i8*)* %4)
%11 = add nsw i32 %10, 1
tail call void @merge(i32 %0, i32* %1, i32 %11, i32 %3, i32 (i8*, i8*)* %4)
%12 = tail call i32 @sort(i32* %1, i32 %2, i32 %10, i32 %3, i32 (i8*, i8*)* %4)
br label %7
}