#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 addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ *ai_addr;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ *ai_canonname;
  int /*<<< orphan*/ ai_flags;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ reuseaddr_opt;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ gai_strerror(int);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, void const *,
               int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int, ...);
int create_listenfd(const char **argv) {
  struct addrinfo hints;
  struct addrinfo *result, *rp;
  int ret;
  int listenfd;
  int reuseaddr_opt = 1;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_UNSPEC;
  hints.ai_flags = AI_PASSIVE;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_protocol = 0;
  hints.ai_canonname = NULL;
  hints.ai_addr = NULL;
  hints.ai_next = NULL;
  ret = getaddrinfo(argv[2], argv[1], &hints, &result);
  if (0 != ret) {
    syslog(LOG_ERR,
           "[%d] Please input an appropriate proxy port or IP address!\n\r "
           "(%s)\r\n",
           324, gai_strerror(ret));
    exit(EXIT_FAILURE);
  }
  for (rp = result; rp != NULL; rp = rp->ai_next) {
    listenfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
    if (-1 == listenfd) {
      syslog(LOG_ERR, "[%d] failed to create socket (%m)!\r\n", 332);
      continue;
    }
    ret = setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR,
                     (const void *)&reuseaddr_opt,
                     (socklen_t)sizeof(reuseaddr_opt));
    if (-1 == ret) {
      syslog(LOG_ERR, "[%d] failed to setsockopt--listenfd:%d (%m)!\r\n", 338,
             listenfd);
      close(listenfd);
      continue;
    }
    if (-1 == bind(listenfd, rp->ai_addr, rp->ai_addrlen)) {
      syslog(LOG_ERR, "[%d] failed to bind--listenfd:%d (%m)!\r\n", 344,
             listenfd);
      close(listenfd);
      continue;
    }
    if (0 == listen(listenfd, 50)) {
      break;
    } else {
      syslog(LOG_ERR, "[%d] failed to listen --listenfd:%d (%m)!\r\n", 352,
             listenfd);
      close(listenfd);
      continue;
    }
  }
  freeaddrinfo(result);
  if (NULL == rp) {
    syslog(LOG_ERR, "[%d] failed to bind socket to proxy_port(%m)!\r\n", 360);
    exit(EXIT_FAILURE);
  }
  return listenfd;
}


