#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 entry, checksum2;
  int checksum = 0;
  printf("Enter an abitrarily long string, ending with carriage return > ");
  while (entry != '\n') {
    entry = getchar();
    checksum += entry;
  }
  checksum = checksum % 64;
  checksum = checksum + 22;
  checksum2 = (char)(checksum);
  printf("Check sum is %c\n", checksum2);
  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     116a <main+0x4a>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x5(%rbp)
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
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x16,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,-0x6(%rbp)
movsbl -0x6(%rbp),%esi
lea    0xeae(%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    %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
store i32 0, i32* %1
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %10, %0
%7 = load i8, i8* %2
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 10
br i1 %9, label %10, label %16
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 = load i32, i32* %4
%15 = add nsw i32 %14, %13
store i32 %15, i32* %4
br label %6
16: ; preds = %6
%17 = load i32, i32* %4
%18 = srem i32 %17, 64
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 22
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = trunc i32 %21 to i8
store i8 %22, i8* %3
%23 = load i8, i8* %3
%24 = sext i8 %23 to i32
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %24)
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
}