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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
movl   $0x0,-0xc(%rbp)
movb   $0x20,-0x5(%rbp)
lea    0xee6(%rip),%rdi
lea    -0x5(%rbp),%rsi
call   1040 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
je     1180 <main+0x60>
movsbl -0x5(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1185 <main+0x65>
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
jne    1153 <main+0x33>
mov    -0x10(%rbp),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
add    $0x20,%edx
mov    %dl,%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%esi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%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>
movb   $0x20,0x7(%rsp)
lea    0xefd(%rip),%r14
lea    0x7(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %ebp,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
movsbl 0x7(%rsp),%eax
lea    (%rbx,%rax,1),%ebp
cmp    $0xa,%eax
jne    1150 <main+0x30>
lea    0x3f(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xffffffc0,%eax
neg    %eax
lea    (%rbx,%rax,1),%esi
add    $0x20,%esi
lea    0xebf(%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 i32
%4 = alloca i32
%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))
store i32 0, i32* %4
store i8 0, i8* %5
store i32 0, i32* %3
store i8 32, i8* %2
br label %7
7: ; preds = %19, %0
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 10
br i1 %11, label %12, label %18
12: ; preds = %7
%13 = load i8, i8* %2
%14 = sext i8 %13 to i32
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = add nsw i32 %16, %15
store i32 %17, i32* %4
br label %18
18: ; preds = %12, %7
br label %19
19: ; preds = %18
%20 = load i8, i8* %2
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 10
br i1 %22, label %7, label %23
23: ; preds = %19
%24 = load i32, i32* %4
%25 = srem i32 %24, 64
%26 = add nsw i32 %25, 32
%27 = trunc i32 %26 to i8
store i8 %27, i8* %5
%28 = load i8, i8* %5
%29 = sext i8 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %29)
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))
store i8 32, i8* %1
br label %3
3: ; preds = %3, %0
%4 = phi i32 [ 0, %0 ], [ %9, %3 ]
%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 = icmp eq i8 %6, 10
%8 = sext i8 %6 to i32
%9 = add nsw i32 %4, %8
br i1 %7, label %10, label %3
10: ; preds = %3
%11 = srem i32 %4, 64
%12 = add nsw i32 %11, 32
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %12)
ret i32 0
}