#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*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *strtok(char *, char *);
scalar_t__ theNshMalloc(int);
char **tokenizeEnvVar(char *givenVar, char **values) {
  char *varCopy = (char *)theNshMalloc((int)(strlen(givenVar) + 1));
  strcpy(varCopy, givenVar);
  char *temp = strtok(varCopy, "!");
  int i = 0;
  while (temp != NULL) {
    values[i++] = temp;
    temp = strtok(NULL, "!");
  }
  values[i] = (char *)NULL;
  return values;
}


x86 assembly (clang, -O0):
<tokenizeEnvVar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%rax
mov    %eax,%edi
call   1040 <theNshMalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ce <tokenizeEnvVar+0x8e>
mov    -0x20(%rbp),%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)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe40(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    1190 <tokenizeEnvVar+0x50>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenizeEnvVar>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1040 <theNshMalloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xe90(%rip),%rsi
mov    %r15,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     11ab <tokenizeEnvVar+0x6b>
xor    %ebx,%ebx
lea    0xe7a(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %rax,(%r12,%rbx,8)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r14,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
jne    1190 <tokenizeEnvVar+0x50>
mov    %ebx,%eax
jmp    11ad <tokenizeEnvVar+0x6d>
xor    %eax,%eax
movq   $0x0,(%r12,%rax,8)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"!\00"
define i8** @tokenizeEnvVar(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 %9, 1
%11 = trunc i64 %10 to i32
%12 = call i64 @theNshMalloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = load i8*, i8** %3
%16 = call i32 @strcpy(i8* %14, i8* %15)
%17 = load i8*, i8** %5
%18 = call i8* @strtok(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %18, i8** %6
store i32 0, i32* %7
br label %19
19: ; preds = %22, %2
%20 = load i8*, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = load i8*, i8** %6
%24 = load i8**, i8*** %4
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds i8*, i8** %24, i64 %27
store i8* %23, i8** %28
%29 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %29, i8** %6
br label %19
30: ; preds = %19
%31 = load i8**, i8*** %4
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
store i8* null, i8** %34
%35 = load i8**, i8*** %4
ret i8** %35
}

LLVM IR (-O2):
@.str = [2 x i8] c"!\00"
define i8** @tokenizeEnvVar(i8* %0, i8** returned writeonly %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = trunc i64 %3 to i32
%5 = add i32 %4, 1
%6 = tail call i64 @theNshMalloc(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 %20, label %11
11: ; preds = %2, %11
%12 = phi i64 [ %14, %11 ], [ 0, %2 ]
%13 = phi i8* [ %16, %11 ], [ %9, %2 ]
%14 = add nuw i64 %12, 1
%15 = getelementptr inbounds i8*, i8** %1, i64 %12
store i8* %13, i8** %15
%16 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %11
18: ; preds = %11
%19 = and i64 %14, 4294967295
br label %20
20: ; preds = %18, %2
%21 = phi i64 [ 0, %2 ], [ %19, %18 ]
%22 = getelementptr inbounds i8*, i8** %1, i64 %21
store i8* null, i8** %22
ret i8** %1
}