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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x9(%rbp),%rdi
call   1050 <scan_data@plt>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
je     1185 <main+0x55>
lea    -0x8(%rbp),%rdi
lea    -0x9(%rbp),%rsi
call   1030 <add@plt>
lea    -0x9(%rbp),%rdi
call   1050 <scan_data@plt>
jmp    115d <main+0x2d>
mov    -0x8(%rbp),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
add    $0x20,%edx
mov    %edx,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xebd(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x3(%rsp),%rdi
call   1050 <scan_data@plt>
mov    $0x20,%esi
cmpb   $0xa,0x3(%rsp)
je     11a1 <main+0x71>
lea    0x4(%rsp),%r14
lea    0x3(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <add@plt>
mov    %rbx,%rdi
call   1050 <scan_data@plt>
cmpb   $0xa,0x3(%rsp)
jne    1170 <main+0x40>
mov    0x4(%rsp),%eax
lea    0x3f(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffffffc0,%ecx
neg    %ecx
lea    (%rax,%rcx,1),%esi
add    $0x20,%esi
mov    %esi,0x4(%rsp)
lea    0xe94(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
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
store i32 0, i32* %1
store i32 0, i32* %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scan_data(i8* %3)
br label %6
6: ; preds = %10, %0
%7 = load i8, i8* %3
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 10
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = call i32 @add(i32* %2, i8* %3)
%12 = call i32 @scan_data(i8* %3)
br label %6
13: ; preds = %6
%14 = load i32, i32* %2
%15 = srem i32 %14, 64
%16 = add nsw i32 %15, 32
store i32 %16, i32* %2
%17 = load i32, i32* %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %17)
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 = alloca i32
%2 = alloca i8
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scan_data(i8* %2)
%6 = load i8, i8* %2
%7 = icmp eq i8 %6, 10
br i1 %7, label %17, label %8
8: ; preds = %0, %8
%9 = call i32 @add(i32* %1, i8* %2)
%10 = call i32 @scan_data(i8* %2)
%11 = load i8, i8* %2
%12 = icmp eq i8 %11, 10
br i1 %12, label %13, label %8
13: ; preds = %8
%14 = load i32, i32* %1
%15 = srem i32 %14, 64
%16 = add nsw i32 %15, 32
br label %17
17: ; preds = %13, %0
%18 = phi i32 [ %16, %13 ], [ 32, %0 ]
store i32 %18, i32* %1
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %18)
ret i32 0
}