#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 **calloc(int, int);
char **realloc(char **, int);
char *strsep(char **, char *);
int split_args(char *line, char ***argp) {
  int argc = 0;
  char *p, **argv;
  if ((argv = calloc(100 + 1, sizeof(char *))) == NULL)
    return -1;
  while ((p = strsep(&line, " \t\r\n")) != NULL) {
    argv[argc++] = p;
    if (argc == 100)
      break;
  }
  argv = realloc(argv, (argc + 1) * sizeof(char *));
  *argp = argv;
  return argc;
}


x86 assembly (clang, -O0):
<split_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x65,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1170 <split_args+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ed <split_args+0xbd>
jmp    1175 <split_args+0x45>
lea    -0x10(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1040 <strsep@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11c1 <split_args+0x91>
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
cmpl   $0x64,-0x1c(%rbp)
jne    11bc <split_args+0x8c>
jmp    11c1 <split_args+0x91>
jmp    1175 <split_args+0x45>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_args>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,0x8(%rsp)
mov    $0x65,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
test   %rax,%rax
je     11a7 <split_args+0x77>
mov    %rax,%r15
xor    %ebx,%ebx
lea    0xe9b(%rip),%r12
lea    0x8(%rsp),%r13
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <strsep@plt>
test   %rax,%rax
je     1193 <split_args+0x63>
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    1170 <split_args+0x40>
mov    $0x64,%ebx
lea    0x8(,%rbx,8),%esi
mov    %r15,%rdi
call   1050 <realloc@plt>
mov    %rax,(%r14)
jmp    11ac <split_args+0x7c>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c" \09\0D\0A\00"
define i32 @split_args(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
store i32 0, i32* %6
%9 = call i8** @calloc(i32 101, i32 8)
store i8** %9, i8*** %8
%10 = icmp eq i8** %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %38
12: ; preds = %2
br label %13
13: ; preds = %26, %12
%14 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %27
16: ; preds = %13
%17 = load i8*, i8** %7
%18 = load i8**, i8*** %8
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8*, i8** %18, i64 %21
store i8* %17, i8** %22
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 100
br i1 %24, label %25, label %26
25: ; preds = %16
br label %27
26: ; preds = %16
br label %13
27: ; preds = %25, %13
%28 = load i8**, i8*** %8
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 8
%33 = trunc i64 %32 to i32
%34 = call i8** @realloc(i8** %28, i32 %33)
store i8** %34, i8*** %8
%35 = load i8**, i8*** %8
%36 = load i8***, i8**** %5
store i8** %35, i8*** %36
%37 = load i32, i32* %6
store i32 %37, i32* %3
br label %38
38: ; preds = %27, %11
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [5 x i8] c" \09\0D\0A\00"
define i32 @split_args(i8* %0, i8*** nocapture writeonly %1) {
%3 = alloca i8*
store i8* %0, i8** %3
%4 = tail call i8** @calloc(i32 101, i32 8)
%5 = icmp eq i8** %4, null
br i1 %5, label %21, label %6
6: ; preds = %2, %10
%7 = phi i64 [ %11, %10 ], [ 0, %2 ]
%8 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = add nuw nsw i64 %7, 1
%12 = getelementptr inbounds i8*, i8** %4, i64 %7
store i8* %8, i8** %12
%13 = icmp eq i64 %11, 100
br i1 %13, label %16, label %6
14: ; preds = %6
%15 = trunc i64 %7 to i32
br label %16
16: ; preds = %10, %14
%17 = phi i32 [ %15, %14 ], [ 100, %10 ]
%18 = shl i32 %17, 3
%19 = add i32 %18, 8
%20 = call i8** @realloc(i8** %4, i32 %19)
store i8** %20, i8*** %1
br label %21
21: ; preds = %2, %16
%22 = phi i32 [ %17, %16 ], [ -1, %2 ]
ret i32 %22
}