#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*/ strcpy(char *, char *);
char *strtok(char *, char *);
int split_token(char trim[1024], char del[], int i) {
  char *s;
  int j = 0;
  s = strtok(trim, del);
  while (s != NULL && j <= i) {
    strcpy(trim, s);
    s = strtok(NULL, del);
    j = j + 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<split_token>:
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
mov    -0x10(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x25(%rbp)
je     1167 <split_token+0x47>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
setle  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1177 <split_token+0x57>
jmp    11a3 <split_token+0x83>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114b <split_token+0x2b>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_token>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
call   1040 <strtok@plt>
test   %rax,%rax
je     1174 <split_token+0x54>
test   %r14d,%r14d
js     1174 <split_token+0x54>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     1174 <split_token+0x54>
lea    0x1(%rbx),%ecx
cmp    %r14d,%ebx
mov    %ecx,%ebx
jl     1150 <split_token+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @split_token(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 = load i8*, i8** %5
%11 = call i8* @strtok(i8* %9, i8* %10)
store i8* %11, i8** %7
br label %12
12: ; preds = %21, %3
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* %8
%17 = load i32, i32* %6
%18 = icmp sle i32 %16, %17
br label %19
19: ; preds = %15, %12
%20 = phi i1 [ false, %12 ], [ %18, %15 ]
br i1 %20, label %21, label %29
21: ; preds = %19
%22 = load i8*, i8** %4
%23 = load i8*, i8** %7
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %5
%26 = call i8* @strtok(i8* null, i8* %25)
store i8* %26, i8** %7
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
br label %12
29: ; preds = %19
ret i32 0
}

LLVM IR (-O2):
define i32 @split_token(i8* %0, i8* nocapture %1, i32 %2) {
%4 = tail call i8* @strtok(i8* %0, i8* %1)
%5 = icmp ne i8* %4, null
%6 = icmp sgt i32 %2, -1
%7 = and i1 %5, %6
br i1 %7, label %8, label %17
8: ; preds = %3, %8
%9 = phi i32 [ %13, %8 ], [ 0, %3 ]
%10 = phi i8* [ %12, %8 ], [ %4, %3 ]
%11 = tail call i32 @strcpy(i8* %0, i8* %10)
%12 = tail call i8* @strtok(i8* null, i8* %1)
%13 = add nuw nsw i32 %9, 1
%14 = icmp ne i8* %12, null
%15 = icmp slt i32 %9, %2
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %8, label %17
17: ; preds = %8, %3
ret i32 0
}