#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 */
double atof(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *strtok(char *, char *);
int imagesFromFile(char *filename, double **images, int num_to_read,
                   int data_dim) {
  int i, j;
  FILE *file;
  file = fopen(filename, "r");
  if (file == NULL) {
    return 1;
  }
  char str[100];
  char *pch = NULL;
  for (i = 0; i < num_to_read && fgets(str, 100, file) != NULL; i++) {
    pch = strtok(str, ",");
    for (j = 0; j < data_dim && pch != NULL; j++) {
      images[i][j] = atof(pch);
      pch = strtok(NULL, ",");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<imagesFromFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1184 <imagesFromFile+0x44>
movl   $0x1,-0x4(%rbp)
jmp    1298 <imagesFromFile+0x158>
movq   $0x0,-0xa8(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
xor    %eax,%eax
cmp    -0x1c(%rbp),%ecx
mov    %al,-0xa9(%rbp)
jge    11cc <imagesFromFile+0x8c>
lea    -0xa0(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x64,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0xa9(%rbp)
mov    -0xa9(%rbp),%al
test   $0x1,%al
jne    11df <imagesFromFile+0x9f>
jmp    1291 <imagesFromFile+0x151>
lea    -0xa0(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0xa8(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
xor    %eax,%eax
cmp    -0x20(%rbp),%ecx
mov    %al,-0xaa(%rbp)
jge    1225 <imagesFromFile+0xe5>
cmpq   $0x0,-0xa8(%rbp)
setne  %al
mov    %al,-0xaa(%rbp)
mov    -0xaa(%rbp),%al
test   $0x1,%al
jne    1238 <imagesFromFile+0xf8>
jmp    127e <imagesFromFile+0x13e>
mov    -0xa8(%rbp),%rdi
call   1030 <atof@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd9e(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0xa8(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1200 <imagesFromFile+0xc0>
jmp    1283 <imagesFromFile+0x143>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1196 <imagesFromFile+0x56>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imagesFromFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %ecx,0xc(%rsp)
mov    %edx,%r15d
mov    %rsi,%rbx
lea    0xe9e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,0x18(%rsp)
test   %rax,%rax
je     1221 <imagesFromFile+0xe1>
test   %r15d,%r15d
jle    121d <imagesFromFile+0xdd>
movslq 0xc(%rsp),%rbp
mov    %r15d,%eax
mov    %rax,0x10(%rsp)
xor    %r14d,%r14d
lea    0x20(%rsp),%r15
lea    0xe68(%rip),%r13
jmp    11ae <imagesFromFile+0x6e>
nopl   0x0(%rax)
add    $0x1,%r14
cmp    0x10(%rsp),%r14
mov    %r12,%r15
je     121d <imagesFromFile+0xdd>
mov    %r15,%rdi
mov    $0x64,%esi
mov    0x18(%rsp),%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     121d <imagesFromFile+0xdd>
mov    %r15,%r12
mov    %r15,%rdi
mov    %r13,%rsi
call   1060 <strtok@plt>
cmpl   $0x0,0xc(%rsp)
jle    11a0 <imagesFromFile+0x60>
test   %rax,%rax
je     11a0 <imagesFromFile+0x60>
mov    $0x1,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rax,%rdi
call   1030 <atof@plt>
mov    (%rbx,%r14,8),%rax
movsd  %xmm0,-0x8(%rax,%r15,8)
xor    %edi,%edi
mov    %r13,%rsi
call   1060 <strtok@plt>
cmp    %rbp,%r15
jge    11a0 <imagesFromFile+0x60>
add    $0x1,%r15
test   %rax,%rax
jne    11f0 <imagesFromFile+0xb0>
jmp    11a0 <imagesFromFile+0x60>
xor    %eax,%eax
jmp    1226 <imagesFromFile+0xe6>
mov    $0x1,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c",\00"
define i32 @imagesFromFile(i8* nocapture %0, double** nocapture %1, i32 %2, i32 %3) {
%5 = alloca [100 x i8]
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %40, label %8
8: ; preds = %4
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %39
11: ; preds = %8
%12 = icmp sgt i32 %3, 0
%13 = sext i32 %3 to i64
%14 = zext i32 %2 to i64
br label %15
15: ; preds = %11, %36
%16 = phi i64 [ 0, %11 ], [ %37, %36 ]
%17 = call i32* @fgets(i8* %9, i32 100, i32* %6)
%18 = icmp eq i32* %17, null
br i1 %18, label %39, label %19
19: ; preds = %15
%20 = call i8* @strtok(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp ne i8* %20, null
%22 = select i1 %12, i1 %21, i1 false
br i1 %22, label %23, label %36
23: ; preds = %19
%24 = getelementptr inbounds double*, double** %1, i64 %16
br label %25
25: ; preds = %23, %25
%26 = phi i64 [ 0, %23 ], [ %32, %25 ]
%27 = phi i8* [ %20, %23 ], [ %31, %25 ]
%28 = call double @atof(i8* %27)
%29 = load double*, double** %24
%30 = getelementptr inbounds double, double* %29, i64 %26
store double %28, double* %30
%31 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%32 = add nuw nsw i64 %26, 1
%33 = icmp slt i64 %32, %13
%34 = icmp ne i8* %31, null
%35 = select i1 %33, i1 %34, i1 false
br i1 %35, label %25, label %36
36: ; preds = %25, %19
%37 = add nuw nsw i64 %16, 1
%38 = icmp eq i64 %37, %14
br i1 %38, label %39, label %15
39: ; preds = %15, %36, %8
br label %40
40: ; preds = %4, %39
%41 = phi i32 [ 0, %39 ], [ 1, %4 ]
ret i32 %41
}