#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 scalar_t__ wint_t;
typedef int wchar_t;

/* Variables and functions */
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ LC_CTYPE;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ dup2(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
scalar_t__ putwchar(int);
int /*<<< orphan*/ *setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int wcwidth(int);
int main(void) {
  wchar_t wc;
  int width;
  if (setlocale(LC_ALL, "") == NULL) {
    fputs("setlocale(LC_ALL, \"\") failed\n", stderr);
    return 1;
  }
  if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) {
    fputs("setlocale(LC_CTYPE, \"en_US.UTF-8\") failed\n", stderr);
    return 1;
  }
  if (sizeof(wchar_t) < 4) {
    fprintf(stderr, "wchar_t is only %zu bytes\n", sizeof(wchar_t));
    return 1;
  }
  if ((width = wcwidth(L' ')) != 1) {
    fprintf(stderr, "wcwidth(L' ') returned %d\n", width);
    return 1;
  }
  dup2(STDERR_FILENO, STDOUT_FILENO);
  wc = L'*';
  if (putwchar(wc) != (wint_t)wc) {
    fputs("bad putwchar return value\n", stderr);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xef0(%rip),%rsi
call   1070 <setlocale@plt>
cmp    $0x0,%rax
jne    11af <main+0x4f>
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    0xe62(%rip),%rdi
call   1040 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    1284 <main+0x124>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
call   1070 <setlocale@plt>
cmp    $0x0,%rax
jne    11ef <main+0x8f>
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
lea    0xe4c(%rip),%rdi
call   1040 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    1284 <main+0x124>
mov    $0x20,%edi
call   1060 <wcwidth@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x1,%eax
je     1229 <main+0xc9>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe3d(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1284 <main+0x124>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
movl   $0x2a,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1080 <putwchar@plt>
movslq -0x8(%rbp),%rcx
cmp    %rcx,%rax
je     127d <main+0x11d>
mov    0x2d6d(%rip),%rax
mov    (%rax),%esi
lea    0xe04(%rip),%rdi
call   1040 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    1284 <main+0x124>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xefe(%rip),%rsi
call   1070 <setlocale@plt>
test   %rax,%rax
je     11e2 <main+0x82>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe93(%rip),%rsi
call   1070 <setlocale@plt>
test   %rax,%rax
je     11f4 <main+0x94>
mov    $0x20,%edi
call   1060 <wcwidth@plt>
cmp    $0x1,%eax
jne    120b <main+0xab>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    $0x2a,%edi
call   1080 <putwchar@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x2a,%rcx
je     1227 <main+0xc7>
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
lea    0xe90(%rip),%rdi
jmp    1204 <main+0xa4>
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
lea    0xe0e(%rip),%rdi
jmp    1204 <main+0xa4>
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
lea    0xe26(%rip),%rdi
call   1040 <fputs@plt>
jmp    1222 <main+0xc2>
mov    0x2dbe(%rip),%rcx
mov    (%rcx),%edi
lea    0xe3a(%rip),%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [30 x i8] c"setlocale(LC_ALL, \22\22) failed\0A\00"
@stderr = global i32 0
@LC_CTYPE = global i32 0
@.str.2 = [12 x i8] c"en_US.UTF-8\00"
@.str.3 = [43 x i8] c"setlocale(LC_CTYPE, \22en_US.UTF-8\22) failed\0A\00"
@.str.4 = [27 x i8] c"wcwidth(L' ') returned %d\0A\00"
@STDERR_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@.str.5 = [27 x i8] c"bad putwchar return value\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @LC_ALL
%5 = call i32* @setlocale(i32 %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 @fputs(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %8)
store i32 1, i32* %1
br label %37
10: ; preds = %0
%11 = load i32, i32* @LC_CTYPE
%12 = call i32* @setlocale(i32 %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = call i32 @fputs(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %15)
store i32 1, i32* %1
br label %37
17: ; preds = %10
%18 = call i32 @wcwidth(i32 32)
store i32 %18, i32* %3
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = load i32, i32* %3
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %22)
store i32 1, i32* %1
br label %37
24: ; preds = %17
%25 = load i32, i32* @STDERR_FILENO
%26 = load i32, i32* @STDOUT_FILENO
%27 = call i32 @dup2(i32 %25, i32 %26)
store i32 42, i32* %2
%28 = load i32, i32* %2
%29 = call i64 @putwchar(i32 %28)
%30 = load i32, i32* %2
%31 = sext i32 %30 to i64
%32 = icmp ne i64 %29, %31
br i1 %32, label %33, label %36
33: ; preds = %24
%34 = load i32, i32* @stderr
%35 = call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %34)
store i32 1, i32* %1
br label %37
36: ; preds = %24
store i32 0, i32* %1
br label %37
37: ; preds = %36, %33, %20, %14, %7
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [30 x i8] c"setlocale(LC_ALL, \22\22) failed\0A\00"
@stderr = global i32 0
@LC_CTYPE = global i32 0
@.str.2 = [12 x i8] c"en_US.UTF-8\00"
@.str.3 = [43 x i8] c"setlocale(LC_CTYPE, \22en_US.UTF-8\22) failed\0A\00"
@.str.4 = [27 x i8] c"wcwidth(L' ') returned %d\0A\00"
@STDERR_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@.str.5 = [27 x i8] c"bad putwchar return value\0A\00"
define i32 @main() {
%1 = load i32, i32* @LC_ALL
%2 = tail call i32* @setlocale(i32 %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i32 @fputs(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %29
7: ; preds = %0
%8 = load i32, i32* @LC_CTYPE
%9 = tail call i32* @setlocale(i32 %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i32, i32* @stderr
%13 = tail call i32 @fputs(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %12)
br label %29
14: ; preds = %7
%15 = tail call i32 @wcwidth(i32 32)
%16 = icmp eq i32 %15, 1
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %15)
br label %29
20: ; preds = %14
%21 = load i32, i32* @STDERR_FILENO
%22 = load i32, i32* @STDOUT_FILENO
%23 = tail call i32 @dup2(i32 %21, i32 %22)
%24 = tail call i64 @putwchar(i32 42)
%25 = icmp eq i64 %24, 42
br i1 %25, label %29, label %26
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = tail call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %20, %26, %17, %11, %4
%30 = phi i32 [ 1, %4 ], [ 1, %11 ], [ 1, %17 ], [ 1, %26 ], [ 0, %20 ]
ret i32 %30
}