#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 *);
void cmd_build_args(char *str, int *argc, char **argv) {
  int i;
  char *token;
  for (i = 1; i < 128; i++, str = NULL) {
    token = strtok(str, " \t\r\n");
    if (token == NULL)
      break;
    argv[i - 1] = token;
  }
  argv[i - 1] = NULL;
  *argc = i - 1;
}


x86 assembly (clang, -O0):
<cmd_build_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x80,-0x1c(%rbp)
jge    1187 <cmd_build_args+0x77>
mov    -0x8(%rbp),%rdi
lea    0xebd(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    115c <cmd_build_args+0x4c>
jmp    1187 <cmd_build_args+0x77>
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movq   $0x0,-0x8(%rbp)
jmp    112b <cmd_build_args+0x1b>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_build_args>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
xor    %ebx,%ebx
lea    0xed9(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rsi
call   1030 <strtok@plt>
test   %rax,%rax
je     1155 <cmd_build_args+0x45>
mov    %rax,(%r12,%rbx,8)
add    $0x1,%rbx
mov    $0x0,%edi
cmp    $0x7f,%rbx
jne    1130 <cmd_build_args+0x20>
mov    $0x7f,%ebx
movslq %ebx,%rax
movq   $0x0,(%r12,%rax,8)
mov    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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