#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 *, double *);
int /*<<< orphan*/ printf(char *);
void read2col(int n, double *x, double *y, 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 %lf", &x[i], &y[i]);
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<read2col>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    119b <read2col+0x4b>
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11ea <read2col+0x9a>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x18(%rbp),%rcx
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rcx
lea    0xe40(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a2 <read2col+0x52>
jmp    11ef <read2col+0x9f>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read2col>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe99(%rip),%rsi
mov    %rcx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11bf <read2col+0x6f>
mov    %rax,%r15
test   %ebp,%ebp
jle    11af <read2col+0x5f>
mov    %ebp,%ebp
add    $0x8,%r14
add    $0x8,%rbx
lea    0xe76(%rip),%r12
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1050 <fscanf@plt>
add    $0x8,%r14
add    $0x8,%rbx
add    $0xffffffffffffffff,%rbp
jne    1190 <read2col+0x40>
mov    %r15,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
lea    0xe44(%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 = [8 x i8] c"%lf %lf\00"
define void @read2col(i32 %0, double* %1, double* %2, i8* %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca double*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
store i32 %0, i32* %5
store double* %1, double** %6
store double* %2, double** %7
store i8* %3, i8** %8
%11 = load i8*, i8** %8
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %9
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %4
store i32 1, i32* %10
br label %18
18: ; preds = %33, %17
%19 = load i32, i32* %10
%20 = load i32, i32* %5
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %36
22: ; preds = %18
%23 = load i32*, i32** %9
%24 = load double*, double** %6
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
%28 = load double*, double** %7
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = call i32 @fscanf(i32* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double* %27, double* %31)
br label %33
33: ; preds = %22
%34 = load i32, i32* %10
%35 = add nsw i32 %34, 1
store i32 %35, i32* %10
br label %18
36: ; preds = %18
br label %37
37: ; preds = %36
%38 = load i32*, i32** %9
%39 = call i32 @fclose(i32* %38)
ret void
}

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