#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sumfile(int, char *);
int main(int argc, char **argv) {
  if (argc < 2) {
    sumfile(0, "-");
    return 0;
  }
  for (int i = 1; i < argc; i++) {
    int fd = open(argv[1], O_RDONLY);
    if (fd == -1) {
      printf("Unable to open %s\n", argv[i]);
      exit(1);
    }
    sumfile(fd, argv[i]);
    close(fd);
  }
  return 0;
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    118a <main+0x3a>
xor    %edi,%edi
lea    0xe87(%rip),%rsi
call   1060 <sumfile@plt>
movl   $0x0,-0x4(%rbp)
jmp    1213 <main+0xc3>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    120c <main+0xbc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11e2 <main+0x92>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <sumfile@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1191 <main+0x41>
movl   $0x0,-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
cmp    $0x2,%edi
jge    116d <main+0x1d>
lea    0xe9c(%rip),%rsi
xor    %edi,%edi
call   1060 <sumfile@plt>
jmp    11af <main+0x5f>
mov    %rsi,%r15
mov    %edi,%r14d
mov    $0x1,%ebx
mov    0x2e69(%rip),%r12
nop
mov    0x8(%r15),%rdi
mov    (%r12),%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11ba <main+0x6a>
mov    %eax,%ebp
mov    (%r15,%rbx,8),%rsi
mov    %eax,%edi
call   1060 <sumfile@plt>
mov    %ebp,%edi
call   1040 <close@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1180 <main+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r15,%rbx,8),%rsi
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"Unable to open %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @sumfile(i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %47
12: ; preds = %2
store i32 1, i32* %6
br label %13
13: ; preds = %43, %12
%14 = load i32, i32* %6
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %46
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %33
25: ; preds = %17
%26 = load i8**, i8*** %5
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %17
%34 = load i32, i32* %7
%35 = load i8**, i8*** %5
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
%39 = load i8*, i8** %38
%40 = call i32 @sumfile(i32 %34, i8* %39)
%41 = load i32, i32* %7
%42 = call i32 @close(i32 %41)
br label %43
43: ; preds = %33
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %13
46: ; preds = %13
store i32 0, i32* %3
br label %47
47: ; preds = %46, %10
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"Unable to open %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = zext i32 %0 to i64
br label %9
7: ; preds = %2
%8 = tail call i32 @sumfile(i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %28
9: ; preds = %4, %21
%10 = phi i64 [ 1, %4 ], [ %26, %21 ]
%11 = load i8*, i8** %5
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %21
15: ; preds = %9
%16 = and i64 %10, 4294967295
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
%19 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %9
%22 = getelementptr inbounds i8*, i8** %1, i64 %10
%23 = load i8*, i8** %22
%24 = tail call i32 @sumfile(i32 %13, i8* %23)
%25 = tail call i32 @close(i32 %13)
%26 = add nuw nsw i64 %10, 1
%27 = icmp eq i64 %26, %6
br i1 %27, label %28, label %9
28: ; preds = %21, %7
ret i32 0
}