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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
je     1172 <main+0x52>
lea    0xee8(%rip),%rdi
lea    -0x9(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
movsbl -0x9(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    1144 <main+0x24>
mov    -0x8(%rbp),%eax
sub    $0xa,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
add    $0x20,%edx
mov    %edx,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xed0(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf00(%rip),%r14
lea    0xf(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
movsbl 0xf(%rsp),%eax
add    %eax,%ebx
cmp    $0xa,%eax
jne    1150 <main+0x30>
lea    -0xa(%rbx),%eax
lea    0x35(%rbx),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffffffc0,%ecx
neg    %ecx
lea    (%rbx,%rcx,1),%esi
add    $0x16,%esi
lea    0xebf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
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 i32
%3 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %9, %0
%6 = load i8, i8* %3
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 10
br i1 %8, label %9, label %15
9: ; preds = %5
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%11 = load i32, i32* %2
%12 = load i8, i8* %3
%13 = sext i8 %12 to i32
%14 = add nsw i32 %11, %13
store i32 %14, i32* %2
br label %5
15: ; preds = %5
%16 = load i32, i32* %2
%17 = sub nsw i32 %16, 10
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = srem i32 %18, 64
%20 = add nsw i32 %19, 32
store i32 %20, i32* %2
%21 = load i32, i32* %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %21)
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 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %0, %3
%4 = phi i32 [ %8, %3 ], [ 0, %0 ]
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%6 = load i8, i8* %1
%7 = sext i8 %6 to i32
%8 = add nsw i32 %4, %7
%9 = icmp eq i8 %6, 10
br i1 %9, label %10, label %3
10: ; preds = %3
%11 = add i32 %8, -10
%12 = srem i32 %11, 64
%13 = add nsw i32 %12, 32
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %13)
ret i32 0
}