#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 **calloc(int const, int);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char **tokenize(int *segments, char **stringp, char *delim) {
  int lenstring;
  char *i;
  char **tokens;
  int segs = 1;
  const int max_segs = 42;
  tokens = calloc(max_segs, sizeof(char *));
  tokens[0] = *stringp;
  lenstring = strlen(*stringp);
  for (i = *stringp; i < *stringp + lenstring && segs < max_segs; i++) {
    if (strncmp(i, delim, strlen(delim)) == 0) {
      i[0] = '\0';
      i = i + strlen(delim) - 1;
      tokens[segs] = i + 1;
      segs++;
    }
  }
  *segments = segs;
  return tokens;
}


x86 assembly (clang, -O0):
<tokenize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x34(%rbp)
movl   $0x2a,-0x38(%rbp)
mov    $0x2a,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
movslq -0x1c(%rbp),%rax
add    %rax,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x39(%rbp)
jae    11b7 <tokenize+0x87>
cmpl   $0x2a,-0x34(%rbp)
setl   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11c7 <tokenize+0x97>
jmp    1258 <tokenize+0x128>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1242 <tokenize+0x112>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdx
add    $0x1,%rdx
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1247 <tokenize+0x117>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    118d <tokenize+0x5d>
mov    -0x34(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %rsi,%r12
mov    %rdi,%rbx
mov    $0x2a,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%r15
mov    (%r12),%rdi
mov    %rdi,(%rax)
call   1040 <strlen@plt>
test   %eax,%eax
mov    %rbx,(%rsp)
jle    11d3 <tokenize+0xa3>
movslq %eax,%r14
mov    (%r12),%rbx
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11bc <tokenize+0x8c>
movb   $0x0,(%rbx)
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rcx
add    %rax,%rbx
add    $0xffffffffffffffff,%rbx
movslq %ebp,%rbp
mov    %rcx,(%r15,%rbp,8)
add    $0x1,%ebp
add    $0x1,%rbx
mov    (%r12),%rax
add    %r14,%rax
cmp    %rax,%rbx
jae    11d8 <tokenize+0xa8>
cmp    $0x2a,%ebp
jl     1180 <tokenize+0x50>
jmp    11d8 <tokenize+0xa8>
mov    $0x1,%ebp
mov    (%rsp),%rax
mov    %ebp,(%rax)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8** @tokenize(i32* %0, i8** %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
store i32 1, i32* %10
store i32 42, i32* %11
%12 = call i8** @calloc(i32 42, i32 8)
store i8** %12, i8*** %9
%13 = load i8**, i8*** %5
%14 = load i8*, i8** %13
%15 = load i8**, i8*** %9
%16 = getelementptr inbounds i8*, i8** %15, i64 0
store i8* %14, i8** %16
%17 = load i8**, i8*** %5
%18 = load i8*, i8** %17
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %7
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %20
store i8* %21, i8** %8
br label %22
22: ; preds = %60, %3
%23 = load i8*, i8** %8
%24 = load i8**, i8*** %5
%25 = load i8*, i8** %24
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = icmp ult i8* %23, %28
br i1 %29, label %30, label %33
30: ; preds = %22
%31 = load i32, i32* %10
%32 = icmp slt i32 %31, 42
br label %33
33: ; preds = %30, %22
%34 = phi i1 [ false, %22 ], [ %32, %30 ]
br i1 %34, label %35, label %63
35: ; preds = %33
%36 = load i8*, i8** %8
%37 = load i8*, i8** %6
%38 = load i8*, i8** %6
%39 = call i32 @strlen(i8* %38)
%40 = call i64 @strncmp(i8* %36, i8* %37, i32 %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %59
42: ; preds = %35
%43 = load i8*, i8** %8
%44 = getelementptr inbounds i8, i8* %43, i64 0
store i8 0, i8* %44
%45 = load i8*, i8** %8
%46 = load i8*, i8** %6
%47 = call i32 @strlen(i8* %46)
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %45, i64 %48
%50 = getelementptr inbounds i8, i8* %49, i64 -1
store i8* %50, i8** %8
%51 = load i8*, i8** %8
%52 = getelementptr inbounds i8, i8* %51, i64 1
%53 = load i8**, i8*** %9
%54 = load i32, i32* %10
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
store i8* %52, i8** %56
%57 = load i32, i32* %10
%58 = add nsw i32 %57, 1
store i32 %58, i32* %10
br label %59
59: ; preds = %42, %35
br label %60
60: ; preds = %59
%61 = load i8*, i8** %8
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %8
br label %22
63: ; preds = %33
%64 = load i32, i32* %10
%65 = load i32*, i32** %4
store i32 %64, i32* %65
%66 = load i8**, i8*** %9
ret i8** %66
}

LLVM IR (-O2):
define noalias i8** @tokenize(i32* nocapture writeonly %0, i8** nocapture %1, i8* %2) {
%4 = tail call i8** @calloc(i32 42, i32 8)
%5 = load i8*, i8** %1
store i8* %5, i8** %4
%6 = tail call i32 @strlen(i8* %5)
%7 = sext i32 %6 to i64
%8 = icmp sgt i32 %6, 0
br i1 %8, label %9, label %35
9: ; preds = %3
%10 = load i8*, i8** %1
br label %11
11: ; preds = %9, %26
%12 = phi i8* [ %29, %26 ], [ %10, %9 ]
%13 = phi i32 [ %27, %26 ], [ 1, %9 ]
%14 = tail call i32 @strlen(i8* %2)
%15 = tail call i64 @strncmp(i8* %12, i8* %2, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %11
store i8 0, i8* %12
%18 = tail call i32 @strlen(i8* %2)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %12, i64 -1
%21 = getelementptr inbounds i8, i8* %20, i64 %19
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = sext i32 %13 to i64
%24 = getelementptr inbounds i8*, i8** %4, i64 %23
store i8* %22, i8** %24
%25 = add nsw i32 %13, 1
br label %26
26: ; preds = %11, %17
%27 = phi i32 [ %25, %17 ], [ %13, %11 ]
%28 = phi i8* [ %21, %17 ], [ %12, %11 ]
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i8*, i8** %1
%31 = getelementptr inbounds i8, i8* %30, i64 %7
%32 = icmp ult i8* %29, %31
%33 = icmp slt i32 %27, 42
%34 = select i1 %32, i1 %33, i1 false
br i1 %34, label %11, label %35
35: ; preds = %26, %3
%36 = phi i32 [ 1, %3 ], [ %27, %26 ]
store i32 %36, i32* %0
ret i8** %4
}