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

/* Variables and functions */
int atoi(char *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
char *strtok(char *, char *);
int main() {
  char buffer[1024];
  char *record;
  char *line;
  int i = 0, j = 0;
  int mat[100][100];
  FILE *fstream = fopen(
      "/home/elsuizo/Dropbox/Freelance/ACC_filter/Acc_SampleFile_001.csv", "r");
  if (fstream == NULL) {
    printf("\n file opening failed ");
    return -1;
  }
  while ((line = fgets(buffer, sizeof(buffer), fstream)) != NULL) {
    record = strtok(line, ",");
    while (record != NULL) {
      printf("record : %s", record);
      mat[i][j++] = atoi(record);
      record = strtok(NULL, ",");
    }
    ++i;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa080,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x424(%rbp)
movl   $0x0,-0x428(%rbp)
lea    0xe83(%rip),%rdi
lea    0xebe(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0xa078(%rbp)
cmpq   $0x0,-0xa078(%rbp)
jne    11b8 <main+0x68>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1297 <main+0x147>
jmp    11bd <main+0x6d>
lea    -0x410(%rbp),%rdi
mov    -0xa078(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
mov    %rax,-0x420(%rbp)
cmp    $0x0,%rax
je     1290 <main+0x140>
mov    -0x420(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     127c <main+0x12c>
mov    -0x418(%rbp),%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x418(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%edx
movslq -0x424(%rbp),%rcx
lea    -0xa070(%rbp),%rax
imul   $0x190,%rcx,%rcx
add    %rcx,%rax
mov    -0x428(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x428(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdf0(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x418(%rbp)
jmp    1200 <main+0xb0>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    11bd <main+0x6d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa080,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
lea    0xeab(%rip),%rdi
lea    0xee6(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11e2 <main+0xa2>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11de <main+0x9e>
lea    0xed6(%rip),%rbx
mov    %rsp,%r15
lea    0xece(%rip),%r12
jmp    11b5 <main+0x75>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11de <main+0x9e>
mov    %rax,%rdi
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     11a0 <main+0x60>
mov    %r12,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
jmp    11c0 <main+0x80>
xor    %eax,%eax
jmp    11f5 <main+0xb5>
lea    0xe5b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [66 x i8] c"/home/elsuizo/Dropbox/Freelance/ACC_filter/Acc_SampleFile_001.csv\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"\0A file opening failed \00"
@.str.3 = [2 x i8] c",\00"
@.str.4 = [12 x i8] c"record : %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [100 x [100 x i32]]
%8 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %5
store i32 0, i32* %6
%9 = call i32* @fopen(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %8
%10 = load i32*, i32** %8
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %43
14: ; preds = %0
br label %15
15: ; preds = %39, %14
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%17 = load i32*, i32** %8
%18 = call i8* @fgets(i8* %16, i32 1024, i32* %17)
store i8* %18, i8** %4
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %42
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = call i8* @strtok(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %22, i8** %3
br label %23
23: ; preds = %26, %20
%24 = load i8*, i8** %3
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %39
26: ; preds = %23
%27 = load i8*, i8** %3
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %27)
%29 = load i8*, i8** %3
%30 = call i32 @atoi(i8* %29)
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %7, i64 0, i64 %32
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds [100 x i32], [100 x i32]* %33, i64 0, i64 %36
store i32 %30, i32* %37
%38 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %38, i8** %3
br label %23
39: ; preds = %23
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %15
42: ; preds = %15
store i32 0, i32* %1
br label %43
43: ; preds = %42, %12
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
@.str = [66 x i8] c"/home/elsuizo/Dropbox/Freelance/ACC_filter/Acc_SampleFile_001.csv\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"\0A file opening failed \00"
@.str.3 = [2 x i8] c",\00"
@.str.4 = [12 x i8] c"record : %s\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i8* @fgets(i8* %2, i32 1024, i32* %3)
%7 = icmp eq i8* %6, null
br i1 %7, label %22, label %13
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %22
10: ; preds = %17, %13
%11 = call i8* @fgets(i8* %2, i32 1024, i32* %3)
%12 = icmp eq i8* %11, null
br i1 %12, label %22, label %13
13: ; preds = %5, %10
%14 = phi i8* [ %11, %10 ], [ %6, %5 ]
%15 = call i8* @strtok(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %10, label %17
17: ; preds = %13, %17
%18 = phi i8* [ %20, %17 ], [ %15, %13 ]
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%20 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %10, label %17
22: ; preds = %10, %5, %8
%23 = phi i32 [ -1, %8 ], [ 0, %5 ], [ 0, %10 ]
ret i32 %23
}