#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 */
typedef int /*<<< orphan*/ val;
struct linger {
  int l_onoff;
  int l_linger;
};
struct addrinfo {
  int ai_flags;
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
};
typedef int /*<<< orphan*/ linger;
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_LINGER;
int /*<<< orphan*/ SO_REUSEADDR;
scalar_t__ bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
scalar_t__ listen(int, int);
scalar_t__ m_malloc(int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ set_sock_priority(int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              void *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char *strerror(int);
int strlen(char *);
int dropbear_listen(const char *address, const char *port, int *socks,
                    unsigned int sockcount, char **errstring, int *maxfd) {
  struct addrinfo hints, *res = NULL, *res0 = NULL;
  int err;
  unsigned int nsock;
  struct linger linger;
  int val;
  int sock;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  if (!address) {
    ;
  } else {
    if (address[0] == '\0')
      address = NULL;
    hints.ai_flags = (1);
  }
  err = getaddrinfo(address, port, &hints, &res0);
  if (err) {
    if (errstring != NULL && *errstring == NULL) {
      int len;
      len = 20 + strlen(gai_strerror(err));
      *errstring = (char *)m_malloc(len);
      snprintf(*errstring, len, "Error resolving: %s", gai_strerror(err));
    }
    if (res0) {
      freeaddrinfo(res0);
      res0 = NULL;
    }
    return -1;
  }
  nsock = 0;
  for (res = res0; res != NULL && nsock < sockcount; res = res->ai_next) {
    socks[nsock] = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    sock = socks[nsock];
    if (sock < 0) {
      err = errno;
      continue;
    }
    val = 1;
    setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&val, sizeof(val));
    linger.l_onoff = 1;
    linger.l_linger = 5;
    setsockopt(sock, SOL_SOCKET, SO_LINGER, (void *)&linger, sizeof(linger));
    set_sock_priority(sock);
    if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) {
      err = errno;
      close(sock);
      continue;
    }
    if (listen(sock, 20) < 0) {
      err = errno;
      close(sock);
      continue;
    }
    *maxfd = (((*maxfd) > (sock)) ? (*maxfd) : (sock));
    nsock++;
  }
  if (res0) {
    freeaddrinfo(res0);
    res0 = NULL;
  }
  if (nsock == 0) {
    if (errstring != NULL && *errstring == NULL) {
      int len;
      len = 20 + strlen(strerror(err));
      *errstring = (char *)m_malloc(len);
      snprintf(*errstring, len, "Error listening: %s", strerror(err));
    }
    return -1;
  }
  return nsock;
}


