#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*/ printf(char *, long);
int scanf(char *, int *);
int /*<<< orphan*/ split_and_count(int *, int, long *);
int main(int argc, char **argv) {
  int i, n, student_num;
  int rc;
  while (1) {
    if ((rc = scanf("%d", &n)) != 1) {
      return 0;
    }
    int students[n];
    for (i = 0; i < n; i++) {
      if ((rc = scanf("%d", &student_num)) != 1) {
        return (1);
      }
      students[i] = student_num;
    }
    long inv;
    split_and_count(students, n, &inv);
    printf("%ld\n", inv);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x1,%eax
je     116e <main+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    123b <main+0x10b>
mov    -0x18(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11f3 <main+0xc3>
lea    0xe51(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <scanf@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x1,%eax
je     11d7 <main+0xa7>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    121a <main+0xea>
mov    -0x48(%rbp),%rax
mov    -0x1c(%rbp),%edx
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119c <main+0x6c>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%esi
lea    -0x40(%rbp),%rdx
call   1050 <split_and_count@plt>
mov    -0x40(%rbp),%rsi
lea    0xdf5(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x34(%rbp),%eax
test   %eax,%eax
je     1236 <main+0x106>
jmp    1231 <main+0x101>
jmp    123b <main+0x10b>
jmp    1146 <main+0x16>
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeb8(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <scanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
jne    1205 <main+0xd5>
lea    0xe9b(%rip),%rbx
lea    -0x30(%rbp),%r14
lea    -0x38(%rbp),%r13
jmp    119f <main+0x6f>
nop
mov    %r15,%rdi
mov    %r13,%rdx
call   1050 <split_and_count@plt>
mov    -0x38(%rbp),%rsi
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
mov    %r12,%rsp
mov    %rbx,%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    1214 <main+0xe4>
mov    %rsp,%r12
mov    -0x2c(%rbp),%eax
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    -0x2c(%rbp),%esi
test   %esi,%esi
jle    1170 <main+0x40>
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    11fd <main+0xcd>
mov    -0x30(%rbp),%eax
mov    %eax,(%r15,%r13,4)
add    $0x1,%r13
movslq -0x2c(%rbp),%rsi
cmp    %rsi,%r13
jl     11d0 <main+0xa0>
lea    -0x38(%rbp),%r13
jmp    1170 <main+0x40>
mov    %r12,%rsp
mov    $0x1,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    1205 <main+0xd5>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %14
14: ; preds = %2, %47
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
store i32 %15, i32* %9
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 0, i32* %3
br label %48
18: ; preds = %14
%19 = load i32, i32* %7
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %10
%22 = alloca i32, i64 %20
store i64 %20, i64* %11
store i32 0, i32* %6
br label %23
23: ; preds = %36, %18
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %39
27: ; preds = %23
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
store i32 %28, i32* %9
%29 = icmp ne i32 %28, 1
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 1, i32* %3
store i32 1, i32* %12
br label %44
31: ; preds = %27
%32 = load i32, i32* %8
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %22, i64 %34
store i32 %32, i32* %35
br label %36
36: ; preds = %31
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %23
39: ; preds = %23
%40 = load i32, i32* %7
%41 = call i32 @split_and_count(i32* %22, i32 %40, i64* %13)
%42 = load i64, i64* %13
%43 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %42)
store i32 0, i32* %12
br label %44
44: ; preds = %39, %30
%45 = load i8*, i8** %10
%46 = load i32, i32* %12
switch i32 %46, label %50 [
i32 0, label %47
i32 1, label %48
]
47: ; preds = %44
br label %14
48: ; preds = %44, %17
%49 = load i32, i32* %3
ret i32 %49
50: ; preds = %44
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %38
10: ; preds = %2
%11 = bitcast i64* %5 to i8*
br label %12
12: ; preds = %10, %31
%13 = load i32, i32* %3
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
%16 = alloca i32, i64 %14
%17 = load i32, i32* %3
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %31
19: ; preds = %12, %24
%20 = phi i64 [ %27, %24 ], [ 0, %12 ]
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%22 = icmp eq i32 %21, 1
br i1 %22, label %24, label %23
23: ; preds = %19
br label %38
24: ; preds = %19
%25 = load i32, i32* %4
%26 = getelementptr inbounds i32, i32* %16, i64 %20
store i32 %25, i32* %26
%27 = add nuw nsw i64 %20, 1
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %27, %29
br i1 %30, label %19, label %31
31: ; preds = %24, %12
%32 = phi i32 [ %17, %12 ], [ %28, %24 ]
%33 = call i32 @split_and_count(i32* %16, i32 %32, i64* %5)
%34 = load i64, i64* %5
%35 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %34)
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%37 = icmp eq i32 %36, 1
br i1 %37, label %12, label %38
38: ; preds = %31, %2, %23
%39 = phi i32 [ 1, %23 ], [ 0, %2 ], [ 0, %31 ]
ret i32 %39
}