#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 *, int, int /*<<< orphan*/ *);
int mbsinit(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int utf8_test_2(void) {
  wchar_t wc;
  mbstate_t s;
  wc = 42;
  memset(&s, 0, sizeof(s));
  assert(mbrtowc(NULL, "", 1, &s) == 0);
  assert(mbsinit(&s));
  wc = 42;
  memset(&s, 0, sizeof(s));
  assert(mbrtowc(&wc, "\xE2", 1, &s) == (size_t)-2);
  assert(mbrtowc(NULL, "", 1, &s) == (size_t)-1);
  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(mbrtowc(NULL, "", 1, &s) == (size_t)-1);
  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(mbrtowc(&wc, "\xA0", 1, &s) == 1);
  assert(mbrtowc(NULL, "", 1, &s) == 0);
  assert(mbsinit(&s));
  return 0;
}


x86 assembly (clang, -O0):
<utf8_test_2>:
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>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe99(%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>
lea    -0x8(%rbp),%rdi
call   1060 <mbsinit@plt>
mov    %eax,%edi
call   1050 <assert@plt>
movl   $0x2a,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
lea    -0x4(%rbp),%rdi
lea    0xe46(%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>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe1d(%rip),%rsi
mov    $0x1,%edx
lea    -0x8(%rbp),%rcx
call   1030 <mbrtowc@plt>
cltq
cmp    $0xffffffffffffffff,%rax
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    -0x4(%rbp),%rdi
lea    0xdd7(%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    0xdad(%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>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd82(%rip),%rsi
mov    $0x1,%edx
lea    -0x8(%rbp),%rcx
call   1030 <mbrtowc@plt>
cltq
cmp    $0xffffffffffffffff,%rax
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    -0x4(%rbp),%rdi
lea    0xd3c(%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    0xd12(%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    0xce8(%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>
xor    %eax,%eax
mov    %eax,%edi
lea    0xcbe(%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>
lea    -0x8(%rbp),%rdi
call   1060 <mbsinit@plt>
mov    %eax,%edi
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_test_2>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
lea    0xe9b(%rip),%r14
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <mbrtowc@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1060 <mbsinit@plt>
mov    %eax,%edi
call   1050 <assert@plt>
movl   $0x2a,0x8(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
lea    0xe4c(%rip),%r12
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    %r12,%rsi
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
mov    %r14,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <mbrtowc@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1050 <assert@plt>
movl   $0x2a,0x8(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <mbrtowc@plt>
xor    %edi,%edi
cmp    $0xfffffffe,%eax
sete   %dil
call   1050 <assert@plt>
lea    0xdc9(%rip),%r13
mov    %r15,%rdi
mov    %r13,%rsi
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
mov    %r14,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <mbrtowc@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1050 <assert@plt>
movl   $0x2a,0x8(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <mbrtowc@plt>
xor    %edi,%edi
cmp    $0xfffffffe,%eax
sete   %dil
call   1050 <assert@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <mbrtowc@plt>
xor    %edi,%edi
cmp    $0xfffffffe,%eax
sete   %dil
call   1050 <assert@plt>
lea    0xd2a(%rip),%rsi
mov    %r15,%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
mov    %r14,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <mbrtowc@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1060 <mbsinit@plt>
mov    %eax,%edi
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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