#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 unsigned char wchar_t;
typedef int /*<<< orphan*/ mbstate_t;

/* Variables and functions */
int /*<<< orphan*/ EILSEQ;
int /*<<< orphan*/ errno;
size_t mbrtowc(wchar_t *__restrict pwc, const char *__restrict s, size_t n,
               mbstate_t *__restrict ps) {
  if (s == NULL)
    return (0);
  if (n == 0)
    return ((size_t)-2);
  if (*s & 0x80) {
    errno = EILSEQ;
    return ((size_t)-1);
  }
  if (pwc != NULL)
    *pwc = (unsigned char)*s;
  return (*s == '\0' ? 0 : 1);
}


x86 assembly (clang, -O0):
<mbrtowc>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    112c <mbrtowc+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    11a9 <mbrtowc+0xa9>
cmpq   $0x0,-0x20(%rbp)
jne    1144 <mbrtowc+0x44>
movq   $0xfffffffffffffffe,-0x8(%rbp)
ff
jmp    11a9 <mbrtowc+0xa9>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1178 <mbrtowc+0x78>
mov    0x2e90(%rip),%rax
mov    (%rax),%ecx
mov    0x2e6f(%rip),%rax
mov    %ecx,(%rax)
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11a9 <mbrtowc+0xa9>
cmpq   $0x0,-0x10(%rbp)
je     118f <mbrtowc+0x8f>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
cltq
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<mbrtowc>:
test   %rsi,%rsi
je     111f <mbrtowc+0x1f>
test   %rdx,%rdx
je     1122 <mbrtowc+0x22>
mov    (%rsi),%cl
test   %cl,%cl
js     112a <mbrtowc+0x2a>
test   %rdi,%rdi
je     1117 <mbrtowc+0x17>
mov    %cl,(%rdi)
xor    %eax,%eax
test   %cl,%cl
setne  %al
ret
xor    %eax,%eax
ret
mov    $0xfffffffffffffffe,%rax
ret
mov    0x2ebf(%rip),%rax
mov    (%rax),%eax
mov    0x2e9e(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffffffffffff,%rax
ret

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

LLVM IR (-O2):
@EILSEQ = global i32 0
@errno = global i32 0
define i64 @mbrtowc(i8* noalias writeonly %0, i8* noalias %1, i64 %2, i32* noalias nocapture readnone %3) {
%5 = icmp eq i8* %1, null
br i1 %5, label %19, label %6
6: ; preds = %4
%7 = icmp eq i64 %2, 0
br i1 %7, label %19, label %8
8: ; preds = %6
%9 = load i8, i8* %1
%10 = icmp sgt i8 %9, -1
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = load i32, i32* @EILSEQ
store i32 %12, i32* @errno
br label %19
13: ; preds = %8
%14 = icmp eq i8* %0, null
br i1 %14, label %16, label %15
15: ; preds = %13
store i8 %9, i8* %0
br label %16
16: ; preds = %15, %13
%17 = icmp ne i8 %9, 0
%18 = zext i1 %17 to i64
br label %19
19: ; preds = %6, %4, %16, %11
%20 = phi i64 [ -1, %11 ], [ %18, %16 ], [ 0, %4 ], [ -2, %6 ]
ret i64 %20
}