#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;
char *nl_langinfo(int /*<<< orphan*/);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
scalar_t__ strcmp(char const *, char *);
bool is_locale_utf8(void) {
  const char *set;
  if (!setlocale(LC_ALL, ""))
    return true;
  set = nl_langinfo(CODESET);
  if (!set)
    return true;
  return (strcmp((set), ("UTF-8")) == 0);
}


x86 assembly (clang, -O0):
<is_locale_utf8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
lea    0xebd(%rip),%rsi
call   1050 <setlocale@plt>
cmp    $0x0,%eax
jne    1162 <is_locale_utf8+0x32>
movl   $0x1,-0x4(%rbp)
jmp    11aa <is_locale_utf8+0x7a>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
call   1040 <nl_langinfo@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118b <is_locale_utf8+0x5b>
movl   $0x1,-0x4(%rbp)
jmp    11aa <is_locale_utf8+0x7a>
mov    -0x10(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_locale_utf8>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    (%rax),%edi
lea    0xec4(%rip),%rsi
call   1050 <setlocale@plt>
mov    $0x1,%ebx
test   %eax,%eax
je     1179 <is_locale_utf8+0x49>
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
call   1040 <nl_langinfo@plt>
test   %rax,%rax
je     1179 <is_locale_utf8+0x49>
lea    0xe97(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@CODESET = global i32 0
@.str.1 = [6 x i8] c"UTF-8\00"
define i32 @is_locale_utf8() {
%1 = alloca i32
%2 = alloca i8*
%3 = load i32, i32* @LC_ALL
%4 = call i32 @setlocale(i32 %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%5 = icmp ne i32 %4, 0
br i1 %5, label %7, label %6
6: ; preds = %0
store i32 1, i32* %1
br label %18
7: ; preds = %0
%8 = load i32, i32* @CODESET
%9 = call i8* @nl_langinfo(i32 %8)
store i8* %9, i8** %2
%10 = load i8*, i8** %2
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %7
store i32 1, i32* %1
br label %18
13: ; preds = %7
%14 = load i8*, i8** %2
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i32
store i32 %17, i32* %1
br label %18
18: ; preds = %13, %12, %6
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@CODESET = global i32 0
@.str.1 = [6 x i8] c"UTF-8\00"
define i32 @is_locale_utf8() {
%1 = load i32, i32* @LC_ALL
%2 = tail call i32 @setlocale(i32 %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32 %2, 0
br i1 %3, label %12, label %4
4: ; preds = %0
%5 = load i32, i32* @CODESET
%6 = tail call i8* @nl_langinfo(i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
%11 = zext i1 %10 to i32
br label %12
12: ; preds = %4, %0, %8
%13 = phi i32 [ %11, %8 ], [ 1, %0 ], [ 1, %4 ]
ret i32 %13
}