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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rax
mov    %rax,-0xb8(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xeac(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x60(%rbp),%rdi
mov    -0xb8(%rbp),%rsi
lea    -0xd0(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0xc0(%rbp)
cmpq   $0x0,-0xc0(%rbp)
je     1233 <main+0x103>
lea    -0xb0(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0xb0(%rbp),%rdi
mov    -0xb8(%rbp),%rsi
lea    -0xd8(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0xc8(%rbp)
cmpq   $0x0,-0xc8(%rbp)
je     120b <main+0xdb>
mov    -0xc0(%rbp),%rsi
mov    -0xc8(%rbp),%rdx
lea    0xe69(%rip),%rdi
call   1040 <printf@plt>
mov    -0xb8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0xd8(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0xc8(%rbp)
jmp    11c0 <main+0x90>
jmp    1210 <main+0xe0>
mov    -0xb8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0xd0(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0xc0(%rbp)
jmp    117e <main+0x4e>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
lea    0xebf(%rip),%rsi
lea    0x60(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xea4(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1050 <strtok_r@plt>
test   %rax,%rax
je     11e2 <main+0xb2>
mov    %rax,%rbx
lea    0x10(%rsp),%r15
lea    0xe85(%rip),%r12
lea    0x8(%rsp),%r13
mov    %rsp,%rbp
lea    0xec2(%rip),%r14
jmp    11a5 <main+0x75>
nopl   0x0(%rax)
xor    %edi,%edi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1050 <strtok_r@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11e2 <main+0xb2>
mov    %r15,%rdi
lea    0xe89(%rip),%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
nopw   0x0(%rax,%rax,1)
mov    %r12,%rsi
mov    %r13,%rdx
call   1050 <strtok_r@plt>
test   %rax,%rax
je     1190 <main+0x60>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
xor    %edi,%edi
jmp    11c0 <main+0x90>
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 = [49 x i8] c"This;is.a:test:of=the/string\\tokenizer-function.\00"
@.str.2 = [20 x i8] c"blah:blat:blab:blag\00"
@.str.3 = [23 x i8] c"So far we're at %s:%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca [80 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %4
%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.1, i64 0, i64 0))
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%12 = load i8*, i8** %4
%13 = call i8* @strtok_r(i8* %11, i8* %12, i8** %7)
store i8* %13, i8** %5
br label %14
14: ; preds = %34, %0
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %37
17: ; preds = %14
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%19 = call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%21 = load i8*, i8** %4
%22 = call i8* @strtok_r(i8* %20, i8* %21, i8** %8)
store i8* %22, i8** %6
br label %23
23: ; preds = %30, %17
%24 = load i8*, i8** %6
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = load i8*, i8** %5
%28 = load i8*, i8** %6
%29 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %27, i8* %28)
br label %30
30: ; preds = %26
%31 = load i8*, i8** %4
%32 = call i8* @strtok_r(i8* null, i8* %31, i8** %8)
store i8* %32, i8** %6
br label %23
33: ; preds = %23
br label %34
34: ; preds = %33
%35 = load i8*, i8** %4
%36 = call i8* @strtok_r(i8* null, i8* %35, i8** %7)
store i8* %36, i8** %5
br label %14
37: ; preds = %14
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"\\/:;=-\00"
@.str.1 = [49 x i8] c"This;is.a:test:of=the/string\\tokenizer-function.\00"
@.str.2 = [20 x i8] c"blah:blat:blab:blag\00"
@.str.3 = [23 x i8] c"So far we're at %s:%s\0A\00"
define i32 @main() {
%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 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%10 = call i8* @strtok_r(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %3)
%11 = icmp eq i8* %10, null
br i1 %11, label %25, label %12
12: ; preds = %0, %22
%13 = phi i8* [ %23, %22 ], [ %10, %0 ]
%14 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%15 = call i8* @strtok_r(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %4)
%16 = icmp eq i8* %15, null
br i1 %16, label %22, label %17
17: ; preds = %12, %17
%18 = phi i8* [ %20, %17 ], [ %15, %12 ]
%19 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %13, i8* %18)
%20 = call i8* @strtok_r(i8* null, 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 %22, label %17
22: ; preds = %17, %12
%23 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %3)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %12
25: ; preds = %22, %0
ret i32 0
}