#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 /*<<< orphan*/ printf(char *, int, int, ...);
void mergeSort(int a[], int p, int r) {
  if (p < r) {
    int q = floor((p + r) / 2);
    printf("Calling MergetSort(%d, %d)\n", p, q);
    mergeSort(a, p, q);
    printf("Calling MergetSort(%d, %d)\n", q + 1, r);
    mergeSort(a, q + 1, r);
    printf("Calling merge(%d, %d, %d)\n ", p, q, r);
    merge(a, p, q, r);
  }
}


x86 assembly (clang, -O0):
<mergeSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11eb <mergeSort+0xab>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1060 <floor@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <mergeSort@plt>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <mergeSort@plt>
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1050 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergeSort>:
cmp    %edx,%esi
jge    11e7 <mergeSort+0xa7>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebx
mov    %rdi,%r15
lea    (%r14,%rbx,1),%eax
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
call   1060 <floor@plt>
mov    %eax,%r12d
lea    0xe89(%rip),%r13
mov    %r13,%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
call   1040 <mergeSort@plt>
lea    0x1(%r12),%ebp
mov    %r13,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1040 <mergeSort@plt>
lea    0xe62(%rip),%rdi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <merge@plt>
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Calling MergetSort(%d, %d)\0A\00"
@.str.1 = [28 x i8] c"Calling merge(%d, %d, %d)\0A \00"
define void @mergeSort(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = load i32, i32* %6
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %40
11: ; preds = %3
%12 = load i32, i32* %5
%13 = load i32, i32* %6
%14 = add nsw i32 %12, %13
%15 = sdiv i32 %14, 2
%16 = call i32 @floor(i32 %15)
store i32 %16, i32* %7
%17 = load i32, i32* %5
%18 = load i32, i32* %7
%19 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18)
%20 = load i32*, i32** %4
%21 = load i32, i32* %5
%22 = load i32, i32* %7
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
%25 = load i32, i32* %6
%26 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %24, i32 %25)
%27 = load i32*, i32** %4
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
%30 = load i32, i32* %6
%31 = load i32, i32* %5
%32 = load i32, i32* %7
%33 = load i32, i32* %6
%34 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %32, i32 %33)
%35 = load i32*, i32** %4
%36 = load i32, i32* %5
%37 = load i32, i32* %7
%38 = load i32, i32* %6
%39 = call i32 @merge(i32* %35, i32 %36, i32 %37, i32 %38)
br label %40
40: ; preds = %11, %3
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"Calling MergetSort(%d, %d)\0A\00"
@.str.1 = [28 x i8] c"Calling merge(%d, %d, %d)\0A \00"
define void @mergeSort(i32* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, %2
br i1 %4, label %6, label %5
5: ; preds = %3, %6
ret void
6: ; preds = %3
%7 = add nsw i32 %2, %1
%8 = sdiv i32 %7, 2
%9 = tail call i32 @floor(i32 %8)
%10 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %9)
tail call void @mergeSort(i32* %0, i32 %1, i32 %9)
%11 = add nsw i32 %9, 1
%12 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %2)
tail call void @mergeSort(i32* %0, i32 %11, i32 %2)
%13 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %9, i32 %2)
%14 = tail call i32 @merge(i32* %0, i32 %1, i32 %9, i32 %2)
br label %5
}