#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ selector(int, int);
int main() {
  int n, s = 0, num_lineas;
  FILE *fp;
  if ((fp = fopen("levels.txt", "r+"))) {
    while (fscanf(fp, "%d", &n) == 1)
      num_lineas++;
    fclose(fp);
  }
  if (num_lineas == 1) {
    fp = fopen("levels.txt", "r+");
    while (s <= 5) {
      s++;
      selector(s, n);
    }
  } else if (num_lineas == 4) {
    fp = fopen("levels.txt", "r+");
    while (fscanf(fp, "%d", &n) == 1) {
      s++;
      selector(s, n);
    }
  } else {
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe93(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11c0 <main+0x70>
jmp    118c <main+0x3c>
mov    -0x18(%rbp),%rdi
lea    0xe77(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11b7 <main+0x67>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118c <main+0x3c>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x1,-0x10(%rbp)
jne    1209 <main+0xb9>
lea    0xe2f(%rip),%rdi
lea    0xe33(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x5,-0xc(%rbp)
jg     1204 <main+0xb4>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <selector@plt>
jmp    11e1 <main+0x91>
jmp    1274 <main+0x124>
cmpl   $0x4,-0x10(%rbp)
jne    1265 <main+0x115>
lea    0xde6(%rip),%rdi
lea    0xdea(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdd9(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1260 <main+0x110>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <selector@plt>
jmp    122a <main+0xda>
jmp    126f <main+0x11f>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1274 <main+0x124>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xea2(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     129e <main+0x14e>
mov    %rax,%rbx
lea    0xe91(%rip),%r14
lea    0x4(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <fscanf@plt>
add    $0x1,%ebp
cmp    $0x1,%eax
je     1190 <main+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    $0x4,%ebp
je     1225 <main+0xd5>
cmp    $0x1,%ebp
jne    129e <main+0x14e>
lea    0xe3d(%rip),%rdi
lea    0xe41(%rip),%rsi
call   1060 <fopen@plt>
mov    0x4(%rsp),%esi
mov    $0x1,%edi
call   1050 <selector@plt>
mov    0x4(%rsp),%esi
mov    $0x2,%edi
call   1050 <selector@plt>
mov    0x4(%rsp),%esi
mov    $0x3,%edi
call   1050 <selector@plt>
mov    0x4(%rsp),%esi
mov    $0x4,%edi
call   1050 <selector@plt>
mov    0x4(%rsp),%esi
mov    $0x5,%edi
call   1050 <selector@plt>
mov    0x4(%rsp),%esi
mov    $0x6,%edi
call   1050 <selector@plt>
jmp    1291 <main+0x141>
lea    0xdd4(%rip),%rdi
lea    0xdd8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xdcc(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1291 <main+0x141>
mov    $0x1,%ebp
lea    0xdae(%rip),%r14
lea    0x4(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x4(%rsp),%esi
mov    %ebp,%edi
call   1050 <selector@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <fscanf@plt>
add    $0x1,%ebp
cmp    $0x1,%eax
je     1270 <main+0x120>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"levels.txt\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %3
%6 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %19
8: ; preds = %0
br label %9
9: ; preds = %13, %8
%10 = load i32*, i32** %5
%11 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
store i32 %15, i32* %4
br label %9
16: ; preds = %9
%17 = load i32*, i32** %5
%18 = call i32 @fclose(i32* %17)
br label %19
19: ; preds = %16, %0
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %34
22: ; preds = %19
%23 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %5
br label %24
24: ; preds = %27, %22
%25 = load i32, i32* %3
%26 = icmp sle i32 %25, 5
br i1 %26, label %27, label %33
27: ; preds = %24
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = load i32, i32* %2
%32 = call i32 @selector(i32 %30, i32 %31)
br label %24
33: ; preds = %24
br label %53
34: ; preds = %19
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 4
br i1 %36, label %37, label %50
37: ; preds = %34
%38 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %38, i32** %5
br label %39
39: ; preds = %43, %37
%40 = load i32*, i32** %5
%41 = call i32 @fscanf(i32* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%42 = icmp eq i32 %41, 1
br i1 %42, label %43, label %49
43: ; preds = %39
%44 = load i32, i32* %3
%45 = add nsw i32 %44, 1
store i32 %45, i32* %3
%46 = load i32, i32* %3
%47 = load i32, i32* %2
%48 = call i32 @selector(i32 %46, i32 %47)
br label %39
49: ; preds = %39
br label %52
50: ; preds = %34
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %49
br label %53
53: ; preds = %52, %33
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"levels.txt\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %37, label %5
5: ; preds = %0, %5
%6 = phi i32 [ %9, %5 ], [ undef, %0 ]
%7 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%8 = icmp eq i32 %7, 1
%9 = add nsw i32 %6, 1
br i1 %8, label %5, label %10
10: ; preds = %5
%11 = call i32 @fclose(i32* %3)
switch i32 %6, label %37 [
i32 1, label %12
i32 4, label %26
]
12: ; preds = %10
%13 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* %1
%15 = call i32 @selector(i32 1, i32 %14)
%16 = load i32, i32* %1
%17 = call i32 @selector(i32 2, i32 %16)
%18 = load i32, i32* %1
%19 = call i32 @selector(i32 3, i32 %18)
%20 = load i32, i32* %1
%21 = call i32 @selector(i32 4, i32 %20)
%22 = load i32, i32* %1
%23 = call i32 @selector(i32 5, i32 %22)
%24 = load i32, i32* %1
%25 = call i32 @selector(i32 6, i32 %24)
br label %39
26: ; preds = %10
%27 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @fscanf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %39
30: ; preds = %26, %30
%31 = phi i32 [ %32, %30 ], [ 0, %26 ]
%32 = add nuw nsw i32 %31, 1
%33 = load i32, i32* %1
%34 = call i32 @selector(i32 %32, i32 %33)
%35 = call i32 @fscanf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%36 = icmp eq i32 %35, 1
br i1 %36, label %30, label %39
37: ; preds = %0, %10
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %30, %12, %26
ret i32 0
}