#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(void) {
  char a[4095];
  int n = 0, sum = 0, checksum;
  n = 0;
  printf("Enter an arbitrarily long string, ending with carriage return > ");
  scanf("%s", a);
  while (a[n] != '\0') {
    sum += (int)(a[n]);
    n++;
  }
  checksum = (sum % 64) + 32;
  printf("Check sum is %c\n", (char)checksum);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1014(%rbp)
movl   $0x0,-0x1018(%rbp)
movl   $0x0,-0x1014(%rbp)
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x1010(%rbp),%rsi
lea    0xed5(%rip),%rdi
call   1040 <scanf@plt>
movslq -0x1014(%rbp),%rax
movsbl -0x1010(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     11b8 <main+0x98>
movslq -0x1014(%rbp),%rax
movsbl -0x1010(%rbp,%rax,1),%eax
ff
add    -0x1018(%rbp),%eax
mov    %eax,-0x1018(%rbp)
mov    -0x1014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1014(%rbp)
jmp    1171 <main+0x51>
mov    -0x1018(%rbp),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
add    $0x20,%edx
mov    %edx,-0x101c(%rbp)
mov    -0x101c(%rbp),%eax
movsbl %al,%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x1000,%rsp
lea    0xed1(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf02(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
mov    (%rsp),%al
test   %al,%al
je     1185 <main+0x65>
lea    0x1(%rsp),%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%eax
add    %eax,%ebx
movzbl (%rcx),%eax
add    $0x1,%rcx
test   %al,%al
jne    1160 <main+0x40>
lea    0x3f(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xffffffc0,%eax
neg    %eax
lea    (%rbx,%rax,1),%esi
add    $0x20,%esi
jmp    118a <main+0x6a>
mov    $0x20,%esi
lea    0xeb3(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1000,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [65 x i8] c"Enter an arbitrarily long string, ending with carriage return > \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [17 x i8] c"Check sum is %c\0A\00"
define i32 @main() {
%1 = alloca [4095 x i8]
%2 = getelementptr inbounds [4095 x i8], [4095 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %0, %7
%8 = phi i64 [ %13, %7 ], [ 0, %0 ]
%9 = phi i8 [ %15, %7 ], [ %5, %0 ]
%10 = phi i32 [ %12, %7 ], [ 0, %0 ]
%11 = sext i8 %9 to i32
%12 = add nsw i32 %10, %11
%13 = add nuw nsw i64 %8, 1
%14 = getelementptr inbounds [4095 x i8], [4095 x i8]* %1, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %7
17: ; preds = %7
%18 = srem i32 %12, 64
%19 = add nsw i32 %18, 32
br label %20
20: ; preds = %17, %0
%21 = phi i32 [ 32, %0 ], [ %19, %17 ]
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %21)
ret i32 0
}