#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 uint8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ assert(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  uint8_t sum = 0;
  if (argc < 2)
    return EXIT_FAILURE;
  FILE *fp = fopen(argv[1], "r");
  if (fp == NULL)
    return EXIT_FAILURE;
  for (;;) {
    uint8_t buffer;
    size_t bytes_read = fread(&buffer, sizeof(uint8_t), 1, fp);
    if (feof(fp))
      break;
    assert(bytes_read == 1);
    sum += buffer;
  }
  if (ferror(fp))
    return EXIT_FAILURE;
  if (fclose(fp) != 0)
    return EXIT_FAILURE;
  printf("%i\n", sum);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a8 <main+0x38>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1297 <main+0x127>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe49(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11dc <main+0x6c>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1297 <main+0x127>
jmp    11e1 <main+0x71>
mov    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     1214 <main+0xa4>
jmp    1234 <main+0xc4>
cmpq   $0x1,-0x30(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x24(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11e1 <main+0x71>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1258 <main+0xe8>
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1297 <main+0x127>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
cmp    $0x0,%rax
je     127c <main+0x10c>
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1297 <main+0x127>
mov    -0x14(%rbp),%esi
lea    0xd7c(%rip),%rdi
call   1060 <printf@plt>
mov    0x2d46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e5d(%rip),%r12
cmp    $0x2,%edi
jl     1247 <main+0xd7>
mov    0x8(%rsi),%rdi
lea    0xe69(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1247 <main+0xd7>
mov    %rax,%r15
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1080 <feof@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    1218 <main+0xa8>
xor    %ebp,%ebp
lea    0xc(%rsp),%r14
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
cmp    $0x1,%rbx
sete   %dil
call   1070 <assert@plt>
add    0xc(%rsp),%ebp
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1080 <feof@plt>
test   %rax,%rax
je     11e0 <main+0x70>
mov    %r15,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1247 <main+0xd7>
mov    %r15,%rdi
call   1050 <fclose@plt>
test   %rax,%rax
jne    1247 <main+0xd7>
lea    0xdc9(%rip),%rdi
mov    %ebp,%esi
call   1060 <printf@plt>
mov    0x2d91(%rip),%r12
mov    (%r12),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%i\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %3
br label %55
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, i64 0, i64 0))
store i32* %18, i32** %7
%19 = load i32*, i32** %7
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = load i32, i32* @EXIT_FAILURE
store i32 %22, i32* %3
br label %55
23: ; preds = %14
br label %24
24: ; preds = %31, %23
%25 = load i32*, i32** %7
%26 = call i64 @fread(i32* %8, i32 4, i32 1, i32* %25)
store i64 %26, i64* %9
%27 = load i32*, i32** %7
%28 = call i64 @feof(i32* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %24
br label %39
31: ; preds = %24
%32 = load i64, i64* %9
%33 = icmp eq i64 %32, 1
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i32, i32* %8
%37 = load i32, i32* %6
%38 = add nsw i32 %37, %36
store i32 %38, i32* %6
br label %24
39: ; preds = %30
%40 = load i32*, i32** %7
%41 = call i64 @ferror(i32* %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = load i32, i32* @EXIT_FAILURE
store i32 %44, i32* %3
br label %55
45: ; preds = %39
%46 = load i32*, i32** %7
%47 = call i64 @fclose(i32* %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = load i32, i32* @EXIT_FAILURE
store i32 %50, i32* %3
br label %55
51: ; preds = %45
%52 = load i32, i32* %6
%53 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %52)
%54 = load i32, i32* @EXIT_SUCCESS
store i32 %54, i32* %3
br label %55
55: ; preds = %51, %49, %43, %21, %12
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%i\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp slt i32 %0, 2
br i1 %4, label %35, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %35, label %10
10: ; preds = %5
%11 = bitcast i32* %3 to i8*
%12 = call i64 @fread(i32* %3, i32 4, i32 1, i32* %8)
%13 = tail call i64 @feof(i32* %8)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %10, %15
%16 = phi i64 [ %23, %15 ], [ %12, %10 ]
%17 = phi i32 [ %22, %15 ], [ 0, %10 ]
%18 = icmp eq i64 %16, 1
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = load i32, i32* %3
%22 = add nsw i32 %21, %17
%23 = call i64 @fread(i32* %3, i32 4, i32 1, i32* %8)
%24 = tail call i64 @feof(i32* %8)
%25 = icmp eq i64 %24, 0
br i1 %25, label %15, label %26
26: ; preds = %15, %10
%27 = phi i32 [ 0, %10 ], [ %22, %15 ]
%28 = tail call i64 @ferror(i32* %8)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = tail call i64 @fclose(i32* %8)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %35
35: ; preds = %33, %5, %26, %30, %2
%36 = phi i32* [ @EXIT_FAILURE, %2 ], [ @EXIT_SUCCESS, %33 ], [ @EXIT_FAILURE, %5 ], [ @EXIT_FAILURE, %26 ], [ @EXIT_FAILURE, %30 ]
%37 = load i32, i32* %36
ret i32 %37
}