#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 stuff;
  int sum;
  int count = 0;
  printf("Enter an abitrarily long string, ending with carriage return > ");
  scanf("%c", &stuff);
  while (stuff > 0) {
    count++;
    sum += (int)stuff % 10;
    stuff = stuff / 10;
    printf("are you stupid %d\n", count);
    printf("%d\n", (int)stuff);
  }
  sum = sum % 64 + ' ';
  printf("Check sum is %c\n", (char)sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef5(%rip),%rdi
lea    -0x5(%rbp),%rsi
call   1040 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x0,%eax
jle    11b3 <main+0x93>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
movsbl -0x5(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    -0xc(%rbp),%edx
mov    %edx,-0xc(%rbp)
movsbl -0x5(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %al,-0x5(%rbp)
mov    -0x10(%rbp),%esi
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x5(%rbp),%esi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1154 <main+0x34>
mov    -0xc(%rbp),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
add    $0x20,%edx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
movsbl %al,%esi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xed1(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf03(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x7(%rsp),%al
test   %al,%al
jle    11cf <main+0xaf>
mov    $0x1,%ebx
lea    0xee4(%rip),%r14
lea    0xeec(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
movzbl %al,%eax
imul   $0xcd,%eax,%ecx
shr    $0xb,%ecx
lea    (%rcx,%rcx,1),%edx
lea    (%rdx,%rdx,4),%edx
sub    %dl,%al
movzbl %al,%eax
add    %eax,%r12d
mov    %cl,0x7(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movsbl 0x7(%rsp),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl 0x7(%rsp),%eax
add    $0x1,%ebx
test   %al,%al
jg     1170 <main+0x50>
lea    0x3f(%r12),%eax
test   %r12d,%r12d
cmovns %r12d,%eax
and    $0xffffffc0,%eax
neg    %eax
lea    (%r12,%rax,1),%esi
add    $0x20,%esi
jmp    11d4 <main+0xb4>
mov    $0x20,%esi
lea    0xe7b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
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 = [19 x i8] c"are you stupid %d\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [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
store i32 0, i32* %1
store i32 0, i32* %4
%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* %2)
br label %7
7: ; preds = %11, %0
%8 = load i8, i8* %2
%9 = sext i8 %8 to i32
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %7
%12 = load i32, i32* %4
%13 = add nsw i32 %12, 1
store i32 %13, i32* %4
%14 = load i8, i8* %2
%15 = sext i8 %14 to i32
%16 = srem i32 %15, 10
%17 = load i32, i32* %3
%18 = add nsw i32 %17, %16
store i32 %18, i32* %3
%19 = load i8, i8* %2
%20 = sext i8 %19 to i32
%21 = sdiv i32 %20, 10
%22 = trunc i32 %21 to i8
store i8 %22, i8* %2
%23 = load i32, i32* %4
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i8, i8* %2
%26 = sext i8 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %26)
br label %7
28: ; preds = %7
%29 = load i32, i32* %3
%30 = srem i32 %29, 64
%31 = add nsw i32 %30, 32
store i32 %31, i32* %3
%32 = load i32, i32* %3
%33 = trunc i32 %32 to i8
%34 = sext i8 %33 to i32
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %34)
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 = [19 x i8] c"are you stupid %d\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [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 sgt i8 %4, 0
br i1 %5, label %6, label %24
6: ; preds = %0, %6
%7 = phi i8 [ %19, %6 ], [ %4, %0 ]
%8 = phi i32 [ %10, %6 ], [ 0, %0 ]
%9 = phi i32 [ %13, %6 ], [ undef, %0 ]
%10 = add nuw nsw i32 %8, 1
%11 = urem i8 %7, 10
%12 = zext i8 %11 to i32
%13 = add nsw i32 %9, %12
%14 = udiv i8 %7, 10
store i8 %14, i8* %1
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%16 = load i8, i8* %1
%17 = sext i8 %16 to i32
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = load i8, i8* %1
%20 = icmp sgt i8 %19, 0
br i1 %20, label %6, label %21
21: ; preds = %6
%22 = srem i32 %13, 64
%23 = add nsw i32 %22, 32
br label %24
24: ; preds = %21, %0
%25 = phi i32 [ 32, %0 ], [ %23, %21 ]
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %25)
ret i32 0
}