x86 assembly (clang, -O0):
<create_listenfd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x5c(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1050 <memset@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2dd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   10b0 <getaddrinfo@plt>
mov    %eax,-0x54(%rbp)
xor    %eax,%eax
cmp    -0x54(%rbp),%eax
je     127c <create_listenfd+0xcc>
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    -0x54(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    -0x60(%rbp),%edi
mov    %eax,%ecx
lea    0xd9e(%rip),%rsi
mov    $0x144,%edx
mov    $0x0,%al
call   1070 <syslog@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     13e6 <create_listenfd+0x236>
mov    -0x50(%rbp),%rax
mov    0x1c(%rax),%edi
mov    -0x50(%rbp),%rax
mov    0x18(%rax),%esi
mov    -0x50(%rbp),%rax
mov    0x10(%rax),%rdx
call   10d0 <socket@plt>
mov    %eax,-0x58(%rbp)
mov    $0xffffffff,%eax
cmp    -0x58(%rbp),%eax
jne    12dc <create_listenfd+0x12c>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
lea    0xd79(%rip),%rsi
mov    $0x14c,%edx
mov    $0x0,%al
call   1070 <syslog@plt>
jmp    13d5 <create_listenfd+0x225>
mov    -0x58(%rbp),%edi
mov    0x2d02(%rip),%rax
mov    (%rax),%esi
mov    0x2cc9(%rip),%rax
mov    (%rax),%edx
lea    -0x5c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x54(%rbp)
mov    $0xffffffff,%eax
cmp    -0x54(%rbp),%eax
jne    133d <create_listenfd+0x18d>
mov    0x2c90(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%ecx
lea    0xd45(%rip),%rsi
mov    $0x152,%edx
mov    $0x0,%al
call   1070 <syslog@plt>
mov    -0x58(%rbp),%edi
call   1060 <close@plt>
jmp    13d5 <create_listenfd+0x225>
mov    -0x58(%rbp),%edi
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x50(%rbp),%rax
mov    (%rax),%edx
call   1090 <bind@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    138e <create_listenfd+0x1de>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%ecx
lea    0xd23(%rip),%rsi
mov    $0x158,%edx
mov    $0x0,%al
call   1070 <syslog@plt>
mov    -0x58(%rbp),%edi
call   1060 <close@plt>
jmp    13d5 <create_listenfd+0x225>
mov    -0x58(%rbp),%edi
mov    $0x32,%esi
call   1080 <listen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    13ae <create_listenfd+0x1fe>
jmp    13e6 <create_listenfd+0x236>
mov    0x2bf3(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%ecx
lea    0xd00(%rip),%rsi
mov    $0x160,%edx
mov    $0x0,%al
call   1070 <syslog@plt>
mov    -0x58(%rbp),%edi
call   1060 <close@plt>
mov    -0x50(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    1284 <create_listenfd+0xd4>
mov    -0x48(%rbp),%rdi
call   10c0 <freeaddrinfo@plt>
xor    %eax,%eax
cmp    -0x50(%rbp),%rax
jne    1425 <create_listenfd+0x275>
mov    0x2ba6(%rip),%rax
mov    (%rax),%edi
lea    0xce2(%rip),%rsi
mov    $0x168,%edx
mov    $0x0,%al
call   1070 <syslog@plt>
mov    0x2ba2(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x58(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_listenfd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%rbx
movl   $0x1,0xc(%rsp)
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1050 <memset@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rsp)
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x40(%rsp)
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
movups %xmm0,0x30(%rsp)
mov    0x8(%rbx),%rsi
mov    0x10(%rbx),%rdi
mov    %rsp,%rcx
mov    %rbp,%rdx
call   10b0 <getaddrinfo@plt>
test   %eax,%eax
jne    137c <create_listenfd+0x1cc>
mov    (%rsp),%r12
test   %r12,%r12
je     13a5 <create_listenfd+0x1f5>
mov    0x2d68(%rip),%r15
mov    0x2da1(%rip),%r13
mov    0x2d6a(%rip),%r14
lea    0xc(%rsp),%rbx
jmp    128d <create_listenfd+0xdd>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15),%edi
lea    0xdff(%rip),%rsi
mov    $0x152,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1070 <syslog@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x20(%r12),%r12
test   %r12,%r12
je     1349 <create_listenfd+0x199>
mov    0x1c(%r12),%edi
mov    0x18(%r12),%esi
mov    0x10(%r12),%rdx
call   10d0 <socket@plt>
cmp    $0xffffffff,%eax
je     1300 <create_listenfd+0x150>
mov    %eax,%ebp
mov    0x0(%r13),%esi
mov    (%r14),%edx
mov    %eax,%edi
mov    %rbx,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1260 <create_listenfd+0xb0>
mov    0x8(%r12),%rsi
mov    (%r12),%edx
mov    %ebp,%edi
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
je     131b <create_listenfd+0x16b>
mov    %ebp,%edi
mov    $0x32,%esi
call   1080 <listen@plt>
test   %rax,%rax
je     132f <create_listenfd+0x17f>
mov    (%r15),%edi
lea    0xdcd(%rip),%rsi
mov    $0x160,%edx
jmp    126f <create_listenfd+0xbf>
xchg   %ax,%ax
mov    (%r15),%edi
lea    0xd3a(%rip),%rsi
mov    $0x14c,%edx
xor    %eax,%eax
call   1070 <syslog@plt>
jmp    127f <create_listenfd+0xcf>
mov    (%r15),%edi
lea    0xd73(%rip),%rsi
mov    $0x158,%edx
jmp    126f <create_listenfd+0xbf>
mov    (%rsp),%rdi
call   10c0 <freeaddrinfo@plt>
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsp),%rdi
call   10c0 <freeaddrinfo@plt>
mov    0x2c4f(%rip),%rax
mov    (%rax),%edi
lea    0xd8b(%rip),%rsi
mov    $0x168,%edx
xor    %eax,%eax
call   1070 <syslog@plt>
mov    0x2c4b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2c25(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xc6d(%rip),%rsi
mov    %ebx,%edi
mov    $0x144,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <syslog@plt>
jmp    136e <create_listenfd+0x1be>
xor    %edi,%edi
jmp    134d <create_listenfd+0x19d>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32*, i64, i32, i32, %struct.addrinfo*, i32*, i32 }
@AF_UNSPEC = global i32 0
@AI_PASSIVE = global i32 0
@SOCK_STREAM = global i32 0
@LOG_ERR = global i32 0
@.str = [68 x i8] c"[%d] Please input an appropriate proxy port or IP address!\0A\0D (%s)\0D\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [37 x i8] c"[%d] failed to create socket (%m)!\0D\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [47 x i8] c"[%d] failed to setsockopt--listenfd:%d (%m)!\0D\0A\00"
@.str.3 = [41 x i8] c"[%d] failed to bind--listenfd:%d (%m)!\0D\0A\00"
@.str.4 = [44 x i8] c"[%d] failed to listen --listenfd:%d (%m)!\0D\0A\00"
@.str.5 = [48 x i8] c"[%d] failed to bind socket to proxy_port(%m)!\0D\0A\00"
define i32 @create_listenfd(i8** %0) {
%2 = alloca i8**
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca %struct.addrinfo*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8** %0, i8*** %2
store i32 1, i32* %8
%9 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 56)
%10 = load i32, i32* @AF_UNSPEC
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i32 0, i32 4
store i32 %10, i32* %11
%12 = load i32, i32* @AI_PASSIVE
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i32 0, i32 7
store i32 %12, i32* %13
%14 = load i32, i32* @SOCK_STREAM
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i32 0, i32 3
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i32 0, i32 2
store i64 0, i64* %16
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i32 0, i32 6
store i32* null, i32** %17
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i32 0, i32 1
store i32* null, i32** %18
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i32 0, i32 5
store %struct.addrinfo* null, %struct.addrinfo** %19
%20 = load i8**, i8*** %2
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = load i8**, i8*** %2
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @getaddrinfo(i8* %22, i8* %25, %struct.addrinfo* %3, %struct.addrinfo** %4)
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp ne i32 0, %27
br i1 %28, label %29, label %36
29: ; preds = %1
%30 = load i32, i32* @LOG_ERR
%31 = load i32, i32* %6
%32 = call i32 @gai_strerror(i32 %31)
%33 = call i32 (i32, i8*, i32, ...) @syslog(i32 %30, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i32 324, i32 %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %1
%37 = load %struct.addrinfo*, %struct.addrinfo** %4
store %struct.addrinfo* %37, %struct.addrinfo** %5
br label %38
38: ; preds = %98, %36
%39 = load %struct.addrinfo*, %struct.addrinfo** %5
%40 = icmp ne %struct.addrinfo* %39, null
br i1 %40, label %41, label %102
41: ; preds = %38
%42 = load %struct.addrinfo*, %struct.addrinfo** %5
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %42, i32 0, i32 4
%44 = load i32, i32* %43
%45 = load %struct.addrinfo*, %struct.addrinfo** %5
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %45, i32 0, i32 3
%47 = load i32, i32* %46
%48 = load %struct.addrinfo*, %struct.addrinfo** %5
%49 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %48, i32 0, i32 2
%50 = load i64, i64* %49
%51 = call i32 @socket(i32 %44, i32 %47, i64 %50)
store i32 %51, i32* %7
%52 = load i32, i32* %7
%53 = icmp eq i32 -1, %52
br i1 %53, label %54, label %57
54: ; preds = %41
%55 = load i32, i32* @LOG_ERR
%56 = call i32 (i32, i8*, i32, ...) @syslog(i32 %55, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 332)
br label %98
57: ; preds = %41
%58 = load i32, i32* %7
%59 = load i32, i32* @SOL_SOCKET
%60 = load i32, i32* @SO_REUSEADDR
%61 = bitcast i32* %8 to i8*
%62 = call i32 @setsockopt(i32 %58, i32 %59, i32 %60, i8* %61, i32 4)
store i32 %62, i32* %6
%63 = load i32, i32* %6
%64 = icmp eq i32 -1, %63
br i1 %64, label %65, label %71
65: ; preds = %57
%66 = load i32, i32* @LOG_ERR
%67 = load i32, i32* %7
%68 = call i32 (i32, i8*, i32, ...) @syslog(i32 %66, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 338, i32 %67)
%69 = load i32, i32* %7
%70 = call i32 @close(i32 %69)
br label %98
71: ; preds = %57
%72 = load i32, i32* %7
%73 = load %struct.addrinfo*, %struct.addrinfo** %5
%74 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %73, i32 0, i32 1
%75 = load i32*, i32** %74
%76 = load %struct.addrinfo*, %struct.addrinfo** %5
%77 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %76, i32 0, i32 0
%78 = load i32, i32* %77
%79 = call i32 @bind(i32 %72, i32* %75, i32 %78)
%80 = icmp eq i32 -1, %79
br i1 %80, label %81, label %87
81: ; preds = %71
%82 = load i32, i32* @LOG_ERR
%83 = load i32, i32* %7
%84 = call i32 (i32, i8*, i32, ...) @syslog(i32 %82, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 344, i32 %83)
%85 = load i32, i32* %7
%86 = call i32 @close(i32 %85)
br label %98
87: ; preds = %71
%88 = load i32, i32* %7
%89 = call i64 @listen(i32 %88, i32 50)
%90 = icmp eq i64 0, %89
br i1 %90, label %91, label %92
91: ; preds = %87
br label %102
92: ; preds = %87
%93 = load i32, i32* @LOG_ERR
%94 = load i32, i32* %7
%95 = call i32 (i32, i8*, i32, ...) @syslog(i32 %93, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 352, i32 %94)
%96 = load i32, i32* %7
%97 = call i32 @close(i32 %96)
br label %98
98: ; preds = %92, %81, %65, %54
%99 = load %struct.addrinfo*, %struct.addrinfo** %5
%100 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %99, i32 0, i32 5
%101 = load %struct.addrinfo*, %struct.addrinfo** %100
store %struct.addrinfo* %101, %struct.addrinfo** %5
br label %38
102: ; preds = %91, %38
%103 = load %struct.addrinfo*, %struct.addrinfo** %4
%104 = call i32 @freeaddrinfo(%struct.addrinfo* %103)
%105 = load %struct.addrinfo*, %struct.addrinfo** %5
%106 = icmp eq %struct.addrinfo* null, %105
br i1 %106, label %107, label %112
107: ; preds = %102
%108 = load i32, i32* @LOG_ERR
%109 = call i32 (i32, i8*, i32, ...) @syslog(i32 %108, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i32 360)
%110 = load i32, i32* @EXIT_FAILURE
%111 = call i32 @exit(i32 %110)
unreachable
112: ; preds = %102
%113 = load i32, i32* %7
ret i32 %113
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32*, i64, i32, i32, %struct.addrinfo*, i32*, i32 }
@AF_UNSPEC = global i32 0
@AI_PASSIVE = global i32 0
@SOCK_STREAM = global i32 0
@LOG_ERR = global i32 0
@.str = [68 x i8] c"[%d] Please input an appropriate proxy port or IP address!\0A\0D (%s)\0D\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [37 x i8] c"[%d] failed to create socket (%m)!\0D\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [47 x i8] c"[%d] failed to setsockopt--listenfd:%d (%m)!\0D\0A\00"
@.str.3 = [41 x i8] c"[%d] failed to bind--listenfd:%d (%m)!\0D\0A\00"
@.str.4 = [44 x i8] c"[%d] failed to listen --listenfd:%d (%m)!\0D\0A\00"
@.str.5 = [48 x i8] c"[%d] failed to bind socket to proxy_port(%m)!\0D\0A\00"
define i32 @create_listenfd(i8** nocapture %0) {
%2 = alloca %struct.addrinfo
%3 = alloca %struct.addrinfo*
%4 = alloca i32
%5 = bitcast %struct.addrinfo* %2 to i8*
%6 = bitcast %struct.addrinfo** %3 to i8*
%7 = bitcast i32* %4 to i8*
store i32 1, i32* %4
%8 = call i32 @memset(%struct.addrinfo* %2, i32 0, i32 56)
%9 = load i32, i32* @AF_UNSPEC
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 4
store i32 %9, i32* %10
%11 = load i32, i32* @AI_PASSIVE
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 7
store i32 %11, i32* %12
%13 = load i32, i32* @SOCK_STREAM
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 3
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 1
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i64 0, i32 5
%17 = getelementptr inbounds i8*, i8** %0, i64 2
%18 = bitcast i32** %15 to i8*
%19 = bitcast %struct.addrinfo** %16 to i8*
%20 = load i8*, i8** %17
%21 = getelementptr inbounds i8*, i8** %0, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @getaddrinfo(i8* %20, i8* %22, %struct.addrinfo* %2, %struct.addrinfo** %3)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %1
%26 = load %struct.addrinfo*, %struct.addrinfo** %3
%27 = icmp eq %struct.addrinfo* %26, null
br i1 %27, label %80, label %34
28: ; preds = %1
%29 = load i32, i32* @LOG_ERR
%30 = call i32 @gai_strerror(i32 %23)
%31 = call i32 (i32, i8*, i32, ...) @syslog(i32 %29, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i32 324, i32 %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %25, %74
%35 = phi %struct.addrinfo* [ %76, %74 ], [ %26, %25 ]
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 4
%37 = load i32, i32* %36
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 3
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 2
%41 = load i64, i64* %40
%42 = call i32 @socket(i32 %37, i32 %39, i64 %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %34
%45 = load i32, i32* @LOG_ERR
%46 = call i32 (i32, i8*, i32, ...) @syslog(i32 %45, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 332)
br label %74
47: ; preds = %34
%48 = load i32, i32* @SOL_SOCKET
%49 = load i32, i32* @SO_REUSEADDR
%50 = call i32 @setsockopt(i32 %42, i32 %48, i32 %49, i8* %7, i32 4)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %56
52: ; preds = %47
%53 = load i32, i32* @LOG_ERR
%54 = call i32 (i32, i8*, i32, ...) @syslog(i32 %53, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 338, i32 %42)
%55 = call i32 @close(i32 %42)
br label %74
56: ; preds = %47
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 1
%58 = load i32*, i32** %57
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 0
%60 = load i32, i32* %59
%61 = call i32 @bind(i32 %42, i32* %58, i32 %60)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %67
63: ; preds = %56
%64 = load i32, i32* @LOG_ERR
%65 = call i32 (i32, i8*, i32, ...) @syslog(i32 %64, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 344, i32 %42)
%66 = call i32 @close(i32 %42)
br label %74
67: ; preds = %56
%68 = call i64 @listen(i32 %42, i32 50)
%69 = icmp eq i64 %68, 0
br i1 %69, label %87, label %70
70: ; preds = %67
%71 = load i32, i32* @LOG_ERR
%72 = call i32 (i32, i8*, i32, ...) @syslog(i32 %71, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 352, i32 %42)
%73 = call i32 @close(i32 %42)
br label %74
74: ; preds = %70, %63, %52, %44
%75 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 5
%76 = load %struct.addrinfo*, %struct.addrinfo** %75
%77 = icmp eq %struct.addrinfo* %76, null
br i1 %77, label %78, label %34
78: ; preds = %74
%79 = load %struct.addrinfo*, %struct.addrinfo** %3
br label %80
80: ; preds = %78, %25
%81 = phi %struct.addrinfo* [ %79, %78 ], [ null, %25 ]
%82 = call i32 @freeaddrinfo(%struct.addrinfo* %81)
%83 = load i32, i32* @LOG_ERR
%84 = call i32 (i32, i8*, i32, ...) @syslog(i32 %83, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i32 360)
%85 = load i32, i32* @EXIT_FAILURE
%86 = call i32 @exit(i32 %85)
unreachable
87: ; preds = %67
%88 = load %struct.addrinfo*, %struct.addrinfo** %3
%89 = call i32 @freeaddrinfo(%struct.addrinfo* %88)
ret i32 %42
}