#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 */

/* Variables and functions */
int /*<<< orphan*/ CODESET;
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ LC_CTYPE;
char *nl_langinfo(int /*<<< orphan*/);
char *setlocale(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ strstr(char *, char *);
int env_is_utf8(void) {
  char *codeset = nl_langinfo(CODESET);
  if (!codeset || !*codeset)
    codeset = setlocale(LC_CTYPE, NULL);
  if (!codeset || !*codeset)
    codeset = setlocale(LC_ALL, NULL);
  if (!codeset || !*codeset)
    return 0;
  return !strstr(codeset, "UTF-8") || !strstr(codeset, "utf8");
}


x86 assembly (clang, -O0):
<env_is_utf8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
call   1030 <nl_langinfo@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1162 <env_is_utf8+0x32>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1178 <env_is_utf8+0x48>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <setlocale@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1190 <env_is_utf8+0x60>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11a6 <env_is_utf8+0x76>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <setlocale@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11be <env_is_utf8+0x8e>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11ca <env_is_utf8+0x9a>
movl   $0x0,-0x4(%rbp)
jmp    1210 <env_is_utf8+0xe0>
mov    -0x10(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1050 <strstr@plt>
mov    %eax,%ecx
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     1205 <env_is_utf8+0xd5>
mov    -0x10(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<env_is_utf8>:
push   %r14
push   %rbx
push   %rax
mov    0x2ea5(%rip),%rax
mov    (%rax),%edi
call   1030 <nl_langinfo@plt>
test   %rax,%rax
je     114f <env_is_utf8+0x1f>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
jne    118c <env_is_utf8+0x5c>
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
xor    %r14d,%r14d
xor    %esi,%esi
call   1040 <setlocale@plt>
test   %rax,%rax
je     116f <env_is_utf8+0x3f>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
jne    118c <env_is_utf8+0x5c>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1040 <setlocale@plt>
test   %rax,%rax
je     11bf <env_is_utf8+0x8f>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     11bf <env_is_utf8+0x8f>
lea    0xe6d(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strstr@plt>
test   %eax,%eax
je     11b9 <env_is_utf8+0x89>
lea    0xe60(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strstr@plt>
xor    %r14d,%r14d
test   %eax,%eax
sete   %r14b
jmp    11bf <env_is_utf8+0x8f>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@CODESET = global i32 0
@LC_CTYPE = global i32 0
@LC_ALL = global i32 0
@.str = [6 x i8] c"UTF-8\00"
@.str.1 = [5 x i8] c"utf8\00"
define i32 @env_is_utf8() {
%1 = alloca i32
%2 = alloca i8*
%3 = load i32, i32* @CODESET
%4 = call i8* @nl_langinfo(i32 %3)
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %7, %0
%12 = load i32, i32* @LC_CTYPE
%13 = call i8* @setlocale(i32 %12, i32* null)
store i8* %13, i8** %2
br label %14
14: ; preds = %11, %7
%15 = load i8*, i8** %2
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i8*, i8** %2
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %17, %14
%22 = load i32, i32* @LC_ALL
%23 = call i8* @setlocale(i32 %22, i32* null)
store i8* %23, i8** %2
br label %24
24: ; preds = %21, %17
%25 = load i8*, i8** %2
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i8*, i8** %2
%29 = load i8, i8* %28
%30 = icmp ne i8 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %27, %24
store i32 0, i32* %1
br label %44
32: ; preds = %27
%33 = load i8*, i8** %2
%34 = call i32 @strstr(i8* %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = load i8*, i8** %2
%38 = call i32 @strstr(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%39 = icmp ne i32 %38, 0
%40 = xor i1 %39, true
br label %41
41: ; preds = %36, %32
%42 = phi i1 [ true, %32 ], [ %40, %36 ]
%43 = zext i1 %42 to i32
store i32 %43, i32* %1
br label %44
44: ; preds = %41, %31
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@CODESET = global i32 0
@LC_CTYPE = global i32 0
@LC_ALL = global i32 0
@.str = [6 x i8] c"UTF-8\00"
@.str.1 = [5 x i8] c"utf8\00"
define i32 @env_is_utf8() {
%1 = load i32, i32* @CODESET
%2 = tail call i8* @nl_langinfo(i32 %1)
%3 = icmp eq i8* %2, null
br i1 %3, label %7, label %4
4: ; preds = %0
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
br i1 %6, label %7, label %21
7: ; preds = %0, %4
%8 = load i32, i32* @LC_CTYPE
%9 = tail call i8* @setlocale(i32 %8, i32* null)
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %7
%12 = load i8, i8* %9
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %7, %11
%15 = load i32, i32* @LC_ALL
%16 = tail call i8* @setlocale(i32 %15, i32* null)
%17 = icmp eq i8* %16, null
br i1 %17, label %29, label %18
18: ; preds = %14
%19 = load i8, i8* %16
%20 = icmp eq i8 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %11, %4, %18
%22 = phi i8* [ %16, %18 ], [ %2, %4 ], [ %9, %11 ]
%23 = tail call i32 @strstr(i8* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = tail call i32 @strstr(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i32 %26, 0
%28 = zext i1 %27 to i32
br label %29
29: ; preds = %21, %25, %14, %18
%30 = phi i32 [ 0, %18 ], [ 0, %14 ], [ 1, %21 ], [ %28, %25 ]
ret i32 %30
}