int matchenv(name)
char *name;
{
  const struct stdenv *ep;
  char *value;
  if (!(ep = getstdenv(name)))
    return (-1);
  if (!(value = getenv(name)))
    value = "";
  return _matchval(ep, value);
}


x86 assembly (clang, -O0):
<matchenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1040 <getstdenv@plt>
cltq
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1163 <matchenv+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    119b <matchenv+0x6b>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1030 <getenv@plt>
cltq
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1189 <matchenv+0x59>
lea    0xe7b(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1050 <_matchval@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matchenv>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <getstdenv@plt>
test   %eax,%eax
je     116f <matchenv+0x3f>
movslq %eax,%r14
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <getenv@plt>
cltq
test   %eax,%eax
lea    0xea6(%rip),%rsi
cmovne %rax,%rsi
mov    %r14,%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <_matchval@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.stdenv = type opaque
@.str = [1 x i8] zeroinitializer
define i32 @matchenv(i8* %0) {
%2 = tail call i32 (i8*, ...) bitcast (i32 (...)* @getstdenv to i32 (i8*, ...)*)(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = sext i32 %2 to i64
%6 = inttoptr i64 %5 to %struct.stdenv*
%7 = tail call i32 (i8*, ...) bitcast (i32 (...)* @getenv to i32 (i8*, ...)*)(i8* %0)
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i8*
%10 = icmp eq i32 %7, 0
%11 = select i1 %10, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %9
%12 = tail call i32 (%struct.stdenv*, i8*, ...) bitcast (i32 (...)* @_matchval to i32 (%struct.stdenv*, i8*, ...)*)(%struct.stdenv* %6, i8* %11)
br label %13
13: ; preds = %1, %4
%14 = phi i32 [ %12, %4 ], [ -1, %1 ]
ret i32 %14
}