#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 *);
int /*<<< orphan*/ set_var(char const *, char const *);
void cmd_getenv(const char *assign_to, char *arg) {
  const char *s;
  s = *arg ? getenv(arg) : "";
  set_var(assign_to, s ? s : "");
}


x86 assembly (clang, -O0):
<cmd_getenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1152 <cmd_getenv+0x32>
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
jmp    1162 <cmd_getenv+0x42>
lea    0xea7(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1162 <cmd_getenv+0x42>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118a <cmd_getenv+0x6a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    119a <cmd_getenv+0x7a>
lea    0xe6f(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    119a <cmd_getenv+0x7a>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <set_var@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_getenv>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xed2(%rip),%rbx
cmpb   $0x0,(%rsi)
mov    %rbx,%rax
je     113e <cmd_getenv+0x1e>
mov    %rsi,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
cmovne %rax,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <set_var@plt>

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

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