#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*/ strcspn(char *, char const *);
int strspn(char *, char const *);
char *cmdsep(char **stringp, const char *delim) {
  char *head = *stringp + strspn(*stringp, delim);
  char *tail = *stringp += strcspn(*stringp, delim);
  *stringp += strspn(*stringp, delim);
  if (!**stringp)
    *stringp = NULL;
  *tail = 0;
  return head;
}


x86 assembly (clang, -O0):
<cmdsep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strspn@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcspn@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rax
movslq %edx,%rdx
add    %rdx,%rax
mov    %rax,(%rcx)
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strspn@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
movslq %edx,%rdx
add    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
cmpb   $0x0,(%rax)
jne    11be <cmdsep+0x9e>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmdsep>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rdi),%rbx
mov    %rbx,%rdi
call   1030 <strspn@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcspn@plt>
movslq %eax,%r13
lea    (%rbx,%r13,1),%rbp
mov    %rbp,(%r14)
mov    %rbp,%rdi
mov    %r15,%rsi
call   1030 <strspn@plt>
cltq
lea    (%rax,%rbp,1),%rcx
mov    %rcx,(%r14)
xor    %edx,%edx
cmpb   $0x0,(%rax,%rbp,1)
cmovne %rcx,%rdx
mov    %rdx,(%r14)
movslq %r12d,%rax
add    %rbx,%rax
movb   $0x0,(%rbx,%r13,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @cmdsep(i8** nocapture %0, i8* nocapture %1) {
%3 = load i8*, i8** %0
%4 = tail call i32 @strspn(i8* %3, i8* %1)
%5 = tail call i32 @strcspn(i8* %3, i8* %1)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %3, i64 %6
store i8* %7, i8** %0
%8 = tail call i32 @strspn(i8* %7, i8* %1)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
store i8* %10, i8** %0
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
%13 = select i1 %12, i8* null, i8* %10
store i8* %13, i8** %0
%14 = sext i32 %4 to i64
%15 = getelementptr inbounds i8, i8* %3, i64 %14
store i8 0, i8* %7
ret i8* %15
}