#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 **ft_alloc_word_mem(int, char const *, char, char **);
int ft_cntwords(char const *, char);
char **ft_copy_words(int, char const *, char, char **);
scalar_t__ ft_memalloc(int);
char **ft_strsplit(char const *s, char c) {
  char **str_arr;
  int words;
  if (s == NULL)
    return (NULL);
  words = ft_cntwords(s, c);
  if (!(str_arr = (char **)ft_memalloc(sizeof(char *) * (words + 1))))
    return (NULL);
  if (!(str_arr = ft_alloc_word_mem(words, s, c, str_arr)))
    return (NULL);
  str_arr = ft_copy_words(words, s, c, str_arr);
  return (str_arr);
}


x86 assembly (clang, -O0):
<ft_strsplit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116a <ft_strsplit+0x2a>
movq   $0x0,-0x8(%rbp)
jmp    11fb <ft_strsplit+0xbb>
mov    -0x10(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1050 <ft_cntwords@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <ft_memalloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a8 <ft_strsplit+0x68>
movq   $0x0,-0x8(%rbp)
jmp    11fb <ft_strsplit+0xbb>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x11(%rbp),%al
mov    -0x20(%rbp),%rcx
movsbl %al,%edx
call   1030 <ft_alloc_word_mem@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11d9 <ft_strsplit+0x99>
movq   $0x0,-0x8(%rbp)
jmp    11fb <ft_strsplit+0xbb>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x11(%rbp),%al
mov    -0x20(%rbp),%rcx
movsbl %al,%edx
call   1040 <ft_copy_words@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_strsplit>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     1194 <ft_strsplit+0x54>
mov    %rdi,%rbx
movsbl %sil,%r14d
mov    %r14d,%esi
call   1050 <ft_cntwords@plt>
mov    %eax,%ebp
lea    0x8(,%rbp,8),%edi
call   1060 <ft_memalloc@plt>
test   %rax,%rax
je     1194 <ft_strsplit+0x54>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
mov    %rax,%rcx
call   1030 <ft_alloc_word_mem@plt>
test   %rax,%rax
je     1194 <ft_strsplit+0x54>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
mov    %rax,%rcx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <ft_copy_words@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i8** @ft_strsplit(i8* %0, i8 signext %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %16, label %4
4: ; preds = %2
%5 = tail call i32 @ft_cntwords(i8* %0, i8 signext %1)
%6 = shl i32 %5, 3
%7 = add i32 %6, 8
%8 = tail call i64 @ft_memalloc(i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %4
%11 = inttoptr i64 %8 to i8**
%12 = tail call i8** @ft_alloc_word_mem(i32 %5, i8* %0, i8 signext %1, i8** %11)
%13 = icmp eq i8** %12, null
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i8** @ft_copy_words(i32 %5, i8* %0, i8 signext %1, i8** %12)
br label %16
16: ; preds = %10, %4, %2, %14
%17 = phi i8** [ %15, %14 ], [ null, %2 ], [ null, %4 ], [ null, %10 ]
ret i8** %17
}