#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 fscanf(int /*<<< orphan*/ *, char *, double *);
int /*<<< orphan*/ printf(char *);
void read_csv_file(FILE *infile, int num_rows, int num_cols, double *matrix) {
  int i, j, info = 0;
  for (i = 0; i < num_rows; ++i) {
    for (j = 0; j < num_cols - 1; ++j) {
      info = fscanf(infile, "%le,", &matrix[i * num_cols + j]);
    }
    info = fscanf(infile, "%le\n", &matrix[i * num_cols + num_cols - 1]);
  }
  if (!info)
    printf("@read_csv_file ERROR in file IO\n");
}


x86 assembly (clang, -O0):
<read_csv_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11db <read_csv_file+0xbb>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11a0 <read_csv_file+0x80>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%eax
imul   -0x10(%rbp),%eax
add    -0x20(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe76(%rip),%rsi
call   1040 <fscanf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1157 <read_csv_file+0x37>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%eax
imul   -0x10(%rbp),%eax
add    -0x10(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe40(%rip),%rsi
call   1040 <fscanf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1144 <read_csv_file+0x24>
cmpl   $0x0,-0x24(%rbp)
jne    11f1 <read_csv_file+0xd1>
lea    0xe1e(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_csv_file>:
test   %esi,%esi
jle    120e <read_csv_file+0xee>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%rbp
mov    %edx,%r15d
mov    %rdi,%rbx
movslq %edx,%rax
add    $0xffffffff,%r15d
mov    %esi,%ecx
mov    %rcx,0x20(%rsp)
mov    %rax,0x28(%rsp)
lea    0x0(,%rax,8),%rax
mov    %rax,0x18(%rsp)
xor    %r13d,%r13d
lea    0xe97(%rip),%r12
mov    %rbp,0x8(%rsp)
mov    %rbp,0x30(%rsp)
mov    %r15,0x10(%rsp)
jmp    11c4 <read_csv_file+0xa4>
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%r15
add    %r15d,%r14d
movslq %r14d,%rax
mov    0x30(%rsp),%rbp
lea    0x0(,%rax,8),%rdx
add    %rbp,%rdx
mov    %rbx,%rdi
lea    0xe60(%rip),%rsi
call   1040 <fscanf@plt>
add    $0x1,%r13
mov    0x8(%rsp),%rcx
add    0x18(%rsp),%rcx
mov    %rcx,0x8(%rsp)
cmp    0x20(%rsp),%r13
je     11fa <read_csv_file+0xda>
mov    %r13,%r14
mov    0x28(%rsp),%rax
imul   %rax,%r14
cmp    $0x2,%eax
jl     1180 <read_csv_file+0x60>
mov    0x10(%rsp),%r15
mov    0x8(%rsp),%rbp
nop
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1040 <fscanf@plt>
add    $0x8,%rbp
add    $0xffffffffffffffff,%r15
jne    11e0 <read_csv_file+0xc0>
jmp    1180 <read_csv_file+0x60>
test   %eax,%eax
lea    0x38(%rsp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
je     120e <read_csv_file+0xee>
ret
lea    0xdf5(%rip),%rdi
jmp    1030 <puts@plt>

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

LLVM IR (-O2):
@.str = [5 x i8] c"%le,\00"
@.str.1 = [5 x i8] c"%le\0A\00"
@str = [32 x i8] c"@read_csv_file ERROR in file IO\00"
define void @read_csv_file(i32* nocapture %0, i32 %1, i32 %2, double* %3) {
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %32
6: ; preds = %4
%7 = add i32 %2, -1
%8 = icmp sgt i32 %2, 1
%9 = sext i32 %2 to i64
%10 = zext i32 %1 to i64
%11 = zext i32 %7 to i64
br label %12
12: ; preds = %6, %22
%13 = phi i64 [ 0, %6 ], [ %28, %22 ]
%14 = mul nsw i64 %13, %9
br i1 %8, label %15, label %22
15: ; preds = %12, %15
%16 = phi i64 [ %20, %15 ], [ 0, %12 ]
%17 = add nsw i64 %16, %14
%18 = getelementptr inbounds double, double* %3, i64 %17
%19 = tail call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double* %18)
%20 = add nuw nsw i64 %16, 1
%21 = icmp eq i64 %20, %11
br i1 %21, label %22, label %15
22: ; preds = %15, %12
%23 = trunc i64 %14 to i32
%24 = add i32 %7, %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %3, i64 %25
%27 = tail call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double* %26)
%28 = add nuw nsw i64 %13, 1
%29 = icmp eq i64 %28, %10
br i1 %29, label %30, label %12
30: ; preds = %22
%31 = icmp eq i32 %27, 0
br i1 %31, label %32, label %34
32: ; preds = %4, %30
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %34
34: ; preds = %32, %30
ret void
}