#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 */
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int a = 0;
  char c;
  int sum;
  printf("Enter an abitrarily long string, ending with carriage return > ");
  while (1) {
    if (c == '\n')
      break;
    else {
      c = getchar();
      a += (int)c;
    }
  }
  sum = a % 64 + 22;
  sum = (char)sum;
  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
jne    1156 <main+0x36>
jmp    116f <main+0x4f>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1144 <main+0x24>
mov    -0x8(%rbp),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
add    $0x16,%edx
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
movsbl %al,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%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   %rbx
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getchar@plt>
movsbl %al,%eax
add    %eax,%ebx
cmp    $0xa,%al
jne    1140 <main+0x20>
lea    0x3f(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xffffffc0,%eax
neg    %eax
lea    (%rbx,%rax,1),%esi
add    $0x16,%esi
lea    0xed6(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [64 x i8] c"Enter an abitrarily long string, ending with carriage return > \00"
@.str.1 = [17 x i8] c"Check sum is %c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %0, %17
%7 = load i8, i8* %3
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 10
br i1 %9, label %10, label %11
10: ; preds = %6
br label %18
11: ; preds = %6
%12 = call signext i8 (...) @getchar()
store i8 %12, i8* %3
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
%15 = load i32, i32* %2
%16 = add nsw i32 %15, %14
store i32 %16, i32* %2
br label %17
17: ; preds = %11
br label %6
18: ; preds = %10
%19 = load i32, i32* %2
%20 = srem i32 %19, 64
%21 = add nsw i32 %20, 22
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = trunc i32 %22 to i8
%24 = sext i8 %23 to i32
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [64 x i8] c"Enter an abitrarily long string, ending with carriage return > \00"
@.str.1 = [17 x i8] c"Check sum is %c\0A\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
br label %2
2: ; preds = %0, %2
%3 = phi i32 [ %6, %2 ], [ 0, %0 ]
%4 = tail call signext i8 (...) @getchar()
%5 = sext i8 %4 to i32
%6 = add nsw i32 %3, %5
%7 = icmp eq i8 %4, 10
br i1 %7, label %8, label %2
8: ; preds = %2
%9 = srem i32 %6, 64
%10 = add nsw i32 %9, 22
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %10)
ret i32 0
}