#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 scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
int EXIT_SUCCESS;
int binarySearch(long long *, int /*<<< orphan*/, int, long long);
scalar_t__ clock();
int /*<<< orphan*/ err(char *);
int /*<<< orphan*/ free(long long *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ quickSort(long long *, int /*<<< orphan*/, int);
int /*<<< orphan*/ readVectorFromFile(long long **, int *, long long *, char *,
                                      char *);
int main(int argc, char **argv) {
  printf("------ Begin 2Sum ------\n");
  int n, i, found = 0;
  long long *v, sum, x, y;
  clock_t start, end;
  char error[128];
  if (argc == 1) {
    err("Err. The input file must be given as an argument.\n");
  }
  if (!readVectorFromFile(&v, &n, &sum, argv[1], error)) {
    err(error);
  }
  start = clock();
  quickSort(v, 0, n - 1);
  for (i = 0; i < n; i++) {
    if (v[i] != sum - v[i] && -1 != binarySearch(v, 0, n - 1, sum - v[i])) {
      found = 1;
      x = v[i];
      y = sum - v[i];
      break;
    }
  }
  end = clock();
  if (found) {
    printf("Found %lld + %lld = %lld\n", x, y, sum);
  } else {
    printf("Found no elements with sum %lld\n", sum);
  }
  free(v);
  printf("Elapsed: %f seconds.\n", (double)(end - start) / CLOCKS_PER_SEC);
  printf("------- End 2Sum -------\n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11b4 <main+0x44>
lea    0xe6b(%rip),%rdi
call   1080 <err@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    -0xd0(%rbp),%r8
lea    -0x28(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1050 <readVectorFromFile@plt>
cmp    $0x0,%eax
jne    11e9 <main+0x79>
lea    -0xd0(%rbp),%rdi
call   1080 <err@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1090 <quickSort@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12b0 <main+0x140>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rdx
movslq -0x18(%rbp),%rsi
sub    (%rdx,%rsi,8),%rcx
cmp    %rcx,%rax
je     129d <main+0x12d>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rsi
sub    (%rax,%rsi,8),%rcx
xor    %esi,%esi
call   1070 <binarySearch@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     129d <main+0x12d>
movl   $0x1,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
movslq -0x18(%rbp),%rdx
sub    (%rcx,%rdx,8),%rax
mov    %rax,-0x40(%rbp)
jmp    12b0 <main+0x140>
jmp    12a2 <main+0x132>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    120c <main+0x9c>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x50(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     12e4 <main+0x174>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12f6 <main+0x186>
mov    -0x30(%rbp),%rsi
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rax
sub    -0x48(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2cd5(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd6a(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2c9e(%rip),%rax
mov    (%rax),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xa8,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xeeb(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x1,%ebp
jne    11af <main+0x2f>
lea    0xe56(%rip),%rdi
call   1090 <err@plt>
mov    0x8(%rbx),%rcx
lea    0x18(%rsp),%rdi
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x20(%rsp),%r8
call   1060 <readVectorFromFile@plt>
test   %eax,%eax
jne    11da <main+0x5a>
lea    0x20(%rsp),%rdi
call   1090 <err@plt>
xor    %eax,%eax
call   1050 <clock@plt>
mov    %rax,%r14
mov    0x18(%rsp),%rdi
mov    0xc(%rsp),%edx
add    $0xffffffff,%edx
xor    %esi,%esi
call   10a0 <quickSort@plt>
mov    0xc(%rsp),%edx
test   %edx,%edx
jle    1247 <main+0xc7>
xor    %ebx,%ebx
jmp    121c <main+0x9c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
movslq %edx,%rax
cmp    %rax,%rbx
jge    1247 <main+0xc7>
mov    0x18(%rsp),%rdi
mov    (%rdi,%rbx,8),%rax
mov    0x10(%rsp),%rcx
sub    %rax,%rcx
cmp    %rcx,%rax
je     1210 <main+0x90>
add    $0xffffffff,%edx
xor    %esi,%esi
call   1080 <binarySearch@plt>
cmp    $0xffffffff,%eax
jne    1266 <main+0xe6>
mov    0xc(%rsp),%edx
jmp    1210 <main+0x90>
xor    %eax,%eax
call   1050 <clock@plt>
mov    %rax,%rbx
mov    0x10(%rsp),%rsi
lea    0xdf0(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    129a <main+0x11a>
mov    0x18(%rsp),%rax
mov    (%rax,%rbx,8),%r15
mov    0x10(%rsp),%rbp
sub    %r15,%rbp
xor    %eax,%eax
call   1050 <clock@plt>
mov    %rax,%rbx
mov    0x10(%rsp),%rcx
lea    0xda6(%rip),%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
sub    %r14,%rbx
cvtsi2sd %rbx,%xmm0
mov    0x2d35(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdb0(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
lea    0xdd1(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d00(%rip),%rax
mov    (%rax),%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"------ Begin 2Sum ------\0A\00"
@.str.1 = [51 x i8] c"Err. The input file must be given as an argument.\0A\00"
@.str.2 = [26 x i8] c"Found %lld + %lld = %lld\0A\00"
@.str.3 = [33 x i8] c"Found no elements with sum %lld\0A\00"
@.str.4 = [22 x i8] c"Elapsed: %f seconds.\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.5 = [26 x i8] c"------- End 2Sum -------\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @err(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %15, i64 0, i64 0
%26 = call i32 @readVectorFromFile(i64** %9, i32* %6, i64* %10, i8* %24, i8* %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %21
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %15, i64 0, i64 0
%30 = call i32 @err(i8* %29)
br label %31
31: ; preds = %28, %21
%32 = call i64 (...) @clock()
store i64 %32, i64* %13
%33 = load i64*, i64** %9
%34 = load i32, i32* %6
%35 = sub nsw i32 %34, 1
%36 = call i32 @quickSort(i64* %33, i32 0, i32 %35)
store i32 0, i32* %7
br label %37
37: ; preds = %82, %31
%38 = load i32, i32* %7
%39 = load i32, i32* %6
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %85
41: ; preds = %37
%42 = load i64*, i64** %9
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i64, i64* %42, i64 %44
%46 = load i64, i64* %45
%47 = load i64, i64* %10
%48 = load i64*, i64** %9
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i64, i64* %48, i64 %50
%52 = load i64, i64* %51
%53 = sub nsw i64 %47, %52
%54 = icmp ne i64 %46, %53
br i1 %54, label %55, label %81
55: ; preds = %41
%56 = load i64*, i64** %9
%57 = load i32, i32* %6
%58 = sub nsw i32 %57, 1
%59 = load i64, i64* %10
%60 = load i64*, i64** %9
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i64, i64* %60, i64 %62
%64 = load i64, i64* %63
%65 = sub nsw i64 %59, %64
%66 = call i32 @binarySearch(i64* %56, i32 0, i32 %58, i64 %65)
%67 = icmp ne i32 -1, %66
br i1 %67, label %68, label %81
68: ; preds = %55
store i32 1, i32* %8
%69 = load i64*, i64** %9
%70 = load i32, i32* %7
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i64, i64* %69, i64 %71
%73 = load i64, i64* %72
store i64 %73, i64* %11
%74 = load i64, i64* %10
%75 = load i64*, i64** %9
%76 = load i32, i32* %7
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i64, i64* %75, i64 %77
%79 = load i64, i64* %78
%80 = sub nsw i64 %74, %79
store i64 %80, i64* %12
br label %85
81: ; preds = %55, %41
br label %82
82: ; preds = %81
%83 = load i32, i32* %7
%84 = add nsw i32 %83, 1
store i32 %84, i32* %7
br label %37
85: ; preds = %68, %37
%86 = call i64 (...) @clock()
store i64 %86, i64* %14
%87 = load i32, i32* %8
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %94
89: ; preds = %85
%90 = load i64, i64* %11
%91 = load i64, i64* %12
%92 = load i64, i64* %10
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i64 %90, i64 %91, i64 %92)
br label %97
94: ; preds = %85
%95 = load i64, i64* %10
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i64 %95)
br label %97
97: ; preds = %94, %89
%98 = load i64*, i64** %9
%99 = call i32 @free(i64* %98)
%100 = load i64, i64* %14
%101 = load i64, i64* %13
%102 = sub nsw i64 %100, %101
%103 = sitofp i64 %102 to double
%104 = load double, double* @CLOCKS_PER_SEC
%105 = fdiv double %103, %104
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), double %105)
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%108 = load i32, i32* @EXIT_SUCCESS
ret i32 %108
}

LLVM IR (-O2):
@.str.1 = [51 x i8] c"Err. The input file must be given as an argument.\0A\00"
@.str.2 = [26 x i8] c"Found %lld + %lld = %lld\0A\00"
@.str.3 = [33 x i8] c"Found no elements with sum %lld\0A\00"
@.str.4 = [22 x i8] c"Elapsed: %f seconds.\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@EXIT_SUCCESS = global i32 0
@str = [25 x i8] c"------ Begin 2Sum ------\00"
@str.6 = [25 x i8] c"------- End 2Sum -------\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i64*
%5 = alloca i64
%6 = alloca [128 x i8]
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%8 = bitcast i32* %3 to i8*
%9 = bitcast i64** %4 to i8*
%10 = bitcast i64* %5 to i8*
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%12 = icmp eq i32 %0, 1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = tail call i32 @err(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @readVectorFromFile(i64** %4, i32* %3, i64* %5, i8* %17, i8* %11)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @err(i8* %11)
br label %22
22: ; preds = %20, %15
%23 = call i64 (...) @clock()
%24 = load i64*, i64** %4
%25 = load i32, i32* %3
%26 = add nsw i32 %25, -1
%27 = call i32 @quickSort(i64* %24, i32 0, i32 %26)
%28 = load i32, i32* %3
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %60
30: ; preds = %22, %45
%31 = phi i32 [ %46, %45 ], [ %28, %22 ]
%32 = phi i64 [ %47, %45 ], [ 0, %22 ]
%33 = load i64*, i64** %4
%34 = getelementptr inbounds i64, i64* %33, i64 %32
%35 = load i64, i64* %34
%36 = load i64, i64* %5
%37 = sub nsw i64 %36, %35
%38 = icmp eq i64 %35, %37
br i1 %38, label %45, label %39
39: ; preds = %30
%40 = add nsw i32 %31, -1
%41 = call i32 @binarySearch(i64* %33, i32 0, i32 %40, i64 %37)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %50
43: ; preds = %39
%44 = load i32, i32* %3
br label %45
45: ; preds = %43, %30
%46 = phi i32 [ %44, %43 ], [ %31, %30 ]
%47 = add nuw nsw i64 %32, 1
%48 = sext i32 %46 to i64
%49 = icmp slt i64 %47, %48
br i1 %49, label %30, label %60
50: ; preds = %39
%51 = and i64 %32, 4294967295
%52 = load i64*, i64** %4
%53 = getelementptr inbounds i64, i64* %52, i64 %51
%54 = load i64, i64* %53
%55 = load i64, i64* %5
%56 = sub nsw i64 %55, %54
%57 = call i64 (...) @clock()
%58 = load i64, i64* %5
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i64 %54, i64 %56, i64 %58)
br label %64
60: ; preds = %45, %22
%61 = call i64 (...) @clock()
%62 = load i64, i64* %5
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i64 %62)
br label %64
64: ; preds = %60, %50
%65 = phi i64 [ %61, %60 ], [ %57, %50 ]
%66 = load i64*, i64** %4
%67 = call i32 @free(i64* %66)
%68 = sub nsw i64 %65, %23
%69 = sitofp i64 %68 to double
%70 = load double, double* @CLOCKS_PER_SEC
%71 = fdiv double %69, %70
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), double %71)
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0))
%74 = load i32, i32* @EXIT_SUCCESS
ret i32 %74
}