#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fptr;
  int val;
  int sum = 0;
  if (argc < 2) {
    printf("Need to provide the file's name.\n");
    return EXIT_FAILURE;
  }
  fptr = fopen(argv[1], "r");
  if (fptr == NULL) {
    printf("fopen fail.\n");
    return EXIT_FAILURE;
  }
  printf("The name of the file is %s.\n", argv[1]);
  while (fscanf(fptr, "%d", &val) == 1) {
    printf("%d ", val);
    sum += val;
  }
  fclose(fptr);
  printf("\nThe sum is %d.\n", sum);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1186 <main+0x46>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1240 <main+0x100>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c8 <main+0x88>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1240 <main+0x100>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe65(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    121a <main+0xda>
mov    -0x1c(%rbp),%esi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11de <main+0x9e>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%esi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jg     116d <main+0x1d>
lea    0xedb(%rip),%rdi
jmp    121d <main+0xcd>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1216 <main+0xc6>
mov    %rax,%rbx
mov    0x8(%rbp),%rsi
lea    0xe6b(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe78(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jne    11f5 <main+0xa5>
lea    0xe62(%rip),%r14
lea    0xe58(%rip),%r15
lea    0xc(%rsp),%r12
xor    %ebp,%ebp
xchg   %ax,%ax
mov    0xc(%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    0xc(%rsp),%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <fscanf@plt>
cmp    $0x1,%eax
je     11d0 <main+0x80>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe22(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2dc4(%rip),%rax
jmp    1229 <main+0xd9>
lea    0xe1a(%rip),%rdi
call   1030 <puts@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Need to provide the file's name.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"fopen fail.\0A\00"
@.str.3 = [29 x i8] c"The name of the file is %s.\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [4 x i8] c"%d \00"
@.str.6 = [17 x i8] c"\0AThe sum is %d.\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %3
br label %45
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
store i32 %23, i32* %3
br label %45
24: ; preds = %14
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %33, %24
%30 = load i32*, i32** %6
%31 = call i32 @fscanf(i32* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %7)
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = load i32, i32* %7
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %7
%37 = load i32, i32* %8
%38 = add nsw i32 %37, %36
store i32 %38, i32* %8
br label %29
39: ; preds = %29
%40 = load i32*, i32** %6
%41 = call i32 @fclose(i32* %40)
%42 = load i32, i32* %8
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %42)
%44 = load i32, i32* @EXIT_SUCCESS
store i32 %44, i32* %3
br label %45
45: ; preds = %39, %21, %11
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [29 x i8] c"The name of the file is %s.\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [4 x i8] c"%d \00"
@.str.6 = [17 x i8] c"\0AThe sum is %d.\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [12 x i8] c"fopen fail.\00"
@str.7 = [33 x i8] c"Need to provide the file's name.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.7, i64 0, i64 0))
br label %32
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %32
15: ; preds = %8
%16 = load i8*, i8** %9
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%18 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %28
20: ; preds = %15, %20
%21 = phi i32 [ %25, %20 ], [ 0, %15 ]
%22 = load i32, i32* %3
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %3
%25 = add nsw i32 %24, %21
%26 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%27 = icmp eq i32 %26, 1
br i1 %27, label %20, label %28
28: ; preds = %20, %15
%29 = phi i32 [ 0, %15 ], [ %25, %20 ]
%30 = call i32 @fclose(i32* %11)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %29)
br label %32
32: ; preds = %28, %13, %6
%33 = phi i32* [ @EXIT_FAILURE, %6 ], [ @EXIT_FAILURE, %13 ], [ @EXIT_SUCCESS, %28 ]
%34 = load i32, i32* %33
ret i32 %34
}