#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct timeval {
  long tv_sec;
  long tv_usec;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_addrtype;
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ *h_addr_list;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ error;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EINPROGRESS;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_ERROR;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
int getopt(int, char **, char *);
int getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
char *optarg;
size_t optind;
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(scalar_t__);
void *strtol(char *, char **, int);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  int sockfd;
  struct sockaddr_in addr;
  struct hostent *host;
  int error = 0;
  int ret;
  socklen_t errlen;
  struct timeval timeout;
  fd_set fdrset, fdwset;
  int verbose = 1;
  int c;
  char *cptr;
  long timeout_sec = 0, timeout_usec = 0;
  int port = 0;
  if (argc < 3) {
    usage(argv[0]);
  }
  while ((c = getopt(argc, argv, "qt:u:")) != -1) {
    switch (c) {
    case 'q':
      verbose = 0;
      break;
    case 't':
      cptr = NULL;
      timeout_sec = strtol(optarg, &cptr, 10);
      if (cptr == optarg)
        usage(argv[0]);
      break;
    case 'u':
      cptr = NULL;
      timeout_usec = strtol(optarg, &cptr, 10);
      if (cptr == optarg)
        usage(argv[0]);
      break;
    default:
      usage(argv[0]);
      break;
    }
  }
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  memset(&addr, 0, sizeof(addr));
  if ((host = gethostbyname(argv[optind])) == NULL) {
    if (verbose)
      fprintf(stderr, "error: host not found");
    exit(-1);
  }
  memcpy(&addr.sin_addr, host->h_addr_list[0], host->h_length);
  addr.sin_family = host->h_addrtype;
  if (argv[optind + 1]) {
    cptr = NULL;
    port = strtol(argv[optind + 1], &cptr, 10);
    if (cptr == argv[optind + 1])
      usage(argv[0]);
  } else {
    usage(argv[0]);
  }
  addr.sin_port = htons(port);
  fcntl(sockfd, F_SETFL, O_NONBLOCK);
  if ((ret = connect(sockfd, (struct sockaddr *)&addr, sizeof(addr))) != 0) {
    if (errno != EINPROGRESS) {
      if (verbose)
        fprintf(stderr, "error: %s port %s: %s\n", argv[optind],
                argv[optind + 1], strerror(errno));
      return (-1);
    }
    FD_ZERO(&fdrset);
    FD_SET(sockfd, &fdrset);
    fdwset = fdrset;
    timeout.tv_sec = timeout_sec + timeout_usec / 1000000;
    timeout.tv_usec = timeout_usec % 1000000;
    if ((ret = select(sockfd + 1, &fdrset, &fdwset, NULL,
                      timeout.tv_sec + timeout.tv_usec > 0 ? &timeout
                                                           : NULL)) == 0) {
      close(sockfd);
      if (verbose)
        fprintf(stdout, "%s port %s user timeout.\n", argv[optind],
                argv[optind + 1]);
      return (2);
    }
    if (FD_ISSET(sockfd, &fdrset) || FD_ISSET(sockfd, &fdwset)) {
      errlen = sizeof(error);
      if ((ret = getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &error, &errlen)) !=
          0) {
        if (verbose)
          fprintf(stderr, "error: %s port %s: getsockopt: %s\n", argv[optind],
                  argv[optind + 1], strerror(errno));
        close(sockfd);
        return (-1);
      }
      if (error != 0) {
        if (verbose)
          fprintf(stdout, "%s port %s closed.\n", argv[optind],
                  argv[optind + 1]);
        close(sockfd);
        return (1);
      }
    } else {
      if (verbose)
        fprintf(stderr, "error: select: sockfd not set\n");
      exit(-1);
    }
  }
  close(sockfd);
  if (verbose)
    fprintf(stdout, "%s port %s open.\n", argv[optind], argv[optind + 1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x1,-0x54(%rbp)
movq   $0x0,-0x68(%rbp)
movq   $0x0,-0x70(%rbp)
movl   $0x0,-0x74(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1284 <main+0x54>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <usage@plt>
jmp    1289 <main+0x59>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd69(%rip),%rdx
call   1100 <getopt@plt>
mov    %eax,-0x58(%rbp)
cmp    $0xffffffff,%eax
je     138d <main+0x15d>
mov    -0x58(%rbp),%eax
mov    %eax,-0x78(%rbp)
sub    $0x71,%eax
je     12de <main+0xae>
jmp    12bc <main+0x8c>
mov    -0x78(%rbp),%eax
sub    $0x74,%eax
je     12ea <main+0xba>
jmp    12cd <main+0x9d>
mov    -0x78(%rbp),%eax
sub    $0x75,%eax
je     1333 <main+0x103>
jmp    137c <main+0x14c>
movl   $0x0,-0x54(%rbp)
jmp    1388 <main+0x158>
movq   $0x0,-0x60(%rbp)
mov    0x2cff(%rip),%rax
mov    (%rax),%rdi
lea    -0x60(%rbp),%rsi
mov    $0xa,%edx
call   10b0 <strtol@plt>
mov    %rax,-0x68(%rbp)
mov    -0x60(%rbp),%rax
mov    0x2cdf(%rip),%rcx
cmp    (%rcx),%rax
jne    132e <main+0xfe>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <usage@plt>
jmp    1388 <main+0x158>
movq   $0x0,-0x60(%rbp)
mov    0x2cb6(%rip),%rax
mov    (%rax),%rdi
lea    -0x60(%rbp),%rsi
mov    $0xa,%edx
call   10b0 <strtol@plt>
mov    %rax,-0x70(%rbp)
mov    -0x60(%rbp),%rax
mov    0x2c96(%rip),%rcx
cmp    (%rcx),%rax
jne    1377 <main+0x147>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <usage@plt>
jmp    1388 <main+0x158>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <usage@plt>
jmp    1289 <main+0x59>
mov    0x2c44(%rip),%rax
mov    (%rax),%edi
mov    0x2c03(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x2bfc(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1090 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1409 <main+0x1d9>
cmpl   $0x0,-0x54(%rbp)
je     13ff <main+0x1cf>
mov    0x2bc1(%rip),%rax
mov    (%rax),%edi
lea    0xc0e(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
lea    -0x20(%rbp),%rdi
add    $0x8,%rdi
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%esi
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%edx
call   10c0 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2b85(%rip),%rcx
mov    (%rcx),%rcx
cmpq   $0x0,0x8(%rax,%rcx,8)
je     14a4 <main+0x274>
movq   $0x0,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2b63(%rip),%rcx
mov    (%rcx),%rcx
mov    0x8(%rax,%rcx,8),%rdi
lea    -0x60(%rbp),%rsi
mov    $0xa,%edx
call   10b0 <strtol@plt>
mov    %eax,-0x74(%rbp)
mov    -0x60(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    0x2b3b(%rip),%rdx
mov    (%rdx),%rdx
cmp    0x8(%rcx,%rdx,8),%rax
jne    149f <main+0x26f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <usage@plt>
jmp    14b0 <main+0x280>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10f0 <usage@plt>
mov    -0x74(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2ae3(%rip),%rax
mov    (%rax),%esi
mov    0x2b02(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1120 <connect@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
je     1837 <main+0x607>
mov    0x2a9f(%rip),%rax
mov    (%rax),%rax
mov    0x2ac5(%rip),%rcx
cmp    (%rcx),%rax
je     1592 <main+0x362>
cmpl   $0x0,-0x54(%rbp)
je     1586 <main+0x356>
mov    0x2a93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2a90(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x88(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2a77(%rip),%rcx
mov    (%rcx),%rcx
mov    0x8(%rax,%rcx,8),%rax
mov    %rax,-0x80(%rbp)
mov    0x2a3c(%rip),%rax
mov    (%rax),%rdi
call   1130 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rdx
mov    -0x80(%rbp),%rcx
mov    %rax,%r8
lea    0xa9d(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    188c <main+0x65c>
lea    -0x4c(%rbp),%rdi
call   10d0 <FD_ZERO@plt>
mov    -0x14(%rbp),%edi
lea    -0x4c(%rbp),%rsi
call   1140 <FD_SET@plt>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x70(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x98(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x70(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x40(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x90(%rbp)
mov    -0x48(%rbp),%rax
add    -0x40(%rbp),%rax
cmp    $0x0,%rax
jle    1617 <main+0x3e7>
lea    -0x48(%rbp),%rax
mov    %rax,-0xa0(%rbp)
jmp    1625 <main+0x3f5>
xor    %eax,%eax
mov    %rax,-0xa0(%rbp)
jmp    1625 <main+0x3f5>
mov    -0x90(%rbp),%edi
mov    -0xa0(%rbp),%r8
lea    -0x4c(%rbp),%rsi
lea    -0x50(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   10e0 <select@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jne    16a9 <main+0x479>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
cmpl   $0x0,-0x54(%rbp)
je     169d <main+0x46d>
mov    0x2920(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x294b(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x10(%rbp),%rax
mov    0x2939(%rip),%rcx
mov    (%rcx),%rcx
mov    0x8(%rax,%rcx,8),%rcx
lea    0x99d(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    188c <main+0x65c>
mov    -0x14(%rbp),%edi
lea    -0x4c(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
jne    16d5 <main+0x4a5>
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1807 <main+0x5d7>
movl   $0x4,-0x34(%rbp)
mov    -0x14(%rbp),%edi
mov    0x28fa(%rip),%rax
mov    (%rax),%esi
mov    0x28a1(%rip),%rax
mov    (%rax),%edx
lea    -0x2c(%rbp),%rcx
lea    -0x34(%rbp),%r8
call   1080 <getsockopt@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
je     179e <main+0x56e>
cmpl   $0x0,-0x54(%rbp)
je     178a <main+0x55a>
mov    0x2895(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb4(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2892(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2879(%rip),%rcx
mov    (%rcx),%rcx
mov    0x8(%rax,%rcx,8),%rax
mov    %rax,-0xa8(%rbp)
mov    0x283b(%rip),%rax
mov    (%rax),%rdi
call   1130 <strerror@plt>
mov    -0xb4(%rbp),%edi
mov    -0xb0(%rbp),%rdx
mov    -0xa8(%rbp),%rcx
mov    %rax,%r8
lea    0x8ca(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    188c <main+0x65c>
cmpl   $0x0,-0x2c(%rbp)
je     1802 <main+0x5d2>
cmpl   $0x0,-0x54(%rbp)
je     17ee <main+0x5be>
mov    0x27cf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x27fa(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x10(%rbp),%rax
mov    0x27e8(%rip),%rcx
mov    (%rcx),%rcx
mov    0x8(%rax,%rcx,8),%rcx
lea    0x889(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    188c <main+0x65c>
jmp    1832 <main+0x602>
cmpl   $0x0,-0x54(%rbp)
je     1828 <main+0x5f8>
mov    0x2798(%rip),%rax
mov    (%rax),%edi
lea    0x863(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
jmp    1837 <main+0x607>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
cmpl   $0x0,-0x54(%rbp)
je     1885 <main+0x655>
mov    0x2738(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x2763(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x10(%rbp),%rax
mov    0x2751(%rip),%rcx
mov    (%rcx),%rcx
mov    0x8(%rax,%rcx,8),%rcx
lea    0x825(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r12
mov    %edi,%ebx
movl   $0x0,0x18(%rsp)
movl   $0x1,0x4(%rsp)
xor    %eax,%eax
mov    %rax,0x30(%rsp)
mov    $0x0,%ebp
cmp    $0x3,%edi
jge    126d <main+0x3d>
mov    (%r12),%rdi
call   10f0 <usage@plt>
lea    0xd8c(%rip),%r15
mov    0x2d7d(%rip),%r14
lea    0x8(%rsp),%r13
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r15,%rdx
call   1100 <getopt@plt>
cmp    $0x75,%eax
jne    12ba <main+0x8a>
movq   $0x0,0x8(%rsp)
mov    (%r14),%rdi
mov    %r13,%rsi
mov    $0xa,%edx
call   10b0 <strtol@plt>
mov    %rax,%rbp
mov    0x8(%rsp),%rax
cmp    (%r14),%rax
jne    1280 <main+0x50>
jmp    1264 <main+0x34>
cmp    $0xffffffff,%eax
je     12f3 <main+0xc3>
cmp    $0x71,%eax
je     12e9 <main+0xb9>
cmp    $0x74,%eax
jne    1264 <main+0x34>
movq   $0x0,0x8(%rsp)
mov    (%r14),%rdi
mov    %r13,%rsi
mov    $0xa,%edx
call   10b0 <strtol@plt>
mov    %rax,0x30(%rsp)
jmp    12ae <main+0x7e>
movl   $0x0,0x4(%rsp)
jmp    1280 <main+0x50>
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
mov    0x2c9d(%rip),%rax
mov    (%rax),%esi
xor    %r13d,%r13d
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,%r15d
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2c96(%rip),%r14
mov    (%r14),%rax
mov    (%r12,%rax,8),%rdi
call   1090 <gethostbyname@plt>
test   %rax,%rax
je     162c <main+0x3fc>
mov    %rax,%rbx
lea    0x28(%rsp),%rdi
mov    0x8(%rax),%rax
mov    (%rax),%esi
mov    0x4(%rbx),%edx
call   10c0 <memcpy@plt>
mov    (%rbx),%eax
mov    %eax,0x24(%rsp)
mov    (%r14),%rax
mov    0x8(%r12,%rax,8),%rdi
test   %rdi,%rdi
je     1392 <main+0x162>
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   10b0 <strtol@plt>
mov    %rax,%r13
mov    0x8(%rsp),%rax
mov    (%r14),%rcx
cmp    0x8(%r12,%rcx,8),%rax
jne    139b <main+0x16b>
mov    (%r12),%rdi
call   10f0 <usage@plt>
mov    %r13d,%edi
call   1050 <htons@plt>
mov    %eax,0x20(%rsp)
mov    0x2bfa(%rip),%rax
mov    (%rax),%esi
mov    0x2c19(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
call   1030 <fcntl@plt>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    $0xc,%edx
call   1120 <connect@plt>
test   %eax,%eax
je     15e5 <main+0x3b5>
mov    0x2bb6(%rip),%r13
mov    0x0(%r13),%rdi
mov    0x2bdb(%rip),%rax
cmp    (%rax),%rdi
jne    1527 <main+0x2f7>
lea    0x14(%rsp),%rbx
mov    %rbx,%rdi
call   10d0 <FD_ZERO@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1140 <FD_SET@plt>
mov    0x14(%rsp),%eax
mov    %eax,0x10(%rsp)
movabs $0x431bde82d7b634db,%rcx
de 1b 43
mov    %rbp,%rax
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x12,%rdx
add    %rax,%rdx
mov    0x30(%rsp),%rcx
add    %rdx,%rcx
mov    %rcx,0x38(%rsp)
imul   $0xf4240,%rdx,%rax
sub    %rax,%rbp
mov    %rbp,0x40(%rsp)
mov    %r15d,%edi
add    $0x1,%edi
xor    %eax,%eax
add    %rcx,%rbp
lea    0x38(%rsp),%r8
cmovle %rax,%r8
lea    0x10(%rsp),%rdx
mov    %rbx,%rsi
xor    %ecx,%ecx
call   10e0 <select@plt>
test   %eax,%eax
je     156f <main+0x33f>
lea    0x14(%rsp),%rsi
mov    %r15d,%edi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
jne    14a3 <main+0x273>
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1654 <main+0x424>
movl   $0x4,0x1c(%rsp)
mov    0x2b2e(%rip),%rax
mov    (%rax),%esi
mov    0x2ad5(%rip),%rax
mov    (%rax),%edx
lea    0x18(%rsp),%rcx
lea    0x1c(%rsp),%r8
mov    %r15d,%edi
call   1080 <getsockopt@plt>
test   %eax,%eax
je     15a5 <main+0x375>
cmpl   $0x0,0x4(%rsp)
je     1515 <main+0x2e5>
mov    0x2acb(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rax
mov    (%r12,%rax,8),%rbp
mov    0x8(%r12,%rax,8),%r14
mov    0x0(%r13),%rdi
call   1130 <strerror@plt>
lea    0xb4a(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %r14,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    $0xffffffff,%ebx
jmp    161b <main+0x3eb>
mov    $0xffffffff,%ebx
cmpl   $0x0,0x4(%rsp)
je     161b <main+0x3eb>
mov    0x2a72(%rip),%rax
mov    (%rax),%ebp
mov    (%r14),%rax
mov    (%r12,%rax,8),%r14
mov    0x8(%r12,%rax,8),%r15
call   1130 <strerror@plt>
lea    0xac4(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    161b <main+0x3eb>
mov    %r15d,%edi
call   1070 <close@plt>
mov    $0x2,%ebx
cmpl   $0x0,0x4(%rsp)
je     161b <main+0x3eb>
mov    0x29fa(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rax
mov    (%r12,%rax,8),%rdx
mov    0x8(%r12,%rax,8),%rcx
lea    0xa90(%rip),%rsi
jmp    1614 <main+0x3e4>
cmpl   $0x0,0x18(%rsp)
je     15e5 <main+0x3b5>
cmpl   $0x0,0x4(%rsp)
je     15d6 <main+0x3a6>
mov    0x29ce(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rax
mov    (%r12,%rax,8),%rdx
mov    0x8(%r12,%rax,8),%rcx
lea    0xaa1(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    $0x1,%ebx
jmp    161b <main+0x3eb>
mov    %r15d,%edi
call   1070 <close@plt>
xor    %ebx,%ebx
cmpl   $0x0,0x4(%rsp)
je     161b <main+0x3eb>
mov    0x298b(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rax
mov    (%r12,%rax,8),%rdx
mov    0x8(%r12,%rax,8),%rcx
lea    0xa91(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmpl   $0x0,0x4(%rsp)
je     164a <main+0x41a>
mov    0x2976(%rip),%rax
mov    (%rax),%edi
lea    0x9c3(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
cmpl   $0x0,0x4(%rsp)
je     164a <main+0x41a>
mov    0x294e(%rip),%rax
mov    (%rax),%edi
lea    0xa19(%rip),%rsi
jmp    1643 <main+0x413>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32, i32* }
%struct.timeval = type { i64, i64 }
%struct.sockaddr = type { i32 }
@.str = [6 x i8] c"qt:u:\00"
@optarg = global i8* null
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@optind = global i64 0
@stderr = global i32 0
@.str.1 = [22 x i8] c"error: host not found\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@errno = global i64 0
@EINPROGRESS = global i64 0
@.str.2 = [23 x i8] c"error: %s port %s: %s\0A\00"
@stdout = global i32 0
@.str.3 = [26 x i8] c"%s port %s user timeout.\0A\00"
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
@.str.4 = [35 x i8] c"error: %s port %s: getsockopt: %s\0A\00"
@.str.5 = [20 x i8] c"%s port %s closed.\0A\00"
@.str.6 = [31 x i8] c"error: select: sockfd not set\0A\00"
@.str.7 = [18 x i8] c"%s port %s open.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.hostent*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.timeval
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8*
%18 = alloca i64
%19 = alloca i64
%20 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
store i32 1, i32* %15
store i64 0, i64* %18
store i64 0, i64* %19
store i32 0, i32* %20
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 3
br i1 %22, label %23, label %28
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @usage(i8* %26)
br label %28
28: ; preds = %23, %2
br label %29
29: ; preds = %68, %28
%30 = load i32, i32* %4
%31 = load i8**, i8*** %5
%32 = call i32 @getopt(i32 %30, i8** %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %32, i32* %16
%33 = icmp ne i32 %32, -1
br i1 %33, label %34, label %69
34: ; preds = %29
%35 = load i32, i32* %16
switch i32 %35, label %63 [
i32 113, label %36
i32 116, label %37
i32 117, label %50
]
36: ; preds = %34
store i32 0, i32* %15
br label %68
37: ; preds = %34
store i8* null, i8** %17
%38 = load i8*, i8** @optarg
%39 = call i8* @strtol(i8* %38, i8** %17, i32 10)
%40 = ptrtoint i8* %39 to i64
store i64 %40, i64* %18
%41 = load i8*, i8** %17
%42 = load i8*, i8** @optarg
%43 = icmp eq i8* %41, %42
br i1 %43, label %44, label %49
44: ; preds = %37
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 0
%47 = load i8*, i8** %46
%48 = call i32 @usage(i8* %47)
br label %49
49: ; preds = %44, %37
br label %68
50: ; preds = %34
store i8* null, i8** %17
%51 = load i8*, i8** @optarg
%52 = call i8* @strtol(i8* %51, i8** %17, i32 10)
%53 = ptrtoint i8* %52 to i64
store i64 %53, i64* %19
%54 = load i8*, i8** %17
%55 = load i8*, i8** @optarg
%56 = icmp eq i8* %54, %55
br i1 %56, label %57, label %62
57: ; preds = %50
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 0
%60 = load i8*, i8** %59
%61 = call i32 @usage(i8* %60)
br label %62
62: ; preds = %57, %50
br label %68
63: ; preds = %34
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 0
%66 = load i8*, i8** %65
%67 = call i32 @usage(i8* %66)
br label %68
68: ; preds = %63, %62, %49, %36
br label %29
69: ; preds = %29
%70 = load i32, i32* @AF_INET
%71 = load i32, i32* @SOCK_STREAM
%72 = call i32 @socket(i32 %70, i32 %71, i32 0)
store i32 %72, i32* %6
%73 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%74 = load i8**, i8*** %5
%75 = load i64, i64* @optind
%76 = getelementptr inbounds i8*, i8** %74, i64 %75
%77 = load i8*, i8** %76
%78 = call %struct.hostent* @gethostbyname(i8* %77)
store %struct.hostent* %78, %struct.hostent** %8
%79 = icmp eq %struct.hostent* %78, null
br i1 %79, label %80, label %88
80: ; preds = %69
%81 = load i32, i32* %15
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %80
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %86
86: ; preds = %83, %80
%87 = call i32 @exit(i32 -1)
unreachable
88: ; preds = %69
%89 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
%90 = load %struct.hostent*, %struct.hostent** %8
%91 = getelementptr inbounds %struct.hostent, %struct.hostent* %90, i32 0, i32 2
%92 = load i32*, i32** %91
%93 = getelementptr inbounds i32, i32* %92, i64 0
%94 = load i32, i32* %93
%95 = load %struct.hostent*, %struct.hostent** %8
%96 = getelementptr inbounds %struct.hostent, %struct.hostent* %95, i32 0, i32 1
%97 = load i32, i32* %96
%98 = call i32 @memcpy(i32* %89, i32 %94, i32 %97)
%99 = load %struct.hostent*, %struct.hostent** %8
%100 = getelementptr inbounds %struct.hostent, %struct.hostent* %99, i32 0, i32 0
%101 = load i32, i32* %100
%102 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %101, i32* %102
%103 = load i8**, i8*** %5
%104 = load i64, i64* @optind
%105 = add i64 %104, 1
%106 = getelementptr inbounds i8*, i8** %103, i64 %105
%107 = load i8*, i8** %106
%108 = icmp ne i8* %107, null
br i1 %108, label %109, label %130
109: ; preds = %88
store i8* null, i8** %17
%110 = load i8**, i8*** %5
%111 = load i64, i64* @optind
%112 = add i64 %111, 1
%113 = getelementptr inbounds i8*, i8** %110, i64 %112
%114 = load i8*, i8** %113
%115 = call i8* @strtol(i8* %114, i8** %17, i32 10)
%116 = ptrtoint i8* %115 to i32
store i32 %116, i32* %20
%117 = load i8*, i8** %17
%118 = load i8**, i8*** %5
%119 = load i64, i64* @optind
%120 = add i64 %119, 1
%121 = getelementptr inbounds i8*, i8** %118, i64 %120
%122 = load i8*, i8** %121
%123 = icmp eq i8* %117, %122
br i1 %123, label %124, label %129
124: ; preds = %109
%125 = load i8**, i8*** %5
%126 = getelementptr inbounds i8*, i8** %125, i64 0
%127 = load i8*, i8** %126
%128 = call i32 @usage(i8* %127)
br label %129
129: ; preds = %124, %109
br label %135
130: ; preds = %88
%131 = load i8**, i8*** %5
%132 = getelementptr inbounds i8*, i8** %131, i64 0
%133 = load i8*, i8** %132
%134 = call i32 @usage(i8* %133)
br label %135
135: ; preds = %130, %129
%136 = load i32, i32* %20
%137 = call i32 @htons(i32 %136)
%138 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %137, i32* %138
%139 = load i32, i32* %6
%140 = load i32, i32* @F_SETFL
%141 = load i32, i32* @O_NONBLOCK
%142 = call i32 @fcntl(i32 %139, i32 %140, i32 %141)
%143 = load i32, i32* %6
%144 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%145 = call i32 @connect(i32 %143, %struct.sockaddr* %144, i32 12)
store i32 %145, i32* %10
%146 = icmp ne i32 %145, 0
br i1 %146, label %147, label %279
147: ; preds = %135
%148 = load i64, i64* @errno
%149 = load i64, i64* @EINPROGRESS
%150 = icmp ne i64 %148, %149
br i1 %150, label %151, label %169
151: ; preds = %147
%152 = load i32, i32* %15
%153 = icmp ne i32 %152, 0
br i1 %153, label %154, label %168
154: ; preds = %151
%155 = load i32, i32* @stderr
%156 = load i8**, i8*** %5
%157 = load i64, i64* @optind
%158 = getelementptr inbounds i8*, i8** %156, i64 %157
%159 = load i8*, i8** %158
%160 = load i8**, i8*** %5
%161 = load i64, i64* @optind
%162 = add i64 %161, 1
%163 = getelementptr inbounds i8*, i8** %160, i64 %162
%164 = load i8*, i8** %163
%165 = load i64, i64* @errno
%166 = call i8* @strerror(i64 %165)
%167 = call i32 (i32, i8*, ...) @fprintf(i32 %155, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %159, i8* %164, i8* %166)
br label %168
168: ; preds = %154, %151
store i32 -1, i32* %3
br label %297
169: ; preds = %147
%170 = call i32 @FD_ZERO(i32* %13)
%171 = load i32, i32* %6
%172 = call i32 @FD_SET(i32 %171, i32* %13)
%173 = load i32, i32* %13
store i32 %173, i32* %14
%174 = load i64, i64* %18
%175 = load i64, i64* %19
%176 = sdiv i64 %175, 1000000
%177 = add nsw i64 %174, %176
%178 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
store i64 %177, i64* %178
%179 = load i64, i64* %19
%180 = srem i64 %179, 1000000
%181 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
store i64 %180, i64* %181
%182 = load i32, i32* %6
%183 = add nsw i32 %182, 1
%184 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%185 = load i64, i64* %184
%186 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%187 = load i64, i64* %186
%188 = add nsw i64 %185, %187
%189 = icmp sgt i64 %188, 0
br i1 %189, label %190, label %191
190: ; preds = %169
br label %192
191: ; preds = %169
br label %192
192: ; preds = %191, %190
%193 = phi %struct.timeval* [ %12, %190 ], [ null, %191 ]
%194 = call i32 @select(i32 %183, i32* %13, i32* %14, i32* null, %struct.timeval* %193)
store i32 %194, i32* %10
%195 = icmp eq i32 %194, 0
br i1 %195, label %196, label %214
196: ; preds = %192
%197 = load i32, i32* %6
%198 = call i32 @close(i32 %197)
%199 = load i32, i32* %15
%200 = icmp ne i32 %199, 0
br i1 %200, label %201, label %213
201: ; preds = %196
%202 = load i32, i32* @stdout
%203 = load i8**, i8*** %5
%204 = load i64, i64* @optind
%205 = getelementptr inbounds i8*, i8** %203, i64 %204
%206 = load i8*, i8** %205
%207 = load i8**, i8*** %5
%208 = load i64, i64* @optind
%209 = add i64 %208, 1
%210 = getelementptr inbounds i8*, i8** %207, i64 %209
%211 = load i8*, i8** %210
%212 = call i32 (i32, i8*, ...) @fprintf(i32 %202, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %206, i8* %211)
br label %213
213: ; preds = %201, %196
store i32 2, i32* %3
br label %297
214: ; preds = %192
%215 = load i32, i32* %6
%216 = call i64 @FD_ISSET(i32 %215, i32* %13)
%217 = icmp ne i64 %216, 0
br i1 %217, label %222, label %218
218: ; preds = %214
%219 = load i32, i32* %6
%220 = call i64 @FD_ISSET(i32 %219, i32* %14)
%221 = icmp ne i64 %220, 0
br i1 %221, label %222, label %270
222: ; preds = %218, %214
store i32 4, i32* %11
%223 = load i32, i32* %6
%224 = load i32, i32* @SOL_SOCKET
%225 = load i32, i32* @SO_ERROR
%226 = call i32 @getsockopt(i32 %223, i32 %224, i32 %225, i32* %9, i32* %11)
store i32 %226, i32* %10
%227 = icmp ne i32 %226, 0
br i1 %227, label %228, label %248
228: ; preds = %222
%229 = load i32, i32* %15
%230 = icmp ne i32 %229, 0
br i1 %230, label %231, label %245
231: ; preds = %228
%232 = load i32, i32* @stderr
%233 = load i8**, i8*** %5
%234 = load i64, i64* @optind
%235 = getelementptr inbounds i8*, i8** %233, i64 %234
%236 = load i8*, i8** %235
%237 = load i8**, i8*** %5
%238 = load i64, i64* @optind
%239 = add i64 %238, 1
%240 = getelementptr inbounds i8*, i8** %237, i64 %239
%241 = load i8*, i8** %240
%242 = load i64, i64* @errno
%243 = call i8* @strerror(i64 %242)
%244 = call i32 (i32, i8*, ...) @fprintf(i32 %232, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %236, i8* %241, i8* %243)
br label %245
245: ; preds = %231, %228
%246 = load i32, i32* %6
%247 = call i32 @close(i32 %246)
store i32 -1, i32* %3
br label %297
248: ; preds = %222
%249 = load i32, i32* %9
%250 = icmp ne i32 %249, 0
br i1 %250, label %251, label %269
251: ; preds = %248
%252 = load i32, i32* %15
%253 = icmp ne i32 %252, 0
br i1 %253, label %254, label %266
254: ; preds = %251
%255 = load i32, i32* @stdout
%256 = load i8**, i8*** %5
%257 = load i64, i64* @optind
%258 = getelementptr inbounds i8*, i8** %256, i64 %257
%259 = load i8*, i8** %258
%260 = load i8**, i8*** %5
%261 = load i64, i64* @optind
%262 = add i64 %261, 1
%263 = getelementptr inbounds i8*, i8** %260, i64 %262
%264 = load i8*, i8** %263
%265 = call i32 (i32, i8*, ...) @fprintf(i32 %255, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %259, i8* %264)
br label %266
266: ; preds = %254, %251
%267 = load i32, i32* %6
%268 = call i32 @close(i32 %267)
store i32 1, i32* %3
br label %297
269: ; preds = %248
br label %278
270: ; preds = %218
%271 = load i32, i32* %15
%272 = icmp ne i32 %271, 0
br i1 %272, label %273, label %276
273: ; preds = %270
%274 = load i32, i32* @stderr
%275 = call i32 (i32, i8*, ...) @fprintf(i32 %274, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
br label %276
276: ; preds = %273, %270
%277 = call i32 @exit(i32 -1)
unreachable
278: ; preds = %269
br label %279
279: ; preds = %278, %135
%280 = load i32, i32* %6
%281 = call i32 @close(i32 %280)
%282 = load i32, i32* %15
%283 = icmp ne i32 %282, 0
br i1 %283, label %284, label %296
284: ; preds = %279
%285 = load i32, i32* @stdout
%286 = load i8**, i8*** %5
%287 = load i64, i64* @optind
%288 = getelementptr inbounds i8*, i8** %286, i64 %287
%289 = load i8*, i8** %288
%290 = load i8**, i8*** %5
%291 = load i64, i64* @optind
%292 = add i64 %291, 1
%293 = getelementptr inbounds i8*, i8** %290, i64 %292
%294 = load i8*, i8** %293
%295 = call i32 (i32, i8*, ...) @fprintf(i32 %285, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8* %289, i8* %294)
br label %296
296: ; preds = %284, %279
store i32 0, i32* %3
br label %297
297: ; preds = %296, %266, %245, %213, %168
%298 = load i32, i32* %3
ret i32 %298
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.timeval = type { i64, i64 }
%struct.hostent = type { i32, i32, i32* }
%struct.sockaddr = type { i32 }
@.str = [6 x i8] c"qt:u:\00"
@optarg = global i8* null
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@optind = global i64 0
@stderr = global i32 0
@.str.1 = [22 x i8] c"error: host not found\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@errno = global i64 0
@EINPROGRESS = global i64 0
@.str.2 = [23 x i8] c"error: %s port %s: %s\0A\00"
@stdout = global i32 0
@.str.3 = [26 x i8] c"%s port %s user timeout.\0A\00"
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
@.str.4 = [35 x i8] c"error: %s port %s: getsockopt: %s\0A\00"
@.str.5 = [20 x i8] c"%s port %s closed.\0A\00"
@.str.6 = [31 x i8] c"error: select: sockfd not set\0A\00"
@.str.7 = [18 x i8] c"%s port %s open.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.timeval
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = bitcast %struct.sockaddr_in* %3 to i8*
%11 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%12 = bitcast i32* %5 to i8*
%13 = bitcast %struct.timeval* %6 to i8*
%14 = bitcast i32* %7 to i8*
%15 = bitcast i32* %8 to i8*
%16 = bitcast i8** %9 to i8*
%17 = icmp slt i32 %0, 3
br i1 %17, label %25, label %31
18: ; preds = %52
%19 = ptrtoint i8* %54 to i64
br label %22
20: ; preds = %45
%21 = ptrtoint i8* %47 to i64
br label %22
22: ; preds = %18, %42, %20
%23 = phi i64 [ %21, %20 ], [ %40, %42 ], [ %40, %18 ]
%24 = phi i64 [ %43, %20 ], [ %19, %18 ], [ %43, %42 ]
br label %25
25: ; preds = %22, %2
%26 = phi i32 [ 1, %2 ], [ %36, %22 ]
%27 = phi i64 [ 0, %2 ], [ %23, %22 ]
%28 = phi i64 [ 0, %2 ], [ %24, %22 ]
%29 = load i8*, i8** %1
%30 = tail call i32 @usage(i8* %29)
br label %31
31: ; preds = %2, %25
%32 = phi i32 [ %26, %25 ], [ 1, %2 ]
%33 = phi i64 [ %27, %25 ], [ 0, %2 ]
%34 = phi i64 [ %28, %25 ], [ 0, %2 ]
br label %35
35: ; preds = %42, %31
%36 = phi i32 [ %32, %31 ], [ 0, %42 ]
%37 = phi i64 [ %33, %31 ], [ %40, %42 ]
%38 = phi i64 [ %34, %31 ], [ %43, %42 ]
br label %39
39: ; preds = %35, %45
%40 = phi i64 [ %37, %35 ], [ %48, %45 ]
%41 = phi i64 [ %38, %35 ], [ %43, %45 ]
br label %42
42: ; preds = %39, %52
%43 = phi i64 [ %55, %52 ], [ %41, %39 ]
%44 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
switch i32 %44, label %22 [
i32 -1, label %59
i32 113, label %35
i32 116, label %45
i32 117, label %52
]
45: ; preds = %42
store i8* null, i8** %9
%46 = load i8*, i8** @optarg
%47 = call i8* @strtol(i8* %46, i8** %9, i32 10)
%48 = ptrtoint i8* %47 to i64
%49 = load i8*, i8** %9
%50 = load i8*, i8** @optarg
%51 = icmp eq i8* %49, %50
br i1 %51, label %20, label %39
52: ; preds = %42
store i8* null, i8** %9
%53 = load i8*, i8** @optarg
%54 = call i8* @strtol(i8* %53, i8** %9, i32 10)
%55 = ptrtoint i8* %54 to i64
%56 = load i8*, i8** %9
%57 = load i8*, i8** @optarg
%58 = icmp eq i8* %56, %57
br i1 %58, label %18, label %42
59: ; preds = %42
%60 = load i32, i32* @AF_INET
%61 = load i32, i32* @SOCK_STREAM
%62 = tail call i32 @socket(i32 %60, i32 %61, i32 0)
%63 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%64 = load i64, i64* @optind
%65 = getelementptr inbounds i8*, i8** %1, i64 %64
%66 = load i8*, i8** %65
%67 = call %struct.hostent* @gethostbyname(i8* %66)
%68 = icmp eq %struct.hostent* %67, null
br i1 %68, label %69, label %76
69: ; preds = %59
%70 = icmp eq i32 %36, 0
br i1 %70, label %74, label %71
71: ; preds = %69
%72 = load i32, i32* @stderr
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %74
74: ; preds = %71, %69
%75 = call i32 @exit(i32 -1)
unreachable
76: ; preds = %59
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
%78 = getelementptr inbounds %struct.hostent, %struct.hostent* %67, i64 0, i32 2
%79 = load i32*, i32** %78
%80 = load i32, i32* %79
%81 = getelementptr inbounds %struct.hostent, %struct.hostent* %67, i64 0, i32 1
%82 = load i32, i32* %81
%83 = call i32 @memcpy(i32* %77, i32 %80, i32 %82)
%84 = getelementptr inbounds %struct.hostent, %struct.hostent* %67, i64 0, i32 0
%85 = load i32, i32* %84
%86 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %85, i32* %86
%87 = load i64, i64* @optind
%88 = add i64 %87, 1
%89 = getelementptr inbounds i8*, i8** %1, i64 %88
%90 = load i8*, i8** %89
%91 = icmp eq i8* %90, null
br i1 %91, label %102, label %92
92: ; preds = %76
store i8* null, i8** %9
%93 = call i8* @strtol(i8* %90, i8** %9, i32 10)
%94 = ptrtoint i8* %93 to i64
%95 = trunc i64 %94 to i32
%96 = load i8*, i8** %9
%97 = load i64, i64* @optind
%98 = add i64 %97, 1
%99 = getelementptr inbounds i8*, i8** %1, i64 %98
%100 = load i8*, i8** %99
%101 = icmp eq i8* %96, %100
br i1 %101, label %102, label %106
102: ; preds = %76, %92
%103 = phi i32 [ %95, %92 ], [ 0, %76 ]
%104 = load i8*, i8** %1
%105 = call i32 @usage(i8* %104)
br label %106
106: ; preds = %102, %92
%107 = phi i32 [ %95, %92 ], [ %103, %102 ]
%108 = call i32 @htons(i32 %107)
%109 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %108, i32* %109
%110 = load i32, i32* @F_SETFL
%111 = load i32, i32* @O_NONBLOCK
%112 = call i32 @fcntl(i32 %62, i32 %110, i32 %111)
%113 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%114 = call i32 @connect(i32 %62, %struct.sockaddr* %113, i32 12)
%115 = icmp eq i32 %114, 0
br i1 %115, label %208, label %116
116: ; preds = %106
%117 = load i64, i64* @errno
%118 = load i64, i64* @EINPROGRESS
%119 = icmp eq i64 %117, %118
br i1 %119, label %132, label %120
120: ; preds = %116
%121 = icmp eq i32 %36, 0
br i1 %121, label %220, label %122
122: ; preds = %120
%123 = load i32, i32* @stderr
%124 = load i64, i64* @optind
%125 = getelementptr inbounds i8*, i8** %1, i64 %124
%126 = load i8*, i8** %125
%127 = add i64 %124, 1
%128 = getelementptr inbounds i8*, i8** %1, i64 %127
%129 = load i8*, i8** %128
%130 = call i8* @strerror(i64 %117)
%131 = call i32 (i32, i8*, ...) @fprintf(i32 %123, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %126, i8* %129, i8* %130)
br label %220
132: ; preds = %116
%133 = call i32 @FD_ZERO(i32* %7)
%134 = call i32 @FD_SET(i32 %62, i32* %7)
%135 = load i32, i32* %7
store i32 %135, i32* %8
%136 = sdiv i64 %43, 1000000
%137 = add nsw i64 %136, %40
%138 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
store i64 %137, i64* %138
%139 = srem i64 %43, 1000000
%140 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
store i64 %139, i64* %140
%141 = add nsw i32 %62, 1
%142 = add nsw i64 %137, %139
%143 = icmp sgt i64 %142, 0
%144 = select i1 %143, %struct.timeval* %6, %struct.timeval* null
%145 = call i32 @select(i32 %141, i32* %7, i32* %8, i32* null, %struct.timeval* %144)
%146 = icmp eq i32 %145, 0
br i1 %146, label %147, label %159
147: ; preds = %132
%148 = call i32 @close(i32 %62)
%149 = icmp eq i32 %36, 0
br i1 %149, label %220, label %150
150: ; preds = %147
%151 = load i32, i32* @stdout
%152 = load i64, i64* @optind
%153 = getelementptr inbounds i8*, i8** %1, i64 %152
%154 = load i8*, i8** %153
%155 = add i64 %152, 1
%156 = getelementptr inbounds i8*, i8** %1, i64 %155
%157 = load i8*, i8** %156
%158 = call i32 (i32, i8*, ...) @fprintf(i32 %151, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %154, i8* %157)
br label %220
159: ; preds = %132
%160 = call i64 @FD_ISSET(i32 %62, i32* %7)
%161 = icmp eq i64 %160, 0
br i1 %161, label %162, label %165
162: ; preds = %159
%163 = call i64 @FD_ISSET(i32 %62, i32* %8)
%164 = icmp eq i64 %163, 0
br i1 %164, label %201, label %165
165: ; preds = %162, %159
store i32 4, i32* %5
%166 = load i32, i32* @SOL_SOCKET
%167 = load i32, i32* @SO_ERROR
%168 = call i32 @getsockopt(i32 %62, i32 %166, i32 %167, i32* %4, i32* %5)
%169 = icmp eq i32 %168, 0
br i1 %169, label %185, label %170
170: ; preds = %165
%171 = icmp eq i32 %36, 0
br i1 %171, label %183, label %172
172: ; preds = %170
%173 = load i32, i32* @stderr
%174 = load i64, i64* @optind
%175 = getelementptr inbounds i8*, i8** %1, i64 %174
%176 = load i8*, i8** %175
%177 = add i64 %174, 1
%178 = getelementptr inbounds i8*, i8** %1, i64 %177
%179 = load i8*, i8** %178
%180 = load i64, i64* @errno
%181 = call i8* @strerror(i64 %180)
%182 = call i32 (i32, i8*, ...) @fprintf(i32 %173, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %176, i8* %179, i8* %181)
br label %183
183: ; preds = %172, %170
%184 = call i32 @close(i32 %62)
br label %220
185: ; preds = %165
%186 = load i32, i32* %4
%187 = icmp eq i32 %186, 0
br i1 %187, label %208, label %188
188: ; preds = %185
%189 = icmp eq i32 %36, 0
br i1 %189, label %199, label %190
190: ; preds = %188
%191 = load i32, i32* @stdout
%192 = load i64, i64* @optind
%193 = getelementptr inbounds i8*, i8** %1, i64 %192
%194 = load i8*, i8** %193
%195 = add i64 %192, 1
%196 = getelementptr inbounds i8*, i8** %1, i64 %195
%197 = load i8*, i8** %196
%198 = call i32 (i32, i8*, ...) @fprintf(i32 %191, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %194, i8* %197)
br label %199
199: ; preds = %190, %188
%200 = call i32 @close(i32 %62)
br label %220
201: ; preds = %162
%202 = icmp eq i32 %36, 0
br i1 %202, label %206, label %203
203: ; preds = %201
%204 = load i32, i32* @stderr
%205 = call i32 (i32, i8*, ...) @fprintf(i32 %204, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
br label %206
206: ; preds = %203, %201
%207 = call i32 @exit(i32 -1)
unreachable
208: ; preds = %185, %106
%209 = call i32 @close(i32 %62)
%210 = icmp eq i32 %36, 0
br i1 %210, label %220, label %211
211: ; preds = %208
%212 = load i32, i32* @stdout
%213 = load i64, i64* @optind
%214 = getelementptr inbounds i8*, i8** %1, i64 %213
%215 = load i8*, i8** %214
%216 = add i64 %213, 1
%217 = getelementptr inbounds i8*, i8** %1, i64 %216
%218 = load i8*, i8** %217
%219 = call i32 (i32, i8*, ...) @fprintf(i32 %212, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8* %215, i8* %218)
br label %220
220: ; preds = %208, %211, %147, %150, %120, %122, %199, %183
%221 = phi i32 [ -1, %183 ], [ 1, %199 ], [ -1, %122 ], [ -1, %120 ], [ 2, %150 ], [ 2, %147 ], [ 0, %211 ], [ 0, %208 ]
ret i32 %221
}