#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 */
double atof(char *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
char *strtok(char *, char *);
int main() {
  char buffer[4096];
  char *record, *line;
  double item;
  int i = 0, j = 0;
  FILE *fstream = fopen("initial_data.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 = strtok(NULL, ",")) {
      printf("item: %8.3f \n", atof(record));
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x102c(%rbp)
movl   $0x0,-0x1030(%rbp)
lea    0xe83(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x1038(%rbp)
cmpq   $0x0,-0x1038(%rbp)
jne    11b8 <main+0x68>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124c <main+0xfc>
jmp    11bd <main+0x6d>
lea    -0x1010(%rbp),%rdi
mov    -0x1038(%rbp),%rdx
mov    $0x1000,%esi
call   1050 <fgets@plt>
mov    %rax,-0x1020(%rbp)
cmp    $0x0,%rax
je     1245 <main+0xf5>
mov    -0x1020(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x1018(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe1f(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x1018(%rbp)
cmp    $0x0,%rax
je     1240 <main+0xf0>
mov    -0x1018(%rbp),%rdi
call   1030 <atof@plt>
lea    0xdf8(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1200 <main+0xb0>
jmp    11bd <main+0x6d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1008,%rsp
lea    0xe9b(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11f7 <main+0xa7>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11f3 <main+0xa3>
lea    0xe91(%rip),%rbx
mov    %rsp,%r15
lea    0xe89(%rip),%r12
jmp    11c5 <main+0x75>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    $0x1000,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11f3 <main+0xa3>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1070 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1070 <strtok@plt>
test   %rax,%rax
je     11b0 <main+0x60>
mov    %rax,%rdi
call   1030 <atof@plt>
mov    %r12,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    11d0 <main+0x80>
xor    %eax,%eax
jmp    120a <main+0xba>
lea    0xe15(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"initial_data.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 = [14 x i8] c"item: %8.3f \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4096 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %6
store i32 0, i32* %7
%9 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 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 %32
14: ; preds = %0
br label %15
15: ; preds = %30, %14
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%17 = load i32*, i32** %8
%18 = call i8* @fgets(i8* %16, i32 4096, i32* %17)
store i8* %18, i8** %4
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %31
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 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %24, i8** %3
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i8*, i8** %3
%28 = call double @atof(i8* %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), double %28)
br label %23
30: ; preds = %23
br label %15
31: ; preds = %15
store i32 0, i32* %1
br label %32
32: ; preds = %31, %12
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@.str = [17 x i8] c"initial_data.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 = [14 x i8] c"item: %8.3f \0A\00"
define i32 @main() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 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 4096, i32* %3)
%7 = icmp eq i8* %6, null
br i1 %7, label %24, 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 %24
10: ; preds = %18, %13
%11 = call i8* @fgets(i8* %2, i32 4096, i32* %3)
%12 = icmp eq i8* %11, null
br i1 %12, label %24, 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 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %10, label %18
18: ; preds = %13, %18
%19 = phi i8* [ %22, %18 ], [ %16, %13 ]
%20 = call double @atof(i8* %19)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), double %20)
%22 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %10, label %18
24: ; preds = %10, %5, %8
%25 = phi i32 [ -1, %8 ], [ 0, %5 ], [ 0, %10 ]
ret i32 %25
}