#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 */
char EOF;
int /*<<< orphan*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fp;
  int n = 0;
  char c;
  if (argc != 2) {
    printf("Usage: %s [FILE]\n", argv[0]);
    return 1;
  }
  fp = fopen(*++argv, "r");
  while ((c = getc(fp)) != EOF || n > 0)
    if (c == '\n' || c == EOF) {
      printf("%d\n", n);
      n = 0;
    } else {
      n += c - '0';
    }
  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)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1178 <main+0x48>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1234 <main+0x104>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xe80(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <getc@plt>
mov    %al,-0x1d(%rbp)
movsbl %al,%ecx
mov    0x2e37(%rip),%rax
movsbl (%rax),%edx
mov    $0x1,%al
cmp    %edx,%ecx
mov    %al,-0x1e(%rbp)
jne    11cb <main+0x9b>
cmpl   $0x0,-0x1c(%rbp)
setg   %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
test   $0x1,%al
jne    11db <main+0xab>
jmp    122d <main+0xfd>
movsbl -0x1d(%rbp),%eax
cmp    $0xa,%eax
je     11fe <main+0xce>
movsbl -0x1d(%rbp),%eax
mov    0x2df5(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    121b <main+0xeb>
mov    -0x1c(%rbp),%esi
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
jmp    1228 <main+0xf8>
movsbl -0x1d(%rbp),%eax
sub    $0x30,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    119b <main+0x6b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11c7 <main+0x97>
mov    0x8(%rsi),%rdi
lea    0xec6(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <getc@plt>
mov    0x2e85(%rip),%r12
mov    (%r12),%dl
xor    %ecx,%ecx
cmp    %dl,%al
je     11dd <main+0xad>
xor    %ebx,%ebx
lea    0xe9e(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
cmp    $0xa,%al
je     11a0 <main+0x70>
cmp    %dl,%al
je     11a0 <main+0x70>
movsbl %al,%eax
add    %eax,%ebx
add    $0xffffffd0,%ebx
jmp    11ae <main+0x7e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1050 <getc@plt>
movzbl (%r12),%edx
cmp    %dl,%al
jne    1180 <main+0x50>
test   %ebx,%ebx
jg     1180 <main+0x50>
xor    %ecx,%ecx
jmp    11dd <main+0xad>
mov    (%rsi),%rsi
lea    0xe2f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Usage: %s [FILE]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.2 = [4 x i8] c"%d\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 i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 1, i32* %3
br label %54
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i32 1
store i8** %18, i8*** %5
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
br label %21
21: ; preds = %52, %16
%22 = load i32*, i32** %6
%23 = call signext i8 @getc(i32* %22)
store i8 %23, i8* %8
%24 = sext i8 %23 to i32
%25 = load i8, i8* @EOF
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %24, %26
br i1 %27, label %31, label %28
28: ; preds = %21
%29 = load i32, i32* %7
%30 = icmp sgt i32 %29, 0
br label %31
31: ; preds = %28, %21
%32 = phi i1 [ true, %21 ], [ %30, %28 ]
br i1 %32, label %33, label %53
33: ; preds = %31
%34 = load i8, i8* %8
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 10
br i1 %36, label %43, label %37
37: ; preds = %33
%38 = load i8, i8* %8
%39 = sext i8 %38 to i32
%40 = load i8, i8* @EOF
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %39, %41
br i1 %42, label %43, label %46
43: ; preds = %37, %33
%44 = load i32, i32* %7
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %44)
store i32 0, i32* %7
br label %52
46: ; preds = %37
%47 = load i8, i8* %8
%48 = sext i8 %47 to i32
%49 = sub nsw i32 %48, 48
%50 = load i32, i32* %7
%51 = add nsw i32 %50, %49
store i32 %51, i32* %7
br label %52
52: ; preds = %46, %43
br label %21
53: ; preds = %31
store i32 0, i32* %3
br label %54
54: ; preds = %53, %11
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [18 x i8] c"Usage: %s [FILE]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %34
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call signext i8 @getc(i32* %10)
%12 = load i8, i8* @EOF
%13 = icmp eq i8 %11, %12
br i1 %13, label %34, label %14
14: ; preds = %7, %27
%15 = phi i8 [ %30, %27 ], [ %12, %7 ]
%16 = phi i8 [ %29, %27 ], [ %11, %7 ]
%17 = phi i32 [ %28, %27 ], [ 0, %7 ]
%18 = icmp eq i8 %16, 10
%19 = icmp eq i8 %16, %15
%20 = select i1 %18, i1 true, i1 %19
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %27
23: ; preds = %14
%24 = sext i8 %16 to i32
%25 = add i32 %17, -48
%26 = add i32 %25, %24
br label %27
27: ; preds = %23, %21
%28 = phi i32 [ 0, %21 ], [ %26, %23 ]
%29 = tail call signext i8 @getc(i32* %10)
%30 = load i8, i8* @EOF
%31 = icmp ne i8 %29, %30
%32 = icmp sgt i32 %28, 0
%33 = select i1 %31, i1 true, i1 %32
br i1 %33, label %14, label %34
34: ; preds = %27, %7, %4
%35 = phi i32 [ 1, %4 ], [ 0, %7 ], [ 0, %27 ]
ret i32 %35
}