#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 strcspn(char *, char const *);
char *strsep(char **str, const char *sep) {
  char *s = *str, *end;
  if (!s) {
    return NULL;
  }
  end = s + strcspn(s, sep);
  if (*end) {
    *end++ = 0;
  } else {
    end = 0;
  }
  *str = end;
  return s;
}


x86 assembly (clang, -O0):
<strsep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1143 <strsep+0x33>
movq   $0x0,-0x8(%rbp)
jmp    11a7 <strsep+0x97>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcspn@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     118c <strsep+0x7c>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,(%rax)
jmp    1194 <strsep+0x84>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strsep>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%rbx
test   %rbx,%rbx
je     1140 <strsep+0x30>
mov    %rdi,%r14
mov    %rbx,%rdi
call   1030 <strcspn@plt>
cltq
cmpb   $0x0,(%rbx,%rax,1)
je     113b <strsep+0x2b>
add    %rbx,%rax
movb   $0x0,(%rax)
add    $0x1,%rax
jmp    113d <strsep+0x2d>
xor    %eax,%eax
mov    %rax,(%r14)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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