#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;
};
typedef int /*<<< orphan*/ s;

/* 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*/ safe_strncpy(char *, char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ test_any(struct charset *);
void test_iso1() {
  struct charset *charset;
  int wc;
  char s[3];
  charset = charset_find("iso-8859-1");
  test_any(charset);
  wc = 0;
  assert(charset_mbtowc(charset, &wc, "\302\200", 9) == 1 && wc == 0xc2);
  safe_strncpy(s, "..", sizeof(s));
  assert(charset_wctomb(charset, s, 256) == -1 && !strcmp(s, ".."));
  assert(charset_wctomb(charset, s, 255) == 1 && !strcmp(s, "\377."));
  assert(charset_wctomb(charset, s, 128) == 1 && !strcmp(s, "\200."));
}


x86 assembly (clang, -O0):
<test_iso1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe81(%rip),%rdi
call   1040 <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   1050 <charset_mbtowc@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x10(%rbp)
jne    11ce <test_iso1+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>
lea    -0xf(%rbp),%rdi
lea    0xe28(%rip),%rsi
mov    $0x3,%edx
call   1060 <safe_strncpy@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,-0x11(%rbp)
jne    122d <test_iso1+0xbd>
lea    -0xf(%rbp),%rdi
lea    0xdf1(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x11(%rbp)
mov    -0x11(%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    $0x1,%ecx
mov    %al,-0x12(%rbp)
jne    1277 <test_iso1+0x107>
lea    -0xf(%rbp),%rdi
lea    0xdaa(%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    $0x80,%edx
call   1030 <charset_wctomb@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x13(%rbp)
jne    12c1 <test_iso1+0x151>
lea    -0xf(%rbp),%rdi
lea    0xd63(%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>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_iso1>:
push   %rbp
push   %rbx
push   %rax
lea    0xe96(%rip),%rdi
call   1040 <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),%rsi
mov    %rbx,%rdi
mov    $0x9,%ecx
call   1050 <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    0xe53(%rip),%rsi
lea    0x1(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x3,%edx
call   1060 <safe_strncpy@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    1201 <test_iso1+0xa1>
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    $0x1,%eax
jne    1235 <test_iso1+0xd5>
movzwl 0x1(%rsp),%eax
xor    $0x2eff,%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    $0x80,%edx
call   1030 <charset_wctomb@plt>
xor    %edi,%edi
cmp    $0x1,%eax
jne    126d <test_iso1+0x10d>
movzwl 0x1(%rsp),%eax
xor    $0x2e80,%eax
movzbl 0x3(%rsp),%ecx
xor    %edi,%edi
or     %ax,%cx
sete   %dil
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-1\00"
@.str.1 = [3 x i8] c"\C2\80\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [3 x i8] c"\FF.\00"
@.str.4 = [3 x i8] c"\80.\00"
define void @test_iso1() {
%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 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%18 = call i32 @safe_strncpy(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 3)
%19 = load %struct.charset*, %struct.charset** %1
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%21 = call i32 @charset_wctomb(%struct.charset* %19, i8* %20, i32 256)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %28
23: ; preds = %13
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%25 = call i32 @strcmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
br label %28
28: ; preds = %23, %13
%29 = phi i1 [ false, %13 ], [ %27, %23 ]
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load %struct.charset*, %struct.charset** %1
%33 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%34 = call i32 @charset_wctomb(%struct.charset* %32, i8* %33, i32 255)
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %41
36: ; preds = %28
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%38 = call i32 @strcmp(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%39 = icmp ne i32 %38, 0
%40 = xor i1 %39, true
br label %41
41: ; preds = %36, %28
%42 = phi i1 [ false, %28 ], [ %40, %36 ]
%43 = zext i1 %42 to i32
%44 = call i32 @assert(i32 %43)
%45 = load %struct.charset*, %struct.charset** %1
%46 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%47 = call i32 @charset_wctomb(%struct.charset* %45, i8* %46, i32 128)
%48 = icmp eq i32 %47, 1
br i1 %48, label %49, label %54
49: ; preds = %41
%50 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%51 = call i32 @strcmp(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%52 = icmp ne i32 %51, 0
%53 = xor i1 %52, true
br label %54
54: ; preds = %49, %41
%55 = phi i1 [ false, %41 ], [ %53, %49 ]
%56 = zext i1 %55 to i32
%57 = call i32 @assert(i32 %56)
ret void
}

LLVM IR (-O2):
%struct.charset = type { i32 }
@.str = [11 x i8] c"iso-8859-1\00"
@.str.1 = [3 x i8] c"\C2\80\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [3 x i8] c"\FF.\00"
@.str.4 = [3 x i8] c"\80.\00"
define void @test_iso1() {
%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 @safe_strncpy(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 3)
%15 = call i32 @charset_wctomb(%struct.charset* %5, i8* %4, i32 256)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %0
%18 = call i32 @bcmp(i8* dereferenceable(3) %4, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 3)
%19 = icmp eq i32 %18, 0
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %17, %0
%22 = phi i32 [ 0, %0 ], [ %20, %17 ]
%23 = call i32 @assert(i32 %22)
%24 = call i32 @charset_wctomb(%struct.charset* %5, i8* %4, i32 255)
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = 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)
%28 = icmp eq i32 %27, 0
%29 = zext i1 %28 to i32
br label %30
30: ; preds = %26, %21
%31 = phi i32 [ 0, %21 ], [ %29, %26 ]
%32 = call i32 @assert(i32 %31)
%33 = call i32 @charset_wctomb(%struct.charset* %5, i8* %4, i32 128)
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = 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)
%37 = icmp eq i32 %36, 0
%38 = zext i1 %37 to i32
br label %39
39: ; preds = %35, %30
%40 = phi i32 [ 0, %30 ], [ %38, %35 ]
%41 = call i32 @assert(i32 %40)
ret void
}