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


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

x86 assembly (clang, -O2):
<merge_sort>:
cmp    %rdx,%rsi
jge    117a <merge_sort+0x5a>
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
lea    (%rdx,%rsi,1),%rax
mov    %rax,%rbx
shr    $0x3f,%rbx
add    %rax,%rbx
sar    %rbx
mov    %rbx,%rdx
call   1040 <merge_sort@plt>
lea    0x1(%rbx),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1040 <merge_sort@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <merge@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @merge_sort(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 = add nsw i64 %12, %13
%15 = sdiv i64 %14, 2
store i64 %15, i64* %7
%16 = load i64*, i64** %4
%17 = load i64, i64* %5
%18 = load i64, i64* %7
%19 = call i32 @merge_sort(i64* %16, i64 %17, i64 %18)
%20 = load i64*, i64** %4
%21 = load i64, i64* %7
%22 = add nsw i64 %21, 1
%23 = load i64, i64* %6
%24 = call i32 @merge_sort(i64* %20, i64 %22, i64 %23)
%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 i32 0
}

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