#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_CTYPE;
int /*<<< orphan*/ nl_langinfo(int /*<<< orphan*/);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int /*<<< orphan*/ trace_error(char *, int /*<<< orphan*/);
int /*<<< orphan*/ trace_warn(char *);
int locale_init(void) {
  int rc;
  if (!setlocale(LC_CTYPE, "")) {
    trace_warn(
        "Can't set the specified locale! Check LANG, LC_CTYPE, LC_ALL.\n");
    return 1;
  };
  rc = (strcmp(nl_langinfo(CODESET), "UTF-8") &&
        strcmp(nl_langinfo(CODESET), "ANSI_X3.4-1968"));
  if (rc) {
    trace_error("Encoding %s unsupported!\n", nl_langinfo(CODESET));
  }
  return rc;
}


x86 assembly (clang, -O0):
<locale_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
lea    0xf05(%rip),%rsi
call   1070 <setlocale@plt>
cmp    $0x0,%eax
jne    118e <locale_init+0x3e>
lea    0xe83(%rip),%rdi
call   1030 <trace_warn@plt>
movl   $0x1,-0x4(%rbp)
jmp    1219 <locale_init+0xc9>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1050 <nl_langinfo@plt>
mov    %eax,%edi
lea    0xe9a(%rip),%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x9(%rbp)
je     11e2 <locale_init+0x92>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1050 <nl_langinfo@plt>
mov    %eax,%edi
lea    0xe72(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1213 <locale_init+0xc3>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1050 <nl_langinfo@plt>
mov    %eax,%esi
lea    0xe46(%rip),%rdi
call   1060 <trace_error@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<locale_init>:
push   %r14
push   %rbx
push   %rax
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    0xf09(%rip),%rsi
call   1070 <setlocale@plt>
test   %eax,%eax
je     11c4 <locale_init+0x74>
mov    0x2e6c(%rip),%r14
mov    (%r14),%edi
call   1050 <nl_langinfo@plt>
lea    0xebc(%rip),%rsi
mov    %eax,%edi
call   1040 <strcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11d5 <locale_init+0x85>
mov    (%r14),%edi
call   1050 <nl_langinfo@plt>
lea    0xea5(%rip),%rsi
mov    %eax,%edi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11d5 <locale_init+0x85>
mov    (%r14),%edi
call   1050 <nl_langinfo@plt>
lea    0xe99(%rip),%rdi
mov    %eax,%esi
call   1060 <trace_error@plt>
jmp    11d0 <locale_init+0x80>
lea    0xe35(%rip),%rdi
call   1030 <trace_warn@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@LC_CTYPE = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [63 x i8] c"Can't set the specified locale! Check LANG, LC_CTYPE, LC_ALL.\0A\00"
@CODESET = global i32 0
@.str.2 = [6 x i8] c"UTF-8\00"
@.str.3 = [15 x i8] c"ANSI_X3.4-1968\00"
@.str.4 = [26 x i8] c"Encoding %s unsupported!\0A\00"
define i32 @locale_init() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @LC_CTYPE
%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 %8, label %6
6: ; preds = %0
%7 = call i32 @trace_warn(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %29
8: ; preds = %0
%9 = load i32, i32* @CODESET
%10 = call i32 @nl_langinfo(i32 %9)
%11 = call i64 @strcmp(i32 %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i32, i32* @CODESET
%15 = call i32 @nl_langinfo(i32 %14)
%16 = call i64 @strcmp(i32 %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
br label %18
18: ; preds = %13, %8
%19 = phi i1 [ false, %8 ], [ %17, %13 ]
%20 = zext i1 %19 to i32
store i32 %20, i32* %2
%21 = load i32, i32* %2
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i32, i32* @CODESET
%25 = call i32 @nl_langinfo(i32 %24)
%26 = call i32 @trace_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %23, %18
%28 = load i32, i32* %2
store i32 %28, i32* %1
br label %29
29: ; preds = %27, %6
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@LC_CTYPE = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [63 x i8] c"Can't set the specified locale! Check LANG, LC_CTYPE, LC_ALL.\0A\00"
@CODESET = global i32 0
@.str.2 = [6 x i8] c"UTF-8\00"
@.str.3 = [15 x i8] c"ANSI_X3.4-1968\00"
@.str.4 = [26 x i8] c"Encoding %s unsupported!\0A\00"
define i32 @locale_init() {
%1 = load i32, i32* @LC_CTYPE
%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 %4, label %6
4: ; preds = %0
%5 = tail call i32 @trace_warn(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
br label %20
6: ; preds = %0
%7 = load i32, i32* @CODESET
%8 = tail call i32 @nl_langinfo(i32 %7)
%9 = tail call i64 @strcmp(i32 %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %6
%12 = load i32, i32* @CODESET
%13 = tail call i32 @nl_langinfo(i32 %12)
%14 = tail call i64 @strcmp(i32 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = load i32, i32* @CODESET
%18 = tail call i32 @nl_langinfo(i32 %17)
%19 = tail call i32 @trace_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %6, %11, %16, %4
%21 = phi i32 [ 1, %4 ], [ 1, %16 ], [ 0, %11 ], [ 0, %6 ]
ret i32 %21
}