#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() {
  while (1) {
    char str[10000] = {0};
    int num;
    char sum;
    printf("Enter an abitrarily long string, ending with carriage return > ");
    scanf("%s", str);
    int i;
    for (i = 0; i < 10000; i++) {
      num += str[i];
    }
    sum = num;
    printf("Check sum is %c\n", sum);
    return (0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2730,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x2720(%rbp),%rdi
xor    %esi,%esi
mov    $0x2710,%edx
call   1040 <memset@plt>
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x2720(%rbp),%rsi
lea    0xecf(%rip),%rdi
call   1050 <scanf@plt>
movl   $0x0,-0x272c(%rbp)
cmpl   $0x2710,-0x272c(%rbp)
jge    11bf <main+0x8f>
movslq -0x272c(%rbp),%rax
movsbl -0x2720(%rbp,%rax,1),%eax
ff
add    -0x2724(%rbp),%eax
mov    %eax,-0x2724(%rbp)
mov    -0x272c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x272c(%rbp)
jmp    1180 <main+0x50>
mov    -0x2724(%rbp),%eax
mov    %al,-0x2725(%rbp)
movsbl -0x2725(%rbp),%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x2730,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x2710,%rsp
mov    %rsp,%rbx
mov    $0x2710,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
lea    0xeaf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
pxor   %xmm0,%xmm0
mov    $0xc,%eax
pxor   %xmm2,%xmm2
pxor   %xmm1,%xmm1
nopl   0x0(%rax,%rax,1)
movdqa -0xc(%rsp,%rax,1),%xmm3
movd   -0x8(%rsp,%rax,1),%xmm4
punpcklbw %xmm0,%xmm3
punpcklwd %xmm0,%xmm3
paddd  %xmm2,%xmm3
punpcklbw %xmm0,%xmm4
punpcklwd %xmm0,%xmm4
paddd  %xmm1,%xmm4
movq   -0x4(%rsp,%rax,1),%xmm2
movd   (%rsp,%rax,1),%xmm1
punpcklbw %xmm0,%xmm2
punpcklwd %xmm0,%xmm2
paddd  %xmm3,%xmm2
punpcklbw %xmm0,%xmm1
punpcklwd %xmm0,%xmm1
paddd  %xmm4,%xmm1
add    $0x10,%rax
cmp    $0x271c,%rax
jne    1180 <main+0x50>
paddd  %xmm2,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddd  %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%eax
movsbl %al,%esi
lea    0xe4c(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x2710,%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 [10000 x i8]
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
store i32 0, i32* %1
br label %6
6: ; preds = %0
%7 = bitcast [10000 x i8]* %2 to i8*
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
store i32 0, i32* %5
br label %11
11: ; preds = %22, %6
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 10000
br i1 %13, label %14, label %25
14: ; preds = %11
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = load i32, i32* %3
%21 = add nsw i32 %20, %19
store i32 %21, i32* %3
br label %22
22: ; preds = %14
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %11
25: ; preds = %11
%26 = load i32, i32* %3
%27 = trunc i32 %26 to i8
store i8 %27, i8* %4
%28 = load i8, i8* %4
%29 = sext i8 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %29)
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 [10000 x i8]
%2 = getelementptr inbounds [10000 x i8], [10000 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 ], [ %30, %5 ]
%7 = phi <4 x i32> [ <i32 undef, i32 0, i32 0, i32 0>, %0 ], [ %28, %5 ]
%8 = phi <4 x i32> [ zeroinitializer, %0 ], [ %29, %5 ]
%9 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %6
%10 = bitcast i8* %9 to <4 x i8>*
%11 = load <4 x i8>, <4 x i8>* %10
%12 = getelementptr inbounds i8, i8* %9, i64 4
%13 = bitcast i8* %12 to <4 x i8>*
%14 = load <4 x i8>, <4 x i8>* %13
%15 = zext <4 x i8> %11 to <4 x i32>
%16 = zext <4 x i8> %14 to <4 x i32>
%17 = add <4 x i32> %7, %15
%18 = add <4 x i32> %8, %16
%19 = or i64 %6, 8
%20 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %19
%21 = bitcast i8* %20 to <4 x i8>*
%22 = load <4 x i8>, <4 x i8>* %21
%23 = getelementptr inbounds i8, i8* %20, i64 4
%24 = bitcast i8* %23 to <4 x i8>*
%25 = load <4 x i8>, <4 x i8>* %24
%26 = zext <4 x i8> %22 to <4 x i32>
%27 = zext <4 x i8> %25 to <4 x i32>
%28 = add <4 x i32> %17, %26
%29 = add <4 x i32> %18, %27
%30 = add nuw nsw i64 %6, 16
%31 = icmp eq i64 %30, 10000
br i1 %31, label %32, label %5
32: ; preds = %5
%33 = add <4 x i32> %29, %28
%34 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %33)
%35 = shl i32 %34, 24
%36 = ashr exact i32 %35, 24
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %36)
ret i32 0
}