#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, float *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int extractData(char *NameINPUT, int nrow, int ncol, double *Matrix,
                char *format) {
  int i = 0, j = 0;
  float value;
  FILE *INPUTFile;
  if ((INPUTFile = fopen(NameINPUT, "r")) == NULL) {
    printf("Error, invalid input file\n");
    return 1;
  }
  if (!strcmp(format, "genotypes")) {
    while ((fscanf(INPUTFile, "%g", &value) != EOF)) {
      Matrix[i * ncol + j] = (double)value;
      j++;
      if (j == ncol) {
        j = 0;
        i++;
      }
    }
  }
  fclose(INPUTFile);
  return 0;
}


x86 assembly (clang, -O0):
<extractData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11ae <extractData+0x5e>
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    124e <extractData+0xfe>
mov    -0x28(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    123e <extractData+0xee>
jmp    11cc <extractData+0x7c>
mov    -0x40(%rbp),%rdi
lea    0xe50(%rip),%rsi
lea    -0x34(%rbp),%rdx
call   1050 <fscanf@plt>
mov    0x2e01(%rip),%rcx
cmp    (%rcx),%rax
je     1239 <extractData+0xe9>
movss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
imul   -0x18(%rbp),%ecx
add    -0x30(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1234 <extractData+0xe4>
movl   $0x0,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11cc <extractData+0x7c>
jmp    123e <extractData+0xee>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extractData>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r15
mov    %rcx,%r14
mov    %edx,%ebp
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1219 <extractData+0xc9>
mov    %rax,%rbx
lea    0xe80(%rip),%rsi
mov    %r15,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    120d <extractData+0xbd>
lea    0xe73(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <fscanf@plt>
mov    0x2e3b(%rip),%r12
cmp    (%r12),%rax
je     120d <extractData+0xbd>
xor    %r13d,%r13d
xor    %r15d,%r15d
nopl   0x0(%rax)
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r15d,%eax
imul   %ebp,%eax
add    %r13d,%eax
cltq
movsd  %xmm0,(%r14,%rax,8)
add    $0x1,%r13d
xor    %eax,%eax
cmp    %ebp,%r13d
sete   %al
mov    $0x0,%edx
cmove  %edx,%r13d
add    %eax,%r15d
mov    %rbx,%rdi
lea    0xe0f(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1050 <fscanf@plt>
cmp    (%r12),%rax
jne    11c0 <extractData+0x70>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    122a <extractData+0xda>
lea    0xdef(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x8,%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"Error, invalid input file\0A\00"
@.str.2 = [10 x i8] c"genotypes\00"
@.str.3 = [3 x i8] c"%g\00"
@EOF = global i64 0
define i32 @extractData(i8* %0, i32 %1, i32 %2, double* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca float
%15 = alloca i32*
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store double* %3, double** %10
store i8* %4, i8** %11
store i32 0, i32* %12
store i32 0, i32* %13
%16 = load i8*, i8** %7
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %15
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %5
%20 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %6
br label %55
21: ; preds = %5
%22 = load i8*, i8** %11
%23 = call i32 @strcmp(i8* %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %52, label %25
25: ; preds = %21
br label %26
26: ; preds = %50, %25
%27 = load i32*, i32** %15
%28 = call i64 @fscanf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %14)
%29 = load i64, i64* @EOF
%30 = icmp ne i64 %28, %29
br i1 %30, label %31, label %51
31: ; preds = %26
%32 = load float, float* %14
%33 = fpext float %32 to double
%34 = load double*, double** %10
%35 = load i32, i32* %12
%36 = load i32, i32* %9
%37 = mul nsw i32 %35, %36
%38 = load i32, i32* %13
%39 = add nsw i32 %37, %38
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %34, i64 %40
store double %33, double* %41
%42 = load i32, i32* %13
%43 = add nsw i32 %42, 1
store i32 %43, i32* %13
%44 = load i32, i32* %13
%45 = load i32, i32* %9
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %50
47: ; preds = %31
store i32 0, i32* %13
%48 = load i32, i32* %12
%49 = add nsw i32 %48, 1
store i32 %49, i32* %12
br label %50
50: ; preds = %47, %31
br label %26
51: ; preds = %26
br label %52
52: ; preds = %51, %21
%53 = load i32*, i32** %15
%54 = call i32 @fclose(i32* %53)
store i32 0, i32* %6
br label %55
55: ; preds = %52, %19
%56 = load i32, i32* %6
ret i32 %56
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"genotypes\00"
@.str.3 = [3 x i8] c"%g\00"
@EOF = global i64 0
@str = [26 x i8] c"Error, invalid input file\00"
define i32 @extractData(i8* nocapture %0, i32 %1, i32 %2, double* nocapture writeonly %3, i8* nocapture %4) {
%6 = alloca float
%7 = bitcast float* %6 to i8*
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %38
12: ; preds = %5
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %4, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %36
15: ; preds = %12
%16 = call i64 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %6)
%17 = load i64, i64* @EOF
%18 = icmp eq i64 %16, %17
br i1 %18, label %36, label %19
19: ; preds = %15, %19
%20 = phi i32 [ %32, %19 ], [ 0, %15 ]
%21 = phi i32 [ %31, %19 ], [ 0, %15 ]
%22 = load float, float* %6
%23 = fpext float %22 to double
%24 = mul nsw i32 %21, %2
%25 = add nsw i32 %24, %20
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %3, i64 %26
store double %23, double* %27
%28 = add nsw i32 %20, 1
%29 = icmp eq i32 %28, %2
%30 = zext i1 %29 to i32
%31 = add nuw nsw i32 %21, %30
%32 = select i1 %29, i32 0, i32 %28
%33 = call i64 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %6)
%34 = load i64, i64* @EOF
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %19
36: ; preds = %19, %15, %12
%37 = call i32 @fclose(i32* %8)
br label %38
38: ; preds = %36, %10
%39 = phi i32 [ 1, %10 ], [ 0, %36 ]
ret i32 %39
}