#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(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int read_basic_csv(char *fileLocation, int numValues, int *values) {
  int ii = 0;
  int nextValue;
  FILE *fileLoc = fopen(fileLocation, "r+");
  if (fileLoc == 0)
    return -3;
  while (!feof(fileLoc)) {
    if (ii >= numValues) {
      fclose(fileLoc);
      return -2;
    }
    nextValue = char_to_int(fgetc(fileLoc));
    values[ii] = nextValue;
    nextValue = char_to_int(fgetc(fileLoc));
    ii++;
  }
  if (ii != numValues) {
    fclose(fileLoc);
    return -1;
  }
  fclose(fileLoc);
  return 0;
}


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)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1195 <read_basic_csv+0x45>
movl   $0xfffffffd,-0x4(%rbp)
jmp    124c <read_basic_csv+0xfc>
jmp    119a <read_basic_csv+0x4a>
mov    -0x30(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b8 <read_basic_csv+0x68>
jmp    121b <read_basic_csv+0xcb>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11d9 <read_basic_csv+0x89>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    124c <read_basic_csv+0xfc>
mov    -0x30(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,%edi
call   1060 <char_to_int@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,%edi
call   1060 <char_to_int@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119a <read_basic_csv+0x4a>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     123c <read_basic_csv+0xec>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124c <read_basic_csv+0xfc>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-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   %r12
push   %rbx
mov    %rdx,%r15
mov    %esi,%r14d
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11de <read_basic_csv+0x8e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    11c7 <read_basic_csv+0x77>
xor    %ebp,%ebp
test   %r14d,%r14d
mov    $0x0,%r12d
cmovg  %r14d,%r12d
nop
cmp    %rbp,%r12
je     11e6 <read_basic_csv+0x96>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    %eax,%edi
call   1060 <char_to_int@plt>
mov    %eax,(%r15,%rbp,4)
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    %eax,%edi
call   1060 <char_to_int@plt>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     1190 <read_basic_csv+0x40>
xor    %r15d,%r15d
cmp    %r14d,%ebp
setne  %r15b
mov    %rbx,%rdi
call   1030 <fclose@plt>
neg    %r15d
jmp    11f4 <read_basic_csv+0xa4>
mov    $0xfffffffd,%r15d
jmp    11f4 <read_basic_csv+0xa4>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0xfffffffe,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"r+\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 i32
%10 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 0, i32* %8
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %10
%13 = load i32*, i32** %10
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -3, i32* %4
br label %53
16: ; preds = %3
br label %17
17: ; preds = %29, %16
%18 = load i32*, i32** %10
%19 = call i32 @feof(i32* %18)
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
br i1 %21, label %22, label %43
22: ; preds = %17
%23 = load i32, i32* %8
%24 = load i32, i32* %6
%25 = icmp sge i32 %23, %24
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32*, i32** %10
%28 = call i32 @fclose(i32* %27)
store i32 -2, i32* %4
br label %53
29: ; preds = %22
%30 = load i32*, i32** %10
%31 = call i32 @fgetc(i32* %30)
%32 = call i32 @char_to_int(i32 %31)
store i32 %32, i32* %9
%33 = load i32, i32* %9
%34 = load i32*, i32** %7
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
store i32 %33, i32* %37
%38 = load i32*, i32** %10
%39 = call i32 @fgetc(i32* %38)
%40 = call i32 @char_to_int(i32 %39)
store i32 %40, i32* %9
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %17
43: ; preds = %17
%44 = load i32, i32* %8
%45 = load i32, i32* %6
%46 = icmp ne i32 %44, %45
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32*, i32** %10
%49 = call i32 @fclose(i32* %48)
store i32 -1, i32* %4
br label %53
50: ; preds = %43
%51 = load i32*, i32** %10
%52 = call i32 @fclose(i32* %51)
store i32 0, i32* %4
br label %53
53: ; preds = %50, %47, %26, %15
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
@.str = [3 x i8] c"r+\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 ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %33, label %6
6: ; preds = %3
%7 = tail call i32 @feof(i32* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %28
9: ; preds = %6
%10 = call i32 @llvm.smax.i32(i32 %1, i32 0)
%11 = zext i32 %10 to i64
br label %12
12: ; preds = %9, %17
%13 = phi i64 [ 0, %9 ], [ %23, %17 ]
%14 = icmp eq i64 %13, %11
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @fclose(i32* %4)
br label %33
17: ; preds = %12
%18 = tail call i32 @fgetc(i32* %4)
%19 = tail call i32 @char_to_int(i32 %18)
%20 = getelementptr inbounds i32, i32* %2, i64 %13
store i32 %19, i32* %20
%21 = tail call i32 @fgetc(i32* %4)
%22 = tail call i32 @char_to_int(i32 %21)
%23 = add nuw nsw i64 %13, 1
%24 = tail call i32 @feof(i32* %4)
%25 = icmp eq i32 %24, 0
br i1 %25, label %12, label %26
26: ; preds = %17
%27 = trunc i64 %23 to i32
br label %28
28: ; preds = %26, %6
%29 = phi i32 [ 0, %6 ], [ %27, %26 ]
%30 = icmp ne i32 %29, %1
%31 = tail call i32 @fclose(i32* %4)
%32 = sext i1 %30 to i32
br label %33
33: ; preds = %28, %3, %15
%34 = phi i32 [ -2, %15 ], [ -3, %3 ], [ %32, %28 ]
ret i32 %34
}