#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*/ gets(char *);
scalar_t__ isalpha(char);
scalar_t__ isspace(char);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char input[128];
  int x, spaces, letters;
  x = spaces = letters = 0;
  printf("Enter the first line of the poem:");
  gets(input);
  while (input[x]) {
    if (isspace(input[x]))
      spaces++;
    if (isalpha(input[x]))
      letters++;
    x++;
  }
  printf("That sentence has %d letters and %d spaces", letters, spaces);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x9c(%rbp)
movl   $0x0,-0x98(%rbp)
movl   $0x0,-0x94(%rbp)
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x90(%rbp),%rdi
call   1050 <gets@plt>
movslq -0x94(%rbp),%rax
cmpb   $0x0,-0x90(%rbp,%rax,1)
je     120d <main+0xcd>
movslq -0x94(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%edi
ff
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11cc <main+0x8c>
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
movslq -0x94(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%edi
ff
call   1060 <isalpha@plt>
cmp    $0x0,%rax
je     11f9 <main+0xb9>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    118a <main+0x4a>
mov    -0x9c(%rbp),%esi
mov    -0x98(%rbp),%edx
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
lea    0xeae(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%rdi
call   1050 <gets@plt>
mov    (%rsp),%al
mov    $0x0,%ebp
test   %al,%al
je     11ab <main+0x6b>
lea    0x1(%rsp),%rbx
xor    %ebp,%ebp
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1040 <isspace@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%r14d
movsbl -0x1(%rbx),%edi
call   1060 <isalpha@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1180 <main+0x40>
lea    0xe70(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Enter the first line of the poem:\00"
@.str.1 = [43 x i8] c"That sentence has %d letters and %d spaces\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
store i32 0, i32* %4
store i32 0, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%8 = call i32 @gets(i8* %7)
br label %9
9: ; preds = %35, %0
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
br i1 %14, label %15, label %38
15: ; preds = %9
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = call i64 @isspace(i8 signext %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %25
25: ; preds = %22, %15
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = call i64 @isalpha(i8 signext %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %35
35: ; preds = %32, %25
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
br label %9
38: ; preds = %9
%39 = load i32, i32* %5
%40 = load i32, i32* %4
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %39, i32 %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"Enter the first line of the poem:\00"
@.str.1 = [43 x i8] c"That sentence has %d letters and %d spaces\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @gets(i8* %2)
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
br i1 %6, label %26, label %7
7: ; preds = %0, %7
%8 = phi i64 [ %22, %7 ], [ 0, %0 ]
%9 = phi i8 [ %24, %7 ], [ %5, %0 ]
%10 = phi i8* [ %23, %7 ], [ %2, %0 ]
%11 = phi i32 [ %21, %7 ], [ 0, %0 ]
%12 = phi i32 [ %16, %7 ], [ 0, %0 ]
%13 = call i64 @isspace(i8 signext %9)
%14 = icmp ne i64 %13, 0
%15 = zext i1 %14 to i32
%16 = add nuw nsw i32 %12, %15
%17 = load i8, i8* %10
%18 = call i64 @isalpha(i8 signext %17)
%19 = icmp ne i64 %18, 0
%20 = zext i1 %19 to i32
%21 = add nuw nsw i32 %11, %20
%22 = add nuw i64 %8, 1
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %26, label %7
26: ; preds = %7, %0
%27 = phi i32 [ 0, %0 ], [ %16, %7 ]
%28 = phi i32 [ 0, %0 ], [ %21, %7 ]
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %28, i32 %27)
ret i32 0
}