#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 hooks_build_argv(char *cmd, char **result) {
  unsigned int i;
  for (i = 0; i < 128; i++, cmd = NULL) {
    result[i] = strtok(cmd, " \t\r\n");
    if (result[i] == NULL)
      break;
  }
  result[128 - 1] = NULL;
}


x86 assembly (clang, -O0):
<hooks_build_argv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x80,-0x14(%rbp)
jae    1184 <hooks_build_argv+0x74>
mov    -0x8(%rbp),%rdi
lea    0xec1(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
cmpq   $0x0,(%rax,%rcx,8)
jne    1169 <hooks_build_argv+0x59>
jmp    1184 <hooks_build_argv+0x74>
jmp    116e <hooks_build_argv+0x5e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movq   $0x0,-0x8(%rbp)
jmp    1127 <hooks_build_argv+0x17>
mov    -0x10(%rbp),%rax
movq   $0x0,0x3f8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hooks_build_argv>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
lea    0xee1(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     1160 <hooks_build_argv+0x50>
mov    $0x1,%ebx
lea    0xec8(%rip),%r14
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r14,%rsi
call   1030 <strtok@plt>
mov    %rax,(%r15,%rbx,8)
test   %rax,%rax
je     1160 <hooks_build_argv+0x50>
lea    0x1(%rbx),%rax
cmp    $0x7f,%rbx
mov    %rax,%rbx
jne    1140 <hooks_build_argv+0x30>
movq   $0x0,0x3f8(%r15)
pop    %rbx
pop    %r14
pop    %r15
ret

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

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