#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 ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, int *, int *, int *, double *, double *, double *,
           double *);
char xsol_read_csv(const char *csv_file_name, double *x) {
  FILE *fid = fopen(csv_file_name, "r");
  if (fid == NULL) {
    printf("The file %s could not be opened.\n", csv_file_name);
    return 0;
  }
  char *line = NULL;
  size_t len = 0, nlines = 0;
  ssize_t read;
  double cap, ftt, cost, vol;
  int eid, source, target;
  if (fid == NULL) {
    printf("The file %s could not be opened.\n", csv_file_name);
    exit(EXIT_FAILURE);
  }
  printf("\nReading xsol file: %s\n", csv_file_name);
  read = getline(&line, &len, fid);
  nlines = 0;
  while ((read = getline(&line, &len, fid)) != -1) {
    if (sscanf(line, "%d %d %d %lf %lf %lf %lf\n", &eid, &source, &target, &cap,
               &ftt, &vol, &cost) != 7) {
      printf("   Line[%zu] %s could not be read.\n", nlines + 1, line);
      exit(EXIT_FAILURE);
    }
    x[nlines] = vol;
    nlines++;
  }
  fclose(fid);
  if (line) {
    free(line);
  }
  return 1;
}


x86 assembly (clang, -O0):
<xsol_read_csv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bd <xsol_read_csv+0x4d>
mov    -0x10(%rbp),%rsi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movb   $0x0,-0x1(%rbp)
jmp    12fa <xsol_read_csv+0x18a>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1200 <xsol_read_csv+0x90>
mov    -0x10(%rbp),%rsi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rsi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x3c(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
je     12d9 <xsol_read_csv+0x169>
mov    -0x28(%rbp),%rdi
lea    0xde6(%rip),%rsi
lea    -0x64(%rbp),%rdx
lea    -0x68(%rbp),%rcx
lea    -0x6c(%rbp),%r8
lea    -0x48(%rbp),%r9
lea    -0x50(%rbp),%r11
lea    -0x60(%rbp),%r10
lea    -0x58(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1060 <sscanf@plt>
cmp    $0x7,%eax
je     12b6 <xsol_read_csv+0x146>
mov    -0x38(%rbp),%rsi
add    $0x1,%rsi
mov    -0x28(%rbp),%rdx
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movsd  -0x60(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    122e <xsol_read_csv+0xbe>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x28(%rbp)
je     12f6 <xsol_read_csv+0x186>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movb   $0x1,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xsol_read_csv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1292 <xsol_read_csv+0x122>
mov    %rax,%r15
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe6f(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%rbx
lea    0x10(%rsp),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1080 <getline@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     1276 <xsol_read_csv+0x106>
mov    $0x1,%ebx
lea    0x40(%rsp),%r13
lea    0x8(%rsp),%rbp
lea    0x10(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x8(%rsp),%rdi
sub    $0x8,%rsp
lea    0xe1c(%rip),%rsi
lea    0x34(%rsp),%rdx
lea    0x30(%rsp),%rcx
lea    0x2c(%rsp),%r8
mov    %r13,%r9
lea    0x38(%rsp),%rax
push   %rax
lea    0x28(%rsp),%rax
push   %rax
lea    0x50(%rsp),%rax
push   %rax
call   1060 <sscanf@plt>
add    $0x20,%rsp
cmp    $0x7,%eax
jne    12b6 <xsol_read_csv+0x146>
movsd  0x18(%rsp),%xmm0
movsd  %xmm0,-0x8(%r14,%rbx,8)
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1080 <getline@plt>
add    $0x1,%rbx
cmp    $0xffffffff,%eax
jne    1210 <xsol_read_csv+0xa0>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     128d <xsol_read_csv+0x11d>
call   1030 <free@plt>
mov    $0x1,%bpl
jmp    12a5 <xsol_read_csv+0x135>
lea    0xd69(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%rdx
lea    0xd94(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [34 x i8] c"The file %s could not be opened.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [24 x i8] c"\0AReading xsol file: %s\0A\00"
@.str.3 = [26 x i8] c"%d %d %d %lf %lf %lf %lf\0A\00"
@.str.4 = [36 x i8] c" Line[%zu] %s could not be read.\0A\00"
define signext i8 @xsol_read_csv(i8* %0, double* %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca double*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i8* %0, i8** %4
store double* %1, double** %5
%18 = load i8*, i8** %4
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = load i8*, i8** %4
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %23)
store i8 0, i8* %3
br label %69
25: ; preds = %2
store i8* null, i8** %7
store i64 0, i64* %8
store i64 0, i64* %9
%26 = load i32*, i32** %6
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i8*, i8** %4
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %25
%34 = load i8*, i8** %4
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = load i32*, i32** %6
%37 = call i32 @getline(i8** %7, i64* %8, i32* %36)
store i32 %37, i32* %10
store i64 0, i64* %9
br label %38
38: ; preds = %53, %33
%39 = load i32*, i32** %6
%40 = call i32 @getline(i8** %7, i64* %8, i32* %39)
store i32 %40, i32* %10
%41 = icmp ne i32 %40, -1
br i1 %41, label %42, label %60
42: ; preds = %38
%43 = load i8*, i8** %7
%44 = call i32 @sscanf(i8* %43, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32* %15, i32* %16, i32* %17, double* %11, double* %12, double* %14, double* %13)
%45 = icmp ne i32 %44, 7
br i1 %45, label %46, label %53
46: ; preds = %42
%47 = load i64, i64* %9
%48 = add i64 %47, 1
%49 = load i8*, i8** %7
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i64 %48, i8* %49)
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %42
%54 = load double, double* %14
%55 = load double*, double** %5
%56 = load i64, i64* %9
%57 = getelementptr inbounds double, double* %55, i64 %56
store double %54, double* %57
%58 = load i64, i64* %9
%59 = add i64 %58, 1
store i64 %59, i64* %9
br label %38
60: ; preds = %38
%61 = load i32*, i32** %6
%62 = call i32 @fclose(i32* %61)
%63 = load i8*, i8** %7
%64 = icmp ne i8* %63, null
br i1 %64, label %65, label %68
65: ; preds = %60
%66 = load i8*, i8** %7
%67 = call i32 @free(i8* %66)
br label %68
68: ; preds = %65, %60
store i8 1, i8* %3
br label %69
69: ; preds = %68, %22
%70 = load i8, i8* %3
ret i8 %70
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [34 x i8] c"The file %s could not be opened.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [24 x i8] c"\0AReading xsol file: %s\0A\00"
@.str.3 = [26 x i8] c"%d %d %d %lf %lf %lf %lf\0A\00"
@.str.4 = [36 x i8] c" Line[%zu] %s could not be read.\0A\00"
define signext i8 @xsol_read_csv(i8* %0, double* nocapture writeonly %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %54
16: ; preds = %2
%17 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%18 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%19 = bitcast double* %5 to i8*
%20 = bitcast double* %6 to i8*
%21 = bitcast double* %7 to i8*
%22 = bitcast double* %8 to i8*
%23 = bitcast i32* %9 to i8*
%24 = bitcast i32* %10 to i8*
%25 = bitcast i32* %11 to i8*
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%27 = call i32 @getline(i8** %3, i64* %4, i32* %12)
%28 = call i32 @getline(i8** %3, i64* %4, i32* %12)
%29 = icmp eq i32 %28, -1
br i1 %29, label %47, label %30
30: ; preds = %16, %41
%31 = phi i64 [ %44, %41 ], [ 0, %16 ]
%32 = load i8*, i8** %3
%33 = call i32 @sscanf(i8* %32, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32* %9, i32* %10, i32* %11, double* %5, double* %6, double* %8, double* %7)
%34 = icmp eq i32 %33, 7
br i1 %34, label %41, label %35
35: ; preds = %30
%36 = add i64 %31, 1
%37 = load i8*, i8** %3
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i64 %36, i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %30
%42 = load double, double* %8
%43 = getelementptr inbounds double, double* %1, i64 %31
store double %42, double* %43
%44 = add i64 %31, 1
%45 = call i32 @getline(i8** %3, i64* %4, i32* %12)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %30
47: ; preds = %41, %16
%48 = call i32 @fclose(i32* %12)
%49 = load i8*, i8** %3
%50 = icmp eq i8* %49, null
br i1 %50, label %53, label %51
51: ; preds = %47
%52 = call i32 @free(i8* %49)
br label %53
53: ; preds = %51, %47
br label %54
54: ; preds = %53, %14
%55 = phi i8 [ 0, %14 ], [ 1, %53 ]
ret i8 %55
}