#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 wint_t;
typedef scalar_t__ wctrans_t;
typedef char wchar_t;
typedef int /*<<< orphan*/ wbuf;

/* Variables and functions */
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ swprintf(char *, int, char *, int);
int towctrans(int, scalar_t__);
scalar_t__ wcscmp(char *, char *);
int wcslen(char *);
scalar_t__ wctrans(char *);
int main(void) {
  char buf[30];
  wchar_t wbuf[30];
  wctrans_t t;
  wint_t wch;
  int errors = 0;
  int len;
  setlocale(LC_ALL, "");
  t = wctrans("test");
  if (t == (wctrans_t)0) {
    puts("locale data files probably not loaded");
    exit(1);
  }
  wch = towctrans(L'A', t);
  printf("towctrans (L'A', t) = %c\n", wch);
  if (wch != L'B')
    errors = 1;
  wch = towctrans(L'B', t);
  printf("towctrans (L'B', t) = %c\n", wch);
  if (wch != L'C')
    errors = 1;
  swprintf(wbuf, sizeof(wbuf) / sizeof(wbuf[0]), L"%Id", 0x499602D2);
  errors |= wcscmp(wbuf, L"bcdefghija") != 0;
  len = wcslen(wbuf);
  errors |= len != 10;
  printf("len = %d, wbuf = L\"%ls\"\n", len, wbuf);
  snprintf(buf, sizeof buf, "%Id", 0x499602D2);
  errors |= strcmp(buf, "bcdefghija") != 0;
  len = strlen(buf);
  errors |= len != 10;
  printf("len = %d, buf = \"%s\"\n", len, buf);
  return errors;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x60(%rbp)
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xeb6(%rip),%rsi
call   10c0 <setlocale@plt>
lea    0xe0e(%rip),%rdi
call   10d0 <wctrans@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    121c <main+0x5c>
lea    0xdf8(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x58(%rbp),%rsi
mov    $0x41,%edi
call   10b0 <towctrans@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%esi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x42,-0x5c(%rbp)
je     124f <main+0x8f>
movl   $0x1,-0x60(%rbp)
mov    -0x58(%rbp),%rsi
mov    $0x42,%edi
call   10b0 <towctrans@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%esi
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x43,-0x5c(%rbp)
je     1282 <main+0xc2>
movl   $0x1,-0x60(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x1e,%esi
lea    0xe0e(%rip),%rdx
mov    $0x499602d2,%ecx
call   10a0 <swprintf@plt>
lea    -0x50(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1030 <wcscmp@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
or     -0x60(%rbp),%eax
mov    %eax,-0x60(%rbp)
lea    -0x50(%rbp),%rdi
call   1070 <wcslen@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xa,-0x64(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
or     -0x60(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x64(%rbp),%esi
lea    -0x50(%rbp),%rdx
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x1e,%esi
lea    0xd77(%rip),%rdx
mov    $0x499602d2,%ecx
call   1080 <snprintf@plt>
lea    -0x30(%rbp),%rdi
lea    0xd66(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
or     -0x60(%rbp),%eax
mov    %eax,-0x60(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xa,-0x64(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
or     -0x60(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x64(%rbp),%esi
lea    -0x30(%rbp),%rdx
lea    0xd2e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x60(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
lea    0xec0(%rip),%rsi
call   10c0 <setlocale@plt>
lea    0xe18(%rip),%rdi
call   10d0 <wctrans@plt>
test   %rax,%rax
je     1308 <main+0x148>
mov    %rax,%rbx
mov    $0x41,%edi
mov    %rax,%rsi
call   10b0 <towctrans@plt>
mov    %eax,%ebp
lea    0xe1c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    $0x42,%ebp
mov    $0x42,%edi
mov    %rbx,%rsi
call   10b0 <towctrans@plt>
mov    %eax,%ebx
lea    0xe14(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    $0x43,%ebx
or     %ebp,%ebx
setne  %r14b
lea    0xe56(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x1e,%esi
mov    $0x499602d2,%ecx
call   10a0 <swprintf@plt>
lea    0xe4a(%rip),%rsi
mov    %rbp,%rdi
call   1030 <wcscmp@plt>
test   %rax,%rax
setne  %r15b
mov    %rbp,%rdi
call   1070 <wcslen@plt>
cmp    $0xa,%eax
setne  %r12b
or     %r15b,%r12b
lea    0xdd1(%rip),%rdi
mov    %eax,%esi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdd7(%rip),%rdx
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    $0x1e,%esi
mov    $0x499602d2,%ecx
call   1080 <snprintf@plt>
lea    0xdbd(%rip),%rsi
mov    %r15,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
setne  %bl
or     %r12b,%bl
or     %r14b,%bl
mov    %r15,%rdi
call   1050 <strlen@plt>
cmp    $0xa,%eax
setne  %cl
or     %bl,%cl
movzbl %cl,%ebp
lea    0xd9a(%rip),%rdi
mov    %eax,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcf6(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"test\00"
@.str.2 = [38 x i8] c"locale data files probably not loaded\00"
@.str.3 = [26 x i8] c"towctrans (L'A', t) = %c\0A\00"
@.str.4 = [26 x i8] c"towctrans (L'B', t) = %c\0A\00"
@.str.5 = [4 x i32] [i32 37, i32 73, i32 100, i32 0]
@.str.6 = [11 x i32] [i32 98, i32 99, i32 100, i32 101, i32 102, i32 103, i32 104, i32 105, i32 106, i32 97, i32 0]
@.str.7 = [25 x i8] c"len = %d, wbuf = L\22%ls\22\0A\00"
@.str.8 = [4 x i8] c"%Id\00"
@.str.9 = [11 x i8] c"bcdefghija\00"
@.str.10 = [22 x i8] c"len = %d, buf = \22%s\22\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca [30 x i8]
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %6
%8 = load i32, i32* @LC_ALL
%9 = call i32 @setlocale(i32 %8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%10 = call i64 @wctrans(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i64 %10, i64* %4
%11 = load i64, i64* %4
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 @puts(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = load i64, i64* %4
%18 = call i32 @towctrans(i32 65, i64 %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %5
%22 = icmp ne i32 %21, 66
br i1 %22, label %23, label %24
23: ; preds = %16
store i32 1, i32* %6
br label %24
24: ; preds = %23, %16
%25 = load i64, i64* %4
%26 = call i32 @towctrans(i32 66, i64 %25)
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %5
%30 = icmp ne i32 %29, 67
br i1 %30, label %31, label %32
31: ; preds = %24
store i32 1, i32* %6
br label %32
32: ; preds = %31, %24
%33 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%34 = call i32 @swprintf(i8* %33, i32 30, i8* bitcast ([4 x i32]* @.str.5 to i8*), i32 1234567890)
%35 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%36 = call i64 @wcscmp(i8* %35, i8* bitcast ([11 x i32]* @.str.6 to i8*))
%37 = icmp ne i64 %36, 0
%38 = zext i1 %37 to i32
%39 = load i32, i32* %6
%40 = or i32 %39, %38
store i32 %40, i32* %6
%41 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%42 = call i32 @wcslen(i8* %41)
store i32 %42, i32* %7
%43 = load i32, i32* %7
%44 = icmp ne i32 %43, 10
%45 = zext i1 %44 to i32
%46 = load i32, i32* %6
%47 = or i32 %46, %45
store i32 %47, i32* %6
%48 = load i32, i32* %7
%49 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%50 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i32 %48, i8* %49)
%51 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%52 = call i32 @snprintf(i8* %51, i32 30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 1234567890)
%53 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%54 = call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%55 = icmp ne i64 %54, 0
%56 = zext i1 %55 to i32
%57 = load i32, i32* %6
%58 = or i32 %57, %56
store i32 %58, i32* %6
%59 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%60 = call i32 @strlen(i8* %59)
store i32 %60, i32* %7
%61 = load i32, i32* %7
%62 = icmp ne i32 %61, 10
%63 = zext i1 %62 to i32
%64 = load i32, i32* %6
%65 = or i32 %64, %63
store i32 %65, i32* %6
%66 = load i32, i32* %7
%67 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%68 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i32 %66, i8* %67)
%69 = load i32, i32* %6
ret i32 %69
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"test\00"
@.str.2 = [38 x i8] c"locale data files probably not loaded\00"
@.str.3 = [26 x i8] c"towctrans (L'A', t) = %c\0A\00"
@.str.4 = [26 x i8] c"towctrans (L'B', t) = %c\0A\00"
@.str.5 = [4 x i32] [i32 37, i32 73, i32 100, i32 0]
@.str.6 = [11 x i32] [i32 98, i32 99, i32 100, i32 101, i32 102, i32 103, i32 104, i32 105, i32 106, i32 97, i32 0]
@.str.7 = [25 x i8] c"len = %d, wbuf = L\22%ls\22\0A\00"
@.str.8 = [4 x i8] c"%Id\00"
@.str.9 = [11 x i8] c"bcdefghija\00"
@.str.10 = [22 x i8] c"len = %d, buf = \22%s\22\0A\00"
define i32 @main() {
%1 = alloca [30 x i8]
%2 = alloca [30 x i8]
%3 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @LC_ALL
%6 = tail call i32 @setlocale(i32 %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%7 = tail call i64 @wctrans(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = tail call i32 @towctrans(i32 65, i64 %7)
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = icmp ne i32 %13, 66
%16 = tail call i32 @towctrans(i32 66, i64 %7)
%17 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = icmp ne i32 %16, 67
%19 = or i1 %15, %18
%20 = call i32 @swprintf(i8* %4, i32 30, i8* bitcast ([4 x i32]* @.str.5 to i8*), i32 1234567890)
%21 = call i64 @wcscmp(i8* %4, i8* bitcast ([11 x i32]* @.str.6 to i8*))
%22 = icmp ne i64 %21, 0
%23 = or i1 %19, %22
%24 = call i32 @wcslen(i8* %4)
%25 = icmp ne i32 %24, 10
%26 = or i1 %23, %25
%27 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i32 %24, i8* %4)
%28 = call i32 @snprintf(i8* %3, i32 30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 1234567890)
%29 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%30 = icmp ne i64 %29, 0
%31 = or i1 %26, %30
%32 = call i32 @strlen(i8* %3)
%33 = icmp ne i32 %32, 10
%34 = or i1 %31, %33
%35 = zext i1 %34 to i32
%36 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i32 %32, i8* %3)
ret i32 %35
}