#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*/ printf(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
char *strtok(char *, char *);
int Data_Read(FILE *fstream, int row, int col, double *info) {
  FILE *fstream_inside = fstream;
  char buffer[2048];
  char *record, *line;
  int i = 0, j = 0;
  if (fstream_inside == NULL) {
    printf("\n file opening failed\n");
    return -1;
  }
  while ((line = fgets(buffer, sizeof(buffer), fstream_inside)) != NULL) {
    record = strtok(line, ",");
    j = 0;
    while (record != NULL) {
      info[j + i * col] = atof(record);
      ++j;
      record = strtok(NULL, ",");
    }
    ++i;
  }
  printf("\n");
  rewind(fstream_inside);
  return 0;
}


x86 assembly (clang, -O0):
<Data_Read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x844(%rbp)
movl   $0x0,-0x848(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a8 <Data_Read+0x58>
lea    0xe69(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128a <Data_Read+0x13a>
jmp    11ad <Data_Read+0x5d>
lea    -0x830(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x800,%esi
call   1060 <fgets@plt>
mov    %rax,-0x840(%rbp)
cmp    $0x0,%rax
je     126e <Data_Read+0x11e>
mov    -0x840(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x838(%rbp)
movl   $0x0,-0x848(%rbp)
cmpq   $0x0,-0x838(%rbp)
je     125a <Data_Read+0x10a>
mov    -0x838(%rbp),%rdi
call   1030 <atof@plt>
mov    -0x20(%rbp),%rax
mov    -0x848(%rbp),%ecx
mov    -0x844(%rbp),%edx
imul   -0x18(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x848(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x848(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdce(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x838(%rbp)
jmp    11f7 <Data_Read+0xa7>
mov    -0x844(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x844(%rbp)
jmp    11ad <Data_Read+0x5d>
lea    0xda0(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <rewind@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Data_Read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
test   %rdi,%rdi
je     1218 <Data_Read+0xb8>
mov    %rcx,%r15
mov    %edx,%ebx
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x800,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1202 <Data_Read+0xa2>
movslq %ebx,%r13
shl    $0x3,%r13
lea    0xe5b(%rip),%rbx
mov    %rsp,%r12
jmp    11c8 <Data_Read+0x68>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x800,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
add    %r13,%r15
test   %rax,%rax
je     1202 <Data_Read+0xa2>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
je     11b0 <Data_Read+0x50>
mov    %r15,%rbp
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1050 <atof@plt>
movsd  %xmm0,0x0(%rbp)
xor    %edi,%edi
mov    %rbx,%rsi
call   1080 <strtok@plt>
add    $0x8,%rbp
test   %rax,%rax
jne    11e0 <Data_Read+0x80>
jmp    11b0 <Data_Read+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   1060 <rewind@plt>
xor    %eax,%eax
jmp    1229 <Data_Read+0xc9>
lea    0xde3(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"\0A file opening failed\0A\00"
@.str.1 = [2 x i8] c",\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @Data_Read(i32* %0, i32 %1, i32 %2, double* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double*
%10 = alloca i32*
%11 = alloca [2048 x i8]
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store double* %3, double** %9
%16 = load i32*, i32** %6
store i32* %16, i32** %10
store i32 0, i32* %14
store i32 0, i32* %15
%17 = load i32*, i32** %10
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %4
%20 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %54
21: ; preds = %4
br label %22
22: ; preds = %47, %21
%23 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%24 = load i32*, i32** %10
%25 = call i8* @fgets(i8* %23, i32 2048, i32* %24)
store i8* %25, i8** %13
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %50
27: ; preds = %22
%28 = load i8*, i8** %13
%29 = call i8* @strtok(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %29, i8** %12
store i32 0, i32* %15
br label %30
30: ; preds = %33, %27
%31 = load i8*, i8** %12
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %47
33: ; preds = %30
%34 = load i8*, i8** %12
%35 = call double @atof(i8* %34)
%36 = load double*, double** %9
%37 = load i32, i32* %15
%38 = load i32, i32* %14
%39 = load i32, i32* %8
%40 = mul nsw i32 %38, %39
%41 = add nsw i32 %37, %40
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %36, i64 %42
store double %35, double* %43
%44 = load i32, i32* %15
%45 = add nsw i32 %44, 1
store i32 %45, i32* %15
%46 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %46, i8** %12
br label %30
47: ; preds = %30
%48 = load i32, i32* %14
%49 = add nsw i32 %48, 1
store i32 %49, i32* %14
br label %22
50: ; preds = %22
%51 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%52 = load i32*, i32** %10
%53 = call i32 @rewind(i32* %52)
store i32 0, i32* %5
br label %54
54: ; preds = %50, %19
%55 = load i32, i32* %5
ret i32 %55
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c",\00"
@str = [22 x i8] c"\0A file opening failed\00"
define i32 @Data_Read(i32* %0, i32 %1, i32 %2, double* nocapture writeonly %3) {
%5 = alloca [2048 x i8]
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%7 = icmp eq i32* %0, null
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = call i8* @fgets(i8* %6, i32 2048, i32* %0)
%10 = icmp eq i8* %9, null
br i1 %10, label %35, label %11
11: ; preds = %8
%12 = sext i32 %2 to i64
br label %15
13: ; preds = %4
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %38
15: ; preds = %11, %31
%16 = phi i64 [ 0, %11 ], [ %32, %31 ]
%17 = phi i8* [ %9, %11 ], [ %33, %31 ]
%18 = call i8* @strtok(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %31, label %20
20: ; preds = %15
%21 = mul nsw i64 %16, %12
br label %22
22: ; preds = %20, %22
%23 = phi i64 [ 0, %20 ], [ %28, %22 ]
%24 = phi i8* [ %18, %20 ], [ %29, %22 ]
%25 = call double @atof(i8* %24)
%26 = add nsw i64 %23, %21
%27 = getelementptr inbounds double, double* %3, i64 %26
store double %25, double* %27
%28 = add nuw i64 %23, 1
%29 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %22
31: ; preds = %22, %15
%32 = add nuw i64 %16, 1
%33 = call i8* @fgets(i8* %6, i32 2048, i32* %0)
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %15
35: ; preds = %31, %8
%36 = call i32 @putchar(i32 10)
%37 = call i32 @rewind(i32* %0)
br label %38
38: ; preds = %35, %13
%39 = phi i32 [ -1, %13 ], [ 0, %35 ]
ret i32 %39
}