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

/* Forward declarations */

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct in_addr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr_list;
};
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char const *);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr const *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
struct hostent *gethostbyname(char const *);
int getopt(int, char **const, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ isdigit(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, struct in_addr *, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
char *optarg;
size_t optind;
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ usage();
int write(int, char *, int);
int main(int argc, char **argv) {
  int i, l;
  int fd = -1;
  int presize = 0;
  int port = 0;
  int cutlf = 1;
  char *cp, *mp, *bod;
  char *prepend = NULL;
  struct sockaddr_in server;
  struct in_addr **list;
  struct hostent *host;
  FILE *f;
  while ((i = getopt(argc, (char **const)argv, "hni:v")) != EOF) {
    switch (i) {
    case 'h':
      usage();
      break;
    case 'i':
      prepend = optarg;
      presize = strlen(prepend) + 1;
      break;
    case 'n':
      cutlf = 0;
      break;
    case 'v':
      (void)fprintf(stderr, "version 0.2\n");
      exit(EXIT_SUCCESS);
      break;
    default:
      usage();
      break;
    }
  }
  if (argv[optind] == NULL)
    usage();
  cp = argv[optind];
  while (*cp != '\0') {
    if (*cp == ':')
      break;
    cp++;
  }
  if (*cp == ':') {
    *cp = '\0';
    cp++;
    mp = cp;
    while (*cp != '\0') {
      if (!isdigit((int)*cp))
        usage();
      cp++;
    }
    port = atoi((const char *)mp);
    if (port < 1 || port > 65535) {
      (void)fprintf(stderr, "Invalid port\n");
      exit(EXIT_FAILURE);
    }
  } else
    usage();
  if ((host = gethostbyname((const char *)argv[optind])) == NULL) {
    (void)fprintf(stderr, "Unknown host: %s\n", argv[optind]);
    exit(EXIT_FAILURE);
  }
  list = (struct in_addr **)host->h_addr_list;
  while (*list != NULL) {
    if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
      (void)perror("Unable to create socket");
      exit(EXIT_FAILURE);
    }
    memset(&server, 0, sizeof(server));
    server.sin_family = AF_INET;
    server.sin_port = htons(port);
    memcpy(&server.sin_addr, *list, sizeof(struct in_addr));
    if (connect(fd, (const struct sockaddr *)&server, sizeof(server)) == 0)
      break;
    close(fd);
    list++;
  }
  if (list == NULL) {
    (void)fprintf(stderr, "Unable to connect\n");
    exit(EXIT_FAILURE);
  }
  if ((mp = (char *)malloc(65536)) == NULL) {
    (void)fprintf(stderr, "Out of memory\n");
    exit(EXIT_FAILURE);
  }
  if (prepend == NULL) {
    bod = mp;
  } else {
    strcpy(mp, prepend);
    *(mp + presize - 1) = ' ';
    bod = mp + presize;
  }
  optind++;
  if (argv[optind] == NULL) {
    i = 65536 - presize;
    while (fgets(bod, i, stdin) != NULL) {
      l = strlen(bod);
      if (cutlf) {
        if (*(bod + l - 1) == '\n')
          l--;
      }
      if (l < 1)
        continue;
      *(bod + l) = '\0';
      l += presize;
      if (write(fd, mp, l) != l) {
        (void)perror("Unable to transmit data");
        exit(EXIT_FAILURE);
      }
    }
  } else {
    while (argv[optind] != NULL) {
      if ((f = fopen(argv[optind], "r")) == NULL) {
        (void)perror(argv[optind]);
        exit(EXIT_FAILURE);
      }
      i = 65536 - presize;
      while (fgets(bod, i, f) != NULL) {
        l = strlen(bod);
        if (cutlf) {
          if (*(bod + l - 1) == '\n')
            l--;
        }
        if (l < 1)
          continue;
        *(bod + l) = '\0';
        l += presize;
        if (write(fd, mp, l) != l) {
          (void)perror("Unable to transmit data");
          exit(EXIT_FAILURE);
        }
      }
      if (!feof(f))
        (void)perror(argv[optind]);
      (void)fclose(f);
      optind++;
    }
  }
  free(mp);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd81(%rip),%rdx
call   1150 <getopt@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d06(%rip),%rcx
cmp    (%rcx),%eax
je     1366 <main+0xf6>
mov    -0x14(%rbp),%eax
add    $0xffffff98,%eax
mov    %eax,%ecx
mov    %rcx,-0x78(%rbp)
sub    $0xe,%eax
ja     135a <main+0xea>
mov    -0x78(%rbp),%rax
lea    0xd0e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1120 <usage@plt>
jmp    1361 <main+0xf1>
mov    0x2cea(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1080 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1361 <main+0xf1>
movl   $0x0,-0x28(%rbp)
jmp    1361 <main+0xf1>
mov    0x2c74(%rip),%rax
mov    (%rax),%edi
lea    0xcfd(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x2c4d(%rip),%rax
mov    (%rax),%edi
call   1170 <exit@plt>
mov    $0x0,%al
call   1120 <usage@plt>
jmp    12ad <main+0x3d>
mov    -0x10(%rbp),%rax
mov    0x2c4f(%rip),%rcx
mov    (%rcx),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    1386 <main+0x116>
mov    $0x0,%al
call   1120 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x2c2f(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     13d2 <main+0x162>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    13c1 <main+0x151>
jmp    13d2 <main+0x162>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    139c <main+0x12c>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1487 <main+0x217>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     143a <main+0x1ca>
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    1429 <main+0x1b9>
mov    $0x0,%al
call   1120 <usage@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    13fd <main+0x18d>
mov    -0x38(%rbp),%rdi
call   1160 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jl     145d <main+0x1ed>
cmpl   $0xffff,-0x24(%rbp)
jle    1482 <main+0x212>
mov    0x2b4c(%rip),%rax
mov    (%rax),%edi
lea    0xbe2(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x2b2d(%rip),%rax
mov    (%rax),%edi
call   1170 <exit@plt>
jmp    148e <main+0x21e>
mov    $0x0,%al
call   1120 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x2b27(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   10d0 <gethostbyname@plt>
mov    %rax,-0x68(%rbp)
cmp    $0x0,%rax
jne    14ea <main+0x27a>
mov    0x2af6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x2af9(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xb88(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x2ac5(%rip),%rax
mov    (%rax),%edi
call   1170 <exit@plt>
mov    -0x68(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
cmpq   $0x0,(%rax)
je     15b7 <main+0x347>
mov    0x2ad6(%rip),%rax
mov    (%rax),%edi
mov    0x2ab5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1190 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1542 <main+0x2d2>
lea    0xb40(%rip),%rdi
call   1140 <perror@plt>
mov    0x2a6d(%rip),%rax
mov    (%rax),%edi
call   1170 <exit@plt>
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    0x2a87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    -0x24(%rbp),%edi
call   1090 <htons@plt>
mov    %eax,-0x54(%rbp)
lea    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%rax
mov    (%rax),%rsi
mov    $0x4,%edx
call   1100 <memcpy@plt>
mov    -0x1c(%rbp),%edi
lea    -0x58(%rbp),%rsi
mov    $0xc,%edx
call   1180 <connect@plt>
cmp    $0x0,%rax
jne    159e <main+0x32e>
jmp    15b7 <main+0x347>
mov    -0x1c(%rbp),%edi
call   10b0 <close@plt>
mov    -0x60(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x60(%rbp)
jmp    14f5 <main+0x285>
cmpq   $0x0,-0x60(%rbp)
jne    15e7 <main+0x377>
mov    0x29e7(%rip),%rax
mov    (%rax),%edi
lea    0xab5(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x29c8(%rip),%rax
mov    (%rax),%edi
call   1170 <exit@plt>
mov    $0x10000,%edi
call   1110 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1624 <main+0x3b4>
mov    0x29aa(%rip),%rax
mov    (%rax),%edi
lea    0xa8b(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    0x298b(%rip),%rax
mov    (%rax),%edi
call   1170 <exit@plt>
cmpq   $0x0,-0x48(%rbp)
jne    163c <main+0x3cc>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1665 <main+0x3f5>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x38(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x20,-0x1(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
movslq -0x20(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    0x2954(%rip),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    0x2946(%rip),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x2938(%rip),%rcx
mov    (%rcx),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    175b <main+0x4eb>
mov    $0x10000,%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2929(%rip),%rax
mov    (%rax),%rdx
call   10c0 <fgets@plt>
cmp    $0x0,%rax
je     1756 <main+0x4e6>
mov    -0x40(%rbp),%rdi
call   1080 <strlen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     16fb <main+0x48b>
mov    -0x40(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl -0x1(%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    16f6 <main+0x486>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    16fb <main+0x48b>
cmpl   $0x1,-0x18(%rbp)
jge    170a <main+0x49a>
jmp    16a1 <main+0x431>
mov    -0x40(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1060 <write@plt>
cmp    -0x18(%rbp),%eax
je     1751 <main+0x4e1>
lea    0x96b(%rip),%rdi
call   1140 <perror@plt>
mov    0x285e(%rip),%rax
mov    (%rax),%edi
call   1170 <exit@plt>
jmp    16a1 <main+0x431>
jmp    18d8 <main+0x668>
jmp    1760 <main+0x4f0>
mov    -0x10(%rbp),%rax
mov    0x2855(%rip),%rcx
mov    (%rcx),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     18d3 <main+0x663>
mov    -0x10(%rbp),%rax
mov    0x283c(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0x92f(%rip),%rsi
call   1130 <fopen@plt>
mov    %rax,-0x70(%rbp)
cmp    $0x0,%rax
jne    17ca <main+0x55a>
mov    -0x10(%rbp),%rax
mov    0x2810(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1140 <perror@plt>
mov    0x27e5(%rip),%rax
mov    (%rax),%edi
call   1170 <exit@plt>
mov    $0x10000,%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x70(%rbp),%rdx
call   10c0 <fgets@plt>
cmp    $0x0,%rax
je     1884 <main+0x614>
mov    -0x40(%rbp),%rdi
call   1080 <strlen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1829 <main+0x5b9>
mov    -0x40(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl -0x1(%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1824 <main+0x5b4>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1829 <main+0x5b9>
cmpl   $0x1,-0x18(%rbp)
jge    1838 <main+0x5c8>
jmp    17d5 <main+0x565>
mov    -0x40(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1060 <write@plt>
cmp    -0x18(%rbp),%eax
je     187f <main+0x60f>
lea    0x83d(%rip),%rdi
call   1140 <perror@plt>
mov    0x2730(%rip),%rax
mov    (%rax),%edi
call   1170 <exit@plt>
jmp    17d5 <main+0x565>
mov    -0x70(%rbp),%rdi
call   10f0 <feof@plt>
cmp    $0x0,%eax
jne    18ad <main+0x63d>
mov    -0x10(%rbp),%rax
mov    0x271f(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1140 <perror@plt>
mov    -0x70(%rbp),%rdi
call   1070 <fclose@plt>
mov    0x2703(%rip),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    0x26f5(%rip),%rax
mov    %rcx,(%rax)
jmp    1760 <main+0x4f0>
jmp    18d8 <main+0x668>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x26b8(%rip),%rax
mov    (%rax),%edi
call   1170 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,0x10(%rsp)
mov    %edi,%ebx
lea    0xdc0(%rip),%rdx
call   1140 <getopt@plt>
mov    0x2d48(%rip),%r15
cmp    (%r15),%eax
jne    1327 <main+0xc7>
mov    $0x1,%r13d
xor    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %eax,%eax
mov    %rax,0x20(%rsp)
mov    0x2d14(%rip),%r15
mov    (%r15),%rax
mov    0x10(%rsp),%rbp
mov    0x0(%rbp,%rax,8),%rbx
test   %rbx,%rbx
jne    12d0 <main+0x70>
xor    %eax,%eax
call   1110 <usage@plt>
mov    (%r15),%rax
mov    0x0(%rbp,%rax,8),%rbx
nopl   (%rax)
add    $0x1,%rbx
movzbl -0x1(%rbx),%eax
test   %al,%al
je     13a7 <main+0x147>
cmp    $0x3a,%al
jne    12d0 <main+0x70>
movb   $0x0,-0x1(%rbx)
mov    (%rbx),%al
test   %al,%al
jne    14b7 <main+0x257>
mov    %rbx,%rdi
call   1150 <atoi@plt>
mov    %eax,%r14d
add    $0xffff0000,%eax
cmp    $0xffff0000,%eax
mov    0x10(%rsp),%rbp
ja     13b1 <main+0x151>
mov    0x2c97(%rip),%rax
mov    (%rax),%edi
lea    0xd2d(%rip),%rsi
jmp    14ab <main+0x24b>
mov    $0x1,%r14d
lea    0xd08(%rip),%rbp
lea    0xcc5(%rip),%r12
xor    %ecx,%ecx
mov    %rcx,0x20(%rsp)
xor    %ecx,%ecx
mov    %rcx,0x8(%rsp)
jmp    1375 <main+0x115>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1110 <usage@plt>
mov    %r14d,%r13d
mov    %ebx,%edi
mov    0x10(%rsp),%rsi
mov    %rbp,%rdx
call   1140 <getopt@plt>
mov    %r13d,%r14d
cmp    (%r15),%eax
je     12a5 <main+0x45>
add    $0xffffff98,%eax
cmp    $0xe,%eax
ja     1350 <main+0xf0>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
xor    %r13d,%r13d
jmp    *%rax
mov    0x2c68(%rip),%rax
mov    (%rax),%rdi
mov    %rdi,0x20(%rsp)
call   1070 <strlen@plt>
add    $0x1,%eax
mov    %rax,0x8(%rsp)
jmp    1357 <main+0xf7>
xor    %r14d,%r14d
xor    %eax,%eax
call   1110 <usage@plt>
mov    (%r15),%rax
mov    0x0(%rbp,%rax,8),%rdi
call   10c0 <gethostbyname@plt>
test   %rax,%rax
jne    13e7 <main+0x187>
mov    0x2be6(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rax
mov    0x0(%rbp,%rax,8),%rdx
lea    0xc82(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
jmp    16dd <main+0x47d>
mov    (%rax),%rbp
mov    $0xffffffff,%r15d
cmpq   $0x0,0x0(%rbp)
je     148c <main+0x22c>
add    $0x8,%rbp
mov    0x2bda(%rip),%r12
lea    0x28(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    0x2bad(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
cmp    $0xffffffff,%eax
je     16d1 <main+0x471>
mov    %eax,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x30(%rsp)
mov    %r14d,%edi
call   1080 <htons@plt>
mov    %eax,0x2c(%rsp)
mov    -0x8(%rbp),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   10f0 <memcpy@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1170 <connect@plt>
test   %rax,%rax
je     148c <main+0x22c>
mov    %r15d,%edi
call   10a0 <close@plt>
cmpq   $0x0,0x0(%rbp)
lea    0x8(%rbp),%rbp
jne    1410 <main+0x1b0>
mov    $0x10000,%edi
call   1100 <malloc@plt>
test   %rax,%rax
jne    14e4 <main+0x284>
mov    0x2b0e(%rip),%rax
mov    (%rax),%edi
lea    0xbdc(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
jmp    16dd <main+0x47d>
lea    0x1(%rbx),%rbp
jmp    14d0 <main+0x270>
nopl   (%rax)
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
je     12f2 <main+0x92>
movsbl %al,%eax
add    $0xffffffd0,%eax
cmp    $0xa,%eax
jb     14c0 <main+0x260>
xor    %eax,%eax
call   1110 <usage@plt>
jmp    14c0 <main+0x260>
mov    %rax,%r12
mov    %rax,%rbx
mov    0x20(%rsp),%rsi
test   %rsi,%rsi
je     150d <main+0x2ad>
mov    %r12,%rdi
call   1040 <strcpy@plt>
movslq 0x8(%rsp),%rax
mov    %r12,%rbx
add    %rax,%rbx
movb   $0x20,-0x1(%r12,%rax,1)
mov    0x2aac(%rip),%rdx
mov    (%rdx),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rdx)
mov    0x10(%rsp),%rbp
mov    0x8(%rbp,%rax,8),%rdi
mov    $0x10000,%r14d
sub    0x8(%rsp),%r14d
test   %rdi,%rdi
mov    %r12,0x18(%rsp)
jne    160c <main+0x3ac>
mov    %r14d,%esi
mov    0x2a8d(%rip),%r12
mov    (%r12),%rdx
mov    %rbx,%rdi
jmp    156a <main+0x30a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
call   10b0 <fgets@plt>
test   %rax,%rax
je     16b9 <main+0x459>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebp
test   %r13d,%r13d
je     1596 <main+0x336>
movslq %ebp,%rax
xor    %ecx,%ecx
cmpb   $0xa,-0x1(%rbx,%rax,1)
sete   %cl
sub    %ecx,%ebp
test   %ebp,%ebp
jle    1560 <main+0x300>
mov    %ebp,%eax
movb   $0x0,(%rbx,%rax,1)
add    0x8(%rsp),%ebp
mov    %r15d,%edi
mov    0x18(%rsp),%rsi
mov    %ebp,%edx
call   1050 <write@plt>
cmp    %ebp,%eax
je     1560 <main+0x300>
lea    0xad8(%rip),%rdi
jmp    16d8 <main+0x478>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
call   10e0 <feof@plt>
test   %eax,%eax
mov    0x10(%rsp),%rbp
je     1687 <main+0x427>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    0x29cc(%rip),%rdx
mov    (%rdx),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rdx)
mov    0x8(%rbp,%rax,8),%rdi
test   %rdi,%rdi
je     16b9 <main+0x459>
lea    0xa9b(%rip),%rsi
call   1120 <fopen@plt>
test   %rax,%rax
je     16eb <main+0x48b>
mov    %rax,%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r12,%rdx
call   10b0 <fgets@plt>
test   %rax,%rax
je     15d0 <main+0x370>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebp
test   %r13d,%r13d
je     1661 <main+0x401>
movslq %ebp,%rax
xor    %ecx,%ecx
cmpb   $0xa,-0x1(%rbx,%rax,1)
sete   %cl
sub    %ecx,%ebp
test   %ebp,%ebp
jle    1630 <main+0x3d0>
mov    %ebp,%eax
movb   $0x0,(%rbx,%rax,1)
add    0x8(%rsp),%ebp
mov    %r15d,%edi
mov    0x18(%rsp),%rsi
mov    %ebp,%edx
call   1050 <write@plt>
cmp    %ebp,%eax
je     1630 <main+0x3d0>
jmp    15b7 <main+0x357>
mov    0x2932(%rip),%rax
mov    (%rax),%rax
mov    0x0(%rbp,%rax,8),%rdi
call   1130 <perror@plt>
jmp    15e5 <main+0x385>
mov    0x2909(%rip),%rax
mov    (%rax),%edi
lea    0x992(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
jmp    16c3 <main+0x463>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x28d6(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
lea    0x997(%rip),%rdi
call   1130 <perror@plt>
mov    0x28c4(%rip),%rax
mov    (%rax),%edi
call   1160 <exit@plt>
mov    0x28ce(%rip),%rax
mov    (%rax),%rax
mov    0x0(%rbp,%rax,8),%rdi
jmp    16d8 <main+0x478>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [6 x i8] c"hni:v\00"
@EOF = global i32 0
@optarg = global i8* null
@stderr = global i32 0
@.str.1 = [13 x i8] c"version 0.2\0A\00"
@EXIT_SUCCESS = global i32 0
@optind = global i64 0
@.str.2 = [14 x i8] c"Invalid port\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [18 x i8] c"Unknown host: %s\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.4 = [24 x i8] c"Unable to create socket\00"
@.str.5 = [19 x i8] c"Unable to connect\0A\00"
@.str.6 = [15 x i8] c"Out of memory\0A\00"
@stdin = global i32* null
@.str.7 = [24 x i8] c"Unable to transmit data\00"
@.str.8 = [2 x i8] c"r\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 i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca %struct.sockaddr_in
%17 = alloca %struct.in_addr**
%18 = alloca %struct.hostent*
%19 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 1, i32* %11
store i8* null, i8** %15
br label %20
20: ; preds = %43, %2
%21 = load i32, i32* %4
%22 = load i8**, i8*** %5
%23 = call i32 @getopt(i32 %21, i8** %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %23, i32* %6
%24 = load i32, i32* @EOF
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %44
26: ; preds = %20
%27 = load i32, i32* %6
switch i32 %27, label %41 [
i32 104, label %28
i32 105, label %30
i32 110, label %35
i32 118, label %36
]
28: ; preds = %26
%29 = call i32 (...) @usage()
br label %43
30: ; preds = %26
%31 = load i8*, i8** @optarg
store i8* %31, i8** %15
%32 = load i8*, i8** %15
%33 = call i32 @strlen(i8* %32)
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %43
35: ; preds = %26
store i32 0, i32* %11
br label %43
36: ; preds = %26
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%39 = load i32, i32* @EXIT_SUCCESS
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %26
%42 = call i32 (...) @usage()
br label %43
43: ; preds = %41, %35, %30, %28
br label %20
44: ; preds = %20
%45 = load i8**, i8*** %5
%46 = load i64, i64* @optind
%47 = getelementptr inbounds i8*, i8** %45, i64 %46
%48 = load i8*, i8** %47
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %52
50: ; preds = %44
%51 = call i32 (...) @usage()
br label %52
52: ; preds = %50, %44
%53 = load i8**, i8*** %5
%54 = load i64, i64* @optind
%55 = getelementptr inbounds i8*, i8** %53, i64 %54
%56 = load i8*, i8** %55
store i8* %56, i8** %12
br label %57
57: ; preds = %68, %52
%58 = load i8*, i8** %12
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %71
62: ; preds = %57
%63 = load i8*, i8** %12
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 58
br i1 %66, label %67, label %68
67: ; preds = %62
br label %71
68: ; preds = %62
%69 = load i8*, i8** %12
%70 = getelementptr inbounds i8, i8* %69, i32 1
store i8* %70, i8** %12
br label %57
71: ; preds = %67, %57
%72 = load i8*, i8** %12
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp eq i32 %74, 58
br i1 %75, label %76, label %111
76: ; preds = %71
%77 = load i8*, i8** %12
store i8 0, i8* %77
%78 = load i8*, i8** %12
%79 = getelementptr inbounds i8, i8* %78, i32 1
store i8* %79, i8** %12
%80 = load i8*, i8** %12
store i8* %80, i8** %13
br label %81
81: ; preds = %94, %76
%82 = load i8*, i8** %12
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %97
86: ; preds = %81
%87 = load i8*, i8** %12
%88 = load i8, i8* %87
%89 = sext i8 %88 to i32
%90 = call i32 @isdigit(i32 %89)
%91 = icmp ne i32 %90, 0
br i1 %91, label %94, label %92
92: ; preds = %86
%93 = call i32 (...) @usage()
br label %94
94: ; preds = %92, %86
%95 = load i8*, i8** %12
%96 = getelementptr inbounds i8, i8* %95, i32 1
store i8* %96, i8** %12
br label %81
97: ; preds = %81
%98 = load i8*, i8** %13
%99 = call i32 @atoi(i8* %98)
store i32 %99, i32* %10
%100 = load i32, i32* %10
%101 = icmp slt i32 %100, 1
br i1 %101, label %105, label %102
102: ; preds = %97
%103 = load i32, i32* %10
%104 = icmp sgt i32 %103, 65535
br i1 %104, label %105, label %110
105: ; preds = %102, %97
%106 = load i32, i32* @stderr
%107 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%108 = load i32, i32* @EXIT_FAILURE
%109 = call i32 @exit(i32 %108)
unreachable
110: ; preds = %102
br label %113
111: ; preds = %71
%112 = call i32 (...) @usage()
br label %113
113: ; preds = %111, %110
%114 = load i8**, i8*** %5
%115 = load i64, i64* @optind
%116 = getelementptr inbounds i8*, i8** %114, i64 %115
%117 = load i8*, i8** %116
%118 = call %struct.hostent* @gethostbyname(i8* %117)
store %struct.hostent* %118, %struct.hostent** %18
%119 = icmp eq %struct.hostent* %118, null
br i1 %119, label %120, label %129
120: ; preds = %113
%121 = load i32, i32* @stderr
%122 = load i8**, i8*** %5
%123 = load i64, i64* @optind
%124 = getelementptr inbounds i8*, i8** %122, i64 %123
%125 = load i8*, i8** %124
%126 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %125)
%127 = load i32, i32* @EXIT_FAILURE
%128 = call i32 @exit(i32 %127)
unreachable
129: ; preds = %113
%130 = load %struct.hostent*, %struct.hostent** %18
%131 = getelementptr inbounds %struct.hostent, %struct.hostent* %130, i32 0, i32 0
%132 = load i64, i64* %131
%133 = inttoptr i64 %132 to %struct.in_addr**
store %struct.in_addr** %133, %struct.in_addr*** %17
br label %134
134: ; preds = %163, %129
%135 = load %struct.in_addr**, %struct.in_addr*** %17
%136 = load %struct.in_addr*, %struct.in_addr** %135
%137 = icmp ne %struct.in_addr* %136, null
br i1 %137, label %138, label %168
138: ; preds = %134
%139 = load i32, i32* @AF_INET
%140 = load i32, i32* @SOCK_DGRAM
%141 = call i32 @socket(i32 %139, i32 %140, i32 0)
store i32 %141, i32* %8
%142 = icmp eq i32 %141, -1
br i1 %142, label %143, label %147
143: ; preds = %138
%144 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%145 = load i32, i32* @EXIT_FAILURE
%146 = call i32 @exit(i32 %145)
unreachable
147: ; preds = %138
%148 = call i32 @memset(%struct.sockaddr_in* %16, i32 0, i32 12)
%149 = load i32, i32* @AF_INET
%150 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 2
store i32 %149, i32* %150
%151 = load i32, i32* %10
%152 = call i32 @htons(i32 %151)
%153 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 1
store i32 %152, i32* %153
%154 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 0
%155 = load %struct.in_addr**, %struct.in_addr*** %17
%156 = load %struct.in_addr*, %struct.in_addr** %155
%157 = call i32 @memcpy(i32* %154, %struct.in_addr* %156, i32 4)
%158 = load i32, i32* %8
%159 = bitcast %struct.sockaddr_in* %16 to %struct.sockaddr*
%160 = call i64 @connect(i32 %158, %struct.sockaddr* %159, i32 12)
%161 = icmp eq i64 %160, 0
br i1 %161, label %162, label %163
162: ; preds = %147
br label %168
163: ; preds = %147
%164 = load i32, i32* %8
%165 = call i32 @close(i32 %164)
%166 = load %struct.in_addr**, %struct.in_addr*** %17
%167 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %166, i32 1
store %struct.in_addr** %167, %struct.in_addr*** %17
br label %134
168: ; preds = %162, %134
%169 = load %struct.in_addr**, %struct.in_addr*** %17
%170 = icmp eq %struct.in_addr** %169, null
br i1 %170, label %171, label %176
171: ; preds = %168
%172 = load i32, i32* @stderr
%173 = call i32 (i32, i8*, ...) @fprintf(i32 %172, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%174 = load i32, i32* @EXIT_FAILURE
%175 = call i32 @exit(i32 %174)
unreachable
176: ; preds = %168
%177 = call i64 @malloc(i32 65536)
%178 = inttoptr i64 %177 to i8*
store i8* %178, i8** %13
%179 = icmp eq i8* %178, null
br i1 %179, label %180, label %185
180: ; preds = %176
%181 = load i32, i32* @stderr
%182 = call i32 (i32, i8*, ...) @fprintf(i32 %181, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%183 = load i32, i32* @EXIT_FAILURE
%184 = call i32 @exit(i32 %183)
unreachable
185: ; preds = %176
%186 = load i8*, i8** %15
%187 = icmp eq i8* %186, null
br i1 %187, label %188, label %190
188: ; preds = %185
%189 = load i8*, i8** %13
store i8* %189, i8** %14
br label %203
190: ; preds = %185
%191 = load i8*, i8** %13
%192 = load i8*, i8** %15
%193 = call i32 @strcpy(i8* %191, i8* %192)
%194 = load i8*, i8** %13
%195 = load i32, i32* %9
%196 = sext i32 %195 to i64
%197 = getelementptr inbounds i8, i8* %194, i64 %196
%198 = getelementptr inbounds i8, i8* %197, i64 -1
store i8 32, i8* %198
%199 = load i8*, i8** %13
%200 = load i32, i32* %9
%201 = sext i32 %200 to i64
%202 = getelementptr inbounds i8, i8* %199, i64 %201
store i8* %202, i8** %14
br label %203
203: ; preds = %190, %188
%204 = load i64, i64* @optind
%205 = add i64 %204, 1
store i64 %205, i64* @optind
%206 = load i8**, i8*** %5
%207 = load i64, i64* @optind
%208 = getelementptr inbounds i8*, i8** %206, i64 %207
%209 = load i8*, i8** %208
%210 = icmp eq i8* %209, null
br i1 %210, label %211, label %262
211: ; preds = %203
%212 = load i32, i32* %9
%213 = sub nsw i32 65536, %212
store i32 %213, i32* %6
br label %214
214: ; preds = %260, %241, %211
%215 = load i8*, i8** %14
%216 = load i32, i32* %6
%217 = load i32*, i32** @stdin
%218 = call i32* @fgets(i8* %215, i32 %216, i32* %217)
%219 = icmp ne i32* %218, null
br i1 %219, label %220, label %261
220: ; preds = %214
%221 = load i8*, i8** %14
%222 = call i32 @strlen(i8* %221)
store i32 %222, i32* %7
%223 = load i32, i32* %11
%224 = icmp ne i32 %223, 0
br i1 %224, label %225, label %238
225: ; preds = %220
%226 = load i8*, i8** %14
%227 = load i32, i32* %7
%228 = sext i32 %227 to i64
%229 = getelementptr inbounds i8, i8* %226, i64 %228
%230 = getelementptr inbounds i8, i8* %229, i64 -1
%231 = load i8, i8* %230
%232 = sext i8 %231 to i32
%233 = icmp eq i32 %232, 10
br i1 %233, label %234, label %237
234: ; preds = %225
%235 = load i32, i32* %7
%236 = add nsw i32 %235, -1
store i32 %236, i32* %7
br label %237
237: ; preds = %234, %225
br label %238
238: ; preds = %237, %220
%239 = load i32, i32* %7
%240 = icmp slt i32 %239, 1
br i1 %240, label %241, label %242
241: ; preds = %238
br label %214
242: ; preds = %238
%243 = load i8*, i8** %14
%244 = load i32, i32* %7
%245 = sext i32 %244 to i64
%246 = getelementptr inbounds i8, i8* %243, i64 %245
store i8 0, i8* %246
%247 = load i32, i32* %9
%248 = load i32, i32* %7
%249 = add nsw i32 %248, %247
store i32 %249, i32* %7
%250 = load i32, i32* %8
%251 = load i8*, i8** %13
%252 = load i32, i32* %7
%253 = call i32 @write(i32 %250, i8* %251, i32 %252)
%254 = load i32, i32* %7
%255 = icmp ne i32 %253, %254
br i1 %255, label %256, label %260
256: ; preds = %242
%257 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%258 = load i32, i32* @EXIT_FAILURE
%259 = call i32 @exit(i32 %258)
unreachable
260: ; preds = %242
br label %214
261: ; preds = %214
br label %350
262: ; preds = %203
br label %263
263: ; preds = %344, %262
%264 = load i8**, i8*** %5
%265 = load i64, i64* @optind
%266 = getelementptr inbounds i8*, i8** %264, i64 %265
%267 = load i8*, i8** %266
%268 = icmp ne i8* %267, null
br i1 %268, label %269, label %349
269: ; preds = %263
%270 = load i8**, i8*** %5
%271 = load i64, i64* @optind
%272 = getelementptr inbounds i8*, i8** %270, i64 %271
%273 = load i8*, i8** %272
%274 = call i32* @fopen(i8* %273, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %274, i32** %19
%275 = icmp eq i32* %274, null
br i1 %275, label %276, label %284
276: ; preds = %269
%277 = load i8**, i8*** %5
%278 = load i64, i64* @optind
%279 = getelementptr inbounds i8*, i8** %277, i64 %278
%280 = load i8*, i8** %279
%281 = call i32 @perror(i8* %280)
%282 = load i32, i32* @EXIT_FAILURE
%283 = call i32 @exit(i32 %282)
unreachable
284: ; preds = %269
%285 = load i32, i32* %9
%286 = sub nsw i32 65536, %285
store i32 %286, i32* %6
br label %287
287: ; preds = %333, %314, %284
%288 = load i8*, i8** %14
%289 = load i32, i32* %6
%290 = load i32*, i32** %19
%291 = call i32* @fgets(i8* %288, i32 %289, i32* %290)
%292 = icmp ne i32* %291, null
br i1 %292, label %293, label %334
293: ; preds = %287
%294 = load i8*, i8** %14
%295 = call i32 @strlen(i8* %294)
store i32 %295, i32* %7
%296 = load i32, i32* %11
%297 = icmp ne i32 %296, 0
br i1 %297, label %298, label %311
298: ; preds = %293
%299 = load i8*, i8** %14
%300 = load i32, i32* %7
%301 = sext i32 %300 to i64
%302 = getelementptr inbounds i8, i8* %299, i64 %301
%303 = getelementptr inbounds i8, i8* %302, i64 -1
%304 = load i8, i8* %303
%305 = sext i8 %304 to i32
%306 = icmp eq i32 %305, 10
br i1 %306, label %307, label %310
307: ; preds = %298
%308 = load i32, i32* %7
%309 = add nsw i32 %308, -1
store i32 %309, i32* %7
br label %310
310: ; preds = %307, %298
br label %311
311: ; preds = %310, %293
%312 = load i32, i32* %7
%313 = icmp slt i32 %312, 1
br i1 %313, label %314, label %315
314: ; preds = %311
br label %287
315: ; preds = %311
%316 = load i8*, i8** %14
%317 = load i32, i32* %7
%318 = sext i32 %317 to i64
%319 = getelementptr inbounds i8, i8* %316, i64 %318
store i8 0, i8* %319
%320 = load i32, i32* %9
%321 = load i32, i32* %7
%322 = add nsw i32 %321, %320
store i32 %322, i32* %7
%323 = load i32, i32* %8
%324 = load i8*, i8** %13
%325 = load i32, i32* %7
%326 = call i32 @write(i32 %323, i8* %324, i32 %325)
%327 = load i32, i32* %7
%328 = icmp ne i32 %326, %327
br i1 %328, label %329, label %333
329: ; preds = %315
%330 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%331 = load i32, i32* @EXIT_FAILURE
%332 = call i32 @exit(i32 %331)
unreachable
333: ; preds = %315
br label %287
334: ; preds = %287
%335 = load i32*, i32** %19
%336 = call i32 @feof(i32* %335)
%337 = icmp ne i32 %336, 0
br i1 %337, label %344, label %338
338: ; preds = %334
%339 = load i8**, i8*** %5
%340 = load i64, i64* @optind
%341 = getelementptr inbounds i8*, i8** %339, i64 %340
%342 = load i8*, i8** %341
%343 = call i32 @perror(i8* %342)
br label %344
344: ; preds = %338, %334
%345 = load i32*, i32** %19
%346 = call i32 @fclose(i32* %345)
%347 = load i64, i64* @optind
%348 = add i64 %347, 1
store i64 %348, i64* @optind
br label %263
349: ; preds = %263
br label %350
350: ; preds = %349, %261
%351 = load i8*, i8** %13
%352 = call i32 @free(i8* %351)
%353 = load i32, i32* @EXIT_SUCCESS
%354 = call i32 @exit(i32 %353)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i64 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [6 x i8] c"hni:v\00"
@EOF = global i32 0
@optarg = global i8* null
@stderr = global i32 0
@.str.1 = [13 x i8] c"version 0.2\0A\00"
@EXIT_SUCCESS = global i32 0
@optind = global i64 0
@.str.2 = [14 x i8] c"Invalid port\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [18 x i8] c"Unknown host: %s\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.4 = [24 x i8] c"Unable to create socket\00"
@.str.6 = [15 x i8] c"Out of memory\0A\00"
@stdin = global i32* null
@.str.7 = [24 x i8] c"Unable to transmit data\00"
@.str.8 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %33, label %8
8: ; preds = %2, %26
%9 = phi i32 [ %30, %26 ], [ %5, %2 ]
%10 = phi i8* [ %29, %26 ], [ null, %2 ]
%11 = phi i32 [ %28, %26 ], [ 1, %2 ]
%12 = phi i32 [ %27, %26 ], [ 0, %2 ]
switch i32 %9, label %24 [
i32 104, label %13
i32 105, label %15
i32 110, label %26
i32 118, label %19
]
13: ; preds = %8
%14 = tail call i32 (...) @usage()
br label %26
15: ; preds = %8
%16 = load i8*, i8** @optarg
%17 = tail call i32 @strlen(i8* %16)
%18 = add nsw i32 %17, 1
br label %26
19: ; preds = %8
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @EXIT_SUCCESS
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %8
%25 = tail call i32 (...) @usage()
br label %26
26: ; preds = %8, %24, %15, %13
%27 = phi i32 [ %12, %24 ], [ %18, %15 ], [ %12, %13 ], [ %12, %8 ]
%28 = phi i32 [ %11, %24 ], [ %11, %15 ], [ %11, %13 ], [ 0, %8 ]
%29 = phi i8* [ %10, %24 ], [ %16, %15 ], [ %10, %13 ], [ %10, %8 ]
%30 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%31 = load i32, i32* @EOF
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %8
33: ; preds = %26, %2
%34 = phi i32 [ 0, %2 ], [ %27, %26 ]
%35 = phi i32 [ 1, %2 ], [ %28, %26 ]
%36 = phi i8* [ null, %2 ], [ %29, %26 ]
%37 = load i64, i64* @optind
%38 = getelementptr inbounds i8*, i8** %1, i64 %37
%39 = load i8*, i8** %38
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %46
41: ; preds = %33
%42 = tail call i32 (...) @usage()
%43 = load i64, i64* @optind
%44 = getelementptr inbounds i8*, i8** %1, i64 %43
%45 = load i8*, i8** %44
br label %46
46: ; preds = %41, %33
%47 = phi i8* [ %39, %33 ], [ %45, %41 ]
br label %48
48: ; preds = %46, %51
%49 = phi i8* [ %52, %51 ], [ %47, %46 ]
%50 = load i8, i8* %49
switch i8 %50, label %51 [
i8 58, label %53
i8 0, label %78
]
51: ; preds = %48
%52 = getelementptr inbounds i8, i8* %49, i64 1
br label %48
53: ; preds = %48
store i8 0, i8* %49
%54 = getelementptr inbounds i8, i8* %49, i64 1
%55 = load i8, i8* %54
%56 = icmp eq i8 %55, 0
br i1 %56, label %69, label %57
57: ; preds = %53, %65
%58 = phi i8 [ %67, %65 ], [ %55, %53 ]
%59 = phi i8* [ %66, %65 ], [ %54, %53 ]
%60 = sext i8 %58 to i32
%61 = add nsw i32 %60, -48
%62 = icmp ult i32 %61, 10
br i1 %62, label %65, label %63
63: ; preds = %57
%64 = tail call i32 (...) @usage()
br label %65
65: ; preds = %63, %57
%66 = getelementptr inbounds i8, i8* %59, i64 1
%67 = load i8, i8* %66
%68 = icmp eq i8 %67, 0
br i1 %68, label %69, label %57
69: ; preds = %65, %53
%70 = tail call i32 @atoi(i8* %54)
%71 = add i32 %70, -65536
%72 = icmp ult i32 %71, -65535
br i1 %72, label %73, label %80
73: ; preds = %69
%74 = load i32, i32* @stderr
%75 = tail call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%76 = load i32, i32* @EXIT_FAILURE
%77 = tail call i32 @exit(i32 %76)
unreachable
78: ; preds = %48
%79 = tail call i32 (...) @usage()
br label %80
80: ; preds = %69, %78
%81 = phi i32 [ %70, %69 ], [ 0, %78 ]
%82 = load i64, i64* @optind
%83 = getelementptr inbounds i8*, i8** %1, i64 %82
%84 = load i8*, i8** %83
%85 = tail call %struct.hostent* @gethostbyname(i8* %84)
%86 = icmp eq %struct.hostent* %85, null
br i1 %86, label %87, label %95
87: ; preds = %80
%88 = load i32, i32* @stderr
%89 = load i64, i64* @optind
%90 = getelementptr inbounds i8*, i8** %1, i64 %89
%91 = load i8*, i8** %90
%92 = tail call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %91)
%93 = load i32, i32* @EXIT_FAILURE
%94 = tail call i32 @exit(i32 %93)
unreachable
95: ; preds = %80
%96 = getelementptr inbounds %struct.hostent, %struct.hostent* %85, i64 0, i32 0
%97 = load i64, i64* %96
%98 = inttoptr i64 %97 to %struct.in_addr**
%99 = load %struct.in_addr*, %struct.in_addr** %98
%100 = icmp eq %struct.in_addr* %99, null
br i1 %100, label %129, label %101
101: ; preds = %95
%102 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
%103 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%104 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%105 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %106
106: ; preds = %101, %124
%107 = phi %struct.in_addr** [ %98, %101 ], [ %126, %124 ]
%108 = load i32, i32* @AF_INET
%109 = load i32, i32* @SOCK_DGRAM
%110 = call i32 @socket(i32 %108, i32 %109, i32 0)
%111 = icmp eq i32 %110, -1
br i1 %111, label %112, label %116
112: ; preds = %106
%113 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%114 = load i32, i32* @EXIT_FAILURE
%115 = call i32 @exit(i32 %114)
unreachable
116: ; preds = %106
%117 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%118 = load i32, i32* @AF_INET
store i32 %118, i32* %102
%119 = call i32 @htons(i32 %81)
store i32 %119, i32* %103
%120 = load %struct.in_addr*, %struct.in_addr** %107
%121 = call i32 @memcpy(i32* %104, %struct.in_addr* %120, i32 4)
%122 = call i64 @connect(i32 %110, %struct.sockaddr* %105, i32 12)
%123 = icmp eq i64 %122, 0
br i1 %123, label %129, label %124
124: ; preds = %116
%125 = call i32 @close(i32 %110)
%126 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %107, i64 1
%127 = load %struct.in_addr*, %struct.in_addr** %126
%128 = icmp eq %struct.in_addr* %127, null
br i1 %128, label %129, label %106
129: ; preds = %116, %124, %95
%130 = phi i32 [ -1, %95 ], [ %110, %124 ], [ %110, %116 ]
%131 = call i64 @malloc(i32 65536)
%132 = inttoptr i64 %131 to i8*
%133 = icmp eq i64 %131, 0
br i1 %133, label %134, label %139
134: ; preds = %129
%135 = load i32, i32* @stderr
%136 = call i32 (i32, i8*, ...) @fprintf(i32 %135, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%137 = load i32, i32* @EXIT_FAILURE
%138 = call i32 @exit(i32 %137)
unreachable
139: ; preds = %129
%140 = icmp eq i8* %36, null
br i1 %140, label %146, label %141
141: ; preds = %139
%142 = call i32 @strcpy(i8* %132, i8* %36)
%143 = sext i32 %34 to i64
%144 = getelementptr inbounds i8, i8* %132, i64 %143
%145 = getelementptr inbounds i8, i8* %144, i64 -1
store i8 32, i8* %145
br label %146
146: ; preds = %139, %141
%147 = phi i8* [ %144, %141 ], [ %132, %139 ]
%148 = load i64, i64* @optind
%149 = add i64 %148, 1
store i64 %149, i64* @optind
%150 = getelementptr inbounds i8*, i8** %1, i64 %149
%151 = load i8*, i8** %150
%152 = icmp eq i8* %151, null
%153 = sub nsw i32 65536, %34
br i1 %152, label %157, label %154
154: ; preds = %146
%155 = icmp eq i32 %35, 0
%156 = getelementptr inbounds i8, i8* %147, i64 -1
br label %190
157: ; preds = %146
%158 = load i32*, i32** @stdin
%159 = call i32* @fgets(i8* %147, i32 %153, i32* %158)
%160 = icmp eq i32* %159, null
br i1 %160, label %244, label %161
161: ; preds = %157
%162 = icmp eq i32 %35, 0
%163 = getelementptr inbounds i8, i8* %147, i64 -1
br label %164
164: ; preds = %161, %176
%165 = call i32 @strlen(i8* %147)
br i1 %162, label %173, label %166
166: ; preds = %164
%167 = sext i32 %165 to i64
%168 = getelementptr inbounds i8, i8* %163, i64 %167
%169 = load i8, i8* %168
%170 = icmp eq i8 %169, 10
%171 = sext i1 %170 to i32
%172 = add nsw i32 %165, %171
br label %173
173: ; preds = %166, %164
%174 = phi i32 [ %165, %164 ], [ %172, %166 ]
%175 = icmp slt i32 %174, 1
br i1 %175, label %176, label %180
176: ; preds = %173, %180
%177 = load i32*, i32** @stdin
%178 = call i32* @fgets(i8* %147, i32 %153, i32* %177)
%179 = icmp eq i32* %178, null
br i1 %179, label %244, label %164
180: ; preds = %173
%181 = zext i32 %174 to i64
%182 = getelementptr inbounds i8, i8* %147, i64 %181
store i8 0, i8* %182
%183 = add nsw i32 %174, %34
%184 = call i32 @write(i32 %130, i8* %132, i32 %183)
%185 = icmp eq i32 %184, %183
br i1 %185, label %176, label %186
186: ; preds = %180
%187 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%188 = load i32, i32* @EXIT_FAILURE
%189 = call i32 @exit(i32 %188)
unreachable
190: ; preds = %154, %237
%191 = phi i8* [ %151, %154 ], [ %242, %237 ]
%192 = call i32* @fopen(i8* %191, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%193 = icmp eq i32* %192, null
br i1 %193, label %194, label %201
194: ; preds = %190
%195 = load i64, i64* @optind
%196 = getelementptr inbounds i8*, i8** %1, i64 %195
%197 = load i8*, i8** %196
%198 = call i32 @perror(i8* %197)
%199 = load i32, i32* @EXIT_FAILURE
%200 = call i32 @exit(i32 %199)
unreachable
201: ; preds = %190
%202 = call i32* @fgets(i8* %147, i32 %153, i32* %192)
%203 = icmp eq i32* %202, null
br i1 %203, label %229, label %204
204: ; preds = %201, %216
%205 = call i32 @strlen(i8* %147)
br i1 %155, label %213, label %206
206: ; preds = %204
%207 = sext i32 %205 to i64
%208 = getelementptr inbounds i8, i8* %156, i64 %207
%209 = load i8, i8* %208
%210 = icmp eq i8 %209, 10
%211 = sext i1 %210 to i32
%212 = add nsw i32 %205, %211
br label %213
213: ; preds = %206, %204
%214 = phi i32 [ %205, %204 ], [ %212, %206 ]
%215 = icmp slt i32 %214, 1
br i1 %215, label %216, label %219
216: ; preds = %213, %219
%217 = call i32* @fgets(i8* %147, i32 %153, i32* %192)
%218 = icmp eq i32* %217, null
br i1 %218, label %229, label %204
219: ; preds = %213
%220 = zext i32 %214 to i64
%221 = getelementptr inbounds i8, i8* %147, i64 %220
store i8 0, i8* %221
%222 = add nsw i32 %214, %34
%223 = call i32 @write(i32 %130, i8* %132, i32 %222)
%224 = icmp eq i32 %223, %222
br i1 %224, label %216, label %225
225: ; preds = %219
%226 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%227 = load i32, i32* @EXIT_FAILURE
%228 = call i32 @exit(i32 %227)
unreachable
229: ; preds = %216, %201
%230 = call i32 @feof(i32* %192)
%231 = icmp eq i32 %230, 0
br i1 %231, label %232, label %237
232: ; preds = %229
%233 = load i64, i64* @optind
%234 = getelementptr inbounds i8*, i8** %1, i64 %233
%235 = load i8*, i8** %234
%236 = call i32 @perror(i8* %235)
br label %237
237: ; preds = %232, %229
%238 = call i32 @fclose(i32* %192)
%239 = load i64, i64* @optind
%240 = add i64 %239, 1
store i64 %240, i64* @optind
%241 = getelementptr inbounds i8*, i8** %1, i64 %240
%242 = load i8*, i8** %241
%243 = icmp eq i8* %242, null
br i1 %243, label %244, label %190
244: ; preds = %237, %176, %157
%245 = call i32 @free(i8* %132)
%246 = load i32, i32* @EXIT_SUCCESS
%247 = call i32 @exit(i32 %246)
unreachable
}