#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 *);
char const *split_locale(char const *);
const char *get_lang_env(const char *category_name) {
  const char *lang;
  lang = getenv("LANGUAGE");
  if (lang)
    return lang;
  lang = getenv("LC_ALL");
  if (!lang)
    lang = getenv(category_name);
  if (!lang)
    lang = getenv("LANG");
  if (!lang)
    return 0;
  return split_locale(lang);
}


x86 assembly (clang, -O0):
<get_lang_env>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xecd(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1154 <get_lang_env+0x34>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11bc <get_lang_env+0x9c>
lea    0xeae(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117c <get_lang_env+0x5c>
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1197 <get_lang_env+0x77>
lea    0xe82(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11af <get_lang_env+0x8f>
movq   $0x0,-0x8(%rbp)
jmp    11bc <get_lang_env+0x9c>
mov    -0x18(%rbp),%rdi
call   1040 <split_locale@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_lang_env>:
push   %rbx
mov    %rdi,%rbx
lea    0xed5(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1137 <get_lang_env+0x17>
pop    %rbx
ret
lea    0xecb(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    1166 <get_lang_env+0x46>
mov    %rbx,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    1166 <get_lang_env+0x46>
lea    0xeb4(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     116f <get_lang_env+0x4f>
mov    %rax,%rdi
pop    %rbx
jmp    1040 <split_locale@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"LANGUAGE\00"
@.str.1 = [7 x i8] c"LC_ALL\00"
@.str.2 = [5 x i8] c"LANG\00"
define i8* @get_lang_env(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load i8*, i8** %4
store i8* %9, i8** %2
br label %29
10: ; preds = %1
%11 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = call i8* @getenv(i8* %15)
store i8* %16, i8** %4
br label %17
17: ; preds = %14, %10
%18 = load i8*, i8** %4
%19 = icmp ne i8* %18, null
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8* %21, i8** %4
br label %22
22: ; preds = %20, %17
%23 = load i8*, i8** %4
%24 = icmp ne i8* %23, null
br i1 %24, label %26, label %25
25: ; preds = %22
store i8* null, i8** %2
br label %29
26: ; preds = %22
%27 = load i8*, i8** %4
%28 = call i8* @split_locale(i8* %27)
store i8* %28, i8** %2
br label %29
29: ; preds = %26, %25, %8
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
@.str = [9 x i8] c"LANGUAGE\00"
@.str.1 = [7 x i8] c"LC_ALL\00"
@.str.2 = [5 x i8] c"LANG\00"
define i8* @get_lang_env(i8* nocapture %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %16
4: ; preds = %1
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %13
7: ; preds = %4
%8 = tail call i8* @getenv(i8* %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 %16, label %13
13: ; preds = %4, %7, %10
%14 = phi i8* [ %11, %10 ], [ %8, %7 ], [ %5, %4 ]
%15 = tail call i8* @split_locale(i8* %14)
br label %16
16: ; preds = %10, %1, %13
%17 = phi i8* [ %15, %13 ], [ %2, %1 ], [ null, %10 ]
ret i8* %17
}