#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*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
char *strdup(char *);
char *strtok_r(char *, char *, char **);
int main(int argc, char **argv) {
  char *test = "/obix/test/testdevice/bool/////";
  char *src = NULL;
  char *token = NULL;
  char *reentrant_ptr;
  src = strdup(test);
  token = strtok_r(src, "/", &reentrant_ptr);
  if (token == NULL) {
    printf("%s: no token in provided string.\n");
    return -1;
  }
  do {
    printf("Token: %s\n", token);
  } while ((token = strtok_r(NULL, "/", &reentrant_ptr)) != NULL);
  free(src);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe95(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11bb <main+0x7b>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1204 <main+0xc4>
jmp    11c0 <main+0x80>
mov    -0x28(%rbp),%rsi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe41(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11c0 <main+0x80>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xeb1(%rip),%rdi
call   1060 <strdup@plt>
mov    %rax,%r14
lea    0xec0(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1050 <strtok_r@plt>
test   %rax,%rax
je     11ab <main+0x6b>
lea    0xecd(%rip),%r15
lea    0xea2(%rip),%r12
mov    %rsp,%rbx
nop
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <strtok_r@plt>
test   %rax,%rax
jne    1180 <main+0x40>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11be <main+0x7e>
lea    0xe6e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [32 x i8] c"/obix/test/testdevice/bool/////\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [34 x i8] c"%s: no token in provided string.\0A\00"
@.str.3 = [11 x i8] c"Token: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* null, i8** %7
store i8* null, i8** %8
%10 = load i8*, i8** %6
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = call i8* @strtok_r(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %9)
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %28
18: ; preds = %2
br label %19
19: ; preds = %22, %18
%20 = load i8*, i8** %8
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %19
%23 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %9)
store i8* %23, i8** %8
%24 = icmp ne i8* %23, null
br i1 %24, label %19, label %25
25: ; preds = %22
%26 = load i8*, i8** %7
%27 = call i32 @free(i8* %26)
store i32 0, i32* %3
br label %28
28: ; preds = %25, %16
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [32 x i8] c"/obix/test/testdevice/bool/////\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [34 x i8] c"%s: no token in provided string.\0A\00"
@.str.3 = [11 x i8] c"Token: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call dereferenceable_or_null(32) i8* @strdup(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%6 = call i8* @strtok_r(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %3)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %17
10: ; preds = %2, %10
%11 = phi i8* [ %13, %10 ], [ %6, %2 ]
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%13 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %3)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %10
15: ; preds = %10
%16 = call i32 @free(i8* %5)
br label %17
17: ; preds = %15, %8
%18 = phi i32 [ -1, %8 ], [ 0, %15 ]
ret i32 %18
}