#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 wchar_t;
typedef int /*<<< orphan*/ s;
typedef char mbstate_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int MB_CUR_MAX;
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
size_t wcrtomb(char *, int, char *);
int check_ascii(const char *locname) {
  wchar_t wc;
  int res = 0;
  printf("Testing locale \"%s\":\n", locname);
  for (wc = 0; wc <= 127; ++wc) {
    char buf[2 * MB_CUR_MAX];
    mbstate_t s;
    size_t n;
    memset(buf, '\xff', sizeof(buf));
    memset(&s, '\0', sizeof(s));
    n = wcrtomb(buf, wc, &s);
    if (n == (size_t)-1) {
      printf("%s: '\\x%x': encoding error\n", locname, (int)wc);
      ++res;
    } else if (n == 0) {
      printf("%s: '\\x%x': 0 returned\n", locname, (int)wc);
      ++res;
    } else if (n != 1) {
      printf("%s: '\\x%x': not 1 returned\n", locname, (int)wc);
      ++res;
    } else if (wc != (wchar_t)buf[0]) {
      printf("%s: L'\\x%x': buf[0] != '\\x%x'\n", locname, (int)wc, (int)wc);
      ++res;
    }
  }
  printf(res == 1 ? "%d error\n" : "%d errors\n", res);
  return res != 0;
}


x86 assembly (clang, -O0):
<check_ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x7f,-0xc(%rbp)
jg     12a5 <check_ascii+0x175>
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
add    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    %eax,%edx
mov    $0xffffffff,%esi
call   1040 <memset@plt>
lea    -0x21(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1040 <memset@plt>
mov    -0x38(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x21(%rbp),%rdx
call   1050 <wcrtomb@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0xffffffffffffffff,-0x30(%rbp)
jne    11f2 <check_ascii+0xc2>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1290 <check_ascii+0x160>
cmpq   $0x0,-0x30(%rbp)
jne    1220 <check_ascii+0xf0>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    128b <check_ascii+0x15b>
cmpq   $0x1,-0x30(%rbp)
je     124e <check_ascii+0x11e>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1286 <check_ascii+0x156>
mov    -0x38(%rbp),%rcx
mov    -0xc(%rbp),%eax
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1281 <check_ascii+0x151>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1286 <check_ascii+0x156>
jmp    128b <check_ascii+0x15b>
jmp    1290 <check_ascii+0x160>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115c <check_ascii+0x2c>
mov    -0x10(%rbp),%ecx
lea    0xde0(%rip),%rdi
lea    0xdcf(%rip),%rax
cmp    $0x1,%ecx
cmove  %rax,%rdi
mov    -0x10(%rbp),%esi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_ascii>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rsi
lea    0xeb5(%rip),%rdi
mov    %rsi,-0x38(%rbp)
xor    %eax,%eax
call   1030 <printf@plt>
lea    -0x29(%rbp),%r15
xor    %r12d,%r12d
xor    %ebx,%ebx
jmp    119c <check_ascii+0x6c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xebb(%rip),%rdi
mov    -0x38(%rbp),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebx
mov    %r14,%rsp
add    $0x1,%r12d
cmp    $0x80,%r12d
je     124c <check_ascii+0x11c>
mov    %rsp,%r14
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
add    %edx,%edx
mov    %rsp,%r13
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    %r13,%rdi
mov    $0xffffffff,%esi
call   1040 <memset@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1040 <memset@plt>
mov    %r13,%rdi
mov    %r12d,%esi
mov    %r15,%rdx
call   1050 <wcrtomb@plt>
cmp    $0x1,%rax
je     1210 <check_ascii+0xe0>
test   %rax,%rax
je     1170 <check_ascii+0x40>
cmp    $0xffffffffffffffff,%rax
jne    1240 <check_ascii+0x110>
lea    0xe19(%rip),%rdi
jmp    1177 <check_ascii+0x47>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl 0x0(%r13),%eax
cmp    %eax,%r12d
je     1188 <check_ascii+0x58>
lea    0xe41(%rip),%rdi
mov    -0x38(%rbp),%rsi
mov    %r12d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1185 <check_ascii+0x55>
nopl   0x0(%rax,%rax,1)
lea    0xe03(%rip),%rdi
jmp    1177 <check_ascii+0x47>
cmp    $0x1,%ebx
lea    0xe2f(%rip),%rax
lea    0xe32(%rip),%rdi
cmove  %rax,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
test   %ebx,%ebx
setne  %al
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Testing locale \22%s\22:\0A\00"
@MB_CUR_MAX = global i32 0
@.str.1 = [28 x i8] c"%s: '\\x%x': encoding error\0A\00"
@.str.2 = [24 x i8] c"%s: '\\x%x': 0 returned\0A\00"
@.str.3 = [28 x i8] c"%s: '\\x%x': not 1 returned\0A\00"
@.str.4 = [31 x i8] c"%s: L'\\x%x': buf[0] != '\\x%x'\0A\00"
@.str.5 = [10 x i8] c"%d error\0A\00"
@.str.6 = [11 x i8] c"%d errors\0A\00"
define i32 @check_ascii(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8
%8 = alloca i64
store i8* %0, i8** %2
store i32 0, i32* %4
%9 = load i8*, i8** %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %9)
store i32 0, i32* %3
br label %11
11: ; preds = %69, %1
%12 = load i32, i32* %3
%13 = icmp sle i32 %12, 127
br i1 %13, label %14, label %72
14: ; preds = %11
%15 = load i32, i32* @MB_CUR_MAX
%16 = mul nsw i32 2, %15
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %5
%19 = alloca i8, i64 %17
store i64 %17, i64* %6
%20 = trunc i64 %17 to i32
%21 = call i32 @memset(i8* %19, i8 signext -1, i32 %20)
%22 = call i32 @memset(i8* %7, i8 signext 0, i32 1)
%23 = load i32, i32* %3
%24 = call i64 @wcrtomb(i8* %19, i32 %23, i8* %7)
store i64 %24, i64* %8
%25 = load i64, i64* %8
%26 = icmp eq i64 %25, -1
br i1 %26, label %27, label %33
27: ; preds = %14
%28 = load i8*, i8** %2
%29 = load i32, i32* %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %28, i32 %29)
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %67
33: ; preds = %14
%34 = load i64, i64* %8
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %33
%37 = load i8*, i8** %2
%38 = load i32, i32* %3
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %37, i32 %38)
%40 = load i32, i32* %4
%41 = add nsw i32 %40, 1
store i32 %41, i32* %4
br label %66
42: ; preds = %33
%43 = load i64, i64* %8
%44 = icmp ne i64 %43, 1
br i1 %44, label %45, label %51
45: ; preds = %42
%46 = load i8*, i8** %2
%47 = load i32, i32* %3
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %46, i32 %47)
%49 = load i32, i32* %4
%50 = add nsw i32 %49, 1
store i32 %50, i32* %4
br label %65
51: ; preds = %42
%52 = load i32, i32* %3
%53 = getelementptr inbounds i8, i8* %19, i64 0
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp ne i32 %52, %55
br i1 %56, label %57, label %64
57: ; preds = %51
%58 = load i8*, i8** %2
%59 = load i32, i32* %3
%60 = load i32, i32* %3
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %58, i32 %59, i32 %60)
%62 = load i32, i32* %4
%63 = add nsw i32 %62, 1
store i32 %63, i32* %4
br label %64
64: ; preds = %57, %51
br label %65
65: ; preds = %64, %45
br label %66
66: ; preds = %65, %36
br label %67
67: ; preds = %66, %27
%68 = load i8*, i8** %5
br label %69
69: ; preds = %67
%70 = load i32, i32* %3
%71 = add nsw i32 %70, 1
store i32 %71, i32* %3
br label %11
72: ; preds = %11
%73 = load i32, i32* %4
%74 = icmp eq i32 %73, 1
%75 = zext i1 %74 to i64
%76 = select i1 %74, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0)
%77 = load i32, i32* %4
%78 = call i32 (i8*, ...) @printf(i8* %76, i32 %77)
%79 = load i32, i32* %4
%80 = icmp ne i32 %79, 0
%81 = zext i1 %80 to i32
ret i32 %81
}

