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

/* Variables and functions */
int MB_LEN_MAX;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
size_t wcrtomb(char *, int /*<<< orphan*/, int /*<<< orphan*/ *);
char dvm_wctochar(wchar_t src) {
  char dummy[MB_LEN_MAX];
  mbstate_t ps;
  memset(&ps, 0, sizeof(mbstate_t));
  size_t wc_len = wcrtomb(dummy, src, &ps);
  assert(wc_len == 1);
  return dummy[0];
}


x86 assembly (clang, -O0):
<dvm_wctochar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%esi
lea    -0x1c(%rbp),%rdx
call   1050 <wcrtomb@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x1,-0x28(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%al
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
movsbl %al,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dvm_wctochar>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
mov    0x2e98(%rip),%rax
mov    (%rax),%ebx
mov    %rsp,%r13
add    $0xf,%rbx
and    $0xfffffffffffffff0,%rbx
mov    %r13,%r12
sub    %rbx,%r12
mov    %r12,%rsp
neg    %rbx
lea    -0x2c(%rbp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    %r12,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
call   1050 <wcrtomb@plt>
xor    %edi,%edi
cmp    $0x1,%rax
sete   %dil
call   1040 <assert@plt>
mov    0x0(%r13,%rbx,1),%al
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MB_LEN_MAX = global i32 0
define signext i8 @dvm_wctochar(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
store i32 %0, i32* %2
%7 = load i32, i32* @MB_LEN_MAX
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %3
%10 = alloca i8, i64 %8
store i64 %8, i64* %4
%11 = call i32 @memset(i32* %5, i32 0, i32 4)
%12 = load i32, i32* %2
%13 = call i64 @wcrtomb(i8* %10, i32 %12, i32* %5)
store i64 %13, i64* %6
%14 = load i64, i64* %6
%15 = icmp eq i64 %14, 1
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = getelementptr inbounds i8, i8* %10, i64 0
%19 = load i8, i8* %18
%20 = load i8*, i8** %3
ret i8 %19
}

LLVM IR (-O2):
@MB_LEN_MAX = global i32 0
define signext i8 @dvm_wctochar(i32 %0) {
%2 = alloca i32
%3 = load i32, i32* @MB_LEN_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = bitcast i32* %2 to i8*
%7 = call i32 @memset(i32* %2, i32 0, i32 4)
%8 = call i64 @wcrtomb(i8* %5, i32 %0, i32* %2)
%9 = icmp eq i64 %8, 1
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8, i8* %5
ret i8 %12
}