#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*/ snprintf(char *, int, char *, char *);
char *strtok(char *, char *);
void str_token(char *dest, int dest_size, char *src, int index, char *delim) {
  char buf[200];
  char *token;
  int i;
  snprintf(buf, sizeof buf, "%s", src);
  token = strtok(buf, delim);
  for (i = 0; i < index; i++)
    token = strtok(NULL, delim);
  snprintf(dest, dest_size, "%s", token);
}


x86 assembly (clang, -O0):
<str_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
lea    -0xf0(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0xc8,%esi
lea    0xeac(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0xf0(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0xf8(%rbp)
movl   $0x0,-0xfc(%rbp)
mov    -0xfc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b1 <str_token+0x91>
mov    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0xf8(%rbp)
mov    -0xfc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfc(%rbp)
jmp    117a <str_token+0x5a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0xf8(%rbp),%rcx
lea    0xe3a(%rip),%rdx
call   1030 <snprintf@plt>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_token>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xd0,%rsp
mov    %r8,%rbp
mov    %ecx,%ebx
mov    %rdx,%rcx
mov    %esi,%r14d
mov    %rdi,%r15
lea    0xebc(%rip),%rdx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0xc8,%esi
call   1030 <snprintf@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1040 <strtok@plt>
test   %ebx,%ebx
jle    117f <str_token+0x5f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %edi,%edi
mov    %rbp,%rsi
call   1040 <strtok@plt>
add    $0xffffffff,%ebx
jne    1170 <str_token+0x50>
lea    0xe7a(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rax,%rcx
call   1030 <snprintf@plt>
add    $0xd0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define void @str_token(i8* %0, i32 %1, i8* %2, i32 %3, i8* nocapture %4) {
%6 = alloca [200 x i8]
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%8 = call i32 @snprintf(i8* %7, i32 200, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%9 = call i8* @strtok(i8* %7, i8* %4)
%10 = icmp sgt i32 %3, 0
br i1 %10, label %11, label %16
11: ; preds = %5, %11
%12 = phi i32 [ %14, %11 ], [ 0, %5 ]
%13 = call i8* @strtok(i8* null, i8* %4)
%14 = add nuw nsw i32 %12, 1
%15 = icmp eq i32 %14, %3
br i1 %15, label %16, label %11
16: ; preds = %11, %5
%17 = phi i8* [ %9, %5 ], [ %13, %11 ]
%18 = call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %17)
ret void
}