#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 */
struct sockaddr {
  int dummy;
};
struct evconnlistener {
  int dummy;
};

/* Variables and functions */
int evconnlistener_get_fd(struct evconnlistener *);
int getsockname(int, struct sockaddr *, unsigned int *);
int regress_get_listener_addr(struct evconnlistener *lev, struct sockaddr *sa,
                              unsigned int *socklen) {
  int s = evconnlistener_get_fd(lev);
  if (s <= 0)
    return -1;
  return getsockname(s, sa, socklen);
}


x86 assembly (clang, -O0):
<regress_get_listener_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <evconnlistener_get_fd@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jg     1156 <regress_get_listener_addr+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    1169 <regress_get_listener_addr+0x49>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <getsockname@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regress_get_listener_addr>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
call   1030 <evconnlistener_get_fd@plt>
test   %eax,%eax
jle    1147 <regress_get_listener_addr+0x27>
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <getsockname@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.evconnlistener = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @regress_get_listener_addr(%struct.evconnlistener* %0, %struct.sockaddr* %1, i32* %2) {
%4 = alloca i32
%5 = alloca %struct.evconnlistener*
%6 = alloca %struct.sockaddr*
%7 = alloca i32*
%8 = alloca i32
store %struct.evconnlistener* %0, %struct.evconnlistener** %5
store %struct.sockaddr* %1, %struct.sockaddr** %6
store i32* %2, i32** %7
%9 = load %struct.evconnlistener*, %struct.evconnlistener** %5
%10 = call i32 @evconnlistener_get_fd(%struct.evconnlistener* %9)
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp sle i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %19
14: ; preds = %3
%15 = load i32, i32* %8
%16 = load %struct.sockaddr*, %struct.sockaddr** %6
%17 = load i32*, i32** %7
%18 = call i32 @getsockname(i32 %15, %struct.sockaddr* %16, i32* %17)
store i32 %18, i32* %4
br label %19
19: ; preds = %14, %13
%20 = load i32, i32* %4
ret i32 %20
}

LLVM IR (-O2):
%struct.evconnlistener = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @regress_get_listener_addr(%struct.evconnlistener* %0, %struct.sockaddr* %1, i32* %2) {
%4 = tail call i32 @evconnlistener_get_fd(%struct.evconnlistener* %0)
%5 = icmp slt i32 %4, 1
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @getsockname(i32 %4, %struct.sockaddr* %1, i32* %2)
br label %8
8: ; preds = %3, %6
%9 = phi i32 [ %7, %6 ], [ -1, %3 ]
ret i32 %9
}