#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 string[1000000];
  int count, i, count2;
  printf("Enter an abitrarily long string, ending with carriage return > ");
  scanf("%s", string);
  count = 0;
  count2 = 0;
  for (i = 0; i < 1000000; ++i) {
    count += (int)string[i];
    if (count2 == count)
      break;
    count2 = count;
  }
  count = count % 64 + ' ';
  printf("Check sum is %c\n", count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf4260,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xf4250(%rbp),%rsi
lea    0xef2(%rip),%rdi
call   1040 <scanf@plt>
movl   $0x0,-0xf4254(%rbp)
movl   $0x0,-0xf425c(%rbp)
movl   $0x0,-0xf4258(%rbp)
cmpl   $0xf4240,-0xf4258(%rbp)
jge    11d3 <main+0xb3>
movslq -0xf4258(%rbp),%rax
movsbl -0xf4250(%rbp,%rax,1),%eax
ff
add    -0xf4254(%rbp),%eax
mov    %eax,-0xf4254(%rbp)
mov    -0xf425c(%rbp),%eax
cmp    -0xf4254(%rbp),%eax
jne    11b3 <main+0x93>
jmp    11d3 <main+0xb3>
mov    -0xf4254(%rbp),%eax
mov    %eax,-0xf425c(%rbp)
mov    -0xf4258(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4258(%rbp)
jmp    1171 <main+0x51>
mov    -0xf4254(%rbp),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
add    $0x20,%edx
mov    %edx,-0xf4254(%rbp)
mov    -0xf4254(%rbp),%esi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xf4260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xf4240,%rsp
lea    0xed1(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf01(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
xor    %eax,%eax
nopl   0x0(%rax)
movsbl (%rsp,%rbx,1),%ecx
add    %ecx,%eax
test   %ecx,%ecx
je     116a <main+0x4a>
lea    0x1(%rbx),%rcx
cmp    $0xf423f,%rbx
mov    %rcx,%rbx
jne    1150 <main+0x30>
lea    0x3f(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffffffc0,%ecx
neg    %ecx
lea    (%rax,%rcx,1),%esi
add    $0x20,%esi
lea    0xebf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xf4240,%rsp
pop    %rbx
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"%s\00"
@.str.2 = [17 x i8] c"Check sum is %c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000000 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [1000000 x i8], [1000000 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)
store i32 0, i32* %3
store i32 0, i32* %5
store i32 0, i32* %4
br label %9
9: ; preds = %26, %0
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 1000000
br i1 %11, label %12, label %29
12: ; preds = %9
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %2, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = load i32, i32* %3
%19 = add nsw i32 %18, %17
store i32 %19, i32* %3
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %12
br label %29
24: ; preds = %12
%25 = load i32, i32* %3
store i32 %25, i32* %5
br label %26
26: ; preds = %24
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %9
29: ; preds = %23, %9
%30 = load i32, i32* %3
%31 = srem i32 %30, 64
%32 = add nsw i32 %31, 32
store i32 %32, i32* %3
%33 = load i32, i32* %3
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %33)
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"%s\00"
@.str.2 = [17 x i8] c"Check sum is %c\0A\00"
define i32 @main() {
%1 = alloca [1000000 x i8]
%2 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 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)
br label %5
5: ; preds = %5, %0
%6 = phi i64 [ 0, %0 ], [ %13, %5 ]
%7 = phi i32 [ 0, %0 ], [ %11, %5 ]
%8 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %1, i64 0, i64 %6
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = add nsw i32 %7, %10
%12 = icmp eq i8 %9, 0
%13 = add nuw nsw i64 %6, 1
%14 = icmp eq i64 %13, 1000000
%15 = select i1 %12, i1 true, i1 %14
br i1 %15, label %16, label %5
16: ; preds = %5
%17 = srem i32 %11, 64
%18 = add nsw i32 %17, 32
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %18)
ret i32 0
}