#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 getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(int);
int main() {
  int add, sum;
  sum = 0;
  printf("Enter an abitrarily long string, ending with carriage return > ");
  while (add != '\n') {
    add = getchar();
    if (add != '\n')
      sum = add + sum;
  }
  sum = sum - 32;
  printf("Check sum is ");
  putchar(sum);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeb3(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0xa,-0x8(%rbp)
je     117e <main+0x4e>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
je     1179 <main+0x49>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1152 <main+0x22>
mov    -0xc(%rbp),%eax
sub    $0x20,%eax
mov    %eax,-0xc(%rbp)
lea    0xeb2(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1030 <putchar@plt>
lea    0xeac(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xec6(%rip),%rdi
call   1040 <printf@plt>
xor    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%eax
mov    %eax,%ecx
cmove  %ebp,%ecx
add    %ecx,%ebx
cmp    $0xa,%eax
jne    1150 <main+0x20>
add    $0xffffffe0,%ebx
lea    0xed0(%rip),%rdi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [64 x i8] c"Enter an abitrarily long string, ending with carriage return > \00"
@.str.1 = [14 x i8] c"Check sum is \00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%4 = call i32 @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %16, %0
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 10
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = call i32 (...) @getchar()
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 10
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = add nsw i32 %13, %14
store i32 %15, i32* %3
br label %16
16: ; preds = %12, %8
br label %5
17: ; preds = %5
%18 = load i32, i32* %3
%19 = sub nsw i32 %18, 32
store i32 %19, i32* %3
%20 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* %3
%22 = call i32 @putchar(i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [64 x i8] c"Enter an abitrarily long string, ending with carriage return > \00"
@.str.1 = [14 x i8] c"Check sum is \00"
define i32 @main() {
%1 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
br label %2
2: ; preds = %0, %2
%3 = phi i32 [ %7, %2 ], [ 0, %0 ]
%4 = tail call i32 (...) @getchar()
%5 = icmp eq i32 %4, 10
%6 = select i1 %5, i32 0, i32 %4
%7 = add nsw i32 %6, %3
br i1 %5, label %8, label %2
8: ; preds = %2
%9 = add i32 %7, -32
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @putchar(i32 %9)
%12 = tail call i32 @putchar(i32 10)
ret i32 0
}