#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 *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strtok(char *, char *);
int readTargets(char *fname, int *unlabeledIdx, char *targets) {
  int idx, 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)) {
    if (pos == unlabeledIdx[0])
      break;
    idx = atoi(strtok(line, " "));
    if (idx != unlabeledIdx[pos + 1] + 1) {
      fprintf(stderr, "Index %i mismatch in target file !\n", idx);
      fprintf(stderr, "Index %i was expected instead\n",
              unlabeledIdx[pos + 1] + 1);
      exit(EXIT_FAILURE);
    }
    label = atoi(strtok(NULL, " "));
    targets[pos++] = label;
    if (label > maxLabel)
      maxLabel = label;
  }
  if (pos < unlabeledIdx[0] - 1) {
    fprintf(stderr, "There are missing targets in the target file\n");
    exit(EXIT_FAILURE);
  }
  fclose(inFile);
  return maxLabel;
}


x86 assembly (clang, -O0):
<readTargets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x200030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11dd <readTargets+0x6d>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    11e2 <readTargets+0x72>
lea    -0x200030(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x200000,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     12ed <readTargets+0x17d>
mov    -0x20(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jne    1215 <readTargets+0xa5>
jmp    12ed <readTargets+0x17d>
lea    -0x200030(%rbp),%rdi
lea    0xdf7(%rip),%rsi
call   1070 <strtok@plt>
mov    %eax,%edi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
mov    (%rcx,%rdx,4),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     12a2 <readTargets+0x132>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd6d(%rip),%rsi
call   1070 <strtok@plt>
mov    %eax,%edi
call   1080 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x20(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jle    12e8 <readTargets+0x178>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    11e2 <readTargets+0x72>
mov    -0x20(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1326 <readTargets+0x1b6>
mov    0x2cd8(%rip),%rax
mov    (%rax),%edi
lea    0xd4e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2cb9(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%eax
add    $0x200030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readTargets>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x200018,%rsp
mov    %rdx,0x8(%rsp)
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe6d(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     12b7 <readTargets+0x147>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
mov    $0x200000,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     124c <readTargets+0xdc>
mov    $0x1,%r12d
lea    0xe4c(%rip),%r13
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    -0x1(%r12),%rax
mov    (%r15),%ecx
cmp    %rcx,%rax
je     124e <readTargets+0xde>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1070 <strtok@plt>
mov    %eax,%edi
call   1080 <atoi@plt>
mov    (%r15,%r12,4),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jne    1274 <readTargets+0x104>
xor    %edi,%edi
mov    %r13,%rsi
call   1070 <strtok@plt>
mov    %eax,%edi
call   1080 <atoi@plt>
mov    0x8(%rsp),%rcx
mov    %al,-0x1(%rcx,%r12,1)
cmp    %ebx,%eax
cmovg  %eax,%ebx
mov    %rbp,%rdi
mov    $0x200000,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
add    $0x1,%r12
test   %rax,%rax
jne    11e0 <readTargets+0x70>
add    $0xffffffffffffffff,%r12
mov    %r12,%rax
jmp    124e <readTargets+0xde>
xor    %eax,%eax
mov    (%r15),%ecx
add    $0xffffffff,%ecx
cmp    %ecx,%eax
jl     12d3 <readTargets+0x163>
mov    %r14,%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    %r12d,%ebx
mov    0x2d62(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xd94(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    (%r15,%rbx,4),%edx
add    $0x1,%edx
lea    0xd9e(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
lea    0xd3b(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    12a9 <readTargets+0x139>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    12a9 <readTargets+0x139>

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"
@.str.3 = [36 x i8] c"Index %i mismatch in target file !\0A\00"
@.str.4 = [31 x i8] c"Index %i was expected instead\0A\00"
@.str.5 = [46 x i8] c"There are missing targets in the target file\0A\00"
define i32 @readTargets(i8* %0, i32* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca [2097152 x i8]
store i8* %0, i8** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
store i32 0, i32* %8
store i32 0, i32* %10
%13 = load i8*, i8** %4
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %11
%15 = load i32*, i32** %11
%16 = icmp ne i32* %15, null
br i1 %16, label %23, label %17
17: ; preds = %3
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %4
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %3
br label %24
24: ; preds = %79, %23
%25 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %12, i64 0, i64 0
%26 = load i32*, i32** %11
%27 = call i64 @fgets(i8* %25, i32 2097152, i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %80
29: ; preds = %24
%30 = load i32, i32* %8
%31 = load i32*, i32** %5
%32 = getelementptr inbounds i32, i32* %31, i64 0
%33 = load i32, i32* %32
%34 = icmp eq i32 %30, %33
br i1 %34, label %35, label %36
35: ; preds = %29
br label %80
36: ; preds = %29
%37 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %12, i64 0, i64 0
%38 = call i32 @strtok(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @atoi(i32 %38)
store i32 %39, i32* %7
%40 = load i32, i32* %7
%41 = load i32*, i32** %5
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %41, i64 %44
%46 = load i32, i32* %45
%47 = add nsw i32 %46, 1
%48 = icmp ne i32 %40, %47
br i1 %48, label %49, label %64
49: ; preds = %36
%50 = load i32, i32* @stderr
%51 = load i32, i32* %7
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %51)
%53 = load i32, i32* @stderr
%54 = load i32*, i32** %5
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %54, i64 %57
%59 = load i32, i32* %58
%60 = add nsw i32 %59, 1
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %60)
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %36
%65 = call i32 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%66 = call i32 @atoi(i32 %65)
store i32 %66, i32* %9
%67 = load i32, i32* %9
%68 = trunc i32 %67 to i8
%69 = load i8*, i8** %6
%70 = load i32, i32* %8
%71 = add nsw i32 %70, 1
store i32 %71, i32* %8
%72 = sext i32 %70 to i64
%73 = getelementptr inbounds i8, i8* %69, i64 %72
store i8 %68, i8* %73
%74 = load i32, i32* %9
%75 = load i32, i32* %10
%76 = icmp sgt i32 %74, %75
br i1 %76, label %77, label %79
77: ; preds = %64
%78 = load i32, i32* %9
store i32 %78, i32* %10
br label %79
79: ; preds = %77, %64
br label %24
80: ; preds = %35, %24
%81 = load i32, i32* %8
%82 = load i32*, i32** %5
%83 = getelementptr inbounds i32, i32* %82, i64 0
%84 = load i32, i32* %83
%85 = sub nsw i32 %84, 1
%86 = icmp slt i32 %81, %85
br i1 %86, label %87, label %92
87: ; preds = %80
%88 = load i32, i32* @stderr
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0))
%90 = load i32, i32* @EXIT_FAILURE
%91 = call i32 @exit(i32 %90)
unreachable
92: ; preds = %80
%93 = load i32*, i32** %11
%94 = call i32 @fclose(i32* %93)
%95 = load i32, i32* %10
ret i32 %95
}

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"
@.str.3 = [36 x i8] c"Index %i mismatch in target file !\0A\00"
@.str.4 = [31 x i8] c"Index %i was expected instead\0A\00"
@.str.5 = [46 x i8] c"There are missing targets in the target file\0A\00"
define i32 @readTargets(i8* %0, i32* nocapture %1, i8* nocapture writeonly %2) {
%4 = alloca [2097152 x i8]
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [2097152 x i8], [2097152 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32* %5, null
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = call i64 @fgets(i8* %6, i32 2097152, i32* %5)
%10 = icmp eq i64 %9, 0
br i1 %10, label %54, label %16
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %8, %41
%17 = phi i64 [ %25, %41 ], [ 0, %8 ]
%18 = phi i32 [ %47, %41 ], [ 0, %8 ]
%19 = load i32, i32* %1
%20 = zext i32 %19 to i64
%21 = icmp eq i64 %17, %20
br i1 %21, label %50, label %22
22: ; preds = %16
%23 = call i32 @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @atoi(i32 %23)
%25 = add nuw i64 %17, 1
%26 = getelementptr inbounds i32, i32* %1, i64 %25
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
%29 = icmp eq i32 %24, %28
br i1 %29, label %41, label %30
30: ; preds = %22
%31 = and i64 %25, 4294967295
%32 = getelementptr inbounds i32, i32* %1, i64 %31
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%35 = load i32, i32* @stderr
%36 = load i32, i32* %32
%37 = add nsw i32 %36, 1
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %22
%42 = call i32 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @atoi(i32 %42)
%44 = trunc i32 %43 to i8
%45 = getelementptr inbounds i8, i8* %2, i64 %17
store i8 %44, i8* %45
%46 = icmp sgt i32 %43, %18
%47 = select i1 %46, i32 %43, i32 %18
%48 = call i64 @fgets(i8* %6, i32 2097152, i32* %5)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %16
50: ; preds = %16, %41
%51 = phi i32 [ %47, %41 ], [ %18, %16 ]
%52 = phi i64 [ %25, %41 ], [ %17, %16 ]
%53 = trunc i64 %52 to i32
br label %54
54: ; preds = %50, %8
%55 = phi i32 [ 0, %8 ], [ %51, %50 ]
%56 = phi i32 [ 0, %8 ], [ %53, %50 ]
%57 = load i32, i32* %1
%58 = add nsw i32 %57, -1
%59 = icmp slt i32 %56, %58
br i1 %59, label %60, label %65
60: ; preds = %54
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0))
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %54
%66 = call i32 @fclose(i32* %5)
ret i32 %55
}