#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(long long *, long long, long long, long long);
void mergeSort(long long int A[], long long int p, long long int r) {
  if (p < r) {
    long long int q = p + (r - p) / 2;
    mergeSort(A, p, q);
    mergeSort(A, q + 1, r);
    merge(A, p, q, r);
  }
}


x86 assembly (clang, -O0):
<mergeSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11a5 <mergeSort+0x85>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <mergeSort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0x18(%rbp),%rdx
call   1030 <mergeSort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1040 <merge@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergeSort>:
mov    %rdx,%rax
sub    %rsi,%rax
jle    1180 <mergeSort+0x60>
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
mov    %rax,%rbx
shr    $0x3f,%rbx
add    %rax,%rbx
sar    %rbx
lea    (%rbx,%rsi,1),%r12
mov    %r12,%rdx
call   1030 <mergeSort@plt>
lea    (%rbx,%r13,1),%rsi
add    $0x1,%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1030 <mergeSort@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <merge@plt>
ret

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

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