#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*/ *getenv(char *);
char *next_token(char *, char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int strlen(char const *);
int tokenize(char *);
char *trim(char const *);
int tokenize_to_argv(const char *str, char **argv) {
  if (str == NULL || argv == NULL)
    return 0;
  int i = 0;
  int len = strlen(str);
  char *ptr = trim(str);
  char *pch = NULL;
  int argc = tokenize(ptr);
  pch = ptr;
  for (i = 0; i < argc; i++) {
    argv[i] = pch;
    do {
      if (getenv("DEBUG") != NULL)
        printf("%-30s%s\n", "[tokenize_to_argv]", argv[i]);
    } while (0);
    pch = next_token(pch, ptr + len);
  }
  return argc;
}


x86 assembly (clang, -O0):
<tokenize_to_argv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1186 <tokenize_to_argv+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1192 <tokenize_to_argv+0x32>
movl   $0x0,-0x4(%rbp)
jmp    1257 <tokenize_to_argv+0xf7>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <trim@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <tokenize@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1251 <tokenize_to_argv+0xf1>
mov    -0x30(%rbp),%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
lea    0xe08(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     1226 <tokenize_to_argv+0xc6>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdec(%rip),%rdi
lea    0xdee(%rip),%rsi
call   1050 <printf@plt>
jmp    122b <tokenize_to_argv+0xcb>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
call   1070 <next_token@plt>
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d5 <tokenize_to_argv+0x75>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenize_to_argv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
test   %rdi,%rdi
je     1204 <tokenize_to_argv+0xa4>
mov    %rsi,%r15
test   %rsi,%rsi
je     1204 <tokenize_to_argv+0xa4>
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1060 <trim@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1080 <tokenize@plt>
test   %eax,%eax
jle    1204 <tokenize_to_argv+0xa4>
movslq %r14d,%rbx
add    %rbp,%rbx
mov    %eax,0x4(%rsp)
mov    %eax,%r13d
xor    %r14d,%r14d
lea    0xe45(%rip),%r12
jmp    11d7 <tokenize_to_argv+0x77>
nopl   (%rax)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <next_token@plt>
mov    %rax,%rbp
add    $0x1,%r14
cmp    %r14,%r13
je     1200 <tokenize_to_argv+0xa0>
mov    %rbp,(%r15,%r14,8)
mov    %r12,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11c0 <tokenize_to_argv+0x60>
lea    0xe17(%rip),%rdi
lea    0xe19(%rip),%rsi
mov    %rbp,%rdx
call   1050 <printf@plt>
jmp    11c0 <tokenize_to_argv+0x60>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"DEBUG\00"
@.str.1 = [9 x i8] c"%-30s%s\0A\00"
@.str.2 = [19 x i8] c"[tokenize_to_argv]\00"
define i32 @tokenize_to_argv(i8* %0, i8** writeonly %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8** %1, null
%5 = or i1 %3, %4
br i1 %5, label %27, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %0)
%8 = tail call i8* @trim(i8* %0)
%9 = tail call i32 @tokenize(i8* %8)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %6
%12 = sext i32 %7 to i64
%13 = getelementptr inbounds i8, i8* %8, i64 %12
%14 = zext i32 %9 to i64
br label %15
15: ; preds = %11, %23
%16 = phi i64 [ 0, %11 ], [ %25, %23 ]
%17 = phi i8* [ %8, %11 ], [ %24, %23 ]
%18 = getelementptr inbounds i8*, i8** %1, i64 %16
store i8* %17, i8** %18
%19 = tail call i32* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %23, label %21
21: ; preds = %15
%22 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %23
23: ; preds = %21, %15
%24 = tail call i8* @next_token(i8* %17, i8* %13)
%25 = add nuw nsw i64 %16, 1
%26 = icmp eq i64 %25, %14
br i1 %26, label %27, label %15
27: ; preds = %23, %6, %2
%28 = phi i32 [ 0, %2 ], [ %9, %6 ], [ %9, %23 ]
ret i32 %28
}