#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char **);
void *realloc(char **, int);
int /*<<< orphan*/ stderr;
char *strtok(char *, char const *);
char **str_split(char *s, const char *ct) {
  char **tab = NULL;
  if (s != NULL && ct != NULL) {
    int i;
    char *cs = NULL;
    size_t size = 1;
    for (i = 0; (cs = strtok(s, ct)); i++) {
      if (size <= i + 1) {
        void *tmp = NULL;
        size <<= 1;
        tmp = realloc(tab, sizeof(*tab) * size);
        if (tmp != NULL) {
          tab = tmp;
        } else {
          fprintf(stderr, "Memoire insuffisante\n");
          free(tab);
          tab = NULL;
          exit(EXIT_FAILURE);
        }
      }
      tab[i] = cs;
      s = NULL;
    }
    tab[i] = NULL;
  }
  return tab;
}


x86 assembly (clang, -O0):
<str_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1278 <str_split+0x128>
cmpq   $0x0,-0x10(%rbp)
je     1278 <str_split+0x128>
movq   $0x0,-0x28(%rbp)
movq   $0x1,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1268 <str_split+0x118>
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
ja     1242 <str_split+0xf2>
movq   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1209 <str_split+0xb9>
mov    -0x38(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    123d <str_split+0xed>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    0xde7(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    1242 <str_split+0xf2>
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movq   $0x0,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1195 <str_split+0x45>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_split>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r15d,%r15d
test   %rdi,%rdi
je     11d7 <str_split+0x87>
mov    %rsi,%r14
test   %rsi,%rsi
je     11d7 <str_split+0x87>
mov    %r14,%rsi
call   1060 <strtok@plt>
mov    %rax,%r13
mov    $0x1,%r12d
xor    %ebx,%ebx
xor    %r15d,%r15d
jmp    11a9 <str_split+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13,(%r15,%rbx,8)
xor    %edi,%edi
mov    %r14,%rsi
call   1060 <strtok@plt>
mov    %rax,%r13
mov    %rbp,%rbx
test   %rax,%rax
je     11cd <str_split+0x7d>
lea    0x1(%rbx),%rbp
cmp    %rbp,%r12
ja     1190 <str_split+0x40>
mov    %r12d,%esi
shl    $0x4,%esi
mov    %r15,%rdi
call   1050 <realloc@plt>
test   %rax,%rax
je     11e9 <str_split+0x99>
add    %r12,%r12
mov    %rax,%r15
jmp    1190 <str_split+0x40>
mov    %ebp,%eax
movq   $0x0,(%r15,%rax,8)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
call   1040 <fprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Memoire insuffisante\0A\00"
@EXIT_FAILURE = global i32 0
define i8** @str_split(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8** null, i8*** %5
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %62
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %62
15: ; preds = %12
store i8* null, i8** %7
store i64 1, i64* %8
store i32 0, i32* %6
br label %16
16: ; preds = %54, %15
%17 = load i8*, i8** %3
%18 = load i8*, i8** %4
%19 = call i8* @strtok(i8* %17, i8* %18)
store i8* %19, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %57
21: ; preds = %16
%22 = load i64, i64* %8
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = icmp ule i64 %22, %25
br i1 %26, label %27, label %48
27: ; preds = %21
store i8* null, i8** %9
%28 = load i64, i64* %8
%29 = shl i64 %28, 1
store i64 %29, i64* %8
%30 = load i8**, i8*** %5
%31 = load i64, i64* %8
%32 = mul i64 8, %31
%33 = trunc i64 %32 to i32
%34 = call i8* @realloc(i8** %30, i32 %33)
store i8* %34, i8** %9
%35 = load i8*, i8** %9
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %40
37: ; preds = %27
%38 = load i8*, i8** %9
%39 = bitcast i8* %38 to i8**
store i8** %39, i8*** %5
br label %47
40: ; preds = %27
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%43 = load i8**, i8*** %5
%44 = call i32 @free(i8** %43)
store i8** null, i8*** %5
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %37
br label %48
48: ; preds = %47, %21
%49 = load i8*, i8** %7
%50 = load i8**, i8*** %5
%51 = load i32, i32* %6
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
store i8* %49, i8** %53
store i8* null, i8** %3
br label %54
54: ; preds = %48
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
br label %16
57: ; preds = %16
%58 = load i8**, i8*** %5
%59 = load i32, i32* %6
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %58, i64 %60
store i8* null, i8** %61
br label %62
62: ; preds = %57, %12, %2
%63 = load i8**, i8*** %5
ret i8** %63
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Memoire insuffisante\0A\00"
@EXIT_FAILURE = global i32 0
define i8** @str_split(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %39
6: ; preds = %2
%7 = tail call i8* @strtok(i8* %0, i8* %1)
%8 = icmp ne i8* %7, null
br label %9
9: ; preds = %6, %30
%10 = phi i64 [ 0, %6 ], [ %14, %30 ]
%11 = phi i8* [ %7, %6 ], [ %34, %30 ]
%12 = phi i64 [ 1, %6 ], [ %32, %30 ]
%13 = phi i8** [ null, %6 ], [ %31, %30 ]
%14 = add nuw i64 %10, 1
%15 = icmp ugt i64 %12, %14
br i1 %15, label %30, label %16
16: ; preds = %9
%17 = trunc i64 %12 to i32
%18 = shl i32 %17, 4
%19 = tail call i8* @realloc(i8** %13, i32 %18)
%20 = icmp eq i8* %19, null
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = shl i64 %12, 1
%23 = bitcast i8* %19 to i8**
br label %30
24: ; preds = %16
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%27 = tail call i32 @free(i8** %13)
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %21, %9
%31 = phi i8** [ %23, %21 ], [ %13, %9 ]
%32 = phi i64 [ %22, %21 ], [ %12, %9 ]
%33 = getelementptr inbounds i8*, i8** %31, i64 %10
store i8* %11, i8** %33
%34 = tail call i8* @strtok(i8* null, i8* %1)
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %9
36: ; preds = %30
%37 = and i64 %14, 4294967295
%38 = getelementptr inbounds i8*, i8** %31, i64 %37
store i8* null, i8** %38
br label %39
39: ; preds = %36, %2
%40 = phi i8** [ %31, %36 ], [ null, %2 ]
ret i8** %40
}