#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
char *strtok(char *, char const *);
int makeargs(char *line, char *argv[], int maxargs) {
  static const char ws[] = " \t\r\n";
  char *cp;
  int argc = 0;
  for (cp = strtok(line, ws); cp; cp = strtok(NULL, ws)) {
    if (argc >= (maxargs - 1)) {
      fprintf(stderr, "Too many arguments to command\n");
      exit(1);
    }
    argv[argc++] = cp;
  }
  argv[argc] = NULL;
  return argc;
}


x86 assembly (clang, -O0):
<makeargs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeab(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11cc <makeargs+0x9c>
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jl     1199 <makeargs+0x69>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe42(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    115e <makeargs+0x2e>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeargs>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
lea    0xebb(%rip),%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     118e <makeargs+0x5e>
add    $0xffffffff,%r15d
xor    %ebx,%ebx
test   %r15d,%r15d
cmovle %ebx,%r15d
lea    0xe9d(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    %rbx,%r15
je     11a8 <makeargs+0x78>
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r12,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
jne    1170 <makeargs+0x40>
jmp    1190 <makeargs+0x60>
xor    %ebx,%ebx
mov    %ebx,%eax
movq   $0x0,(%r14,%rax,8)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@makeargs.ws = internal constant [5 x i8] c" \09\0D\0A\00"
@stderr = global i32 0
@.str = [31 x i8] c"Too many arguments to command\0A\00"
define i32 @makeargs(i8* %0, i8** nocapture writeonly %1, i32 %2) {
%4 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @makeargs.ws, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %25, label %6
6: ; preds = %3
%7 = add i32 %2, -1
%8 = call i32 @llvm.smax.i32(i32 %7, i32 0)
%9 = zext i32 %8 to i64
br label %10
10: ; preds = %6, %18
%11 = phi i64 [ 0, %6 ], [ %19, %18 ]
%12 = phi i8* [ %4, %6 ], [ %21, %18 ]
%13 = icmp eq i64 %11, %9
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = add nuw nsw i64 %11, 1
%20 = getelementptr inbounds i8*, i8** %1, i64 %11
store i8* %12, i8** %20
%21 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @makeargs.ws, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %10
23: ; preds = %18
%24 = trunc i64 %19 to i32
br label %25
25: ; preds = %23, %3
%26 = phi i32 [ 0, %3 ], [ %24, %23 ]
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %1, i64 %27
store i8* null, i8** %28
ret i32 %26
}