#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*/ fscanf(int /*<<< orphan*/ *, char *, double *);
int /*<<< orphan*/ printf(char *);
void read1col(int n, double *x, char *filename) {
  FILE *fp;
  if ((fp = fopen(filename, "r")) == NULL) {
    printf("\nError opening file\n");
    exit(1);
  } else {
    int i;
    for (i = 1; i <= n; i++) {
      fscanf(fp, "%lf", &x[i]);
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<read1col>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1197 <read1col+0x47>
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11d7 <read1col+0x87>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe53(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119e <read1col+0x4e>
jmp    11dc <read1col+0x8c>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read1col>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe9d(%rip),%rsi
mov    %rdx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ba <read1col+0x6a>
mov    %rax,%r14
test   %ebp,%ebp
jle    11a8 <read1col+0x58>
mov    %ebp,%ebp
add    $0x8,%rbx
lea    0xe7e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
add    $0x8,%rbx
add    $0xffffffffffffffff,%rbp
jne    1190 <read1col+0x40>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [21 x i8] c"\0AError opening file\0A\00"
@.str.2 = [4 x i8] c"%lf\00"
define void @read1col(i32 %0, double* %1, i8* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %4
store double* %1, double** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %7
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %3
store i32 1, i32* %8
br label %16
16: ; preds = %27, %15
%17 = load i32, i32* %8
%18 = load i32, i32* %4
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = load i32*, i32** %7
%22 = load double*, double** %5
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %25)
br label %27
27: ; preds = %20
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %16
30: ; preds = %16
br label %31
31: ; preds = %30
%32 = load i32*, i32** %7
%33 = call i32 @fclose(i32* %32)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%lf\00"
@str = [20 x i8] c"\0AError opening file\00"
define void @read1col(i32 %0, double* %1, i8* nocapture %2) {
%4 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = icmp slt i32 %0, 1
br i1 %7, label %20, label %8
8: ; preds = %6
%9 = add nuw i32 %0, 1
%10 = zext i32 %9 to i64
br label %14
11: ; preds = %3
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %8, %14
%15 = phi i64 [ 1, %8 ], [ %18, %14 ]
%16 = getelementptr inbounds double, double* %1, i64 %15
%17 = tail call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %16)
%18 = add nuw nsw i64 %15, 1
%19 = icmp eq i64 %18, %10
br i1 %19, label %20, label %14
20: ; preds = %14, %6
%21 = tail call i32 @fclose(i32* %4)
ret void
}