#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*/ close(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, double *);
void read_vector(double *vector, int m) {
  FILE *fp;
  fp = fopen("vector.dat", "r");
  int i;
  for (i = 0; i < m; i++) {
    fscanf(fp, "%lf", &vector[i]);
  }
  close(fp);
}


x86 assembly (clang, -O0):
<read_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeba(%rip),%rdi
lea    0xebe(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1196 <read_vector+0x66>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe8a(%rip),%rsi
call   1030 <fscanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115d <read_vector+0x2d>
mov    -0x18(%rbp),%rdi
call   1040 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_vector>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xebd(%rip),%rdi
lea    0xec1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
test   %ebp,%ebp
jle    1178 <read_vector+0x48>
mov    %ebp,%ebp
lea    0xeae(%rip),%r15
nop
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <fscanf@plt>
add    $0x8,%rbx
add    $0xffffffffffffffff,%rbp
jne    1160 <read_vector+0x30>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <close@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"vector.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%lf\00"
define void @read_vector(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
%7 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
store i32 0, i32* %6
br label %8
8: ; preds = %19, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = load i32*, i32** %5
%14 = load double*, double** %3
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %14, i64 %16
%18 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %17)
br label %19
19: ; preds = %12
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
br label %8
22: ; preds = %8
%23 = load i32*, i32** %5
%24 = call i32 @close(i32* %23)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"vector.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%lf\00"
define void @read_vector(double* %0, i32 %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %13
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %11, %7 ]
%9 = getelementptr inbounds double, double* %0, i64 %8
%10 = tail call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %9)
%11 = add nuw nsw i64 %8, 1
%12 = icmp eq i64 %11, %6
br i1 %12, label %13, label %7
13: ; preds = %7, %2
%14 = tail call i32 @close(i32* %3)
ret void
}