#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 *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strtok(char *, char *);
int test_strtok(void) {
  char str[18];
  strcpy(str, "abc def ab:de");
  printf("\tstrtok");
  if (strcmp(strtok(str, " "), "abc"))
    return 1;
  if (strcmp(strtok(NULL, ": "), "def"))
    return 1;
  if (strcmp(strtok(NULL, "d:"), "ab"))
    return 1;
  if (strcmp(strtok(NULL, " "), "de"))
    return 1;
  printf("\tpassed.\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_strtok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x20(%rbp),%rdi
lea    0xead(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xeaf(%rip),%rdi
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
lea    0xeac(%rip),%rsi
call   1060 <strtok@plt>
mov    %eax,%edi
lea    0xe99(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1198 <test_strtok+0x58>
movl   $0x1,-0x4(%rbp)
jmp    1247 <test_strtok+0x107>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe77(%rip),%rsi
call   1060 <strtok@plt>
mov    %eax,%edi
lea    0xe6c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11cc <test_strtok+0x8c>
movl   $0x1,-0x4(%rbp)
jmp    1247 <test_strtok+0x107>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe4a(%rip),%rsi
call   1060 <strtok@plt>
mov    %eax,%edi
lea    0xe3f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1200 <test_strtok+0xc0>
movl   $0x1,-0x4(%rbp)
jmp    1247 <test_strtok+0x107>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe10(%rip),%rsi
call   1060 <strtok@plt>
mov    %eax,%edi
lea    0xdf2(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1234 <test_strtok+0xf4>
movl   $0x1,-0x4(%rbp)
jmp    1247 <test_strtok+0x107>
lea    0xdec(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strtok>:
push   %rbx
sub    $0x20,%rsp
lea    0xea4(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xea0(%rip),%rdi
call   1050 <printf@plt>
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strtok@plt>
lea    0xe8d(%rip),%rsi
mov    %eax,%edi
call   1060 <strcmp@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    120b <test_strtok+0xbb>
lea    0xe79(%rip),%rsi
xor    %edi,%edi
call   1070 <strtok@plt>
lea    0xe6e(%rip),%rsi
mov    %eax,%edi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    120b <test_strtok+0xbb>
lea    0xe5f(%rip),%rsi
xor    %edi,%edi
call   1070 <strtok@plt>
lea    0xe54(%rip),%rsi
mov    %eax,%edi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    120b <test_strtok+0xbb>
lea    0xe38(%rip),%rsi
xor    %edi,%edi
call   1070 <strtok@plt>
lea    0xe1a(%rip),%rsi
mov    %eax,%edi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    120b <test_strtok+0xbb>
lea    0xe23(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"abc def ab:de\00"
@.str.1 = [8 x i8] c"\09strtok\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [4 x i8] c"abc\00"
@.str.4 = [3 x i8] c": \00"
@.str.5 = [4 x i8] c"def\00"
@.str.6 = [3 x i8] c"d:\00"
@.str.7 = [3 x i8] c"ab\00"
@.str.8 = [3 x i8] c"de\00"
@.str.9 = [10 x i8] c"\09passed.\0A\00"
define i32 @test_strtok() {
%1 = alloca i32
%2 = alloca [18 x i8]
%3 = getelementptr inbounds [18 x i8], [18 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds [18 x i8], [18 x i8]* %2, i64 0, i64 0
%7 = call i32 @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = call i64 @strcmp(i32 %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 1, i32* %1
br label %28
11: ; preds = %0
%12 = call i32 @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%13 = call i64 @strcmp(i32 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 1, i32* %1
br label %28
16: ; preds = %11
%17 = call i32 @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%18 = call i64 @strcmp(i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 1, i32* %1
br label %28
21: ; preds = %16
%22 = call i32 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = call i64 @strcmp(i32 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 1, i32* %1
br label %28
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %1
br label %28
28: ; preds = %26, %25, %20, %15, %10
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str = [14 x i8] c"abc def ab:de\00"
@.str.1 = [8 x i8] c"\09strtok\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [4 x i8] c"abc\00"
@.str.4 = [3 x i8] c": \00"
@.str.5 = [4 x i8] c"def\00"
@.str.6 = [3 x i8] c"d:\00"
@.str.7 = [3 x i8] c"ab\00"
@.str.8 = [3 x i8] c"de\00"
@str = [9 x i8] c"\09passed.\00"
define i32 @test_strtok() {
%1 = alloca [18 x i8]
%2 = getelementptr inbounds [18 x i8], [18 x i8]* %1, i64 0, i64 0
%3 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @strtok(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%6 = call i64 @strcmp(i32 %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %22
8: ; preds = %0
%9 = call i32 @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%10 = call i64 @strcmp(i32 %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = call i32 @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%14 = call i64 @strcmp(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = call i32 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = call i64 @strcmp(i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %22
22: ; preds = %16, %12, %8, %0, %20
%23 = phi i32 [ 0, %20 ], [ 1, %0 ], [ 1, %8 ], [ 1, %12 ], [ 1, %16 ]
ret i32 %23
}