#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 *strdup(char *);
char *strtok(char *, char *);
void ReadSubCommand(char *in, char **argv, int size) {
  char *p;
  char *delim = " ";
  p = strtok(in, delim);
  int i = 0;
  for (i = 0; i < size - 1; i++) {
    argv[i] = strdup(p);
    p = strtok(NULL, delim);
    if (p == NULL)
      break;
  }
  if (argv[i] != NULL) {
    argv[i + 1] = NULL;
  }
}


x86 assembly (clang, -O0):
<ReadSubCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    0xec6(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ba <ReadSubCommand+0x9a>
mov    -0x20(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1030 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a7 <ReadSubCommand+0x87>
jmp    11ba <ReadSubCommand+0x9a>
jmp    11ac <ReadSubCommand+0x8c>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    115d <ReadSubCommand+0x3d>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11e2 <ReadSubCommand+0xc2>
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadSubCommand>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r12
lea    0xecb(%rip),%rsi
call   1030 <strtok@plt>
xor    %ebp,%ebp
cmp    $0x2,%r14d
jl     1187 <ReadSubCommand+0x67>
add    $0xffffffff,%r14d
mov    %r14d,%ebx
xor    %ebp,%ebp
lea    0xeae(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%rdi
call   1040 <strdup@plt>
mov    %rax,(%r12,%rbp,8)
xor    %edi,%edi
mov    %r15,%rsi
call   1030 <strtok@plt>
test   %rax,%rax
je     1187 <ReadSubCommand+0x67>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1160 <ReadSubCommand+0x40>
mov    %r14d,%ebp
mov    %ebp,%eax
cmpq   $0x0,(%r12,%rax,8)
je     1199 <ReadSubCommand+0x79>
movq   $0x0,0x8(%r12,%rax,8)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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