#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 char_to_int(char);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, int, ...);
int read_basic_csv(char *fileLocation, int numValues, int *values) {
  FILE *filePointer = fopen(fileLocation, "r");
  if (filePointer == NULL) {
    return -3;
  }
  char c;
  int idx = 0;
  while (!feof(filePointer)) {
    c = fgetc(filePointer);
    if (c == -1) {
      fclose(filePointer);
      break;
    }
    printf("read %c, ", c);
    if (c < '0' || c > '9') {
      continue;
    }
    printf("idx = %d, numValues = %d\n", idx, numValues);
    if (idx >= numValues) {
      fclose(filePointer);
      return -2;
    }
    values[idx] = char_to_int(c);
    idx++;
  }
  printf("idx = %d, numValues = %d\n", idx, numValues);
  if (idx == numValues) {
    fclose(filePointer);
    return 0;
  } else {
    fclose(filePointer);
    return -1;
  }
}


x86 assembly (clang, -O0):
<read_basic_csv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119e <read_basic_csv+0x3e>
movl   $0xfffffffd,-0x4(%rbp)
jmp    12b9 <read_basic_csv+0x159>
movl   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11c3 <read_basic_csv+0x63>
jmp    1274 <read_basic_csv+0x114>
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
cmp    $0xffffffff,%eax
jne    11ea <read_basic_csv+0x8a>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1274 <read_basic_csv+0x114>
movsbl -0x29(%rbp),%esi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x29(%rbp),%eax
cmp    $0x30,%eax
jl     1216 <read_basic_csv+0xb6>
movsbl -0x29(%rbp),%eax
cmp    $0x39,%eax
jle    121b <read_basic_csv+0xbb>
jmp    11a5 <read_basic_csv+0x45>
mov    -0x30(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     1250 <read_basic_csv+0xf0>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12b9 <read_basic_csv+0x159>
movsbl -0x29(%rbp),%edi
call   1070 <char_to_int@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11a5 <read_basic_csv+0x45>
mov    -0x30(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    12a9 <read_basic_csv+0x149>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b9 <read_basic_csv+0x159>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_basic_csv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbp
mov    %esi,%r15d
lea    0xe85(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1218 <read_basic_csv+0xb8>
mov    %rax,%rbx
mov    %rbp,0x8(%rsp)
test   %r15d,%r15d
mov    $0x0,%eax
cmovg  %r15d,%eax
mov    %rax,0x10(%rsp)
lea    0xe59(%rip),%rbp
xor    %r12d,%r12d
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1227 <read_basic_csv+0xc7>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    $0xff,%al
je     121f <read_basic_csv+0xbf>
mov    %eax,%r14d
movsbl %al,%r13d
mov    %rbp,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xc6,%r14b
cmp    $0xf6,%r14b
jb     11b0 <read_basic_csv+0x50>
lea    0xe1f(%rip),%rdi
mov    %r12d,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    0x10(%rsp),%r12
je     125f <read_basic_csv+0xff>
mov    %r13d,%edi
call   1070 <char_to_int@plt>
mov    0x8(%rsp),%rcx
mov    %eax,(%rcx,%r12,4)
add    $0x1,%r12
jmp    11b0 <read_basic_csv+0x50>
mov    $0xfffffffd,%ebp
jmp    124e <read_basic_csv+0xee>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xdde(%rip),%rdi
mov    %r12d,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %ebp,%ebp
cmp    %r15d,%r12d
setne  %bpl
mov    %rbx,%rdi
call   1030 <fclose@plt>
neg    %ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0xfffffffe,%ebp
jmp    124e <read_basic_csv+0xee>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [10 x i8] c"read %c, \00"
@.str.2 = [26 x i8] c"idx = %d, numValues = %d\0A\00"
define i32 @read_basic_csv(i8* nocapture %0, i32 %1, i32* nocapture writeonly %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %40, label %6
6: ; preds = %3
%7 = call i32 @llvm.smax.i32(i32 %1, i32 0)
%8 = zext i32 %7 to i64
br label %9
9: ; preds = %6, %30
%10 = phi i64 [ 0, %6 ], [ %33, %30 ]
br label %11
11: ; preds = %9, %19
%12 = tail call i32 @feof(i32* %4)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %34
14: ; preds = %11
%15 = tail call signext i8 @fgetc(i32* %4)
%16 = icmp eq i8 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @fclose(i32* %4)
br label %34
19: ; preds = %14
%20 = sext i8 %15 to i32
%21 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = add i8 %15, -58
%23 = icmp ult i8 %22, -10
br i1 %23, label %11, label %24
24: ; preds = %19
%25 = trunc i64 %10 to i32
%26 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %25, i32 %1)
%27 = icmp eq i64 %10, %8
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = tail call i32 @fclose(i32* %4)
br label %40
30: ; preds = %24
%31 = tail call i32 @char_to_int(i8 signext %15)
%32 = getelementptr inbounds i32, i32* %2, i64 %10
store i32 %31, i32* %32
%33 = add nuw nsw i64 %10, 1
br label %9
34: ; preds = %11, %17
%35 = trunc i64 %10 to i32
%36 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %35, i32 %1)
%37 = icmp ne i32 %35, %1
%38 = tail call i32 @fclose(i32* %4)
%39 = sext i1 %37 to i32
br label %40
40: ; preds = %34, %28, %3
%41 = phi i32 [ -3, %3 ], [ -2, %28 ], [ %39, %34 ]
ret i32 %41
}