#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 */
scalar_t__ getenv(char *);
char *rtl_getvar2(void *user, char *name) {
  char *val;
  if (!name || !*name)
    return "";
  val = (char *)getenv(name);
  if (!val)
    return "";
  return val;
}


x86 assembly (clang, -O0):
<rtl_getvar2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1138 <rtl_getvar2+0x28>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1148 <rtl_getvar2+0x38>
lea    0xec1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1178 <rtl_getvar2+0x68>
mov    -0x18(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1170 <rtl_getvar2+0x60>
lea    0xe99(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1178 <rtl_getvar2+0x68>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtl_getvar2>:
push   %rbx
lea    0xee8(%rip),%rbx
test   %rsi,%rsi
je     1132 <rtl_getvar2+0x22>
cmpb   $0x0,(%rsi)
je     1132 <rtl_getvar2+0x22>
mov    %rsi,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1132 <rtl_getvar2+0x22>
mov    %rax,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @rtl_getvar2(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %9, %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %23
14: ; preds = %9
%15 = load i8*, i8** %5
%16 = call i64 @getenv(i8* %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %21, label %20
20: ; preds = %14
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %23
21: ; preds = %14
%22 = load i8*, i8** %6
store i8* %22, i8** %3
br label %23
23: ; preds = %21, %20, %13
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @rtl_getvar2(i8* nocapture readnone %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = tail call i64 @getenv(i8* %1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = inttoptr i64 %8 to i8*
br label %12
12: ; preds = %7, %2, %4, %10
%13 = phi i8* [ %11, %10 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %4 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %7 ]
ret i8* %13
}