#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__ getenv(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
int parsePath(char *dirs[]) {
  char *pathEnvVar;
  char *thePath;
  int i = 0;
  for (i = 0; i < 64; i++)
    dirs[i] = 0;
  char path[] = "PATH";
  pathEnvVar = (char *)getenv(path);
  thePath = (char *)malloc(strlen(pathEnvVar) + 1);
  strcpy(thePath, pathEnvVar);
  char *ptr = strtok(thePath, ":");
  int index = 0;
  while (0 != ptr) {
    dirs[index] = (char *)malloc(strlen(ptr) + 1);
    strcpy(dirs[index], ptr);
    dirs[index][strlen(ptr) + 1] = '\0';
    ptr = strtok(0, ":");
    index++;
  };
  return 1;
}


x86 assembly (clang, -O0):
<parsePath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x40,-0x1c(%rbp)
jge    1192 <parsePath+0x42>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116a <parsePath+0x1a>
mov    0xe68(%rip),%eax
mov    %eax,-0x21(%rbp)
mov    0xe63(%rip),%al
mov    %al,-0x1d(%rbp)
lea    -0x21(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xe25(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
je     127e <parsePath+0x12e>
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd9e(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11f0 <parsePath+0xa0>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsePath>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    $0x200,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe82(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xe5a(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     1217 <parsePath+0xb7>
mov    %rax,%rbx
lea    0xe43(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,(%r15)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    (%r15),%r12
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,0x1(%rax,%r12,1)
xor    %edi,%edi
mov    %r14,%rsi
call   1080 <strtok@plt>
mov    %rax,%rbx
add    $0x8,%r15
test   %rax,%rax
jne    11d0 <parsePath+0x70>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@__const.parsePath.path = [5 x i8] c"PATH\00"
@.str = [2 x i8] c":\00"
define i32 @parsePath(i8** nocapture %0) {
%2 = bitcast i8** %0 to i8*
%3 = tail call i64 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__const.parsePath.path, i64 0, i64 0))
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @strlen(i8* %4)
%6 = add nsw i32 %5, 1
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @strcpy(i8* %8, i8* %4)
%10 = tail call i8* @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %29, label %12
12: ; preds = %1, %12
%13 = phi i64 [ %27, %12 ], [ 0, %1 ]
%14 = phi i8* [ %26, %12 ], [ %10, %1 ]
%15 = tail call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 1
%17 = tail call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
%19 = getelementptr inbounds i8*, i8** %0, i64 %13
store i8* %18, i8** %19
%20 = tail call i32 @strcpy(i8* %18, i8* %14)
%21 = load i8*, i8** %19
%22 = tail call i32 @strlen(i8* %14)
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
store i8 0, i8* %25
%26 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = add nuw i64 %13, 1
%28 = icmp eq i8* %26, null
br i1 %28, label %29, label %12
29: ; preds = %12, %1
ret i32 1
}