#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 str_split(char *input_string, const char token_delimiter, char **args) {
  int id_tok = 0;
  char delim[] = {token_delimiter, '\0'};
  char *token = strtok(input_string, delim);
  while (token != NULL) {
    args[id_tok] = strdup(token);
    token = strtok(0, delim);
    id_tok++;
  }
  args[id_tok] = NULL;
}


x86 assembly (clang, -O0):
<str_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x1e(%rbp)
movb   $0x0,-0x1d(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x1e(%rbp),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     119a <str_split+0x7a>
mov    -0x28(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
lea    -0x1e(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1030 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1158 <str_split+0x38>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_split>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %sil,0xe(%rsp)
movb   $0x0,0xf(%rsp)
lea    0xe(%rsp),%rsi
call   1030 <strtok@plt>
test   %rax,%rax
je     1173 <str_split+0x53>
xor    %ebx,%ebx
lea    0xe(%rsp),%r14
nopl   0x0(%rax)
mov    %rax,%rdi
call   1040 <strdup@plt>
mov    %rax,(%r15,%rbx,8)
xor    %edi,%edi
mov    %r14,%rsi
call   1030 <strtok@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1150 <str_split+0x30>
mov    %ebx,%eax
jmp    1175 <str_split+0x55>
xor    %eax,%eax
movq   $0x0,(%r15,%rax,8)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @str_split(i8* %0, i8 signext %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8**
%7 = alloca i32
%8 = alloca [2 x i8]
%9 = alloca i8*
store i8* %0, i8** %4
store i8 %1, i8* %5
store i8** %2, i8*** %6
store i32 0, i32* %7
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%11 = load i8, i8* %5
store i8 %11, i8* %10
%12 = getelementptr inbounds i8, i8* %10, i64 1
store i8 0, i8* %12
%13 = load i8*, i8** %4
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%15 = call i8* @strtok(i8* %13, i8* %14)
store i8* %15, i8** %9
br label %16
16: ; preds = %19, %3
%17 = load i8*, i8** %9
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %30
19: ; preds = %16
%20 = load i8*, i8** %9
%21 = call i8* @strdup(i8* %20)
%22 = load i8**, i8*** %6
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
store i8* %21, i8** %25
%26 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%27 = call i8* @strtok(i8* null, i8* %26)
store i8* %27, i8** %9
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %16
30: ; preds = %16
%31 = load i8**, i8*** %6
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
store i8* null, i8** %34
ret void
}

LLVM IR (-O2):
define void @str_split(i8* %0, i8 signext %1, i8** nocapture writeonly %2) {
%4 = alloca [2 x i8]
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
store i8 %1, i8* %5
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 0, i8* %6
%7 = call i8* @strtok(i8* %0, i8* %5)
%8 = icmp eq i8* %7, null
br i1 %8, label %19, label %9
9: ; preds = %3, %9
%10 = phi i64 [ %15, %9 ], [ 0, %3 ]
%11 = phi i8* [ %14, %9 ], [ %7, %3 ]
%12 = tail call i8* @strdup(i8* %11)
%13 = getelementptr inbounds i8*, i8** %2, i64 %10
store i8* %12, i8** %13
%14 = call i8* @strtok(i8* null, i8* %5)
%15 = add nuw i64 %10, 1
%16 = icmp eq i8* %14, null
br i1 %16, label %17, label %9
17: ; preds = %9
%18 = and i64 %15, 4294967295
br label %19
19: ; preds = %17, %3
%20 = phi i64 [ 0, %3 ], [ %18, %17 ]
%21 = getelementptr inbounds i8*, i8** %2, i64 %20
store i8* null, i8** %21
ret void
}