#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 num;
  char i;
  char final;
  printf("Enter an abitrarily long string, ending with carriage return > ");
  scanf("%c", &i);
  num = i;
  while (i != '\n') {
    scanf("%c", &i);
    if (i != '\n') {
      num += i;
    }
  }
  final = num % 64;
  final += ' ';
  printf("Check sum is %c\n", final);
  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    -0x9(%rbp),%rsi
call   1040 <scanf@plt>
movsbl -0x9(%rbp),%eax
mov    %eax,-0x8(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
je     118d <main+0x6d>
lea    0xed8(%rip),%rdi
lea    -0x9(%rbp),%rsi
call   1040 <scanf@plt>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
je     1188 <main+0x68>
movsbl -0x9(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1154 <main+0x34>
mov    -0x8(%rbp),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0xa(%rbp)
movsbl -0xa(%rbp),%eax
add    $0x20,%eax
mov    %al,-0xa(%rbp)
movsbl -0xa(%rbp),%esi
lea    0xe91(%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    %r15d,%r15d
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf01(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1040 <scanf@plt>
movsbl 0x7(%rsp),%ebp
mov    $0x2a,%esi
cmp    $0xa,%ebp
je     11a4 <main+0x84>
lea    0xee1(%rip),%r14
lea    0x7(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
movzbl 0x7(%rsp),%eax
cmp    $0xa,%al
mov    %eax,%ecx
cmove  %r15d,%ecx
movsbl %cl,%ecx
add    %ecx,%ebp
cmp    $0xa,%al
jne    1170 <main+0x50>
lea    0x3f(%rbp),%eax
test   %ebp,%ebp
cmovns %ebp,%eax
and    $0xffffffc0,%eax
neg    %eax
lea    (%rax,%rbp,1),%esi
add    $0x20,%esi
lea    0xe98(%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 i32
%3 = alloca i8
%4 = alloca i8
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 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = load i8, i8* %3
%8 = sext i8 %7 to i32
store i32 %8, i32* %2
br label %9
9: ; preds = %23, %0
%10 = load i8, i8* %3
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 10
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%15 = load i8, i8* %3
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 10
br i1 %17, label %18, label %23
18: ; preds = %13
%19 = load i8, i8* %3
%20 = sext i8 %19 to i32
%21 = load i32, i32* %2
%22 = add nsw i32 %21, %20
store i32 %22, i32* %2
br label %23
23: ; preds = %18, %13
br label %9
24: ; preds = %9
%25 = load i32, i32* %2
%26 = srem i32 %25, 64
%27 = trunc i32 %26 to i8
store i8 %27, i8* %4
%28 = load i8, i8* %4
%29 = sext i8 %28 to i32
%30 = add nsw i32 %29, 32
%31 = trunc i32 %30 to i8
store i8 %31, i8* %4
%32 = load i8, i8* %4
%33 = sext i8 %32 to i32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %33)
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 %19, label %6
6: ; preds = %0
%7 = sext i8 %4 to i32
br label %8
8: ; preds = %6, %8
%9 = phi i32 [ %15, %8 ], [ %7, %6 ]
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%11 = load i8, i8* %1
%12 = icmp eq i8 %11, 10
%13 = select i1 %12, i8 0, i8 %11
%14 = sext i8 %13 to i32
%15 = add nsw i32 %9, %14
br i1 %12, label %16, label %8
16: ; preds = %8
%17 = srem i32 %15, 64
%18 = add nsw i32 %17, 32
br label %19
19: ; preds = %16, %0
%20 = phi i32 [ 42, %0 ], [ %18, %16 ]
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %20)
ret i32 0
}