#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*/ LC_ALL;
int /*<<< orphan*/ LC_CTYPE;
char *setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strcmp(char *, char *);
void init_locale(void) {
  char *s = setlocale(LC_ALL, "");
  if (s) {
    s = setlocale(LC_CTYPE, NULL);
    if (s && !strcmp(s, "C")) {
      s = setlocale(LC_CTYPE, "iso_8859_1");
      if (!s)
        s = setlocale(LC_CTYPE, "C");
    }
  }
}


x86 assembly (clang, -O0):
<init_locale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
lea    0xed4(%rip),%rsi
call   1040 <setlocale@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11cd <init_locale+0xad>
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <setlocale@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11c8 <init_locale+0xa8>
mov    -0x8(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11c8 <init_locale+0xa8>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
call   1040 <setlocale@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11c3 <init_locale+0xa3>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1040 <setlocale@plt>
mov    %rax,-0x8(%rbp)
jmp    11c8 <init_locale+0xa8>
jmp    11cd <init_locale+0xad>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_locale>:
push   %rbx
mov    0x2eb0(%rip),%rax
mov    (%rax),%edi
lea    0xedb(%rip),%rsi
call   1040 <setlocale@plt>
test   %rax,%rax
je     1176 <init_locale+0x56>
mov    0x2ea6(%rip),%rbx
mov    (%rbx),%edi
xor    %esi,%esi
call   1040 <setlocale@plt>
test   %rax,%rax
je     1176 <init_locale+0x56>
lea    0xea9(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
jne    1176 <init_locale+0x56>
mov    (%rbx),%edi
lea    0xe96(%rip),%rsi
call   1040 <setlocale@plt>
test   %rax,%rax
je     1178 <init_locale+0x58>
pop    %rbx
ret
mov    (%rbx),%edi
lea    0xe7f(%rip),%rsi
pop    %rbx
jmp    1040 <setlocale@plt>

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@LC_CTYPE = global i32 0
@.str.1 = [2 x i8] c"C\00"
@.str.2 = [11 x i8] c"iso_8859_1\00"
define void @init_locale() {
%1 = alloca i8*
%2 = load i32, i32* @LC_ALL
%3 = call i8* @setlocale(i32 %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %1
%4 = load i8*, i8** %1
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %25
6: ; preds = %0
%7 = load i32, i32* @LC_CTYPE
%8 = call i8* @setlocale(i32 %7, i8* null)
store i8* %8, i8** %1
%9 = load i8*, i8** %1
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %24
11: ; preds = %6
%12 = load i8*, i8** %1
%13 = call i32 @strcmp(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp ne i32 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %11
%16 = load i32, i32* @LC_CTYPE
%17 = call i8* @setlocale(i32 %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i8* %17, i8** %1
%18 = load i8*, i8** %1
%19 = icmp ne i8* %18, null
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = load i32, i32* @LC_CTYPE
%22 = call i8* @setlocale(i32 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %22, i8** %1
br label %23
23: ; preds = %20, %15
br label %24
24: ; preds = %23, %11, %6
br label %25
25: ; preds = %24, %0
ret void
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@LC_CTYPE = global i32 0
@.str.1 = [2 x i8] c"C\00"
@.str.2 = [11 x i8] c"iso_8859_1\00"
define void @init_locale() {
%1 = load i32, i32* @LC_ALL
%2 = tail call i8* @setlocale(i32 %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %18, label %4
4: ; preds = %0
%5 = load i32, i32* @LC_CTYPE
%6 = tail call i8* @setlocale(i32 %5, i8* null)
%7 = icmp eq i8* %6, null
br i1 %7, label %18, label %8
8: ; preds = %4
%9 = tail call i32 @strcmp(i8* %6, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = load i32, i32* @LC_CTYPE
%13 = tail call i8* @setlocale(i32 %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* @LC_CTYPE
%17 = tail call i8* @setlocale(i32 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %4, %8, %15, %11, %0
ret void
}