#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 */
char *strtok(char *, char *);
char **urealloc(char **, int);
char *ustrdup(char *);
char **ps_parse_argv(char *cmd, size_t *pargc) {
  char **argv = NULL;
  int argc = 0;
  for (char *s = strtok(cmd, " \t"); s; s = strtok(NULL, " \t")) {
    argv = urealloc(argv, (++argc + 1) * sizeof *argv);
    argv[argc - 1] = ustrdup(s);
  }
  argv[argc] = NULL;
  *pargc = argc;
  return argv;
}


x86 assembly (clang, -O0):
<ps_parse_argv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11c5 <ps_parse_argv+0x95>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1050 <urealloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <ustrdup@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe49(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    1163 <ps_parse_argv+0x33>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
movslq -0x1c(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ps_parse_argv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,(%rsp)
lea    0xeba(%rip),%r15
mov    %r15,%rsi
call   1030 <strtok@plt>
mov    %rax,%rbx
mov    $0x10,%ebp
xor    %r14d,%r14d
xor    %r12d,%r12d
nopl   0x0(%rax)
mov    %r14,%r13
add    $0x1,%r14
mov    %r12,%rdi
mov    %ebp,%esi
call   1050 <urealloc@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1040 <ustrdup@plt>
mov    %rax,(%r12,%r13,8)
xor    %edi,%edi
mov    %r15,%rsi
call   1030 <strtok@plt>
mov    %rax,%rbx
add    $0x8,%ebp
test   %rax,%rax
jne    1160 <ps_parse_argv+0x30>
mov    %r14d,%eax
movq   $0x0,(%r12,%rax,8)
mov    (%rsp),%rcx
mov    %rax,(%rcx)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c" \09\00"
define i8** @ps_parse_argv(i8* %0, i64* nocapture writeonly %1) {
%3 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp ne i8* %3, null
br label %8
5: ; preds = %8
%6 = and i64 %12, 4294967295
%7 = getelementptr inbounds i8*, i8** %16, i64 %6
store i8* null, i8** %7
store i64 %6, i64* %1
ret i8** %16
8: ; preds = %2, %8
%9 = phi i64 [ 0, %2 ], [ %12, %8 ]
%10 = phi i8* [ %3, %2 ], [ %19, %8 ]
%11 = phi i8** [ null, %2 ], [ %16, %8 ]
%12 = add nuw i64 %9, 1
%13 = trunc i64 %9 to i32
%14 = shl i32 %13, 3
%15 = add i32 %14, 16
%16 = tail call i8** @urealloc(i8** %11, i32 %15)
%17 = tail call i8* @ustrdup(i8* %10)
%18 = getelementptr inbounds i8*, i8** %16, i64 %9
store i8* %17, i8** %18
%19 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %5, label %8
}