#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main(void) {
  char input;
  int a, checksum;
  printf("Enter an abitrarily long string, ending with carriage return > ");
  scanf("%c", &input);
  a = 0;
  do {
    input = (int)input + a;
    scanf("%c", &a);
  } while (a != '\n');
  checksum = ((int)input % 64) + (int)' ';
  printf("Check sum is %c\n", checksum);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefc(%rip),%rdi
lea    -0x5(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
movsbl -0x5(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %al,-0x5(%rbp)
lea    0xed9(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0xa,-0xc(%rbp)
jne    1156 <main+0x36>
movsbl -0x5(%rbp),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
add    $0x20,%edx
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf07(%rip),%r14
lea    0x3(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rbx
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
add    %al,0x3(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0xa,%eax
jne    1160 <main+0x40>
mov    0x3(%rsp),%al
mov    %eax,%ecx
sar    $0x7,%cl
shr    $0x2,%cl
add    %al,%cl
and    $0xc0,%cl
sub    %cl,%al
add    $0x20,%al
movsbl %al,%esi
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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