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


x86 assembly (clang, -O0):
<tokenize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-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),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
movslq -0x1c(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    1204 <tokenize+0xd4>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11ee <tokenize+0xbe>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
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)
cmpl   $0x2a,-0x34(%rbp)
jle    11e9 <tokenize+0xb9>
jmp    1204 <tokenize+0xd4>
jmp    11ee <tokenize+0xbe>
jmp    11f3 <tokenize+0xc3>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    117f <tokenize+0x4f>
mov    -0x34(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x40,%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,%r15
mov    %rsi,%r13
mov    %rdi,(%rsp)
mov    $0x2a,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%r12
mov    0x0(%r13),%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11ae <tokenize+0x7e>
movslq %eax,%rbp
mov    0x0(%r13),%rbx
xor    %r14d,%r14d
jmp    1180 <tokenize+0x50>
add    $0x1,%rbx
mov    0x0(%r13),%rax
add    %rbp,%rax
cmp    %rax,%rbx
jae    11b1 <tokenize+0x81>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1170 <tokenize+0x40>
movb   $0x0,(%rbx)
lea    0x1(%rbx),%rax
movslq %r14d,%rcx
mov    %rax,(%r12,%rcx,8)
lea    0x1(%rcx),%r14d
cmp    $0x29,%ecx
jle    1170 <tokenize+0x40>
jmp    11b1 <tokenize+0x81>
xor    %r14d,%r14d
mov    (%rsp),%rax
mov    %r14d,(%rax)
mov    %r12,%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 0, 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 = call i32 @strlen(i8* %14)
store i32 %15, i32* %7
%16 = load i8**, i8*** %5
%17 = load i8*, i8** %16
store i8* %17, i8** %8
br label %18
18: ; preds = %47, %3
%19 = load i8*, i8** %8
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %20
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = icmp ult i8* %19, %24
br i1 %25, label %26, label %50
26: ; preds = %18
%27 = load i8*, i8** %8
%28 = load i8*, i8** %6
%29 = call i64 @strncmp(i8* %27, i8* %28, i32 1)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %46
31: ; preds = %26
%32 = load i8*, i8** %8
%33 = getelementptr inbounds i8, i8* %32, i64 0
store i8 0, i8* %33
%34 = load i8*, i8** %8
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8**, i8*** %9
%37 = load i32, i32* %10
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
store i8* %35, i8** %39
%40 = load i32, i32* %10
%41 = add nsw i32 %40, 1
store i32 %41, i32* %10
%42 = load i32, i32* %10
%43 = icmp sgt i32 %42, 42
br i1 %43, label %44, label %45
44: ; preds = %31
br label %50
45: ; preds = %31
br label %46
46: ; preds = %45, %26
br label %47
47: ; preds = %46
%48 = load i8*, i8** %8
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %8
br label %18
50: ; preds = %44, %18
%51 = load i32, i32* %10
%52 = load i32*, i32** %4
store i32 %51, i32* %52
%53 = load i8**, i8*** %9
ret i8** %53
}

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
%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 %28
9: ; preds = %3
%10 = load i8*, i8** %1
br label %11
11: ; preds = %9, %22
%12 = phi i8* [ %24, %22 ], [ %10, %9 ]
%13 = phi i32 [ %23, %22 ], [ 0, %9 ]
%14 = tail call i64 @strncmp(i8* %12, i8* %2, i32 1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %11
store i8 0, i8* %12
%17 = getelementptr inbounds i8, i8* %12, i64 1
%18 = sext i32 %13 to i64
%19 = getelementptr inbounds i8*, i8** %4, i64 %18
store i8* %17, i8** %19
%20 = add nsw i32 %13, 1
%21 = icmp sgt i32 %13, 41
br i1 %21, label %28, label %22
22: ; preds = %11, %16
%23 = phi i32 [ %20, %16 ], [ %13, %11 ]
%24 = getelementptr inbounds i8, i8* %12, i64 1
%25 = load i8*, i8** %1
%26 = getelementptr inbounds i8, i8* %25, i64 %7
%27 = icmp ult i8* %24, %26
br i1 %27, label %11, label %28
28: ; preds = %22, %16, %3
%29 = phi i32 [ 0, %3 ], [ %20, %16 ], [ %23, %22 ]
store i32 %29, i32* %0
ret i8** %4
}