#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int fwrite(int *, int, int, int /*<<< orphan*/ *);
int scanf(char *, int *);
int /*<<< orphan*/ stdin;
int main(void) {
  int i, j, n, tmp, s;
  int a[2];
  FILE *out, *in;
  in = freopen("input.txt", "r", stdin);
  out = fopen("output.bin", "w+b");
  s = scanf("%d", &n);
  fseek(out, 0L, SEEK_SET);
  for (i = 0; i < n; i++) {
    s = scanf("%d", &tmp);
    s = fwrite(&tmp, sizeof(int), 1, out);
  }
  fflush(out);
  fseek(out, 0L, SEEK_SET);
  for (i = n - 1; i >= 0; i--) {
    for (j = 0; j < i; j++) {
      s = fread(a, sizeof(int), 2, out);
      if (a[0] > a[1]) {
        tmp = a[0];
        a[0] = a[1];
        a[1] = tmp;
        fseek(out, -2 * sizeof(int), SEEK_CUR);
        s = fwrite(a, sizeof(int), 2, out);
      }
      fseek(out, -sizeof(int), SEEK_CUR);
    }
    fseek(out, 0L, SEEK_SET);
  }
  fclose(in);
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
lea    0xe61(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1050 <freopen@plt>
mov    %rax,-0x30(%rbp)
lea    0xe56(%rip),%rdi
lea    0xe5a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
lea    0xe4e(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1080 <scanf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2dec(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <fseek@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    123d <main+0xbd>
lea    0xe12(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1080 <scanf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rcx
lea    -0x14(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11f6 <main+0x76>
mov    -0x28(%rbp),%rdi
call   1060 <fflush@plt>
mov    -0x28(%rbp),%rdi
mov    0x2d7f(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <fseek@plt>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1338 <main+0x1b8>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1314 <main+0x194>
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x4,%esi
mov    $0x2,%edx
call   1030 <fread@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    12ed <main+0x16d>
mov    -0x20(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2d23(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffffffffff8,%rsi
call   1070 <fseek@plt>
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x4,%esi
mov    $0x2,%edx
call   10a0 <fwrite@plt>
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2cf0(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffffffffffc,%rsi
call   1070 <fseek@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1276 <main+0xf6>
mov    -0x28(%rbp),%rdi
mov    0x2cb1(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <fseek@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1265 <main+0xe5>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e4b(%rip),%rax
mov    (%rax),%edx
lea    0xe62(%rip),%rdi
lea    0xe65(%rip),%rsi
call   1050 <freopen@plt>
mov    %rax,0x10(%rsp)
lea    0xe56(%rip),%rdi
lea    0xe5a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
lea    0xe4f(%rip),%rdi
mov    %rsp,%rsi
call   1080 <scanf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
cmpl   $0x0,(%rsp)
jle    1228 <main+0xa8>
lea    0xe25(%rip),%r15
lea    0xc(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <scanf@plt>
mov    %r12,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
add    $0x1,%ebp
cmp    (%rsp),%ebp
jl     1200 <main+0x80>
mov    %rbx,%rdi
call   1060 <fflush@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    (%rsp),%r12d
test   %r12d,%r12d
jle    1324 <main+0x1a4>
lea    0x4(%rsp),%r15
mov    0x2d8c(%rip),%rbp
jmp    1280 <main+0x100>
xchg   %ax,%ax
mov    0x2d69(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
cmp    $0x1,%r12d
mov    %r14d,%r12d
jbe    1324 <main+0x1a4>
cmp    $0x2,%r12d
jb     1311 <main+0x191>
lea    -0x1(%r12),%r14d
mov    $0x1,%r13d
jmp    12bb <main+0x13b>
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0xfffffffffffffffc,%rsi
call   1070 <fseek@plt>
add    $0x1,%r13d
cmp    %r13d,%r12d
je     1260 <main+0xe0>
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x2,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    0x4(%rsp),%eax
mov    0x8(%rsp),%ecx
cmp    %ecx,%eax
jle    12a0 <main+0x120>
mov    %eax,0xc(%rsp)
mov    %ecx,0x4(%rsp)
mov    %eax,0x8(%rsp)
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0xfffffffffffffff8,%rsi
call   1070 <fseek@plt>
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x2,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
jmp    12a0 <main+0x120>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    0x10(%rsp),%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [11 x i8] c"output.bin\00"
@.str.3 = [4 x i8] c"w+b\00"
@.str.4 = [3 x i8] c"%d\00"
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [2 x i32]
%8 = alloca i32*
%9 = alloca i32*
store i32 0, i32* %1
%10 = load i32, i32* @stdin
%11 = call i32* @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %10)
store i32* %11, i32** %9
%12 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i32* %12, i32** %8
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %4)
store i32 %13, i32* %6
%14 = load i32*, i32** %8
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @fseek(i32* %14, i64 0, i32 %15)
store i32 0, i32* %2
br label %17
17: ; preds = %25, %0
%18 = load i32, i32* %2
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %5)
store i32 %22, i32* %6
%23 = load i32*, i32** %8
%24 = call i32 @fwrite(i32* %5, i32 4, i32 1, i32* %23)
store i32 %24, i32* %6
br label %25
25: ; preds = %21
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %17
28: ; preds = %17
%29 = load i32*, i32** %8
%30 = call i32 @fflush(i32* %29)
%31 = load i32*, i32** %8
%32 = load i32, i32* @SEEK_SET
%33 = call i32 @fseek(i32* %31, i64 0, i32 %32)
%34 = load i32, i32* %4
%35 = sub nsw i32 %34, 1
store i32 %35, i32* %2
br label %36
36: ; preds = %78, %28
%37 = load i32, i32* %2
%38 = icmp sge i32 %37, 0
br i1 %38, label %39, label %81
39: ; preds = %36
store i32 0, i32* %3
br label %40
40: ; preds = %71, %39
%41 = load i32, i32* %3
%42 = load i32, i32* %2
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %74
44: ; preds = %40
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%46 = load i32*, i32** %8
%47 = call i32 @fread(i32* %45, i32 4, i32 2, i32* %46)
store i32 %47, i32* %6
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%49 = load i32, i32* %48
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%51 = load i32, i32* %50
%52 = icmp sgt i32 %49, %51
br i1 %52, label %53, label %67
53: ; preds = %44
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%55 = load i32, i32* %54
store i32 %55, i32* %5
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%57 = load i32, i32* %56
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
store i32 %57, i32* %58
%59 = load i32, i32* %5
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
store i32 %59, i32* %60
%61 = load i32*, i32** %8
%62 = load i32, i32* @SEEK_CUR
%63 = call i32 @fseek(i32* %61, i64 -8, i32 %62)
%64 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%65 = load i32*, i32** %8
%66 = call i32 @fwrite(i32* %64, i32 4, i32 2, i32* %65)
store i32 %66, i32* %6
br label %67
67: ; preds = %53, %44
%68 = load i32*, i32** %8
%69 = load i32, i32* @SEEK_CUR
%70 = call i32 @fseek(i32* %68, i64 -4, i32 %69)
br label %71
71: ; preds = %67
%72 = load i32, i32* %3
%73 = add nsw i32 %72, 1
store i32 %73, i32* %3
br label %40
74: ; preds = %40
%75 = load i32*, i32** %8
%76 = load i32, i32* @SEEK_SET
%77 = call i32 @fseek(i32* %75, i64 0, i32 %76)
br label %78
78: ; preds = %74
%79 = load i32, i32* %2
%80 = add nsw i32 %79, -1
store i32 %80, i32* %2
br label %36
81: ; preds = %36
%82 = load i32*, i32** %9
%83 = call i32 @fclose(i32* %82)
%84 = load i32*, i32** %8
%85 = call i32 @fclose(i32* %84)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [11 x i8] c"output.bin\00"
@.str.3 = [4 x i8] c"w+b\00"
@.str.4 = [3 x i8] c"%d\00"
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x i32]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast [2 x i32]* %3 to i8*
%7 = load i32, i32* @stdin
%8 = tail call i32* @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%11 = load i32, i32* @SEEK_SET
%12 = call i32 @fseek(i32* %9, i64 0, i32 %11)
%13 = load i32, i32* %1
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %0, %15
%16 = phi i32 [ %19, %15 ], [ 0, %0 ]
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%18 = call i32 @fwrite(i32* %2, i32 4, i32 1, i32* %9)
%19 = add nuw nsw i32 %16, 1
%20 = load i32, i32* %1
%21 = icmp slt i32 %19, %20
br i1 %21, label %15, label %22
22: ; preds = %15, %0
%23 = call i32 @fflush(i32* %9)
%24 = load i32, i32* @SEEK_SET
%25 = call i32 @fseek(i32* %9, i64 0, i32 %24)
%26 = load i32, i32* %1
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %58
28: ; preds = %22
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
br label %31
31: ; preds = %28, %55
%32 = phi i32 [ %26, %28 ], [ %34, %55 ]
%33 = phi i32 [ %26, %28 ], [ %35, %55 ]
%34 = add i32 %32, -1
%35 = add nsw i32 %33, -1
%36 = icmp ugt i32 %33, 1
br i1 %36, label %40, label %37
37: ; preds = %31
%38 = load i32, i32* @SEEK_SET
%39 = call i32 @fseek(i32* %9, i64 0, i32 %38)
br label %58
40: ; preds = %31, %50
%41 = phi i32 [ %53, %50 ], [ 0, %31 ]
%42 = call i32 @fread(i32* %29, i32 4, i32 2, i32* %9)
%43 = load i32, i32* %29
%44 = load i32, i32* %30
%45 = icmp sgt i32 %43, %44
br i1 %45, label %46, label %50
46: ; preds = %40
store i32 %43, i32* %2
store i32 %44, i32* %29
store i32 %43, i32* %30
%47 = load i32, i32* @SEEK_CUR
%48 = call i32 @fseek(i32* %9, i64 -8, i32 %47)
%49 = call i32 @fwrite(i32* %29, i32 4, i32 2, i32* %9)
br label %50
50: ; preds = %46, %40
%51 = load i32, i32* @SEEK_CUR
%52 = call i32 @fseek(i32* %9, i64 -4, i32 %51)
%53 = add nuw nsw i32 %41, 1
%54 = icmp eq i32 %53, %34
br i1 %54, label %55, label %40
55: ; preds = %50
%56 = load i32, i32* @SEEK_SET
%57 = call i32 @fseek(i32* %9, i64 0, i32 %56)
br i1 %36, label %31, label %58
58: ; preds = %55, %37, %22
%59 = call i32 @fclose(i32* %8)
%60 = call i32 @fclose(i32* %9)
ret i32 0
}