#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(int /*<<< orphan*/);
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;
int /*<<< orphan*/ strtok(char *, char *);
int readLSVMTargets(char *fname, char *targets) {
  int pos = 0;
  int label, maxlabel = 0;
  FILE *inFile = fopen(fname, "r");
  char line[2097152];
  if (!inFile) {
    fprintf(stderr, "File %s does not exist\n", fname);
    exit(EXIT_FAILURE);
  }
  while (fgets(line, 2097152, inFile)) {
    label = atoi(strtok(line, " "));
    targets[pos++] = label;
    if (label > maxlabel)
      maxlabel = label;
  }
  fclose(inFile);
  return maxlabel;
}


x86 assembly (clang, -O0):
<readLSVMTargets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x200030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d7 <readLSVMTargets+0x67>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe3e(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    11dc <readLSVMTargets+0x6c>
lea    -0x200030(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x200000,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1249 <readLSVMTargets+0xd9>
lea    -0x200030(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   1070 <strtok@plt>
mov    %eax,%edi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    1244 <readLSVMTargets+0xd4>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11dc <readLSVMTargets+0x6c>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
add    $0x200030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readLSVMTargets>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200000,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xe74(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     120c <readLSVMTargets+0x9c>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x200000,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11f2 <readLSVMTargets+0x82>
lea    0xe63(%rip),%r15
mov    %rsp,%r12
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   1070 <strtok@plt>
mov    %eax,%edi
call   1080 <atoi@plt>
mov    %al,(%rbx)
cmp    %ebp,%eax
cmovg  %eax,%ebp
mov    %r12,%rdi
mov    $0x200000,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    11c0 <readLSVMTargets+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x200000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
mov    %rbp,%rdx
call   1050 <fprintf@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

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 = [2 x i8] c" \00"
define i32 @readLSVMTargets(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca [2097152 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32 0, i32* %7
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = icmp ne i32* %12, null
br i1 %13, label %20, label %14
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %3
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
br label %21
21: ; preds = %42, %20
%22 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %9, i64 0, i64 0
%23 = load i32*, i32** %8
%24 = call i64 @fgets(i8* %22, i32 2097152, i32* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %43
26: ; preds = %21
%27 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %9, i64 0, i64 0
%28 = call i32 @strtok(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @atoi(i32 %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %4
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
store i8 %31, i8* %36
%37 = load i32, i32* %6
%38 = load i32, i32* %7
%39 = icmp sgt i32 %37, %38
br i1 %39, label %40, label %42
40: ; preds = %26
%41 = load i32, i32* %6
store i32 %41, i32* %7
br label %42
42: ; preds = %40, %26
br label %21
43: ; preds = %21
%44 = load i32*, i32** %8
%45 = call i32 @fclose(i32* %44)
%46 = load i32, i32* %7
ret i32 %46
}

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 = [2 x i8] c" \00"
define i32 @readLSVMTargets(i8* %0, i8* nocapture writeonly %1) {
%3 = alloca [2097152 x 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]* %3, i64 0, i64 0
%6 = icmp eq i32* %4, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i64 @fgets(i8* %5, i32 2097152, i32* %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %27, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %7, %15
%16 = phi i64 [ %21, %15 ], [ 0, %7 ]
%17 = phi i32 [ %24, %15 ], [ 0, %7 ]
%18 = call i32 @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @atoi(i32 %18)
%20 = trunc i32 %19 to i8
%21 = add nuw i64 %16, 1
%22 = getelementptr inbounds i8, i8* %1, i64 %16
store i8 %20, i8* %22
%23 = icmp sgt i32 %19, %17
%24 = select i1 %23, i32 %19, i32 %17
%25 = call i64 @fgets(i8* %5, i32 2097152, i32* %4)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %15
27: ; preds = %15, %7
%28 = phi i32 [ 0, %7 ], [ %24, %15 ]
%29 = call i32 @fclose(i32* %4)
ret i32 %28
}