#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 str[50];
  printf(" We will count the number of letters\n");
  printf("-------------------------------------\n");
  printf("Tell me the word: \n");
  scanf("%s", str);
  int i;
  for (i = 0; str[i] != '\0'; i++)
    printf("The letter %d is %c\n", i, str[i]);
  printf("|The number of words is: %d\n", i);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xefd(%rip),%rdi
call   1040 <scanf@plt>
movl   $0x0,-0x44(%rbp)
movslq -0x44(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11aa <main+0x8a>
mov    -0x44(%rbp),%esi
movslq -0x44(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%edx
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1170 <main+0x50>
mov    -0x44(%rbp),%esi
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
lea    0xef7(%rip),%rdi
call   1030 <puts@plt>
lea    0xf10(%rip),%rdi
call   1030 <puts@plt>
lea    0xf2a(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9e(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
mov    (%rsp),%al
test   %al,%al
je     119e <main+0x6e>
lea    0xe8b(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl %al,%edx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x1(%rsp,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1180 <main+0x50>
jmp    11a0 <main+0x70>
xor    %ebx,%ebx
lea    0xe71(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [38 x i8] c" We will count the number of letters\0A\00"
@.str.1 = [39 x i8] c"-------------------------------------\0A\00"
@.str.2 = [20 x i8] c"Tell me the word: \0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [21 x i8] c"The letter %d is %c\0A\00"
@.str.5 = [29 x i8] c"|The number of words is: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %7)
store i32 0, i32* %3
br label %9
9: ; preds = %24, %0
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [50 x i8], [50 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 %27
16: ; preds = %9
%17 = load i32, i32* %3
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %17, i32 %22)
br label %24
24: ; preds = %16
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %9
27: ; preds = %9
%28 = load i32, i32* %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [21 x i8] c"The letter %d is %c\0A\00"
@.str.5 = [29 x i8] c"|The number of words is: %d\0A\00"
@str = [37 x i8] c" We will count the number of letters\00"
@str.6 = [38 x i8] c"-------------------------------------\00"
@str.7 = [19 x i8] c"Tell me the word: \00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.6, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.7, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%7 = load i8, i8* %2
%8 = icmp eq i8 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %0, %9
%10 = phi i64 [ %15, %9 ], [ 0, %0 ]
%11 = phi i8 [ %17, %9 ], [ %7, %0 ]
%12 = sext i8 %11 to i32
%13 = trunc i64 %10 to i32
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %13, i32 %12)
%15 = add nuw i64 %10, 1
%16 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %9
19: ; preds = %9
%20 = trunc i64 %15 to i32
br label %21
21: ; preds = %19, %0
%22 = phi i32 [ 0, %0 ], [ %20, %19 ]
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %22)
ret i32 0
}