#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 */
char *getenv(char const *);
const char *_nl_locale_name(int category, const char *categoryname) {
  const char *retval;
  retval = getenv("LC_ALL");
  if (retval == NULL || retval[0] == '\0') {
    retval = getenv(categoryname);
    if (retval == NULL || retval[0] == '\0') {
      retval = getenv("LANG");
      if (retval == NULL || retval[0] == '\0')
        retval = "C";
    }
  }
  return retval;
}


x86 assembly (clang, -O0):
<_nl_locale_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeda(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     114a <_nl_locale_name+0x3a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11b2 <_nl_locale_name+0xa2>
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1172 <_nl_locale_name+0x62>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11ad <_nl_locale_name+0x9d>
lea    0xe8e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119d <_nl_locale_name+0x8d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a8 <_nl_locale_name+0x98>
lea    0xe68(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11ad <_nl_locale_name+0x9d>
jmp    11b2 <_nl_locale_name+0xa2>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_nl_locale_name>:
push   %rbx
mov    %rsi,%rbx
lea    0xee5(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     112c <_nl_locale_name+0x1c>
cmpb   $0x0,(%rax)
je     112c <_nl_locale_name+0x1c>
pop    %rbx
ret
mov    %rbx,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     113e <_nl_locale_name+0x2e>
cmpb   $0x0,(%rax)
jne    112a <_nl_locale_name+0x1a>
lea    0xec2(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1154 <_nl_locale_name+0x44>
cmpb   $0x0,(%rax)
jne    112a <_nl_locale_name+0x1a>
lea    0xeb1(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"LC_ALL\00"
@.str.1 = [5 x i8] c"LANG\00"
@.str.2 = [2 x i8] c"C\00"
define i8* @_nl_locale_name(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %5
%7 = load i8*, i8** %5
%8 = icmp eq i8* %7, null
br i1 %8, label %15, label %9
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %39
15: ; preds = %9, %2
%16 = load i8*, i8** %4
%17 = call i8* @getenv(i8* %16)
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = icmp eq i8* %18, null
br i1 %19, label %26, label %20
20: ; preds = %15
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %38
26: ; preds = %20, %15
%27 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %27, i8** %5
%28 = load i8*, i8** %5
%29 = icmp eq i8* %28, null
br i1 %29, label %36, label %30
30: ; preds = %26
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %30, %26
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %5
br label %37
37: ; preds = %36, %30
br label %38
38: ; preds = %37, %20
br label %39
39: ; preds = %38, %9
%40 = load i8*, i8** %5
ret i8* %40
}

LLVM IR (-O2):
@.str = [7 x i8] c"LC_ALL\00"
@.str.1 = [5 x i8] c"LANG\00"
@.str.2 = [2 x i8] c"C\00"
define i8* @_nl_locale_name(i32 %0, i8* nocapture %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i8, i8* %3
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %21
8: ; preds = %5, %2
%9 = tail call i8* @getenv(i8* %1)
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i8, i8* %9
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %11, %8
%15 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i8, i8* %15
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17, %14
br label %21
21: ; preds = %11, %20, %17, %5
%22 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), %20 ], [ %15, %17 ], [ %9, %11 ], [ %3, %5 ]
ret i8* %22
}