#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, int *);
int /*<<< orphan*/ stderr;
char readFile(short *links, int linkCount, short *resources, int zoneCount) {
  FILE *linksFile = fopen("LinksFinal.in", "r");
  FILE *resourcesFile = fopen("ResourcesLowishAmerica.in", "r");
  if (linksFile == NULL || resourcesFile == NULL) {
    fprintf(stderr, "Error! Could not open file.\n");
    return 0;
  }
  for (int i = 0; i < zoneCount; i++) {
    int zoneId;
    int resource;
    fscanf(resourcesFile, "%d %d", &zoneId, &resource);
    resources[zoneId] = (short)resource;
  }
  for (int i = 0; i < linkCount; i++) {
    int start, end;
    fscanf(linksFile, "%d %d", &start, &end);
    links[i * 2] = (short)start;
    links[i * 2 + 1] = (short)end;
  }
  fclose(linksFile);
  fclose(resourcesFile);
  return 1;
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
lea    0xea3(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
lea    0xe9c(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     119a <readFile+0x5a>
cmpq   $0x0,-0x38(%rbp)
jne    11b8 <readFile+0x78>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1050 <fprintf@plt>
movb   $0x0,-0x1(%rbp)
jmp    1283 <readFile+0x143>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1203 <readFile+0xc3>
mov    -0x38(%rbp),%rdi
lea    0xe71(%rip),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x44(%rbp),%rcx
call   1040 <fscanf@plt>
mov    -0x44(%rbp),%eax
mov    %ax,%dx
mov    -0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11bf <readFile+0x7f>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    126d <readFile+0x12d>
mov    -0x30(%rbp),%rdi
lea    0xe26(%rip),%rsi
lea    -0x4c(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   1040 <fscanf@plt>
mov    -0x4c(%rbp),%eax
mov    %ax,%dx
mov    -0x10(%rbp),%rax
mov    -0x48(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    %dx,(%rax,%rcx,2)
mov    -0x50(%rbp),%eax
mov    %ax,%dx
mov    -0x10(%rbp),%rax
mov    -0x48(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dx,(%rax,%rcx,2)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    120a <readFile+0xca>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
movb   $0x1,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebp
mov    %rdx,%r13
mov    %esi,%r12d
mov    %rdi,%rbx
lea    0xea0(%rip),%rdi
lea    0xea7(%rip),%r15
mov    %r15,%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xe97(%rip),%rdi
mov    %r15,%rsi
call   1060 <fopen@plt>
test   %r14,%r14
je     1239 <readFile+0xf9>
mov    %rax,%r15
test   %rax,%rax
je     1239 <readFile+0xf9>
mov    %r12d,0x14(%rsp)
test   %ebp,%ebp
jle    11dc <readFile+0x9c>
lea    0xc(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
lea    0xe8d(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r12,%rcx
call   1040 <fscanf@plt>
movzwl 0xc(%rsp),%eax
movslq 0x10(%rsp),%rcx
mov    %ax,0x0(%r13,%rcx,2)
add    $0xffffffff,%ebp
jne    11b0 <readFile+0x70>
mov    0x14(%rsp),%eax
test   %eax,%eax
jle    1225 <readFile+0xe5>
mov    %eax,%r12d
xor    %r13d,%r13d
lea    0xc(%rsp),%rbp
nop
mov    %r14,%rdi
lea    0xe4d(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rbp,%rcx
call   1040 <fscanf@plt>
movzwl 0x10(%rsp),%eax
mov    %ax,(%rbx,%r13,4)
movzwl 0xc(%rsp),%eax
mov    %ax,0x2(%rbx,%r13,4)
add    $0x1,%r13
cmp    %r13,%r12
jne    11f0 <readFile+0xb0>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    $0x1,%al
jmp    1250 <readFile+0x110>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"LinksFinal.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"ResourcesLowishAmerica.in\00"
@stderr = global i32 0
@.str.3 = [29 x i8] c"Error! Could not open file.\0A\00"
@.str.4 = [6 x i8] c"%d %d\00"
define signext i8 @readFile(i16* %0, i32 %1, i16* %2, i32 %3) {
%5 = alloca i8
%6 = alloca i16*
%7 = alloca i32
%8 = alloca i16*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i16* %0, i16** %6
store i32 %1, i32* %7
store i16* %2, i16** %8
store i32 %3, i32* %9
%18 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %10
%19 = call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %11
%20 = load i32*, i32** %10
%21 = icmp eq i32* %20, null
br i1 %21, label %25, label %22
22: ; preds = %4
%23 = load i32*, i32** %11
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22, %4
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
store i8 0, i8* %5
br label %76
28: ; preds = %22
store i32 0, i32* %12
br label %29
29: ; preds = %42, %28
%30 = load i32, i32* %12
%31 = load i32, i32* %9
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %45
33: ; preds = %29
%34 = load i32*, i32** %11
%35 = call i32 @fscanf(i32* %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %13, i32* %14)
%36 = load i32, i32* %14
%37 = trunc i32 %36 to i16
%38 = load i16*, i16** %8
%39 = load i32, i32* %13
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i16, i16* %38, i64 %40
store i16 %37, i16* %41
br label %42
42: ; preds = %33
%43 = load i32, i32* %12
%44 = add nsw i32 %43, 1
store i32 %44, i32* %12
br label %29
45: ; preds = %29
store i32 0, i32* %15
br label %46
46: ; preds = %68, %45
%47 = load i32, i32* %15
%48 = load i32, i32* %7
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %71
50: ; preds = %46
%51 = load i32*, i32** %10
%52 = call i32 @fscanf(i32* %51, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %16, i32* %17)
%53 = load i32, i32* %16
%54 = trunc i32 %53 to i16
%55 = load i16*, i16** %6
%56 = load i32, i32* %15
%57 = mul nsw i32 %56, 2
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i16, i16* %55, i64 %58
store i16 %54, i16* %59
%60 = load i32, i32* %17
%61 = trunc i32 %60 to i16
%62 = load i16*, i16** %6
%63 = load i32, i32* %15
%64 = mul nsw i32 %63, 2
%65 = add nsw i32 %64, 1
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i16, i16* %62, i64 %66
store i16 %61, i16* %67
br label %68
68: ; preds = %50
%69 = load i32, i32* %15
%70 = add nsw i32 %69, 1
store i32 %70, i32* %15
br label %46
71: ; preds = %46
%72 = load i32*, i32** %10
%73 = call i32 @fclose(i32* %72)
%74 = load i32*, i32** %11
%75 = call i32 @fclose(i32* %74)
store i8 1, i8* %5
br label %76
76: ; preds = %71, %25
%77 = load i8, i8* %5
ret i8 %77
}

LLVM IR (-O2):
@.str = [14 x i8] c"LinksFinal.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"ResourcesLowishAmerica.in\00"
@stderr = global i32 0
@.str.3 = [29 x i8] c"Error! Could not open file.\0A\00"
@.str.4 = [6 x i8] c"%d %d\00"
define signext i8 @readFile(i16* nocapture writeonly %0, i32 %1, i16* nocapture writeonly %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %9, null
%12 = icmp eq i32* %10, null
%13 = or i1 %11, %12
br i1 %13, label %19, label %14
14: ; preds = %4
%15 = icmp sgt i32 %3, 0
br i1 %15, label %16, label %22
16: ; preds = %14
%17 = bitcast i32* %5 to i8*
%18 = bitcast i32* %6 to i8*
br label %28
19: ; preds = %4
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %54
22: ; preds = %28, %14
%23 = icmp sgt i32 %1, 0
br i1 %23, label %24, label %38
24: ; preds = %22
%25 = bitcast i32* %7 to i8*
%26 = bitcast i32* %8 to i8*
%27 = zext i32 %1 to i64
br label %41
28: ; preds = %16, %28
%29 = phi i32 [ 0, %16 ], [ %36, %28 ]
%30 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %5, i32* %6)
%31 = load i32, i32* %6
%32 = trunc i32 %31 to i16
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i16, i16* %2, i64 %34
store i16 %32, i16* %35
%36 = add nuw nsw i32 %29, 1
%37 = icmp eq i32 %36, %3
br i1 %37, label %22, label %28
38: ; preds = %41, %22
%39 = call i32 @fclose(i32* %9)
%40 = call i32 @fclose(i32* %10)
br label %54
41: ; preds = %24, %41
%42 = phi i64 [ 0, %24 ], [ %52, %41 ]
%43 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %7, i32* %8)
%44 = load i32, i32* %7
%45 = trunc i32 %44 to i16
%46 = shl nuw nsw i64 %42, 1
%47 = getelementptr inbounds i16, i16* %0, i64 %46
store i16 %45, i16* %47
%48 = load i32, i32* %8
%49 = trunc i32 %48 to i16
%50 = or i64 %46, 1
%51 = getelementptr inbounds i16, i16* %0, i64 %50
store i16 %49, i16* %51
%52 = add nuw nsw i64 %42, 1
%53 = icmp eq i64 %52, %27
br i1 %53, label %38, label %41
54: ; preds = %38, %19
%55 = phi i8 [ 0, %19 ], [ 1, %38 ]
ret i8 %55
}