#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 = 8888;
  size_t sinsize;
  struct sockaddr_in sin;
  fd_set fds;
  char *host = "208.49.239.247";
  int port = 6666;
  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);
  }
  puts("waiting for client");
  if (select(s + 1, &fds, 0, 0, 0) < 0) {
    perror("select");
    exit(1);
  }
  sinsize = sizeof(sin);
  c = accept(s, &sin, &sinsize);
  if (c < 0) {
    perror("accept");
    exit(1);
  }
  puts("got client");
  printf("connecting to server...");
  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 to server");
  for (;;) {
    FD_ZERO(&fds);
    FD_SET(r, &fds);
    FD_SET(c, &fds);
    if (select(((r > c) ? r : c) + 1, &fds, 0, 0, 0) < 0) {
      perror("select");
      break;
    }
    if (FD_ISSET(r, &fds)) {
      if (pass_message("server", r, c) != 0)
        break;
    }
    if (FD_ISSET(c, &fds)) {
      if (pass_message("client", c, r) != 0)
        break;
    }
  }
  close(r);
  close(s);
  close(c);
  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   $0x22b8,-0x20(%rbp)
lea    0xd6c(%rip),%rax
mov    %rax,-0x50(%rbp)
movl   $0x1a0a,-0x54(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd62(%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    0xc9c(%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    0xc58(%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    0xbfc(%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    0xbd4(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    0xbc5(%rip),%rdi
call   1030 <puts@plt>
mov    -0x14(%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    14ad <main+0x23d>
lea    0xbaa(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@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    14e8 <main+0x278>
lea    0xb76(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    0xb67(%rip),%rdi
call   1030 <puts@plt>
lea    0xb66(%rip),%rdi
call   1080 <printf@plt>
mov    0x2a99(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
mov    0x2a93(%rip),%rax
mov    (%rax),%edi
mov    0x2a92(%rip),%rax
mov    (%rax),%esi
mov    0x2aa1(%rip),%rax
mov    (%rax),%edx
call   1190 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1551 <main+0x2e1>
lea    0xad5(%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    0x2a64(%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    15b8 <main+0x348>
lea    0xad0(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    0xac2(%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>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    15fc <main+0x38c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
jmp    1602 <main+0x392>
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    1635 <main+0x3c5>
lea    0xa1d(%rip),%rdi
call   1120 <perror@plt>
jmp    16b2 <main+0x442>
mov    -0x1c(%rbp),%edi
lea    -0x44(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1671 <main+0x401>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xa36(%rip),%rdi
call   1060 <pass_message@plt>
cmp    $0x0,%rax
je     166c <main+0x3fc>
jmp    16b2 <main+0x442>
jmp    1671 <main+0x401>
mov    -0x18(%rbp),%edi
lea    -0x44(%rbp),%rsi
call   1050 <FD_ISSET@plt>
cmp    $0x0,%rax
je     16ad <main+0x43d>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0x9ad(%rip),%rdi
call   1060 <pass_message@plt>
cmp    $0x0,%rax
je     16a8 <main+0x438>
jmp    16b2 <main+0x442>
jmp    16ad <main+0x43d>
jmp    15c4 <main+0x354>
mov    -0x1c(%rbp),%edi
call   10a0 <close@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
mov    -0x18(%rbp),%edi
call   10a0 <close@plt>
xor    %edi,%edi
call   1160 <exit@plt>

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    0xd85(%rip),%rdx
call   1130 <getopt@plt>
mov    0x2d2a(%rip),%r15
cmp    (%r15),%eax
jne    12ed <main+0x7d>
movl   $0x1a0a,0x4(%rsp)
lea    0xd56(%rip),%rax
mov    %rax,0x8(%rsp)
mov    $0x22b8,%r13d
mov    0x2cec(%rip),%r15
mov    (%r15),%edi
mov    0x2cea(%rip),%r12
mov    (%r12),%esi
mov    0x2cf7(%rip),%rbp
mov    0x0(%rbp),%edx
call   1190 <socket@plt>
test   %eax,%eax
jns    137f <main+0x10f>
lea    0xd2f(%rip),%rdi
jmp    152f <main+0x2bf>
mov    $0x22b8,%r13d
lea    0xd06(%rip),%rcx
mov    %rcx,0x8(%rsp)
movl   $0x1a0a,0x4(%rsp)
mov    0x2cea(%rip),%r12
lea    0xcfa(%rip),%r14
jmp    133d <main+0xcd>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1100 <usage@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1130 <getopt@plt>
cmp    (%r15),%eax
je     12b5 <main+0x45>
cmp    $0x73,%eax
je     1360 <main+0xf0>
cmp    $0x70,%eax
je     1370 <main+0x100>
cmp    $0x6c,%eax
jne    1320 <main+0xb0>
mov    (%r12),%rdi
call   1150 <atoi@plt>
mov    %eax,%r13d
jmp    1327 <main+0xb7>
nopw   0x0(%rax,%rax,1)
mov    (%r12),%rax
mov    %rax,0x8(%rsp)
jmp    1327 <main+0xb7>
nopl   0x0(%rax,%rax,1)
mov    (%r12),%rdi
call   1150 <atoi@plt>
mov    %eax,0x4(%rsp)
jmp    1327 <main+0xb7>
mov    %eax,%r14d
movl   $0x1,(%rsp)
mov    0x2c50(%rip),%rax
mov    (%rax),%esi
mov    0x2bff(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
jne    1410 <main+0x1a0>
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1090 <memset@plt>
mov    %r13d,%edi
call   1070 <htons@plt>
mov    %rax,0x28(%rsp)
mov    0x2bff(%rip),%r13
mov    0x0(%r13),%rax
mov    %rax,0x20(%rsp)
mov    0x2be7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x18,%edx
call   1110 <bind@plt>
test   %rax,%rax
jns    141c <main+0x1ac>
lea    0xc1e(%rip),%rdi
jmp    152f <main+0x2bf>
lea    0xc07(%rip),%rdi
jmp    152f <main+0x2bf>
mov    %r14d,%edi
mov    $0x1,%esi
call   10f0 <listen@plt>
test   %rax,%rax
jns    143a <main+0x1ca>
lea    0xbf9(%rip),%rdi
jmp    152f <main+0x2bf>
lea    0xbf4(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%edi
add    $0x1,%edi
lea    0x14(%rsp),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10d0 <select@plt>
test   %rax,%rax
jns    146e <main+0x1fe>
lea    0xbdf(%rip),%rdi
jmp    152f <main+0x2bf>
movq   $0x18,0x30(%rsp)
lea    0x18(%rsp),%rsi
lea    0x30(%rsp),%rdx
mov    %r14d,%edi
call   1140 <accept@plt>
mov    %eax,(%rsp)
test   %eax,%eax
jns    149c <main+0x22c>
lea    0xbb8(%rip),%rdi
jmp    152f <main+0x2bf>
lea    0xbb3(%rip),%rdi
call   1030 <puts@plt>
lea    0xbb2(%rip),%rdi
call   1080 <printf@plt>
mov    0x2ae5(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
mov    (%r15),%edi
mov    (%r12),%esi
mov    0x0(%rbp),%edx
call   1190 <socket@plt>
test   %eax,%eax
js     12e1 <main+0x71>
mov    %eax,%ebx
lea    0x18(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1090 <memset@plt>
mov    0x4(%rsp),%edi
call   1070 <htons@plt>
mov    %rax,0x28(%rsp)
mov    0x0(%r13),%rax
mov    %rax,0x20(%rsp)
mov    0x8(%rsp),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x18(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x18,%edx
call   1170 <connect@plt>
test   %rax,%rax
jns    153e <main+0x2ce>
lea    0xb4a(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    0xb3c(%rip),%rdi
call   1030 <puts@plt>
lea    0x14(%rsp),%rbp
lea    0xaeb(%rip),%r15
lea    0xb31(%rip),%r12
nopl   (%rax)
mov    %rbp,%rdi
call   10c0 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1180 <FD_SET@plt>
mov    (%rsp),%edi
mov    %rbp,%rsi
call   1180 <FD_SET@plt>
mov    (%rsp),%edi
cmp    %edi,%ebx
cmovg  %ebx,%edi
add    $0x1,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10d0 <select@plt>
test   %rax,%rax
js     15e1 <main+0x371>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     15bd <main+0x34d>
mov    (%rsp),%edx
mov    %r12,%rdi
mov    %ebx,%esi
call   1060 <pass_message@plt>
test   %rax,%rax
jne    15ed <main+0x37d>
mov    (%rsp),%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1560 <main+0x2f0>
mov    (%rsp),%esi
mov    %r15,%rdi
mov    %ebx,%edx
call   1060 <pass_message@plt>
test   %rax,%rax
je     1560 <main+0x2f0>
jmp    15ed <main+0x37d>
lea    0xa60(%rip),%rdi
call   1120 <perror@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
mov    %r14d,%edi
call   10a0 <close@plt>
mov    (%rsp),%edi
call   10a0 <close@plt>
xor    %edi,%edi
call   1160 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i32 }
@.str = [15 x i8] c"208.49.239.247\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 = [19 x i8] c"waiting for client\00"
@.str.7 = [7 x i8] c"select\00"
@.str.8 = [7 x i8] c"accept\00"
@.str.9 = [11 x i8] c"got client\00"
@.str.10 = [24 x i8] c"connecting to server...\00"
@stdout = global i32 0
@.str.11 = [8 x i8] c"connect\00"
@.str.12 = [20 x i8] c"connected to server\00"
@.str.13 = [7 x i8] c"server\00"
@.str.14 = [7 x i8] c"client\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 8888, i32* %9
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %13
store i32 6666, 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
%77 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%78 = load i32, i32* %6
%79 = add nsw i32 %78, 1
%80 = call i64 @select(i32 %79, i32* %12, i32 0, i32 0, i32 0)
%81 = icmp slt i64 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %76
%83 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%84 = call i32 @exit(i32 1)
unreachable
85: ; preds = %76
store i64 24, i64* %10
%86 = load i32, i32* %6
%87 = call i32 @accept(i32 %86, %struct.sockaddr_in* %11, i64* %10)
store i32 %87, i32* %7
%88 = load i32, i32* %7
%89 = icmp slt i32 %88, 0
br i1 %89, label %90, label %93
90: ; preds = %85
%91 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%92 = call i32 @exit(i32 1)
unreachable
93: ; preds = %85
%94 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%95 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
%96 = load i32, i32* @stdout
%97 = call i32 @fflush(i32 %96)
%98 = load i32, i32* @PF_INET
%99 = load i32, i32* @SOCK_STREAM
%100 = load i32, i32* @IPPROTO_TCP
%101 = call i32 @socket(i32 %98, i32 %99, i32 %100)
store i32 %101, i32* %8
%102 = load i32, i32* %8
%103 = icmp slt i32 %102, 0
br i1 %103, label %104, label %107
104: ; preds = %93
%105 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%106 = call i32 @exit(i32 1)
unreachable
107: ; preds = %93
%108 = call i32 @memset(%struct.sockaddr_in* %11, i32 0, i32 24)
%109 = load i32, i32* %14
%110 = call i8* @htons(i32 %109)
%111 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i8* %110, i8** %111
%112 = load i8*, i8** @AF_INET
%113 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i8* %112, i8** %113
%114 = load i8*, i8** %13
%115 = call i32 @inet_addr(i8* %114)
%116 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%117 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %116, i32 0, i32 0
store i32 %115, i32* %117
%118 = load i32, i32* %8
%119 = call i64 @connect(i32 %118, %struct.sockaddr_in* %11, i32 24)
%120 = icmp slt i64 %119, 0
br i1 %120, label %121, label %124
121: ; preds = %107
%122 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
%123 = call i32 @exit(i32 1)
unreachable
124: ; preds = %107
%125 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0))
br label %126
126: ; preds = %168, %124
%127 = call i32 @FD_ZERO(i32* %12)
%128 = load i32, i32* %8
%129 = call i32 @FD_SET(i32 %128, i32* %12)
%130 = load i32, i32* %7
%131 = call i32 @FD_SET(i32 %130, i32* %12)
%132 = load i32, i32* %8
%133 = load i32, i32* %7
%134 = icmp sgt i32 %132, %133
br i1 %134, label %135, label %137
135: ; preds = %126
%136 = load i32, i32* %8
br label %139
137: ; preds = %126
%138 = load i32, i32* %7
br label %139
139: ; preds = %137, %135
%140 = phi i32 [ %136, %135 ], [ %138, %137 ]
%141 = add nsw i32 %140, 1
%142 = call i64 @select(i32 %141, i32* %12, i32 0, i32 0, i32 0)
%143 = icmp slt i64 %142, 0
br i1 %143, label %144, label %146
144: ; preds = %139
%145 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %169
146: ; preds = %139
%147 = load i32, i32* %8
%148 = call i64 @FD_ISSET(i32 %147, i32* %12)
%149 = icmp ne i64 %148, 0
br i1 %149, label %150, label %157
150: ; preds = %146
%151 = load i32, i32* %8
%152 = load i32, i32* %7
%153 = call i64 @pass_message(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i32 %151, i32 %152)
%154 = icmp ne i64 %153, 0
br i1 %154, label %155, label %156
155: ; preds = %150
br label %169
156: ; preds = %150
br label %157
157: ; preds = %156, %146
%158 = load i32, i32* %7
%159 = call i64 @FD_ISSET(i32 %158, i32* %12)
%160 = icmp ne i64 %159, 0
br i1 %160, label %161, label %168
161: ; preds = %157
%162 = load i32, i32* %7
%163 = load i32, i32* %8
%164 = call i64 @pass_message(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i64 0, i64 0), i32 %162, i32 %163)
%165 = icmp ne i64 %164, 0
br i1 %165, label %166, label %167
166: ; preds = %161
br label %169
167: ; preds = %161
br label %168
168: ; preds = %167, %157
br label %126
169: ; preds = %166, %155, %144
%170 = load i32, i32* %8
%171 = call i32 @close(i32 %170)
%172 = load i32, i32* %6
%173 = call i32 @close(i32 %172)
%174 = load i32, i32* %7
%175 = call i32 @close(i32 %174)
%176 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i32 }
@.str = [15 x i8] c"208.49.239.247\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 = [19 x i8] c"waiting for client\00"
@.str.7 = [7 x i8] c"select\00"
@.str.8 = [7 x i8] c"accept\00"
@.str.9 = [11 x i8] c"got client\00"
@.str.10 = [24 x i8] c"connecting to server...\00"
@stdout = global i32 0
@.str.11 = [8 x i8] c"connect\00"
@.str.12 = [20 x i8] c"connected to server\00"
@.str.13 = [7 x i8] c"server\00"
@.str.14 = [7 x i8] c"client\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 ], [ 6666, %2 ]
%17 = phi i8* [ %31, %29 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %2 ]
%18 = phi i32 [ %30, %29 ], [ 8888, %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 [ 8888, %2 ], [ %30, %29 ]
%38 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %2 ], [ %31, %29 ]
%39 = phi i32 [ 6666, %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 %72, label %75
72: ; preds = %69
%73 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%74 = call i32 @exit(i32 1)
unreachable
75: ; preds = %69
%76 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%77 = add nuw nsw i32 %43, 1
%78 = call i64 @select(i32 %77, i32* %6, i32 0, i32 0, i32 0)
%79 = icmp slt i64 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %75
%81 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %75
store i64 24, i64* %4
%84 = call i32 @accept(i32 %43, %struct.sockaddr_in* %5, i64* %4)
store i32 %84, i32* %3
%85 = icmp slt i32 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %83
%87 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %83
%90 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%91 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
%92 = load i32, i32* @stdout
%93 = call i32 @fflush(i32 %92)
%94 = load i32, i32* @PF_INET
%95 = load i32, i32* @SOCK_STREAM
%96 = load i32, i32* @IPPROTO_TCP
%97 = call i32 @socket(i32 %94, i32 %95, i32 %96)
%98 = icmp slt i32 %97, 0
br i1 %98, label %99, label %102
99: ; preds = %89
%100 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %89
%103 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 24)
%104 = call i8* @htons(i32 %39)
store i8* %104, i8** %59
%105 = load i8*, i8** @AF_INET
store i8* %105, i8** %61
%106 = call i32 @inet_addr(i8* %38)
store i32 %106, i32* %63
%107 = call i64 @connect(i32 %97, %struct.sockaddr_in* %5, i32 24)
%108 = icmp slt i64 %107, 0
br i1 %108, label %109, label %112
109: ; preds = %102
%110 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
%111 = call i32 @exit(i32 1)
unreachable
112: ; preds = %102
%113 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0))
br label %114
114: ; preds = %142, %112
%115 = call i32 @FD_ZERO(i32* %6)
%116 = call i32 @FD_SET(i32 %97, i32* %6)
%117 = load i32, i32* %3
%118 = call i32 @FD_SET(i32 %117, i32* %6)
%119 = load i32, i32* %3
%120 = icmp sgt i32 %97, %119
%121 = select i1 %120, i32 %97, i32 %119
%122 = add nsw i32 %121, 1
%123 = call i64 @select(i32 %122, i32* %6, i32 0, i32 0, i32 0)
%124 = icmp slt i64 %123, 0
br i1 %124, label %125, label %127
125: ; preds = %114
%126 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %143
127: ; preds = %114
%128 = call i64 @FD_ISSET(i32 %97, i32* %6)
%129 = icmp eq i64 %128, 0
br i1 %129, label %134, label %130
130: ; preds = %127
%131 = load i32, i32* %3
%132 = call i64 @pass_message(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i32 %97, i32 %131)
%133 = icmp eq i64 %132, 0
br i1 %133, label %134, label %143
134: ; preds = %130, %127
%135 = load i32, i32* %3
%136 = call i64 @FD_ISSET(i32 %135, i32* %6)
%137 = icmp eq i64 %136, 0
br i1 %137, label %142, label %138
138: ; preds = %134
%139 = load i32, i32* %3
%140 = call i64 @pass_message(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i64 0, i64 0), i32 %139, i32 %97)
%141 = icmp eq i64 %140, 0
br i1 %141, label %142, label %143
142: ; preds = %138, %134
br label %114
143: ; preds = %138, %130, %125
%144 = call i32 @close(i32 %97)
%145 = call i32 @close(i32 %43)
%146 = load i32, i32* %3
%147 = call i32 @close(i32 %146)
%148 = call i32 @exit(i32 0)
unreachable
}