#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 countMinNumFlipByInversion(int *, int);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ scanf(char *, int *);
int main() {
  int lenArr, arr[1000], index;
  while (scanf("%d", &lenArr) > 0) {
    for (index = 0; index < lenArr; index++)
      scanf("%d", &arr[index]);
    printf("Minimum exchange operations : %d\n",
           countMinNumFlipByInversion(arr, lenArr));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmp    $0x0,%rax
jle    11cc <main+0x9c>
movl   $0x0,-0xfb4(%rbp)
mov    -0xfb4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11aa <main+0x7a>
movslq -0xfb4(%rbp),%rax
lea    -0xfb0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe6f(%rip),%rdi
call   1050 <scanf@plt>
mov    -0xfb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfb4(%rbp)
jmp    1166 <main+0x36>
lea    -0xfb0(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <countMinNumFlipByInversion@plt>
mov    %eax,%esi
lea    0xe41(%rip),%rdi
call   1030 <printf@plt>
jmp    1142 <main+0x12>
xor    %eax,%eax
add    $0xfc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xfb8,%rsp
lea    0xeb8(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
test   %rax,%rax
jle    11cf <main+0x9f>
lea    0x10(%rsp),%r14
lea    0xe9d(%rip),%r13
lea    0xe99(%rip),%r15
lea    0xc(%rsp),%r12
jmp    11a2 <main+0x72>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <countMinNumFlipByInversion@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    11cf <main+0x9f>
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    1180 <main+0x50>
mov    %r14,%rbx
xor    %ebp,%ebp
nop
mov    %r13,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rsi
add    $0x4,%rbx
cmp    %rsi,%rbp
jl     11b0 <main+0x80>
jmp    1180 <main+0x50>
xor    %eax,%eax
add    $0xfb8,%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 = [34 x i8] c"Minimum exchange operations : %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1000 x 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* %2)
%7 = icmp sgt i64 %6, 0
br i1 %7, label %8, label %26
8: ; preds = %5
store i32 0, i32* %4
br label %9
9: ; preds = %18, %8
%10 = load i32, i32* %4
%11 = load i32, i32* %2
%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 [1000 x i32], [1000 x i32]* %3, 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 [1000 x i32], [1000 x i32]* %3, i64 0, i64 0
%23 = load i32, i32* %2
%24 = call i32 @countMinNumFlipByInversion(i32* %22, i32 %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %5
26: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [34 x i8] c"Minimum exchange operations : %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [1000 x i32]* %2 to i8*
%5 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = icmp sgt i64 %5, 0
br i1 %6, label %7, label %26
7: ; preds = %0
%8 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 0
br label %9
9: ; preds = %7, %20
%10 = load i32, i32* %1
%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 [1000 x i32], [1000 x i32]* %2, 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* %1
%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 = call i32 @countMinNumFlipByInversion(i32* %8, i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%25 = icmp sgt i64 %24, 0
br i1 %25, label %9, label %26
26: ; preds = %20, %0
ret i32 0
}