#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 *);
int split_words(char *);
char *strdup(char const *);
int strlen(char *);
void stub1(char const *, void *);
void words(const char *sentence, void (*callback)(const char *, void *),
           void *memo) {
  char *words = strdup(sentence);
  int word_count = split_words(words);
  char *word = words;
  while (word_count-- > 0) {
    (*callback)(word, memo);
    word = word + strlen(word) + 1;
  }
  free(words);
}


x86 assembly (clang, -O0):
<words>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <split_words@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x24(%rbp)
cmp    $0x0,%eax
jle    11c1 <words+0x81>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   *%rax
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1175 <words+0x35>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<words>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r12
call   1060 <strdup@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <split_words@plt>
test   %eax,%eax
jle    1192 <words+0x52>
mov    %eax,%ebp
add    $0x1,%ebp
mov    %r15,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   *%r12
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%rbx
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1170 <words+0x30>
mov    %r15,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @words(i8* %0, void (i8*, i8*)* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca void (i8*, i8*)*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store void (i8*, i8*)* %1, void (i8*, i8*)** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %4
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = call i32 @split_words(i8* %12)
store i32 %13, i32* %8
%14 = load i8*, i8** %7
store i8* %14, i8** %9
br label %15
15: ; preds = %19, %3
%16 = load i32, i32* %8
%17 = add nsw i32 %16, -1
store i32 %17, i32* %8
%18 = icmp sgt i32 %16, 0
br i1 %18, label %19, label %29
19: ; preds = %15
%20 = load void (i8*, i8*)*, void (i8*, i8*)** %5
%21 = load i8*, i8** %9
%22 = load i8*, i8** %6
%23 = load i8*, i8** %9
%24 = load i8*, i8** %9
%25 = call i32 @strlen(i8* %24)
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8* %28, i8** %9
br label %15
29: ; preds = %15
%30 = load i8*, i8** %7
%31 = call i32 @free(i8* %30)
ret void
}

LLVM IR (-O2):
define void @words(i8* nocapture %0, void (i8*, i8*)* nocapture %1, i8* %2) {
%4 = tail call i8* @strdup(i8* %0)
%5 = tail call i32 @split_words(i8* %4)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %3, %7
%8 = phi i8* [ %14, %7 ], [ %4, %3 ]
%9 = phi i32 [ %10, %7 ], [ %5, %3 ]
%10 = add nsw i32 %9, -1
tail call void %1(i8* %8, i8* %2)
%11 = tail call i32 @strlen(i8* %8)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %8, i64 1
%14 = getelementptr inbounds i8, i8* %13, i64 %12
%15 = icmp ugt i32 %9, 1
br i1 %15, label %7, label %16
16: ; preds = %7, %3
%17 = tail call i32 @free(i8* %4)
ret void
}