#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 EOF;
int getchar();
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ putchar(int);
int main(void) {
  char sum = -1;
  int c;
  while ((c = getchar()) != EOF) {
    putchar(c);
    sum += c;
    if (c == '\n') {
      printf("\n\tSum is %d.\n", sum);
      sum = -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0xff,-0x5(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e94(%rip),%rcx
cmp    (%rcx),%eax
je     1193 <main+0x63>
mov    -0xc(%rbp),%edi
call   1030 <putchar@plt>
mov    -0xc(%rbp),%ecx
movsbl -0x5(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x5(%rbp)
cmpl   $0xa,-0xc(%rbp)
jne    118e <main+0x5e>
lea    0xe7f(%rip),%rdi
movsbl -0x5(%rbp),%esi
call   1040 <printf@plt>
movb   $0xff,-0x5(%rbp)
jmp    1143 <main+0x13>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2ea3(%rip),%r15
cmp    (%r15),%eax
jne    1157 <main+0x27>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
mov    $0xffffffff,%ebx
lea    0xe9b(%rip),%r14
jmp    117e <main+0x4e>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
je     114a <main+0x1a>
mov    %ebp,%edi
call   1030 <putchar@plt>
movsbl %bl,%ebx
add    %ebp,%ebx
cmp    $0xa,%ebp
jne    1170 <main+0x40>
movsbl %bl,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%ebx
jmp    1170 <main+0x40>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [14 x i8] c"\0A\09Sum is %d.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
store i32 0, i32* %1
store i8 -1, i8* %2
br label %4
4: ; preds = %21, %0
%5 = call i32 (...) @getchar()
store i32 %5, i32* %3
%6 = load i32, i32* @EOF
%7 = icmp ne i32 %5, %6
br i1 %7, label %8, label %22
8: ; preds = %4
%9 = load i32, i32* %3
%10 = call i32 @putchar(i32 %9)
%11 = load i32, i32* %3
%12 = load i8, i8* %2
%13 = sext i8 %12 to i32
%14 = add nsw i32 %13, %11
%15 = trunc i32 %14 to i8
store i8 %15, i8* %2
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 10
br i1 %17, label %18, label %21
18: ; preds = %8
%19 = load i8, i8* %2
%20 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8 signext %19)
store i8 -1, i8* %2
br label %21
21: ; preds = %18, %8
br label %4
22: ; preds = %4
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [14 x i8] c"\0A\09Sum is %d.\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @EOF
%3 = icmp eq i32 %1, %2
br i1 %3, label %20, label %4
4: ; preds = %0, %15
%5 = phi i32 [ %17, %15 ], [ %1, %0 ]
%6 = phi i32 [ %16, %15 ], [ -1, %0 ]
%7 = tail call i32 @putchar(i32 %5)
%8 = shl i32 %6, 24
%9 = ashr exact i32 %8, 24
%10 = add nsw i32 %9, %5
%11 = icmp eq i32 %5, 10
br i1 %11, label %12, label %15
12: ; preds = %4
%13 = trunc i32 %10 to i8
%14 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8 signext %13)
br label %15
15: ; preds = %12, %4
%16 = phi i32 [ -1, %12 ], [ %10, %4 ]
%17 = tail call i32 (...) @getchar()
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %4
20: ; preds = %15, %0
ret i32 0
}