#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 *strtok(char *, char *);
void strtokTest() {
  char str[] = "- This, a sample string.";
  char *pch;
  printf("Splitting string \"%s\" into tokens:\n", str);
  pch = strtok(str, " ,.-");
  while (pch != NULL) {
    printf("%s\n", pch);
    pch = strtok(NULL, " ,.-");
  }
  printf("\n%s\n", str);
}


x86 assembly (clang, -O0):
<strtokTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xece(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xecb(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xec9(%rip),%al
mov    %al,-0x8(%rbp)
lea    -0x20(%rbp),%rsi
lea    0xebc(%rip),%rdi
call   1030 <printf@plt>
lea    -0x20(%rbp),%rdi
lea    0xed0(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11aa <strtokTest+0x8a>
mov    -0x28(%rbp),%rsi
lea    0xeb7(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xea1(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    1176 <strtokTest+0x56>
lea    -0x20(%rbp),%rsi
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtokTest>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movups 0xedb(%rip),%xmm0
movups %xmm0,0x9(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xed4(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1030 <printf@plt>
lea    0xee6(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strtok@plt>
test   %rax,%rax
je     119a <strtokTest+0x7a>
lea    0xed8(%rip),%r14
lea    0xecb(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
jne    1180 <strtokTest+0x60>
lea    0xea1(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.strtokTest.str = [25 x i8] c"- This, a sample string.\00"
@.str = [36 x i8] c"Splitting string \22%s\22 into tokens:\0A\00"
@.str.1 = [5 x i8] c" ,.-\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [5 x i8] c"\0A%s\0A\00"
define void @strtokTest() {
%1 = alloca [25 x i8]
%2 = alloca i8*
%3 = bitcast [25 x i8]* %1 to i8*
%4 = getelementptr inbounds [25 x i8], [25 x i8]* %1, i64 0, i64 0
%5 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = getelementptr inbounds [25 x i8], [25 x i8]* %1, i64 0, i64 0
%7 = call i8* @strtok(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %7, i8** %2
br label %8
8: ; preds = %11, %0
%9 = load i8*, i8** %2
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i8*, i8** %2
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %14, i8** %2
br label %8
15: ; preds = %8
%16 = getelementptr inbounds [25 x i8], [25 x i8]* %1, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %16)
ret void
}

LLVM IR (-O2):
@__const.strtokTest.str = [25 x i8] c"- This, a sample string.\00"
@.str = [36 x i8] c"Splitting string \22%s\22 into tokens:\0A\00"
@.str.1 = [5 x i8] c" ,.-\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [5 x i8] c"\0A%s\0A\00"
define void @strtokTest() {
%1 = alloca [25 x i8]
%2 = getelementptr inbounds [25 x i8], [25 x i8]* %1, i64 0, i64 0
%3 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = call i8* @strtok(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %11, label %6
6: ; preds = %0, %6
%7 = phi i8* [ %9, %6 ], [ %4, %0 ]
%8 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%9 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %6
11: ; preds = %6, %0
%12 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %2)
ret void
}