#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 EOF;
int /*<<< orphan*/ *efopen(char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int total_file(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int total = 0;
  int error;
  int verbose = 0;
  int ch;
  extern int optind;
  extern int getopt();
  error = 0;
  while ((ch = getopt(argc, argv, "vh")) != EOF) {
    switch (ch) {
    case 'v':
      verbose = 1;
      break;
    case 'h':
      fprintf(stderr, "usage: total [-vh] [files ...]\n");
      fprintf(stderr, "-v means talk a lot\n");
      fprintf(stderr, "-h means print this help\n");
      exit(0);
    case '?':
    default:
      error = 1;
      break;
    }
  }
  if (error) {
    fprintf(stderr, "usage: total [-vh] [files ...]\n");
    fprintf(stderr, "-v means talk a lot\n");
    fprintf(stderr, "-h means print this help\n");
    exit(1);
  }
  if (argc > optind) {
    int i;
    for (i = optind; i < argc; i++) {
      FILE *f;
      int count;
      f = efopen(argv[i], "r");
      count = total_file(f);
      if (verbose) {
        printf("%d %s\n", count, argv[i]);
      }
      total += count;
      fclose(f);
    }
    printf("%d\n", total);
  } else {
    printf("%d\n", total_file(stdin));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe57(%rip),%rdx
mov    $0x0,%al
call   1080 <getopt@plt>
mov    %eax,-0x20(%rbp)
mov    0x2e26(%rip),%rcx
cmp    (%rcx),%eax
je     125b <main+0xeb>
mov    -0x20(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x3f,%eax
je     124a <main+0xda>
jmp    11d6 <main+0x66>
mov    -0x38(%rbp),%eax
sub    $0x68,%eax
je     1204 <main+0x94>
jmp    11e7 <main+0x77>
mov    -0x38(%rbp),%eax
sub    $0x76,%eax
jne    124f <main+0xdf>
jmp    11f8 <main+0x88>
movl   $0x1,-0x1c(%rbp)
jmp    1256 <main+0xe6>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
call   1070 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    124f <main+0xdf>
movl   $0x1,-0x18(%rbp)
jmp    119b <main+0x2b>
cmpl   $0x0,-0x18(%rbp)
je     12ae <main+0x13e>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
lea    0xd8e(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
lea    0xd99(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
lea    0xd99(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%eax
mov    0x2d10(%rip),%rcx
cmp    (%rcx),%eax
jle    135d <main+0x1ed>
mov    0x2d01(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1347 <main+0x1d7>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd67(%rip),%rsi
call   1060 <efopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <total_file@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1327 <main+0x1b7>
mov    -0x34(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x34(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12cc <main+0x15c>
mov    -0x14(%rbp),%esi
lea    0xd0a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    137c <main+0x20c>
mov    0x2c84(%rip),%rax
mov    (%rax),%rdi
call   1030 <total_file@plt>
mov    %eax,%esi
lea    0xce6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe79(%rip),%rdx
xor    %ebp,%ebp
xor    %eax,%eax
call   1080 <getopt@plt>
mov    0x2e49(%rip),%r12
cmp    (%r12),%eax
je     121f <main+0xaf>
lea    0xe58(%rip),%r13
xor    %r15d,%r15d
xor    %ecx,%ecx
jmp    11cf <main+0x5f>
nop
mov    $0x1,%r15d
mov    %ecx,%ebp
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1080 <getopt@plt>
mov    %ebp,%ecx
cmp    (%r12),%eax
je     1216 <main+0xa6>
mov    $0x1,%ebp
cmp    $0x76,%eax
je     11b8 <main+0x48>
cmp    $0x68,%eax
jne    11b0 <main+0x40>
mov    0x2deb(%rip),%rbx
mov    (%rbx),%edi
lea    0xe15(%rip),%rsi
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe27(%rip),%rsi
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe2e(%rip),%rsi
call   1070 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
test   %r15d,%r15d
jne    12c5 <main+0x155>
mov    0x2da2(%rip),%rax
movslq (%rax),%rax
cmp    %ebx,%eax
jge    1293 <main+0x123>
mov    %ebp,0x4(%rsp)
lea    (%r14,%rax,8),%r15
sub    %eax,%ebx
xor    %r12d,%r12d
xor    %ebp,%ebp
jmp    1256 <main+0xe6>
xchg   %ax,%ax
add    %ebx,%ebp
mov    %r13,%rdi
call   1040 <fclose@plt>
add    $0x1,%r12
mov    %r14,%rbx
cmp    %r12d,%ebx
je     12a4 <main+0x134>
mov    %rbx,%r14
mov    (%r15,%r12,8),%rdi
lea    0xdee(%rip),%rsi
call   1060 <efopen@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1030 <total_file@plt>
mov    %eax,%ebx
cmpl   $0x0,0x4(%rsp)
je     1240 <main+0xd0>
mov    (%r15,%r12,8),%rdx
lea    0xdcc(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1240 <main+0xd0>
mov    0x2d4e(%rip),%rax
mov    (%rax),%rdi
call   1030 <total_file@plt>
mov    %eax,%ebp
lea    0xdb0(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d04(%rip),%rbx
mov    (%rbx),%edi
lea    0xd2e(%rip),%rsi
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd40(%rip),%rsi
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd47(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"vh\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"usage: total [-vh] [files ...]\0A\00"
@.str.2 = [21 x i8] c"-v means talk a lot\0A\00"
@.str.3 = [26 x i8] c"-h means print this help\0A\00"
@optind = external global i32
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [7 x i8] c"%d %s\0A\00"
@.str.6 = [4 x i8] c"%d\0A\00"
@stdin = global i32* null
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 i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %8
store i32 0, i32* %7
br label %13
13: ; preds = %32, %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 (i32, i8**, i8*, ...) bitcast (i32 (...)* @getopt to i32 (i32, i8**, i8*, ...)*)(i32 %14, i8** %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %9
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %33
19: ; preds = %13
%20 = load i32, i32* %9
switch i32 %20, label %31 [
i32 118, label %21
i32 104, label %22
i32 63, label %30
]
21: ; preds = %19
store i32 1, i32* %8
br label %32
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %19
br label %31
31: ; preds = %19, %30
store i32 1, i32* %7
br label %32
32: ; preds = %31, %21
br label %13
33: ; preds = %13
%34 = load i32, i32* %7
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %44
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %33
%45 = load i32, i32* %4
%46 = load i32, i32* @optind
%47 = icmp sgt i32 %45, %46
br i1 %47, label %48, label %85
48: ; preds = %44
%49 = load i32, i32* @optind
store i32 %49, i32* %10
br label %50
50: ; preds = %79, %48
%51 = load i32, i32* %10
%52 = load i32, i32* %4
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %82
54: ; preds = %50
%55 = load i8**, i8*** %5
%56 = load i32, i32* %10
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = load i8*, i8** %58
%60 = call i32* @efopen(i8* %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %60, i32** %11
%61 = load i32*, i32** %11
%62 = call i32 @total_file(i32* %61)
store i32 %62, i32* %12
%63 = load i32, i32* %8
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %73
65: ; preds = %54
%66 = load i32, i32* %12
%67 = load i8**, i8*** %5
%68 = load i32, i32* %10
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8*, i8** %67, i64 %69
%71 = load i8*, i8** %70
%72 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %66, i8* %71)
br label %73
73: ; preds = %65, %54
%74 = load i32, i32* %12
%75 = load i32, i32* %6
%76 = add nsw i32 %75, %74
store i32 %76, i32* %6
%77 = load i32*, i32** %11
%78 = call i32 @fclose(i32* %77)
br label %79
79: ; preds = %73
%80 = load i32, i32* %10
%81 = add nsw i32 %80, 1
store i32 %81, i32* %10
br label %50
82: ; preds = %50
%83 = load i32, i32* %6
%84 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %83)
br label %89
85: ; preds = %44
%86 = load i32*, i32** @stdin
%87 = call i32 @total_file(i32* %86)
%88 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %87)
br label %89
89: ; preds = %85, %82
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"vh\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"usage: total [-vh] [files ...]\0A\00"
@.str.2 = [21 x i8] c"-v means talk a lot\0A\00"
@.str.3 = [26 x i8] c"-h means print this help\0A\00"
@optind = external global i32
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [7 x i8] c"%d %s\0A\00"
@.str.6 = [4 x i8] c"%d\0A\00"
@stdin = global i32* null
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 (i32, i8**, i8*, ...) bitcast (i32 (...)* @getopt to i32 (i32, i8**, i8*, ...)*)(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %35, label %6
6: ; preds = %2, %19
%7 = phi i32 [ %22, %19 ], [ %3, %2 ]
%8 = phi i32 [ %21, %19 ], [ 0, %2 ]
%9 = phi i32 [ %20, %19 ], [ 0, %2 ]
switch i32 %7, label %18 [
i32 118, label %19
i32 104, label %10
]
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%17 = tail call i32 @exit(i32 0)
unreachable
18: ; preds = %6
br label %19
19: ; preds = %6, %18
%20 = phi i32 [ %9, %18 ], [ 1, %6 ]
%21 = phi i32 [ 1, %18 ], [ %8, %6 ]
%22 = tail call i32 (i32, i8**, i8*, ...) bitcast (i32 (...)* @getopt to i32 (i32, i8**, i8*, ...)*)(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %6
25: ; preds = %19
%26 = icmp eq i32 %21, 0
br i1 %26, label %35, label %27
27: ; preds = %25
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %2, %25
%36 = phi i32 [ %20, %25 ], [ 0, %2 ]
%37 = load i32, i32* @optind
%38 = icmp slt i32 %37, %0
br i1 %38, label %39, label %58
39: ; preds = %35
%40 = icmp eq i32 %36, 0
%41 = sext i32 %37 to i64
br label %42
42: ; preds = %39, %52
%43 = phi i64 [ %41, %39 ], [ %55, %52 ]
%44 = phi i32 [ 0, %39 ], [ %53, %52 ]
%45 = getelementptr inbounds i8*, i8** %1, i64 %43
%46 = load i8*, i8** %45
%47 = tail call i32* @efopen(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%48 = tail call i32 @total_file(i32* %47)
br i1 %40, label %52, label %49
49: ; preds = %42
%50 = load i8*, i8** %45
%51 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %48, i8* %50)
br label %52
52: ; preds = %49, %42
%53 = add nsw i32 %48, %44
%54 = tail call i32 @fclose(i32* %47)
%55 = add nsw i64 %43, 1
%56 = trunc i64 %55 to i32
%57 = icmp eq i32 %56, %0
br i1 %57, label %61, label %42
58: ; preds = %35
%59 = load i32*, i32** @stdin
%60 = tail call i32 @total_file(i32* %59)
br label %61
61: ; preds = %52, %58
%62 = phi i32 [ %60, %58 ], [ %53, %52 ]
%63 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %62)
ret i32 0
}