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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xc(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
je     1193 <main+0x53>
lea    0xec8(%rip),%rdi
lea    -0x5(%rbp),%rsi
call   1060 <scanf@plt>
lea    -0xc(%rbp),%rsi
movsbl -0x5(%rbp),%edi
call   1040 <findsum@plt>
jmp    1164 <main+0x24>
lea    -0xc(%rbp),%rdi
call   1030 <addspace@plt>
mov    -0xc(%rbp),%eax
movsbl %al,%esi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb0(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,0xc(%rsp)
lea    0xeda(%rip),%r14
lea    0xb(%rsp),%r15
lea    0xc(%rsp),%rbx
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
movsbl 0xb(%rsp),%edi
mov    %rbx,%rsi
call   1040 <findsum@plt>
cmpb   $0xa,0xb(%rsp)
jne    1170 <main+0x30>
lea    0xc(%rsp),%rdi
call   1030 <addspace@plt>
movsbl 0xc(%rsp),%esi
lea    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
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
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %5
5: ; preds = %9, %0
%6 = load i8, i8* %2
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 10
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%11 = load i8, i8* %2
%12 = call i32 @findsum(i8 signext %11, i32* %3)
br label %5
13: ; preds = %5
%14 = call i32 @addspace(i32* %3)
%15 = load i32, i32* %3
%16 = trunc i32 %15 to i8
%17 = sext i8 %16 to i32
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, 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 = [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 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %5
5: ; preds = %0, %5
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%7 = load i8, i8* %1
%8 = call i32 @findsum(i8 signext %7, i32* %2)
%9 = load i8, i8* %1
%10 = icmp eq i8 %9, 10
br i1 %10, label %11, label %5
11: ; preds = %5
%12 = call i32 @addspace(i32* %2)
%13 = load i32, i32* %2
%14 = shl i32 %13, 24
%15 = ashr exact i32 %14, 24
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %15)
ret i32 0
}