#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 *);
char *getenv_locale() {
  char *s = getenv("LANGUAGE");
  if (s && s[0])
    return s;
  s = getenv("LC_ALL");
  if (s && s[0])
    return s;
  s = getenv("LC_MESSAGES");
  if (s && s[0])
    return s;
  s = getenv("LANG");
  if (s && s[0])
    return s;
  return NULL;
}


x86 assembly (clang, -O0):
<getenv_locale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xee1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1150 <getenv_locale+0x40>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1150 <getenv_locale+0x40>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1200 <getenv_locale+0xf0>
lea    0xeb2(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1188 <getenv_locale+0x78>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1188 <getenv_locale+0x78>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1200 <getenv_locale+0xf0>
lea    0xe81(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c0 <getenv_locale+0xb0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c0 <getenv_locale+0xb0>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1200 <getenv_locale+0xf0>
lea    0xe55(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f8 <getenv_locale+0xe8>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f8 <getenv_locale+0xe8>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1200 <getenv_locale+0xf0>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getenv_locale>:
push   %rax
lea    0xee8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1129 <getenv_locale+0x19>
cmpb   $0x0,(%rax)
je     1129 <getenv_locale+0x19>
pop    %rcx
ret
lea    0xed9(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     113f <getenv_locale+0x2f>
cmpb   $0x0,(%rax)
jne    1127 <getenv_locale+0x17>
lea    0xeca(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1155 <getenv_locale+0x45>
cmpb   $0x0,(%rax)
jne    1127 <getenv_locale+0x17>
lea    0xec0(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     116b <getenv_locale+0x5b>
cmpb   $0x0,(%rax)
jne    1127 <getenv_locale+0x17>
xor    %eax,%eax
pop    %rcx
ret

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

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