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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef4(%rip),%rdi
lea    -0x5(%rbp),%rsi
call   1040 <scanf@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
mov    0x2e85(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x15(%rbp)
je     117b <main+0x5b>
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    118b <main+0x6b>
jmp    11aa <main+0x8a>
mov    -0x10(%rbp),%rax
movsbq -0x5(%rbp),%rcx
add    %rcx,%rax
mov    $0x40,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x10(%rbp)
jmp    1145 <main+0x25>
mov    -0x10(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl %al,%esi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xed1(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf03(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x2e9a(%rip),%r15
mov    $0x20,%esi
cmp    (%r15),%eax
je     11a9 <main+0x89>
mov    0x7(%rsp),%al
cmp    $0xa,%al
je     11a9 <main+0x89>
xor    %ebx,%ebx
lea    0xed7(%rip),%r14
lea    0x7(%rsp),%r12
xchg   %ax,%ax
movsbq %al,%rax
lea    (%rbx,%rax,1),%rcx
add    $0x3f,%rcx
add    %rax,%rbx
cmovns %rbx,%rcx
and    $0xffffffffffffffc0,%rcx
sub    %rcx,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
cmp    (%r15),%eax
je     11a3 <main+0x83>
movzbl 0x7(%rsp),%eax
cmp    $0xa,%al
jne    1170 <main+0x50>
add    $0x20,%bl
movsbl %bl,%esi
lea    0xe93(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
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"
@EOF = global i32 0
@.str.2 = [17 x i8] c"Check sum is %c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i64
%4 = alloca i32
store i32 0, i32* %1
store i64 0, i64* %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 = %16, %0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
store i32 %7, i32* %4
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i8, i8* %2
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 10
br label %14
14: ; preds = %10, %6
%15 = phi i1 [ false, %6 ], [ %13, %10 ]
br i1 %15, label %16, label %22
16: ; preds = %14
%17 = load i64, i64* %3
%18 = load i8, i8* %2
%19 = sext i8 %18 to i64
%20 = add nsw i64 %17, %19
%21 = srem i64 %20, 64
store i64 %21, i64* %3
br label %6
22: ; preds = %14
%23 = load i64, i64* %3
%24 = add nsw i64 %23, 32
store i64 %24, i64* %3
%25 = load i64, i64* %3
%26 = trunc i64 %25 to i8
%27 = sext i8 %26 to i32
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %27)
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"
@EOF = global i32 0
@.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))
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%4 = load i32, i32* @EOF
%5 = icmp ne i32 %3, %4
%6 = load i8, i8* %1
%7 = icmp ne i8 %6, 10
%8 = select i1 %5, i1 %7, i1 false
br i1 %8, label %9, label %26
9: ; preds = %0, %9
%10 = phi i8 [ %18, %9 ], [ %6, %0 ]
%11 = phi i64 [ %14, %9 ], [ 0, %0 ]
%12 = sext i8 %10 to i64
%13 = add nsw i64 %11, %12
%14 = srem i64 %13, 64
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%16 = load i32, i32* @EOF
%17 = icmp ne i32 %15, %16
%18 = load i8, i8* %1
%19 = icmp ne i8 %18, 10
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %9, label %21
21: ; preds = %9
%22 = trunc i64 %14 to i32
%23 = shl nsw i32 %22, 24
%24 = add i32 %23, 536870912
%25 = ashr exact i32 %24, 24
br label %26
26: ; preds = %21, %0
%27 = phi i32 [ 32, %0 ], [ %25, %21 ]
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %27)
ret i32 0
}