#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*/ clean_line(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *wstrtok(char *s, char *t) {
  static char buf[1024];
  static char buf2[1024];
  static char emptystr[16];
  static int len;
  int j, i;
  emptystr[0] = '\0';
  if (s != NULL) {
    strcpy(buf, s);
    len = strlen(buf);
    i = 0;
  } else
    i = strlen(buf) + 1;
  if (i >= len)
    return (emptystr);
  j = i;
  if (i > 0)
    buf[i - 1] = t[0];
  for (; buf[i] != '\0' && buf[i] != t[0]; i++)
    ;
  buf[i] = '\0';
  strcpy(buf2, &buf[j]);
  clean_line(buf2);
  return (buf2);
}


x86 assembly (clang, -O0):
<wstrtok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movb   $0x0,0x3709(%rip)
cmpq   $0x0,-0x10(%rbp)
je     1180 <wstrtok+0x50>
mov    -0x10(%rbp),%rsi
lea    0x2ef3(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2ee7(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,0x36ec(%rip)
movl   $0x0,-0x20(%rbp)
jmp    1192 <wstrtok+0x62>
lea    0x2ec9(%rip),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    0x36c5(%rip),%eax
jl     11b1 <wstrtok+0x81>
lea    0x36a8(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    127d <wstrtok+0x14d>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    11da <wstrtok+0xaa>
mov    -0x18(%rbp),%rax
mov    (%rax),%dl
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e79(%rip),%rax
mov    %dl,(%rax,%rcx,1)
jmp    11df <wstrtok+0xaf>
movslq -0x20(%rbp),%rcx
lea    0x2e66(%rip),%rax
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     121a <wstrtok+0xea>
movslq -0x20(%rbp),%rcx
lea    0x2e49(%rip),%rax
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    122a <wstrtok+0xfa>
jmp    123d <wstrtok+0x10d>
jmp    122f <wstrtok+0xff>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11df <wstrtok+0xaf>
movslq -0x20(%rbp),%rcx
lea    0x2e08(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
movslq -0x1c(%rbp),%rax
lea    0x2df9(%rip),%rsi
add    %rax,%rsi
lea    0x31ef(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x31e3(%rip),%rdi
call   1050 <clean_line@plt>
lea    0x31d7(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wstrtok>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
movb   $0x0,0x3711(%rip)
test   %rdi,%rdi
je     116c <wstrtok+0x3c>
mov    %rdi,%rsi
lea    0x2f02(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,0x36fc(%rip)
xor    %ecx,%ecx
test   %eax,%eax
jg     1193 <wstrtok+0x63>
jmp    11de <wstrtok+0xae>
lea    0x2edd(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%ecx
cmp    0x36dc(%rip),%ecx
jge    11de <wstrtok+0xae>
test   %eax,%eax
js     1193 <wstrtok+0x63>
mov    (%r15),%dl
mov    %eax,%eax
mov    %dl,(%rax,%r14,1)
movslq %ecx,%rax
lea    0x2eb3(%rip),%rcx
lea    (%rcx,%rax,1),%rsi
mov    (%rax,%rcx,1),%dl
test   %dl,%dl
je     11c1 <wstrtok+0x91>
mov    (%r15),%bl
nopl   0x0(%rax,%rax,1)
cmp    %bl,%dl
je     11c1 <wstrtok+0x91>
movzbl 0x1(%rax,%rcx,1),%edx
add    $0x1,%rax
test   %dl,%dl
jne    11b0 <wstrtok+0x80>
movb   $0x0,(%rax,%rcx,1)
lea    0x3284(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <clean_line@plt>
jmp    11e5 <wstrtok+0xb5>
lea    0x366b(%rip),%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@wstrtok.buf = internal global [1024 x i8] zeroinitializer
@wstrtok.buf2 = internal global [1024 x i8] zeroinitializer
@wstrtok.emptystr = internal global [16 x i8] zeroinitializer
@wstrtok.len = internal global i32 0
define i8* @wstrtok(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8 0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @wstrtok.emptystr, i64 0, i64 0)
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i32 @strcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @wstrtok.buf, i64 0, i64 0), i8* %11)
%13 = call i32 @strlen(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @wstrtok.buf, i64 0, i64 0))
store i32 %13, i32* @wstrtok.len
store i32 0, i32* %7
br label %17
14: ; preds = %2
%15 = call i32 @strlen(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @wstrtok.buf, i64 0, i64 0))
%16 = add nsw i32 %15, 1
store i32 %16, i32* %7
br label %17
17: ; preds = %14, %10
%18 = load i32, i32* %7
%19 = load i32, i32* @wstrtok.len
%20 = icmp sge i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @wstrtok.emptystr, i64 0, i64 0), i8** %3
br label %68
22: ; preds = %17
%23 = load i32, i32* %7
store i32 %23, i32* %6
%24 = load i32, i32* %7
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %22
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = load i8, i8* %28
%30 = load i32, i32* %7
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* @wstrtok.buf, i64 0, i64 %32
store i8 %29, i8* %33
br label %34
34: ; preds = %26, %22
br label %35
35: ; preds = %56, %34
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* @wstrtok.buf, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %53
42: ; preds = %35
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* @wstrtok.buf, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i64 0
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %47, %51
br label %53
53: ; preds = %42, %35
%54 = phi i1 [ false, %35 ], [ %52, %42 ]
br i1 %54, label %55, label %59
55: ; preds = %53
br label %56
56: ; preds = %55
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 1
store i32 %58, i32* %7
br label %35
59: ; preds = %53
%60 = load i32, i32* %7
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* @wstrtok.buf, i64 0, i64 %61
store i8 0, i8* %62
%63 = load i32, i32* %6
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* @wstrtok.buf, i64 0, i64 %64
%66 = call i32 @strcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @wstrtok.buf2, i64 0, i64 0), i8* %65)
%67 = call i32 @clean_line(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @wstrtok.buf2, i64 0, i64 0))
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @wstrtok.buf2, i64 0, i64 0), i8** %3
br label %68
68: ; preds = %59, %21
%69 = load i8*, i8** %3
ret i8* %69
}

