#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 input, n;
  int code, total = 0;
  printf("Enter an abitrarily long string, ending with carriage return > ");
  while (code != '\n') {
    n = getchar();
    code = (int)n;
    total += code;
  }
  total = (total % 64) + 22;
  char output = (char)total;
  printf("Check sum is %c\n", output);
  return 0;
}


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

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getchar@plt>
movsbl %al,%eax
add    %eax,%ebx
cmp    $0xa,%al
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    $0x16,%esi
lea    0xed6(%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 i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %11, %0
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 10
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = call signext i8 (...) @getchar()
store i8 %12, i8* %3
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = add nsw i32 %16, %15
store i32 %17, i32* %5
br label %8
18: ; preds = %8
%19 = load i32, i32* %5
%20 = srem i32 %19, 64
%21 = add nsw i32 %20, 22
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = trunc i32 %22 to i8
store i8 %23, i8* %6
%24 = load i8, i8* %6
%25 = sext i8 %24 to i32
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %25)
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 = %0, %2
%3 = phi i32 [ %6, %2 ], [ 0, %0 ]
%4 = tail call signext i8 (...) @getchar()
%5 = sext i8 %4 to i32
%6 = add nsw i32 %3, %5
%7 = icmp eq i8 %4, 10
br i1 %7, label %8, label %2
8: ; preds = %2
%9 = srem i32 %6, 64
%10 = add nsw i32 %9, 22
%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
}