#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 *get_env_with_fallback(const char *name1, const char *name2,
                                  const char *fallback) {
  const char *val;
  val = getenv(name1);
  if (!val || *val == 0) {
    val = getenv(name2);
  }
  if (!val || *val == 0) {
    val = fallback;
  }
  return val;
}


x86 assembly (clang, -O0):
<get_env_with_fallback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     114c <get_env_with_fallback+0x3c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1159 <get_env_with_fallback+0x49>
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1174 <get_env_with_fallback+0x64>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    117c <get_env_with_fallback+0x6c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_env_with_fallback>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
call   1030 <getenv@plt>
test   %rax,%rax
je     1129 <get_env_with_fallback+0x19>
cmpb   $0x0,(%rax)
jne    113e <get_env_with_fallback+0x2e>
mov    %rbx,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     113b <get_env_with_fallback+0x2b>
cmpb   $0x0,(%rax)
jne    113e <get_env_with_fallback+0x2e>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @get_env_with_fallback(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %4
%9 = call i8* @getenv(i8* %8)
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = load i8*, i8** %7
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12, %3
%18 = load i8*, i8** %5
%19 = call i8* @getenv(i8* %18)
store i8* %19, i8** %7
br label %20
20: ; preds = %17, %12
%21 = load i8*, i8** %7
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i8*, i8** %7
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %23, %20
%29 = load i8*, i8** %6
store i8* %29, i8** %7
br label %30
30: ; preds = %28, %23
%31 = load i8*, i8** %7
ret i8* %31
}

LLVM IR (-O2):
define i8* @get_env_with_fallback(i8* nocapture %0, i8* nocapture %1, i8* readnone %2) {
%4 = tail call i8* @getenv(i8* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = load i8, i8* %4
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %3, %6
%10 = tail call i8* @getenv(i8* %1)
%11 = icmp eq i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load i8, i8* %10
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12, %9
br label %16
16: ; preds = %6, %15, %12
%17 = phi i8* [ %2, %15 ], [ %10, %12 ], [ %4, %6 ]
ret i8* %17
}