#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 */
char *malloc(int);
size_t strlen(char const *);
scalar_t__ tokenize_words_aux(char const *, size_t, char *);
char *tokenize_words(const char str[]) {
  if (str == NULL || *str == '\0')
    return NULL;
  size_t str_len = strlen(str);
  char *buffer;
  if ((buffer = malloc(2 * str_len)) == NULL)
    return NULL;
  if (tokenize_words_aux(str, str_len, buffer)) {
    size_t res_len = strlen(buffer);
    if (res_len > 0)
      buffer[res_len - 1] = '\0';
    return buffer;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<tokenize_words>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1157 <tokenize_words+0x27>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1164 <tokenize_words+0x34>
movq   $0x0,-0x8(%rbp)
jmp    11f3 <tokenize_words+0xc3>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    119b <tokenize_words+0x6b>
movq   $0x0,-0x8(%rbp)
jmp    11f3 <tokenize_words+0xc3>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <tokenize_words_aux@plt>
cmp    $0x0,%rax
je     11eb <tokenize_words+0xbb>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jbe    11de <tokenize_words+0xae>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f3 <tokenize_words+0xc3>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenize_words>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1185 <tokenize_words+0x55>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1185 <tokenize_words+0x55>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
lea    (%rax,%rax,1),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1185 <tokenize_words+0x55>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1050 <tokenize_words_aux@plt>
test   %rax,%rax
je     1185 <tokenize_words+0x55>
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     1188 <tokenize_words+0x58>
movb   $0x0,-0x1(%rax,%r14,1)
jmp    1188 <tokenize_words+0x58>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @tokenize_words(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9, %1
store i8* null, i8** %2
br label %43
15: ; preds = %9
%16 = load i8*, i8** %3
%17 = call i64 @strlen(i8* %16)
store i64 %17, i64* %4
%18 = load i64, i64* %4
%19 = mul i64 2, %18
%20 = trunc i64 %19 to i32
%21 = call i8* @malloc(i32 %20)
store i8* %21, i8** %5
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %15
store i8* null, i8** %2
br label %43
24: ; preds = %15
%25 = load i8*, i8** %3
%26 = load i64, i64* %4
%27 = load i8*, i8** %5
%28 = call i64 @tokenize_words_aux(i8* %25, i64 %26, i8* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %42
30: ; preds = %24
%31 = load i8*, i8** %5
%32 = call i64 @strlen(i8* %31)
store i64 %32, i64* %6
%33 = load i64, i64* %6
%34 = icmp ugt i64 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = load i8*, i8** %5
%37 = load i64, i64* %6
%38 = sub i64 %37, 1
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 0, i8* %39
br label %40
40: ; preds = %35, %30
%41 = load i8*, i8** %5
store i8* %41, i8** %2
br label %43
42: ; preds = %24
store i8* null, i8** %2
br label %43
43: ; preds = %42, %40, %23, %14
%44 = load i8*, i8** %2
ret i8* %44
}

LLVM IR (-O2):
define i8* @tokenize_words(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %21, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %21, label %6
6: ; preds = %3
%7 = tail call i64 @strlen(i8* %0)
%8 = trunc i64 %7 to i32
%9 = shl i32 %8, 1
%10 = tail call i8* @malloc(i32 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %21, label %12
12: ; preds = %6
%13 = tail call i64 @tokenize_words_aux(i8* %0, i64 %7, i8* %10)
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = tail call i64 @strlen(i8* %10)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = add i64 %16, -1
%20 = getelementptr inbounds i8, i8* %10, i64 %19
store i8 0, i8* %20
br label %21
21: ; preds = %6, %18, %15, %12, %1, %3
%22 = phi i8* [ null, %3 ], [ null, %1 ], [ null, %6 ], [ %10, %18 ], [ %10, %15 ], [ null, %12 ]
ret i8* %22
}