#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 */
scalar_t__ merge(unsigned long *, unsigned long *, unsigned long, unsigned long,
                 unsigned long);
unsigned long int _mergeSort(unsigned long int arr[], unsigned long int temp[],
                             unsigned long int left, unsigned long int right) {
  unsigned long int mid, inv_count = 0;
  if (right > left) {
    mid = (right + left) / 2;
    inv_count = _mergeSort(arr, temp, left, mid);
    inv_count += _mergeSort(arr, temp, mid + 1, right);
    inv_count += merge(arr, temp, left, mid + 1, right);
  }
  return inv_count;
}


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    %rcx,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    11bd <_mergeSort+0x9d>
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1030 <_mergeSort@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
add    $0x1,%rdx
mov    -0x20(%rbp),%rcx
call   1030 <_mergeSort@plt>
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
mov    -0x20(%rbp),%r8
call   1040 <merge@plt>
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_mergeSort>:
cmp    %rdx,%rcx
jbe    1191 <_mergeSort+0x71>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r12
lea    (%rcx,%rdx,1),%rbx
shr    %rbx
mov    %rbx,%rcx
call   1030 <_mergeSort@plt>
mov    %rax,(%rsp)
add    $0x1,%rbx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <_mergeSort@plt>
mov    %rax,%rbp
add    (%rsp),%rbp
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
mov    %r14,%r8
call   1040 <merge@plt>
add    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
ret

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

LLVM IR (-O2):
define i64 @_mergeSort(i64* %0, i64* %1, i64 %2, i64 %3) {
%5 = icmp ugt i64 %3, %2
br i1 %5, label %8, label %6
6: ; preds = %4, %8
%7 = phi i64 [ %16, %8 ], [ 0, %4 ]
ret i64 %7
8: ; preds = %4
%9 = add i64 %3, %2
%10 = lshr i64 %9, 1
%11 = tail call i64 @_mergeSort(i64* %0, i64* %1, i64 %2, i64 %10)
%12 = add nuw i64 %10, 1
%13 = tail call i64 @_mergeSort(i64* %0, i64* %1, i64 %12, i64 %3)
%14 = add i64 %13, %11
%15 = tail call i64 @merge(i64* %0, i64* %1, i64 %2, i64 %12, i64 %3)
%16 = add i64 %14, %15
br label %6
}