#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 */
char *lsftp_s_skip(char const *, char const *);
char *lsftp_s_skipn(char const *, char const *);
char *strdup(char const *);
const char *lsftp_s_strtok(const char *s, const char *sep, char **store) {
  const char *tend;
  char *scopy;
  *store = NULL;
  if (!s)
    return NULL;
  s = lsftp_s_skip(s, sep);
  if (!s || !(*s))
    return NULL;
  tend = lsftp_s_skipn(s, sep);
  scopy = strdup(s);
  if (!scopy)
    return NULL;
  scopy[tend - s] = 0;
  *store = scopy;
  return tend;
}


x86 assembly (clang, -O0):
<lsftp_s_strtok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
jne    1167 <lsftp_s_strtok+0x37>
movq   $0x0,-0x8(%rbp)
jmp    11f9 <lsftp_s_strtok+0xc9>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <lsftp_s_skip@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1190 <lsftp_s_strtok+0x60>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    119d <lsftp_s_strtok+0x6d>
movq   $0x0,-0x8(%rbp)
jmp    11f9 <lsftp_s_strtok+0xc9>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <lsftp_s_skipn@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11d3 <lsftp_s_strtok+0xa3>
movq   $0x0,-0x8(%rbp)
jmp    11f9 <lsftp_s_strtok+0xc9>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lsftp_s_strtok>:
push   %r15
push   %r14
push   %rbx
movq   $0x0,(%rdx)
test   %rdi,%rdi
je     1183 <lsftp_s_strtok+0x53>
mov    %rdx,%r14
mov    %rsi,%r15
call   1040 <lsftp_s_skip@plt>
test   %rax,%rax
je     1183 <lsftp_s_strtok+0x53>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     1183 <lsftp_s_strtok+0x53>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <lsftp_s_skipn@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <strdup@plt>
test   %rax,%rax
je     1183 <lsftp_s_strtok+0x53>
mov    %r15,%rcx
sub    %rbx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    %rax,(%r14)
jmp    1186 <lsftp_s_strtok+0x56>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @lsftp_s_strtok(i8* %0, i8* %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
%10 = load i8**, i8*** %7
store i8* null, i8** %10
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %3
store i8* null, i8** %4
br label %45
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = load i8*, i8** %6
%17 = call i8* @lsftp_s_skip(i8* %15, i8* %16)
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %20, %14
store i8* null, i8** %4
br label %45
25: ; preds = %20
%26 = load i8*, i8** %5
%27 = load i8*, i8** %6
%28 = call i8* @lsftp_s_skipn(i8* %26, i8* %27)
store i8* %28, i8** %8
%29 = load i8*, i8** %5
%30 = call i8* @strdup(i8* %29)
store i8* %30, i8** %9
%31 = load i8*, i8** %9
%32 = icmp ne i8* %31, null
br i1 %32, label %34, label %33
33: ; preds = %25
store i8* null, i8** %4
br label %45
34: ; preds = %25
%35 = load i8*, i8** %9
%36 = load i8*, i8** %8
%37 = load i8*, i8** %5
%38 = ptrtoint i8* %36 to i64
%39 = ptrtoint i8* %37 to i64
%40 = sub i64 %38, %39
%41 = getelementptr inbounds i8, i8* %35, i64 %40
store i8 0, i8* %41
%42 = load i8*, i8** %9
%43 = load i8**, i8*** %7
store i8* %42, i8** %43
%44 = load i8*, i8** %8
store i8* %44, i8** %4
br label %45
45: ; preds = %34, %33, %24, %13
%46 = load i8*, i8** %4
ret i8* %46
}

LLVM IR (-O2):
define i8* @lsftp_s_strtok(i8* %0, i8* %1, i8** nocapture writeonly %2) {
store i8* null, i8** %2
%4 = icmp eq i8* %0, null
br i1 %4, label %20, label %5
5: ; preds = %3
%6 = tail call i8* @lsftp_s_skip(i8* %0, i8* %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %20, label %8
8: ; preds = %5
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %8
%12 = tail call i8* @lsftp_s_skipn(i8* %6, i8* %1)
%13 = tail call i8* @strdup(i8* %6)
%14 = icmp eq i8* %13, null
br i1 %14, label %20, label %15
15: ; preds = %11
%16 = ptrtoint i8* %12 to i64
%17 = ptrtoint i8* %6 to i64
%18 = sub i64 %16, %17
%19 = getelementptr inbounds i8, i8* %13, i64 %18
store i8 0, i8* %19
store i8* %13, i8** %2
br label %20
20: ; preds = %11, %5, %8, %3, %15
%21 = phi i8* [ %12, %15 ], [ null, %3 ], [ null, %8 ], [ null, %5 ], [ null, %11 ]
ret i8* %21
}