#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*/ copy_into_array(char **, char const *, char);
scalar_t__ malloc(int);
int nb_words(char const *, char);
char **ft_strsplit(char const *s, char c) {
  char **ret;
  int nb;
  nb = nb_words(s, c) + 1;
  ret = (char **)malloc(nb * sizeof(char *));
  if (ret) {
    copy_into_array(ret, s, c);
    ret[nb - 1] = 0;
  }
  return (ret);
}


x86 assembly (clang, -O0):
<ft_strsplit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1030 <nb_words@plt>
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1199 <ft_strsplit+0x69>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movsbl -0x9(%rbp),%edx
call   1040 <copy_into_array@plt>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_strsplit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
call   1030 <nb_words@plt>
mov    %eax,%ebx
lea    0x8(,%rbx,8),%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1173 <ft_strsplit+0x43>
movsbl %r15b,%edx
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <copy_into_array@plt>
movslq %ebx,%rax
movq   $0x0,0x0(%rbp,%rax,8)
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
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 i32
store i8* %0, i8** %3
store i8 %1, i8* %4
%7 = load i8*, i8** %3
%8 = load i8, i8* %4
%9 = call i32 @nb_words(i8* %7, i8 signext %8)
%10 = add nsw i32 %9, 1
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 8
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8**
store i8** %16, i8*** %5
%17 = load i8**, i8*** %5
%18 = icmp ne i8** %17, null
br i1 %18, label %19, label %29
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %3
%22 = load i8, i8* %4
%23 = call i32 @copy_into_array(i8** %20, i8* %21, i8 signext %22)
%24 = load i8**, i8*** %5
%25 = load i32, i32* %6
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %24, i64 %27
store i8* null, i8** %28
br label %29
29: ; preds = %19, %2
%30 = load i8**, i8*** %5
ret i8** %30
}

LLVM IR (-O2):
define i8** @ft_strsplit(i8* %0, i8 signext %1) {
%3 = tail call i32 @nb_words(i8* %0, i8 signext %1)
%4 = shl i32 %3, 3
%5 = add i32 %4, 8
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8**
%8 = icmp eq i64 %6, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = tail call i32 @copy_into_array(i8** %7, i8* %0, i8 signext %1)
%11 = sext i32 %3 to i64
%12 = getelementptr inbounds i8*, i8** %7, i64 %11
store i8* null, i8** %12
br label %13
13: ; preds = %9, %2
ret i8** %7
}