#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *strtok(char *, char const *);
int get_directory_list(const char *default_directory, char ***directory_list) {
  int i, count = 0;
  const char *tokensep = "/";
  char *buf;
  char *token;
  char **directory_listp;
  buf = (char *)malloc(sizeof(char *) * strlen(default_directory + 1));
  strcpy(buf, default_directory);
  token = strtok(buf, tokensep);
  while (token != NULL) {
    token = strtok(NULL, tokensep);
    count++;
  }
  strcpy(buf, default_directory);
  token = strtok(buf, tokensep);
  *directory_list = (char **)malloc(sizeof(char *) * (count + 1));
  for (i = 0, directory_listp = *directory_list; i < count; i++) {
    *directory_listp = (char *)malloc(strlen(token) + 1);
    strcpy(*directory_listp, token);
    *directory_listp++;
    token = strtok(NULL, tokensep);
  }
  *directory_listp = (char *)NULL;
  return (count);
}


x86 assembly (clang, -O0):
<get_directory_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xea2(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1040 <strlen@plt>
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11c8 <get_directory_list+0x88>
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119e <get_directory_list+0x5e>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1279 <get_directory_list+0x139>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1215 <get_directory_list+0xd5>
mov    -0x38(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_directory_list>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
add    $0x1,%rdi
call   1040 <strlen@plt>
lea    0x0(,%rax,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
lea    0xe85(%rip),%rsi
mov    %r13,%rdi
call   1060 <strtok@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     11b3 <get_directory_list+0x73>
lea    0xe6e(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
add    $0x1,%r15d
test   %rax,%rax
jne    11a0 <get_directory_list+0x60>
mov    %r13,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
lea    0xe3b(%rip),%rsi
mov    %r13,%rdi
call   1060 <strtok@plt>
mov    %rax,%r12
lea    0x8(,%r15,8),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,(%r14)
test   %r15d,%r15d
je     1234 <get_directory_list+0xf4>
lea    0xe11(%rip),%r14
mov    %r15d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,(%rbx)
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
add    $0x8,%rbx
xor    %edi,%edi
mov    %r14,%rsi
call   1060 <strtok@plt>
mov    %rax,%r12
add    $0xffffffff,%ebp
jne    1200 <get_directory_list+0xc0>
movq   $0x0,(%rbx)
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i32 @get_directory_list(i8* %0, i8*** %1) {
%3 = alloca i8*
%4 = alloca i8***
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8**
store i8* %0, i8** %3
store i8*** %1, i8**** %4
store i32 0, i32* %6
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %7
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = call i32 @strlen(i8* %12)
%14 = sext i32 %13 to i64
%15 = mul i64 8, %14
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = load i8*, i8** %3
%21 = call i32 @strcpy(i8* %19, i8* %20)
%22 = load i8*, i8** %8
%23 = load i8*, i8** %7
%24 = call i8* @strtok(i8* %22, i8* %23)
store i8* %24, i8** %9
br label %25
25: ; preds = %28, %2
%26 = load i8*, i8** %9
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i8*, i8** %7
%30 = call i8* @strtok(i8* null, i8* %29)
store i8* %30, i8** %9
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %25
33: ; preds = %25
%34 = load i8*, i8** %8
%35 = load i8*, i8** %3
%36 = call i32 @strcpy(i8* %34, i8* %35)
%37 = load i8*, i8** %8
%38 = load i8*, i8** %7
%39 = call i8* @strtok(i8* %37, i8* %38)
store i8* %39, i8** %9
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = mul i64 8, %42
%44 = trunc i64 %43 to i32
%45 = call i64 @malloc(i32 %44)
%46 = inttoptr i64 %45 to i8**
%47 = load i8***, i8**** %4
store i8** %46, i8*** %47
store i32 0, i32* %5
%48 = load i8***, i8**** %4
%49 = load i8**, i8*** %48
store i8** %49, i8*** %10
br label %50
50: ; preds = %70, %33
%51 = load i32, i32* %5
%52 = load i32, i32* %6
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %73
54: ; preds = %50
%55 = load i8*, i8** %9
%56 = call i32 @strlen(i8* %55)
%57 = add nsw i32 %56, 1
%58 = call i64 @malloc(i32 %57)
%59 = inttoptr i64 %58 to i8*
%60 = load i8**, i8*** %10
store i8* %59, i8** %60
%61 = load i8**, i8*** %10
%62 = load i8*, i8** %61
%63 = load i8*, i8** %9
%64 = call i32 @strcpy(i8* %62, i8* %63)
%65 = load i8**, i8*** %10
%66 = getelementptr inbounds i8*, i8** %65, i32 1
store i8** %66, i8*** %10
%67 = load i8*, i8** %65
%68 = load i8*, i8** %7
%69 = call i8* @strtok(i8* null, i8* %68)
store i8* %69, i8** %9
br label %70
70: ; preds = %54
%71 = load i32, i32* %5
%72 = add nsw i32 %71, 1
store i32 %72, i32* %5
br label %50
73: ; preds = %50
%74 = load i8**, i8*** %10
store i8* null, i8** %74
%75 = load i32, i32* %6
ret i32 %75
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i32 @get_directory_list(i8* %0, i8*** nocapture writeonly %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 1
%4 = tail call i32 @strlen(i8* %3)
%5 = shl i32 %4, 3
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @strcpy(i8* %7, i8* %0)
%9 = tail call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %2, %11
%12 = phi i32 [ %14, %11 ], [ 0, %2 ]
%13 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = add nuw nsw i32 %12, 1
%15 = icmp eq i8* %13, null
br i1 %15, label %16, label %11
16: ; preds = %11, %2
%17 = phi i32 [ 0, %2 ], [ %14, %11 ]
%18 = tail call i32 @strcpy(i8* %7, i8* %0)
%19 = tail call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = shl i32 %17, 3
%21 = add i32 %20, 8
%22 = tail call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8**
store i8** %23, i8*** %1
%24 = icmp eq i32 %17, 0
br i1 %24, label %38, label %25
25: ; preds = %16, %25
%26 = phi i8** [ %34, %25 ], [ %23, %16 ]
%27 = phi i8* [ %35, %25 ], [ %19, %16 ]
%28 = phi i32 [ %36, %25 ], [ 0, %16 ]
%29 = tail call i32 @strlen(i8* %27)
%30 = add nsw i32 %29, 1
%31 = tail call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %26
%33 = tail call i32 @strcpy(i8* %32, i8* %27)
%34 = getelementptr inbounds i8*, i8** %26, i64 1
%35 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%36 = add nuw i32 %28, 1
%37 = icmp eq i32 %36, %17
br i1 %37, label %38, label %25
38: ; preds = %25, %16
%39 = phi i8** [ %23, %16 ], [ %34, %25 ]
store i8* null, i8** %39
ret i32 %17
}