#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 fscanf(int /*<<< orphan*/ *, char *, int *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
double *read_coords_2D(char *filename, int *nodes) {
  double *res;
  int len, size, a, i;
  FILE *f;
  f = fopen(filename, "r");
  if (fscanf(f, "%d %d %d %d\n", &len, &size, &a, &a) == -1)
    printf("Error reading file %s \n", filename);
  *nodes = len;
  res = (double *)malloc(sizeof(double) * len * size);
  for (i = 0; i < len * size; i += 2) {
    if (fscanf(f, "%d %lf %lf\n", &a, &res[i], &res[i + 1]) == -1)
      printf("Error reading file %s \n", filename);
  }
  fclose(f);
  return res;
}


x86 assembly (clang, -O0):
<read_coords_2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe83(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%r9
mov    %r9,%r8
mov    $0x0,%al
call   1050 <fscanf@plt>
cmp    $0xffffffff,%eax
jne    11ae <read_coords_2D+0x5e>
mov    -0x8(%rbp),%rsi
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
movslq -0x20(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x1c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
cmp    %ecx,%eax
jge    124f <read_coords_2D+0xff>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rcx
movslq -0x28(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rcx
mov    -0x18(%rbp),%r8
mov    -0x28(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
add    %rax,%r8
lea    0xe0f(%rip),%rsi
lea    -0x24(%rbp),%rdx
mov    $0x0,%al
call   1050 <fscanf@plt>
cmp    $0xffffffff,%eax
jne    123c <read_coords_2D+0xec>
mov    -0x8(%rbp),%rsi
lea    0xdd8(%rip),%rdi
call   1040 <printf@plt>
jmp    1241 <read_coords_2D+0xf1>
mov    -0x28(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x28(%rbp)
jmp    11d9 <read_coords_2D+0x89>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_coords_2D>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe88(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %rax,%rdi
mov    %r8,%r9
xor    %eax,%eax
call   1050 <fscanf@plt>
cmp    $0xffffffff,%eax
jne    11aa <read_coords_2D+0x5a>
lea    0xe6d(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    0x8(%rsp),%edi
mov    %edi,0x0(%rbp)
imul   0x4(%rsp),%edi
shl    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    0x4(%rsp),%eax
imul   0x8(%rsp),%eax
test   %eax,%eax
jle    1231 <read_coords_2D+0xe1>
lea    0xe50(%rip),%r12
lea    0xc(%rsp),%r13
xor    %ebp,%ebp
mov    0x10(%rsp),%r15
jmp    1204 <read_coords_2D+0xb4>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x4(%rsp),%eax
imul   0x8(%rsp),%eax
add    $0x10,%r15
add    $0x2,%ebp
cmp    %ebp,%eax
jle    1231 <read_coords_2D+0xe1>
lea    0x8(%r15),%r8
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <fscanf@plt>
cmp    $0xffffffff,%eax
jne    11f0 <read_coords_2D+0xa0>
lea    0xde8(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
jmp    11f0 <read_coords_2D+0xa0>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x10(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [13 x i8] c"%d %d %d %d\0A\00"
@.str.2 = [24 x i8] c"Error reading file %s \0A\00"
@.str.3 = [12 x i8] c"%d %lf %lf\0A\00"
define double* @read_coords_2D(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i8* %0, i8** %3
store i32* %1, i32** %4
%11 = load i8*, i8** %3
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %10
%13 = load i32*, i32** %10
%14 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32* %6, i32* %7, i32* %8, i32* %8)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %16, %2
%20 = load i32, i32* %6
%21 = load i32*, i32** %4
store i32 %20, i32* %21
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = mul i64 8, %23
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = mul i64 %24, %26
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to double*
store double* %30, double** %5
store i32 0, i32* %9
br label %31
31: ; preds = %54, %19
%32 = load i32, i32* %9
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = mul nsw i32 %33, %34
%36 = icmp slt i32 %32, %35
br i1 %36, label %37, label %57
37: ; preds = %31
%38 = load i32*, i32** %10
%39 = load double*, double** %5
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double*, double** %5
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %43, i64 %46
%48 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %38, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32* %8, double* %42, double* %47)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %53
50: ; preds = %37
%51 = load i8*, i8** %3
%52 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %50, %37
br label %54
54: ; preds = %53
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 2
store i32 %56, i32* %9
br label %31
57: ; preds = %31
%58 = load i32*, i32** %10
%59 = call i32 @fclose(i32* %58)
%60 = load double*, double** %5
ret double* %60
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [13 x i8] c"%d %d %d %d\0A\00"
@.str.2 = [24 x i8] c"Error reading file %s \0A\00"
@.str.3 = [12 x i8] c"%d %lf %lf\0A\00"
define double* @read_coords_2D(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4, i32* %5, i32* %5)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %14
14: ; preds = %12, %2
%15 = load i32, i32* %3
store i32 %15, i32* %1
%16 = shl i32 %15, 3
%17 = load i32, i32* %4
%18 = mul i32 %16, %17
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to double*
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = mul nsw i32 %22, %21
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %41
25: ; preds = %14, %34
%26 = phi i64 [ %35, %34 ], [ 0, %14 ]
%27 = getelementptr inbounds double, double* %20, i64 %26
%28 = or i64 %26, 1
%29 = getelementptr inbounds double, double* %20, i64 %28
%30 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32* %5, double* %27, double* %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %34
34: ; preds = %25, %32
%35 = add nuw i64 %26, 2
%36 = load i32, i32* %3
%37 = load i32, i32* %4
%38 = mul nsw i32 %37, %36
%39 = trunc i64 %35 to i32
%40 = icmp sgt i32 %38, %39
br i1 %40, label %25, label %41
41: ; preds = %34, %14
%42 = call i32 @fclose(i32* %9)
ret double* %20
}