#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*/ add_tab(char *, char **, int);
int /*<<< orphan*/ add_words(char *, char *);
int count_char(char *);
int count_words(char *);
void *malloc(int);
char **my_str_to_wordtab(char *str) {
  int cwords;
  int length;
  char *words;
  char **wordtab;
  cwords = count_words(str);
  if ((wordtab = malloc((cwords + 1) * sizeof(char *))) == NULL)
    return (0);
  length = count_char(str) + cwords;
  if ((words = malloc(length * sizeof(char))) == NULL)
    return (0);
  add_words(str, words);
  add_tab(words, wordtab, cwords);
  return (wordtab);
}


x86 assembly (clang, -O0):
<my_str_to_wordtab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <count_words@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1196 <my_str_to_wordtab+0x46>
movq   $0x0,-0x8(%rbp)
jmp    11f4 <my_str_to_wordtab+0xa4>
mov    -0x10(%rbp),%rdi
call   1040 <count_char@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11cf <my_str_to_wordtab+0x7f>
movq   $0x0,-0x8(%rbp)
jmp    11f4 <my_str_to_wordtab+0xa4>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <add_words@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <add_tab@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_str_to_wordtab>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <count_words@plt>
mov    %eax,%r14d
lea    0x8(,%r14,8),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11ac <my_str_to_wordtab+0x5c>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <count_char@plt>
lea    (%rax,%r14,1),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11ac <my_str_to_wordtab+0x5c>
mov    %rax,%r12
mov    %r15,%rdi
mov    %rax,%rsi
call   1070 <add_words@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1060 <add_tab@plt>
jmp    11ae <my_str_to_wordtab+0x5e>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8** @my_str_to_wordtab(i8* %0) {
%2 = tail call i32 @count_words(i8* %0)
%3 = shl i32 %2, 3
%4 = add i32 %3, 8
%5 = tail call i8* @malloc(i32 %4)
%6 = bitcast i8* %5 to i8**
%7 = icmp eq i8* %5, null
br i1 %7, label %16, label %8
8: ; preds = %1
%9 = tail call i32 @count_char(i8* %0)
%10 = add nsw i32 %9, %2
%11 = tail call i8* @malloc(i32 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = tail call i32 @add_words(i8* %0, i8* %11)
%15 = tail call i32 @add_tab(i8* %11, i8** %6, i32 %2)
br label %16
16: ; preds = %8, %1, %13
%17 = phi i8** [ %6, %13 ], [ null, %1 ], [ null, %8 ]
ret i8** %17
}