#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 */
typedef scalar_t__ wchar_t;

/* Variables and functions */
int /*<<< orphan*/ EILSEQ;
int /*<<< orphan*/ MB_LEN_MAX;
int /*<<< orphan*/ errc(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
size_t mbrtowc(scalar_t__ *, char *, int /*<<< orphan*/, int /*<<< orphan*/ *);
char *mbssep(char **stringp, const wchar_t *delim) {
  char *s, *tok;
  const wchar_t *spanp;
  wchar_t c, sc;
  size_t n;
  if ((s = *stringp) == NULL)
    return (NULL);
  for (tok = s;;) {
    n = mbrtowc(&c, s, MB_LEN_MAX, NULL);
    if (n == (size_t)-1 || n == (size_t)-2)
      errc(1, EILSEQ, NULL);
    s += n;
    spanp = delim;
    do {
      if ((sc = *spanp++) == c) {
        if (c == 0)
          s = NULL;
        else
          s[-n] = '\0';
        *stringp = s;
        return (tok);
      }
    } while (sc != 0);
  }
}


x86 assembly (clang, -O0):
<mbssep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1152 <mbssep+0x32>
movq   $0x0,-0x8(%rbp)
jmp    122c <mbssep+0x10c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
mov    0x2e73(%rip),%rax
mov    (%rax),%edx
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <mbrtowc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0xffffffffffffffff,-0x48(%rbp)
je     118e <mbssep+0x6e>
cmpq   $0xfffffffffffffffe,-0x48(%rbp)
jne    11a5 <mbssep+0x85>
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <errc@plt>
mov    -0x48(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x30(%rbp)
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
cmp    -0x38(%rbp),%rax
jne    1217 <mbssep+0xf7>
cmpq   $0x0,-0x38(%rbp)
jne    11f1 <mbssep+0xd1>
movq   $0x0,-0x20(%rbp)
jmp    11ff <mbssep+0xdf>
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
sub    -0x48(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    122c <mbssep+0x10c>
jmp    121c <mbssep+0xfc>
cmpq   $0x0,-0x40(%rbp)
jne    11b9 <mbssep+0x99>
jmp    115a <mbssep+0x3a>
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mbssep>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x8(%rsp)
mov    (%rdi),%r12
test   %r12,%r12
je     11bb <mbssep+0x9b>
mov    %rdi,%r14
mov    0x2e8f(%rip),%rax
lea    0x10(%rsp),%rdi
mov    %r12,%rbx
mov    %rax,%r13
mov    (%rax),%edx
mov    %rdi,%r15
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1040 <mbrtowc@plt>
mov    %rax,%rbp
cmp    $0xfffffffffffffffe,%rax
jb     1181 <mbssep+0x61>
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
xor    %edx,%edx
call   1030 <errc@plt>
add    %rbx,%rbp
mov    0x10(%rsp),%rax
mov    0x8(%rsp),%rcx
xchg   %ax,%ax
mov    (%rcx),%rdx
cmp    %rax,%rdx
je     11ac <mbssep+0x8c>
add    $0x8,%rcx
test   %rdx,%rdx
jne    1190 <mbssep+0x70>
mov    %rbp,%rbx
mov    %r13,%rax
mov    %r15,%rdi
jmp    1151 <mbssep+0x31>
test   %rax,%rax
je     11b6 <mbssep+0x96>
movb   $0x0,(%rbx)
jmp    11b8 <mbssep+0x98>
xor    %ebp,%ebp
mov    %rbp,(%r14)
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MB_LEN_MAX = global i32 0
@EILSEQ = global i32 0
define i8* @mbssep(i8** %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i64*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
store i8** %0, i8*** %4
store i64* %1, i64** %5
%12 = load i8**, i8*** %4
%13 = load i8*, i8** %12
store i8* %13, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %2
store i8* null, i8** %3
br label %59
16: ; preds = %2
%17 = load i8*, i8** %6
store i8* %17, i8** %7
br label %18
18: ; preds = %58, %16
%19 = load i8*, i8** %6
%20 = load i32, i32* @MB_LEN_MAX
%21 = call i64 @mbrtowc(i64* %9, i8* %19, i32 %20, i32* null)
store i64 %21, i64* %11
%22 = load i64, i64* %11
%23 = icmp eq i64 %22, -1
br i1 %23, label %27, label %24
24: ; preds = %18
%25 = load i64, i64* %11
%26 = icmp eq i64 %25, -2
br i1 %26, label %27, label %30
27: ; preds = %24, %18
%28 = load i32, i32* @EILSEQ
%29 = call i32 @errc(i32 1, i32 %28, i32* null)
br label %30
30: ; preds = %27, %24
%31 = load i64, i64* %11
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i64 %31
store i8* %33, i8** %6
%34 = load i64*, i64** %5
store i64* %34, i64** %8
br label %35
35: ; preds = %55, %30
%36 = load i64*, i64** %8
%37 = getelementptr inbounds i64, i64* %36, i32 1
store i64* %37, i64** %8
%38 = load i64, i64* %36
store i64 %38, i64* %10
%39 = load i64, i64* %9
%40 = icmp eq i64 %38, %39
br i1 %40, label %41, label %54
41: ; preds = %35
%42 = load i64, i64* %9
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %41
store i8* null, i8** %6
br label %50
45: ; preds = %41
%46 = load i8*, i8** %6
%47 = load i64, i64* %11
%48 = sub i64 0, %47
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 0, i8* %49
br label %50
50: ; preds = %45, %44
%51 = load i8*, i8** %6
%52 = load i8**, i8*** %4
store i8* %51, i8** %52
%53 = load i8*, i8** %7
store i8* %53, i8** %3
br label %59
54: ; preds = %35
br label %55
55: ; preds = %54
%56 = load i64, i64* %10
%57 = icmp ne i64 %56, 0
br i1 %57, label %35, label %58
58: ; preds = %55
br label %18
59: ; preds = %50, %15
%60 = load i8*, i8** %3
ret i8* %60
}

LLVM IR (-O2):
@MB_LEN_MAX = global i32 0
@EILSEQ = global i32 0
define i8* @mbssep(i8** nocapture %0, i64* nocapture %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = load i8*, i8** %0
%6 = icmp eq i8* %5, null
br i1 %6, label %30, label %7
7: ; preds = %27, %2
%8 = phi i8* [ %5, %2 ], [ %16, %27 ]
%9 = load i32, i32* @MB_LEN_MAX
%10 = call i64 @mbrtowc(i64* %3, i8* %8, i32 %9, i32* null)
%11 = icmp ugt i64 %10, -3
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i32, i32* @EILSEQ
%14 = call i32 @errc(i32 1, i32 %13, i32* null)
br label %15
15: ; preds = %7, %12
%16 = getelementptr inbounds i8, i8* %8, i64 %10
%17 = load i64, i64* %3
br label %18
18: ; preds = %27, %15
%19 = phi i64* [ %1, %15 ], [ %28, %27 ]
%20 = load i64, i64* %19
%21 = icmp eq i64 %20, %17
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = icmp eq i64 %17, 0
br i1 %23, label %25, label %24
24: ; preds = %22
store i8 0, i8* %8
br label %25
25: ; preds = %22, %24
%26 = phi i8* [ %16, %24 ], [ null, %22 ]
store i8* %26, i8** %0
br label %30
27: ; preds = %18
%28 = getelementptr inbounds i64, i64* %19, i64 1
%29 = icmp eq i64 %20, 0
br i1 %29, label %7, label %18
30: ; preds = %2, %25
ret i8* %5
}