#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 */
long BUFSIZ;
int EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int main(int argc, const char *argv[]) {
  register unsigned sum;
  register int i, c;
  register FILE *f;
  register long nbytes;
  int errflg = 0;
  i = 1;
  do {
    if (i < argc) {
      if ((f = fopen(argv[i], "r")) == NULL) {
        fprintf(stderr, "sum: Can't open %s\n", argv[i]);
        errflg += 10;
        continue;
      }
    } else
      f = stdin;
    sum = 0;
    nbytes = 0;
    while ((c = getc(f)) != EOF) {
      nbytes++;
      if (sum & 01)
        sum = (sum >> 1) + 0x8000;
      else
        sum >>= 1;
      sum += c;
      sum &= 0xFFFF;
    }
    if (ferror(f)) {
      errflg++;
      fprintf(stderr, "sum: read error on %s\n",
              argc > 1 ? argv[i] : (const char *)"-");
    }
    printf("%05u%6ld", sum, (nbytes + BUFSIZ - 1) / BUFSIZ);
    if (argc > 2)
      printf(" %s", argv[i]);
    printf("\n");
    fclose(f);
  } while (++i < argc);
  exit(errflg);
}


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,-0x34(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11fa <main+0x8a>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe4d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11f5 <main+0x85>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe20(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x34(%rbp)
jmp    1359 <main+0x1e9>
jmp    1208 <main+0x98>
mov    0x2de7(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2db6(%rip),%rcx
cmp    (%rcx),%eax
je     1282 <main+0x112>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1260 <main+0xf0>
mov    -0x14(%rbp),%eax
shr    $0x1,%eax
add    $0x8000,%eax
mov    %eax,-0x14(%rbp)
jmp    1269 <main+0xf9>
mov    -0x14(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0xffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1217 <main+0xa7>
mov    -0x28(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12ec <main+0x17c>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    0x2d2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    12c9 <main+0x159>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
jmp    12d9 <main+0x169>
lea    0xd5d(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    12d9 <main+0x169>
mov    -0x38(%rbp),%edi
mov    -0x40(%rbp),%rdx
lea    0xd2f(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%rax
mov    0x2cce(%rip),%rcx
add    (%rcx),%rax
sub    $0x1,%rax
mov    0x2cc0(%rip),%rcx
cqto
idivq  (%rcx)
mov    %rax,%rdx
lea    0xd18(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
jle    1342 <main+0x1d2>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xcfd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xccb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmp    -0x8(%rbp),%eax
jl     1194 <main+0x24>
mov    -0x34(%rbp),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,0x10(%rsp)
movslq %edi,%rax
mov    %rax,0x20(%rsp)
cmp    $0x3,%eax
mov    $0x2,%eax
mov    %edi,0xc(%rsp)
cmovge %edi,%eax
mov    %rax,0x18(%rsp)
mov    $0x1,%r12d
mov    0x2e24(%rip),%rbp
xor    %r13d,%r13d
jmp    11f1 <main+0x71>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
add    $0x1,%r12
cmp    0x18(%rsp),%r12
je     133e <main+0x1be>
cmp    0x20(%rsp),%r12
jge    1240 <main+0xc0>
mov    0x10(%rsp),%rax
mov    (%rax,%r12,8),%rdi
lea    0xdf8(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    124a <main+0xca>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rsp),%rax
mov    (%rax,%r12,8),%rdx
lea    0xdd4(%rip),%rsi
call   1070 <fprintf@plt>
add    $0xa,%r13d
jmp    11e2 <main+0x62>
nopl   0x0(%rax)
mov    0x2da1(%rip),%rax
mov    (%rax),%r14
mov    %r14,%rdi
call   10a0 <getc@plt>
cmp    0x0(%rbp),%eax
jne    1260 <main+0xe0>
xor    %r15d,%r15d
xor    %ebx,%ebx
jmp    1294 <main+0x114>
xchg   %ax,%ax
xor    %ebx,%ebx
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
mov    %r15d,%ecx
shr    %ecx
shl    $0xf,%r15d
or     %ecx,%r15d
add    %eax,%r15d
movzwl %r15w,%r15d
mov    %r14,%rdi
call   10a0 <getc@plt>
cmp    0x0(%rbp),%eax
jne    1270 <main+0xf0>
mov    %r14,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     12d1 <main+0x151>
lea    0xd85(%rip),%rdx
cmpl   $0x2,0xc(%rsp)
jl     12b8 <main+0x138>
mov    0x10(%rsp),%rax
mov    (%rax,%r12,8),%rdx
add    $0x1,%r13d
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
lea    0xd4a(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%rcx
lea    (%rbx,%rcx,1),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     1300 <main+0x180>
cqto
idiv   %rcx
mov    %rax,%rdx
jmp    1306 <main+0x186>
nopl   0x0(%rax)
xor    %edx,%edx
div    %ecx
mov    %eax,%edx
lea    0xd22(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x3,0xc(%rsp)
jl     11d0 <main+0x50>
mov    0x10(%rsp),%rax
mov    (%rax,%r12,8),%rsi
lea    0xd06(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11d0 <main+0x50>
mov    %r13d,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"sum: Can't open %s\0A\00"
@stdin = global i32* null
@EOF = global i32 0
@.str.2 = [23 x i8] c"sum: read error on %s\0A\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [9 x i8] c"%05u%6ld\00"
@BUFSIZ = global i64 0
@.str.5 = [4 x i8] c" %s\00"
@.str.6 = [2 x i8] c"\0A\00"
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 i64
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
store i32 1, i32* %7
br label %12
12: ; preds = %104, %2
%13 = load i32, i32* %7
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %35
16: ; preds = %12
%17 = load i8**, i8*** %5
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %9
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %34
24: ; preds = %16
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i32, i32* %11
%33 = add nsw i32 %32, 10
store i32 %33, i32* %11
br label %104
34: ; preds = %16
br label %37
35: ; preds = %12
%36 = load i32*, i32** @stdin
store i32* %36, i32** %9
br label %37
37: ; preds = %35, %34
store i32 0, i32* %6
store i64 0, i64* %10
br label %38
38: ; preds = %56, %37
%39 = load i32*, i32** %9
%40 = call i32 @getc(i32* %39)
store i32 %40, i32* %8
%41 = load i32, i32* @EOF
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %62
43: ; preds = %38
%44 = load i64, i64* %10
%45 = add nsw i64 %44, 1
store i64 %45, i64* %10
%46 = load i32, i32* %6
%47 = and i32 %46, 1
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %43
%50 = load i32, i32* %6
%51 = lshr i32 %50, 1
%52 = add i32 %51, 32768
store i32 %52, i32* %6
br label %56
53: ; preds = %43
%54 = load i32, i32* %6
%55 = lshr i32 %54, 1
store i32 %55, i32* %6
br label %56
56: ; preds = %53, %49
%57 = load i32, i32* %8
%58 = load i32, i32* %6
%59 = add i32 %58, %57
store i32 %59, i32* %6
%60 = load i32, i32* %6
%61 = and i32 %60, 65535
store i32 %61, i32* %6
br label %38
62: ; preds = %38
%63 = load i32*, i32** %9
%64 = call i64 @ferror(i32* %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %82
66: ; preds = %62
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
%69 = load i32, i32* @stderr
%70 = load i32, i32* %4
%71 = icmp sgt i32 %70, 1
br i1 %71, label %72, label %78
72: ; preds = %66
%73 = load i8**, i8*** %5
%74 = load i32, i32* %7
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8*, i8** %73, i64 %75
%77 = load i8*, i8** %76
br label %79
78: ; preds = %66
br label %79
79: ; preds = %78, %72
%80 = phi i8* [ %77, %72 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), %78 ]
%81 = call i32 @fprintf(i32 %69, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %80)
br label %82
82: ; preds = %79, %62
%83 = load i32, i32* %6
%84 = load i64, i64* %10
%85 = load i64, i64* @BUFSIZ
%86 = add nsw i64 %84, %85
%87 = sub nsw i64 %86, 1
%88 = load i64, i64* @BUFSIZ
%89 = sdiv i64 %87, %88
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %83, i64 %89)
%91 = load i32, i32* %4
%92 = icmp sgt i32 %91, 2
br i1 %92, label %93, label %100
93: ; preds = %82
%94 = load i8**, i8*** %5
%95 = load i32, i32* %7
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8*, i8** %94, i64 %96
%98 = load i8*, i8** %97
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %98)
br label %100
100: ; preds = %93, %82
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%102 = load i32*, i32** %9
%103 = call i32 @fclose(i32* %102)
br label %104
104: ; preds = %100, %24
%105 = load i32, i32* %7
%106 = add nsw i32 %105, 1
store i32 %106, i32* %7
%107 = load i32, i32* %4
%108 = icmp slt i32 %106, %107
br i1 %108, label %12, label %109
109: ; preds = %104
%110 = load i32, i32* %11
%111 = call i32 @exit(i32 %110)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"sum: Can't open %s\0A\00"
@stdin = global i32* null
@EOF = global i32 0
@.str.2 = [23 x i8] c"sum: read error on %s\0A\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [9 x i8] c"%05u%6ld\00"
@BUFSIZ = global i64 0
@.str.5 = [4 x i8] c" %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
%4 = icmp sgt i32 %0, 2
%5 = sext i32 %0 to i64
%6 = call i32 @llvm.smax.i32(i32 %0, i32 2)
%7 = zext i32 %6 to i64
br label %8
8: ; preds = %70, %2
%9 = phi i64 [ %72, %70 ], [ 1, %2 ]
%10 = phi i32 [ %71, %70 ], [ 0, %2 ]
%11 = icmp slt i64 %9, %5
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = getelementptr inbounds i8*, i8** %1, i64 %9
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %24
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %13
%20 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = add nsw i32 %10, 10
br label %70
22: ; preds = %8
%23 = load i32*, i32** @stdin
br label %24
24: ; preds = %12, %22
%25 = phi i32* [ %15, %12 ], [ %23, %22 ]
%26 = tail call i32 @getc(i32* %25)
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %42, label %29
29: ; preds = %24, %29
%30 = phi i32 [ %39, %29 ], [ %26, %24 ]
%31 = phi i64 [ %33, %29 ], [ 0, %24 ]
%32 = phi i32 [ %38, %29 ], [ 0, %24 ]
%33 = add nuw nsw i64 %31, 1
%34 = lshr i32 %32, 1
%35 = shl nuw nsw i32 %32, 15
%36 = or i32 %35, %34
%37 = add i32 %36, %30
%38 = and i32 %37, 65535
%39 = tail call i32 @getc(i32* %25)
%40 = load i32, i32* @EOF
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %29
42: ; preds = %29, %24
%43 = phi i32 [ 0, %24 ], [ %38, %29 ]
%44 = phi i64 [ 0, %24 ], [ %33, %29 ]
%45 = tail call i64 @ferror(i32* %25)
%46 = icmp eq i64 %45, 0
br i1 %46, label %56, label %47
47: ; preds = %42
%48 = add nsw i32 %10, 1
%49 = load i32, i32* @stderr
br i1 %3, label %50, label %53
50: ; preds = %47
%51 = getelementptr inbounds i8*, i8** %1, i64 %9
%52 = load i8*, i8** %51
br label %53
53: ; preds = %47, %50
%54 = phi i8* [ %52, %50 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), %47 ]
%55 = tail call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %53, %42
%57 = phi i32 [ %48, %53 ], [ %10, %42 ]
%58 = load i64, i64* @BUFSIZ
%59 = add i64 %44, -1
%60 = add i64 %59, %58
%61 = sdiv i64 %60, %58
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %43, i64 %61)
br i1 %4, label %63, label %67
63: ; preds = %56
%64 = getelementptr inbounds i8*, i8** %1, i64 %9
%65 = load i8*, i8** %64
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %65)
br label %67
67: ; preds = %63, %56
%68 = tail call i32 @putchar(i32 10)
%69 = tail call i32 @fclose(i32* %25)
br label %70
70: ; preds = %67, %17
%71 = phi i32 [ %21, %17 ], [ %57, %67 ]
%72 = add nuw nsw i64 %9, 1
%73 = icmp eq i64 %72, %7
br i1 %73, label %74, label %8
74: ; preds = %70
%75 = tail call i32 @exit(i32 %71)
unreachable
}