#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 */
struct charset {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
struct charset *charset_find(char *);
int charset_mbtowc(struct charset *, int *, char *, int);
int charset_wctomb(struct charset *, char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ test_any(struct charset *);
void test_iso2() {
  struct charset *charset;
  int wc;
  char s[3];
  charset = charset_find("iso-8859-2");
  test_any(charset);
  wc = 0;
  assert(charset_mbtowc(charset, &wc, "\302\200", 9) == 1 && wc == 0xc2);
  assert(charset_mbtowc(charset, &wc, "\377", 2) == 1 && wc == 0x2d9);
  strcpy(s, "..");
  assert(charset_wctomb(charset, s, 256) == -1 && !strcmp(s, ".."));
  assert(charset_wctomb(charset, s, 255) == -1 && !strcmp(s, ".."));
  assert(charset_wctomb(charset, s, 258) == 1 && !strcmp(s, "\303."));
  assert(charset_wctomb(charset, s, 128) == 1 && !strcmp(s, "\200."));
}


x86 assembly (clang, -O0):
<test_iso2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe81(%rip),%rdi
call   1050 <charset_find@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <test_any@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
lea    0xe64(%rip),%rdx
mov    $0x9,%ecx
call   1060 <charset_mbtowc@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x10(%rbp)
jne    11ce <test_iso2+0x5e>
cmpl   $0xc2,-0xc(%rbp)
sete   %al
mov    %al,-0x10(%rbp)
mov    -0x10(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
lea    0xe24(%rip),%rdx
mov    $0x2,%ecx
call   1060 <charset_mbtowc@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x11(%rbp)
jne    1211 <test_iso2+0xa1>
cmpl   $0x2d9,-0xc(%rbp)
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0xf(%rbp),%rdi
lea    0xde7(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
lea    -0xf(%rbp),%rsi
mov    $0x100,%edx
call   1030 <charset_wctomb@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x12(%rbp)
jne    126b <test_iso2+0xfb>
lea    -0xf(%rbp),%rdi
lea    0xdb5(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    -0xf(%rbp),%rsi
mov    $0xff,%edx
call   1030 <charset_wctomb@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x13(%rbp)
jne    12b5 <test_iso2+0x145>
lea    -0xf(%rbp),%rdi
lea    0xd6b(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x13(%rbp)
mov    -0x13(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    -0xf(%rbp),%rsi
mov    $0x102,%edx
call   1030 <charset_wctomb@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x14(%rbp)
jne    12ff <test_iso2+0x18f>
lea    -0xf(%rbp),%rdi
lea    0xd24(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x14(%rbp)
mov    -0x14(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    -0xf(%rbp),%rsi
mov    $0x80,%edx
call   1030 <charset_wctomb@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x15(%rbp)
jne    1349 <test_iso2+0x1d9>
lea    -0xf(%rbp),%rdi
lea    0xcdd(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_iso2>:
push   %rbp
push   %rbx
push   %rax
lea    0xe96(%rip),%rdi
call   1050 <charset_find@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <test_any@plt>
movl   $0x0,0x4(%rsp)
lea    0xe82(%rip),%rdx
lea    0x4(%rsp),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x9,%ecx
call   1060 <charset_mbtowc@plt>
mov    $0xc2,%ecx
xor    0x4(%rsp),%ecx
xor    $0x1,%eax
xor    %edi,%edi
or     %eax,%ecx
sete   %dil
call   1070 <assert@plt>
lea    0xe50(%rip),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x2,%ecx
call   1060 <charset_mbtowc@plt>
mov    $0x2d9,%ecx
xor    0x4(%rsp),%ecx
xor    $0x1,%eax
xor    %edi,%edi
or     %eax,%ecx
sete   %dil
call   1070 <assert@plt>
lea    0xe22(%rip),%rsi
lea    0x1(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x100,%edx
call   1030 <charset_wctomb@plt>
xor    %ebp,%ebp
mov    $0x0,%edi
cmp    $0xffffffff,%eax
jne    122f <test_iso2+0xcf>
movzwl 0x1(%rsp),%eax
xor    $0x2e2e,%eax
movzbl 0x3(%rsp),%ecx
xor    %edi,%edi
or     %ax,%cx
sete   %dil
call   1070 <assert@plt>
lea    0x1(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xff,%edx
call   1030 <charset_wctomb@plt>
cmp    $0xffffffff,%eax
jne    1263 <test_iso2+0x103>
movzwl 0x1(%rsp),%eax
xor    $0x2e2e,%eax
movzbl 0x3(%rsp),%ecx
xor    %ebp,%ebp
or     %ax,%cx
sete   %bpl
mov    %ebp,%edi
call   1070 <assert@plt>
lea    0x1(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x102,%edx
call   1030 <charset_wctomb@plt>
xor    %ebp,%ebp
mov    $0x0,%edi
cmp    $0x1,%eax
jne    12a0 <test_iso2+0x140>
movzwl 0x1(%rsp),%eax
xor    $0x2ec3,%eax
movzbl 0x3(%rsp),%ecx
xor    %edi,%edi
or     %ax,%cx
sete   %dil
call   1070 <assert@plt>
lea    0x1(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x80,%edx
call   1030 <charset_wctomb@plt>
cmp    $0x1,%eax
jne    12d4 <test_iso2+0x174>
movzwl 0x1(%rsp),%eax
xor    $0x2e80,%eax
movzbl 0x3(%rsp),%ecx
xor    %ebp,%ebp
or     %ax,%cx
sete   %bpl
mov    %ebp,%edi
call   1070 <assert@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.charset = type { i32 }
@.str = [11 x i8] c"iso-8859-2\00"
@.str.1 = [3 x i8] c"\C2\80\00"
@.str.2 = [2 x i8] c"\FF\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [3 x i8] c"\C3.\00"
@.str.5 = [3 x i8] c"\80.\00"
define void @test_iso2() {
%1 = alloca %struct.charset*
%2 = alloca i32
%3 = alloca [3 x i8]
%4 = call %struct.charset* @charset_find(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store %struct.charset* %4, %struct.charset** %1
%5 = load %struct.charset*, %struct.charset** %1
%6 = call i32 @test_any(%struct.charset* %5)
store i32 0, i32* %2
%7 = load %struct.charset*, %struct.charset** %1
%8 = call i32 @charset_mbtowc(%struct.charset* %7, i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 9)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 194
br label %13
13: ; preds = %10, %0
%14 = phi i1 [ false, %0 ], [ %12, %10 ]
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load %struct.charset*, %struct.charset** %1
%18 = call i32 @charset_mbtowc(%struct.charset* %17, i32* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 2)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, 729
br label %23
23: ; preds = %20, %13
%24 = phi i1 [ false, %13 ], [ %22, %20 ]
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%28 = call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%29 = load %struct.charset*, %struct.charset** %1
%30 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%31 = call i32 @charset_wctomb(%struct.charset* %29, i8* %30, i32 256)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %38
33: ; preds = %23
%34 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%35 = call i32 @strcmp(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp ne i32 %35, 0
%37 = xor i1 %36, true
br label %38
38: ; preds = %33, %23
%39 = phi i1 [ false, %23 ], [ %37, %33 ]
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = load %struct.charset*, %struct.charset** %1
%43 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%44 = call i32 @charset_wctomb(%struct.charset* %42, i8* %43, i32 255)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %51
46: ; preds = %38
%47 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%48 = call i32 @strcmp(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%49 = icmp ne i32 %48, 0
%50 = xor i1 %49, true
br label %51
51: ; preds = %46, %38
%52 = phi i1 [ false, %38 ], [ %50, %46 ]
%53 = zext i1 %52 to i32
%54 = call i32 @assert(i32 %53)
%55 = load %struct.charset*, %struct.charset** %1
%56 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%57 = call i32 @charset_wctomb(%struct.charset* %55, i8* %56, i32 258)
%58 = icmp eq i32 %57, 1
br i1 %58, label %59, label %64
59: ; preds = %51
%60 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%61 = call i32 @strcmp(i8* %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%62 = icmp ne i32 %61, 0
%63 = xor i1 %62, true
br label %64
64: ; preds = %59, %51
%65 = phi i1 [ false, %51 ], [ %63, %59 ]
%66 = zext i1 %65 to i32
%67 = call i32 @assert(i32 %66)
%68 = load %struct.charset*, %struct.charset** %1
%69 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%70 = call i32 @charset_wctomb(%struct.charset* %68, i8* %69, i32 128)
%71 = icmp eq i32 %70, 1
br i1 %71, label %72, label %77
72: ; preds = %64
%73 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%74 = call i32 @strcmp(i8* %73, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%75 = icmp ne i32 %74, 0
%76 = xor i1 %75, true
br label %77
77: ; preds = %72, %64
%78 = phi i1 [ false, %64 ], [ %76, %72 ]
%79 = zext i1 %78 to i32
%80 = call i32 @assert(i32 %79)
ret void
}

LLVM IR (-O2):
%struct.charset = type { i32 }
@.str = [11 x i8] c"iso-8859-2\00"
@.str.1 = [3 x i8] c"\C2\80\00"
@.str.2 = [2 x i8] c"\FF\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [3 x i8] c"\C3.\00"
@.str.5 = [3 x i8] c"\80.\00"
define void @test_iso2() {
%1 = alloca i32
%2 = alloca [3 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%5 = tail call %struct.charset* @charset_find(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @test_any(%struct.charset* %5)
store i32 0, i32* %1
%7 = call i32 @charset_mbtowc(%struct.charset* %5, i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 9)
%8 = icmp eq i32 %7, 1
%9 = load i32, i32* %1
%10 = icmp eq i32 %9, 194
%11 = select i1 %8, i1 %10, i1 false
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = call i32 @charset_mbtowc(%struct.charset* %5, i32* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 2)
%15 = icmp eq i32 %14, 1
%16 = load i32, i32* %1
%17 = icmp eq i32 %16, 729
%18 = select i1 %15, i1 %17, i1 false
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @charset_wctomb(%struct.charset* %5, i8* %4, i32 256)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %28
24: ; preds = %0
%25 = call i32 @bcmp(i8* dereferenceable(3) %4, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 3)
%26 = icmp eq i32 %25, 0
%27 = zext i1 %26 to i32
br label %28
28: ; preds = %24, %0
%29 = phi i32 [ 0, %0 ], [ %27, %24 ]
%30 = call i32 @assert(i32 %29)
%31 = call i32 @charset_wctomb(%struct.charset* %5, i8* %4, i32 255)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = call i32 @bcmp(i8* dereferenceable(3) %4, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 3)
%35 = icmp eq i32 %34, 0
%36 = zext i1 %35 to i32
br label %37
37: ; preds = %33, %28
%38 = phi i32 [ 0, %28 ], [ %36, %33 ]
%39 = call i32 @assert(i32 %38)
%40 = call i32 @charset_wctomb(%struct.charset* %5, i8* %4, i32 258)
%41 = icmp eq i32 %40, 1
br i1 %41, label %42, label %46
42: ; preds = %37
%43 = call i32 @bcmp(i8* dereferenceable(3) %4, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 3)
%44 = icmp eq i32 %43, 0
%45 = zext i1 %44 to i32
br label %46
46: ; preds = %42, %37
%47 = phi i32 [ 0, %37 ], [ %45, %42 ]
%48 = call i32 @assert(i32 %47)
%49 = call i32 @charset_wctomb(%struct.charset* %5, i8* %4, i32 128)
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %55
51: ; preds = %46
%52 = call i32 @bcmp(i8* dereferenceable(3) %4, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64 3)
%53 = icmp eq i32 %52, 0
%54 = zext i1 %53 to i32
br label %55
55: ; preds = %51, %46
%56 = phi i32 [ 0, %46 ], [ %54, %51 ]
%57 = call i32 @assert(i32 %56)
ret void
}