#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 *const);
char *gen_strsep(char **const stringp, const char *const delim) {
  char *p = *stringp;
  if (p) {
    char *q = p + strcspn(p, delim);
    *stringp = *q ? q + 1 : NULL;
    *q = '\0';
  }
  return p;
}


x86 assembly (clang, -O0):
<gen_strsep>:
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,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1199 <gen_strsep+0x89>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcspn@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     117c <gen_strsep+0x6c>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1187 <gen_strsep+0x77>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    1187 <gen_strsep+0x77>
mov    -0x30(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_strsep>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%rbx
test   %rbx,%rbx
je     113f <gen_strsep+0x2f>
mov    %rdi,%r14
mov    %rbx,%rdi
call   1030 <strcspn@plt>
cltq
xor    %ecx,%ecx
cmpb   $0x0,(%rbx,%rax,1)
lea    0x1(%rbx,%rax,1),%rdx
cmovne %rdx,%rcx
mov    %rcx,(%r14)
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @gen_strsep(i8** nocapture %0, i8* nocapture %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %13, 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
%11 = getelementptr inbounds i8, i8* %8, i64 1
%12 = select i1 %10, i8* null, i8* %11
store i8* %12, i8** %0
store i8 0, i8* %8
br label %13
13: ; preds = %5, %2
ret i8* %3
}