#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*/ str;

/* Variables and functions */
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
size_t wcstombs(char *, int *, int);
int main() {
  wchar_t wstr[2];
  char str[5];
  size_t i;
  setlocale(LC_ALL, "");
  wstr[0] = 0x8428;
  wstr[1] = 0x0;
  for (i = 0; i < sizeof(str); i++)
    str[i] = '\0';
  if (wcstombs(str, wstr, sizeof(str)) != (size_t)-1) {
    for (i = 0; i < sizeof(str); i++)
      fprintf(stdout, "%02X ", (unsigned char)str[i]);
    fprintf(stdout, "\n");
    fprintf(stdout, "PASS\n");
    return 0;
  } else {
    char *errstr = strerror(errno);
    fprintf(stdout, "%s\n", errstr);
    fprintf(stdout, "FAIL\n");
    return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    0xeb6(%rip),%rsi
call   1040 <setlocale@plt>
movl   $0x8428,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x5,-0x20(%rbp)
jae    119f <main+0x5f>
mov    -0x20(%rbp),%rax
movb   $0x0,-0x11(%rbp,%rax,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    117a <main+0x3a>
lea    -0x11(%rbp),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x5,%edx
call   1050 <wcstombs@plt>
cmp    $0xffffffffffffffff,%rax
je     1239 <main+0xf9>
movq   $0x0,-0x20(%rbp)
cmpq   $0x5,-0x20(%rbp)
jae    11ff <main+0xbf>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
movzbl -0x11(%rbp,%rax,1),%edx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11c3 <main+0x83>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1284 <main+0x144>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,-0x28(%rbp)
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xdad(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
lea    0xd9a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
lea    0xebd(%rip),%rsi
call   1040 <setlocale@plt>
movq   $0x8428,0x8(%rsp)
movl   $0x0,(%rsp)
movb   $0x0,0x4(%rsp)
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    $0x5,%edx
call   1050 <wcstombs@plt>
cmp    $0xffffffffffffffff,%rax
je     1212 <main+0xd2>
mov    0x2e43(%rip),%rbp
mov    0x0(%rbp),%edi
movzbl (%rsp),%edx
lea    0xe5d(%rip),%rbx
xor    %r14d,%r14d
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%rbp),%edi
movzbl 0x1(%rsp),%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%rbp),%edi
movzbl 0x2(%rsp),%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%rbp),%edi
movzbl 0x3(%rsp),%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%rbp),%edi
movzbl 0x4(%rsp),%edx
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xe12(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xdf6(%rip),%rsi
jmp    1247 <main+0x107>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    0x2db1(%rip),%rcx
mov    (%rcx),%edi
lea    0xddc(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%r14d
lea    0xdc9(%rip),%rsi
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@stdout = global i32 0
@.str.1 = [6 x i8] c"%02X \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [6 x i8] c"PASS\0A\00"
@errno = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [6 x i8] c"FAIL\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca [5 x i8]
%4 = alloca i64
%5 = alloca i8*
store i32 0, i32* %1
%6 = load i32, i32* @LC_ALL
%7 = call i32 @setlocale(i32 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
store i32 33832, i32* %8
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
store i32 0, i32* %9
store i64 0, i64* %4
br label %10
10: ; preds = %16, %0
%11 = load i64, i64* %4
%12 = icmp ult i64 %11, 5
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i64, i64* %4
%15 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %13
%17 = load i64, i64* %4
%18 = add i64 %17, 1
store i64 %18, i64* %4
br label %10
19: ; preds = %10
%20 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%22 = call i64 @wcstombs(i8* %20, i32* %21, i32 5)
%23 = icmp ne i64 %22, -1
br i1 %23, label %24, label %43
24: ; preds = %19
store i64 0, i64* %4
br label %25
25: ; preds = %35, %24
%26 = load i64, i64* %4
%27 = icmp ult i64 %26, 5
br i1 %27, label %28, label %38
28: ; preds = %25
%29 = load i32, i32* @stdout
%30 = load i64, i64* %4
%31 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %28
%36 = load i64, i64* %4
%37 = add i64 %36, 1
store i64 %37, i64* %4
br label %25
38: ; preds = %25
%39 = load i32, i32* @stdout
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* @stdout
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %51
43: ; preds = %19
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
store i8* %45, i8** %5
%46 = load i32, i32* @stdout
%47 = load i8*, i8** %5
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %47)
%49 = load i32, i32* @stdout
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %51
51: ; preds = %43, %38
%52 = load i32, i32* %1
ret i32 %52
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@stdout = global i32 0
@.str.1 = [6 x i8] c"%02X \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [6 x i8] c"PASS\0A\00"
@errno = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [6 x i8] c"FAIL\0A\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [5 x i8]
%3 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%4 = bitcast [2 x i32]* %1 to i8*
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @LC_ALL
%7 = tail call i32 @setlocale(i32 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
store i32 33832, i32* %8
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
store i32 0, i32* %9
%10 = call i64 @wcstombs(i8* %5, i32* %8, i32 5)
%11 = icmp eq i64 %10, -1
br i1 %11, label %39, label %12
12: ; preds = %0
%13 = load i32, i32* @stdout
%14 = load i8, i8* %5
%15 = zext i8 %14 to i32
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @stdout
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 1
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32, i32* @stdout
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 2
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load i32, i32* @stdout
%28 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 3
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = load i32, i32* @stdout
%33 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 4
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = load i32, i32* @stdout
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %44
39: ; preds = %0
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = load i32, i32* @stdout
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %41)
br label %44
44: ; preds = %39, %12
%45 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), %39 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %12 ]
%46 = phi i32 [ 1, %39 ], [ 0, %12 ]
%47 = load i32, i32* @stdout
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* %45)
ret i32 %46
}