#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 count_words(char *);
char *extract_word(int, char *);
char **malloc(int);
char **ft_split_whitespaces(char *str) {
  char **ptr;
  int nb_words;
  int i;
  nb_words = count_words(str);
  ptr = malloc(sizeof(char *) * (nb_words + 1));
  if (ptr == 0)
    return (0);
  i = 0;
  while (i < nb_words) {
    ptr[i] = extract_word(i, str);
    i++;
  }
  ptr[i] = 0;
  return (ptr);
}


x86 assembly (clang, -O0):
<ft_split_whitespaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <count_words@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1177 <ft_split_whitespaces+0x47>
movq   $0x0,-0x8(%rbp)
jmp    11cb <ft_split_whitespaces+0x9b>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b3 <ft_split_whitespaces+0x83>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <extract_word@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    117e <ft_split_whitespaces+0x4e>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_split_whitespaces>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <count_words@plt>
mov    %eax,%ebx
lea    0x8(,%rbx,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     1184 <ft_split_whitespaces+0x54>
test   %ebx,%ebx
jle    1179 <ft_split_whitespaces+0x49>
mov    %ebx,%r12d
xor    %ebx,%ebx
nop
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <extract_word@plt>
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <ft_split_whitespaces+0x30>
jmp    117c <ft_split_whitespaces+0x4c>
xor    %r12d,%r12d
movq   $0x0,(%r15,%r12,8)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define noalias i8** @ft_split_whitespaces(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 = icmp eq i8** %5, null
br i1 %6, label %23, label %7
7: ; preds = %1
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %20
9: ; preds = %7
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %16, %11 ]
%13 = trunc i64 %12 to i32
%14 = tail call i8* @extract_word(i32 %13, i8* %0)
%15 = getelementptr inbounds i8*, i8** %5, i64 %12
store i8* %14, i8** %15
%16 = add nuw nsw i64 %12, 1
%17 = icmp eq i64 %16, %10
br i1 %17, label %18, label %11
18: ; preds = %11
%19 = zext i32 %2 to i64
br label %20
20: ; preds = %7, %18
%21 = phi i64 [ %19, %18 ], [ 0, %7 ]
%22 = getelementptr inbounds i8*, i8** %5, i64 %21
store i8* null, i8** %22
br label %23
23: ; preds = %1, %20
ret i8** %5
}