#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 */
char EOF;
int /*<<< orphan*/ LC_CTYPE;
int MB_CUR_MAX;
int UCHAR_MAX;
int WEOF;
int /*<<< orphan*/ assert(int);
int btowc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
char wctob(int);
int main(int argc, char *argv[]) {
  int i;
  printf("1..2\n");
  assert(btowc(EOF) == WEOF);
  assert(wctob(WEOF) == EOF);
  for (i = 0; i < UCHAR_MAX; i++)
    assert(btowc(i) == (wchar_t)i && i == (int)wctob(i));
  assert(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
  assert(MB_CUR_MAX > 1);
  assert(btowc('A') == L'A' && wctob(L'A') == 'A');
  assert(btowc(0xa3) == WEOF && wctob(0xa3c1) == EOF);
  printf("ok 1 - btowc()\n");
  printf("ok 2 - wctob()\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e47(%rip),%rax
movsbl (%rax),%edi
call   1070 <btowc@plt>
mov    0x2e28(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1080 <wctob@plt>
movsbl %al,%eax
mov    0x2e11(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e06(%rip),%rcx
cmp    (%rcx),%eax
jge    1240 <main+0xe0>
mov    -0x14(%rbp),%edi
call   1070 <btowc@plt>
movslq %eax,%rcx
movslq -0x14(%rbp),%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x15(%rbp)
jne    1225 <main+0xc5>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <wctob@plt>
mov    %al,%cl
mov    -0x1c(%rbp),%eax
movsbl %cl,%ecx
cmp    %ecx,%eax
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d8 <main+0x78>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xdb6(%rip),%rsi
call   1060 <setlocale@plt>
mov    %eax,%edi
lea    0xda8(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0x2d7d(%rip),%rax
cmpl   $0x1,(%rax)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x41,%edi
call   1070 <btowc@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x41,%ecx
mov    %al,-0x1d(%rbp)
jne    12bb <main+0x15b>
mov    $0x41,%edi
call   1080 <wctob@plt>
movsbl %al,%eax
cmp    $0x41,%eax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0xa3,%edi
call   1070 <btowc@plt>
mov    %eax,%ecx
xor    %eax,%eax
mov    0x2ce3(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x1e(%rbp)
jne    1307 <main+0x1a7>
mov    $0xa3c1,%edi
call   1080 <wctob@plt>
movsbl %al,%eax
mov    0x2cd4(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
sete   %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xcf7(%rip),%rdi
call   1030 <printf@plt>
lea    0xcfb(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e55(%rip),%r14
movsbl (%r14),%edi
call   1070 <btowc@plt>
mov    0x2e35(%rip),%r15
xor    %edi,%edi
cmp    (%r15),%eax
sete   %dil
call   1050 <assert@plt>
mov    (%r15),%edi
call   1080 <wctob@plt>
xor    %edi,%edi
cmp    (%r14),%al
sete   %dil
call   1050 <assert@plt>
mov    0x2e32(%rip),%r12
cmpl   $0x0,(%r12)
jle    120a <main+0xaa>
xor    %ebx,%ebx
jmp    11f8 <main+0x98>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1080 <wctob@plt>
movsbq %al,%rax
mov    %eax,%eax
cmp    %rax,%rbx
sete   %al
movzbl %al,%edi
call   1050 <assert@plt>
add    $0x1,%rbx
movslq (%r12),%rax
cmp    %rax,%rbx
jge    120a <main+0xaa>
mov    %ebx,%edi
call   1070 <btowc@plt>
cltq
cmp    %rax,%rbx
je     11d0 <main+0x70>
xor    %eax,%eax
jmp    11e3 <main+0x83>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rbx
mov    %rbx,%rsi
call   1060 <setlocale@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    0x2db7(%rip),%rax
xor    %edi,%edi
cmpl   $0x2,(%rax)
setge  %dil
call   1050 <assert@plt>
mov    $0x41,%edi
call   1070 <btowc@plt>
xor    %ebx,%ebx
mov    $0x0,%edi
cmp    $0x41,%eax
jne    1277 <main+0x117>
mov    $0x41,%edi
call   1080 <wctob@plt>
xor    %edi,%edi
cmp    $0x41,%al
sete   %dil
call   1050 <assert@plt>
mov    $0xa3,%edi
call   1070 <btowc@plt>
cmp    (%r15),%eax
jne    129d <main+0x13d>
mov    $0xa3c1,%edi
call   1080 <wctob@plt>
xor    %ebx,%ebx
cmp    (%r14),%al
sete   %bl
mov    %ebx,%edi
call   1050 <assert@plt>
lea    0xd66(%rip),%rdi
call   1030 <puts@plt>
lea    0xd69(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"1..2\0A\00"
@EOF = global i8 0
@WEOF = global i32 0
@UCHAR_MAX = global i32 0
@LC_CTYPE = global i32 0
@.str.1 = [12 x i8] c"ja_JP.eucJP\00"
@MB_CUR_MAX = global i32 0
@.str.2 = [16 x i8] c"ok 1 - btowc()\0A\00"
@.str.3 = [16 x i8] c"ok 2 - wctob()\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = load i8, i8* @EOF
%9 = sext i8 %8 to i32
%10 = call i32 @btowc(i32 %9)
%11 = load i32, i32* @WEOF
%12 = icmp eq i32 %10, %11
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32, i32* @WEOF
%16 = call signext i8 @wctob(i32 %15)
%17 = sext i8 %16 to i32
%18 = load i8, i8* @EOF
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %17, %19
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
store i32 0, i32* %6
br label %23
23: ; preds = %44, %2
%24 = load i32, i32* %6
%25 = load i32, i32* @UCHAR_MAX
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %47
27: ; preds = %23
%28 = load i32, i32* %6
%29 = call i32 @btowc(i32 %28)
%30 = sext i32 %29 to i64
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = icmp eq i64 %30, %32
br i1 %33, label %34, label %40
34: ; preds = %27
%35 = load i32, i32* %6
%36 = load i32, i32* %6
%37 = call signext i8 @wctob(i32 %36)
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %35, %38
br label %40
40: ; preds = %34, %27
%41 = phi i1 [ false, %27 ], [ %39, %34 ]
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
br label %44
44: ; preds = %40
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
br label %23
47: ; preds = %23
%48 = load i32, i32* @LC_CTYPE
%49 = call i32 @setlocale(i32 %48, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%50 = call i64 @strcmp(i32 %49, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = load i32, i32* @MB_CUR_MAX
%55 = icmp sgt i32 %54, 1
%56 = zext i1 %55 to i32
%57 = call i32 @assert(i32 %56)
%58 = call i32 @btowc(i32 65)
%59 = icmp eq i32 %58, 65
br i1 %59, label %60, label %64
60: ; preds = %47
%61 = call signext i8 @wctob(i32 65)
%62 = sext i8 %61 to i32
%63 = icmp eq i32 %62, 65
br label %64
64: ; preds = %60, %47
%65 = phi i1 [ false, %47 ], [ %63, %60 ]
%66 = zext i1 %65 to i32
%67 = call i32 @assert(i32 %66)
%68 = call i32 @btowc(i32 163)
%69 = load i32, i32* @WEOF
%70 = icmp eq i32 %68, %69
br i1 %70, label %71, label %77
71: ; preds = %64
%72 = call signext i8 @wctob(i32 41921)
%73 = sext i8 %72 to i32
%74 = load i8, i8* @EOF
%75 = sext i8 %74 to i32
%76 = icmp eq i32 %73, %75
br label %77
77: ; preds = %71, %64
%78 = phi i1 [ false, %64 ], [ %76, %71 ]
%79 = zext i1 %78 to i32
%80 = call i32 @assert(i32 %79)
%81 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%82 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@EOF = global i8 0
@WEOF = global i32 0
@UCHAR_MAX = global i32 0
@LC_CTYPE = global i32 0
@.str.1 = [12 x i8] c"ja_JP.eucJP\00"
@MB_CUR_MAX = global i32 0
@str = [5 x i8] c"1..2\00"
@str.4 = [15 x i8] c"ok 1 - btowc()\00"
@str.5 = [15 x i8] c"ok 2 - wctob()\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%4 = load i8, i8* @EOF
%5 = sext i8 %4 to i32
%6 = tail call i32 @btowc(i32 %5)
%7 = load i32, i32* @WEOF
%8 = icmp eq i32 %6, %7
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = load i32, i32* @WEOF
%12 = tail call signext i8 @wctob(i32 %11)
%13 = load i8, i8* @EOF
%14 = icmp eq i8 %12, %13
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = load i32, i32* @UCHAR_MAX
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %38
19: ; preds = %2, %30
%20 = phi i64 [ %34, %30 ], [ 0, %2 ]
%21 = trunc i64 %20 to i32
%22 = tail call i32 @btowc(i32 %21)
%23 = sext i32 %22 to i64
%24 = icmp eq i64 %20, %23
br i1 %24, label %25, label %30
25: ; preds = %19
%26 = tail call signext i8 @wctob(i32 %21)
%27 = sext i8 %26 to i64
%28 = and i64 %27, 4294967295
%29 = icmp eq i64 %20, %28
br label %30
30: ; preds = %25, %19
%31 = phi i1 [ false, %19 ], [ %29, %25 ]
%32 = zext i1 %31 to i32
%33 = tail call i32 @assert(i32 %32)
%34 = add nuw nsw i64 %20, 1
%35 = load i32, i32* @UCHAR_MAX
%36 = sext i32 %35 to i64
%37 = icmp slt i64 %34, %36
br i1 %37, label %19, label %38
38: ; preds = %30, %2
%39 = load i32, i32* @LC_CTYPE
%40 = tail call i32 @setlocale(i32 %39, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%41 = tail call i64 @strcmp(i32 %40, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
%43 = zext i1 %42 to i32
%44 = tail call i32 @assert(i32 %43)
%45 = load i32, i32* @MB_CUR_MAX
%46 = icmp sgt i32 %45, 1
%47 = zext i1 %46 to i32
%48 = tail call i32 @assert(i32 %47)
%49 = tail call i32 @btowc(i32 65)
%50 = icmp eq i32 %49, 65
br i1 %50, label %51, label %55
51: ; preds = %38
%52 = tail call signext i8 @wctob(i32 65)
%53 = icmp eq i8 %52, 65
%54 = zext i1 %53 to i32
br label %55
55: ; preds = %51, %38
%56 = phi i32 [ 0, %38 ], [ %54, %51 ]
%57 = tail call i32 @assert(i32 %56)
%58 = tail call i32 @btowc(i32 163)
%59 = load i32, i32* @WEOF
%60 = icmp eq i32 %58, %59
br i1 %60, label %61, label %66
61: ; preds = %55
%62 = tail call signext i8 @wctob(i32 41921)
%63 = load i8, i8* @EOF
%64 = icmp eq i8 %62, %63
%65 = zext i1 %64 to i32
br label %66
66: ; preds = %61, %55
%67 = phi i32 [ 0, %55 ], [ %65, %61 ]
%68 = tail call i32 @assert(i32 %67)
%69 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.4, i64 0, i64 0))
%70 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.5, i64 0, i64 0))
ret i32 0
}