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


x86 assembly (clang, -O0):
<_nl_locale_name_posix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xeda(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1157 <_nl_locale_name_posix+0x47>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1157 <_nl_locale_name_posix+0x47>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11cc <_nl_locale_name_posix+0xbc>
mov    -0x18(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     118c <_nl_locale_name_posix+0x7c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     118c <_nl_locale_name_posix+0x7c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11cc <_nl_locale_name_posix+0xbc>
lea    0xe74(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c4 <_nl_locale_name_posix+0xb4>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c4 <_nl_locale_name_posix+0xb4>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11cc <_nl_locale_name_posix+0xbc>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

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

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

LLVM IR (-O2):
@.str = [7 x i8] c"LC_ALL\00"
@.str.1 = [5 x i8] c"LANG\00"
define i8* @_nl_locale_name_posix(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 = %17, %11, %5, %20
%22 = phi i8* [ null, %20 ], [ %3, %5 ], [ %9, %11 ], [ %15, %17 ]
ret i8* %22
}