#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*/ free(char *);
char *strdup(char *);
int /*<<< orphan*/ *strtok(char *, char *);
int words(char *source) {
  int i;
  char *string;
  if (source == NULL)
    i = 0;
  else {
    string = strdup(source);
    if (strtok(string, " ") == NULL)
      i = 0;
    else
      for (i = 1; strtok(NULL, " "); ++i) {
      };
    free(string);
  }
  return i;
}


x86 assembly (clang, -O0):
<words>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1153 <words+0x23>
movl   $0x0,-0xc(%rbp)
jmp    11c8 <words+0x98>
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1040 <strtok@plt>
cmp    $0x0,%rax
jne    1186 <words+0x56>
movl   $0x0,-0xc(%rbp)
jmp    11bf <words+0x8f>
movl   $0x1,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe68(%rip),%rsi
call   1040 <strtok@plt>
cmp    $0x0,%rax
je     11ba <words+0x8a>
jmp    11ac <words+0x7c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118d <words+0x5d>
jmp    11bf <words+0x8f>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<words>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     117c <words+0x4c>
call   1050 <strdup@plt>
mov    %rax,%r14
lea    0xeb7(%rip),%rsi
mov    %rax,%rdi
call   1040 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1172 <words+0x42>
lea    0xea1(%rip),%r15
nop
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
add    $0x1,%ebx
test   %rax,%rax
jne    1160 <words+0x30>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    117e <words+0x4e>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i32 @words(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %15, label %3
3: ; preds = %1
%4 = tail call i8* @strdup(i8* %0)
%5 = tail call i32* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %12, label %7
7: ; preds = %3, %7
%8 = phi i32 [ %11, %7 ], [ 1, %3 ]
%9 = tail call i32* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
%11 = add nuw nsw i32 %8, 1
br i1 %10, label %12, label %7
12: ; preds = %7, %3
%13 = phi i32 [ 0, %3 ], [ %8, %7 ]
%14 = tail call i32 @free(i8* %4)
br label %15
15: ; preds = %1, %12
%16 = phi i32 [ %13, %12 ], [ 0, %1 ]
ret i32 %16
}