LLVM IR (-O2):
@.str = [22 x i8] c"Testing locale \22%s\22:\0A\00"
@MB_CUR_MAX = global i32 0
@.str.1 = [28 x i8] c"%s: '\\x%x': encoding error\0A\00"
@.str.2 = [24 x i8] c"%s: '\\x%x': 0 returned\0A\00"
@.str.3 = [28 x i8] c"%s: '\\x%x': not 1 returned\0A\00"
@.str.4 = [31 x i8] c"%s: L'\\x%x': buf[0] != '\\x%x'\0A\00"
@.str.5 = [10 x i8] c"%d error\0A\00"
@.str.6 = [11 x i8] c"%d errors\0A\00"
define i32 @check_ascii(i8* %0) {
%2 = alloca i8
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %4
4: ; preds = %1, %31
%5 = phi i32 [ 0, %1 ], [ %33, %31 ]
%6 = phi i32 [ 0, %1 ], [ %32, %31 ]
%7 = load i32, i32* @MB_CUR_MAX
%8 = shl nsw i32 %7, 1
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
%11 = alloca i8, i64 %9
%12 = call i32 @memset(i8* %11, i8 signext -1, i32 %8)
%13 = call i32 @memset(i8* %2, i8 signext 0, i32 1)
%14 = call i64 @wcrtomb(i8* %11, i32 %5, i8* %2)
switch i64 %14, label %21 [
i64 -1, label %15
i64 0, label %18
i64 1, label %24
]
15: ; preds = %4
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %5)
%17 = add nsw i32 %6, 1
br label %31
18: ; preds = %4
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %5)
%20 = add nsw i32 %6, 1
br label %31
21: ; preds = %4
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 %5)
%23 = add nsw i32 %6, 1
br label %31
24: ; preds = %4
%25 = load i8, i8* %11
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %5, %26
br i1 %27, label %31, label %28
28: ; preds = %24
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %0, i32 %5, i32 %5)
%30 = add nsw i32 %6, 1
br label %31
31: ; preds = %18, %24, %28, %21, %15
%32 = phi i32 [ %17, %15 ], [ %20, %18 ], [ %23, %21 ], [ %30, %28 ], [ %6, %24 ]
%33 = add nuw nsw i32 %5, 1
%34 = icmp eq i32 %33, 128
br i1 %34, label %35, label %4
35: ; preds = %31
%36 = icmp eq i32 %32, 1
%37 = select i1 %36, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %37, i32 %32)
%39 = icmp ne i32 %32, 0
%40 = zext i1 %39 to i32
ret i32 %40
}