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

/* Variables and functions */
int /*<<< orphan*/ LC_ALL;
scalar_t__ WEOF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ ferror(int /*<<< orphan*/);
scalar_t__ findchar(scalar_t__);
scalar_t__ getwchar();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, scalar_t__);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  int wide;
  wchar_t w = 0x2021;
  wchar_t new;
  setlocale(LC_ALL, "");
  while ((w = getwchar()) != WEOF) {
    new = findchar(w);
    if (new != WEOF) {
      w = new;
    }
    printf("%lc", w);
  }
  if (ferror(stdin)) {
    perror("read");
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x2021,-0x20(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe65(%rip),%rsi
call   1070 <setlocale@plt>
mov    $0x0,%al
call   1030 <getwchar@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%rax
je     11fc <main+0x8c>
mov    -0x20(%rbp),%rdi
call   1060 <findchar@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2e02(%rip),%rcx
cmp    (%rcx),%rax
je     11e7 <main+0x77>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe0e(%rip),%rdi
call   1050 <printf@plt>
jmp    11a3 <main+0x33>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1220 <main+0xb0>
lea    0xde9(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
call   1070 <setlocale@plt>
xor    %eax,%eax
call   1030 <getwchar@plt>
mov    0x2e40(%rip),%r15
cmp    (%r15),%rax
je     11d9 <main+0x69>
mov    %rax,%rbx
lea    0xe59(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <findchar@plt>
cmp    (%r15),%rax
cmovne %rax,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <getwchar@plt>
mov    %rax,%rbx
cmp    (%r15),%rax
jne    11b0 <main+0x40>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1040 <ferror@plt>
test   %rax,%rax
je     11f8 <main+0x88>
lea    0xe11(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@WEOF = global i64 0
@.str.1 = [4 x i8] c"%lc\00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"read\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 8225, i64* %7
%9 = load i32, i32* @LC_ALL
%10 = call i32 @setlocale(i32 %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %23, %2
%12 = call i64 (...) @getwchar()
store i64 %12, i64* %7
%13 = load i64, i64* @WEOF
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load i64, i64* %7
%17 = call i64 @findchar(i64 %16)
store i64 %17, i64* %8
%18 = load i64, i64* %8
%19 = load i64, i64* @WEOF
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = load i64, i64* %8
store i64 %22, i64* %7
br label %23
23: ; preds = %21, %15
%24 = load i64, i64* %7
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %24)
br label %11
26: ; preds = %11
%27 = load i32, i32* @stdin
%28 = call i64 @ferror(i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %26
%33 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@WEOF = global i64 0
@.str.1 = [4 x i8] c"%lc\00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"read\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @LC_ALL
%4 = tail call i32 @setlocale(i32 %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%5 = tail call i64 (...) @getwchar()
%6 = load i64, i64* @WEOF
%7 = icmp eq i64 %5, %6
br i1 %7, label %18, label %8
8: ; preds = %2, %8
%9 = phi i64 [ %15, %8 ], [ %5, %2 ]
%10 = tail call i64 @findchar(i64 %9)
%11 = load i64, i64* @WEOF
%12 = icmp eq i64 %10, %11
%13 = select i1 %12, i64 %9, i64 %10
%14 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %13)
%15 = tail call i64 (...) @getwchar()
%16 = load i64, i64* @WEOF
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %8
18: ; preds = %8, %2
%19 = load i32, i32* @stdin
%20 = tail call i64 @ferror(i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
%25 = tail call i32 @exit(i32 0)
unreachable
}