#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
void read_vector_from_file(char *filename, int dim, int dim2, float *v) {
  FILE *fd;
  int i = 0;
  float *tmp = v;
  fd = fopen(filename, "r");
  for (i = 0; i < dim; i++) {
    fscanf(fd, "%f ", tmp++);
  }
  for (; i < dim2; i++) {
    *tmp = (float)0;
    tmp++;
  }
  fclose(fd);
}


x86 assembly (clang, -O0):
<read_vector_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ab <read_vector_from_file+0x7b>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x30(%rbp)
mov    %eax,%edx
lea    0xe6a(%rip),%rsi
call   1040 <fscanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1170 <read_vector_from_file+0x40>
jmp    11b0 <read_vector_from_file+0x80>
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11e1 <read_vector_from_file+0xb1>
mov    -0x30(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b0 <read_vector_from_file+0x80>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_vector_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %esi,%r12d
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
test   %r12d,%r12d
jle    11d1 <read_vector_from_file+0x91>
mov    %ebp,0x4(%rsp)
lea    0xe90(%rip),%r13
mov    %r12d,%r15d
mov    %ebx,%ebp
nopw   0x0(%rax,%rax,1)
add    $0x4,%rbx
mov    %r14,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1050 <fscanf@plt>
add    $0x4,%ebp
add    $0xffffffff,%r15d
jne    1180 <read_vector_from_file+0x40>
mov    0x4(%rsp),%ebp
cmp    %ebp,%r12d
jge    11bb <read_vector_from_file+0x7b>
not    %r12d
add    %ebp,%r12d
lea    0x4(,%r12,4),%rdx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
xor    %r12d,%r12d
cmp    %ebp,%r12d
jl     11a3 <read_vector_from_file+0x63>
jmp    11bb <read_vector_from_file+0x7b>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%f \00"
define void @read_vector_from_file(i8* %0, i32 %1, i32 %2, float* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca float*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca float*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store float* %3, float** %8
store i32 0, i32* %10
%12 = load float*, float** %8
store float* %12, float** %11
%13 = load i8*, i8** %5
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %9
store i32 0, i32* %10
br label %15
15: ; preds = %25, %4
%16 = load i32, i32* %10
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load i32*, i32** %9
%21 = load float*, float** %11
%22 = getelementptr inbounds float, float* %21, i32 1
store float* %22, float** %11
%23 = ptrtoint float* %21 to i32
%24 = call i32 @fscanf(i32* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %19
%26 = load i32, i32* %10
%27 = add nsw i32 %26, 1
store i32 %27, i32* %10
br label %15
28: ; preds = %15
br label %29
29: ; preds = %37, %28
%30 = load i32, i32* %10
%31 = load i32, i32* %7
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %40
33: ; preds = %29
%34 = load float*, float** %11
store float 0.000000e+00, float* %34
%35 = load float*, float** %11
%36 = getelementptr inbounds float, float* %35, i32 1
store float* %36, float** %11
br label %37
37: ; preds = %33
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %29
40: ; preds = %29
%41 = load i32*, i32** %9
%42 = call i32 @fclose(i32* %41)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%f \00"
define void @read_vector_from_file(i8* nocapture %0, i32 %1, i32 %2, float* %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp sgt i32 %1, 0
br i1 %6, label %18, label %7
7: ; preds = %18, %4
%8 = phi i32 [ 0, %4 ], [ %1, %18 ]
%9 = phi float* [ %3, %4 ], [ %21, %18 ]
%10 = icmp slt i32 %8, %2
br i1 %10, label %11, label %27
11: ; preds = %7
%12 = bitcast float* %9 to i8*
%13 = xor i32 %8, -1
%14 = add i32 %13, %2
%15 = zext i32 %14 to i64
%16 = shl nuw nsw i64 %15, 2
%17 = add nuw nsw i64 %16, 4
br label %27
18: ; preds = %4, %18
%19 = phi float* [ %21, %18 ], [ %3, %4 ]
%20 = phi i32 [ %25, %18 ], [ 0, %4 ]
%21 = getelementptr inbounds float, float* %19, i64 1
%22 = ptrtoint float* %19 to i64
%23 = trunc i64 %22 to i32
%24 = tail call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = add nuw nsw i32 %20, 1
%26 = icmp eq i32 %25, %1
br i1 %26, label %7, label %18
27: ; preds = %11, %7
%28 = tail call i32 @fclose(i32* %5)
ret void
}