#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 *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int ferror(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
char *strtok(char *, char *);
void initdata(double *u1, char *fname) {
  int ix, iy;
  FILE *fp;
  char buffer[4096];
  char *record = 0, *line = 0;
  fp = fopen(fname, "r");
  if (!fp) {
    printf("File %s could not be found", fname);
  } else {
    printf("File %s open\n", fname);
    for (iy = 0; iy < 100; iy++) {
      line = fgets(buffer, sizeof(buffer), fp);
      if (buffer) {
        record = strtok(line, ", ");
        for (ix = 0; ix < 100; ix++) {
          if (record) {
            *(u1 + (100 * iy + ix)) = atof(record);
            record = strtok(0, ", ");
          }
        }
      } else {
        int err;
        if ((err = ferror(fp)))
          printf("error: %d\n", err);
        break;
      }
    }
  }
  fclose(fp);
  printf("\nFile closed\n");
}


x86 assembly (clang, -O0):
<initdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x1028(%rbp)
movq   $0x0,-0x1030(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11cf <initdata+0x5f>
mov    -0x10(%rbp),%rsi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12ef <initdata+0x17f>
mov    -0x10(%rbp),%rsi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x64,-0x18(%rbp)
jge    12ea <initdata+0x17a>
lea    -0x1020(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x1000,%esi
call   1070 <fgets@plt>
mov    %rax,-0x1030(%rbp)
lea    -0x1020(%rbp),%rax
cmp    $0x0,%rax
je     12a6 <initdata+0x136>
mov    -0x1030(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x1028(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    12a1 <initdata+0x131>
cmpq   $0x0,-0x1028(%rbp)
je     128e <initdata+0x11e>
mov    -0x1028(%rbp),%rdi
call   1040 <atof@plt>
mov    -0x8(%rbp),%rax
imul   $0x64,-0x18(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
xor    %eax,%eax
mov    %eax,%edi
lea    0xda9(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x1028(%rbp)
jmp    1293 <initdata+0x123>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1240 <initdata+0xd0>
jmp    12d7 <initdata+0x167>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
mov    %eax,-0x1034(%rbp)
cmp    $0x0,%eax
je     12d2 <initdata+0x162>
mov    -0x1034(%rbp),%esi
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12ea <initdata+0x17a>
jmp    12dc <initdata+0x16c>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11e8 <initdata+0x78>
jmp    12ef <initdata+0x17f>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xd3a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initdata>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe72(%rip),%rsi
mov    %r15,%rdi
call   1080 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     121a <initdata+0xaa>
lea    0xe78(%rip),%rdi
xor    %r13d,%r13d
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%r15
lea    0xe6f(%rip),%r12
jmp    11d1 <initdata+0x61>
xchg   %ax,%ax
add    $0x1,%r13
add    $0x320,%rbx
cmp    $0x64,%r13
je     122b <initdata+0xbb>
mov    %r15,%rdi
mov    $0x1000,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
mov    %rax,%rdi
mov    %r12,%rsi
call   1090 <strtok@plt>
xor    %ebp,%ebp
jmp    1211 <initdata+0xa1>
mov    %rax,%rdi
call   1040 <atof@plt>
movsd  %xmm0,(%rbx,%rbp,8)
xor    %edi,%edi
mov    %r12,%rsi
call   1090 <strtok@plt>
add    $0x1,%rbp
cmp    $0x64,%rbp
je     11c0 <initdata+0x50>
test   %rax,%rax
jne    11f0 <initdata+0x80>
xor    %eax,%eax
jmp    1207 <initdata+0x97>
lea    0xde1(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    0xdf4(%rip),%rdi
call   1030 <puts@plt>
add    $0x1008,%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 = [27 x i8] c"File %s could not be found\00"
@.str.2 = [14 x i8] c"File %s open\0A\00"
@.str.3 = [3 x i8] c", \00"
@.str.4 = [11 x i8] c"error: %d\0A\00"
@.str.5 = [14 x i8] c"\0AFile closed\0A\00"
define void @initdata(double* %0, i8* %1) {
%3 = alloca double*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [4096 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store double* %0, double** %3
store i8* %1, i8** %4
store i8* null, i8** %9
store i8* null, i8** %10
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %7
%14 = load i32*, i32** %7
%15 = icmp ne i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %69
19: ; preds = %2
%20 = load i8*, i8** %4
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %20)
store i32 0, i32* %6
br label %22
22: ; preds = %65, %19
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 100
br i1 %24, label %25, label %68
25: ; preds = %22
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%27 = load i32*, i32** %7
%28 = call i8* @fgets(i8* %26, i32 4096, i32* %27)
store i8* %28, i8** %10
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %56
31: ; preds = %25
%32 = load i8*, i8** %10
%33 = call i8* @strtok(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i8* %33, i8** %9
store i32 0, i32* %5
br label %34
34: ; preds = %52, %31
%35 = load i32, i32* %5
%36 = icmp slt i32 %35, 100
br i1 %36, label %37, label %55
37: ; preds = %34
%38 = load i8*, i8** %9
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %51
40: ; preds = %37
%41 = load i8*, i8** %9
%42 = call double @atof(i8* %41)
%43 = load double*, double** %3
%44 = load i32, i32* %6
%45 = mul nsw i32 100, %44
%46 = load i32, i32* %5
%47 = add nsw i32 %45, %46
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %43, i64 %48
store double %42, double* %49
%50 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i8* %50, i8** %9
br label %51
51: ; preds = %40, %37
br label %52
52: ; preds = %51
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
br label %34
55: ; preds = %34
br label %64
56: ; preds = %25
%57 = load i32*, i32** %7
%58 = call i32 @ferror(i32* %57)
store i32 %58, i32* %11
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %56
%61 = load i32, i32* %11
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %60, %56
br label %68
64: ; preds = %55
br label %65
65: ; preds = %64
%66 = load i32, i32* %6
%67 = add nsw i32 %66, 1
store i32 %67, i32* %6
br label %22
68: ; preds = %63, %22
br label %69
69: ; preds = %68, %16
%70 = load i32*, i32** %7
%71 = call i32 @fclose(i32* %70)
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [27 x i8] c"File %s could not be found\00"
@.str.2 = [14 x i8] c"File %s open\0A\00"
@.str.3 = [3 x i8] c", \00"
@str = [13 x i8] c"\0AFile closed\00"
define void @initdata(double* nocapture writeonly %0, i8* %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %32
9: ; preds = %2
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %11
11: ; preds = %9, %29
%12 = phi i64 [ 0, %9 ], [ %30, %29 ]
%13 = call i8* @fgets(i8* %4, i32 4096, i32* %5)
%14 = call i8* @strtok(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%15 = mul nuw nsw i64 %12, 100
br label %16
16: ; preds = %11, %25
%17 = phi i64 [ 0, %11 ], [ %27, %25 ]
%18 = phi i8* [ %14, %11 ], [ %26, %25 ]
%19 = icmp eq i8* %18, null
br i1 %19, label %25, label %20
20: ; preds = %16
%21 = call double @atof(i8* %18)
%22 = add nuw nsw i64 %17, %15
%23 = getelementptr inbounds double, double* %0, i64 %22
store double %21, double* %23
%24 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %16, %20
%26 = phi i8* [ %24, %20 ], [ null, %16 ]
%27 = add nuw nsw i64 %17, 1
%28 = icmp eq i64 %27, 100
br i1 %28, label %29, label %16
29: ; preds = %25
%30 = add nuw nsw i64 %12, 1
%31 = icmp eq i64 %30, 100
br i1 %31, label %32, label %11
32: ; preds = %29, %7
%33 = call i32 @fclose(i32* %5)
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
ret void
}