#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 *);
int printf(char *, int);
int main() {
  int i = 0, c = 1;
  char s[100];
  gets(s);
  while ((*s = s[i++]))
    c += *s == ' ';
  return printf("%d", c), 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <gets@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cltq
mov    -0x70(%rbp,%rax,1),%al
mov    %al,-0x70(%rbp)
cmp    $0x0,%al
je     117c <main+0x5c>
movsbl -0x70(%rbp),%eax
cmp    $0x20,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1146 <main+0x26>
mov    -0xc(%rbp),%esi
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x68,%rsp
mov    %rsp,%rdi
call   1040 <gets@plt>
mov    (%rsp),%cl
test   %cl,%cl
je     115b <main+0x3b>
lea    0x1(%rsp),%rax
mov    $0x1,%esi
nopl   (%rax)
xor    %edx,%edx
cmp    $0x20,%cl
sete   %dl
add    %edx,%esi
movzbl (%rax),%ecx
add    $0x1,%rax
test   %cl,%cl
jne    1140 <main+0x20>
movb   $0x0,(%rsp)
jmp    1160 <main+0x40>
mov    $0x1,%esi
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
store i32 1, i32* %3
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%6 = call i32 @gets(i8* %5)
br label %7
7: ; preds = %15, %0
%8 = load i32, i32* %2
%9 = add nsw i32 %8, 1
store i32 %9, i32* %2
%10 = sext i32 %8 to i64
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
store i8 %12, i8* %13
%14 = icmp ne i8 %12, 0
br i1 %14, label %15, label %23
15: ; preds = %7
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 32
%20 = zext i1 %19 to i32
%21 = load i32, i32* %3
%22 = add nsw i32 %21, %20
store i32 %22, i32* %3
br label %7
23: ; preds = %7
%24 = load i32, i32* %3
%25 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i32 @gets(i8* %2)
%4 = load i8, i8* %2
%5 = icmp eq i8 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %0, %6
%7 = phi i64 [ %10, %6 ], [ 0, %0 ]
%8 = phi i8 [ %15, %6 ], [ %4, %0 ]
%9 = phi i32 [ %13, %6 ], [ 1, %0 ]
%10 = add nuw nsw i64 %7, 1
%11 = icmp eq i8 %8, 32
%12 = zext i1 %11 to i32
%13 = add nuw nsw i32 %9, %12
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %10
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %6
17: ; preds = %6
store i8 0, i8* %2
br label %18
18: ; preds = %17, %0
%19 = phi i32 [ %13, %17 ], [ 1, %0 ]
%20 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %19)
ret i32 0
}