#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, final;
  sum = 0;
  printf("Enter an abitrarily long string, ending with carriage return > ");
  while (add != '\n') {
    add = getchar();
    if (add != '\n')
      sum = add + sum;
  }
  final = (sum % 64) + 32;
  printf("Check sum is ");
  putchar(final);
  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
mov    $0x40,%ecx
cltd
idiv   %ecx
add    $0x20,%edx
mov    %edx,-0x10(%rbp)
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%edi
call   1030 <putchar@plt>
lea    0xea4(%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>
lea    0x3f(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xffffffc0,%eax
neg    %eax
add    %eax,%ebx
add    $0x20,%ebx
lea    0xec1(%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
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%5 = call i32 @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %17, %0
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 10
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = call i32 (...) @getchar()
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, 10
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = add nsw i32 %14, %15
store i32 %16, i32* %3
br label %17
17: ; preds = %13, %9
br label %6
18: ; preds = %6
%19 = load i32, i32* %3
%20 = srem i32 %19, 64
%21 = add nsw i32 %20, 32
store i32 %21, i32* %4
%22 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* %4
%24 = call i32 @putchar(i32 %23)
%25 = 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 = srem i32 %7, 64
%10 = add nsw i32 %9, 32
%11 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @putchar(i32 %10)
%13 = tail call i32 @putchar(i32 10)
ret i32 0
}