#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 *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
char *tokquote(char *, char *);
char *tokquote_r(char *, char *, char **);
int strtok_freebsd_tests(void) {
  char blah[80], test[80];
  char *brkb, *brkt, *phrase, *sep, *word;
  sep = "\\/:;=-";
  phrase = "foo";
  printf("String tokenizer test:\n");
  strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function.");
  for (word = tokquote(test, sep); word; word = tokquote(NULL, sep))
    printf("Next word is \"%s\".\n", word);
  strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function.");
  for (word = tokquote_r(test, sep, &brkt); word;
       word = tokquote_r(NULL, sep, &brkt)) {
    strcpy(blah, "blah:blat:blab:blag");
    for (phrase = tokquote_r(blah, sep, &brkb); phrase;
         phrase = tokquote_r(NULL, sep, &brkb))
      printf("So far we're at %s:%s\n", word, phrase);
  }
  return (0);
}


x86 assembly (clang, -O0):
<strtok_freebsd_tests>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
lea    0xeae(%rip),%rax
mov    %rax,-0xc0(%rbp)
lea    0xea7(%rip),%rax
mov    %rax,-0xb8(%rbp)
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0xa0(%rbp),%rdi
mov    -0xc0(%rbp),%rsi
call   1060 <tokquote@plt>
mov    %rax,-0xc8(%rbp)
cmpq   $0x0,-0xc8(%rbp)
je     11e1 <strtok_freebsd_tests+0xa1>
mov    -0xc8(%rbp),%rsi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc0(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <tokquote@plt>
mov    %rax,-0xc8(%rbp)
jmp    11a2 <strtok_freebsd_tests+0x62>
lea    -0xa0(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0xa0(%rbp),%rdi
mov    -0xc0(%rbp),%rsi
lea    -0xb0(%rbp),%rdx
call   1050 <tokquote_r@plt>
mov    %rax,-0xc8(%rbp)
cmpq   $0x0,-0xc8(%rbp)
je     12c6 <strtok_freebsd_tests+0x186>
lea    -0x50(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x50(%rbp),%rdi
mov    -0xc0(%rbp),%rsi
lea    -0xa8(%rbp),%rdx
call   1050 <tokquote_r@plt>
mov    %rax,-0xb8(%rbp)
cmpq   $0x0,-0xb8(%rbp)
je     129e <strtok_freebsd_tests+0x15e>
mov    -0xc8(%rbp),%rsi
mov    -0xb8(%rbp),%rdx
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc0(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0xa8(%rbp),%rdx
call   1050 <tokquote_r@plt>
mov    %rax,-0xb8(%rbp)
jmp    1251 <strtok_freebsd_tests+0x111>
jmp    12a3 <strtok_freebsd_tests+0x163>
mov    -0xc0(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0xb0(%rbp),%rdx
call   1050 <tokquote_r@plt>
mov    %rax,-0xc8(%rbp)
jmp    1215 <strtok_freebsd_tests+0xd5>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtok_freebsd_tests>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
lea    0xf0f(%rip),%rdi
call   1040 <puts@plt>
lea    0xe93(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe78(%rip),%rsi
mov    %rbx,%rdi
call   1070 <tokquote@plt>
test   %rax,%rax
je     11cc <strtok_freebsd_tests+0x7c>
lea    0xe9c(%rip),%rbx
lea    0xe5d(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
mov    %rbp,%rsi
call   1070 <tokquote@plt>
test   %rax,%rax
jne    11b0 <strtok_freebsd_tests+0x60>
lea    0xe34(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe19(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1060 <tokquote_r@plt>
test   %rax,%rax
je     1274 <strtok_freebsd_tests+0x124>
mov    %rax,%rbx
lea    0x60(%rsp),%r15
lea    0xdfa(%rip),%r12
lea    0x8(%rsp),%r13
mov    %rsp,%rbp
lea    0xe4b(%rip),%r14
jmp    1235 <strtok_freebsd_tests+0xe5>
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1060 <tokquote_r@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1274 <strtok_freebsd_tests+0x124>
mov    %r15,%rdi
lea    0xe0d(%rip),%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
nopw   0x0(%rax,%rax,1)
mov    %r12,%rsi
mov    %r13,%rdx
call   1060 <tokquote_r@plt>
test   %rax,%rax
je     1220 <strtok_freebsd_tests+0xd0>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
jmp    1250 <strtok_freebsd_tests+0x100>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"\\/:;=-\00"
@.str.1 = [4 x i8] c"foo\00"
@.str.2 = [24 x i8] c"String tokenizer test:\0A\00"
@.str.3 = [49 x i8] c"This;is.a:test:of=the/string\\tokenizer-function.\00"
@.str.4 = [20 x i8] c"Next word is \22%s\22.\0A\00"
@.str.5 = [20 x i8] c"blah:blat:blab:blag\00"
@.str.6 = [23 x i8] c"So far we're at %s:%s\0A\00"
define i32 @strtok_freebsd_tests() {
%1 = alloca [80 x i8]
%2 = alloca [80 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%12 = load i8*, i8** %6
%13 = call i8* @tokquote(i8* %11, i8* %12)
store i8* %13, i8** %7
br label %14
14: ; preds = %20, %0
%15 = load i8*, i8** %7
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = load i8*, i8** %7
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17
%21 = load i8*, i8** %6
%22 = call i8* @tokquote(i8* null, i8* %21)
store i8* %22, i8** %7
br label %14
23: ; preds = %14
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%25 = call i32 @strcpy(i8* %24, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%27 = load i8*, i8** %6
%28 = call i8* @tokquote_r(i8* %26, i8* %27, i8** %4)
store i8* %28, i8** %7
br label %29
29: ; preds = %49, %23
%30 = load i8*, i8** %7
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %52
32: ; preds = %29
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%34 = call i32 @strcpy(i8* %33, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%35 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%36 = load i8*, i8** %6
%37 = call i8* @tokquote_r(i8* %35, i8* %36, i8** %3)
store i8* %37, i8** %5
br label %38
38: ; preds = %45, %32
%39 = load i8*, i8** %5
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %48
41: ; preds = %38
%42 = load i8*, i8** %7
%43 = load i8*, i8** %5
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %42, i8* %43)
br label %45
45: ; preds = %41
%46 = load i8*, i8** %6
%47 = call i8* @tokquote_r(i8* null, i8* %46, i8** %3)
store i8* %47, i8** %5
br label %38
48: ; preds = %38
br label %49
49: ; preds = %48
%50 = load i8*, i8** %6
%51 = call i8* @tokquote_r(i8* null, i8* %50, i8** %4)
store i8* %51, i8** %7
br label %29
52: ; preds = %29
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"\\/:;=-\00"
@.str.3 = [49 x i8] c"This;is.a:test:of=the/string\\tokenizer-function.\00"
@.str.4 = [20 x i8] c"Next word is \22%s\22.\0A\00"
@.str.5 = [20 x i8] c"blah:blat:blab:blag\00"
@.str.6 = [23 x i8] c"So far we're at %s:%s\0A\00"
@str = [23 x i8] c"String tokenizer test:\00"
define i32 @strtok_freebsd_tests() {
%1 = alloca [80 x i8]
%2 = alloca [80 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%7 = bitcast i8** %3 to i8*
%8 = bitcast i8** %4 to i8*
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%10 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
%11 = call i8* @tokquote(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %18, label %13
13: ; preds = %0, %13
%14 = phi i8* [ %16, %13 ], [ %11, %0 ]
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %14)
%16 = call i8* @tokquote(i8* null, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %13
18: ; preds = %13, %0
%19 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
%20 = call i8* @tokquote_r(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %4)
%21 = icmp eq i8* %20, null
br i1 %21, label %35, label %22
22: ; preds = %18, %32
%23 = phi i8* [ %33, %32 ], [ %20, %18 ]
%24 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%25 = call i8* @tokquote_r(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %3)
%26 = icmp eq i8* %25, null
br i1 %26, label %32, label %27
27: ; preds = %22, %27
%28 = phi i8* [ %30, %27 ], [ %25, %22 ]
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %23, i8* %28)
%30 = call i8* @tokquote_r(i8* null, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %3)
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %27
32: ; preds = %27, %22
%33 = call i8* @tokquote_r(i8* null, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %4)
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %22
35: ; preds = %32, %18
ret i32 0
}