#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_SUCCESS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
char *get_current_dir_name();
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (2 < argc) {
    printf("-1\n");
    exit(EXIT_SUCCESS);
  }
  char *path = argv[1];
  FILE *in = fopen(path, "r");
  if (NULL == in) {
    printf("%s\npath: %s\n current dir: %s\n", strerror(errno), argv[1],
           get_current_dir_name());
    exit(EXIT_SUCCESS);
  }
  unsigned n;
  fscanf(in, "%u", &n);
  long long sum = 0;
  for (unsigned i = 0; i < n; ++i) {
    int current;
    fscanf(in, "%d", &current);
    sum += current;
  }
  printf("%lld\n", sum);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jge    11a0 <main+0x40>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1218 <main+0xb8>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1050 <get_current_dir_name@plt>
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xe01(%rip),%rsi
lea    -0x24(%rbp),%rdx
mov    $0x0,%al
call   1040 <fscanf@plt>
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    1279 <main+0x119>
mov    -0x20(%rbp),%rdi
lea    0xdd3(%rip),%rsi
lea    -0x38(%rbp),%rdx
mov    $0x0,%al
call   1040 <fscanf@plt>
movslq -0x38(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    123d <main+0xdd>
mov    -0x30(%rbp),%rsi
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jl     1192 <main+0x22>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
jmp    1252 <main+0xe2>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe60(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    11df <main+0x6f>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%r14
mov    0x8(%rbx),%rbx
xor    %eax,%eax
call   1060 <get_current_dir_name@plt>
lea    0xe35(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1252 <main+0xe2>
mov    %rax,%r14
lea    0xe37(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1050 <fscanf@plt>
cmpl   $0x0,0x8(%rsp)
jne    1203 <main+0x93>
xor    %ebx,%ebx
jmp    1241 <main+0xd1>
lea    0xe19(%rip),%r15
lea    0xc(%rsp),%r12
xor    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
movslq 0xc(%rsp),%rax
add    %rax,%rbx
add    $0x1,%ebp
cmp    0x8(%rsp),%ebp
jb     1220 <main+0xb0>
lea    0xdde(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"-1\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"%s\0Apath: %s\0A current dir: %s\0A\00"
@errno = global i32 0
@.str.3 = [3 x i8] c"%u\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [6 x i8] c"%lld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 2, %12
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_SUCCESS
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %7
%24 = load i32*, i32** %7
%25 = icmp eq i32* null, %24
br i1 %25, label %26, label %36
26: ; preds = %18
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i8* (...) @get_current_dir_name()
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %28, i8* %31, i8* %32)
%34 = load i32, i32* @EXIT_SUCCESS
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %18
%37 = load i32*, i32** %7
%38 = call i32 (i32*, i8*, ...) @fscanf(i32* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %8)
store i64 0, i64* %9
store i32 0, i32* %10
br label %39
39: ; preds = %50, %36
%40 = load i32, i32* %10
%41 = load i32, i32* %8
%42 = icmp ult i32 %40, %41
br i1 %42, label %43, label %53
43: ; preds = %39
%44 = load i32*, i32** %7
%45 = call i32 (i32*, i8*, ...) @fscanf(i32* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %11)
%46 = load i32, i32* %11
%47 = sext i32 %46 to i64
%48 = load i64, i64* %9
%49 = add nsw i64 %48, %47
store i64 %49, i64* %9
br label %50
50: ; preds = %43
%51 = load i32, i32* %10
%52 = add i32 %51, 1
store i32 %52, i32* %10
br label %39
53: ; preds = %39
%54 = load i64, i64* %9
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i64 %54)
%56 = load i32, i32* @EXIT_SUCCESS
%57 = call i32 @exit(i32 %56)
unreachable
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"%s\0Apath: %s\0A current dir: %s\0A\00"
@errno = global i32 0
@.str.3 = [3 x i8] c"%u\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [6 x i8] c"%lld\0A\00"
@str = [3 x i8] c"-1\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = icmp sgt i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_SUCCESS
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %23
15: ; preds = %10
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = load i8*, i8** %11
%19 = tail call i8* (...) @get_current_dir_name()
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %17, i8* %18, i8* %19)
%21 = load i32, i32* @EXIT_SUCCESS
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %10
%24 = bitcast i32* %3 to i8*
%25 = call i32 (i32*, i8*, ...) @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%26 = load i32, i32* %3
%27 = icmp eq i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %23
%29 = bitcast i32* %4 to i8*
br label %35
30: ; preds = %35, %23
%31 = phi i64 [ 0, %23 ], [ %41, %35 ]
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i64 %31)
%33 = load i32, i32* @EXIT_SUCCESS
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %28, %35
%36 = phi i32 [ 0, %28 ], [ %42, %35 ]
%37 = phi i64 [ 0, %28 ], [ %41, %35 ]
%38 = call i32 (i32*, i8*, ...) @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = add nsw i64 %37, %40
%42 = add nuw i32 %36, 1
%43 = load i32, i32* %3
%44 = icmp ult i32 %42, %43
br i1 %44, label %35, label %30
}