#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 */

/* Variables and functions */
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int read_basic_csv(char *, int, int *);
int main(int argc, char const *argv[]) {
  int numValues = 7;
  int *values = malloc(numValues * sizeof(int));
  for (int j = 0; j < numValues; j++) {
    values[j] = -1;
    printf("%d ", values[j]);
  }
  int result =
      read_basic_csv("/Users/shellieo/Documents/GDrive/Y2-SEM2/CAB202/Prac/"
                     "Week5-File IO and Bitwise Operations/sol3array.txt",
                     numValues, values);
  for (int j = 0; j < numValues; j++) {
    printf("%d ", values[j]);
  }
  printf("Result #1 = %d\n\n", result);
  result = read_basic_csv("./testfile.all.txt", numValues, values);
  for (int j = 0; j < numValues; j++) {
    printf("%d ", values[j]);
  }
  printf("Result #2 = %d\n\n", result);
  free(values);
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x7,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b7 <main+0x77>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe5c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1177 <main+0x37>
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    0xe3f(%rip),%rdi
call   1040 <read_basic_csv@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1205 <main+0xc5>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe0e(%rip),%rdi
call   1050 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d4 <main+0x94>
mov    -0x28(%rbp),%esi
lea    0xe5d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    0xe5b(%rip),%rdi
call   1040 <read_basic_csv@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1262 <main+0x122>
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdb1(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1231 <main+0xf1>
mov    -0x28(%rbp),%esi
lea    0xe24(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x1c,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movl   $0xffffffff,(%rax)
lea    0xea2(%rip),%r14
mov    %r14,%rdi
mov    $0xffffffff,%esi
call   1050 <printf@plt>
movl   $0xffffffff,0x4(%rbx)
mov    %r14,%rdi
mov    $0xffffffff,%esi
call   1050 <printf@plt>
movl   $0xffffffff,0x8(%rbx)
mov    %r14,%rdi
mov    $0xffffffff,%esi
call   1050 <printf@plt>
movl   $0xffffffff,0xc(%rbx)
mov    %r14,%rdi
mov    $0xffffffff,%esi
call   1050 <printf@plt>
movl   $0xffffffff,0x10(%rbx)
mov    %r14,%rdi
mov    $0xffffffff,%esi
call   1050 <printf@plt>
movl   $0xffffffff,0x14(%rbx)
mov    %r14,%rdi
mov    $0xffffffff,%esi
call   1050 <printf@plt>
movl   $0xffffffff,0x18(%rbx)
mov    %r14,%rdi
mov    $0xffffffff,%esi
call   1050 <printf@plt>
lea    0xe1a(%rip),%rdi
mov    $0x7,%esi
mov    %rbx,%rdx
call   1040 <read_basic_csv@plt>
mov    %eax,%ebp
mov    (%rbx),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    0x4(%rbx),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    0x8(%rbx),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    0xc(%rbx),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    0x10(%rbx),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    0x14(%rbx),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    0x18(%rbx),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
lea    0xe20(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
lea    0xe23(%rip),%rdi
mov    $0x7,%esi
mov    %rbx,%rdx
call   1040 <read_basic_csv@plt>
mov    %eax,%ebp
mov    (%rbx),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    0x4(%rbx),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    0x8(%rbx),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    0xc(%rbx),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    0x10(%rbx),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    0x14(%rbx),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    0x18(%rbx),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
lea    0xdd4(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
@.str.1 = [104 x i8] c"/Users/shellieo/Documents/GDrive/Y2-SEM2/CAB202/Prac/Week5-File IO and Bitwise Operations/sol3array.txt\00"
@.str.2 = [17 x i8] c"Result = %d\0A\0A\00"
@.str.3 = [19 x i8] c"./testfile.all.txt\00"
@.str.4 = [17 x i8] c"Result = %d\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 7, i32* %6
%12 = load i32, i32* %6
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 4
%15 = trunc i64 %14 to i32
%16 = call i32* @malloc(i32 %15)
store i32* %16, i32** %7
store i32 0, i32* %8
br label %17
17: ; preds = %32, %2
%18 = load i32, i32* %8
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %35
21: ; preds = %17
%22 = load i32*, i32** %7
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
store i32 -1, i32* %25
%26 = load i32*, i32** %7
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %21
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
br label %17
35: ; preds = %17
%36 = load i32, i32* %6
%37 = load i32*, i32** %7
%38 = call i32 @read_basic_csv(i8* getelementptr inbounds ([104 x i8], [104 x i8]* @.str.1, i64 0, i64 0), i32 %36, i32* %37)
store i32 %38, i32* %9
store i32 0, i32* %10
br label %39
39: ; preds = %50, %35
%40 = load i32, i32* %10
%41 = load i32, i32* %6
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %53
43: ; preds = %39
%44 = load i32*, i32** %7
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
%48 = load i32, i32* %47
%49 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %43
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
store i32 %52, i32* %10
br label %39
53: ; preds = %39
%54 = load i32, i32* %9
%55 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %54)
%56 = load i32, i32* %6
%57 = load i32*, i32** %7
%58 = call i32 @read_basic_csv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %56, i32* %57)
store i32 %58, i32* %9
store i32 0, i32* %11
br label %59
59: ; preds = %70, %53
%60 = load i32, i32* %11
%61 = load i32, i32* %6
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %73
63: ; preds = %59
%64 = load i32*, i32** %7
%65 = load i32, i32* %11
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %64, i64 %66
%68 = load i32, i32* %67
%69 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %68)
br label %70
70: ; preds = %63
%71 = load i32, i32* %11
%72 = add nsw i32 %71, 1
store i32 %72, i32* %11
br label %59
73: ; preds = %59
%74 = load i32, i32* %9
%75 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %74)
%76 = load i32*, i32** %7
%77 = call i32 @free(i32* %76)
%78 = load i32, i32* %9
ret i32 %78
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
@.str.1 = [104 x i8] c"/Users/shellieo/Documents/GDrive/Y2-SEM2/CAB202/Prac/Week5-File IO and Bitwise Operations/sol3array.txt\00"
@.str.2 = [17 x i8] c"Result = %d\0A\0A\00"
@.str.3 = [19 x i8] c"./testfile.all.txt\00"
@.str.4 = [17 x i8] c"Result = %d\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @malloc(i32 28)
store i32 -1, i32* %3
%4 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 -1)
%5 = getelementptr inbounds i32, i32* %3, i64 1
store i32 -1, i32* %5
%6 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 -1)
%7 = getelementptr inbounds i32, i32* %3, i64 2
store i32 -1, i32* %7
%8 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 -1)
%9 = getelementptr inbounds i32, i32* %3, i64 3
store i32 -1, i32* %9
%10 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 -1)
%11 = getelementptr inbounds i32, i32* %3, i64 4
store i32 -1, i32* %11
%12 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 -1)
%13 = getelementptr inbounds i32, i32* %3, i64 5
store i32 -1, i32* %13
%14 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 -1)
%15 = getelementptr inbounds i32, i32* %3, i64 6
store i32 -1, i32* %15
%16 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 -1)
%17 = tail call i32 @read_basic_csv(i8* getelementptr inbounds ([104 x i8], [104 x i8]* @.str.1, i64 0, i64 0), i32 7, i32* %3)
%18 = load i32, i32* %3
%19 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %5
%21 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %7
%23 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %9
%25 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %11
%27 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %13
%29 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %15
%31 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%33 = tail call i32 @read_basic_csv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 7, i32* %3)
%34 = load i32, i32* %3
%35 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %5
%37 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %7
%39 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %9
%41 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %11
%43 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %13
%45 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %15
%47 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %46)
%48 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %33)
%49 = tail call i32 @free(i32* %3)
ret i32 %33
}