#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 */
int connect_unix(char *);
int /*<<< orphan*/ dropbear_log(char *);
char *getenv(char *);
int connect_agent() {
  int fd = -1;
  char *agent_sock = NULL;
  agent_sock = getenv("SSH_AUTH_SOCK");
  if (agent_sock == NULL)
    return -1;
  fd = connect_unix(agent_sock);
  if (fd < 0) {
    dropbear_log("Failed to connect to agent");
  }
  return fd;
}


x86 assembly (clang, -O0):
<connect_agent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xffffffff,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xeb2(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116e <connect_agent+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <connect_agent+0x66>
mov    -0x10(%rbp),%rdi
call   1050 <connect_unix@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1190 <connect_agent+0x60>
lea    0xe83(%rip),%rdi
call   1040 <dropbear_log@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connect_agent>:
push   %rbx
lea    0xec8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     115e <connect_agent+0x2e>
mov    %rax,%rdi
call   1050 <connect_unix@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1163 <connect_agent+0x33>
lea    0xeb7(%rip),%rdi
call   1040 <dropbear_log@plt>
jmp    1163 <connect_agent+0x33>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"SSH_AUTH_SOCK\00"
@.str.1 = [27 x i8] c"Failed to connect to agent\00"
define i32 @connect_agent() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 -1, i32* %2
store i8* null, i8** %3
%4 = call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %0
store i32 -1, i32* %1
br label %17
8: ; preds = %0
%9 = load i8*, i8** %3
%10 = call i32 @connect_unix(i8* %9)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @dropbear_log(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
%16 = load i32, i32* %2
store i32 %16, i32* %1
br label %17
17: ; preds = %15, %7
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@.str = [14 x i8] c"SSH_AUTH_SOCK\00"
@.str.1 = [27 x i8] c"Failed to connect to agent\00"
define i32 @connect_agent() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %8, label %3
3: ; preds = %0
%4 = tail call i32 @connect_unix(i8* %1)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @dropbear_log(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %3, %6, %0
%9 = phi i32 [ -1, %0 ], [ %4, %6 ], [ %4, %3 ]
ret i32 %9
}