#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 {
  int dummy;
};
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;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ hints;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int AI_NUMERICSERV;
int AI_PASSIVE;
scalar_t__ ECONNABORTED;
scalar_t__ EINTR;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *gai_strerror(int);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int getopt(int, char **, char *);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
char *optarg;
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int main(int argc, char **argv) {
  char *listen_port = "9004";
  int opt;
  while ((opt = getopt(argc, argv, "l:")) != -1) {
    switch (opt) {
    case 'l':
      listen_port = optarg;
      break;
    default:
      fprintf(stderr, "usage: %s [-l listen_port]\n",
              argv[0] ? argv[0] : "nc_listen");
      return -1;
    }
  }
  struct addrinfo hints;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_NUMERICSERV | AI_PASSIVE;
  struct addrinfo *ai_bind;
  int r = getaddrinfo(NULL, listen_port, &hints, &ai_bind);
  if (r) {
    fprintf(stderr, "getaddrinfo: %s \n", gai_strerror(r));
    return -1;
  }
  int sock =
      socket(ai_bind->ai_family, ai_bind->ai_socktype, ai_bind->ai_protocol);
  if (sock < 0) {
    fprintf(stderr, "socket: %s\n", strerror(errno));
    return -1;
  }
  int bret = bind(sock, ai_bind->ai_addr, ai_bind->ai_addrlen);
  if (bret < 0) {
    fprintf(stderr, "bind: %d %s\n", bret, strerror(errno));
    return -1;
  }
  if (listen(sock, 0xF) < 0) {
    fprintf(stderr, "listen: %s\n", strerror(errno));
    return -1;
  }
  for (;;) {
    struct sockaddr_storage addr;
    socklen_t addr_len = sizeof(addr);
    int con = accept(sock, (struct sockaddr *)&addr, &addr_len);
    if (con < 0) {
      if (errno == ECONNABORTED || errno == EINTR) {
        errno = 0;
        continue;
      } else {
        fprintf(stderr, "accept: %s\n", strerror(errno));
      }
    }
    printf("got connection.\n");
    close(con);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe20(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe13(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     1287 <main+0xc7>
mov    -0x1c(%rbp),%eax
sub    $0x6c,%eax
jne    1227 <main+0x67>
jmp    1214 <main+0x54>
mov    0x2ddd(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1282 <main+0xc2>
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1251 <main+0x91>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x68(%rbp)
jmp    1261 <main+0xa1>
lea    0xdcc(%rip),%rax
mov    %rax,-0x68(%rbp)
jmp    1261 <main+0xa1>
mov    -0x5c(%rbp),%edi
mov    -0x68(%rbp),%rdx
lea    0xd99(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f2 <main+0x332>
jmp    11e4 <main+0x24>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    0x2d32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d3a(%rip),%rax
mov    (%rax),%eax
mov    0x2d19(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   10c0 <getaddrinfo@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     131a <main+0x15a>
mov    0x2cd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x44(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    -0x6c(%rbp),%edi
mov    %rax,%rdx
lea    0xd27(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f2 <main+0x332>
mov    -0x40(%rbp),%rax
mov    0x14(%rax),%edi
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%esi
mov    -0x40(%rbp),%rax
mov    0xc(%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jge    137c <main+0x1bc>
mov    0x2c78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
mov    0x2c5c(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    -0x70(%rbp),%edi
mov    %rax,%rdx
lea    0xcd7(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f2 <main+0x332>
mov    -0x48(%rbp),%edi
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%esi
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%edx
call   1090 <bind@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    13e3 <main+0x223>
mov    0x2c1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    0x2bf8(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    -0x78(%rbp),%edi
mov    -0x74(%rbp),%edx
mov    %rax,%rcx
lea    0xc7c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f2 <main+0x332>
mov    -0x48(%rbp),%edi
mov    $0xf,%esi
call   1080 <listen@plt>
cmp    $0x0,%rax
jge    1435 <main+0x275>
mov    0x2bbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    0x2ba3(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    -0x7c(%rbp),%edi
mov    %rax,%rdx
lea    0xc37(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f2 <main+0x332>
jmp    143a <main+0x27a>
movl   $0x4,-0x54(%rbp)
mov    -0x48(%rbp),%edi
lea    -0x50(%rbp),%rsi
lea    -0x54(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x58(%rbp)
jge    14d9 <main+0x319>
mov    0x2b4b(%rip),%rax
mov    (%rax),%rax
mov    0x2b31(%rip),%rcx
cmp    (%rcx),%rax
je     1492 <main+0x2d2>
mov    0x2b31(%rip),%rax
mov    (%rax),%rax
mov    0x2b1f(%rip),%rcx
cmp    (%rcx),%rax
jne    14a5 <main+0x2e5>
mov    0x2b17(%rip),%rax
movq   $0x0,(%rax)
jmp    143a <main+0x27a>
mov    0x2b14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x80(%rbp)
mov    0x2af8(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    -0x80(%rbp),%edi
mov    %rax,%rdx
lea    0xb98(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    14d9 <main+0x319>
lea    0xb91(%rip),%rdi
call   1030 <printf@plt>
mov    -0x58(%rbp),%edi
call   1060 <close@plt>
jmp    143a <main+0x27a>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0xe26(%rip),%r14
lea    0xe24(%rip),%r15
mov    0x2e10(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   10a0 <getopt@plt>
cmp    $0x6c,%eax
jne    1208 <main+0x48>
mov    (%r12),%r14
jmp    11f0 <main+0x30>
cmp    $0xffffffff,%eax
jne    1285 <main+0xc5>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x34(%rsp)
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
mov    0x2dae(%rip),%rax
mov    0x2d8f(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0x20(%rsp)
lea    0x10(%rsp),%rcx
xor    %edi,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   10c0 <getaddrinfo@plt>
test   %eax,%eax
je     12c2 <main+0x102>
mov    0x2d52(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xdb0(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
jmp    12a7 <main+0xe7>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rax
test   %rax,%rax
lea    0xd88(%rip),%rdx
cmovne %rax,%rdx
lea    0xd61(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%rsp),%rax
mov    0x14(%rax),%edi
mov    0xc(%rax),%edx
mov    0x10(%rax),%esi
call   10e0 <socket@plt>
test   %eax,%eax
js     13b7 <main+0x1f7>
mov    %eax,%r13d
mov    0x10(%rsp),%rax
mov    0x4(%rax),%edx
mov    0x8(%rax),%esi
mov    %r13d,%edi
call   1090 <bind@plt>
test   %eax,%eax
js     13db <main+0x21b>
mov    %r13d,%edi
mov    $0xf,%esi
call   1080 <listen@plt>
test   %rax,%rax
js     140f <main+0x24f>
lea    0x18(%rsp),%r14
lea    0xc(%rsp),%r15
mov    0x2c8e(%rip),%rbx
mov    0x2c77(%rip),%r12
mov    %r13d,0x8(%rsp)
jmp    137d <main+0x1bd>
mov    %r15,%r13
mov    %r14,%r15
mov    %r12,%r14
mov    0x2c80(%rip),%rax
mov    (%rax),%r12d
call   10d0 <strerror@plt>
mov    %r12d,%edi
mov    %r14,%r12
mov    %r15,%r14
mov    %r13,%r15
mov    0x8(%rsp),%r13d
lea    0xd05(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xd00(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1060 <close@plt>
movl   $0x4,0xc(%rsp)
mov    %r13d,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10b0 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    136a <main+0x1aa>
mov    (%rbx),%rdi
cmp    (%r12),%rdi
je     13ae <main+0x1ee>
mov    0x2bff(%rip),%rax
cmp    (%rax),%rdi
jne    1330 <main+0x170>
movq   $0x0,(%rbx)
jmp    137d <main+0x1bd>
mov    0x2c02(%rip),%rax
mov    (%rax),%ebx
mov    0x2be9(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
lea    0xc6a(%rip),%rsi
jmp    127e <main+0xbe>
mov    %eax,%ebp
mov    0x2bdc(%rip),%rax
mov    (%rax),%ebx
mov    0x2bc3(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
lea    0xc50(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12ae <main+0xee>
mov    0x2baa(%rip),%rax
mov    (%rax),%ebx
mov    0x2b91(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
lea    0xc2b(%rip),%rsi
jmp    127e <main+0xbe>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"9004\00"
@.str.1 = [3 x i8] c"l:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.2 = [28 x i8] c"usage: %s [-l listen_port]\0A\00"
@.str.3 = [10 x i8] c"nc_listen\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AI_NUMERICSERV = global i32 0
@AI_PASSIVE = global i32 0
@.str.4 = [18 x i8] c"getaddrinfo: %s \0A\00"
@.str.5 = [12 x i8] c"socket: %s\0A\00"
@errno = global i64 0
@.str.6 = [13 x i8] c"bind: %d %s\0A\00"
@.str.7 = [12 x i8] c"listen: %s\0A\00"
@ECONNABORTED = global i64 0
@EINTR = global i64 0
@.str.8 = [12 x i8] c"accept: %s\0A\00"
@.str.9 = [17 x i8] c"got connection.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.addrinfo
%9 = alloca %struct.addrinfo*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.sockaddr_storage
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %6
br label %16
16: ; preds = %39, %2
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call i32 @getopt(i32 %17, i8** %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %19, i32* %7
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %40
21: ; preds = %16
%22 = load i32, i32* %7
switch i32 %22, label %25 [
i32 108, label %23
]
23: ; preds = %21
%24 = load i8*, i8** @optarg
store i8* %24, i8** %6
br label %39
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %35
31: ; preds = %25
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
br label %36
35: ; preds = %25
br label %36
36: ; preds = %35, %31
%37 = phi i8* [ %34, %31 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), %35 ]
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %37)
store i32 -1, i32* %3
br label %129
39: ; preds = %23
br label %16
40: ; preds = %16
%41 = call i32 @memset(%struct.addrinfo* %8, i32 0, i32 24)
%42 = load i32, i32* @AF_INET
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 5
store i32 %42, i32* %43
%44 = load i32, i32* @SOCK_STREAM
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 4
store i32 %44, i32* %45
%46 = load i32, i32* @AI_NUMERICSERV
%47 = load i32, i32* @AI_PASSIVE
%48 = or i32 %46, %47
%49 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 0
store i32 %48, i32* %49
%50 = load i8*, i8** %6
%51 = call i32 @getaddrinfo(i32* null, i8* %50, %struct.addrinfo* %8, %struct.addrinfo** %9)
store i32 %51, i32* %10
%52 = load i32, i32* %10
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %40
%55 = load i32, i32* @stderr
%56 = load i32, i32* %10
%57 = call i8* @gai_strerror(i32 %56)
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %57)
store i32 -1, i32* %3
br label %129
59: ; preds = %40
%60 = load %struct.addrinfo*, %struct.addrinfo** %9
%61 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i32 0, i32 5
%62 = load i32, i32* %61
%63 = load %struct.addrinfo*, %struct.addrinfo** %9
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %63, i32 0, i32 4
%65 = load i32, i32* %64
%66 = load %struct.addrinfo*, %struct.addrinfo** %9
%67 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %66, i32 0, i32 3
%68 = load i32, i32* %67
%69 = call i32 @socket(i32 %62, i32 %65, i32 %68)
store i32 %69, i32* %11
%70 = load i32, i32* %11
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %77
72: ; preds = %59
%73 = load i32, i32* @stderr
%74 = load i64, i64* @errno
%75 = call i8* @strerror(i64 %74)
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %75)
store i32 -1, i32* %3
br label %129
77: ; preds = %59
%78 = load i32, i32* %11
%79 = load %struct.addrinfo*, %struct.addrinfo** %9
%80 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %79, i32 0, i32 2
%81 = load i32, i32* %80
%82 = load %struct.addrinfo*, %struct.addrinfo** %9
%83 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %82, i32 0, i32 1
%84 = load i32, i32* %83
%85 = call i32 @bind(i32 %78, i32 %81, i32 %84)
store i32 %85, i32* %12
%86 = load i32, i32* %12
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %94
88: ; preds = %77
%89 = load i32, i32* @stderr
%90 = load i32, i32* %12
%91 = load i64, i64* @errno
%92 = call i8* @strerror(i64 %91)
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %90, i8* %92)
store i32 -1, i32* %3
br label %129
94: ; preds = %77
%95 = load i32, i32* %11
%96 = call i64 @listen(i32 %95, i32 15)
%97 = icmp slt i64 %96, 0
br i1 %97, label %98, label %103
98: ; preds = %94
%99 = load i32, i32* @stderr
%100 = load i64, i64* @errno
%101 = call i8* @strerror(i64 %100)
%102 = call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* %101)
store i32 -1, i32* %3
br label %129
103: ; preds = %94
br label %104
104: ; preds = %125, %118, %103
store i32 4, i32* %14
%105 = load i32, i32* %11
%106 = bitcast %struct.sockaddr_storage* %13 to %struct.sockaddr*
%107 = call i32 @accept(i32 %105, %struct.sockaddr* %106, i32* %14)
store i32 %107, i32* %15
%108 = load i32, i32* %15
%109 = icmp slt i32 %108, 0
br i1 %109, label %110, label %125
110: ; preds = %104
%111 = load i64, i64* @errno
%112 = load i64, i64* @ECONNABORTED
%113 = icmp eq i64 %111, %112
br i1 %113, label %118, label %114
114: ; preds = %110
%115 = load i64, i64* @errno
%116 = load i64, i64* @EINTR
%117 = icmp eq i64 %115, %116
br i1 %117, label %118, label %119
118: ; preds = %114, %110
store i64 0, i64* @errno
br label %104
119: ; preds = %114
%120 = load i32, i32* @stderr
%121 = load i64, i64* @errno
%122 = call i8* @strerror(i64 %121)
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %122)
br label %124
124: ; preds = %119
br label %125
125: ; preds = %124, %104
%126 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
%127 = load i32, i32* %15
%128 = call i32 @close(i32 %127)
br label %104
129: ; preds = %98, %88, %72, %54, %36
%130 = load i32, i32* %3
ret i32 %130
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"9004\00"
@.str.1 = [3 x i8] c"l:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.2 = [28 x i8] c"usage: %s [-l listen_port]\0A\00"
@.str.3 = [10 x i8] c"nc_listen\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AI_NUMERICSERV = global i32 0
@AI_PASSIVE = global i32 0
@.str.4 = [18 x i8] c"getaddrinfo: %s \0A\00"
@.str.5 = [12 x i8] c"socket: %s\0A\00"
@errno = global i64 0
@.str.6 = [13 x i8] c"bind: %d %s\0A\00"
@.str.7 = [12 x i8] c"listen: %s\0A\00"
@ECONNABORTED = global i64 0
@EINTR = global i64 0
@.str.8 = [12 x i8] c"accept: %s\0A\00"
@str = [16 x i8] c"got connection.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca %struct.sockaddr_storage
%6 = alloca i32
br label %7
7: ; preds = %10, %2
%8 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %2 ], [ %11, %10 ]
%9 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
switch i32 %9, label %12 [
i32 -1, label %18
i32 108, label %10
]
10: ; preds = %7
%11 = load i8*, i8** @optarg
br label %7
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %1
%15 = icmp eq i8* %14, null
%16 = select i1 %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %14
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %96
18: ; preds = %7
%19 = bitcast %struct.addrinfo* %3 to i8*
%20 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 24)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 5
store i32 %21, i32* %22
%23 = load i32, i32* @SOCK_STREAM
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %23, i32* %24
%25 = load i32, i32* @AI_NUMERICSERV
%26 = load i32, i32* @AI_PASSIVE
%27 = or i32 %26, %25
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 0
store i32 %27, i32* %28
%29 = bitcast %struct.addrinfo** %4 to i8*
%30 = call i32 @getaddrinfo(i32* null, i8* %8, %struct.addrinfo* %3, %struct.addrinfo** %4)
%31 = icmp eq i32 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %18
%33 = load i32, i32* @stderr
%34 = call i8* @gai_strerror(i32 %30)
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %34)
br label %95
36: ; preds = %18
%37 = load %struct.addrinfo*, %struct.addrinfo** %4
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i64 0, i32 5
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i64 0, i32 4
%41 = load i32, i32* %40
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i64 0, i32 3
%43 = load i32, i32* %42
%44 = call i32 @socket(i32 %39, i32 %41, i32 %43)
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %36
%47 = load i32, i32* @stderr
%48 = load i64, i64* @errno
%49 = call i8* @strerror(i64 %48)
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %49)
br label %95
51: ; preds = %36
%52 = load %struct.addrinfo*, %struct.addrinfo** %4
%53 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %52, i64 0, i32 2
%54 = load i32, i32* %53
%55 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %52, i64 0, i32 1
%56 = load i32, i32* %55
%57 = call i32 @bind(i32 %44, i32 %54, i32 %56)
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %64
59: ; preds = %51
%60 = load i32, i32* @stderr
%61 = load i64, i64* @errno
%62 = call i8* @strerror(i64 %61)
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %57, i8* %62)
br label %95
64: ; preds = %51
%65 = call i64 @listen(i32 %44, i32 15)
%66 = icmp slt i64 %65, 0
br i1 %66, label %71, label %67
67: ; preds = %64
%68 = bitcast %struct.sockaddr_storage* %5 to i8*
%69 = bitcast i32* %6 to i8*
%70 = bitcast %struct.sockaddr_storage* %5 to %struct.sockaddr*
br label %76
71: ; preds = %64
%72 = load i32, i32* @stderr
%73 = load i64, i64* @errno
%74 = call i8* @strerror(i64 %73)
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* %74)
br label %95
76: ; preds = %67, %94
store i32 4, i32* %6
%77 = call i32 @accept(i32 %44, %struct.sockaddr* %70, i32* %6)
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %91
79: ; preds = %76
%80 = load i64, i64* @errno
%81 = load i64, i64* @ECONNABORTED
%82 = icmp eq i64 %80, %81
%83 = load i64, i64* @EINTR
%84 = icmp eq i64 %80, %83
%85 = select i1 %82, i1 true, i1 %84
br i1 %85, label %86, label %87
86: ; preds = %79
store i64 0, i64* @errno
br label %94
87: ; preds = %79
%88 = load i32, i32* @stderr
%89 = call i8* @strerror(i64 %80)
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %89)
br label %91
91: ; preds = %87, %76
%92 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%93 = call i32 @close(i32 %77)
br label %94
94: ; preds = %91, %86
br label %76
95: ; preds = %46, %71, %59, %32
br label %96
96: ; preds = %95, %12
ret i32 -1
}