LLVM IR (-O2):
@wstrtok.buf = internal global [1024 x i8] zeroinitializer
@wstrtok.buf2 = internal global [1024 x i8] zeroinitializer
@wstrtok.emptystr = internal global [16 x i8] zeroinitializer
@wstrtok.len = internal unnamed_addr global i32 0
define i8* @wstrtok(i8* %0, i8* nocapture %1) {
store i8 0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @wstrtok.emptystr, i64 0, i64 0)
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @wstrtok.buf, i64 0, i64 0))
%6 = add nsw i32 %5, 1
%7 = load i32, i32* @wstrtok.len
%8 = icmp slt i32 %6, %7
br i1 %8, label %13, label %41
9: ; preds = %2
%10 = tail call i32 @strcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @wstrtok.buf, i64 0, i64 0), i8* %0)
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @wstrtok.buf, i64 0, i64 0))
store i32 %11, i32* @wstrtok.len
%12 = icmp sgt i32 %11, 0
br i1 %12, label %19, label %41
13: ; preds = %4
%14 = icmp sgt i32 %5, -1
br i1 %14, label %15, label %19
15: ; preds = %13
%16 = load i8, i8* %1
%17 = zext i32 %5 to i64
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* @wstrtok.buf, i64 0, i64 %17
store i8 %16, i8* %18
br label %19
19: ; preds = %9, %15, %13
%20 = phi i32 [ %6, %15 ], [ %6, %13 ], [ 0, %9 ]
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* @wstrtok.buf, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %36, label %25
25: ; preds = %19
%26 = load i8, i8* %1
br label %31
27: ; preds = %31
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* @wstrtok.buf, i64 0, i64 %35
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %25, %27
%32 = phi i64 [ %21, %25 ], [ %35, %27 ]
%33 = phi i8 [ %23, %25 ], [ %29, %27 ]
%34 = icmp eq i8 %33, %26
%35 = add i64 %32, 1
br i1 %34, label %36, label %27
36: ; preds = %31, %27, %19
%37 = phi i64 [ %21, %19 ], [ %35, %27 ], [ %32, %31 ]
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* @wstrtok.buf, i64 0, i64 %37
store i8 0, i8* %38
%39 = tail call i32 @strcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @wstrtok.buf2, i64 0, i64 0), i8* %22)
%40 = tail call i32 @clean_line(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @wstrtok.buf2, i64 0, i64 0))
br label %41
41: ; preds = %9, %4, %36
%42 = phi i8* [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @wstrtok.buf2, i64 0, i64 0), %36 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @wstrtok.emptystr, i64 0, i64 0), %4 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @wstrtok.emptystr, i64 0, i64 0), %9 ]
ret i8* %42
}