#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 char wchar_t;

/* Variables and functions */
int /*<<< orphan*/ LC_CTYPE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int wctomb(char *, char);
int main() {
  wchar_t c[100];
  char buf[100];
  size_t n = 0;
  c[0] = 'f';
  c[1] = 'n';
  c[2] = 0xd6;
  c[3] = 'r';
  c[4] = 'd';
  c[5] = 0;
  setlocale(LC_CTYPE, "de_DE.UTF8");
  assert(wctomb(buf, c[0]) == 1);
  assert(wctomb(buf + 1, c[1]) == 1);
  assert(wctomb(buf + 2, c[2]) == 2);
  assert(wctomb(buf + 4, c[3]) == 1);
  assert(wctomb(buf + 5, c[4]) == 1);
  buf[6] = 0;
  assert(!strcmp(buf, "fn\xc3\x96rd"));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movq   $0x0,-0xe8(%rbp)
movb   $0x66,-0x70(%rbp)
movb   $0x6e,-0x6f(%rbp)
movb   $0xd6,-0x6e(%rbp)
movb   $0x72,-0x6d(%rbp)
movb   $0x64,-0x6c(%rbp)
movb   $0x0,-0x6b(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
call   1050 <setlocale@plt>
lea    -0xe0(%rbp),%rdi
movsbl -0x70(%rbp),%esi
call   1060 <wctomb@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0xe0(%rbp),%rdi
add    $0x1,%rdi
movsbl -0x6f(%rbp),%esi
call   1060 <wctomb@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0xe0(%rbp),%rdi
add    $0x2,%rdi
movsbl -0x6e(%rbp),%esi
call   1060 <wctomb@plt>
cmp    $0x2,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0xe0(%rbp),%rdi
add    $0x4,%rdi
movsbl -0x6d(%rbp),%esi
call   1060 <wctomb@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0xe0(%rbp),%rdi
add    $0x5,%rdi
movsbl -0x6c(%rbp),%esi
call   1060 <wctomb@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movb   $0x0,-0xda(%rbp)
lea    -0xe0(%rbp),%rdi
lea    0xdc3(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x68,%rsp
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
lea    0xebc(%rip),%rsi
call   1040 <setlocale@plt>
mov    %rsp,%rdi
mov    $0x66,%esi
call   1050 <wctomb@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1030 <assert@plt>
lea    0x1(%rsp),%rdi
mov    $0x6e,%esi
call   1050 <wctomb@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1030 <assert@plt>
lea    0x2(%rsp),%rdi
mov    $0xffffffd6,%esi
call   1050 <wctomb@plt>
xor    %edi,%edi
cmp    $0x2,%eax
sete   %dil
call   1030 <assert@plt>
lea    0x4(%rsp),%rdi
mov    $0x72,%esi
call   1050 <wctomb@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1030 <assert@plt>
lea    0x5(%rsp),%rdi
mov    $0x64,%esi
call   1050 <wctomb@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1030 <assert@plt>
movb   $0x0,0x6(%rsp)
mov    $0x96c36e66,%eax
xor    (%rsp),%eax
mov    $0x647296,%ecx
xor    0x3(%rsp),%ecx
xor    %edi,%edi
or     %eax,%ecx
sete   %dil
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x68,%rsp
ret

LLVM IR (-O0):
@LC_CTYPE = global i32 0
@.str = [11 x i8] c"de_DE.UTF8\00"
@.str.1 = [7 x i8] c"fn\C3\96rd\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = alloca i64
store i64 0, i64* %3
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
store i8 102, i8* %4
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 1
store i8 110, i8* %5
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 2
store i8 -42, i8* %6
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 3
store i8 114, i8* %7
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 4
store i8 100, i8* %8
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 5
store i8 0, i8* %9
%10 = load i32, i32* @LC_CTYPE
%11 = call i32 @setlocale(i32 %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%14 = load i8, i8* %13
%15 = call i32 @wctomb(i8* %12, i8 signext %14)
%16 = icmp eq i32 %15, 1
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 1
%22 = load i8, i8* %21
%23 = call i32 @wctomb(i8* %20, i8 signext %22)
%24 = icmp eq i32 %23, 1
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%28 = getelementptr inbounds i8, i8* %27, i64 2
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 2
%30 = load i8, i8* %29
%31 = call i32 @wctomb(i8* %28, i8 signext %30)
%32 = icmp eq i32 %31, 2
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%36 = getelementptr inbounds i8, i8* %35, i64 4
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 3
%38 = load i8, i8* %37
%39 = call i32 @wctomb(i8* %36, i8 signext %38)
%40 = icmp eq i32 %39, 1
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%44 = getelementptr inbounds i8, i8* %43, i64 5
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 4
%46 = load i8, i8* %45
%47 = call i32 @wctomb(i8* %44, i8 signext %46)
%48 = icmp eq i32 %47, 1
%49 = zext i1 %48 to i32
%50 = call i32 @assert(i32 %49)
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 6
store i8 0, i8* %51
%52 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%53 = call i32 @strcmp(i8* %52, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%54 = icmp ne i32 %53, 0
%55 = xor i1 %54, true
%56 = zext i1 %55 to i32
%57 = call i32 @assert(i32 %56)
ret i32 0
}

LLVM IR (-O2):
@LC_CTYPE = global i32 0
@.str = [11 x i8] c"de_DE.UTF8\00"
@.str.1 = [7 x i8] c"fn\C3\96rd\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @LC_CTYPE
%4 = tail call i32 @setlocale(i32 %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @wctomb(i8* %2, i8 signext 102)
%6 = icmp eq i32 %5, 1
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 1
%10 = call i32 @wctomb(i8* %9, i8 signext 110)
%11 = icmp eq i32 %10, 1
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 2
%15 = call i32 @wctomb(i8* %14, i8 signext -42)
%16 = icmp eq i32 %15, 2
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 4
%20 = call i32 @wctomb(i8* %19, i8 signext 114)
%21 = icmp eq i32 %20, 1
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 5
%25 = call i32 @wctomb(i8* %24, i8 signext 100)
%26 = icmp eq i32 %25, 1
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 6
store i8 0, i8* %29
%30 = call i32 @bcmp(i8* dereferenceable(7) %2, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 7)
%31 = icmp eq i32 %30, 0
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
ret i32 0
}