#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() {
  char x, rem;
  char sum;
  char checksum;
  printf("Enter an abitrarily long string, ending with carriage return > ");
  scanf("%c", &x);
  sum = 0;
  while (x != '\n') {
    sum = sum + x;
    scanf("%c", &x);
  }
  rem = sum % 64;
  checksum = rem + ' ';
  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
call   1040 <scanf@plt>
movb   $0x0,-0x7(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
je     1180 <main+0x60>
movsbl -0x7(%rbp),%eax
movsbl -0x5(%rbp),%ecx
add    %ecx,%eax
mov    %al,-0x7(%rbp)
lea    0xece(%rip),%rdi
lea    -0x5(%rbp),%rsi
call   1040 <scanf@plt>
jmp    1151 <main+0x31>
movsbl -0x7(%rbp),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x6(%rbp)
movsbl -0x6(%rbp),%eax
add    $0x20,%eax
mov    %al,-0x8(%rbp)
movsbl -0x8(%rbp),%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xed2(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf02(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x7(%rsp),%al
mov    $0x20,%esi
cmp    $0xa,%al
je     11a0 <main+0x80>
lea    0xee4(%rip),%r14
lea    0x7(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl %al,%ebx
add    %ebp,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
movsbl %bl,%ebp
movzbl 0x7(%rsp),%eax
cmp    $0xa,%al
jne    1170 <main+0x50>
mov    %ebx,%eax
sar    $0x7,%al
shr    $0x2,%al
add    %bl,%al
and    $0xc0,%al
sub    %al,%bl
add    $0x20,%bl
movsbl %bl,%esi
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
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 i8
%4 = alloca i8
%5 = alloca i8
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
store i8 0, i8* %4
br label %8
8: ; preds = %12, %0
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 10
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = load i8, i8* %4
%14 = sext i8 %13 to i32
%15 = load i8, i8* %2
%16 = sext i8 %15 to i32
%17 = add nsw i32 %14, %16
%18 = trunc i32 %17 to i8
store i8 %18, i8* %4
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %8
20: ; preds = %8
%21 = load i8, i8* %4
%22 = sext i8 %21 to i32
%23 = srem i32 %22, 64
%24 = trunc i32 %23 to i8
store i8 %24, i8* %3
%25 = load i8, i8* %3
%26 = sext i8 %25 to i32
%27 = add nsw i32 %26, 32
%28 = trunc i32 %27 to i8
store i8 %28, i8* %5
%29 = load i8, i8* %5
%30 = sext i8 %29 to i32
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %30)
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))
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 10
br i1 %5, label %21, label %6
6: ; preds = %0, %6
%7 = phi i8 [ %14, %6 ], [ %4, %0 ]
%8 = phi i32 [ %13, %6 ], [ 0, %0 ]
%9 = zext i8 %7 to i32
%10 = add nsw i32 %8, %9
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%12 = shl i32 %10, 24
%13 = ashr exact i32 %12, 24
%14 = load i8, i8* %1
%15 = icmp eq i8 %14, 10
br i1 %15, label %16, label %6
16: ; preds = %6
%17 = trunc i32 %10 to i8
%18 = srem i8 %17, 64
%19 = add nsw i8 %18, 32
%20 = sext i8 %19 to i32
br label %21
21: ; preds = %16, %0
%22 = phi i32 [ 32, %0 ], [ %20, %16 ]
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %22)
ret i32 0
}