#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*/ printf(char *, char *);
char *strdup(char *);
char *strtok(char *, char *);
void split_token(char *arg, char *split, char **out_tokens) {
  if (arg != NULL) {
    char *arg_copy = strdup(arg);
    out_tokens[0] = NULL;
    out_tokens[1] = NULL;
    char *token;
    token = strtok(arg_copy, split);
    printf("my %s\n", token);
    int t_i = 0;
    while (token != NULL && t_i < 2) {
      printf(" %s\n", token);
      out_tokens[t_i] = strdup(token);
      t_i = t_i + 1;
      printf("my2 %s\n", token);
      token = strtok(NULL, split);
      printf("my3 %s\n", token);
    }
  }
}


x86 assembly (clang, -O0):
<split_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1231 <split_token+0x101>
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x2c(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x2d(%rbp)
je     11b5 <split_token+0x85>
cmpl   $0x2,-0x2c(%rbp)
setl   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    11c5 <split_token+0x95>
jmp    122c <split_token+0xfc>
mov    -0x28(%rbp),%rsi
lea    0xe3a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe06(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xded(%rip),%rdi
call   1030 <printf@plt>
jmp    119b <split_token+0x6b>
jmp    1231 <split_token+0x101>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_token>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1208 <split_token+0xd8>
mov    %rdx,%r15
mov    %rsi,%r14
call   1050 <strdup@plt>
xorps  %xmm0,%xmm0
movups %xmm0,(%r15)
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strtok@plt>
mov    %rax,%rbx
lea    0xe9b(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
test   %rbx,%rbx
je     1208 <split_token+0xd8>
lea    0xe8d(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1050 <strdup@plt>
mov    %rax,(%r15)
lea    0xe70(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
mov    %rax,%rbx
lea    0xe5c(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
test   %rbx,%rbx
je     1208 <split_token+0xd8>
lea    0xe43(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1050 <strdup@plt>
mov    %rax,0x8(%r15)
lea    0xe25(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
lea    0xe14(%rip),%rdi
mov    %rax,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <printf@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"my %s\0A\00"
@.str.1 = [5 x i8] c" %s\0A\00"
@.str.2 = [8 x i8] c"my2 %s\0A\00"
@.str.3 = [8 x i8] c"my3 %s\0A\00"
define void @split_token(i8* %0, i8* nocapture %1, i8** nocapture writeonly %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %25, label %5
5: ; preds = %3
%6 = tail call i8* @strdup(i8* %0)
%7 = bitcast i8** %2 to i8*
%8 = tail call i8* @strtok(i8* %6, i8* %1)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = icmp eq i8* %8, null
br i1 %10, label %25, label %11
11: ; preds = %5
%12 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%13 = tail call i8* @strdup(i8* %8)
store i8* %13, i8** %2
%14 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%15 = tail call i8* @strtok(i8* null, i8* %1)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = icmp eq i8* %15, null
br i1 %17, label %25, label %18
18: ; preds = %11
%19 = getelementptr inbounds i8*, i8** %2, i64 1
%20 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%21 = tail call i8* @strdup(i8* %15)
store i8* %21, i8** %19
%22 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%23 = tail call i8* @strtok(i8* null, i8* %1)
%24 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %11, %18, %5, %3
ret void
}