#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_FAILURE;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strtok_r(char *, char *, char **);
int readNbClass(char *fname) {
  FILE *inFile = fopen(fname, "r");
  char line[2097152];
  char *sym;
  int label;
  int maxLabel = 0;
  char *ctxL;
  if (!inFile) {
    fprintf(stderr, "File %s does not exist\n", fname);
    exit(EXIT_FAILURE);
  }
  fgets(line, 2097152, inFile);
  while (fgets(line, 2097152, inFile)) {
    if ((sym = (char *)strtok_r(line, " \n", &ctxL))) {
      sym = (char *)strtok_r(NULL, " \n", &ctxL);
      label = atoi(sym);
      if (label > 0 && label > maxLabel)
        maxLabel = label;
      if (label < -1) {
        fprintf(stderr,
                "Labels must be positive except for auxilary nodes (-1)\n",
                fname);
        exit(EXIT_FAILURE);
      }
    }
  }
  fclose(inFile);
  return maxLabel;
}


x86 assembly (clang, -O0):
<readNbClass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x200030,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x200020(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cf <readNbClass+0x5f>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe46(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    -0x200010(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200000,%esi
call   1050 <fgets@plt>
lea    -0x200010(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200000,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12c7 <readNbClass+0x157>
lea    -0x200010(%rbp),%rdi
lea    0xe09(%rip),%rsi
lea    -0x200028(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x200018(%rbp)
cmp    $0x0,%rax
je     12c2 <readNbClass+0x152>
xor    %eax,%eax
mov    %eax,%edi
lea    0xde1(%rip),%rsi
lea    -0x200028(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x200018(%rbp)
mov    -0x200018(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x20001c(%rbp)
cmpl   $0x0,-0x20001c(%rbp)
jle    1289 <readNbClass+0x119>
mov    -0x20001c(%rbp),%eax
cmp    -0x200020(%rbp),%eax
jle    1289 <readNbClass+0x119>
mov    -0x20001c(%rbp),%eax
mov    %eax,-0x200020(%rbp)
cmpl   $0xffffffff,-0x20001c(%rbp)
jge    12bd <readNbClass+0x14d>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd73(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    12c2 <readNbClass+0x152>
jmp    11e4 <readNbClass+0x74>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x200020(%rbp),%eax
add    $0x200030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readNbClass>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x200018,%rsp
mov    %rdi,%r14
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1270 <readNbClass+0x100>
mov    %rax,%r15
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x200000,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
mov    $0x200000,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1254 <readNbClass+0xe4>
lea    0xe47(%rip),%r12
lea    0x10(%rsp),%r13
lea    0x8(%rsp),%rbp
jmp    11f5 <readNbClass+0x85>
nop
mov    %r13,%rdi
mov    $0x200000,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1254 <readNbClass+0xe4>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1040 <strtok_r@plt>
test   %rax,%rax
je     11e0 <readNbClass+0x70>
xor    %edi,%edi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1040 <strtok_r@plt>
mov    %rax,%rdi
call   1080 <atoi@plt>
cmp    %ebx,%eax
mov    %ebx,%ecx
cmovg  %eax,%ecx
test   %eax,%eax
cmovg  %ecx,%ebx
cmp    $0xfffffffe,%eax
jg     11e0 <readNbClass+0x70>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
add    $0x200018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xd82(%rip),%rsi
jmp    123e <readNbClass+0xce>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"File %s does not exist\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c" \0A\00"
@.str.3 = [56 x i8] c"Labels must be positive except for auxilary nodes (-1)\0A\00"
define i32 @readNbClass(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [2097152 x i8]
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %3
store i32 0, i32* %7
%11 = load i32*, i32** %3
%12 = icmp ne i32* %11, null
br i1 %12, label %19, label %13
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %2
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %1
%20 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %4, i64 0, i64 0
%21 = load i32*, i32** %3
%22 = call i64 @fgets(i8* %20, i32 2097152, i32* %21)
br label %23
23: ; preds = %56, %19
%24 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %4, i64 0, i64 0
%25 = load i32*, i32** %3
%26 = call i64 @fgets(i8* %24, i32 2097152, i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %57
28: ; preds = %23
%29 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %4, i64 0, i64 0
%30 = call i64 @strtok_r(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %8)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %5
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %56
33: ; preds = %28
%34 = call i64 @strtok_r(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %8)
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %5
%36 = load i8*, i8** %5
%37 = call i32 @atoi(i8* %36)
store i32 %37, i32* %6
%38 = load i32, i32* %6
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %33
%41 = load i32, i32* %6
%42 = load i32, i32* %7
%43 = icmp sgt i32 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = load i32, i32* %6
store i32 %45, i32* %7
br label %46
46: ; preds = %44, %40, %33
%47 = load i32, i32* %6
%48 = icmp slt i32 %47, -1
br i1 %48, label %49, label %55
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = load i8*, i8** %2
%52 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0), i8* %51)
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %46
br label %56
56: ; preds = %55, %28
br label %23
57: ; preds = %23
%58 = load i32*, i32** %3
%59 = call i32 @fclose(i32* %58)
%60 = load i32, i32* %7
ret i32 %60
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"File %s does not exist\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c" \0A\00"
@.str.3 = [56 x i8] c"Labels must be positive except for auxilary nodes (-1)\0A\00"
define i32 @readNbClass(i8* %0) {
%2 = alloca [2097152 x i8]
%3 = alloca i8*
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %2, i64 0, i64 0
%6 = bitcast i8** %3 to i8*
%7 = icmp eq i32* %4, null
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %1
%14 = call i64 @fgets(i8* %5, i32 2097152, i32* %4)
%15 = call i64 @fgets(i8* %5, i32 2097152, i32* %4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %39, label %17
17: ; preds = %13, %35
%18 = phi i32 [ %36, %35 ], [ 0, %13 ]
%19 = call i64 @strtok_r(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %35, label %21
21: ; preds = %17
%22 = call i64 @strtok_r(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %3)
%23 = inttoptr i64 %22 to i8*
%24 = call i32 @atoi(i8* %23)
%25 = icmp sgt i32 %24, 0
%26 = icmp sgt i32 %24, %18
%27 = select i1 %25, i1 %26, i1 false
%28 = select i1 %27, i32 %24, i32 %18
%29 = icmp slt i32 %24, -1
br i1 %29, label %30, label %35
30: ; preds = %21
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %21, %17
%36 = phi i32 [ %28, %21 ], [ %18, %17 ]
%37 = call i64 @fgets(i8* %5, i32 2097152, i32* %4)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %17
39: ; preds = %35, %13
%40 = phi i32 [ 0, %13 ], [ %36, %35 ]
%41 = call i32 @fclose(i32* %4)
ret i32 %40
}