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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int mbrtowc(int *, char const *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int utf8_test_1(void) {
  wchar_t wc;
  mbstate_t s;
  wc = 42;
  memset(&s, 0, sizeof(s));
  assert(mbrtowc(&wc, "\xE2", 1, &s) == (size_t)-2);
  assert(mbrtowc(&wc, "\x89", 1, &s) == (size_t)-2);
  assert(wc == 42);
  assert(mbrtowc(&wc, "\xA0", 1, &s) == 1);
  assert(wc == 0x2260);
  assert(mbrtowc(&wc, "", 1, &s) == 0);
  assert(wc == 0);
  const char str[] = "\xe0\xa0\x80";
  wc = 42;
  memset(&s, 0, sizeof(s));
  assert(mbrtowc(&wc, str, 1, &s) == -2);
  assert(mbrtowc(&wc, str + 1, 2, &s) == 2);
  assert(wc == 0x800);
  wc = 42;
  memset(&s, 0, sizeof(s));
  assert(mbrtowc(&wc, str, 3, &s) == 3);
  assert(wc == 0x800);
  return 0;
}


x86 assembly (clang, -O0):
<utf8_test_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x2a,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
lea    -0x4(%rbp),%rdi
lea    0xea6(%rip),%rsi
mov    $0x1,%edx
lea    -0x8(%rbp),%rcx
call   1030 <mbrtowc@plt>
cltq
cmp    $0xfffffffffffffffe,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x4(%rbp),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x1,%edx
lea    -0x8(%rbp),%rcx
call   1030 <mbrtowc@plt>
cltq
cmp    $0xfffffffffffffffe,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0x2a,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x4(%rbp),%rdi
lea    0xe41(%rip),%rsi
mov    $0x1,%edx
lea    -0x8(%rbp),%rcx
call   1030 <mbrtowc@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0x2260,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x4(%rbp),%rdi
lea    0xe09(%rip),%rsi
mov    $0x1,%edx
lea    -0x8(%rbp),%rcx
call   1030 <mbrtowc@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0x0,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0xdd1(%rip),%eax
mov    %eax,-0xc(%rbp)
movl   $0x2a,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
lea    -0xc(%rbp),%rsi
lea    -0x4(%rbp),%rdi
mov    $0x1,%edx
lea    -0x8(%rbp),%rcx
call   1030 <mbrtowc@plt>
cmp    $0xfffffffe,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0xc(%rbp),%rsi
add    $0x1,%rsi
lea    -0x4(%rbp),%rdi
mov    $0x2,%edx
lea    -0x8(%rbp),%rcx
call   1030 <mbrtowc@plt>
cmp    $0x2,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0x800,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x2a,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
lea    -0xc(%rbp),%rsi
lea    -0x4(%rbp),%rdi
mov    $0x3,%edx
lea    -0x8(%rbp),%rcx
call   1030 <mbrtowc@plt>
cmp    $0x3,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0x800,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_test_1>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x2a,0x4(%rsp)
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
lea    0xea4(%rip),%rsi
lea    0x4(%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <mbrtowc@plt>
xor    %edi,%edi
cmp    $0xfffffffe,%eax
sete   %dil
call   1050 <assert@plt>
lea    0xe7c(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <mbrtowc@plt>
xor    %edi,%edi
cmp    $0xfffffffe,%eax
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpl   $0x2a,0x4(%rsp)
sete   %dil
call   1050 <assert@plt>
lea    0xe49(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <mbrtowc@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpl   $0x2260,0x4(%rsp)
sete   %dil
call   1050 <assert@plt>
lea    0xe10(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <mbrtowc@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpl   $0x0,0x4(%rsp)
sete   %dil
call   1050 <assert@plt>
movl   $0x80a0e0,0x8(%rsp)
movl   $0x2a,0x4(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
lea    0x8(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <mbrtowc@plt>
xor    %edi,%edi
cmp    $0xfffffffe,%eax
sete   %dil
call   1050 <assert@plt>
lea    0x9(%rsp),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
mov    %rbx,%rcx
call   1030 <mbrtowc@plt>
xor    %edi,%edi
cmp    $0x2,%eax
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpl   $0x800,0x4(%rsp)
sete   %dil
call   1050 <assert@plt>
movl   $0x2a,0x4(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
mov    %rbx,%rcx
call   1030 <mbrtowc@plt>
xor    %edi,%edi
cmp    $0x3,%eax
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpl   $0x800,0x4(%rsp)
sete   %dil
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\E2\00"
@.str.1 = [2 x i8] c"\89\00"
@.str.2 = [2 x i8] c"\A0\00"
@.str.3 = [1 x i8] zeroinitializer
@__const.utf8_test_1.str = [4 x i8] c"\E0\A0\80\00"
define i32 @utf8_test_1() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4 x i8]
store i32 42, i32* %1
%4 = call i32 @memset(i32* %2, i32 0, i32 4)
%5 = call i32 @mbrtowc(i32* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1, i32* %2)
%6 = sext i32 %5 to i64
%7 = icmp eq i64 %6, -2
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = call i32 @mbrtowc(i32* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1, i32* %2)
%11 = sext i32 %10 to i64
%12 = icmp eq i64 %11, -2
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32, i32* %1
%16 = icmp eq i32 %15, 42
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = call i32 @mbrtowc(i32* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1, i32* %2)
%20 = icmp eq i32 %19, 1
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i32, i32* %1
%24 = icmp eq i32 %23, 8800
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = call i32 @mbrtowc(i32* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 1, i32* %2)
%28 = icmp eq i32 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i32, i32* %1
%32 = icmp eq i32 %31, 0
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = bitcast [4 x i8]* %3 to i8*
store i32 42, i32* %1
%36 = call i32 @memset(i32* %2, i32 0, i32 4)
%37 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%38 = call i32 @mbrtowc(i32* %1, i8* %37, i32 1, i32* %2)
%39 = icmp eq i32 %38, -2
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = call i32 @mbrtowc(i32* %1, i8* %43, i32 2, i32* %2)
%45 = icmp eq i32 %44, 2
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = load i32, i32* %1
%49 = icmp eq i32 %48, 2048
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
store i32 42, i32* %1
%52 = call i32 @memset(i32* %2, i32 0, i32 4)
%53 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%54 = call i32 @mbrtowc(i32* %1, i8* %53, i32 3, i32* %2)
%55 = icmp eq i32 %54, 3
%56 = zext i1 %55 to i32
%57 = call i32 @assert(i32 %56)
%58 = load i32, i32* %1
%59 = icmp eq i32 %58, 2048
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"\E2\00"
@.str.1 = [2 x i8] c"\89\00"
@.str.2 = [2 x i8] c"\A0\00"
@.str.3 = [1 x i8] zeroinitializer
define i32 @utf8_test_1() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
store i32 42, i32* %1
%6 = call i32 @memset(i32* %2, i32 0, i32 4)
%7 = call i32 @mbrtowc(i32* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1, i32* %2)
%8 = icmp eq i32 %7, -2
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = call i32 @mbrtowc(i32* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1, i32* %2)
%12 = icmp eq i32 %11, -2
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32, i32* %1
%16 = icmp eq i32 %15, 42
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = call i32 @mbrtowc(i32* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1, i32* %2)
%20 = icmp eq i32 %19, 1
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i32, i32* %1
%24 = icmp eq i32 %23, 8800
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = call i32 @mbrtowc(i32* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 1, i32* %2)
%28 = icmp eq i32 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i32, i32* %1
%32 = icmp eq i32 %31, 0
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = bitcast i32* %3 to i8*
store i32 8429792, i32* %3
store i32 42, i32* %1
%36 = call i32 @memset(i32* %2, i32 0, i32 4)
%37 = call i32 @mbrtowc(i32* %1, i8* %35, i32 1, i32* %2)
%38 = icmp eq i32 %37, -2
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = getelementptr inbounds i8, i8* %35, i64 1
%42 = call i32 @mbrtowc(i32* %1, i8* %41, i32 2, i32* %2)
%43 = icmp eq i32 %42, 2
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load i32, i32* %1
%47 = icmp eq i32 %46, 2048
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
store i32 42, i32* %1
%50 = call i32 @memset(i32* %2, i32 0, i32 4)
%51 = call i32 @mbrtowc(i32* %1, i8* %35, i32 3, i32* %2)
%52 = icmp eq i32 %51, 3
%53 = zext i1 %52 to i32
%54 = call i32 @assert(i32 %53)
%55 = load i32, i32* %1
%56 = icmp eq i32 %55, 2048
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
ret i32 0
}