#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 fig08_26() {
  char string[] = "This is a sentence with 7 tokens";
  char *tokenPtr;
  printf("%s\n%s\n\n%s\n", "The string to be tokenized is:", string,
         "The tokens are:");
  tokenPtr = strtok(string, " ");
  while (tokenPtr != NULL) {
    printf("%s\n", tokenPtr);
    tokenPtr = strtok(NULL, " ");
  }
}


x86 assembly (clang, -O0):
<fig08_26>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    -0x30(%rbp),%rdi
lea    0xebd(%rip),%rsi
mov    $0x21,%edx
call   1040 <memcpy@plt>
lea    -0x30(%rbp),%rdx
lea    0xec9(%rip),%rdi
lea    0xecd(%rip),%rsi
lea    0xee5(%rip),%rcx
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
lea    0xee3(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11b7 <fig08_26+0x87>
mov    -0x38(%rbp),%rsi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xeb2(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x38(%rbp)
jmp    1181 <fig08_26+0x51>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig08_26>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movaps 0xee2(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x20(%rsp)
lea    0xed7(%rip),%rdi
lea    0xedb(%rip),%rsi
lea    0xef3(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeef(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strtok@plt>
test   %rax,%rax
je     11ac <fig08_26+0x8c>
lea    0xea8(%rip),%r14
lea    0xed4(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
jne    1190 <fig08_26+0x70>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.fig08_26.string = [33 x i8] c"This is a sentence with 7 tokens\00"
@.str = [11 x i8] c"%s\0A%s\0A\0A%s\0A\00"
@.str.1 = [31 x i8] c"The string to be tokenized is:\00"
@.str.2 = [16 x i8] c"The tokens are:\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [4 x i8] c"%s\0A\00"
define void @fig08_26() {
%1 = alloca [33 x i8]
%2 = alloca i8*
%3 = bitcast [33 x i8]* %1 to i8*
%4 = getelementptr inbounds [33 x i8], [33 x i8]* %1, i64 0, i64 0
%5 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%6 = getelementptr inbounds [33 x i8], [33 x i8]* %1, i64 0, i64 0
%7 = call i8* @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, 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 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %12)
%14 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %14, i8** %2
br label %8
15: ; preds = %8
ret void
}

LLVM IR (-O2):
@__const.fig08_26.string = [33 x i8] c"This is a sentence with 7 tokens\00"
@.str = [11 x i8] c"%s\0A%s\0A\0A%s\0A\00"
@.str.1 = [31 x i8] c"The string to be tokenized is:\00"
@.str.2 = [16 x i8] c"The tokens are:\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [4 x i8] c"%s\0A\00"
define void @fig08_26() {
%1 = alloca [33 x i8]
%2 = getelementptr inbounds [33 x i8], [33 x i8]* %1, i64 0, i64 0
%3 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%4 = call i8* @strtok(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, 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 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%9 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %6
11: ; preds = %6, %0
ret void
}