#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 MergeAndCount(int *, int, int);
int SortAndCount(int *arr, int lo, int hi) {
  int mid = (hi + lo) / 2;
  if (hi > lo) {
    int count1 = SortAndCount(arr, lo, mid);
    int count2 = SortAndCount(arr, mid + 1, hi);
    int count3 = MergeAndCount(arr, lo, hi);
    return (count1 + count2 + count3);
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<SortAndCount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1199 <SortAndCount+0x79>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1040 <SortAndCount@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x18(%rbp),%edx
call   1040 <SortAndCount@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <MergeAndCount@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a0 <SortAndCount+0x80>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SortAndCount>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %ebp,%ebp
cmp    %esi,%edx
jle    1171 <SortAndCount+0x51>
mov    %edx,%r14d
mov    %esi,%ebx
mov    %rdi,%r15
lea    (%r14,%rbx,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %ebp,%edx
call   1040 <SortAndCount@plt>
mov    %eax,%r12d
add    $0x1,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1040 <SortAndCount@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
call   1030 <MergeAndCount@plt>
add    %r12d,%ebp
add    %eax,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @SortAndCount(i32* %0, i32 %1, i32 %2) {
%4 = add nsw i32 %2, %1
%5 = sdiv i32 %4, 2
%6 = icmp sgt i32 %2, %1
br i1 %6, label %9, label %7
7: ; preds = %3, %9
%8 = phi i32 [ %15, %9 ], [ 0, %3 ]
ret i32 %8
9: ; preds = %3
%10 = tail call i32 @SortAndCount(i32* %0, i32 %1, i32 %5)
%11 = add nsw i32 %5, 1
%12 = tail call i32 @SortAndCount(i32* %0, i32 %11, i32 %2)
%13 = tail call i32 @MergeAndCount(i32* %0, i32 %1, i32 %2)
%14 = add nsw i32 %12, %10
%15 = add nsw i32 %14, %13
br label %7
}