#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 line_num = 0;
  int start_line = line_num;
  int i, n, student_num;
  int rc;
  while (1) {
    if ((rc = scanf("%d", &n)) != 1) {
      return 0;
    }
    if (n == 0) {
      return 0;
    }
    line_num++;
    start_line = line_num;
    int students[n];
    for (i = 0; i < n; i++) {
      if ((rc = scanf("%d", &student_num)) != 1) {
        return (1);
      }
      line_num++;
      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)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    0xea6(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <scanf@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x1,%eax
je     117b <main+0x4b>
movl   $0x0,-0x4(%rbp)
jmp    1276 <main+0x146>
cmpl   $0x0,-0x20(%rbp)
jne    1191 <main+0x61>
movl   $0x0,-0x4(%rbp)
jmp    1276 <main+0x146>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    122e <main+0xfe>
lea    0xe1f(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1040 <scanf@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x1,%eax
je     1209 <main+0xd9>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1255 <main+0x125>
mov    -0x50(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
mov    -0x24(%rbp),%edx
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ce <main+0x9e>
mov    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%esi
lea    -0x48(%rbp),%rdx
call   1050 <split_and_count@plt>
mov    -0x48(%rbp),%rsi
lea    0xdba(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x3c(%rbp),%eax
test   %eax,%eax
je     1271 <main+0x141>
jmp    126c <main+0x13c>
jmp    1276 <main+0x146>
jmp    1153 <main+0x23>
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>
xor    %ecx,%ecx
cmp    $0x1,%eax
jne    1206 <main+0xd6>
lea    0xe9d(%rip),%rbx
lea    -0x30(%rbp),%r15
lea    -0x38(%rbp),%r14
jmp    119f <main+0x6f>
nopl   (%rax)
mov    %r13,%rdi
mov    %r14,%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    1217 <main+0xe7>
mov    -0x2c(%rbp),%eax
test   %rax,%rax
je     1217 <main+0xe7>
mov    %rsp,%r12
mov    %rsp,%r13
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    -0x2c(%rbp),%esi
test   %esi,%esi
jle    1170 <main+0x40>
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    11fe <main+0xce>
mov    -0x30(%rbp),%eax
mov    %eax,0x0(%r13,%r14,4)
add    $0x1,%r14
movslq -0x2c(%rbp),%rsi
cmp    %rsi,%r14
jl     11d0 <main+0xa0>
lea    -0x38(%rbp),%r14
jmp    1170 <main+0x40>
mov    %r12,%rsp
mov    $0x1,%ecx
mov    %ecx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ecx,%ecx
jmp    1206 <main+0xd6>

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 i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
%15 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%16 = load i32, i32* %6
store i32 %16, i32* %7
br label %17
17: ; preds = %2, %59
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %9)
store i32 %18, i32* %11
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 0, i32* %3
br label %60
21: ; preds = %17
%22 = load i32, i32* %9
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 0, i32* %3
br label %60
25: ; preds = %21
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
%28 = load i32, i32* %6
store i32 %28, i32* %7
%29 = load i32, i32* %9
%30 = zext i32 %29 to i64
%31 = call i8* @llvm.stacksave()
store i8* %31, i8** %12
%32 = alloca i32, i64 %30
store i64 %30, i64* %13
store i32 0, i32* %8
br label %33
33: ; preds = %48, %25
%34 = load i32, i32* %8
%35 = load i32, i32* %9
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %51
37: ; preds = %33
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %10)
store i32 %38, i32* %11
%39 = icmp ne i32 %38, 1
br i1 %39, label %40, label %41
40: ; preds = %37
store i32 1, i32* %3
store i32 1, i32* %14
br label %56
41: ; preds = %37
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
%44 = load i32, i32* %10
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %32, i64 %46
store i32 %44, i32* %47
br label %48
48: ; preds = %41
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %33
51: ; preds = %33
%52 = load i32, i32* %9
%53 = call i32 @split_and_count(i32* %32, i32 %52, i64* %15)
%54 = load i64, i64* %15
%55 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %54)
store i32 0, i32* %14
br label %56
56: ; preds = %51, %40
%57 = load i8*, i8** %12
%58 = load i32, i32* %14
switch i32 %58, label %62 [
i32 0, label %59
i32 1, label %60
]
59: ; preds = %56
br label %17
60: ; preds = %56, %24, %20
%61 = load i32, i32* %3
ret i32 %61
62: ; preds = %56
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 %40
10: ; preds = %2
%11 = bitcast i64* %5 to i8*
br label %12
12: ; preds = %10, %33
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 0
br i1 %14, label %40, label %15
15: ; preds = %12
%16 = zext i32 %13 to i64
%17 = call i8* @llvm.stacksave()
%18 = alloca i32, i64 %16
%19 = load i32, i32* %3
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %33
21: ; preds = %15, %26
%22 = phi i64 [ %29, %26 ], [ 0, %15 ]
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%24 = icmp eq i32 %23, 1
br i1 %24, label %26, label %25
25: ; preds = %21
br label %40
26: ; preds = %21
%27 = load i32, i32* %4
%28 = getelementptr inbounds i32, i32* %18, i64 %22
store i32 %27, i32* %28
%29 = add nuw nsw i64 %22, 1
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = icmp slt i64 %29, %31
br i1 %32, label %21, label %33
33: ; preds = %26, %15
%34 = phi i32 [ %19, %15 ], [ %30, %26 ]
%35 = call i32 @split_and_count(i32* %18, i32 %34, i64* %5)
%36 = load i64, i64* %5
%37 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %36)
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%39 = icmp eq i32 %38, 1
br i1 %39, label %12, label %40
40: ; preds = %33, %12, %2, %25
%41 = phi i32 [ 1, %25 ], [ 0, %2 ], [ 0, %12 ], [ 0, %33 ]
ret i32 %41
}