#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ srv_addr;
typedef int socklen_t;
typedef int /*<<< orphan*/ cl_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_LOOPBACK;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int atoi(int /*<<< orphan*/);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int dup2(int, int);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int /*<<< orphan*/);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ perror(char *);
scalar_t__ pollwait(int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int const *,
                      int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int sockfd, connfd, port = -1;
  struct sockaddr_in srv_addr = {};
  int lis = 0, con = 0, fd = -1;
  const int yes = 1;
  while (1) {
    int c;
    c = getopt(argc, argv, "lcp:f:");
    if (c == -1)
      break;
    switch (c) {
    case 'l':
      lis++;
      break;
    case 'c':
      con++;
      break;
    case 'p':
      port = atoi(optarg);
      break;
    case 'f':
      fd = atoi(optarg);
      break;
    default:
      usage();
    }
  }
  if (lis && con) {
    fprintf(stderr, "vznnc"
                    ": options -l and -c are exclusive\n");
    usage();
  }
  if (!lis && !con) {
    fprintf(stderr, "vznnc"
                    ": either -l or -c is required\n");
    usage();
  }
  if (port < 0) {
    fprintf(stderr, "vznnc"
                    ": option -p is required\n");
    usage();
  }
  if (argc - optind < 1)
    usage();
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0) {
    perror("vznnc"
           ": socket()");
    return 220;
  }
  if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int))) {
    perror("vznnc"
           ": setsockopt()");
    return 220;
  }
  srv_addr.sin_family = AF_INET;
  srv_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  srv_addr.sin_port = htons(port);
  if (lis) {
    struct sockaddr_in cl_addr = {};
    socklen_t cl_len = sizeof(cl_addr);
    if (bind(sockfd, (struct sockaddr *)&srv_addr, sizeof(srv_addr)) < 0) {
      perror("vznnc"
             ": bind()");
      return 220;
    }
    if (listen(sockfd, 0) < 0) {
      perror("vznnc"
             ": listen()");
      return 220;
    }
    if (pollwait(sockfd))
      return 220;
    connfd = accept(sockfd, (struct sockaddr *)&cl_addr, &cl_len);
    if (connfd < 0) {
      perror("vznnc"
             ": accept()");
      return 220;
    }
    close(sockfd);
    sockfd = -1;
  } else {
    if (connect(sockfd, (struct sockaddr *)&srv_addr, sizeof(srv_addr)) < 0) {
      perror("vznnc"
             ": connect()");
      return 220;
    }
    connfd = sockfd;
  }
  if (fd < 0) {
    close(0);
    close(1);
    dup2(connfd, 0);
    dup2(connfd, 1);
    close(connfd);
  } else {
    if (fd != connfd) {
      close(fd);
      if (dup2(connfd, fd) != fd) {
        perror("vznnc"
               ": dup2()");
        return 220;
      }
      close(connfd);
    }
  }
  execvp(argv[optind], argv + optind);
  perror("vznnc"
         ": execvp()");
  return 127;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0xffffffff,-0x34(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdc1(%rip),%rdx
call   10f0 <getopt@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    128e <main+0x6e>
jmp    130b <main+0xeb>
mov    -0x3c(%rbp),%eax
add    $0xffffff9d,%eax
mov    %eax,%ecx
mov    %rcx,-0x58(%rbp)
sub    $0xd,%eax
ja     12ff <main+0xdf>
mov    -0x58(%rbp),%rax
lea    0xd52(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1306 <main+0xe6>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1306 <main+0xe6>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
call   1120 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1306 <main+0xe6>
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
call   1120 <atoi@plt>
mov    %eax,-0x34(%rbp)
jmp    1306 <main+0xe6>
mov    $0x0,%al
call   10c0 <usage@plt>
jmp    1269 <main+0x49>
cmpl   $0x0,-0x2c(%rbp)
je     133b <main+0x11b>
cmpl   $0x0,-0x30(%rbp)
je     133b <main+0x11b>
mov    0x2c92(%rip),%rax
mov    (%rax),%edi
lea    0xd10(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x0,%al
call   10c0 <usage@plt>
cmpl   $0x0,-0x2c(%rbp)
jne    136b <main+0x14b>
cmpl   $0x0,-0x30(%rbp)
jne    136b <main+0x14b>
mov    0x2c62(%rip),%rax
mov    (%rax),%edi
lea    0xd08(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x0,%al
call   10c0 <usage@plt>
cmpl   $0x0,-0x1c(%rbp)
jge    1391 <main+0x171>
mov    0x2c3c(%rip),%rax
mov    (%rax),%edi
lea    0xd06(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x0,%al
call   10c0 <usage@plt>
mov    -0x8(%rbp),%eax
mov    0x2c35(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x1,%eax
jge    13ad <main+0x18d>
mov    $0x0,%al
call   10c0 <usage@plt>
mov    0x2c24(%rip),%rax
mov    (%rax),%edi
mov    0x2bf3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    13eb <main+0x1cb>
lea    0xccf(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xdc,-0x4(%rbp)
jmp    1644 <main+0x424>
mov    -0x14(%rbp),%edi
mov    0x2beb(%rip),%rax
mov    (%rax),%esi
mov    0x2baa(%rip),%rax
mov    (%rax),%edx
lea    -0x38(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
je     1431 <main+0x211>
lea    0xc99(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xdc,-0x4(%rbp)
jmp    1644 <main+0x424>
mov    0x2ba0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2b84(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1540 <main+0x320>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
movl   $0xc,-0x4c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
cmp    $0x0,%rax
jge    14ad <main+0x28d>
lea    0xc31(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xdc,-0x4(%rbp)
jmp    1644 <main+0x424>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   10b0 <listen@plt>
cmp    $0x0,%rax
jge    14d9 <main+0x2b9>
lea    0xc13(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xdc,-0x4(%rbp)
jmp    1644 <main+0x424>
mov    -0x14(%rbp),%edi
call   1090 <pollwait@plt>
cmp    $0x0,%rax
je     14f7 <main+0x2d7>
movl   $0xdc,-0x4(%rbp)
jmp    1644 <main+0x424>
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x4c(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    152c <main+0x30c>
lea    0xbd0(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xdc,-0x4(%rbp)
jmp    1644 <main+0x424>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    1579 <main+0x359>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1130 <connect@plt>
cmp    $0x0,%rax
jge    1573 <main+0x353>
lea    0xb99(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xdc,-0x4(%rbp)
jmp    1644 <main+0x424>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    15b8 <main+0x398>
xor    %edi,%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   1080 <close@plt>
mov    -0x18(%rbp),%edi
xor    %esi,%esi
call   1050 <dup2@plt>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   1050 <dup2@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
jmp    1605 <main+0x3e5>
mov    -0x34(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1600 <main+0x3e0>
mov    -0x34(%rbp),%edi
call   1080 <close@plt>
mov    -0x18(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1050 <dup2@plt>
cmp    -0x34(%rbp),%eax
je     15f8 <main+0x3d8>
lea    0xb25(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xdc,-0x4(%rbp)
jmp    1644 <main+0x424>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
jmp    1605 <main+0x3e5>
mov    -0x10(%rbp),%rax
mov    0x29c0(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rsi
mov    0x29ae(%rip),%rax
movslq (%rax),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1110 <execvp@plt>
lea    0xae2(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x7f,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%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,%r12
mov    %edi,%ebp
movl   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
movl   $0x1,0x24(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xded(%rip),%rbx
lea    0xdae(%rip),%r15
xor    %r13d,%r13d
xor    %r14d,%r14d
movl   $0xffffffff,0x8(%rsp)
ff
jmp    127c <main+0x6c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0xffffffff,%eax
je     12ce <main+0xbe>
xor    %eax,%eax
call   10b0 <usage@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10e0 <getopt@plt>
lea    -0x63(%rax),%ecx
cmp    $0xd,%ecx
ja     1270 <main+0x60>
movslq (%r15,%rcx,4),%rax
add    %r15,%rax
jmp    *%rax
add    $0x1,%r14d
jmp    127c <main+0x6c>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
call   1110 <atoi@plt>
mov    %eax,0x8(%rsp)
jmp    127c <main+0x6c>
add    $0x1,%r13d
jmp    127c <main+0x6c>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
call   1110 <atoi@plt>
mov    %eax,0xc(%rsp)
jmp    127c <main+0x6c>
test   %r13d,%r13d
je     12f4 <main+0xe4>
test   %r14d,%r14d
je     12f4 <main+0xe4>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
lea    0xd57(%rip),%rsi
call   1090 <fprintf@plt>
xor    %eax,%eax
call   10b0 <usage@plt>
or     %r13d,%r14d
mov    0xc(%rsp),%ebx
jne    1319 <main+0x109>
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
lea    0xd5a(%rip),%rsi
call   1090 <fprintf@plt>
xor    %eax,%eax
call   10b0 <usage@plt>
test   %ebx,%ebx
jns    1339 <main+0x129>
mov    0x2c94(%rip),%rax
mov    (%rax),%edi
lea    0xd5e(%rip),%rsi
call   1090 <fprintf@plt>
xor    %eax,%eax
call   10b0 <usage@plt>
mov    0x2c90(%rip),%r14
cmp    %ebp,(%r14)
jl     134c <main+0x13c>
xor    %eax,%eax
call   10b0 <usage@plt>
mov    0x2c85(%rip),%r15
mov    (%r15),%edi
mov    0x2c53(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
test   %eax,%eax
js     142d <main+0x21d>
mov    %eax,%ebp
mov    0x2c69(%rip),%rax
mov    (%rax),%esi
mov    0x2c28(%rip),%rax
mov    (%rax),%edx
lea    0x24(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
jne    1436 <main+0x226>
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    0x2c1d(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    %ebx,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
test   %r13d,%r13d
je     143f <main+0x22f>
movl   $0x0,0x30(%rsp)
movq   $0x0,0x28(%rsp)
movl   $0xc,0x20(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10c0 <bind@plt>
test   %rax,%rax
js     145e <main+0x24e>
mov    %ebp,%edi
xor    %esi,%esi
call   10a0 <listen@plt>
test   %rax,%rax
js     1467 <main+0x257>
mov    %ebp,%edi
call   1080 <pollwait@plt>
test   %rax,%rax
jne    1473 <main+0x263>
lea    0x28(%rsp),%rsi
lea    0x20(%rsp),%rdx
mov    %ebp,%edi
call   10f0 <accept@plt>
test   %eax,%eax
jns    1487 <main+0x277>
lea    0xcc0(%rip),%rdi
jmp    146e <main+0x25e>
lea    0xc75(%rip),%rdi
jmp    146e <main+0x25e>
lea    0xc7c(%rip),%rdi
jmp    146e <main+0x25e>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   1120 <connect@plt>
test   %rax,%rax
jns    1494 <main+0x284>
lea    0xc9f(%rip),%rdi
jmp    146e <main+0x25e>
lea    0xc68(%rip),%rdi
jmp    146e <main+0x25e>
lea    0xc6d(%rip),%rdi
call   10d0 <perror@plt>
mov    $0xdc,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r15d
mov    %ebp,%edi
call   1070 <close@plt>
mov    %r15d,%ebp
mov    0x8(%rsp),%ebx
test   %ebx,%ebx
jns    14c4 <main+0x2b4>
xor    %edi,%edi
call   1070 <close@plt>
mov    $0x1,%edi
call   1070 <close@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <dup2@plt>
mov    %ebp,%edi
mov    $0x1,%esi
call   1050 <dup2@plt>
jmp    14dc <main+0x2cc>
cmp    %ebp,%ebx
je     14e3 <main+0x2d3>
mov    %ebx,%edi
call   1070 <close@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1050 <dup2@plt>
cmp    %ebx,%eax
jne    1509 <main+0x2f9>
mov    %ebp,%edi
call   1070 <close@plt>
movslq (%r14),%rax
lea    (%r12,%rax,8),%rsi
mov    (%r12,%rax,8),%rdi
call   1100 <execvp@plt>
lea    0xc20(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x7f,%eax
jmp    1478 <main+0x268>
lea    0xbfc(%rip),%rdi
jmp    146e <main+0x25e>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"lcp:f:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [40 x i8] c"vznnc: options -l and -c are exclusive\0A\00"
@.str.2 = [36 x i8] c"vznnc: either -l or -c is required\0A\00"
@.str.3 = [30 x i8] c"vznnc: option -p is required\0A\00"
@optind = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [16 x i8] c"vznnc: socket()\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.5 = [20 x i8] c"vznnc: setsockopt()\00"
@INADDR_LOOPBACK = global i32 0
@.str.6 = [14 x i8] c"vznnc: bind()\00"
@.str.7 = [16 x i8] c"vznnc: listen()\00"
@.str.8 = [16 x i8] c"vznnc: accept()\00"
@.str.9 = [17 x i8] c"vznnc: connect()\00"
@.str.10 = [14 x i8] c"vznnc: dup2()\00"
@.str.11 = [16 x i8] c"vznnc: execvp()\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.sockaddr_in
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %8
%17 = bitcast %struct.sockaddr_in* %9 to i8*
store i32 0, i32* %10
store i32 0, i32* %11
store i32 -1, i32* %12
store i32 1, i32* %13
br label %18
18: ; preds = %2, %41
%19 = load i32, i32* %4
%20 = load i8**, i8*** %5
%21 = call i32 @getopt(i32 %19, i8** %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %21, i32* %14
%22 = load i32, i32* %14
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %25
24: ; preds = %18
br label %42
25: ; preds = %18
%26 = load i32, i32* %14
switch i32 %26, label %39 [
i32 108, label %27
i32 99, label %30
i32 112, label %33
i32 102, label %36
]
27: ; preds = %25
%28 = load i32, i32* %10
%29 = add nsw i32 %28, 1
store i32 %29, i32* %10
br label %41
30: ; preds = %25
%31 = load i32, i32* %11
%32 = add nsw i32 %31, 1
store i32 %32, i32* %11
br label %41
33: ; preds = %25
%34 = load i32, i32* @optarg
%35 = call i32 @atoi(i32 %34)
store i32 %35, i32* %8
br label %41
36: ; preds = %25
%37 = load i32, i32* @optarg
%38 = call i32 @atoi(i32 %37)
store i32 %38, i32* %12
br label %41
39: ; preds = %25
%40 = call i32 (...) @usage()
br label %41
41: ; preds = %39, %36, %33, %30, %27
br label %18
42: ; preds = %24
%43 = load i32, i32* %10
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %52
45: ; preds = %42
%46 = load i32, i32* %11
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %45
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%51 = call i32 (...) @usage()
br label %52
52: ; preds = %48, %45, %42
%53 = load i32, i32* %10
%54 = icmp ne i32 %53, 0
br i1 %54, label %62, label %55
55: ; preds = %52
%56 = load i32, i32* %11
%57 = icmp ne i32 %56, 0
br i1 %57, label %62, label %58
58: ; preds = %55
%59 = load i32, i32* @stderr
%60 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%61 = call i32 (...) @usage()
br label %62
62: ; preds = %58, %55, %52
%63 = load i32, i32* %8
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %62
%66 = load i32, i32* @stderr
%67 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%68 = call i32 (...) @usage()
br label %69
69: ; preds = %65, %62
%70 = load i32, i32* %4
%71 = load i32, i32* @optind
%72 = sub nsw i32 %70, %71
%73 = icmp slt i32 %72, 1
br i1 %73, label %74, label %76
74: ; preds = %69
%75 = call i32 (...) @usage()
br label %76
76: ; preds = %74, %69
%77 = load i32, i32* @AF_INET
%78 = load i32, i32* @SOCK_STREAM
%79 = call i32 @socket(i32 %77, i32 %78, i32 0)
store i32 %79, i32* %6
%80 = load i32, i32* %6
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %76
%83 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
store i32 220, i32* %3
br label %185
84: ; preds = %76
%85 = load i32, i32* %6
%86 = load i32, i32* @SOL_SOCKET
%87 = load i32, i32* @SO_REUSEADDR
%88 = call i64 @setsockopt(i32 %85, i32 %86, i32 %87, i32* %13, i32 4)
%89 = icmp ne i64 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %84
%91 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
store i32 220, i32* %3
br label %185
92: ; preds = %84
%93 = load i32, i32* @AF_INET
%94 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %93, i32* %94
%95 = load i32, i32* @INADDR_LOOPBACK
%96 = call i32 @htonl(i32 %95)
%97 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%98 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %97, i32 0, i32 0
store i32 %96, i32* %98
%99 = load i32, i32* %8
%100 = call i32 @htons(i32 %99)
%101 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %100, i32* %101
%102 = load i32, i32* %10
%103 = icmp ne i32 %102, 0
br i1 %103, label %104, label %134
104: ; preds = %92
%105 = bitcast %struct.sockaddr_in* %15 to i8*
store i32 12, i32* %16
%106 = load i32, i32* %6
%107 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%108 = call i64 @bind(i32 %106, %struct.sockaddr* %107, i32 12)
%109 = icmp slt i64 %108, 0
br i1 %109, label %110, label %112
110: ; preds = %104
%111 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
store i32 220, i32* %3
br label %185
112: ; preds = %104
%113 = load i32, i32* %6
%114 = call i64 @listen(i32 %113, i32 0)
%115 = icmp slt i64 %114, 0
br i1 %115, label %116, label %118
116: ; preds = %112
%117 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
store i32 220, i32* %3
br label %185
118: ; preds = %112
%119 = load i32, i32* %6
%120 = call i64 @pollwait(i32 %119)
%121 = icmp ne i64 %120, 0
br i1 %121, label %122, label %123
122: ; preds = %118
store i32 220, i32* %3
br label %185
123: ; preds = %118
%124 = load i32, i32* %6
%125 = bitcast %struct.sockaddr_in* %15 to %struct.sockaddr*
%126 = call i32 @accept(i32 %124, %struct.sockaddr* %125, i32* %16)
store i32 %126, i32* %7
%127 = load i32, i32* %7
%128 = icmp slt i32 %127, 0
br i1 %128, label %129, label %131
129: ; preds = %123
%130 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
store i32 220, i32* %3
br label %185
131: ; preds = %123
%132 = load i32, i32* %6
%133 = call i32 @close(i32 %132)
store i32 -1, i32* %6
br label %143
134: ; preds = %92
%135 = load i32, i32* %6
%136 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%137 = call i64 @connect(i32 %135, %struct.sockaddr* %136, i32 12)
%138 = icmp slt i64 %137, 0
br i1 %138, label %139, label %141
139: ; preds = %134
%140 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
store i32 220, i32* %3
br label %185
141: ; preds = %134
%142 = load i32, i32* %6
store i32 %142, i32* %7
br label %143
143: ; preds = %141, %131
%144 = load i32, i32* %12
%145 = icmp slt i32 %144, 0
br i1 %145, label %146, label %155
146: ; preds = %143
%147 = call i32 @close(i32 0)
%148 = call i32 @close(i32 1)
%149 = load i32, i32* %7
%150 = call i32 @dup2(i32 %149, i32 0)
%151 = load i32, i32* %7
%152 = call i32 @dup2(i32 %151, i32 1)
%153 = load i32, i32* %7
%154 = call i32 @close(i32 %153)
br label %173
155: ; preds = %143
%156 = load i32, i32* %12
%157 = load i32, i32* %7
%158 = icmp ne i32 %156, %157
br i1 %158, label %159, label %172
159: ; preds = %155
%160 = load i32, i32* %12
%161 = call i32 @close(i32 %160)
%162 = load i32, i32* %7
%163 = load i32, i32* %12
%164 = call i32 @dup2(i32 %162, i32 %163)
%165 = load i32, i32* %12
%166 = icmp ne i32 %164, %165
br i1 %166, label %167, label %169
167: ; preds = %159
%168 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0))
store i32 220, i32* %3
br label %185
169: ; preds = %159
%170 = load i32, i32* %7
%171 = call i32 @close(i32 %170)
br label %172
172: ; preds = %169, %155
br label %173
173: ; preds = %172, %146
%174 = load i8**, i8*** %5
%175 = load i32, i32* @optind
%176 = sext i32 %175 to i64
%177 = getelementptr inbounds i8*, i8** %174, i64 %176
%178 = load i8*, i8** %177
%179 = load i8**, i8*** %5
%180 = load i32, i32* @optind
%181 = sext i32 %180 to i64
%182 = getelementptr inbounds i8*, i8** %179, i64 %181
%183 = call i32 @execvp(i8* %178, i8** %182)
%184 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
store i32 127, i32* %3
br label %185
185: ; preds = %173, %167, %139, %129, %122, %116, %110, %90, %82
%186 = load i32, i32* %3
ret i32 %186
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"lcp:f:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [40 x i8] c"vznnc: options -l and -c are exclusive\0A\00"
@.str.2 = [36 x i8] c"vznnc: either -l or -c is required\0A\00"
@.str.3 = [30 x i8] c"vznnc: option -p is required\0A\00"
@optind = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [16 x i8] c"vznnc: socket()\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.5 = [20 x i8] c"vznnc: setsockopt()\00"
@INADDR_LOOPBACK = global i32 0
@.str.6 = [14 x i8] c"vznnc: bind()\00"
@.str.7 = [16 x i8] c"vznnc: listen()\00"
@.str.8 = [16 x i8] c"vznnc: accept()\00"
@.str.9 = [17 x i8] c"vznnc: connect()\00"
@.str.10 = [14 x i8] c"vznnc: dup2()\00"
@.str.11 = [16 x i8] c"vznnc: execvp()\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast i32* %4 to i8*
store i32 1, i32* %4
br label %9
9: ; preds = %29, %2
%10 = phi i32 [ %31, %29 ], [ -1, %2 ]
%11 = phi i32 [ %15, %29 ], [ 0, %2 ]
%12 = phi i32 [ %19, %29 ], [ 0, %2 ]
%13 = phi i32 [ %22, %29 ], [ -1, %2 ]
br label %14
14: ; preds = %9, %25
%15 = phi i32 [ %11, %9 ], [ %26, %25 ]
%16 = phi i32 [ %12, %9 ], [ %19, %25 ]
%17 = phi i32 [ %13, %9 ], [ %22, %25 ]
br label %18
18: ; preds = %14, %27
%19 = phi i32 [ %16, %14 ], [ %28, %27 ]
%20 = phi i32 [ %17, %14 ], [ %22, %27 ]
br label %21
21: ; preds = %18, %32
%22 = phi i32 [ %20, %18 ], [ %34, %32 ]
br label %23
23: ; preds = %21, %35
%24 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
switch i32 %24, label %35 [
i32 -1, label %37
i32 108, label %25
i32 99, label %27
i32 112, label %29
i32 102, label %32
]
25: ; preds = %23
%26 = add nsw i32 %15, 1
br label %14
27: ; preds = %23
%28 = add nsw i32 %19, 1
br label %18
29: ; preds = %23
%30 = load i32, i32* @optarg
%31 = tail call i32 @atoi(i32 %30)
br label %9
32: ; preds = %23
%33 = load i32, i32* @optarg
%34 = tail call i32 @atoi(i32 %33)
br label %21
35: ; preds = %23
%36 = tail call i32 (...) @usage()
br label %23
37: ; preds = %23
%38 = icmp ne i32 %15, 0
%39 = icmp ne i32 %19, 0
%40 = select i1 %38, i1 %39, i1 false
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = tail call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%44 = tail call i32 (...) @usage()
br label %45
45: ; preds = %41, %37
%46 = select i1 %38, i1 true, i1 %39
br i1 %46, label %51, label %47
47: ; preds = %45
%48 = load i32, i32* @stderr
%49 = tail call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%50 = tail call i32 (...) @usage()
br label %51
51: ; preds = %47, %45
%52 = icmp slt i32 %10, 0
br i1 %52, label %53, label %57
53: ; preds = %51
%54 = load i32, i32* @stderr
%55 = tail call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%56 = tail call i32 (...) @usage()
br label %57
57: ; preds = %53, %51
%58 = load i32, i32* @optind
%59 = icmp slt i32 %58, %0
br i1 %59, label %62, label %60
60: ; preds = %57
%61 = tail call i32 (...) @usage()
br label %62
62: ; preds = %60, %57
%63 = load i32, i32* @AF_INET
%64 = load i32, i32* @SOCK_STREAM
%65 = tail call i32 @socket(i32 %63, i32 %64, i32 0)
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %62
%68 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %137
69: ; preds = %62
%70 = load i32, i32* @SOL_SOCKET
%71 = load i32, i32* @SO_REUSEADDR
%72 = call i64 @setsockopt(i32 %65, i32 %70, i32 %71, i32* %4, i32 4)
%73 = icmp eq i64 %72, 0
br i1 %73, label %76, label %74
74: ; preds = %69
%75 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %137
76: ; preds = %69
%77 = load i32, i32* @AF_INET
%78 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %77, i32* %78
%79 = load i32, i32* @INADDR_LOOPBACK
%80 = call i32 @htonl(i32 %79)
%81 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %80, i32* %81
%82 = call i32 @htons(i32 %10)
%83 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %82, i32* %83
br i1 %38, label %84, label %106
84: ; preds = %76
%85 = bitcast %struct.sockaddr_in* %5 to i8*
%86 = bitcast i32* %6 to i8*
store i32 12, i32* %6
%87 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%88 = call i64 @bind(i32 %65, %struct.sockaddr* %87, i32 12)
%89 = icmp slt i64 %88, 0
br i1 %89, label %100, label %90
90: ; preds = %84
%91 = call i64 @listen(i32 %65, i32 0)
%92 = icmp slt i64 %91, 0
br i1 %92, label %100, label %93
93: ; preds = %90
%94 = call i64 @pollwait(i32 %65)
%95 = icmp eq i64 %94, 0
br i1 %95, label %96, label %103
96: ; preds = %93
%97 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%98 = call i32 @accept(i32 %65, %struct.sockaddr* %97, i32* %6)
%99 = icmp slt i32 %98, 0
br i1 %99, label %100, label %104
100: ; preds = %96, %90, %84
%101 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), %84 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), %90 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), %96 ]
%102 = call i32 @perror(i8* %101)
br label %103
103: ; preds = %100, %93
br label %137
104: ; preds = %96
%105 = call i32 @close(i32 %65)
br label %112
106: ; preds = %76
%107 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%108 = call i64 @connect(i32 %65, %struct.sockaddr* %107, i32 12)
%109 = icmp slt i64 %108, 0
br i1 %109, label %110, label %112
110: ; preds = %106
%111 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
br label %137
112: ; preds = %104, %106
%113 = phi i32 [ %98, %104 ], [ %65, %106 ]
%114 = icmp slt i32 %22, 0
br i1 %114, label %115, label %120
115: ; preds = %112
%116 = call i32 @close(i32 0)
%117 = call i32 @close(i32 1)
%118 = call i32 @dup2(i32 %113, i32 0)
%119 = call i32 @dup2(i32 %113, i32 1)
br label %128
120: ; preds = %112
%121 = icmp eq i32 %22, %113
br i1 %121, label %130, label %122
122: ; preds = %120
%123 = call i32 @close(i32 %22)
%124 = call i32 @dup2(i32 %113, i32 %22)
%125 = icmp eq i32 %124, %22
br i1 %125, label %128, label %126
126: ; preds = %122
%127 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0))
br label %137
128: ; preds = %122, %115
%129 = call i32 @close(i32 %113)
br label %130
130: ; preds = %128, %120
%131 = load i32, i32* @optind
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds i8*, i8** %1, i64 %132
%134 = load i8*, i8** %133
%135 = call i32 @execvp(i8* %134, i8** %133)
%136 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
br label %137
137: ; preds = %103, %130, %126, %110, %74, %67
%138 = phi i32 [ 220, %67 ], [ 220, %74 ], [ 127, %130 ], [ 220, %126 ], [ 220, %110 ], [ 220, %103 ]
ret i32 %138
}