#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_storage {
  int dummy;
};
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin6_addr;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  scalar_t__ ai_family;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_flags;
};
typedef int socklen_t;

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
int /*<<< orphan*/ AI_PASSIVE;
scalar_t__ EHOSTDOWN;
scalar_t__ EHOSTUNREACH;
scalar_t__ ENETDOWN;
scalar_t__ ENETUNREACH;
scalar_t__ ENONET;
scalar_t__ ENOPROTOOPT;
scalar_t__ EOPNOTSUPP;
scalar_t__ EPROTO;
int INET6_ADDRSTRLEN;
int INET_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *const, int *);
int bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *);
scalar_t__ errno;
int /*<<< orphan*/ errx(int, char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
scalar_t__ getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo const *,
                       struct addrinfo **);
int /*<<< orphan*/ inet_ntop(scalar_t__, int /*<<< orphan*/ *, char *, int);
int listen(int, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(struct sockaddr_in6 *, int /*<<< orphan*/, int);
int socket(scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ warn(char *);
int /*<<< orphan*/ warnx(char *, ...);
int main(void) {
  const struct addrinfo hints = {
      .ai_family = AF_INET, .ai_socktype = SOCK_STREAM, .ai_flags = AI_PASSIVE};
  struct addrinfo *ai = NULL;
  if (getaddrinfo(NULL, "2233", &hints, &ai))
    errx(1, "getaddrinfo");
  int fd;
  struct addrinfo *p = NULL;
  for (p = ai; p; p = p->ai_next) {
    fd = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
    if (fd == -1) {
      warn("socket");
      continue;
    }
    if (bind(fd, p->ai_addr, p->ai_addrlen) == -1) {
      warn("bind");
      close(fd);
      continue;
    }
    if (listen(fd, 0) == -1) {
      warn("listen");
      close(fd);
      continue;
    }
  }
  if (!p) {
    freeaddrinfo(ai);
    errx(1, "no local addr");
  }
  if (p->ai_family == AF_INET) {
    char ip[INET_ADDRSTRLEN];
    struct sockaddr_in sa;
    (void)memcpy(&sa, p->ai_addr, sizeof(struct sockaddr_in));
    if (!inet_ntop(AF_INET, &sa.sin_addr, ip, INET_ADDRSTRLEN))
      warn("inet_ntop");
    else
      warnx("listening on %.*s", INET_ADDRSTRLEN, ip);
  } else if (p->ai_family == AF_INET6) {
    char ip[INET6_ADDRSTRLEN];
    struct sockaddr_in6 sa;
    (void)memcpy(&sa, p->ai_addr, sizeof(struct sockaddr_in6));
    if (!inet_ntop(AF_INET6, &sa.sin6_addr, ip, INET6_ADDRSTRLEN))
      warn("inet_ntop");
    else
      warnx("listening on %.*s", INET6_ADDRSTRLEN, ip);
  } else {
    warnx("listening on unknown addrinfo family");
  }
  freeaddrinfo(ai);
  struct sockaddr_storage _addr;
  struct sockaddr *const addr = (struct sockaddr *)&_addr;
  socklen_t addrlen;
retry:
  addrlen = sizeof(struct sockaddr_storage);
  const int conn_fd = accept(fd, addr, &addrlen);
  if (conn_fd == -1) {
    if (errno == ENETDOWN || errno == ENOPROTOOPT || errno == EPROTO ||
        errno == EHOSTDOWN || errno == EHOSTUNREACH || errno == ENONET ||
        errno == EOPNOTSUPP || errno == ENETUNREACH)
      goto retry;
    else
      err(1, "accept");
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x38(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdc8(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   10d0 <getaddrinfo@plt>
cmp    $0x0,%rax
je     1260 <main+0x90>
mov    $0x1,%edi
lea    0xdaa(%rip),%rsi
call   1050 <errx@plt>
movq   $0x0,-0x48(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     132d <main+0x15d>
mov    -0x48(%rbp),%rax
mov    (%rax),%rdi
mov    -0x48(%rbp),%rax
mov    0x14(%rax),%esi
mov    -0x48(%rbp),%rax
mov    0x10(%rax),%edx
call   10f0 <socket@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    12b3 <main+0xe3>
lea    0xd68(%rip),%rdi
call   1040 <warn@plt>
jmp    131c <main+0x14c>
mov    -0x3c(%rbp),%edi
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%esi
mov    -0x48(%rbp),%rax
mov    0xc(%rax),%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12eb <main+0x11b>
lea    0xd3f(%rip),%rdi
call   1040 <warn@plt>
mov    -0x3c(%rbp),%edi
call   1070 <close@plt>
jmp    131c <main+0x14c>
mov    -0x3c(%rbp),%edi
xor    %esi,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1317 <main+0x147>
lea    0xd18(%rip),%rdi
call   1040 <warn@plt>
mov    -0x3c(%rbp),%edi
call   1070 <close@plt>
jmp    131c <main+0x14c>
jmp    131c <main+0x14c>
mov    -0x48(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    1270 <main+0xa0>
cmpq   $0x0,-0x48(%rbp)
jne    1352 <main+0x182>
mov    -0x38(%rbp),%rdi
call   10e0 <freeaddrinfo@plt>
mov    $0x1,%edi
lea    0xcd7(%rip),%rsi
call   1050 <errx@plt>
mov    -0x48(%rbp),%rax
mov    (%rax),%rax
mov    0x2c70(%rip),%rcx
cmp    (%rcx),%rax
jne    1418 <main+0x248>
mov    0x2c08(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x98(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x58(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%esi
mov    $0x8,%edx
call   1080 <memcpy@plt>
mov    -0x98(%rbp),%rdx
mov    0x2c15(%rip),%rax
mov    (%rax),%rdi
lea    -0x60(%rbp),%rsi
add    $0x4,%rsi
mov    0x2bab(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%eax
jne    13ee <main+0x21e>
lea    0xc4e(%rip),%rdi
call   1040 <warn@plt>
jmp    140c <main+0x23c>
mov    -0x98(%rbp),%rdx
mov    0x2b7c(%rip),%rax
mov    (%rax),%esi
lea    0xc37(%rip),%rdi
mov    $0x0,%al
call   1060 <warnx@plt>
mov    -0x50(%rbp),%rax
mov    %rax,%rsp
jmp    14ed <main+0x31d>
mov    -0x48(%rbp),%rax
mov    (%rax),%rax
mov    0x2b82(%rip),%rcx
cmp    (%rcx),%rax
jne    14da <main+0x30a>
mov    0x2bb2(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xa0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x70(%rbp)
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%esi
lea    -0x78(%rbp),%rdi
mov    $0x8,%edx
call   1080 <memcpy@plt>
mov    -0xa0(%rbp),%rdx
mov    0x2b27(%rip),%rax
mov    (%rax),%rdi
lea    -0x78(%rbp),%rsi
mov    0x2b59(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%eax
jne    14b0 <main+0x2e0>
lea    0xb8c(%rip),%rdi
call   1040 <warn@plt>
jmp    14ce <main+0x2fe>
mov    -0xa0(%rbp),%rdx
mov    0x2b2a(%rip),%rax
mov    (%rax),%esi
lea    0xb75(%rip),%rdi
mov    $0x0,%al
call   1060 <warnx@plt>
mov    -0x68(%rbp),%rax
mov    %rax,%rsp
jmp    14e8 <main+0x318>
lea    0xb6d(%rip),%rdi
mov    $0x0,%al
call   1060 <warnx@plt>
jmp    14ed <main+0x31d>
mov    -0x38(%rbp),%rdi
call   10e0 <freeaddrinfo@plt>
lea    -0x80(%rbp),%rax
mov    %rax,-0x88(%rbp)
movl   $0x4,-0x8c(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x88(%rbp),%rsi
lea    -0x8c(%rbp),%rdx
call   10c0 <accept@plt>
mov    %eax,-0x90(%rbp)
cmpl   $0xffffffff,-0x90(%rbp)
jne    161f <main+0x44f>
mov    0x2a45(%rip),%rax
mov    (%rax),%rax
mov    0x2a7b(%rip),%rcx
cmp    (%rcx),%rax
je     1604 <main+0x434>
mov    0x2a2b(%rip),%rax
mov    (%rax),%rax
mov    0x2a81(%rip),%rcx
cmp    (%rcx),%rax
je     1604 <main+0x434>
mov    0x2a11(%rip),%rax
mov    (%rax),%rax
mov    0x2a1f(%rip),%rcx
cmp    (%rcx),%rax
je     1604 <main+0x434>
mov    0x29f7(%rip),%rax
mov    (%rax),%rax
mov    0x29dd(%rip),%rcx
cmp    (%rcx),%rax
je     1604 <main+0x434>
mov    0x29dd(%rip),%rax
mov    (%rax),%rax
mov    0x2a03(%rip),%rcx
cmp    (%rcx),%rax
je     1604 <main+0x434>
mov    0x29c3(%rip),%rax
mov    (%rax),%rax
mov    0x29f1(%rip),%rcx
cmp    (%rcx),%rax
je     1604 <main+0x434>
mov    0x29a9(%rip),%rax
mov    (%rax),%rax
mov    0x29af(%rip),%rcx
cmp    (%rcx),%rax
je     1604 <main+0x434>
mov    0x298f(%rip),%rax
mov    (%rax),%rax
mov    0x29cd(%rip),%rcx
cmp    (%rcx),%rax
jne    1609 <main+0x439>
jmp    1501 <main+0x331>
mov    $0x1,%edi
lea    0xa5e(%rip),%rsi
call   1090 <err@plt>
jmp    161f <main+0x44f>
mov    -0x3c(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    0x2df0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x68(%rbp)
movq   $0x0,-0x60(%rbp)
movl   $0x0,-0x58(%rbp)
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
movq   $0x0,-0x50(%rbp)
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
movq   $0x0,-0x30(%rbp)
lea    0xdd3(%rip),%rsi
lea    -0x68(%rbp),%rdx
lea    -0x30(%rbp),%rcx
xor    %edi,%edi
call   10d0 <getaddrinfo@plt>
test   %rax,%rax
je     1252 <main+0x82>
lea    0xdbd(%rip),%rsi
mov    $0x1,%edi
call   1050 <errx@plt>
mov    -0x30(%rbp),%r13
test   %r13,%r13
je     12e7 <main+0x117>
lea    0xdab(%rip),%r14
lea    0xdab(%rip),%r15
lea    0xda9(%rip),%r12
jmp    1291 <main+0xc1>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <warn@plt>
mov    0x18(%r13),%r13
test   %r13,%r13
je     12e1 <main+0x111>
mov    0x0(%r13),%rdi
mov    0x14(%r13),%esi
mov    0x10(%r13),%edx
call   10f0 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1280 <main+0xb0>
mov    0x8(%r13),%esi
mov    0xc(%r13),%edx
mov    %ebx,%edi
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
je     12d0 <main+0x100>
mov    %ebx,%edi
xor    %esi,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1288 <main+0xb8>
mov    %r12,%rdi
jmp    12d3 <main+0x103>
mov    %r15,%rdi
call   1040 <warn@plt>
mov    %ebx,%edi
call   1070 <close@plt>
jmp    1288 <main+0xb8>
mov    -0x30(%rbp),%rdi
jmp    12e9 <main+0x119>
xor    %edi,%edi
call   10e0 <freeaddrinfo@plt>
lea    0xd2f(%rip),%rsi
mov    $0x1,%edi
call   1050 <errx@plt>
mov    %rsp,%r15
mov    0x2c7f(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    0x8,%esi
lea    -0x40(%rbp),%rdi
mov    $0x8,%edx
call   1080 <memcpy@plt>
mov    0x2c9e(%rip),%rax
mov    (%rax),%rdi
lea    -0x3c(%rbp),%rsi
mov    (%r12),%ecx
mov    %r14,%rdx
call   1030 <inet_ntop@plt>
test   %eax,%eax
je     1368 <main+0x198>
mov    (%r12),%esi
lea    0xce0(%rip),%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <warnx@plt>
jmp    1374 <main+0x1a4>
lea    0xcc3(%rip),%rdi
call   1040 <warn@plt>
mov    %r15,%rsp
mov    -0x30(%rbp),%rdi
call   10e0 <freeaddrinfo@plt>
lea    -0x34(%rbp),%r15
mov    0x2c5d(%rip),%r12
mov    0x2c16(%rip),%r13
mov    0x2be7(%rip),%r14
nopl   0x0(%rax)
movl   $0x4,-0x34(%rbp)
mov    %ebx,%edi
lea    -0x40(%rbp),%rsi
mov    %r15,%rdx
call   10c0 <accept@plt>
cmp    $0xffffffff,%eax
jne    1422 <main+0x252>
mov    0x2bcf(%rip),%rax
mov    (%rax),%rax
mov    0x2bfd(%rip),%rcx
cmp    (%rcx),%rax
je     13a0 <main+0x1d0>
cmp    (%r12),%rax
je     13a0 <main+0x1d0>
cmp    0x0(%r13),%rax
je     13a0 <main+0x1d0>
cmp    (%r14),%rax
je     13a0 <main+0x1d0>
mov    0x2bd0(%rip),%rcx
cmp    (%rcx),%rax
je     13a0 <main+0x1d0>
mov    0x2bcc(%rip),%rcx
cmp    (%rcx),%rax
je     13a0 <main+0x1d0>
mov    0x2ba0(%rip),%rcx
cmp    (%rcx),%rax
je     13a0 <main+0x1d0>
mov    0x2bc4(%rip),%rcx
cmp    (%rcx),%rax
je     13a0 <main+0x1d0>
lea    0xc36(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i64, i32, i32, i32, i32, %struct.addrinfo*, i32 }
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr_in6 = type { i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i64 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [5 x i8] c"2233\00"
@.str.1 = [12 x i8] c"getaddrinfo\00"
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [7 x i8] c"listen\00"
@.str.5 = [14 x i8] c"no local addr\00"
@INET_ADDRSTRLEN = global i32 0
@.str.6 = [10 x i8] c"inet_ntop\00"
@.str.7 = [18 x i8] c"listening on %.*s\00"
@AF_INET6 = global i64 0
@INET6_ADDRSTRLEN = global i32 0
@.str.8 = [37 x i8] c"listening on unknown addrinfo family\00"
@errno = global i64 0
@ENETDOWN = global i64 0
@ENOPROTOOPT = global i64 0
@EPROTO = global i64 0
@EHOSTDOWN = global i64 0
@EHOSTUNREACH = global i64 0
@ENONET = global i64 0
@EOPNOTSUPP = global i64 0
@ENETUNREACH = global i64 0
@.str.9 = [7 x i8] c"accept\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.addrinfo
%3 = alloca %struct.addrinfo*
%4 = alloca i32
%5 = alloca %struct.addrinfo*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.sockaddr_in
%9 = alloca i8*
%10 = alloca i64
%11 = alloca %struct.sockaddr_in6
%12 = alloca %struct.sockaddr_storage
%13 = alloca %struct.sockaddr*
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %1
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 0
%17 = load i64, i64* @AF_INET
store i64 %17, i64* %16
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 1
store i32 0, i32* %18
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 2
store i32 0, i32* %19
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 3
store i32 0, i32* %20
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 4
%22 = load i32, i32* @SOCK_STREAM
store i32 %22, i32* %21
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 5
store %struct.addrinfo* null, %struct.addrinfo** %23
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 6
%25 = load i32, i32* @AI_PASSIVE
store i32 %25, i32* %24
store %struct.addrinfo* null, %struct.addrinfo** %3
%26 = call i64 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %2, %struct.addrinfo** %3)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %0
%29 = call i32 @errx(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %0
store %struct.addrinfo* null, %struct.addrinfo** %5
%31 = load %struct.addrinfo*, %struct.addrinfo** %3
store %struct.addrinfo* %31, %struct.addrinfo** %5
br label %32
32: ; preds = %73, %30
%33 = load %struct.addrinfo*, %struct.addrinfo** %5
%34 = icmp ne %struct.addrinfo* %33, null
br i1 %34, label %35, label %77
35: ; preds = %32
%36 = load %struct.addrinfo*, %struct.addrinfo** %5
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i32 0, i32 0
%38 = load i64, i64* %37
%39 = load %struct.addrinfo*, %struct.addrinfo** %5
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i32 0, i32 4
%41 = load i32, i32* %40
%42 = load %struct.addrinfo*, %struct.addrinfo** %5
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %42, i32 0, i32 3
%44 = load i32, i32* %43
%45 = call i32 @socket(i64 %38, i32 %41, i32 %44)
store i32 %45, i32* %4
%46 = load i32, i32* %4
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %35
%49 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %73
50: ; preds = %35
%51 = load i32, i32* %4
%52 = load %struct.addrinfo*, %struct.addrinfo** %5
%53 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %52, i32 0, i32 1
%54 = load i32, i32* %53
%55 = load %struct.addrinfo*, %struct.addrinfo** %5
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %55, i32 0, i32 2
%57 = load i32, i32* %56
%58 = call i32 @bind(i32 %51, i32 %54, i32 %57)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %64
60: ; preds = %50
%61 = call i32 @warn(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%62 = load i32, i32* %4
%63 = call i32 @close(i32 %62)
br label %73
64: ; preds = %50
%65 = load i32, i32* %4
%66 = call i32 @listen(i32 %65, i32 0)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %72
68: ; preds = %64
%69 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%70 = load i32, i32* %4
%71 = call i32 @close(i32 %70)
br label %73
72: ; preds = %64
br label %73
73: ; preds = %72, %68, %60, %48
%74 = load %struct.addrinfo*, %struct.addrinfo** %5
%75 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %74, i32 0, i32 5
%76 = load %struct.addrinfo*, %struct.addrinfo** %75
store %struct.addrinfo* %76, %struct.addrinfo** %5
br label %32
77: ; preds = %32
%78 = load %struct.addrinfo*, %struct.addrinfo** %5
%79 = icmp ne %struct.addrinfo* %78, null
br i1 %79, label %84, label %80
80: ; preds = %77
%81 = load %struct.addrinfo*, %struct.addrinfo** %3
%82 = call i32 @freeaddrinfo(%struct.addrinfo* %81)
%83 = call i32 @errx(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %84
84: ; preds = %80, %77
%85 = load %struct.addrinfo*, %struct.addrinfo** %5
%86 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %85, i32 0, i32 0
%87 = load i64, i64* %86
%88 = load i64, i64* @AF_INET
%89 = icmp eq i64 %87, %88
br i1 %89, label %90, label %112
90: ; preds = %84
%91 = load i32, i32* @INET_ADDRSTRLEN
%92 = zext i32 %91 to i64
%93 = call i8* @llvm.stacksave()
store i8* %93, i8** %6
%94 = alloca i8, i64 %92
store i64 %92, i64* %7
%95 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr_in6*
%96 = load %struct.addrinfo*, %struct.addrinfo** %5
%97 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %96, i32 0, i32 1
%98 = load i32, i32* %97
%99 = call i32 @memcpy(%struct.sockaddr_in6* %95, i32 %98, i32 8)
%100 = load i64, i64* @AF_INET
%101 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%102 = load i32, i32* @INET_ADDRSTRLEN
%103 = call i32 @inet_ntop(i64 %100, i32* %101, i8* %94, i32 %102)
%104 = icmp ne i32 %103, 0
br i1 %104, label %107, label %105
105: ; preds = %90
%106 = call i32 @warn(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %110
107: ; preds = %90
%108 = load i32, i32* @INET_ADDRSTRLEN
%109 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i32 %108, i8* %94)
br label %110
110: ; preds = %107, %105
%111 = load i8*, i8** %6
br label %142
112: ; preds = %84
%113 = load %struct.addrinfo*, %struct.addrinfo** %5
%114 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %113, i32 0, i32 0
%115 = load i64, i64* %114
%116 = load i64, i64* @AF_INET6
%117 = icmp eq i64 %115, %116
br i1 %117, label %118, label %139
118: ; preds = %112
%119 = load i32, i32* @INET6_ADDRSTRLEN
%120 = zext i32 %119 to i64
%121 = call i8* @llvm.stacksave()
store i8* %121, i8** %9
%122 = alloca i8, i64 %120
store i64 %120, i64* %10
%123 = load %struct.addrinfo*, %struct.addrinfo** %5
%124 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %123, i32 0, i32 1
%125 = load i32, i32* %124
%126 = call i32 @memcpy(%struct.sockaddr_in6* %11, i32 %125, i32 8)
%127 = load i64, i64* @AF_INET6
%128 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %11, i32 0, i32 0
%129 = load i32, i32* @INET6_ADDRSTRLEN
%130 = call i32 @inet_ntop(i64 %127, i32* %128, i8* %122, i32 %129)
%131 = icmp ne i32 %130, 0
br i1 %131, label %134, label %132
132: ; preds = %118
%133 = call i32 @warn(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %137
134: ; preds = %118
%135 = load i32, i32* @INET6_ADDRSTRLEN
%136 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i32 %135, i8* %122)
br label %137
137: ; preds = %134, %132
%138 = load i8*, i8** %9
br label %141
139: ; preds = %112
%140 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0))
br label %141
141: ; preds = %139, %137
br label %142
142: ; preds = %141, %110
%143 = load %struct.addrinfo*, %struct.addrinfo** %3
%144 = call i32 @freeaddrinfo(%struct.addrinfo* %143)
%145 = bitcast %struct.sockaddr_storage* %12 to %struct.sockaddr*
store %struct.sockaddr* %145, %struct.sockaddr** %13
br label %146
146: ; preds = %184, %142
store i32 4, i32* %14
%147 = load i32, i32* %4
%148 = load %struct.sockaddr*, %struct.sockaddr** %13
%149 = call i32 @accept(i32 %147, %struct.sockaddr* %148, i32* %14)
store i32 %149, i32* %15
%150 = load i32, i32* %15
%151 = icmp eq i32 %150, -1
br i1 %151, label %152, label %188
152: ; preds = %146
%153 = load i64, i64* @errno
%154 = load i64, i64* @ENETDOWN
%155 = icmp eq i64 %153, %154
br i1 %155, label %184, label %156
156: ; preds = %152
%157 = load i64, i64* @errno
%158 = load i64, i64* @ENOPROTOOPT
%159 = icmp eq i64 %157, %158
br i1 %159, label %184, label %160
160: ; preds = %156
%161 = load i64, i64* @errno
%162 = load i64, i64* @EPROTO
%163 = icmp eq i64 %161, %162
br i1 %163, label %184, label %164
164: ; preds = %160
%165 = load i64, i64* @errno
%166 = load i64, i64* @EHOSTDOWN
%167 = icmp eq i64 %165, %166
br i1 %167, label %184, label %168
168: ; preds = %164
%169 = load i64, i64* @errno
%170 = load i64, i64* @EHOSTUNREACH
%171 = icmp eq i64 %169, %170
br i1 %171, label %184, label %172
172: ; preds = %168
%173 = load i64, i64* @errno
%174 = load i64, i64* @ENONET
%175 = icmp eq i64 %173, %174
br i1 %175, label %184, label %176
176: ; preds = %172
%177 = load i64, i64* @errno
%178 = load i64, i64* @EOPNOTSUPP
%179 = icmp eq i64 %177, %178
br i1 %179, label %184, label %180
180: ; preds = %176
%181 = load i64, i64* @errno
%182 = load i64, i64* @ENETUNREACH
%183 = icmp eq i64 %181, %182
br i1 %183, label %184, label %185
184: ; preds = %180, %176, %172, %168, %164, %160, %156, %152
br label %146
185: ; preds = %180
%186 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
br label %187
187: ; preds = %185
br label %188
188: ; preds = %187, %146
%189 = load i32, i32* %4
%190 = call i32 @close(i32 %189)
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i32, i32, i32, i32, %struct.addrinfo*, i32 }
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr_in6 = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i64 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [5 x i8] c"2233\00"
@.str.1 = [12 x i8] c"getaddrinfo\00"
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [7 x i8] c"listen\00"
@.str.5 = [14 x i8] c"no local addr\00"
@INET_ADDRSTRLEN = global i32 0
@.str.6 = [10 x i8] c"inet_ntop\00"
@.str.7 = [18 x i8] c"listening on %.*s\00"
@AF_INET6 = global i64 0
@INET6_ADDRSTRLEN = global i32 0
@errno = global i64 0
@ENETDOWN = global i64 0
@ENOPROTOOPT = global i64 0
@EPROTO = global i64 0
@EHOSTDOWN = global i64 0
@EHOSTUNREACH = global i64 0
@ENONET = global i64 0
@EOPNOTSUPP = global i64 0
@ENETUNREACH = global i64 0
@.str.9 = [7 x i8] c"accept\00"
define i32 @main() {
%1 = alloca %struct.addrinfo
%2 = alloca %struct.addrinfo*
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_storage
%5 = alloca i32
%6 = bitcast %struct.addrinfo* %1 to i8*
%7 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 0
%8 = load i64, i64* @AF_INET
store i64 %8, i64* %7
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 1
store i32 0, i32* %9
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 2
store i32 0, i32* %10
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 3
store i32 0, i32* %11
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 4
%13 = load i32, i32* @SOCK_STREAM
store i32 %13, i32* %12
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 5
store %struct.addrinfo* null, %struct.addrinfo** %14
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 6
%16 = load i32, i32* @AI_PASSIVE
store i32 %16, i32* %15
%17 = bitcast %struct.addrinfo** %2 to i8*
store %struct.addrinfo* null, %struct.addrinfo** %2
%18 = call i64 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %1, %struct.addrinfo** %2)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %0
%21 = call i32 @errx(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %0
%23 = load %struct.addrinfo*, %struct.addrinfo** %2
%24 = icmp eq %struct.addrinfo* %23, null
br i1 %24, label %59, label %25
25: ; preds = %22, %53
%26 = phi %struct.addrinfo* [ %55, %53 ], [ %23, %22 ]
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 0
%28 = load i64, i64* %27
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 4
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 3
%32 = load i32, i32* %31
%33 = call i32 @socket(i64 %28, i32 %30, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %25
%36 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %53
37: ; preds = %25
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 1
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 2
%41 = load i32, i32* %40
%42 = call i32 @bind(i32 %33, i32 %39, i32 %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %37
%45 = call i32 @warn(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%46 = call i32 @close(i32 %33)
br label %53
47: ; preds = %37
%48 = call i32 @listen(i32 %33, i32 0)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%52 = call i32 @close(i32 %33)
br label %53
53: ; preds = %47, %50, %44, %35
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 5
%55 = load %struct.addrinfo*, %struct.addrinfo** %54
%56 = icmp eq %struct.addrinfo* %55, null
br i1 %56, label %57, label %25
57: ; preds = %53
%58 = load %struct.addrinfo*, %struct.addrinfo** %2
br label %59
59: ; preds = %57, %22
%60 = phi %struct.addrinfo* [ null, %22 ], [ %58, %57 ]
%61 = phi i32 [ undef, %22 ], [ %33, %57 ]
%62 = call i32 @freeaddrinfo(%struct.addrinfo* %60)
%63 = call i32 @errx(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%64 = load i32, i32* @INET_ADDRSTRLEN
%65 = zext i32 %64 to i64
%66 = call i8* @llvm.stacksave()
%67 = alloca i8, i64 %65
%68 = bitcast %struct.sockaddr_in* %3 to i8*
%69 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr_in6*
%70 = load i32, i32* inttoptr (i64 8 to i32*)
%71 = call i32 @memcpy(%struct.sockaddr_in6* %69, i32 %70, i32 8)
%72 = load i64, i64* @AF_INET
%73 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%74 = load i32, i32* @INET_ADDRSTRLEN
%75 = call i32 @inet_ntop(i64 %72, i32* %73, i8* %67, i32 %74)
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %59
%78 = call i32 @warn(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %82
79: ; preds = %59
%80 = load i32, i32* @INET_ADDRSTRLEN
%81 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i32 %80, i8* %67)
br label %82
82: ; preds = %77, %79
%83 = load %struct.addrinfo*, %struct.addrinfo** %2
%84 = call i32 @freeaddrinfo(%struct.addrinfo* %83)
%85 = bitcast %struct.sockaddr_storage* %4 to i8*
%86 = bitcast %struct.sockaddr_storage* %4 to %struct.sockaddr*
%87 = bitcast i32* %5 to i8*
br label %88
88: ; preds = %91, %82
store i32 4, i32* %5
%89 = call i32 @accept(i32 %61, %struct.sockaddr* %86, i32* %5)
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %118
91: ; preds = %88
%92 = load i64, i64* @errno
%93 = load i64, i64* @ENETDOWN
%94 = icmp eq i64 %92, %93
%95 = load i64, i64* @ENOPROTOOPT
%96 = icmp eq i64 %92, %95
%97 = select i1 %94, i1 true, i1 %96
%98 = load i64, i64* @EPROTO
%99 = icmp eq i64 %92, %98
%100 = select i1 %97, i1 true, i1 %99
%101 = load i64, i64* @EHOSTDOWN
%102 = icmp eq i64 %92, %101
%103 = select i1 %100, i1 true, i1 %102
%104 = load i64, i64* @EHOSTUNREACH
%105 = icmp eq i64 %92, %104
%106 = select i1 %103, i1 true, i1 %105
%107 = load i64, i64* @ENONET
%108 = icmp eq i64 %92, %107
%109 = select i1 %106, i1 true, i1 %108
%110 = load i64, i64* @EOPNOTSUPP
%111 = icmp eq i64 %92, %110
%112 = select i1 %109, i1 true, i1 %111
%113 = load i64, i64* @ENETUNREACH
%114 = icmp eq i64 %92, %113
%115 = select i1 %112, i1 true, i1 %114
br i1 %115, label %88, label %116
116: ; preds = %91
%117 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
br label %118
118: ; preds = %88, %116
%119 = call i32 @close(i32 %61)
ret i32 0
}