#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int readVectorFromFile(long long **v, int *n, long long *sum, char *file,
                       char *err) {
  FILE *inputFile = fopen(file, "rt");
  int countReadedElements = 0, i = 0;
  if (inputFile == NULL) {
    strcpy(err, "Err. Could not open file.\n");
    return 0;
  }
  if (fscanf(inputFile, "%d", n) != 1) {
    fclose(inputFile);
    strcpy(err, "Err. Could not read number of elements.\n");
    return 0;
  }
  if (fscanf(inputFile, "%lld", sum) != 1) {
    fclose(inputFile);
    strcpy(err, "Err. Could not read target sum to search for if there are 2 "
                "values x + y = sum.\n");
    return 0;
  }
  *v = (long long *)malloc(sizeof(long long) * (*n));
  while (!feof(inputFile)) {
    if (fscanf(inputFile, "%lld", &(*v)[i++]) != 1) {
      break;
    }
    countReadedElements++;
  }
  fclose(inputFile);
  if (countReadedElements != *n) {
    strcpy(err, "Err. Number of declared elements does not match with the one "
                "found in file.\n");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<readVectorFromFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11c5 <readVectorFromFile+0x65>
mov    -0x30(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    130b <readVectorFromFile+0x1ab>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
cmp    $0x1,%eax
je     1209 <readVectorFromFile+0xa9>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    130b <readVectorFromFile+0x1ab>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
cmp    $0x1,%eax
je     124d <readVectorFromFile+0xed>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rdi
lea    0xe13(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    130b <readVectorFromFile+0x1ab>
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1287 <readVectorFromFile+0x127>
jmp    12d0 <readVectorFromFile+0x170>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x40(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x40(%rbp)
cltq
shl    $0x3,%rax
add    %rax,%rdx
lea    0xd9d(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
cmp    $0x1,%eax
je     12c2 <readVectorFromFile+0x162>
jmp    12d0 <readVectorFromFile+0x170>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1269 <readVectorFromFile+0x109>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x3c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
je     1304 <readVectorFromFile+0x1a4>
mov    -0x30(%rbp),%rdi
lea    0xdad(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    130b <readVectorFromFile+0x1ab>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readVectorFromFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe82(%rip),%rsi
mov    %rcx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     123c <readVectorFromFile+0xdc>
mov    %rax,%rbx
lea    0xe85(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    1245 <readVectorFromFile+0xe5>
lea    0xe94(%rip),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    124e <readVectorFromFile+0xee>
mov    (%r15),%edi
shl    $0x3,%edi
call   1070 <malloc@plt>
mov    %rax,(%r12)
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1221 <readVectorFromFile+0xc1>
xor    %r13d,%r13d
xor    %ebp,%ebp
xchg   %ax,%ax
mov    (%r12),%rdx
add    %r13,%rdx
mov    %rbx,%rdi
lea    0xe49(%rip),%rsi
xor    %eax,%eax
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    1221 <readVectorFromFile+0xc1>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1060 <feof@plt>
add    $0x8,%r13
test   %eax,%eax
je     11f0 <readVectorFromFile+0x90>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x1,%eax
cmp    (%r15),%ebp
je     126a <readVectorFromFile+0x10a>
lea    0xe66(%rip),%r15
jmp    125d <readVectorFromFile+0xfd>
lea    0xdc0(%rip),%r15
jmp    125d <readVectorFromFile+0xfd>
lea    0xdd5(%rip),%r15
jmp    1255 <readVectorFromFile+0xf5>
lea    0xdfa(%rip),%r15
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rt\00"
@.str.1 = [27 x i8] c"Err. Could not open file.\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [41 x i8] c"Err. Could not read number of elements.\0A\00"
@.str.4 = [5 x i8] c"%lld\00"
@.str.5 = [81 x i8] c"Err. Could not read target sum to search for if there are 2 values x + y = sum.\0A\00"
@.str.6 = [77 x i8] c"Err. Number of declared elements does not match with the one found in file.\0A\00"
define i32 @readVectorFromFile(i64** %0, i32* %1, i64* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i64**
%8 = alloca i32*
%9 = alloca i64*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
store i64** %0, i64*** %7
store i32* %1, i32** %8
store i64* %2, i64** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%15 = load i8*, i8** %10
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %12
store i32 0, i32* %13
store i32 0, i32* %14
%17 = load i32*, i32** %12
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %5
%20 = load i8*, i8** %11
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %6
br label %81
22: ; preds = %5
%23 = load i32*, i32** %12
%24 = load i32*, i32** %8
%25 = call i32 (i32*, i8*, ...) @fscanf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %24)
%26 = icmp ne i32 %25, 1
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i32*, i32** %12
%29 = call i32 @fclose(i32* %28)
%30 = load i8*, i8** %11
%31 = call i32 @strcpy(i8* %30, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
br label %81
32: ; preds = %22
%33 = load i32*, i32** %12
%34 = load i64*, i64** %9
%35 = call i32 (i32*, i8*, ...) @fscanf(i32* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64* %34)
%36 = icmp ne i32 %35, 1
br i1 %36, label %37, label %42
37: ; preds = %32
%38 = load i32*, i32** %12
%39 = call i32 @fclose(i32* %38)
%40 = load i8*, i8** %11
%41 = call i32 @strcpy(i8* %40, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %6
br label %81
42: ; preds = %32
%43 = load i32*, i32** %8
%44 = load i32, i32* %43
%45 = sext i32 %44 to i64
%46 = mul i64 8, %45
%47 = trunc i64 %46 to i32
%48 = call i64 @malloc(i32 %47)
%49 = inttoptr i64 %48 to i64*
%50 = load i64**, i64*** %7
store i64* %49, i64** %50
br label %51
51: ; preds = %67, %42
%52 = load i32*, i32** %12
%53 = call i32 @feof(i32* %52)
%54 = icmp ne i32 %53, 0
%55 = xor i1 %54, true
br i1 %55, label %56, label %70
56: ; preds = %51
%57 = load i32*, i32** %12
%58 = load i64**, i64*** %7
%59 = load i64*, i64** %58
%60 = load i32, i32* %14
%61 = add nsw i32 %60, 1
store i32 %61, i32* %14
%62 = sext i32 %60 to i64
%63 = getelementptr inbounds i64, i64* %59, i64 %62
%64 = call i32 (i32*, i8*, ...) @fscanf(i32* %57, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64* %63)
%65 = icmp ne i32 %64, 1
br i1 %65, label %66, label %67
66: ; preds = %56
br label %70
67: ; preds = %56
%68 = load i32, i32* %13
%69 = add nsw i32 %68, 1
store i32 %69, i32* %13
br label %51
70: ; preds = %66, %51
%71 = load i32*, i32** %12
%72 = call i32 @fclose(i32* %71)
%73 = load i32, i32* %13
%74 = load i32*, i32** %8
%75 = load i32, i32* %74
%76 = icmp ne i32 %73, %75
br i1 %76, label %77, label %80
77: ; preds = %70
%78 = load i8*, i8** %11
%79 = call i32 @strcpy(i8* %78, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %6
br label %81
80: ; preds = %70
store i32 1, i32* %6
br label %81
81: ; preds = %80, %77, %37, %27, %19
%82 = load i32, i32* %6
ret i32 %82
}

LLVM IR (-O2):
@.str = [3 x i8] c"rt\00"
@.str.1 = [27 x i8] c"Err. Could not open file.\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [41 x i8] c"Err. Could not read number of elements.\0A\00"
@.str.4 = [5 x i8] c"%lld\00"
@.str.5 = [81 x i8] c"Err. Could not read target sum to search for if there are 2 values x + y = sum.\0A\00"
@.str.6 = [77 x i8] c"Err. Number of declared elements does not match with the one found in file.\0A\00"
define i32 @readVectorFromFile(i64** nocapture %0, i32* %1, i64* %2, i8* nocapture %3, i8* %4) {
%6 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %42, label %8
8: ; preds = %5
%9 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %39
11: ; preds = %8
%12 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64* %2)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %39
14: ; preds = %11
%15 = load i32, i32* %1
%16 = shl i32 %15, 3
%17 = tail call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i64*
store i64* %18, i64** %0
%19 = tail call i32 @feof(i32* %6)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %34
21: ; preds = %14, %27
%22 = phi i64 [ %28, %27 ], [ 0, %14 ]
%23 = load i64*, i64** %0
%24 = getelementptr inbounds i64, i64* %23, i64 %22
%25 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64* %24)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = add nuw i64 %22, 1
%29 = tail call i32 @feof(i32* %6)
%30 = icmp eq i32 %29, 0
br i1 %30, label %21, label %31
31: ; preds = %21, %27
%32 = phi i64 [ %28, %27 ], [ %22, %21 ]
%33 = trunc i64 %32 to i32
br label %34
34: ; preds = %31, %14
%35 = phi i32 [ 0, %14 ], [ %33, %31 ]
%36 = tail call i32 @fclose(i32* %6)
%37 = load i32, i32* %1
%38 = icmp eq i32 %35, %37
br i1 %38, label %45, label %42
39: ; preds = %11, %8
%40 = phi i8* [ getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), %8 ], [ getelementptr inbounds ([81 x i8], [81 x i8]* @.str.5, i64 0, i64 0), %11 ]
%41 = tail call i32 @fclose(i32* %6)
br label %42
42: ; preds = %39, %34, %5
%43 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), %5 ], [ getelementptr inbounds ([77 x i8], [77 x i8]* @.str.6, i64 0, i64 0), %34 ], [ %40, %39 ]
%44 = tail call i32 @strcpy(i8* %4, i8* %43)
br label %45
45: ; preds = %42, %34
%46 = phi i32 [ 1, %34 ], [ 0, %42 ]
ret i32 %46
}