#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 EXIT_SUCCESS;
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ LC_NUMERIC;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ localeconv();
int /*<<< orphan*/ printenv(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
char *setlocale(int /*<<< orphan*/, char *);
int main(int argc, char *argv[]) {
  char *old_locale;
  printf("set env to C\n");
  if ((old_locale = setlocale(LC_ALL, "C")) == NULL) {
    printf("set locale failed\n");
    exit(2);
  } else {
    printenv(localeconv());
  }
  printf("set env to en_GB\n");
  if ((old_locale = setlocale(LC_NUMERIC, "en_GB.utf8")) == NULL) {
    printf("set locale failed\n");
    exit(2);
  } else {
    printenv(localeconv());
  }
  printf("set env to zh_CN\n");
  if ((old_locale = setlocale(LC_NUMERIC, "zh_CN.utf8")) == NULL) {
    printf("set locale failed\n");
    exit(2);
  } else {
    printenv(localeconv());
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
call   1060 <setlocale@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ab <main+0x5b>
lea    0xe74(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1030 <localeconv@plt>
mov    %eax,%edi
call   1050 <printenv@plt>
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1060 <setlocale@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11fe <main+0xae>
lea    0xe21(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1030 <localeconv@plt>
mov    %eax,%edi
call   1050 <printenv@plt>
lea    0xe2d(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
call   1060 <setlocale@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1251 <main+0x101>
lea    0xdce(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1030 <localeconv@plt>
mov    %eax,%edi
call   1050 <printenv@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xebe(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xeb4(%rip),%rsi
call   1060 <setlocale@plt>
test   %rax,%rax
je     11f1 <main+0xa1>
xor    %eax,%eax
call   1040 <localeconv@plt>
mov    %eax,%edi
call   1050 <printenv@plt>
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e50(%rip),%rbx
mov    (%rbx),%edi
lea    0xe5f(%rip),%rsi
call   1060 <setlocale@plt>
test   %rax,%rax
je     11f1 <main+0xa1>
xor    %eax,%eax
call   1040 <localeconv@plt>
mov    %eax,%edi
call   1050 <printenv@plt>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%edi
lea    0xe3d(%rip),%rsi
call   1060 <setlocale@plt>
test   %rax,%rax
je     11f1 <main+0xa1>
xor    %eax,%eax
call   1040 <localeconv@plt>
mov    %eax,%edi
call   1050 <printenv@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"set env to C\0A\00"
@LC_ALL = global i32 0
@.str.1 = [2 x i8] c"C\00"
@.str.2 = [19 x i8] c"set locale failed\0A\00"
@.str.3 = [18 x i8] c"set env to en_GB\0A\00"
@LC_NUMERIC = global i32 0
@.str.4 = [11 x i8] c"en_GB.utf8\00"
@.str.5 = [18 x i8] c"set env to zh_CN\0A\00"
@.str.6 = [11 x i8] c"zh_CN.utf8\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @LC_ALL
%9 = call i8* @setlocale(i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %9, i8** %6
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @exit(i32 2)
unreachable
14: ; preds = %2
%15 = call i32 (...) @localeconv()
%16 = call i32 @printenv(i32 %15)
br label %17
17: ; preds = %14
%18 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%19 = load i32, i32* @LC_NUMERIC
%20 = call i8* @setlocale(i32 %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
store i8* %20, i8** %6
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @exit(i32 2)
unreachable
25: ; preds = %17
%26 = call i32 (...) @localeconv()
%27 = call i32 @printenv(i32 %26)
br label %28
28: ; preds = %25
%29 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%30 = load i32, i32* @LC_NUMERIC
%31 = call i8* @setlocale(i32 %30, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
store i8* %31, i8** %6
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @exit(i32 2)
unreachable
36: ; preds = %28
%37 = call i32 (...) @localeconv()
%38 = call i32 @printenv(i32 %37)
br label %39
39: ; preds = %36
%40 = load i32, i32* @EXIT_SUCCESS
ret i32 %40
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str.1 = [2 x i8] c"C\00"
@LC_NUMERIC = global i32 0
@.str.4 = [11 x i8] c"en_GB.utf8\00"
@.str.6 = [11 x i8] c"zh_CN.utf8\00"
@EXIT_SUCCESS = global i32 0
@str = [13 x i8] c"set env to C\00"
@str.7 = [17 x i8] c"set env to en_GB\00"
@str.8 = [17 x i8] c"set env to zh_CN\00"
@str.11 = [18 x i8] c"set locale failed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%4 = load i32, i32* @LC_ALL
%5 = tail call i8* @setlocale(i32 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.11, i64 0, i64 0))
%9 = tail call i32 @exit(i32 2)
unreachable
10: ; preds = %2
%11 = tail call i32 (...) @localeconv()
%12 = tail call i32 @printenv(i32 %11)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0))
%14 = load i32, i32* @LC_NUMERIC
%15 = tail call i8* @setlocale(i32 %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.11, i64 0, i64 0))
%19 = tail call i32 @exit(i32 2)
unreachable
20: ; preds = %10
%21 = tail call i32 (...) @localeconv()
%22 = tail call i32 @printenv(i32 %21)
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.8, i64 0, i64 0))
%24 = load i32, i32* @LC_NUMERIC
%25 = tail call i8* @setlocale(i32 %24, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.11, i64 0, i64 0))
%29 = tail call i32 @exit(i32 2)
unreachable
30: ; preds = %20
%31 = tail call i32 (...) @localeconv()
%32 = tail call i32 @printenv(i32 %31)
%33 = load i32, i32* @EXIT_SUCCESS
ret i32 %33
}