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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
je     117c <main+0x5c>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
jne    116d <main+0x4d>
jmp    117c <main+0x5c>
movsbl -0x5(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1144 <main+0x24>
mov    -0xc(%rbp),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
add    $0x20,%edx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%esi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
movsbl %al,%ecx
lea    (%rbx,%rcx,1),%eax
cmp    $0xa,%cl
jne    1140 <main+0x20>
lea    0x3f(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xffffffc0,%eax
neg    %eax
lea    (%rbx,%rax,1),%esi
add    $0x20,%esi
lea    0xed2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

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

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