#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 floor(int);
int /*<<< orphan*/ merge(int *, int, int, int);
int *mergeSort(int *A, int p, int q) {
  if (p == q) {
    return A;
  }
  int m = p + floor((q - p) / 2);
  mergeSort(A, p, m);
  mergeSort(A, m + 1, q);
  merge(A, p, m, q);
  return A;
}


x86 assembly (clang, -O0):
<mergeSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    115b <mergeSort+0x2b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11bb <mergeSort+0x8b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1050 <floor@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <mergeSort@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x18(%rbp),%edx
call   1030 <mergeSort@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1040 <merge@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergeSort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
mov    %edx,%eax
sub    %esi,%eax
je     118a <mergeSort+0x5a>
mov    %edx,%r14d
mov    %esi,%ebp
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
call   1050 <floor@plt>
mov    %eax,%r15d
lea    (%r15,%rbp,1),%r12d
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
call   1030 <mergeSort@plt>
lea    (%r15,%rbp,1),%esi
add    $0x1,%esi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1030 <mergeSort@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r14d,%ecx
call   1040 <merge@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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