#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, float *);
int /*<<< orphan*/ stderr;
void read_data_from_file(char *filename, int problem_size, double *data) {
  FILE *fp;
  fp = fopen(filename, "r");
  if (fp == NULL) {
    fprintf(stderr, "Can't open input file!\n\n");
    exit(1);
  }
  float tmp1;
  char tmp;
  for (int i = 0; i < (problem_size * 2); i++) {
    fscanf(fp, "%f ", &tmp1);
    data[i] = tmp1;
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<read_data_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a1 <read_data_from_file+0x51>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jge    11f1 <read_data_from_file+0xa1>
mov    -0x20(%rbp),%rdi
lea    0xe57(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1040 <fscanf@plt>
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a8 <read_data_from_file+0x58>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_data_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11de <read_data_from_file+0x8e>
mov    %rax,%r13
test   %r15d,%r15d
jle    11c7 <read_data_from_file+0x77>
add    %r15d,%r15d
cmp    $0x2,%r15d
mov    $0x1,%ebp
cmovge %r15d,%ebp
xor    %ebx,%ebx
lea    0xe88(%rip),%r15
lea    0x4(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <fscanf@plt>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11a0 <read_data_from_file+0x50>
mov    %r13,%rdi
call   1030 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Can't open input file!\0A\0A\00"
@.str.2 = [4 x i8] c"%f \00"
define void @read_data_from_file(i8* %0, i32 %1, double* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca double*
%7 = alloca i32*
%8 = alloca float
%9 = alloca i8
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store double* %2, double** %6
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %7
%13 = load i32*, i32** %7
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %3
store i32 0, i32* %10
br label %20
20: ; preds = %34, %19
%21 = load i32, i32* %10
%22 = load i32, i32* %5
%23 = mul nsw i32 %22, 2
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %37
25: ; preds = %20
%26 = load i32*, i32** %7
%27 = call i32 @fscanf(i32* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), float* %8)
%28 = load float, float* %8
%29 = fpext float %28 to double
%30 = load double*, double** %6
%31 = load i32, i32* %10
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
store double %29, double* %33
br label %34
34: ; preds = %25
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
store i32 %36, i32* %10
br label %20
37: ; preds = %20
%38 = load i32*, i32** %7
%39 = call i32 @fclose(i32* %38)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Can't open input file!\0A\0A\00"
@.str.2 = [4 x i8] c"%f \00"
define void @read_data_from_file(i8* nocapture %0, i32 %1, double* nocapture writeonly %2) {
%4 = alloca float
%5 = tail call i32* @fopen(i8* %0, 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 %11
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %3
%12 = bitcast float* %4 to i8*
%13 = icmp sgt i32 %1, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = shl nuw i32 %1, 1
%16 = call i32 @llvm.smax.i32(i32 %15, i32 1)
%17 = zext i32 %16 to i64
br label %20
18: ; preds = %20, %11
%19 = call i32 @fclose(i32* %5)
ret void
20: ; preds = %14, %20
%21 = phi i64 [ 0, %14 ], [ %26, %20 ]
%22 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), float* %4)
%23 = load float, float* %4
%24 = fpext float %23 to double
%25 = getelementptr inbounds double, double* %2, i64 %21
store double %24, double* %25
%26 = add nuw nsw i64 %21, 1
%27 = icmp eq i64 %26, %17
br i1 %27, label %18, label %20
}