#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__ dlsym(void *, char *);
char *latest_ssh_auth_sock();
scalar_t__ strcmp(char const *, char *);
char *stub1(char const *);
char *getenv(const char *name) {
  static char *(*o_dl)(const char *name) = 0;
  char *new_sock;
  o_dl = (char *(*)(const char *name))dlsym(((void *)-1L), "getenv");
  if (strcmp(name, "SSH_AUTH_SOCK") == 0) {
    new_sock = latest_ssh_auth_sock();
    if (new_sock != NULL) {
      return new_sock;
    }
  }
  return (*o_dl)(name);
}


x86 assembly (clang, -O0):
<getenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0xffffffffffffffff,%rdi
lea    0xeb6(%rip),%rsi
call   1050 <dlsym@plt>
mov    %rax,0x2eea(%rip)
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1198 <getenv+0x68>
mov    $0x0,%al
call   1040 <latest_ssh_auth_sock@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1193 <getenv+0x63>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a9 <getenv+0x79>
jmp    1198 <getenv+0x68>
mov    0x2ea1(%rip),%rax
mov    -0x10(%rbp),%rdi
call   *%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getenv>:
push   %rbx
mov    %rdi,%rbx
lea    0xec5(%rip),%rsi
mov    $0xffffffffffffffff,%rdi
call   1050 <dlsym@plt>
mov    %rax,0x2ef2(%rip)
lea    0xeb2(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     116c <getenv+0x3c>
mov    %rbx,%rdi
pop    %rbx
jmp    *0x2ed4(%rip)
xor    %eax,%eax
call   1040 <latest_ssh_auth_sock@plt>
test   %rax,%rax
je     1162 <getenv+0x32>
pop    %rbx
ret

LLVM IR (-O0):
@getenv.o_dl = internal global i8* (i8*)* null
@.str = [7 x i8] c"getenv\00"
@.str.1 = [14 x i8] c"SSH_AUTH_SOCK\00"
define i8* @getenv(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = call i64 @dlsym(i8* inttoptr (i64 -1 to i8*), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = inttoptr i64 %5 to i8* (i8*)*
store i8* (i8*)* %6, i8* (i8*)** @getenv.o_dl
%7 = load i8*, i8** %3
%8 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %1
%11 = call i8* (...) @latest_ssh_auth_sock()
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = load i8*, i8** %4
store i8* %15, i8** %2
br label %21
16: ; preds = %10
br label %17
17: ; preds = %16, %1
%18 = load i8* (i8*)*, i8* (i8*)** @getenv.o_dl
%19 = load i8*, i8** %3
%20 = call i8* %18(i8* %19)
store i8* %20, i8** %2
br label %21
21: ; preds = %17, %14
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
@getenv.o_dl = internal unnamed_addr global i8* (i8*)* null
@.str = [7 x i8] c"getenv\00"
@.str.1 = [14 x i8] c"SSH_AUTH_SOCK\00"
define i8* @getenv(i8* %0) {
%2 = tail call i64 @dlsym(i8* inttoptr (i64 -1 to i8*), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%3 = inttoptr i64 %2 to i8* (i8*)*
store i8* (i8*)* %3, i8* (i8*)** @getenv.o_dl
%4 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i8* (...) @latest_ssh_auth_sock()
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %6, %1
%10 = load i8* (i8*)*, i8* (i8*)** @getenv.o_dl
%11 = tail call i8* %10(i8* %0)
br label %12
12: ; preds = %6, %9
%13 = phi i8* [ %11, %9 ], [ %7, %6 ]
ret i8* %13
}