#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*/ free(char *);
char *strdup(char *);
char *strtok(char *, char *);
int path_split(char *path, char *parts[], char *delimiter) {
  char *pch;
  int i = 0;
  pch = strtok(path, delimiter);
  while ((NULL != pch)) {
    pch = strtok(NULL, delimiter);
    if (NULL == pch)
      break;
    parts[i++] = strdup(pch);
  }
  free(pch);
  return i;
}


x86 assembly (clang, -O0):
<path_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
je     11b1 <path_split+0x81>
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    118a <path_split+0x5a>
jmp    11b1 <path_split+0x81>
mov    -0x20(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    115c <path_split+0x2c>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_split>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdx,%rsi
call   1040 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     117f <path_split+0x4f>
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     117f <path_split+0x4f>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1050 <strdup@plt>
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
jne    1160 <path_split+0x30>
xor    %edi,%edi
call   1030 <free@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @path_split(i8* %0, i8** %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
store i32 0, i32* %8
%9 = load i8*, i8** %4
%10 = load i8*, i8** %6
%11 = call i8* @strtok(i8* %9, i8* %10)
store i8* %11, i8** %7
br label %12
12: ; preds = %21, %3
%13 = load i8*, i8** %7
%14 = icmp ne i8* null, %13
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = load i8*, i8** %6
%17 = call i8* @strtok(i8* null, i8* %16)
store i8* %17, i8** %7
%18 = load i8*, i8** %7
%19 = icmp eq i8* null, %18
br i1 %19, label %20, label %21
20: ; preds = %15
br label %29
21: ; preds = %15
%22 = load i8*, i8** %7
%23 = call i8* @strdup(i8* %22)
%24 = load i8**, i8*** %5
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
store i32 %26, i32* %8
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds i8*, i8** %24, i64 %27
store i8* %23, i8** %28
br label %12
29: ; preds = %20, %12
%30 = load i8*, i8** %7
%31 = call i32 @free(i8* %30)
%32 = load i32, i32* %8
ret i32 %32
}

LLVM IR (-O2):
define i32 @path_split(i8* %0, i8** nocapture writeonly %1, i8* nocapture %2) {
%4 = tail call i8* @strtok(i8* %0, i8* %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %19, label %6
6: ; preds = %3
%7 = tail call i8* @strtok(i8* null, i8* %2)
%8 = icmp eq i8* %7, null
br i1 %8, label %19, label %9
9: ; preds = %6, %9
%10 = phi i8* [ %15, %9 ], [ %7, %6 ]
%11 = phi i64 [ %13, %9 ], [ 0, %6 ]
%12 = tail call i8* @strdup(i8* %10)
%13 = add nuw i64 %11, 1
%14 = getelementptr inbounds i8*, i8** %1, i64 %11
store i8* %12, i8** %14
%15 = tail call i8* @strtok(i8* null, i8* %2)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %9
17: ; preds = %9
%18 = trunc i64 %13 to i32
br label %19
19: ; preds = %6, %17, %3
%20 = phi i32 [ 0, %3 ], [ %18, %17 ], [ 0, %6 ]
%21 = tail call i32 @free(i8* null)
ret i32 %20
}