#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 {
  TYPE_1__ sin_addr;
  void *sin_family;
  void *sin_port;
};
typedef int /*<<< orphan*/ sin;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ c;

/* Variables and functions */
void *AF_INET;
int EOF;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr_in *, size_t *);
int atoi(char *);
scalar_t__ bind(int, struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr_in *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int getopt(int, char **, char *);
void *htons(int);
int /*<<< orphan*/ inet_addr(char *);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
char *optarg;
scalar_t__ pass_message(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/,
                  int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int s;
  int c;
  int r;
  int localport = 6699;
  size_t sinsize;
  struct sockaddr_in sin;
  fd_set fds;
  char *host = "192.168.0.101";
  int port = 6699;
  while ((r = getopt(argc, argv, "hs:p:l:")) != EOF) {
    switch (r) {
    case 'l':
      localport = atoi(optarg);
      break;
    case 's':
      host = optarg;
      break;
    case 'p':
      port = atoi(optarg);
      break;
    default:
      usage();
    }
  }
  s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (s < 0) {
    perror("socket");
    exit(1);
  }
  c = 1;
  if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &c, sizeof(c)) != 0) {
    perror("setsockopt");
    exit(1);
  }
  memset(&sin, 0, sizeof(sin));
  sin.sin_port = htons(localport);
  sin.sin_family = AF_INET;
  sin.sin_addr.s_addr = INADDR_ANY;
  if (bind(s, &sin, sizeof(sin)) < 0) {
    perror("bind");
    exit(1);
  }
  if (listen(s, 1) < 0) {
    perror("listen");
    exit(1);
  }
  for (;;) {
    puts("waiting for connection");
    sinsize = sizeof(sin);
    c = accept(s, &sin, &sinsize);
    if (c < 0) {
      perror("accept");
      exit(1);
    }
    puts("got incoming connection");
    printf("connecting to client...");
    fflush(stdout);
    r = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (r < 0) {
      perror("socket");
      exit(1);
    }
    memset(&sin, 0, sizeof(sin));
    sin.sin_port = htons(port);
    sin.sin_family = AF_INET;
    sin.sin_addr.s_addr = inet_addr(host);
    if (connect(r, &sin, sizeof(sin)) < 0) {
      perror("connect");
      exit(1);
    }
    puts("connected");
    for (;;) {
      FD_ZERO(&fds);
      FD_SET(r, &fds);
      FD_SET(c, &fds);
      puts("Waiting for input");
      if (select(((r > c) ? r : c) + 1, &fds, 0, 0, 0) < 0) {
        perror("select");
        break;
      }
      if (FD_ISSET(c, &fds)) {
        if (pass_message("remote", c, r) != 0)
          break;
      }
      if (FD_ISSET(r, &fds)) {
        if (pass_message("local", r, c) != 0)
          break;
      }
    }
    close(r);
    close(c);
  }
  close(s);
  exit(0);
}


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   $0x1a2b,-0x20(%rbp)
lea    0xd6c(%rip),%rax
mov    %rax,-0x50(%rbp)
movl   $0x1a2b,-0x54(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd61(%rip),%rdx
call   1130 <getopt@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d04(%rip),%rcx
cmp    (%rcx),%eax
je     1347 <main+0xd7>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x58(%rbp)
sub    $0x6c,%eax
je     12fa <main+0x8a>
jmp    12d8 <main+0x68>
mov    -0x58(%rbp),%eax
sub    $0x70,%eax
je     1324 <main+0xb4>
jmp    12e9 <main+0x79>
mov    -0x58(%rbp),%eax
sub    $0x73,%eax
je     1311 <main+0xa1>
jmp    133b <main+0xcb>
mov    0x2cf7(%rip),%rax
mov    (%rax),%rdi
call   1150 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    1342 <main+0xd2>
mov    0x2ce0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    1342 <main+0xd2>
mov    0x2ccd(%rip),%rax
mov    (%rax),%rdi
call   1150 <atoi@plt>
mov    %eax,-0x54(%rbp)
jmp    1342 <main+0xd2>
mov    $0x0,%al
call   1100 <usage@plt>
jmp    129f <main+0x2f>
mov    0x2c5a(%rip),%rax
mov    (%rax),%edi
mov    0x2c59(%rip),%rax
mov    (%rax),%esi
mov    0x2c68(%rip),%rax
mov    (%rax),%edx
call   1190 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    138a <main+0x11a>
lea    0xc9b(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2c45(%rip),%rax
mov    (%rax),%esi
mov    0x2bf4(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
je     13d5 <main+0x165>
lea    0xc57(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1090 <memset@plt>
mov    -0x20(%rbp),%edi
call   1070 <htons@plt>
mov    %rax,-0x30(%rbp)
mov    0x2be0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2bca(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x18,%edx
call   1110 <bind@plt>
cmp    $0x0,%rax
jge    143c <main+0x1cc>
lea    0xbfb(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   10f0 <listen@plt>
cmp    $0x0,%rax
jge    1469 <main+0x1f9>
lea    0xbd3(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
jmp    146e <main+0x1fe>
lea    0xbbf(%rip),%rdi
call   1030 <puts@plt>
movq   $0x18,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1140 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    14b5 <main+0x245>
lea    0xba5(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    0xb96(%rip),%rdi
call   1030 <puts@plt>
lea    0xba2(%rip),%rdi
call   1080 <printf@plt>
mov    0x2acc(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
mov    0x2ac6(%rip),%rax
mov    (%rax),%edi
mov    0x2ac5(%rip),%rax
mov    (%rax),%esi
mov    0x2ad4(%rip),%rax
mov    (%rax),%edx
call   1190 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    151e <main+0x2ae>
lea    0xb07(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1090 <memset@plt>
mov    -0x54(%rbp),%edi
call   1070 <htons@plt>
mov    %rax,-0x30(%rbp)
mov    0x2a97(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x50(%rbp),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,-0x40(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x18,%edx
call   1170 <connect@plt>
cmp    $0x0,%rax
jge    1585 <main+0x315>
lea    0xb0c(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    0xafe(%rip),%rdi
call   1030 <puts@plt>
lea    -0x44(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
mov    -0x1c(%rbp),%edi
lea    -0x44(%rbp),%rsi
call   1180 <FD_SET@plt>
mov    -0x18(%rbp),%edi
lea    -0x44(%rbp),%rsi
call   1180 <FD_SET@plt>
lea    0xadb(%rip),%rdi
call   1030 <puts@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    15d5 <main+0x365>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
jmp    15db <main+0x36b>
mov    -0x18(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%edi
add    $0x1,%edi
lea    -0x44(%rbp),%rsi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   10d0 <select@plt>
cmp    $0x0,%rax
jge    160e <main+0x39e>
lea    0xaa2(%rip),%rdi
call   1120 <perror@plt>
jmp    168b <main+0x41b>
mov    -0x18(%rbp),%edi
lea    -0x44(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     164a <main+0x3da>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xa7c(%rip),%rdi
call   1060 <pass_message@plt>
cmp    $0x0,%rax
je     1645 <main+0x3d5>
jmp    168b <main+0x41b>
jmp    164a <main+0x3da>
mov    -0x1c(%rbp),%edi
lea    -0x44(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1686 <main+0x416>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xa47(%rip),%rdi
call   1060 <pass_message@plt>
cmp    $0x0,%rax
je     1681 <main+0x411>
jmp    168b <main+0x41b>
jmp    1686 <main+0x416>
jmp    1591 <main+0x321>
mov    -0x1c(%rbp),%edi
call   10a0 <close@plt>
mov    -0x18(%rbp),%edi
call   10a0 <close@plt>
jmp    146e <main+0x1fe>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0xd84(%rip),%rdx
call   1130 <getopt@plt>
mov    0x2d2a(%rip),%r12
cmp    (%r12),%eax
jne    12ea <main+0x7a>
lea    0xd5d(%rip),%rax
mov    %rax,0x10(%rsp)
mov    $0x1a2b,%r14d
movl   $0x1a2b,0xc(%rsp)
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
mov    0x2cea(%rip),%rax
mov    (%rax),%esi
mov    0x2cf9(%rip),%rax
mov    (%rax),%edx
call   1190 <socket@plt>
test   %eax,%eax
jns    137f <main+0x10f>
lea    0xd31(%rip),%rdi
jmp    1413 <main+0x1a3>
lea    0xd0f(%rip),%rcx
mov    %rcx,0x10(%rsp)
movl   $0x1a2b,0xc(%rsp)
mov    0x2cf3(%rip),%r13
lea    0xd02(%rip),%r15
mov    $0x1a2b,%r14d
jmp    133e <main+0xce>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1100 <usage@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1130 <getopt@plt>
cmp    (%r12),%eax
je     12b6 <main+0x46>
cmp    $0x73,%eax
je     1360 <main+0xf0>
cmp    $0x70,%eax
je     1370 <main+0x100>
cmp    $0x6c,%eax
jne    1320 <main+0xb0>
mov    0x0(%r13),%rdi
call   1150 <atoi@plt>
mov    %eax,%r14d
jmp    1327 <main+0xb7>
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%rax
mov    %rax,0x10(%rsp)
jmp    1327 <main+0xb7>
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%rdi
call   1150 <atoi@plt>
mov    %eax,0xc(%rsp)
jmp    1327 <main+0xb7>
mov    %eax,%ebx
movl   $0x1,0x8(%rsp)
mov    0x2c50(%rip),%rax
mov    (%rax),%esi
mov    0x2bff(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
jne    140c <main+0x19c>
lea    0x28(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1090 <memset@plt>
mov    %r14d,%edi
call   1070 <htons@plt>
mov    %rax,0x38(%rsp)
mov    0x2bfe(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x30(%rsp)
mov    0x2be7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x18,%edx
call   1110 <bind@plt>
test   %rax,%rax
jns    1422 <main+0x1b2>
lea    0xc1e(%rip),%rdi
jmp    1413 <main+0x1a3>
lea    0xc0a(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   10f0 <listen@plt>
test   %rax,%rax
jns    143c <main+0x1cc>
lea    0xbf3(%rip),%rdi
jmp    1413 <main+0x1a3>
lea    0xbf1(%rip),%rdi
call   1030 <puts@plt>
movq   $0x18,0x18(%rsp)
lea    0x28(%rsp),%rsi
lea    0x18(%rsp),%rdx
mov    %ebx,0x24(%rsp)
mov    %ebx,%edi
call   1140 <accept@plt>
mov    %eax,0x8(%rsp)
test   %eax,%eax
jns    1477 <main+0x207>
lea    0xbd6(%rip),%rdi
jmp    1413 <main+0x1a3>
lea    0x44(%rsp),%r12
lea    0xc11(%rip),%r15
lea    0xc2a(%rip),%r14
lea    0xc1c(%rip),%r13
jmp    14e0 <main+0x270>
lea    0xc0c(%rip),%rdi
call   1120 <perror@plt>
nop
mov    %ebx,%edi
call   10a0 <close@plt>
mov    0x8(%rsp),%edi
call   10a0 <close@plt>
lea    0xb7d(%rip),%rdi
call   1030 <puts@plt>
movq   $0x18,0x18(%rsp)
mov    0x24(%rsp),%edi
lea    0x28(%rsp),%rsi
lea    0x18(%rsp),%rdx
call   1140 <accept@plt>
mov    %eax,0x8(%rsp)
test   %eax,%eax
js     146e <main+0x1fe>
lea    0xb6b(%rip),%rdi
call   1030 <puts@plt>
lea    0xb77(%rip),%rdi
call   1080 <printf@plt>
mov    0x2aa1(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
mov    0x2a9b(%rip),%rax
mov    (%rax),%edi
mov    0x2a9a(%rip),%rax
mov    (%rax),%esi
mov    0x2aa9(%rip),%rax
mov    (%rax),%edx
call   1190 <socket@plt>
test   %eax,%eax
js     12de <main+0x6e>
mov    %eax,%ebx
lea    0x28(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1090 <memset@plt>
mov    0xc(%rsp),%edi
call   1070 <htons@plt>
mov    %rax,0x38(%rsp)
mov    0x2a7f(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x30(%rsp)
mov    0x10(%rsp),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x28(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x18,%edx
call   1170 <connect@plt>
test   %rax,%rax
js     1641 <main+0x3d1>
lea    0xafc(%rip),%rdi
call   1030 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
call   10c0 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r12,%rsi
call   1180 <FD_SET@plt>
mov    0x8(%rsp),%edi
mov    %r12,%rsi
call   1180 <FD_SET@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%edi
cmp    %edi,%ebx
cmovg  %ebx,%edi
add    $0x1,%edi
mov    %r12,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10d0 <select@plt>
test   %rax,%rax
js     1493 <main+0x223>
mov    0x8(%rsp),%edi
mov    %r12,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1612 <main+0x3a2>
mov    0x8(%rsp),%esi
mov    %r13,%rdi
mov    %ebx,%edx
call   1060 <pass_message@plt>
test   %rax,%rax
jne    14a0 <main+0x230>
mov    %ebx,%edi
mov    %r12,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     15a0 <main+0x330>
mov    0x8(%rsp),%edx
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <pass_message@plt>
test   %rax,%rax
je     15a0 <main+0x330>
jmp    14a0 <main+0x230>
lea    0xa3a(%rip),%rdi
jmp    1413 <main+0x1a3>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i32 }
@.str = [14 x i8] c"192.168.0.101\00"
@.str.1 = [8 x i8] c"hs:p:l:\00"
@EOF = global i32 0
@optarg = global i8* null
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [11 x i8] c"setsockopt\00"
@AF_INET = global i8* null
@INADDR_ANY = global i32 0
@.str.4 = [5 x i8] c"bind\00"
@.str.5 = [7 x i8] c"listen\00"
@.str.6 = [23 x i8] c"waiting for connection\00"
@.str.7 = [7 x i8] c"accept\00"
@.str.8 = [24 x i8] c"got incoming connection\00"
@.str.9 = [24 x i8] c"connecting to client...\00"
@stdout = global i32 0
@.str.10 = [8 x i8] c"connect\00"
@.str.11 = [10 x i8] c"connected\00"
@.str.12 = [18 x i8] c"Waiting for input\00"
@.str.13 = [7 x i8] c"select\00"
@.str.14 = [7 x i8] c"remote\00"
@.str.15 = [6 x i8] c"local\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 i32
%10 = alloca i64
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 6699, i32* %9
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %13
store i32 6699, i32* %14
br label %15
15: ; preds = %33, %2
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call i32 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 %18, i32* %8
%19 = load i32, i32* @EOF
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %34
21: ; preds = %15
%22 = load i32, i32* %8
switch i32 %22, label %31 [
i32 108, label %23
i32 115, label %26
i32 112, label %28
]
23: ; preds = %21
%24 = load i8*, i8** @optarg
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %9
br label %33
26: ; preds = %21
%27 = load i8*, i8** @optarg
store i8* %27, i8** %13
br label %33
28: ; preds = %21
%29 = load i8*, i8** @optarg
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %14
br label %33
31: ; preds = %21
%32 = call i32 (...) @usage()
br label %33
33: ; preds = %31, %28, %26, %23
br label %15
34: ; preds = %15
%35 = load i32, i32* @PF_INET
%36 = load i32, i32* @SOCK_STREAM
%37 = load i32, i32* @IPPROTO_TCP
%38 = call i32 @socket(i32 %35, i32 %36, i32 %37)
store i32 %38, i32* %6
%39 = load i32, i32* %6
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %34
%42 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %34
store i32 1, i32* %7
%45 = load i32, i32* %6
%46 = load i32, i32* @SOL_SOCKET
%47 = load i32, i32* @SO_REUSEADDR
%48 = call i64 @setsockopt(i32 %45, i32 %46, i32 %47, i32* %7, i32 4)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %44
%51 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %44
%54 = call i32 @memset(%struct.sockaddr_in* %11, i32 0, i32 24)
%55 = load i32, i32* %9
%56 = call i8* @htons(i32 %55)
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i8* %56, i8** %57
%58 = load i8*, i8** @AF_INET
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i8* %58, i8** %59
%60 = load i32, i32* @INADDR_ANY
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%62 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %61, i32 0, i32 0
store i32 %60, i32* %62
%63 = load i32, i32* %6
%64 = call i64 @bind(i32 %63, %struct.sockaddr_in* %11, i32 24)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %53
%67 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %53
%70 = load i32, i32* %6
%71 = call i64 @listen(i32 %70, i32 1)
%72 = icmp slt i64 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %69
%74 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %69
br label %77
77: ; preds = %163, %76
%78 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
store i64 24, i64* %10
%79 = load i32, i32* %6
%80 = call i32 @accept(i32 %79, %struct.sockaddr_in* %11, i64* %10)
store i32 %80, i32* %7
%81 = load i32, i32* %7
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %77
%84 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%85 = call i32 @exit(i32 1)
unreachable
86: ; preds = %77
%87 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%88 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%89 = load i32, i32* @stdout
%90 = call i32 @fflush(i32 %89)
%91 = load i32, i32* @PF_INET
%92 = load i32, i32* @SOCK_STREAM
%93 = load i32, i32* @IPPROTO_TCP
%94 = call i32 @socket(i32 %91, i32 %92, i32 %93)
store i32 %94, i32* %8
%95 = load i32, i32* %8
%96 = icmp slt i32 %95, 0
br i1 %96, label %97, label %100
97: ; preds = %86
%98 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%99 = call i32 @exit(i32 1)
unreachable
100: ; preds = %86
%101 = call i32 @memset(%struct.sockaddr_in* %11, i32 0, i32 24)
%102 = load i32, i32* %14
%103 = call i8* @htons(i32 %102)
%104 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i8* %103, i8** %104
%105 = load i8*, i8** @AF_INET
%106 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i8* %105, i8** %106
%107 = load i8*, i8** %13
%108 = call i32 @inet_addr(i8* %107)
%109 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%110 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %109, i32 0, i32 0
store i32 %108, i32* %110
%111 = load i32, i32* %8
%112 = call i64 @connect(i32 %111, %struct.sockaddr_in* %11, i32 24)
%113 = icmp slt i64 %112, 0
br i1 %113, label %114, label %117
114: ; preds = %100
%115 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%116 = call i32 @exit(i32 1)
unreachable
117: ; preds = %100
%118 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
br label %119
119: ; preds = %162, %117
%120 = call i32 @FD_ZERO(i32* %12)
%121 = load i32, i32* %8
%122 = call i32 @FD_SET(i32 %121, i32* %12)
%123 = load i32, i32* %7
%124 = call i32 @FD_SET(i32 %123, i32* %12)
%125 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
%126 = load i32, i32* %8
%127 = load i32, i32* %7
%128 = icmp sgt i32 %126, %127
br i1 %128, label %129, label %131
129: ; preds = %119
%130 = load i32, i32* %8
br label %133
131: ; preds = %119
%132 = load i32, i32* %7
br label %133
133: ; preds = %131, %129
%134 = phi i32 [ %130, %129 ], [ %132, %131 ]
%135 = add nsw i32 %134, 1
%136 = call i64 @select(i32 %135, i32* %12, i32 0, i32 0, i32 0)
%137 = icmp slt i64 %136, 0
br i1 %137, label %138, label %140
138: ; preds = %133
%139 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0))
br label %163
140: ; preds = %133
%141 = load i32, i32* %7
%142 = call i64 @FD_ISSET(i32 %141, i32* %12)
%143 = icmp ne i64 %142, 0
br i1 %143, label %144, label %151
144: ; preds = %140
%145 = load i32, i32* %7
%146 = load i32, i32* %8
%147 = call i64 @pass_message(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i64 0, i64 0), i32 %145, i32 %146)
%148 = icmp ne i64 %147, 0
br i1 %148, label %149, label %150
149: ; preds = %144
br label %163
150: ; preds = %144
br label %151
151: ; preds = %150, %140
%152 = load i32, i32* %8
%153 = call i64 @FD_ISSET(i32 %152, i32* %12)
%154 = icmp ne i64 %153, 0
br i1 %154, label %155, label %162
155: ; preds = %151
%156 = load i32, i32* %8
%157 = load i32, i32* %7
%158 = call i64 @pass_message(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.15, i64 0, i64 0), i32 %156, i32 %157)
%159 = icmp ne i64 %158, 0
br i1 %159, label %160, label %161
160: ; preds = %155
br label %163
161: ; preds = %155
br label %162
162: ; preds = %161, %151
br label %119
163: ; preds = %160, %149, %138
%164 = load i32, i32* %8
%165 = call i32 @close(i32 %164)
%166 = load i32, i32* %7
%167 = call i32 @close(i32 %166)
br label %77
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i32 }
@.str = [14 x i8] c"192.168.0.101\00"
@.str.1 = [8 x i8] c"hs:p:l:\00"
@EOF = global i32 0
@optarg = global i8* null
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [11 x i8] c"setsockopt\00"
@AF_INET = global i8* null
@INADDR_ANY = global i32 0
@.str.4 = [5 x i8] c"bind\00"
@.str.5 = [7 x i8] c"listen\00"
@.str.6 = [23 x i8] c"waiting for connection\00"
@.str.7 = [7 x i8] c"accept\00"
@.str.8 = [24 x i8] c"got incoming connection\00"
@.str.9 = [24 x i8] c"connecting to client...\00"
@stdout = global i32 0
@.str.10 = [8 x i8] c"connect\00"
@.str.11 = [10 x i8] c"connected\00"
@.str.12 = [18 x i8] c"Waiting for input\00"
@.str.13 = [7 x i8] c"select\00"
@.str.14 = [7 x i8] c"remote\00"
@.str.15 = [6 x i8] c"local\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = bitcast i64* %4 to i8*
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %36, label %14
14: ; preds = %2, %29
%15 = phi i32 [ %33, %29 ], [ %11, %2 ]
%16 = phi i32 [ %32, %29 ], [ 6699, %2 ]
%17 = phi i8* [ %31, %29 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %2 ]
%18 = phi i32 [ %30, %29 ], [ 6699, %2 ]
switch i32 %15, label %27 [
i32 108, label %19
i32 115, label %22
i32 112, label %24
]
19: ; preds = %14
%20 = load i8*, i8** @optarg
%21 = tail call i32 @atoi(i8* %20)
br label %29
22: ; preds = %14
%23 = load i8*, i8** @optarg
br label %29
24: ; preds = %14
%25 = load i8*, i8** @optarg
%26 = tail call i32 @atoi(i8* %25)
br label %29
27: ; preds = %14
%28 = tail call i32 (...) @usage()
br label %29
29: ; preds = %27, %24, %22, %19
%30 = phi i32 [ %18, %27 ], [ %18, %24 ], [ %18, %22 ], [ %21, %19 ]
%31 = phi i8* [ %17, %27 ], [ %17, %24 ], [ %23, %22 ], [ %17, %19 ]
%32 = phi i32 [ %16, %27 ], [ %26, %24 ], [ %16, %22 ], [ %16, %19 ]
%33 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %14
36: ; preds = %29, %2
%37 = phi i32 [ 6699, %2 ], [ %30, %29 ]
%38 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %2 ], [ %31, %29 ]
%39 = phi i32 [ 6699, %2 ], [ %32, %29 ]
%40 = load i32, i32* @PF_INET
%41 = load i32, i32* @SOCK_STREAM
%42 = load i32, i32* @IPPROTO_TCP
%43 = tail call i32 @socket(i32 %40, i32 %41, i32 %42)
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %36
%46 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%47 = tail call i32 @exit(i32 1)
unreachable
48: ; preds = %36
store i32 1, i32* %3
%49 = load i32, i32* @SOL_SOCKET
%50 = load i32, i32* @SO_REUSEADDR
%51 = call i64 @setsockopt(i32 %43, i32 %49, i32 %50, i32* %3, i32 4)
%52 = icmp eq i64 %51, 0
br i1 %52, label %56, label %53
53: ; preds = %48
%54 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %48
%57 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 24)
%58 = call i8* @htons(i32 %37)
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i8* %58, i8** %59
%60 = load i8*, i8** @AF_INET
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i8* %60, i8** %61
%62 = load i32, i32* @INADDR_ANY
%63 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i32 %62, i32* %63
%64 = call i64 @bind(i32 %43, %struct.sockaddr_in* %5, i32 24)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %56
%67 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %56
%70 = call i64 @listen(i32 %43, i32 1)
%71 = icmp slt i64 %70, 0
br i1 %71, label %76, label %72
72: ; preds = %69
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
store i64 24, i64* %4
%74 = call i32 @accept(i32 %43, %struct.sockaddr_in* %5, i64* %4)
store i32 %74, i32* %3
%75 = icmp slt i32 %74, 0
br i1 %75, label %79, label %82
76: ; preds = %69
%77 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %137, %72
%80 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %72, %137
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%84 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%85 = load i32, i32* @stdout
%86 = call i32 @fflush(i32 %85)
%87 = load i32, i32* @PF_INET
%88 = load i32, i32* @SOCK_STREAM
%89 = load i32, i32* @IPPROTO_TCP
%90 = call i32 @socket(i32 %87, i32 %88, i32 %89)
%91 = icmp slt i32 %90, 0
br i1 %91, label %92, label %95
92: ; preds = %82
%93 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %82
%96 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 24)
%97 = call i8* @htons(i32 %39)
store i8* %97, i8** %59
%98 = load i8*, i8** @AF_INET
store i8* %98, i8** %61
%99 = call i32 @inet_addr(i8* %38)
store i32 %99, i32* %63
%100 = call i64 @connect(i32 %90, %struct.sockaddr_in* %5, i32 24)
%101 = icmp slt i64 %100, 0
br i1 %101, label %102, label %105
102: ; preds = %95
%103 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%104 = call i32 @exit(i32 1)
unreachable
105: ; preds = %95
%106 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
br label %107
107: ; preds = %136, %105
%108 = call i32 @FD_ZERO(i32* %6)
%109 = call i32 @FD_SET(i32 %90, i32* %6)
%110 = load i32, i32* %3
%111 = call i32 @FD_SET(i32 %110, i32* %6)
%112 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
%113 = load i32, i32* %3
%114 = icmp sgt i32 %90, %113
%115 = select i1 %114, i32 %90, i32 %113
%116 = add nsw i32 %115, 1
%117 = call i64 @select(i32 %116, i32* %6, i32 0, i32 0, i32 0)
%118 = icmp slt i64 %117, 0
br i1 %118, label %119, label %121
119: ; preds = %107
%120 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0))
br label %137
121: ; preds = %107
%122 = load i32, i32* %3
%123 = call i64 @FD_ISSET(i32 %122, i32* %6)
%124 = icmp eq i64 %123, 0
br i1 %124, label %129, label %125
125: ; preds = %121
%126 = load i32, i32* %3
%127 = call i64 @pass_message(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i64 0, i64 0), i32 %126, i32 %90)
%128 = icmp eq i64 %127, 0
br i1 %128, label %129, label %137
129: ; preds = %125, %121
%130 = call i64 @FD_ISSET(i32 %90, i32* %6)
%131 = icmp eq i64 %130, 0
br i1 %131, label %136, label %132
132: ; preds = %129
%133 = load i32, i32* %3
%134 = call i64 @pass_message(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.15, i64 0, i64 0), i32 %90, i32 %133)
%135 = icmp eq i64 %134, 0
br i1 %135, label %136, label %137
136: ; preds = %132, %129
br label %107
137: ; preds = %132, %125, %119
%138 = call i32 @close(i32 %90)
%139 = load i32, i32* %3
%140 = call i32 @close(i32 %139)
%141 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
store i64 24, i64* %4
%142 = call i32 @accept(i32 %43, %struct.sockaddr_in* %5, i64* %4)
store i32 %142, i32* %3
%143 = icmp slt i32 %142, 0
br i1 %143, label %79, label %82
}