#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 *strnpbrk(char *, char const *, size_t);
char *strnsep(char **restrict string, const char *restrict delimiters,
              size_t *restrict maxlen) {
  char *r = *string;
  char *next;
  if (r == NULL)
    return NULL;
  next = strnpbrk(r, delimiters, *maxlen);
  if (next != NULL)
    *next++ = 0, *maxlen -= (size_t)(next - r);
  *string = next;
  return r;
}


x86 assembly (clang, -O0):
<strnsep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1147 <strnsep+0x37>
movq   $0x0,-0x8(%rbp)
jmp    11a7 <strnsep+0x97>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
call   1030 <strnpbrk@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1194 <strnsep+0x84>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rax
sub    %rax,%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x10(%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):
<strnsep>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%r12
test   %r12,%r12
je     1153 <strnsep+0x43>
mov    %rdx,%r15
mov    %rdi,%r14
mov    (%rdx),%rbx
mov    %r12,%rdi
mov    %rbx,%rdx
call   1030 <strnpbrk@plt>
test   %rax,%rax
je     114e <strnsep+0x3e>
mov    %rax,%rcx
add    $0x1,%rcx
movb   $0x0,(%rax)
add    %r12,%rbx
sub    %rcx,%rbx
mov    %rbx,(%r15)
jmp    1150 <strnsep+0x40>
xor    %ecx,%ecx
mov    %rcx,(%r14)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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