#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_ascii() {
  struct charset *charset;
  int wc;
  char s[3];
  charset = charset_find("us-ascii");
  test_any(charset);
  wc = 0;
  assert(charset_mbtowc(charset, &wc, "\177", 2) == 1 && wc == 127);
  assert(charset_mbtowc(charset, &wc, "\200", 2) == -1);
  safe_strncpy(s, "..", sizeof(s));
  assert(charset_wctomb(charset, s, 256) == -1 && !strcmp(s, ".."));
  assert(charset_wctomb(charset, s, 255) == -1);
  assert(charset_wctomb(charset, s, 128) == -1);
  assert(charset_wctomb(charset, s, 127) == 1 && !strcmp(s, "\177."));
}


x86 assembly (clang, -O0):
<test_ascii>:
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    0xe62(%rip),%rdx
mov    $0x2,%ecx
call   1050 <charset_mbtowc@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x10(%rbp)
jne    11cb <test_ascii+0x5b>
cmpl   $0x7f,-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   1050 <charset_mbtowc@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0xf(%rbp),%rdi
lea    0xe01(%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    1253 <test_ascii+0xe3>
lea    -0xf(%rbp),%rdi
lea    0xdca(%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>
cmp    $0xffffffff,%eax
sete   %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>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    -0xf(%rbp),%rsi
mov    $0x7f,%edx
call   1030 <charset_wctomb@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x12(%rbp)
jne    12e1 <test_ascii+0x171>
lea    -0xf(%rbp),%rdi
lea    0xd3f(%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>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_ascii>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
call   1040 <charset_find@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <test_any@plt>
movl   $0x0,0xc(%rsp)
lea    0xe7b(%rip),%rdx
lea    0xc(%rsp),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x2,%ecx
call   1050 <charset_mbtowc@plt>
xor    $0x1,%eax
mov    0xc(%rsp),%ecx
xor    $0x7f,%ecx
xor    %edi,%edi
or     %eax,%ecx
sete   %dil
call   1070 <assert@plt>
lea    0xe4a(%rip),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x2,%ecx
call   1050 <charset_mbtowc@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1070 <assert@plt>
lea    0xe27(%rip),%rsi
lea    0x9(%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    %r14d,%r14d
mov    $0x0,%edi
cmp    $0xffffffff,%eax
jne    122d <test_ascii+0xcd>
movzwl 0x9(%rsp),%eax
xor    $0x2e2e,%eax
movzbl 0xb(%rsp),%ecx
xor    %edi,%edi
or     %ax,%cx
sete   %dil
call   1070 <assert@plt>
lea    0x9(%rsp),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0xff,%edx
call   1030 <charset_wctomb@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x80,%edx
call   1030 <charset_wctomb@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x7f,%edx
call   1030 <charset_wctomb@plt>
cmp    $0x1,%eax
jne    12a1 <test_ascii+0x141>
movzwl 0x9(%rsp),%eax
xor    $0x2e7f,%eax
movzbl 0xb(%rsp),%ecx
xor    %r14d,%r14d
or     %ax,%cx
sete   %r14b
mov    %r14d,%edi
call   1070 <assert@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.charset = type { i32 }
@.str = [9 x i8] c"us-ascii\00"
@.str.1 = [2 x i8] c"\7F\00"
@.str.2 = [2 x i8] c"\80\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [3 x i8] c"\7F.\00"
define void @test_ascii() {
%1 = alloca %struct.charset*
%2 = alloca i32
%3 = alloca [3 x i8]
%4 = call %struct.charset* @charset_find(i8* getelementptr inbounds ([9 x i8], [9 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 ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 2)
%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, 127
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
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%23 = call i32 @safe_strncpy(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 3)
%24 = load %struct.charset*, %struct.charset** %1
%25 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%26 = call i32 @charset_wctomb(%struct.charset* %24, i8* %25, i32 256)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %33
28: ; preds = %13
%29 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%30 = call i32 @strcmp(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
%32 = xor i1 %31, true
br label %33
33: ; preds = %28, %13
%34 = phi i1 [ false, %13 ], [ %32, %28 ]
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = load %struct.charset*, %struct.charset** %1
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%39 = call i32 @charset_wctomb(%struct.charset* %37, i8* %38, i32 255)
%40 = icmp eq i32 %39, -1
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = load %struct.charset*, %struct.charset** %1
%44 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%45 = call i32 @charset_wctomb(%struct.charset* %43, i8* %44, i32 128)
%46 = icmp eq i32 %45, -1
%47 = zext i1 %46 to i32
%48 = call i32 @assert(i32 %47)
%49 = load %struct.charset*, %struct.charset** %1
%50 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%51 = call i32 @charset_wctomb(%struct.charset* %49, i8* %50, i32 127)
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %58
53: ; preds = %33
%54 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%55 = call i32 @strcmp(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%56 = icmp ne i32 %55, 0
%57 = xor i1 %56, true
br label %58
58: ; preds = %53, %33
%59 = phi i1 [ false, %33 ], [ %57, %53 ]
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
ret void
}

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