#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 */
scalar_t__ find_next_token(char const **, unsigned int *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strlen(char *);
char *variable_buffer_output(char *, char *, int /*<<< orphan*/);
char *func_words(char *o, char **argv,
                 const char *funcname __attribute__((unused))) {
  int i = 0;
  const char *word_iterator = argv[0];
  char buf[20];
  while (find_next_token(&word_iterator, (unsigned int *)0) != 0)
    ++i;
  sprintf(buf, "%d", i);
  o = variable_buffer_output(o, buf, strlen(buf));
  return o;
}


x86 assembly (clang, -O0):
<func_words>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <find_next_token@plt>
cmp    $0x0,%rax
je     118b <func_words+0x4b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1166 <func_words+0x26>
lea    -0x40(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe67(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1040 <variable_buffer_output@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func_words>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%r14
mov    (%rsi),%rax
mov    %rax,0x8(%rsp)
mov    $0xffffffff,%ebp
lea    0x8(%rsp),%rbx
nopl   (%rax)
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <find_next_token@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    1160 <func_words+0x20>
lea    0xe87(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %ebp,%edx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <variable_buffer_output@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i8* @func_words(i8* %0, i8** nocapture %1, i8* nocapture readnone %2) {
%4 = alloca i8*
%5 = alloca [20 x i8]
%6 = bitcast i8** %4 to i8*
%7 = load i8*, i8** %1
store i8* %7, i8** %4
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
br label %9
9: ; preds = %9, %3
%10 = phi i32 [ 0, %3 ], [ %13, %9 ]
%11 = call i64 @find_next_token(i8** %4, i32* null)
%12 = icmp eq i64 %11, 0
%13 = add nuw nsw i32 %10, 1
br i1 %12, label %14, label %9
14: ; preds = %9
%15 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
%16 = call i32 @strlen(i8* %8)
%17 = call i8* @variable_buffer_output(i8* %0, i8* %8, i32 %16)
ret i8* %17
}