#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*/ *);
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, *line;
  double item;
  fp = fopen(fname, "r");
  if (!fp) {
    printf("File %s could not be found", fname);
  } else {
    printf("File %s open\n", fname);
    for (ix = 0; ix < 100; ix++) {
      line = fgets(buffer, sizeof(buffer), fp);
      record = strtok(line, ",");
      for (iy = 0; iy < 100; iy++) {
        record = strtok(NULL, ",");
        *((u1 + 100 * ix) + iy) = atof(record);
      }
    }
  }
  fclose(fp);
  printf("File closed\n");
}


x86 assembly (clang, -O0):
<initdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a9 <initdata+0x49>
mov    -0x10(%rbp),%rsi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1277 <initdata+0x117>
mov    -0x10(%rbp),%rsi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    1272 <initdata+0x112>
lea    -0x1020(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x1000,%esi
call   1060 <fgets@plt>
mov    %rax,-0x1030(%rbp)
mov    -0x1030(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x1028(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x64,-0x18(%rbp)
jge    125f <initdata+0xff>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe0d(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x1028(%rbp)
mov    -0x1028(%rbp),%rdi
call   1030 <atof@plt>
mov    -0x8(%rbp),%rax
imul   $0x64,-0x14(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1209 <initdata+0xa9>
jmp    1264 <initdata+0x104>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c2 <initdata+0x62>
jmp    1277 <initdata+0x117>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1050 <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     1214 <initdata+0xa4>
lea    0xe78(%rip),%rdi
xor    %r13d,%r13d
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%r15
lea    0xe6f(%rip),%r12
nopl   0x0(%rax)
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
nopl   (%rax)
xor    %edi,%edi
mov    %r12,%rsi
call   1090 <strtok@plt>
mov    %rax,%rdi
call   1040 <atof@plt>
movsd  %xmm0,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    $0x64,%rbp
jne    11e0 <initdata+0x70>
add    $0x1,%r13
add    $0x320,%rbx
cmp    $0x64,%r13
jne    11c0 <initdata+0x50>
jmp    1225 <initdata+0xb5>
lea    0xde7(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    0xdf9(%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 = [2 x i8] c",\00"
@.str.4 = [13 x i8] c"File 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 double
store double* %0, double** %3
store i8* %1, i8** %4
%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 %54
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* %5
br label %22
22: ; preds = %50, %19
%23 = load i32, i32* %5
%24 = icmp slt i32 %23, 100
br i1 %24, label %25, label %53
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 = load i8*, i8** %10
%30 = call i8* @strtok(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %30, i8** %9
store i32 0, i32* %6
br label %31
31: ; preds = %46, %25
%32 = load i32, i32* %6
%33 = icmp slt i32 %32, 100
br i1 %33, label %34, label %49
34: ; preds = %31
%35 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %35, i8** %9
%36 = load i8*, i8** %9
%37 = call double @atof(i8* %36)
%38 = load double*, double** %3
%39 = load i32, i32* %5
%40 = mul nsw i32 100, %39
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %38, i64 %41
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
store double %37, double* %45
br label %46
46: ; preds = %34
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %31
49: ; preds = %31
br label %50
50: ; preds = %49
%51 = load i32, i32* %5
%52 = add nsw i32 %51, 1
store i32 %52, i32* %5
br label %22
53: ; preds = %22
br label %54
54: ; preds = %53, %16
%55 = load i32*, i32** %7
%56 = call i32 @fclose(i32* %55)
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, 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 = [2 x i8] c",\00"
@str = [12 x i8] c"File 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 %27
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, %24
%12 = phi i64 [ 0, %9 ], [ %25, %24 ]
%13 = call i8* @fgets(i8* %4, i32 4096, i32* %5)
%14 = call i8* @strtok(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%15 = mul nuw nsw i64 %12, 100
%16 = getelementptr inbounds double, double* %0, i64 %15
br label %17
17: ; preds = %11, %17
%18 = phi i64 [ 0, %11 ], [ %22, %17 ]
%19 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%20 = call double @atof(i8* %19)
%21 = getelementptr inbounds double, double* %16, i64 %18
store double %20, double* %21
%22 = add nuw nsw i64 %18, 1
%23 = icmp eq i64 %22, 100
br i1 %23, label %24, label %17
24: ; preds = %17
%25 = add nuw nsw i64 %12, 1
%26 = icmp eq i64 %25, 100
br i1 %26, label %27, label %11
27: ; preds = %24, %7
%28 = call i32 @fclose(i32* %5)
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
ret void
}