#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 *mystrcpy(char *, int);
int strlen(char *);
char *strtok(char *, char *);
void parse_input(char *buf, char **argv) {
  char *bufcpy = mystrcpy(buf, 1024);
  char *token = strtok(bufcpy, " ");
  int argc = 0;
  if (strlen(token)) {
    argv[argc] = mystrcpy(token, strlen(token) + 1);
  } else {
    argc--;
  }
  for (argc++; (token = strtok(NULL, " ")); argc++) {
    if (strlen(token)) {
      argv[argc] = mystrcpy(token, strlen(token) + 1);
    } else {
      argc--;
    }
  }
  free(bufcpy);
}


x86 assembly (clang, -O0):
<parse_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x400,%esi
call   1050 <mystrcpy@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
je     11c2 <parse_input+0x82>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
add    $0x1,%esi
call   1050 <mystrcpy@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11cb <parse_input+0x8b>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe21(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1253 <parse_input+0x113>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
je     1237 <parse_input+0xf7>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
add    $0x1,%esi
call   1050 <mystrcpy@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    1240 <parse_input+0x100>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1245 <parse_input+0x105>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d4 <parse_input+0x94>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_input>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    $0x400,%esi
call   1050 <mystrcpy@plt>
mov    %rax,%r14
lea    0xea1(%rip),%rsi
mov    %rax,%rdi
call   1060 <strtok@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     1193 <parse_input+0x53>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%esi
mov    %rbx,%rdi
call   1050 <mystrcpy@plt>
mov    %rax,(%r15)
mov    $0x1,%ebp
jmp    1195 <parse_input+0x55>
xor    %ebp,%ebp
lea    0xe64(%rip),%rsi
xor    %edi,%edi
call   1060 <strtok@plt>
test   %rax,%rax
je     1200 <parse_input+0xc0>
mov    %rax,%rbx
lea    0xe4e(%rip),%r12
jmp    11d8 <parse_input+0x98>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffff,%ebp
add    $0x1,%ebp
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1200 <parse_input+0xc0>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     11c0 <parse_input+0x80>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%esi
mov    %rbx,%rdi
call   1050 <mystrcpy@plt>
movslq %ebp,%rcx
mov    %rax,(%r15,%rcx,8)
jmp    11c3 <parse_input+0x83>
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define void @parse_input(i8* %0, i8** nocapture writeonly %1) {
%3 = tail call i8* @mystrcpy(i8* %0, i32 1024)
%4 = tail call i8* @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @strlen(i8* %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = tail call i32 @strlen(i8* %4)
%9 = add nsw i32 %8, 1
%10 = tail call i8* @mystrcpy(i8* %4, i32 %9)
store i8* %10, i8** %1
br label %11
11: ; preds = %2, %7
%12 = phi i32 [ 1, %7 ], [ 0, %2 ]
%13 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %33, label %15
15: ; preds = %11, %28
%16 = phi i8* [ %31, %28 ], [ %13, %11 ]
%17 = phi i32 [ %30, %28 ], [ %12, %11 ]
%18 = tail call i32 @strlen(i8* %16)
%19 = icmp eq i32 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %15
%21 = tail call i32 @strlen(i8* %16)
%22 = add nsw i32 %21, 1
%23 = tail call i8* @mystrcpy(i8* %16, i32 %22)
%24 = sext i32 %17 to i64
%25 = getelementptr inbounds i8*, i8** %1, i64 %24
store i8* %23, i8** %25
br label %28
26: ; preds = %15
%27 = add nsw i32 %17, -1
br label %28
28: ; preds = %20, %26
%29 = phi i32 [ %17, %20 ], [ %27, %26 ]
%30 = add nsw i32 %29, 1
%31 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %15
33: ; preds = %28, %11
%34 = tail call i32 @free(i8* %3)
ret void
}