#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*/ assert(int);
char *getenv(char *);
int /*<<< orphan*/ strcmp(char *, char *);
scalar_t__ strstr(char *, char *);
const char *nl_langinfo(int it) {
  char *locale;
  assert(it == 1234);
  locale = getenv("LC_ALL");
  if (!locale)
    locale = getenv("LC_CTYPE");
  if (!locale)
    locale = getenv("LANG");
  if (locale) {
    if (!strcmp(locale, "C") || !strcmp(locale, "POSIX"))
      return "ANSI_X3.4-1968";
    if (strstr(locale, "UTF-8") || strstr(locale, "utf-8") ||
        strstr(locale, "UTF8") || strstr(locale, "utf8")) {
      return "UTF-8";
    }
    return "ISO-8859-1";
  } else {
    return "ANSI_X3.4-1968";
  }
}


x86 assembly (clang, -O0):
<nl_langinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x4d2,-0xc(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xe9a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118a <nl_langinfo+0x4a>
lea    0xe86(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a5 <nl_langinfo+0x65>
lea    0xe74(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     127a <nl_langinfo+0x13a>
mov    -0x18(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
je     11e2 <nl_langinfo+0xa2>
mov    -0x18(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11f2 <nl_langinfo+0xb2>
lea    0xe34(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1285 <nl_langinfo+0x145>
mov    -0x18(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
jne    125a <nl_langinfo+0x11a>
mov    -0x18(%rbp),%rdi
lea    0xe1b(%rip),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
jne    125a <nl_langinfo+0x11a>
mov    -0x18(%rbp),%rdi
lea    0xe07(%rip),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
jne    125a <nl_langinfo+0x11a>
mov    -0x18(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     126a <nl_langinfo+0x12a>
lea    0xdcb(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1285 <nl_langinfo+0x145>
lea    0xdd1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1285 <nl_langinfo+0x145>
lea    0xd9c(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nl_langinfo>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
cmp    $0x4d2,%edi
sete   %al
mov    %eax,%edi
call   1050 <assert@plt>
lea    0xea3(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1196 <nl_langinfo+0x56>
lea    0xe96(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1196 <nl_langinfo+0x56>
lea    0xe8b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1228 <nl_langinfo+0xe8>
lea    0xe78(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
lea    0xe71(%rip),%r14
test   %eax,%eax
je     122f <nl_langinfo+0xef>
lea    0xe60(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     122f <nl_langinfo+0xef>
lea    0xe62(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
jne    122f <nl_langinfo+0xef>
lea    0xe51(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
jne    122f <nl_langinfo+0xef>
lea    0xe43(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
jne    122f <nl_langinfo+0xef>
lea    0xe34(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
lea    0xe27(%rip),%rax
lea    0xe0a(%rip),%r14
cmove  %rax,%r14
jmp    122f <nl_langinfo+0xef>
lea    0xdee(%rip),%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"LC_ALL\00"
@.str.1 = [9 x i8] c"LC_CTYPE\00"
@.str.2 = [5 x i8] c"LANG\00"
@.str.3 = [2 x i8] c"C\00"
@.str.4 = [6 x i8] c"POSIX\00"
@.str.5 = [15 x i8] c"ANSI_X3.4-1968\00"
@.str.6 = [6 x i8] c"UTF-8\00"
@.str.7 = [6 x i8] c"utf-8\00"
@.str.8 = [5 x i8] c"UTF8\00"
@.str.9 = [5 x i8] c"utf8\00"
@.str.10 = [11 x i8] c"ISO-8859-1\00"
define i8* @nl_langinfo(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, 1234
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %1
%13 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i8* %13, i8** %4
br label %14
14: ; preds = %12, %1
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8* %18, i8** %4
br label %19
19: ; preds = %17, %14
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %49
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = call i32 @strcmp(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i8*, i8** %4
%28 = call i32 @strcmp(i8* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %26, %22
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %50
31: ; preds = %26
%32 = load i8*, i8** %4
%33 = call i64 @strstr(i8* %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%34 = icmp ne i64 %33, 0
br i1 %34, label %47, label %35
35: ; preds = %31
%36 = load i8*, i8** %4
%37 = call i64 @strstr(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%38 = icmp ne i64 %37, 0
br i1 %38, label %47, label %39
39: ; preds = %35
%40 = load i8*, i8** %4
%41 = call i64 @strstr(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%42 = icmp ne i64 %41, 0
br i1 %42, label %47, label %43
43: ; preds = %39
%44 = load i8*, i8** %4
%45 = call i64 @strstr(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %43, %39, %35, %31
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %50
48: ; preds = %43
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i8** %2
br label %50
49: ; preds = %19
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %50
50: ; preds = %49, %48, %47, %30
%51 = load i8*, i8** %2
ret i8* %51
}

LLVM IR (-O2):
@.str = [7 x i8] c"LC_ALL\00"
@.str.1 = [9 x i8] c"LC_CTYPE\00"
@.str.2 = [5 x i8] c"LANG\00"
@.str.3 = [2 x i8] c"C\00"
@.str.4 = [6 x i8] c"POSIX\00"
@.str.5 = [15 x i8] c"ANSI_X3.4-1968\00"
@.str.6 = [6 x i8] c"UTF-8\00"
@.str.7 = [6 x i8] c"utf-8\00"
@.str.8 = [5 x i8] c"UTF8\00"
@.str.9 = [5 x i8] c"utf8\00"
@.str.10 = [11 x i8] c"ISO-8859-1\00"
define i8* @nl_langinfo(i32 %0) {
%2 = icmp eq i32 %0, 1234
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %33, label %13
13: ; preds = %1, %7, %10
%14 = phi i8* [ %11, %10 ], [ %8, %7 ], [ %5, %1 ]
%15 = tail call i32 @strcmp(i8* %14, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %33, label %17
17: ; preds = %13
%18 = tail call i32 @strcmp(i8* %14, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
br i1 %19, label %33, label %20
20: ; preds = %17
%21 = tail call i64 @strstr(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %20
%24 = tail call i64 @strstr(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = tail call i64 @strstr(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = tail call i64 @strstr(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
%32 = select i1 %31, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0)
br label %33
33: ; preds = %29, %10, %20, %23, %26, %13, %17
%34 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), %17 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), %13 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), %26 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), %23 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), %20 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), %10 ], [ %32, %29 ]
ret i8* %34
}