#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 *getarg(char **);
char **newbuf();
char **sizeset(char **, size_t);
char **tokenize(char *buf, size_t bufsize) {
  char *p, **list;
  size_t i;
  list = newbuf();
  for (p = buf, i = 0; p < buf + bufsize; i++) {
    list = sizeset(list, i + 1);
    if ((list[i] = getarg(&p)) == 0) {
      free(list);
      return 0;
    }
  }
  list[i] = 0;
  *p = 0;
  return list;
}


x86 assembly (clang, -O0):
<tokenize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1050 <newbuf@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    -0x18(%rbp),%rcx
cmp    %rcx,%rax
jae    11e0 <tokenize+0xa0>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
add    $0x1,%rsi
call   1060 <sizeset@plt>
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <getarg@plt>
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    11ca <tokenize+0x8a>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ff <tokenize+0xbf>
jmp    11cf <tokenize+0x8f>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    116b <tokenize+0x2b>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenize>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r12
mov    %rdi,%r15
xor    %r13d,%r13d
xor    %eax,%eax
call   1050 <newbuf@plt>
mov    %rax,%r14
mov    %r15,0x8(%rsp)
test   %r12,%r12
jle    11ad <tokenize+0x6d>
add    %r12,%r15
xor    %r13d,%r13d
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rbx
add    $0x1,%r13
mov    %r14,%rdi
mov    %r13,%rsi
call   1060 <sizeset@plt>
mov    %rax,%r14
mov    %r12,%rdi
call   1040 <getarg@plt>
mov    %rax,(%r14,%rbx,8)
test   %rax,%rax
je     11bf <tokenize+0x7f>
cmp    %r15,0x8(%rsp)
jb     1180 <tokenize+0x40>
movq   $0x0,(%r14,%r13,8)
mov    0x8(%rsp),%rax
movb   $0x0,(%rax)
jmp    11ca <tokenize+0x8a>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8** @tokenize(i8* %0, i64 %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
%9 = call i8** (...) @newbuf()
store i8** %9, i8*** %7
%10 = load i8*, i8** %4
store i8* %10, i8** %6
store i64 0, i64* %8
br label %11
11: ; preds = %31, %2
%12 = load i8*, i8** %6
%13 = load i8*, i8** %4
%14 = load i64, i64* %5
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = icmp ult i8* %12, %15
br i1 %16, label %17, label %34
17: ; preds = %11
%18 = load i8**, i8*** %7
%19 = load i64, i64* %8
%20 = add i64 %19, 1
%21 = call i8** @sizeset(i8** %18, i64 %20)
store i8** %21, i8*** %7
%22 = call i8* @getarg(i8** %6)
%23 = load i8**, i8*** %7
%24 = load i64, i64* %8
%25 = getelementptr inbounds i8*, i8** %23, i64 %24
store i8* %22, i8** %25
%26 = icmp eq i8* %22, null
br i1 %26, label %27, label %30
27: ; preds = %17
%28 = load i8**, i8*** %7
%29 = call i32 @free(i8** %28)
store i8** null, i8*** %3
br label %40
30: ; preds = %17
br label %31
31: ; preds = %30
%32 = load i64, i64* %8
%33 = add i64 %32, 1
store i64 %33, i64* %8
br label %11
34: ; preds = %11
%35 = load i8**, i8*** %7
%36 = load i64, i64* %8
%37 = getelementptr inbounds i8*, i8** %35, i64 %36
store i8* null, i8** %37
%38 = load i8*, i8** %6
store i8 0, i8* %38
%39 = load i8**, i8*** %7
store i8** %39, i8*** %3
br label %40
40: ; preds = %34, %27
%41 = load i8**, i8*** %3
ret i8** %41
}

LLVM IR (-O2):
define i8** @tokenize(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i8** (...) @newbuf()
store i8* %0, i8** %3
%6 = getelementptr inbounds i8, i8* %0, i64 %1
%7 = icmp sgt i64 %1, 0
br i1 %7, label %8, label %21
8: ; preds = %2, %16
%9 = phi i64 [ %11, %16 ], [ 0, %2 ]
%10 = phi i8** [ %12, %16 ], [ %5, %2 ]
%11 = add i64 %9, 1
%12 = call i8** @sizeset(i8** %10, i64 %11)
%13 = call i8* @getarg(i8** %3)
%14 = getelementptr inbounds i8*, i8** %12, i64 %9
store i8* %13, i8** %14
%15 = icmp eq i8* %13, null
br i1 %15, label %19, label %16
16: ; preds = %8
%17 = load i8*, i8** %3
%18 = icmp ult i8* %17, %6
br i1 %18, label %8, label %21
19: ; preds = %8
%20 = call i32 @free(i8** %12)
br label %26
21: ; preds = %16, %2
%22 = phi i8** [ %5, %2 ], [ %12, %16 ]
%23 = phi i64 [ 0, %2 ], [ %11, %16 ]
%24 = getelementptr inbounds i8*, i8** %22, i64 %23
store i8* null, i8** %24
%25 = load i8*, i8** %3
store i8 0, i8* %25
br label %26
26: ; preds = %21, %19
%27 = phi i8** [ null, %19 ], [ %22, %21 ]
ret i8** %27
}