x86 assembly (clang, -O0):
<dropbear_listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
movq   $0x0,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1080 <memset@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    124a <dropbear_listen+0x6a>
jmp    1269 <dropbear_listen+0x89>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1262 <dropbear_listen+0x82>
movq   $0x0,-0x10(%rbp)
movl   $0x1,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x58(%rbp),%rdx
lea    -0x68(%rbp),%rcx
call   10d0 <getaddrinfo@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
je     1338 <dropbear_listen+0x158>
cmpq   $0x0,-0x30(%rbp)
je     1310 <dropbear_listen+0x130>
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1310 <dropbear_listen+0x130>
mov    -0x6c(%rbp),%edi
call   1070 <gai_strerror@plt>
mov    %rax,%rdi
call   1050 <strlen@plt>
add    $0x14,%eax
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%edi
call   10a0 <m_malloc@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x98(%rbp)
mov    -0x84(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x6c(%rbp),%edi
call   1070 <gai_strerror@plt>
mov    -0x98(%rbp),%rdi
mov    -0x8c(%rbp),%esi
mov    %rax,%rcx
lea    0xcf5(%rip),%rdx
call   1060 <snprintf@plt>
cmpq   $0x0,-0x68(%rbp)
je     132c <dropbear_listen+0x14c>
mov    -0x68(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
movq   $0x0,-0x68(%rbp)
movl   $0xffffffff,-0x4(%rbp)
jmp    15a4 <dropbear_listen+0x3c4>
movl   $0x0,-0x70(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0x60(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x60(%rbp)
mov    %al,-0x99(%rbp)
je     1369 <dropbear_listen+0x189>
mov    -0x70(%rbp),%eax
cmp    -0x24(%rbp),%eax
setb   %al
mov    %al,-0x99(%rbp)
mov    -0x99(%rbp),%al
test   $0x1,%al
jne    137c <dropbear_listen+0x19c>
jmp    14e7 <dropbear_listen+0x307>
mov    -0x60(%rbp),%rax
mov    0x14(%rax),%edi
mov    -0x60(%rbp),%rax
mov    0x10(%rax),%esi
mov    -0x60(%rbp),%rax
mov    0xc(%rax),%edx
call   1100 <socket@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
mov    -0x70(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    -0x70(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x80(%rbp)
cmpl   $0x0,-0x80(%rbp)
jge    13ca <dropbear_listen+0x1ea>
mov    0x2c00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
jmp    14d6 <dropbear_listen+0x2f6>
movl   $0x1,-0x7c(%rbp)
mov    -0x80(%rbp),%edi
mov    0x2c0d(%rip),%rax
mov    (%rax),%esi
mov    0x2bd4(%rip),%rax
mov    (%rax),%edx
lea    -0x7c(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
movl   $0x1,-0x78(%rbp)
movl   $0x5,-0x74(%rbp)
mov    -0x80(%rbp),%edi
mov    0x2bdb(%rip),%rax
mov    (%rax),%esi
mov    0x2bca(%rip),%rax
mov    (%rax),%edx
lea    -0x78(%rbp),%rcx
mov    $0x8,%r8d
call   1040 <setsockopt@plt>
mov    -0x80(%rbp),%edi
call   1030 <set_sock_priority@plt>
mov    -0x80(%rbp),%edi
mov    -0x60(%rbp),%rax
mov    0x8(%rax),%esi
mov    -0x60(%rbp),%rax
mov    0x4(%rax),%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    1468 <dropbear_listen+0x288>
mov    0x2b6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x80(%rbp),%edi
call   1090 <close@plt>
jmp    14d6 <dropbear_listen+0x2f6>
mov    -0x80(%rbp),%edi
mov    $0x14,%esi
call   10b0 <listen@plt>
cmp    $0x0,%rax
jge    1498 <dropbear_listen+0x2b8>
mov    0x2b3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x80(%rbp),%edi
call   1090 <close@plt>
jmp    14d6 <dropbear_listen+0x2f6>
mov    -0x38(%rbp),%rax
mov    (%rax),%eax
cmp    -0x80(%rbp),%eax
jle    14b8 <dropbear_listen+0x2d8>
mov    -0x38(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xa0(%rbp)
jmp    14c1 <dropbear_listen+0x2e1>
mov    -0x80(%rbp),%eax
mov    %eax,-0xa0(%rbp)
mov    -0xa0(%rbp),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
mov    -0x60(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x60(%rbp)
jmp    1347 <dropbear_listen+0x167>
cmpq   $0x0,-0x68(%rbp)
je     1503 <dropbear_listen+0x323>
mov    -0x68(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
movq   $0x0,-0x68(%rbp)
cmpl   $0x0,-0x70(%rbp)
jne    159e <dropbear_listen+0x3be>
cmpq   $0x0,-0x30(%rbp)
je     1592 <dropbear_listen+0x3b2>
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1592 <dropbear_listen+0x3b2>
mov    -0x6c(%rbp),%edi
call   10e0 <strerror@plt>
mov    %rax,%rdi
call   1050 <strlen@plt>
add    $0x14,%eax
mov    %eax,-0x88(%rbp)
mov    -0x88(%rbp),%edi
call   10a0 <m_malloc@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x88(%rbp),%eax
mov    %eax,-0xa4(%rbp)
mov    -0x6c(%rbp),%edi
call   10e0 <strerror@plt>
mov    -0xb0(%rbp),%rdi
mov    -0xa4(%rbp),%esi
mov    %rax,%rcx
lea    0xa87(%rip),%rdx
call   1060 <snprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15a4 <dropbear_listen+0x3c4>
mov    -0x70(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dropbear_listen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r9,0x28(%rsp)
mov    %r8,0x18(%rsp)
mov    %ecx,%r13d
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,0x10(%rsp)
lea    0x38(%rsp),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0x20,%edx
call   1080 <memset@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4c(%rsp)
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x48(%rsp)
test   %rbx,%rbx
je     1250 <dropbear_listen+0x70>
xor    %ebp,%ebp
cmpb   $0x0,(%rbx)
cmovne %rbx,%rbp
movl   $0x1,0x38(%rsp)
lea    0x38(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %rbp,%rdi
mov    %r14,%rsi
call   10d0 <getaddrinfo@plt>
test   %eax,%eax
je     12d5 <dropbear_listen+0xf5>
mov    0x18(%rsp),%rbx
test   %rbx,%rbx
je     12b8 <dropbear_listen+0xd8>
cmpq   $0x0,(%rbx)
jne    12b8 <dropbear_listen+0xd8>
mov    %eax,%ebp
mov    %eax,%edi
call   1070 <gai_strerror@plt>
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x14(%rax),%r14d
mov    %r14d,%edi
call   10a0 <m_malloc@plt>
mov    %rax,%r15
mov    %rax,(%rbx)
mov    %ebp,%edi
call   1070 <gai_strerror@plt>
lea    0xd56(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rax,%rcx
call   1060 <snprintf@plt>
mov    0x10(%rsp),%rdi
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     143f <dropbear_listen+0x25f>
call   10f0 <freeaddrinfo@plt>
jmp    143f <dropbear_listen+0x25f>
mov    0x10(%rsp),%r14
test   %r14,%r14
je     1416 <dropbear_listen+0x236>
test   %r13d,%r13d
je     1416 <dropbear_listen+0x236>
xor    %ebp,%ebp
movl   $0x0,0xc(%rsp)
cs nopw 0x0(%rax,%rax,1)
mov    0x14(%r14),%edi
mov    0xc(%r14),%edx
mov    0x10(%r14),%esi
call   1100 <socket@plt>
mov    %eax,%r15d
mov    %ebp,%eax
mov    %r15d,(%r12,%rax,4)
test   %r15d,%r15d
js     13f0 <dropbear_listen+0x210>
movl   $0x1,0x24(%rsp)
mov    0x2cb6(%rip),%rbx
mov    (%rbx),%esi
mov    0x2c7d(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
lea    0x24(%rsp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
movabs $0x500000001,%rax
mov    %rax,0x30(%rsp)
mov    (%rbx),%esi
mov    0x2c78(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
lea    0x30(%rsp),%rcx
mov    $0x8,%r8d
call   1040 <setsockopt@plt>
mov    %r15d,%edi
call   1030 <set_sock_priority@plt>
mov    0x4(%r14),%edx
mov    0x8(%r14),%esi
mov    %r15d,%edi
call   10c0 <bind@plt>
test   %rax,%rax
js     13d0 <dropbear_listen+0x1f0>
mov    %r15d,%edi
mov    $0x14,%esi
call   10b0 <listen@plt>
test   %rax,%rax
js     13d0 <dropbear_listen+0x1f0>
mov    0x28(%rsp),%rcx
mov    (%rcx),%eax
cmp    %r15d,%eax
cmovg  %eax,%r15d
mov    %r15d,(%rcx)
add    $0x1,%ebp
jmp    13fd <dropbear_listen+0x21d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2be9(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %r15d,%edi
call   1090 <close@plt>
jmp    13fd <dropbear_listen+0x21d>
nopw   0x0(%rax,%rax,1)
mov    0x2bc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x18(%r14),%r14
test   %r14,%r14
je     140f <dropbear_listen+0x22f>
cmp    %r13d,%ebp
jb     1300 <dropbear_listen+0x120>
mov    0x10(%rsp),%r14
jmp    1420 <dropbear_listen+0x240>
movl   $0x0,0xc(%rsp)
xor    %ebp,%ebp
mov    0x18(%rsp),%r12
test   %r14,%r14
je     143b <dropbear_listen+0x25b>
mov    %r14,%rdi
call   10f0 <freeaddrinfo@plt>
movq   $0x0,0x10(%rsp)
test   %ebp,%ebp
je     1450 <dropbear_listen+0x270>
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%ebp
test   %r12,%r12
je     143f <dropbear_listen+0x25f>
cmpq   $0x0,(%r12)
jne    143f <dropbear_listen+0x25f>
mov    0xc(%rsp),%ebx
mov    %ebx,%edi
call   10e0 <strerror@plt>
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x14(%rax),%r14d
mov    %r14d,%edi
call   10a0 <m_malloc@plt>
mov    %rax,%r15
mov    %rax,(%r12)
mov    %ebx,%edi
call   10e0 <strerror@plt>
lea    0xb7f(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rax,%rcx
call   1060 <snprintf@plt>
jmp    143f <dropbear_listen+0x25f>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32, %struct.addrinfo* }
%struct.linger = type { i32, i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str = [20 x i8] c"Error resolving: %s\00"
@errno = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@SO_LINGER = global i32 0
@.str.1 = [20 x i8] c"Error listening: %s\00"
define i32 @dropbear_listen(i8* %0, i8* %1, i32* %2, i32 %3, i8** %4, i32* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i8**
%13 = alloca i32*
%14 = alloca %struct.addrinfo
%15 = alloca %struct.addrinfo*
%16 = alloca %struct.addrinfo*
%17 = alloca i32
%18 = alloca i32
%19 = alloca %struct.linger
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
store i8* %0, i8** %8
store i8* %1, i8** %9
store i32* %2, i32** %10
store i32 %3, i32* %11
store i8** %4, i8*** %12
store i32* %5, i32** %13
store %struct.addrinfo* null, %struct.addrinfo** %15
store %struct.addrinfo* null, %struct.addrinfo** %16
%24 = call i32 @memset(%struct.addrinfo* %14, i32 0, i32 32)
%25 = load i32, i32* @AF_UNSPEC
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %14, i32 0, i32 5
store i32 %25, i32* %26
%27 = load i32, i32* @SOCK_STREAM
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %14, i32 0, i32 4
store i32 %27, i32* %28
%29 = load i8*, i8** %8
%30 = icmp ne i8* %29, null
br i1 %30, label %32, label %31
31: ; preds = %6
br label %41
32: ; preds = %6
%33 = load i8*, i8** %8
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %32
store i8* null, i8** %8
br label %39
39: ; preds = %38, %32
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %14, i32 0, i32 0
store i32 1, i32* %40
br label %41
41: ; preds = %39, %31
%42 = load i8*, i8** %8
%43 = load i8*, i8** %9
%44 = call i32 @getaddrinfo(i8* %42, i8* %43, %struct.addrinfo* %14, %struct.addrinfo** %16)
store i32 %44, i32* %17
%45 = load i32, i32* %17
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %76
47: ; preds = %41
%48 = load i8**, i8*** %12
%49 = icmp ne i8** %48, null
br i1 %49, label %50, label %69
50: ; preds = %47
%51 = load i8**, i8*** %12
%52 = load i8*, i8** %51
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %69
54: ; preds = %50
%55 = load i32, i32* %17
%56 = call i8* @gai_strerror(i32 %55)
%57 = call i32 @strlen(i8* %56)
%58 = add nsw i32 20, %57
store i32 %58, i32* %22
%59 = load i32, i32* %22
%60 = call i64 @m_malloc(i32 %59)
%61 = inttoptr i64 %60 to i8*
%62 = load i8**, i8*** %12
store i8* %61, i8** %62
%63 = load i8**, i8*** %12
%64 = load i8*, i8** %63
%65 = load i32, i32* %22
%66 = load i32, i32* %17
%67 = call i8* @gai_strerror(i32 %66)
%68 = call i32 @snprintf(i8* %64, i32 %65, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %67)
br label %69
69: ; preds = %54, %50, %47
%70 = load %struct.addrinfo*, %struct.addrinfo** %16
%71 = icmp ne %struct.addrinfo* %70, null
br i1 %71, label %72, label %75
72: ; preds = %69
%73 = load %struct.addrinfo*, %struct.addrinfo** %16
%74 = call i32 @freeaddrinfo(%struct.addrinfo* %73)
store %struct.addrinfo* null, %struct.addrinfo** %16
br label %75
75: ; preds = %72, %69
store i32 -1, i32* %7
br label %200
76: ; preds = %41
store i32 0, i32* %18
%77 = load %struct.addrinfo*, %struct.addrinfo** %16
store %struct.addrinfo* %77, %struct.addrinfo** %15
br label %78
78: ; preds = %162, %76
%79 = load %struct.addrinfo*, %struct.addrinfo** %15
%80 = icmp ne %struct.addrinfo* %79, null
br i1 %80, label %81, label %85
81: ; preds = %78
%82 = load i32, i32* %18
%83 = load i32, i32* %11
%84 = icmp ult i32 %82, %83
br label %85
85: ; preds = %81, %78
%86 = phi i1 [ false, %78 ], [ %84, %81 ]
br i1 %86, label %87, label %166
87: ; preds = %85
%88 = load %struct.addrinfo*, %struct.addrinfo** %15
%89 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %88, i32 0, i32 5
%90 = load i32, i32* %89
%91 = load %struct.addrinfo*, %struct.addrinfo** %15
%92 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %91, i32 0, i32 4
%93 = load i32, i32* %92
%94 = load %struct.addrinfo*, %struct.addrinfo** %15
%95 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %94, i32 0, i32 3
%96 = load i32, i32* %95
%97 = call i32 @socket(i32 %90, i32 %93, i32 %96)
%98 = load i32*, i32** %10
%99 = load i32, i32* %18
%100 = zext i32 %99 to i64
%101 = getelementptr inbounds i32, i32* %98, i64 %100
store i32 %97, i32* %101
%102 = load i32*, i32** %10
%103 = load i32, i32* %18
%104 = zext i32 %103 to i64
%105 = getelementptr inbounds i32, i32* %102, i64 %104
%106 = load i32, i32* %105
store i32 %106, i32* %21
%107 = load i32, i32* %21
%108 = icmp slt i32 %107, 0
br i1 %108, label %109, label %111
109: ; preds = %87
%110 = load i32, i32* @errno
store i32 %110, i32* %17
br label %162
111: ; preds = %87
store i32 1, i32* %20
%112 = load i32, i32* %21
%113 = load i32, i32* @SOL_SOCKET
%114 = load i32, i32* @SO_REUSEADDR
%115 = bitcast i32* %20 to i8*
%116 = call i32 @setsockopt(i32 %112, i32 %113, i32 %114, i8* %115, i32 4)
%117 = getelementptr inbounds %struct.linger, %struct.linger* %19, i32 0, i32 0
store i32 1, i32* %117
%118 = getelementptr inbounds %struct.linger, %struct.linger* %19, i32 0, i32 1
store i32 5, i32* %118
%119 = load i32, i32* %21
%120 = load i32, i32* @SOL_SOCKET
%121 = load i32, i32* @SO_LINGER
%122 = bitcast %struct.linger* %19 to i8*
%123 = call i32 @setsockopt(i32 %119, i32 %120, i32 %121, i8* %122, i32 8)
%124 = load i32, i32* %21
%125 = call i32 @set_sock_priority(i32 %124)
%126 = load i32, i32* %21
%127 = load %struct.addrinfo*, %struct.addrinfo** %15
%128 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %127, i32 0, i32 2
%129 = load i32, i32* %128
%130 = load %struct.addrinfo*, %struct.addrinfo** %15
%131 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %130, i32 0, i32 1
%132 = load i32, i32* %131
%133 = call i64 @bind(i32 %126, i32 %129, i32 %132)
%134 = icmp slt i64 %133, 0
br i1 %134, label %135, label %139
135: ; preds = %111
%136 = load i32, i32* @errno
store i32 %136, i32* %17
%137 = load i32, i32* %21
%138 = call i32 @close(i32 %137)
br label %162
139: ; preds = %111
%140 = load i32, i32* %21
%141 = call i64 @listen(i32 %140, i32 20)
%142 = icmp slt i64 %141, 0
br i1 %142, label %143, label %147
143: ; preds = %139
%144 = load i32, i32* @errno
store i32 %144, i32* %17
%145 = load i32, i32* %21
%146 = call i32 @close(i32 %145)
br label %162
147: ; preds = %139
%148 = load i32*, i32** %13
%149 = load i32, i32* %148
%150 = load i32, i32* %21
%151 = icmp sgt i32 %149, %150
br i1 %151, label %152, label %155
152: ; preds = %147
%153 = load i32*, i32** %13
%154 = load i32, i32* %153
br label %157
155: ; preds = %147
%156 = load i32, i32* %21
br label %157
157: ; preds = %155, %152
%158 = phi i32 [ %154, %152 ], [ %156, %155 ]
%159 = load i32*, i32** %13
store i32 %158, i32* %159
%160 = load i32, i32* %18
%161 = add i32 %160, 1
store i32 %161, i32* %18
br label %162
162: ; preds = %157, %143, %135, %109
%163 = load %struct.addrinfo*, %struct.addrinfo** %15
%164 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %163, i32 0, i32 6
%165 = load %struct.addrinfo*, %struct.addrinfo** %164
store %struct.addrinfo* %165, %struct.addrinfo** %15
br label %78
166: ; preds = %85
%167 = load %struct.addrinfo*, %struct.addrinfo** %16
%168 = icmp ne %struct.addrinfo* %167, null
br i1 %168, label %169, label %172
169: ; preds = %166
%170 = load %struct.addrinfo*, %struct.addrinfo** %16
%171 = call i32 @freeaddrinfo(%struct.addrinfo* %170)
store %struct.addrinfo* null, %struct.addrinfo** %16
br label %172
172: ; preds = %169, %166
%173 = load i32, i32* %18
%174 = icmp eq i32 %173, 0
br i1 %174, label %175, label %198
175: ; preds = %172
%176 = load i8**, i8*** %12
%177 = icmp ne i8** %176, null
br i1 %177, label %178, label %197
178: ; preds = %175
%179 = load i8**, i8*** %12
%180 = load i8*, i8** %179
%181 = icmp eq i8* %180, null
br i1 %181, label %182, label %197
182: ; preds = %178
%183 = load i32, i32* %17
%184 = call i8* @strerror(i32 %183)
%185 = call i32 @strlen(i8* %184)
%186 = add nsw i32 20, %185
store i32 %186, i32* %23
%187 = load i32, i32* %23
%188 = call i64 @m_malloc(i32 %187)
%189 = inttoptr i64 %188 to i8*
%190 = load i8**, i8*** %12
store i8* %189, i8** %190
%191 = load i8**, i8*** %12
%192 = load i8*, i8** %191
%193 = load i32, i32* %23
%194 = load i32, i32* %17
%195 = call i8* @strerror(i32 %194)
%196 = call i32 @snprintf(i8* %192, i32 %193, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %195)
br label %197
197: ; preds = %182, %178, %175
store i32 -1, i32* %7
br label %200
198: ; preds = %172
%199 = load i32, i32* %18
store i32 %199, i32* %7
br label %200
200: ; preds = %198, %197, %75
%201 = load i32, i32* %7
ret i32 %201
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32, %struct.addrinfo* }
%struct.linger = type { i32, i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str = [20 x i8] c"Error resolving: %s\00"
@errno = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@SO_LINGER = global i32 0
@.str.1 = [20 x i8] c"Error listening: %s\00"
define i32 @dropbear_listen(i8* %0, i8* %1, i32* nocapture writeonly %2, i32 %3, i8** %4, i32* nocapture %5) {
%7 = alloca %struct.addrinfo
%8 = alloca %struct.addrinfo*
%9 = alloca %struct.linger
%10 = alloca i32
%11 = bitcast %struct.addrinfo* %7 to i8*
%12 = bitcast %struct.addrinfo** %8 to i8*
store %struct.addrinfo* null, %struct.addrinfo** %8
%13 = bitcast %struct.linger* %9 to i8*
%14 = bitcast i32* %10 to i8*
%15 = call i32 @memset(%struct.addrinfo* %7, i32 0, i32 32)
%16 = load i32, i32* @AF_UNSPEC
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 5
store i32 %16, i32* %17
%18 = load i32, i32* @SOCK_STREAM
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 4
store i32 %18, i32* %19
%20 = icmp eq i8* %0, null
br i1 %20, label %26, label %21
21: ; preds = %6
%22 = load i8, i8* %0
%23 = icmp eq i8 %22, 0
%24 = select i1 %23, i8* null, i8* %0
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 0
store i32 1, i32* %25
br label %26
26: ; preds = %6, %21
%27 = phi i8* [ %24, %21 ], [ null, %6 ]
%28 = call i32 @getaddrinfo(i8* %27, i8* %1, %struct.addrinfo* %7, %struct.addrinfo** %8)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %26
%31 = load %struct.addrinfo*, %struct.addrinfo** %8
%32 = icmp ne %struct.addrinfo* %31, null
%33 = icmp ne i32 %3, 0
%34 = and i1 %32, %33
br i1 %34, label %35, label %110
35: ; preds = %30
%36 = getelementptr inbounds %struct.linger, %struct.linger* %9, i64 0, i32 0
%37 = getelementptr inbounds %struct.linger, %struct.linger* %9, i64 0, i32 1
br label %56
38: ; preds = %26
%39 = icmp eq i8** %4, null
br i1 %39, label %51, label %40
40: ; preds = %38
%41 = load i8*, i8** %4
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %51
43: ; preds = %40
%44 = call i8* @gai_strerror(i32 %28)
%45 = call i32 @strlen(i8* %44)
%46 = add nsw i32 %45, 20
%47 = call i64 @m_malloc(i32 %46)
%48 = inttoptr i64 %47 to i8*
store i8* %48, i8** %4
%49 = call i8* @gai_strerror(i32 %28)
%50 = call i32 @snprintf(i8* %48, i32 %46, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %49)
br label %51
51: ; preds = %43, %40, %38
%52 = load %struct.addrinfo*, %struct.addrinfo** %8
%53 = icmp eq %struct.addrinfo* %52, null
br i1 %53, label %132, label %54
54: ; preds = %51
%55 = call i32 @freeaddrinfo(%struct.addrinfo* %52)
br label %132
56: ; preds = %35, %100
%57 = phi %struct.addrinfo* [ %31, %35 ], [ %104, %100 ]
%58 = phi i32 [ 0, %35 ], [ %102, %100 ]
%59 = phi i32 [ 0, %35 ], [ %101, %100 ]
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 5
%61 = load i32, i32* %60
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 4
%63 = load i32, i32* %62
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 3
%65 = load i32, i32* %64
%66 = call i32 @socket(i32 %61, i32 %63, i32 %65)
%67 = zext i32 %58 to i64
%68 = getelementptr inbounds i32, i32* %2, i64 %67
store i32 %66, i32* %68
%69 = icmp slt i32 %66, 0
br i1 %69, label %70, label %72
70: ; preds = %56
%71 = load i32, i32* @errno
br label %100
72: ; preds = %56
store i32 1, i32* %10
%73 = load i32, i32* @SOL_SOCKET
%74 = load i32, i32* @SO_REUSEADDR
%75 = call i32 @setsockopt(i32 %66, i32 %73, i32 %74, i8* %14, i32 4)
store i32 1, i32* %36
store i32 5, i32* %37
%76 = load i32, i32* @SOL_SOCKET
%77 = load i32, i32* @SO_LINGER
%78 = call i32 @setsockopt(i32 %66, i32 %76, i32 %77, i8* %13, i32 8)
%79 = call i32 @set_sock_priority(i32 %66)
%80 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 2
%81 = load i32, i32* %80
%82 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 1
%83 = load i32, i32* %82
%84 = call i64 @bind(i32 %66, i32 %81, i32 %83)
%85 = icmp slt i64 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %72
%87 = load i32, i32* @errno
%88 = call i32 @close(i32 %66)
br label %100
89: ; preds = %72
%90 = call i64 @listen(i32 %66, i32 20)
%91 = icmp slt i64 %90, 0
br i1 %91, label %92, label %95
92: ; preds = %89
%93 = load i32, i32* @errno
%94 = call i32 @close(i32 %66)
br label %100
95: ; preds = %89
%96 = load i32, i32* %5
%97 = icmp sgt i32 %96, %66
%98 = select i1 %97, i32 %96, i32 %66
store i32 %98, i32* %5
%99 = add nuw i32 %58, 1
br label %100
100: ; preds = %95, %92, %86, %70
%101 = phi i32 [ %71, %70 ], [ %87, %86 ], [ %93, %92 ], [ %59, %95 ]
%102 = phi i32 [ %58, %70 ], [ %58, %86 ], [ %58, %92 ], [ %99, %95 ]
%103 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 6
%104 = load %struct.addrinfo*, %struct.addrinfo** %103
%105 = icmp ne %struct.addrinfo* %104, null
%106 = icmp ult i32 %102, %3
%107 = select i1 %105, i1 %106, i1 false
br i1 %107, label %56, label %108
108: ; preds = %100
%109 = load %struct.addrinfo*, %struct.addrinfo** %8
br label %110
110: ; preds = %108, %30
%111 = phi %struct.addrinfo* [ %31, %30 ], [ %109, %108 ]
%112 = phi i32 [ 0, %30 ], [ %101, %108 ]
%113 = phi i32 [ 0, %30 ], [ %102, %108 ]
%114 = icmp eq %struct.addrinfo* %111, null
br i1 %114, label %117, label %115
115: ; preds = %110
%116 = call i32 @freeaddrinfo(%struct.addrinfo* %111)
store %struct.addrinfo* null, %struct.addrinfo** %8
br label %117
117: ; preds = %115, %110
%118 = icmp eq i32 %113, 0
br i1 %118, label %119, label %132
119: ; preds = %117
%120 = icmp eq i8** %4, null
br i1 %120, label %132, label %121
121: ; preds = %119
%122 = load i8*, i8** %4
%123 = icmp eq i8* %122, null
br i1 %123, label %124, label %132
124: ; preds = %121
%125 = call i8* @strerror(i32 %112)
%126 = call i32 @strlen(i8* %125)
%127 = add nsw i32 %126, 20
%128 = call i64 @m_malloc(i32 %127)
%129 = inttoptr i64 %128 to i8*
store i8* %129, i8** %4
%130 = call i8* @strerror(i32 %112)
%131 = call i32 @snprintf(i8* %129, i32 %127, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %130)
br label %132
132: ; preds = %117, %119, %121, %124, %51, %54
%133 = phi i32 [ -1, %54 ], [ -1, %51 ], [ -1, %124 ], [ -1, %121 ], [ -1, %119 ], [ %113, %117 ]
ret i32 %133
}