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


x86 assembly (clang, -O0):
<read3col>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    119f <read3col+0x4f>
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11fd <read3col+0xad>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
movslq -0x34(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x18(%rbp),%rcx
movslq -0x34(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rcx
mov    -0x20(%rbp),%r8
movslq -0x34(%rbp),%rax
shl    $0x3,%rax
add    %rax,%r8
lea    0xe2d(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a6 <read3col+0x56>
jmp    1202 <read3col+0xb2>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

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

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