#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 */
scalar_t__ EOF;
int /*<<< orphan*/ current_time(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *, int *, int *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ update_entrant_location(int, int, char *);
void read_time_file(char filename[256]) {
  FILE *file;
  file = fopen(filename, "r");
  if (!file) {
    fprintf(stderr, "Can't open the file \"%s\"! (Does it exist?)\n", filename);
  } else {
    int node = 0;
    int competitor_id = 0;
    char type[2];
    char time[6];
    while (fscanf(file, "%s %d %d %s\n", type, &node, &competitor_id, time) !=
           EOF) {
      if (strcmp(type, "T") == 0) {
        update_entrant_location(competitor_id, node, time);
        current_time(time);
      } else {
        printf(
            "An error occurred somewhere. Is the time file syntax correct?\n");
      }
    }
  }
}


x86 assembly (clang, -O0):
<read_time_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b9 <read_time_file+0x49>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe53(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1244 <read_time_file+0xd4>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1a(%rbp),%rdx
lea    -0x20(%rbp),%r9
lea    0xe54(%rip),%rsi
lea    -0x14(%rbp),%rcx
lea    -0x18(%rbp),%r8
call   1040 <fscanf@plt>
mov    0x2dfa(%rip),%rcx
cmp    (%rcx),%rax
je     123f <read_time_file+0xcf>
lea    -0x1a(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    122e <read_time_file+0xbe>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
lea    -0x20(%rbp),%rdx
call   1080 <update_entrant_location@plt>
lea    -0x20(%rbp),%rdi
call   1060 <current_time@plt>
jmp    123a <read_time_file+0xca>
lea    0xe08(%rip),%rdi
call   1030 <printf@plt>
jmp    11c7 <read_time_file+0x57>
jmp    1244 <read_time_file+0xd4>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_time_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0xe78(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11e3 <read_time_file+0x73>
mov    %rax,%r15
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xe82(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0x12(%rsp),%r9
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%rax
jne    1209 <read_time_file+0x99>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
mov    %rbx,%rdx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fprintf@plt>
lea    0x10(%rsp),%rbx
lea    0x12(%rsp),%r12
lea    0xe14(%rip),%r13
lea    0xc(%rsp),%rbp
lea    0x8(%rsp),%r14
jmp    1263 <read_time_file+0xf3>
cs nopw 0x0(%rax,%rax,1)
lea    0xe06(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %r14,%r8
mov    %r12,%r9
call   1040 <fscanf@plt>
mov    0x2d8e(%rip),%rcx
cmp    (%rcx),%rax
je     11d4 <read_time_file+0x64>
mov    %rbx,%rdi
lea    0xdce(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1230 <read_time_file+0xc0>
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
mov    %r12,%rdx
call   1080 <update_entrant_location@plt>
mov    %r12,%rdi
call   1060 <current_time@plt>
jmp    123c <read_time_file+0xcc>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [44 x i8] c"Can't open the file \22%s\22! (Does it exist?)\0A\00"
@.str.2 = [13 x i8] c"%s %d %d %s\0A\00"
@EOF = global i64 0
@.str.3 = [2 x i8] c"T\00"
@.str.4 = [63 x i8] c"An error occurred somewhere. Is the time file syntax correct?\0A\00"
define void @read_time_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2 x i8]
%7 = alloca [6 x i8]
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %3
%10 = load i32*, i32** %3
%11 = icmp ne i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %2
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %39
16: ; preds = %1
store i32 0, i32* %4
store i32 0, i32* %5
br label %17
17: ; preds = %37, %16
%18 = load i32*, i32** %3
%19 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%20 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%21 = call i64 @fscanf(i32* %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %19, i32* %4, i32* %5, i8* %20)
%22 = load i64, i64* @EOF
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %38
24: ; preds = %17
%25 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %24
%29 = load i32, i32* %5
%30 = load i32, i32* %4
%31 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%32 = call i32 @update_entrant_location(i32 %29, i32 %30, i8* %31)
%33 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%34 = call i32 @current_time(i8* %33)
br label %37
35: ; preds = %24
%36 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.4, i64 0, i64 0))
br label %37
37: ; preds = %35, %28
br label %17
38: ; preds = %17
br label %39
39: ; preds = %38, %12
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [44 x i8] c"Can't open the file \22%s\22! (Does it exist?)\0A\00"
@.str.2 = [13 x i8] c"%s %d %d %s\0A\00"
@EOF = global i64 0
@.str.3 = [2 x i8] c"T\00"
@str = [62 x i8] c"An error occurred somewhere. Is the time file syntax correct?\00"
define void @read_time_file(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x i8]
%5 = alloca [6 x i8]
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %34
11: ; preds = %1
%12 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%13 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%15 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%16 = call i64 @fscanf(i32* %6, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %14, i32* %2, i32* %3, i8* %15)
%17 = load i64, i64* @EOF
%18 = icmp eq i64 %16, %17
br i1 %18, label %33, label %19
19: ; preds = %11, %29
%20 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* %3
%24 = load i32, i32* %2
%25 = call i32 @update_entrant_location(i32 %23, i32 %24, i8* %15)
%26 = call i32 @current_time(i8* %15)
br label %29
27: ; preds = %19
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str, i64 0, i64 0))
br label %29
29: ; preds = %27, %22
%30 = call i64 @fscanf(i32* %6, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %14, i32* %2, i32* %3, i8* %15)
%31 = load i64, i64* @EOF
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %19
33: ; preds = %29, %11
br label %34
34: ; preds = %33, %8
ret void
}