#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*/ mergeSortAndCountInversion(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
scalar_t__ scanf(char *, int *);
int main(void) {
  int arr[1000000], mSize, i;
  while (scanf("%d", &mSize) > 0) {
    for (i = 0; i < mSize; i++)
      scanf("%d", &arr[i]);
    printf("%lld\n", mergeSortAndCountInversion(arr, 0, mSize - 1));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3d0920,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
lea    -0x3d0914(%rbp),%rsi
call   1050 <scanf@plt>
cmp    $0x0,%rax
jle    11da <main+0xaa>
movl   $0x0,-0x3d0918(%rbp)
mov    -0x3d0918(%rbp),%eax
cmp    -0x3d0914(%rbp),%eax
jge    11b0 <main+0x80>
movslq -0x3d0918(%rbp),%rax
lea    -0x3d0910(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe69(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x3d0918(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0918(%rbp)
jmp    1169 <main+0x39>
lea    -0x3d0910(%rbp),%rdi
mov    -0x3d0914(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1040 <mergeSortAndCountInversion@plt>
mov    %eax,%esi
lea    0xe33(%rip),%rdi
call   1030 <printf@plt>
jmp    1142 <main+0x12>
xor    %eax,%eax
add    $0x3d0920,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3d0918,%rsp
lea    0xeb8(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
test   %rax,%rax
jle    11df <main+0xaf>
lea    0x10(%rsp),%r14
lea    0xe99(%rip),%r13
lea    0xe95(%rip),%r15
lea    0xc(%rsp),%r12
jmp    11a7 <main+0x77>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xffffffff,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <mergeSortAndCountInversion@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
test   %rax,%rax
jle    11df <main+0xaf>
mov    0xc(%rsp),%edx
test   %edx,%edx
jle    1180 <main+0x50>
mov    %r14,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rdx
add    $0x4,%rbx
cmp    %rdx,%rbp
jl     11c0 <main+0x90>
jmp    1180 <main+0x50>
xor    %eax,%eax
add    $0x3d0918,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000000 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
br label %5
5: ; preds = %21, %0
%6 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%7 = icmp sgt i64 %6, 0
br i1 %7, label %8, label %27
8: ; preds = %5
store i32 0, i32* %4
br label %9
9: ; preds = %18, %8
%10 = load i32, i32* %4
%11 = load i32, i32* %3
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %21
13: ; preds = %9
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 %15
%17 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %16)
br label %18
18: ; preds = %13
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %9
21: ; preds = %9
%22 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %2, i64 0, i64 0
%23 = load i32, i32* %3
%24 = sub nsw i32 %23, 1
%25 = call i32 @mergeSortAndCountInversion(i32* %22, i32 0, i32 %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %5
27: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca [1000000 x i32]
%2 = alloca i32
%3 = bitcast [1000000 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%6 = icmp sgt i64 %5, 0
br i1 %6, label %7, label %27
7: ; preds = %0
%8 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 0
br label %9
9: ; preds = %7, %20
%10 = load i32, i32* %2
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %9, %12
%13 = phi i64 [ %16, %12 ], [ 0, %9 ]
%14 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %1, i64 0, i64 %13
%15 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %14)
%16 = add nuw nsw i64 %13, 1
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %12, label %20
20: ; preds = %12, %9
%21 = phi i32 [ %10, %9 ], [ %17, %12 ]
%22 = add nsw i32 %21, -1
%23 = call i32 @mergeSortAndCountInversion(i32* %8, i32 0, i32 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%26 = icmp sgt i64 %25, 0
br i1 %26, label %9, label %27
27: ; preds = %20, %0
ret i32 0
}