#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 EOF;
int /*<<< orphan*/ add_edge(int, int, int, double);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int read_one_edge(int /*<<< orphan*/ *, int *, int *, int *, double *);
int /*<<< orphan*/ stderr;
void read_edges_from_file(char *name) {
  FILE *f = NULL;
  int from = 0, to = 0, delay = 0, n = 0, i = 0;
  double effect = 0;
  f = fopen(name, "r");
  if (f == NULL) {
    fprintf(stderr, "Fail to read \"%s\" for edges.\n", name);
    exit(-1);
  }
  i = 0;
  while (!feof(f)) {
    n = read_one_edge(f, &from, &to, &delay, &effect);
    if (n == EOF || (n == 0 && feof(f))) {
      break;
    } else if (n == 0) {
      continue;
    } else if (n != 4) {
      fprintf(stderr,
              "Error in reading edge file, after reading %d edge(s).\nIn the "
              "edge file, each line represents an edge, with the 0-based "
              "'from' index, followed by 0-based 'to' index, followed by "
              "delay, followed by the effect, all separated by space.\n",
              i);
      exit(-1);
    }
    add_edge(from, to, delay, effect);
    i++;
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<read_edges_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f3 <read_edges_from_file+0x83>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1219 <read_edges_from_file+0xa9>
jmp    12d1 <read_edges_from_file+0x161>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x30(%rbp),%r8
call   1070 <read_one_edge@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2da9(%rip),%rcx
cmp    (%rcx),%eax
je     1264 <read_edges_from_file+0xf4>
cmpl   $0x0,-0x20(%rbp)
jne    1269 <read_edges_from_file+0xf9>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     1269 <read_edges_from_file+0xf9>
jmp    12d1 <read_edges_from_file+0x161>
cmpl   $0x0,-0x20(%rbp)
jne    1278 <read_edges_from_file+0x108>
jmp    11fa <read_edges_from_file+0x8a>
cmpl   $0x4,-0x20(%rbp)
je     12a6 <read_edges_from_file+0x136>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xd8b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    12ab <read_edges_from_file+0x13b>
jmp    12b0 <read_edges_from_file+0x140>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
movsd  -0x30(%rbp),%xmm0
call   1030 <add_edge@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11fa <read_edges_from_file+0x8a>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_edges_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe57(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1276 <read_edges_from_file+0x106>
mov    %rax,%rbx
movl   $0x0,(%rsp)
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%r12
lea    0x4(%rsp),%r13
lea    0x10(%rsp),%rbp
mov    0x2e0c(%rip),%r14
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    123b <read_edges_from_file+0xcb>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
call   1070 <read_one_edge@plt>
cmp    (%r14),%eax
je     123b <read_edges_from_file+0xcb>
test   %eax,%eax
jne    1219 <read_edges_from_file+0xa9>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %rax,%rax
je     11e0 <read_edges_from_file+0x70>
jmp    123b <read_edges_from_file+0xcb>
cmp    $0x4,%eax
jne    1252 <read_edges_from_file+0xe2>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
movsd  0x10(%rsp),%xmm0
call   1030 <add_edge@plt>
addl   $0x1,(%rsp)
jmp    11e0 <read_edges_from_file+0x70>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
lea    0xdbe(%rip),%rsi
mov    (%rsp),%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Fail to read \22%s\22 for edges.\0A\00"
@EOF = global i32 0
@.str.2 = [233 x i8] c"Error in reading edge file, after reading %d edge(s).\0AIn the edge file, each line represents an edge, with the 0-based 'from' index, followed by 0-based 'to' index, followed by delay, followed by the effect, all separated by space.\0A\00"
define void @read_edges_from_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
store i8* %0, i8** %2
store i32* null, i32** %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store double 0.000000e+00, double* %9
%10 = load i8*, i8** %2
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %19
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %2
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %1
store i32 0, i32* %8
br label %20
20: ; preds = %53, %42, %19
%21 = load i32*, i32** %3
%22 = call i64 @feof(i32* %21)
%23 = icmp ne i64 %22, 0
%24 = xor i1 %23, true
br i1 %24, label %25, label %61
25: ; preds = %20
%26 = load i32*, i32** %3
%27 = call i32 @read_one_edge(i32* %26, i32* %4, i32* %5, i32* %6, double* %9)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %38, label %31
31: ; preds = %25
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i32*, i32** %3
%36 = call i64 @feof(i32* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34, %25
br label %61
39: ; preds = %34, %31
%40 = load i32, i32* %7
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %39
br label %20
43: ; preds = %39
%44 = load i32, i32* %7
%45 = icmp ne i32 %44, 4
br i1 %45, label %46, label %51
46: ; preds = %43
%47 = load i32, i32* @stderr
%48 = load i32, i32* %8
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([233 x i8], [233 x i8]* @.str.2, i64 0, i64 0), i32 %48)
%50 = call i32 @exit(i32 -1)
unreachable
51: ; preds = %43
br label %52
52: ; preds = %51
br label %53
53: ; preds = %52
%54 = load i32, i32* %4
%55 = load i32, i32* %5
%56 = load i32, i32* %6
%57 = load double, double* %9
%58 = call i32 @add_edge(i32 %54, i32 %55, i32 %56, double %57)
%59 = load i32, i32* %8
%60 = add nsw i32 %59, 1
store i32 %60, i32* %8
br label %20
61: ; preds = %38, %20
%62 = load i32*, i32** %3
%63 = call i32 @fclose(i32* %62)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Fail to read \22%s\22 for edges.\0A\00"
@EOF = global i32 0
@.str.2 = [233 x i8] c"Error in reading edge file, after reading %d edge(s).\0AIn the edge file, each line represents an edge, with the 0-based 'from' index, followed by 0-based 'to' index, followed by delay, followed by the effect, all separated by space.\0A\00"
define void @read_edges_from_file(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%7 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = bitcast double* %5 to i8*
store double 0.000000e+00, double* %5
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %38
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %38, %24
%17 = call i64 @feof(i32* %10)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %40
19: ; preds = %16
%20 = call i32 @read_one_edge(i32* %10, i32* %2, i32* %3, i32* %4, double* %5)
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %40, label %23
23: ; preds = %19
switch i32 %20, label %27 [
i32 0, label %24
i32 4, label %31
]
24: ; preds = %23
%25 = call i64 @feof(i32* %10)
%26 = icmp eq i64 %25, 0
br i1 %26, label %16, label %40
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([233 x i8], [233 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%30 = call i32 @exit(i32 -1)
unreachable
31: ; preds = %23
%32 = load i32, i32* %2
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = load double, double* %5
%36 = call i32 @add_edge(i32 %32, i32 %33, i32 %34, double %35)
%37 = add nuw nsw i32 %39, 1
br label %38
38: ; preds = %1, %31
%39 = phi i32 [ %37, %31 ], [ 0, %1 ]
br label %16
40: ; preds = %19, %24, %16
%41 = call i32 @fclose(i32* %10)
ret void
}