#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 const *);
char *strtok(char *, char *);
int add_parameters(const char *input, char ***params) {
  int i;
  char *piece;
  char *input_copy = strdup(input);
  piece = strtok(input_copy, " ");
  if (piece == NULL)
    return 0;
  (*params)[1] = piece;
  for (i = 2; i < 1024 && piece != NULL; i++) {
    piece = strtok(NULL, " ");
    if (piece == NULL)
      break;
    (*params)[i] = piece;
  }
  return (i - 1);
}


x86 assembly (clang, -O0):
<add_parameters>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xeb8(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1168 <add_parameters+0x48>
movl   $0x0,-0x4(%rbp)
jmp    11f9 <add_parameters+0xd9>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rcx,0x8(%rax)
movl   $0x2,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x400,-0x1c(%rbp)
mov    %al,-0x31(%rbp)
jge    119b <add_parameters+0x7b>
cmpq   $0x0,-0x28(%rbp)
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11ab <add_parameters+0x8b>
jmp    11f0 <add_parameters+0xd0>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe4a(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11cf <add_parameters+0xaf>
jmp    11f0 <add_parameters+0xd0>
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117e <add_parameters+0x5e>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_parameters>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
call   1040 <strdup@plt>
lea    0xecc(%rip),%rsi
mov    %rax,%rdi
call   1030 <strtok@plt>
test   %rax,%rax
je     118a <add_parameters+0x6a>
mov    (%r14),%rcx
mov    %rax,0x8(%rcx)
mov    $0x2,%ebx
lea    0xeac(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edi,%edi
mov    %r15,%rsi
call   1030 <strtok@plt>
test   %rax,%rax
je     118e <add_parameters+0x6e>
mov    (%r14),%rcx
mov    %rax,(%rcx,%rbx,8)
add    $0x1,%rbx
cmp    $0x400,%rbx
jne    1160 <add_parameters+0x40>
mov    $0x3ff,%ebx
jmp    1191 <add_parameters+0x71>
xor    %ebx,%ebx
jmp    1191 <add_parameters+0x71>
add    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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