#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 atoi(char *);
int /*<<< orphan*/ exit(int);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strtok(char *, char *);
void initdata(double u1[100][100], char *fname) {
  int i = 0, j = 0;
  FILE *fp = fopen(fname, "r");
  if (!fp) {
    fprintf(stderr, "Can't open input file %s!\n", fname);
    exit(1);
  }
  char *line, *temp, *data;
  char *record;
  char buffer[2048];
  double val;
  while ((line = fgets(buffer, sizeof(buffer), fp)) != NULL) {
    record = strtok(line, ",");
    while (record != NULL) {
      if (j >= 100) {
        break;
      }
      u1[i][j] = atoi(record);
      record = strtok(NULL, ",");
      j++;
    }
    j = 0;
    i++;
  }
}


x86 assembly (clang, -O0):
<initdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c3 <initdata+0x63>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe4e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11c8 <initdata+0x68>
lea    -0x840(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x800,%esi
call   1030 <fgets@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1274 <initdata+0x114>
mov    -0x28(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     125f <initdata+0xff>
cmpl   $0x64,-0x18(%rbp)
jl     1219 <initdata+0xb9>
jmp    125f <initdata+0xff>
mov    -0x40(%rbp),%rdi
call   1070 <atoi@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0x320,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdd5(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ff <initdata+0x9f>
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c8 <initdata+0x68>
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initdata>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %rsi,%r15
mov    %rdi,%r13
lea    0xe83(%rip),%rsi
mov    %r15,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     122e <initdata+0xce>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x800,%esi
mov    %rax,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     121d <initdata+0xbd>
lea    0xe70(%rip),%r15
mov    %rsp,%r12
jmp    11dc <initdata+0x7c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x800,%esi
mov    %r14,%rdx
call   1030 <fgets@plt>
add    $0x320,%r13
test   %rax,%rax
je     121d <initdata+0xbd>
mov    %rax,%rdi
mov    %r15,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     11c0 <initdata+0x60>
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %rax,%rdi
call   1070 <atoi@plt>
movsd  %xmm0,0x0(%r13,%rbx,8)
xor    %edi,%edi
mov    %r15,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     11c0 <initdata+0x60>
lea    0x1(%rbx),%rcx
cmp    $0x63,%rbx
mov    %rcx,%rbx
jb     11f0 <initdata+0x90>
jmp    11c0 <initdata+0x60>
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
mov    %r15,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Can't open input file %s!\0A\00"
@.str.2 = [2 x i8] c",\00"
define void @initdata([100 x double]* nocapture writeonly %0, i8* %1) {
%3 = alloca [2048 x i8]
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%12 = call i8* @fgets(i8* %11, i32 2048, i32* %4)
%13 = icmp eq i8* %12, null
br i1 %13, label %33, label %14
14: ; preds = %10, %29
%15 = phi i64 [ %30, %29 ], [ 0, %10 ]
%16 = phi i8* [ %31, %29 ], [ %12, %10 ]
%17 = call i8* @strtok(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %29, label %19
19: ; preds = %14, %19
%20 = phi i64 [ %25, %19 ], [ 0, %14 ]
%21 = phi i8* [ %24, %19 ], [ %17, %14 ]
%22 = call double @atoi(i8* %21)
%23 = getelementptr inbounds [100 x double], [100 x double]* %0, i64 %15, i64 %20
store double %22, double* %23
%24 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = add nuw nsw i64 %20, 1
%26 = icmp eq i8* %24, null
%27 = icmp ugt i64 %20, 98
%28 = select i1 %26, i1 true, i1 %27
br i1 %28, label %29, label %19
29: ; preds = %19, %14
%30 = add nuw i64 %15, 1
%31 = call i8* @fgets(i8* %11, i32 2048, i32* %4)
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %14
33: ; preds = %29, %10
ret void
}