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

/* Forward declarations */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ *h_addr_list;
};
typedef int /*<<< orphan*/ srv_address;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ assertf(int, int, char *, char *, char *, ...);
int atoi(char *);
scalar_t__ connect(int, struct sockaddr_in *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *optarg;
int optind;
int /*<<< orphan*/ printf(char *, ...);
size_t read(int, char *, int);
scalar_t__ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ version();
int main(int argc, char *argv[]) {
  int port = 6662;
  int opt = 0;
  int verbose = 1;
  char *hostname = NULL;
  while ((opt = getopt(argc, argv, "hvqP:H:")) != -1) {
    switch (opt) {
    case 'h':
      usage();
      exit(0);
    case 'v':
      version();
      exit(0);
    case 'P':
      port = atoi(optarg);
      break;
    case 'H':
      hostname = optarg;
      break;
    case 'q':
      verbose = 0;
      break;
    case '?':
      exit(0);
    case ':':
      exit(0);
    default:
      usage();
      exit(1);
    }
  }
  if (optind >= argc) {
    fprintf(stderr, "Missing directory operand\n");
    usage();
    exit(1);
  }
  hostname = !hostname ? "localhost" : hostname;
  struct hostent *server;
  server = gethostbyname(hostname);
  (assertf((server == NULL), 1, "\033[31;1mError\033[0m", ("gethostbyname"),
           ("Host %s:%d not found"), hostname, port));
  struct sockaddr_in srv_address;
  memset((char *)&srv_address, 0, sizeof(srv_address));
  srv_address.sin_family = AF_INET;
  memcpy(&srv_address.sin_addr.s_addr, server->h_addr_list[0],
         server->h_length);
  srv_address.sin_port = htons(port);
  int sock = socket(AF_INET, SOCK_STREAM, 0);
  (assertf((sock < 0), 1, "\033[31;1mError\033[0m", ("socket"), (NULL)));
  (assertf((connect(sock, &srv_address, sizeof(srv_address)) < 0), 1,
           "\033[31;1mError\033[0m", ("connect"), ("Can't connect to %s:%d"),
           hostname, port));
  verbose ? printf("Connected to host %s:%d\n", hostname, port) : 0;
  char accept_buffer[256];
  memset(accept_buffer, 0, 256);
  while (optind < argc) {
    char *current_dirname = argv[optind];
    printf("%s\n", current_dirname);
    (assertf((send(sock, current_dirname, strlen(current_dirname), 0) < 0), 1,
             "\033[31;1mError\033[0m", ("send"), (NULL)));
    ++optind;
    while (1) {
      memset(accept_buffer, 0, 256);
      size_t readed = read(sock, accept_buffer, 256);
      (assertf((readed < 0), 1, "\033[31;1mError\033[0m", ("read from socket"),
               (NULL)));
      if (readed > 0) {
        char *pch = strchr(accept_buffer, '/');
        if (pch != NULL) {
          *pch = '\0';
          printf("%s", accept_buffer);
          memset(accept_buffer, 0, 256);
          break;
        } else {
          printf("%s", accept_buffer);
        }
      } else {
        verbose ? printf("Lost connection with server\n") : 0;
        break;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1a06,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe90(%rip),%rdx
call   1100 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     131a <main+0xfa>
mov    -0x18(%rbp),%eax
add    $0xffffffc6,%eax
mov    %eax,%ecx
mov    %rcx,-0x170(%rbp)
sub    $0x3c,%eax
ja     1304 <main+0xe4>
mov    -0x170(%rbp),%rax
lea    0xd65(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   10e0 <usage@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    $0x0,%al
call   10d0 <version@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    0x2d31(%rip),%rax
mov    (%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    1315 <main+0xf5>
mov    0x2d1a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1315 <main+0xf5>
movl   $0x0,-0x1c(%rbp)
jmp    1315 <main+0xf5>
xor    %edi,%edi
call   1120 <exit@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    $0x0,%al
call   10e0 <usage@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    1256 <main+0x36>
mov    0x2cb7(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     1352 <main+0x132>
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
lea    0xdc0(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x0,%al
call   10e0 <usage@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
cmpq   $0x0,-0x28(%rbp)
jne    1370 <main+0x150>
lea    0xdb3(%rip),%rax
mov    %rax,-0x178(%rbp)
jmp    137b <main+0x15b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x178(%rbp)
mov    -0x178(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    -0x28(%rbp),%r9
mov    -0x14(%rbp),%eax
mov    $0x1,%esi
lea    0xd6e(%rip),%rdx
lea    0xd78(%rip),%rcx
lea    0xd7f(%rip),%r8
mov    %eax,(%rsp)
mov    $0x0,%al
call   10f0 <assertf@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2bfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
lea    -0x40(%rbp),%rdi
add    $0x4,%rdi
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%esi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
call   10c0 <memcpy@plt>
mov    -0x14(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x40(%rbp)
mov    0x2bca(%rip),%rax
mov    (%rax),%edi
mov    0x2ba1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x1,%esi
lea    0xcde(%rip),%rdx
lea    0xd56(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   10f0 <assertf@plt>
mov    -0x44(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xc,%edx
call   1130 <connect@plt>
cmp    $0x0,%rax
setl   %al
and    $0x1,%al
movzbl %al,%edi
mov    -0x28(%rbp),%r9
mov    -0x14(%rbp),%eax
mov    $0x1,%esi
lea    0xc9b(%rip),%rdx
lea    0xcc8(%rip),%rcx
lea    0xcc9(%rip),%r8
mov    %eax,(%rsp)
mov    $0x0,%al
call   10f0 <assertf@plt>
cmpl   $0x0,-0x1c(%rbp)
je     14c2 <main+0x2a2>
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xcbe(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14c7 <main+0x2a7>
jmp    14c7 <main+0x2a7>
lea    -0x150(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
mov    0x2af7(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    16a6 <main+0x486>
mov    -0x10(%rbp),%rax
mov    0x2ae1(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x158(%rbp)
mov    -0x158(%rbp),%rsi
lea    0xc7a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x184(%rbp)
mov    -0x158(%rbp),%rax
mov    %rax,-0x180(%rbp)
mov    -0x158(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x184(%rbp),%edi
mov    -0x180(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0x0,%rax
setl   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x1,%esi
lea    0xbb6(%rip),%rdx
lea    0xc1f(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   10f0 <assertf@plt>
mov    0x2a53(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    0x2a47(%rip),%rax
mov    %ecx,(%rax)
lea    -0x150(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
mov    -0x44(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0x100,%edx
call   1090 <read@plt>
mov    %rax,-0x160(%rbp)
cmpq   $0x0,-0x160(%rbp)
setb   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x1,%esi
lea    0xb44(%rip),%rdx
lea    0xbb2(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   10f0 <assertf@plt>
cmpq   $0x0,-0x160(%rbp)
jbe    1675 <main+0x455>
lea    -0x150(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %rax,-0x168(%rbp)
cmpq   $0x0,-0x168(%rbp)
je     165b <main+0x43b>
mov    -0x168(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x150(%rbp),%rsi
lea    0xb6b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x150(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
jmp    16a1 <main+0x481>
lea    -0x150(%rbp),%rsi
lea    0xb3e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    169c <main+0x47c>
cmpl   $0x0,-0x1c(%rbp)
je     1692 <main+0x472>
lea    0xb24(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1697 <main+0x477>
jmp    1697 <main+0x477>
jmp    16a1 <main+0x481>
jmp    1593 <main+0x373>
jmp    14da <main+0x2ba>
xor    %eax,%eax
add    $0x190,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
mov    $0x1a06,%r12d
movl   $0x1,0x10(%rsp)
xor    %r14d,%r14d
lea    0xda2(%rip),%r13
mov    0x2d93(%rip),%r15
jmp    127b <main+0x4b>
nopw   0x0(%rax,%rax,1)
mov    (%r15),%rdi
call   1120 <atoi@plt>
mov    %eax,%r12d
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r13,%rdx
call   1110 <getopt@plt>
cmp    $0x50,%eax
je     1270 <main+0x40>
cmp    $0x47,%eax
jle    12b8 <main+0x88>
cmp    $0x70,%eax
jg     12a5 <main+0x75>
cmp    $0x48,%eax
jne    1571 <main+0x341>
mov    (%r15),%r14
jmp    127b <main+0x4b>
cmp    $0x71,%eax
jne    1584 <main+0x354>
movl   $0x0,0x10(%rsp)
jmp    127b <main+0x4b>
cmp    $0xffffffff,%eax
jne    1560 <main+0x330>
mov    %rbp,0x28(%rsp)
mov    0x2d0b(%rip),%rax
mov    %ebx,0x14(%rsp)
cmp    %ebx,(%rax)
jge    1597 <main+0x367>
test   %r14,%r14
lea    0xd40(%rip),%r15
cmovne %r14,%r15
mov    %r15,%rdi
call   10b0 <gethostbyname@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
sete   %dil
mov    %r12d,(%rsp)
lea    0xd27(%rip),%rdx
lea    0xd31(%rip),%rcx
lea    0xd38(%rip),%r8
mov    $0x1,%esi
mov    %r15,%r9
xor    %eax,%eax
call   1100 <assertf@plt>
lea    0x18(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x2ca2(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x20(%rsp)
lea    0x1c(%rsp),%rdi
mov    0x8(%rbx),%rax
mov    (%rax),%esi
mov    (%rbx),%edx
call   10d0 <memcpy@plt>
mov    %r12d,%edi
call   1050 <htons@plt>
mov    %eax,0x18(%rsp)
mov    0x0(%rbp),%edi
mov    0x2c53(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,%r14d
mov    %eax,%edi
shr    $0x1f,%edi
lea    0xd23(%rip),%rcx
mov    $0x1,%esi
lea    0xc9c(%rip),%rbx
mov    %rbx,%rdx
xor    %r8d,%r8d
xor    %eax,%eax
call   1100 <assertf@plt>
mov    %r14d,%edi
mov    %r13,%rsi
mov    $0xc,%edx
call   1140 <connect@plt>
shr    $0x3f,%rax
mov    %r12d,(%rsp)
lea    0xca4(%rip),%rcx
lea    0xca5(%rip),%r8
mov    %eax,%edi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r15,%r9
xor    %eax,%eax
call   1100 <assertf@plt>
cmpl   $0x0,0x10(%rsp)
je     13f3 <main+0x1c3>
lea    0xc9a(%rip),%rdi
mov    %r15,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x30(%rsp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1090 <memset@plt>
mov    0x2bcd(%rip),%rax
mov    (%rax),%eax
cmp    0x14(%rsp),%eax
jge    154c <main+0x31c>
lea    0xc0f(%rip),%r13
lea    0x30(%rsp),%rbp
lea    0xc74(%rip),%r12
jmp    1460 <main+0x230>
nopl   0x0(%rax)
movb   $0x0,(%rax)
lea    0xc75(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1090 <memset@plt>
mov    (%r15),%eax
cmp    0x14(%rsp),%eax
jge    154c <main+0x31c>
cltq
mov    0x28(%rsp),%rcx
mov    (%rcx,%rax,8),%r15
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    0x2b50(%rip),%r15
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
shr    $0x3f,%rax
mov    %eax,%edi
mov    $0x1,%esi
mov    %r13,%rdx
lea    0xbf3(%rip),%rcx
xor    %r8d,%r8d
xor    %eax,%eax
call   1100 <assertf@plt>
addl   $0x1,(%r15)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1090 <memset@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x100,%edx
call   10a0 <read@plt>
mov    %rax,%rbx
xor    %edi,%edi
mov    $0x1,%esi
mov    %r13,%rdx
mov    %r12,%rcx
xor    %r8d,%r8d
xor    %eax,%eax
call   1100 <assertf@plt>
test   %rbx,%rbx
je     1530 <main+0x300>
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
test   %rax,%rax
jne    1430 <main+0x200>
lea    0xb94(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    14c0 <main+0x290>
nopw   0x0(%rax,%rax,1)
cmpl   $0x0,0x10(%rsp)
je     1453 <main+0x223>
lea    0xb70(%rip),%rdi
call   1030 <puts@plt>
jmp    1453 <main+0x223>
xor    %eax,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x3a,%eax
je     156a <main+0x33a>
cmp    $0x3f,%eax
jne    15ac <main+0x37c>
xor    %edi,%edi
call   1130 <exit@plt>
cmp    $0x68,%eax
jne    15ac <main+0x37c>
xor    %eax,%eax
call   10f0 <usage@plt>
xor    %edi,%edi
call   1130 <exit@plt>
cmp    $0x76,%eax
jne    15ac <main+0x37c>
xor    %eax,%eax
call   10e0 <version@plt>
xor    %edi,%edi
call   1130 <exit@plt>
mov    0x2a2a(%rip),%rax
mov    (%rax),%edi
lea    0xa61(%rip),%rsi
call   10c0 <fprintf@plt>
xor    %eax,%eax
call   10f0 <usage@plt>
mov    $0x1,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i32, i32* }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@.str = [8 x i8] c"hvqP:H:\00"
@optarg = global i8* null
@optind = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Missing directory operand\0A\00"
@.str.2 = [10 x i8] c"localhost\00"
@.str.3 = [17 x i8] c"\1B[31;1mError\1B[0m\00"
@.str.4 = [14 x i8] c"gethostbyname\00"
@.str.5 = [21 x i8] c"Host %s:%d not found\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.6 = [7 x i8] c"socket\00"
@.str.7 = [8 x i8] c"connect\00"
@.str.8 = [23 x i8] c"Can't connect to %s:%d\00"
@.str.9 = [25 x i8] c"Connected to host %s:%d\0A\00"
@.str.10 = [4 x i8] c"%s\0A\00"
@.str.11 = [5 x i8] c"send\00"
@.str.12 = [17 x i8] c"read from socket\00"
@.str.13 = [3 x i8] c"%s\00"
@.str.14 = [29 x i8] c"Lost connection with server\0A\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 i8*
%10 = alloca %struct.hostent*
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
%13 = alloca [256 x i8]
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 6662, i32* %6
store i32 0, i32* %7
store i32 1, i32* %8
store i8* null, i8** %9
br label %17
17: ; preds = %43, %2
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = call i32 @getopt(i32 %18, i8** %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 %20, i32* %7
%21 = icmp ne i32 %20, -1
br i1 %21, label %22, label %44
22: ; preds = %17
%23 = load i32, i32* %7
switch i32 %23, label %40 [
i32 104, label %24
i32 118, label %27
i32 80, label %30
i32 72, label %33
i32 113, label %35
i32 63, label %36
i32 58, label %38
]
24: ; preds = %22
%25 = call i32 (...) @usage()
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %22
%28 = call i32 (...) @version()
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %22
%31 = load i8*, i8** @optarg
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %6
br label %43
33: ; preds = %22
%34 = load i8*, i8** @optarg
store i8* %34, i8** %9
br label %43
35: ; preds = %22
store i32 0, i32* %8
br label %43
36: ; preds = %22
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %22
%39 = call i32 @exit(i32 0)
unreachable
40: ; preds = %22
%41 = call i32 (...) @usage()
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %35, %33, %30
br label %17
44: ; preds = %17
%45 = load i32, i32* @optind
%46 = load i32, i32* %4
%47 = icmp sge i32 %45, %46
br i1 %47, label %48, label %53
48: ; preds = %44
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%51 = call i32 (...) @usage()
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %44
%54 = load i8*, i8** %9
%55 = icmp ne i8* %54, null
br i1 %55, label %57, label %56
56: ; preds = %53
br label %59
57: ; preds = %53
%58 = load i8*, i8** %9
br label %59
59: ; preds = %57, %56
%60 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %56 ], [ %58, %57 ]
store i8* %60, i8** %9
%61 = load i8*, i8** %9
%62 = call %struct.hostent* @gethostbyname(i8* %61)
store %struct.hostent* %62, %struct.hostent** %10
%63 = load %struct.hostent*, %struct.hostent** %10
%64 = icmp eq %struct.hostent* %63, null
%65 = zext i1 %64 to i32
%66 = load i8*, i8** %9
%67 = load i32, i32* %6
%68 = call i32 (i32, i32, i8*, i8*, i8*, ...) @assertf(i32 %65, i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %66, i32 %67)
%69 = bitcast %struct.sockaddr_in* %11 to i8*
%70 = call i32 @memset(i8* %69, i32 0, i32 12)
%71 = load i32, i32* @AF_INET
%72 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %71, i32* %72
%73 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%74 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %73, i32 0, i32 0
%75 = load %struct.hostent*, %struct.hostent** %10
%76 = getelementptr inbounds %struct.hostent, %struct.hostent* %75, i32 0, i32 1
%77 = load i32*, i32** %76
%78 = getelementptr inbounds i32, i32* %77, i64 0
%79 = load i32, i32* %78
%80 = load %struct.hostent*, %struct.hostent** %10
%81 = getelementptr inbounds %struct.hostent, %struct.hostent* %80, i32 0, i32 0
%82 = load i32, i32* %81
%83 = call i32 @memcpy(i32* %74, i32 %79, i32 %82)
%84 = load i32, i32* %6
%85 = call i32 @htons(i32 %84)
%86 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i32 %85, i32* %86
%87 = load i32, i32* @AF_INET
%88 = load i32, i32* @SOCK_STREAM
%89 = call i32 @socket(i32 %87, i32 %88, i32 0)
store i32 %89, i32* %12
%90 = load i32, i32* %12
%91 = icmp slt i32 %90, 0
%92 = zext i1 %91 to i32
%93 = call i32 (i32, i32, i8*, i8*, i8*, ...) @assertf(i32 %92, i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* null)
%94 = load i32, i32* %12
%95 = call i64 @connect(i32 %94, %struct.sockaddr_in* %11, i32 12)
%96 = icmp slt i64 %95, 0
%97 = zext i1 %96 to i32
%98 = load i8*, i8** %9
%99 = load i32, i32* %6
%100 = call i32 (i32, i32, i8*, i8*, i8*, ...) @assertf(i32 %97, i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %98, i32 %99)
%101 = load i32, i32* %8
%102 = icmp ne i32 %101, 0
br i1 %102, label %103, label %107
103: ; preds = %59
%104 = load i8*, i8** %9
%105 = load i32, i32* %6
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i8* %104, i32 %105)
br label %108
107: ; preds = %59
br label %108
108: ; preds = %107, %103
%109 = phi i32 [ %106, %103 ], [ 0, %107 ]
%110 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%111 = call i32 @memset(i8* %110, i32 0, i32 256)
br label %112
112: ; preds = %170, %108
%113 = load i32, i32* @optind
%114 = load i32, i32* %4
%115 = icmp slt i32 %113, %114
br i1 %115, label %116, label %171
116: ; preds = %112
%117 = load i8**, i8*** %5
%118 = load i32, i32* @optind
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds i8*, i8** %117, i64 %119
%121 = load i8*, i8** %120
store i8* %121, i8** %14
%122 = load i8*, i8** %14
%123 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* %122)
%124 = load i32, i32* %12
%125 = load i8*, i8** %14
%126 = load i8*, i8** %14
%127 = call i32 @strlen(i8* %126)
%128 = call i64 @send(i32 %124, i8* %125, i32 %127, i32 0)
%129 = icmp slt i64 %128, 0
%130 = zext i1 %129 to i32
%131 = call i32 (i32, i32, i8*, i8*, i8*, ...) @assertf(i32 %130, i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i8* null)
%132 = load i32, i32* @optind
%133 = add nsw i32 %132, 1
store i32 %133, i32* @optind
br label %134
134: ; preds = %116, %169
%135 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%136 = call i32 @memset(i8* %135, i32 0, i32 256)
%137 = load i32, i32* %12
%138 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%139 = call i64 @read(i32 %137, i8* %138, i32 256)
store i64 %139, i64* %15
%140 = load i64, i64* %15
%141 = icmp ult i64 %140, 0
%142 = zext i1 %141 to i32
%143 = call i32 (i32, i32, i8*, i8*, i8*, ...) @assertf(i32 %142, i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0), i8* null)
%144 = load i64, i64* %15
%145 = icmp ugt i64 %144, 0
br i1 %145, label %146, label %161
146: ; preds = %134
%147 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%148 = call i8* @strchr(i8* %147, i8 signext 47)
store i8* %148, i8** %16
%149 = load i8*, i8** %16
%150 = icmp ne i8* %149, null
br i1 %150, label %151, label %157
151: ; preds = %146
%152 = load i8*, i8** %16
store i8 0, i8* %152
%153 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%154 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i8* %153)
%155 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%156 = call i32 @memset(i8* %155, i32 0, i32 256)
br label %170
157: ; preds = %146
%158 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i8* %158)
br label %160
160: ; preds = %157
br label %169
161: ; preds = %134
%162 = load i32, i32* %8
%163 = icmp ne i32 %162, 0
br i1 %163, label %164, label %166
164: ; preds = %161
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.14, i64 0, i64 0))
br label %167
166: ; preds = %161
br label %167
167: ; preds = %166, %164
%168 = phi i32 [ %165, %164 ], [ 0, %166 ]
br label %170
169: ; preds = %160
br label %134
170: ; preds = %167, %151
br label %112
171: ; preds = %112
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i32* }
@.str = [8 x i8] c"hvqP:H:\00"
@optarg = global i8* null
@optind = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Missing directory operand\0A\00"
@.str.2 = [10 x i8] c"localhost\00"
@.str.3 = [17 x i8] c"\1B[31;1mError\1B[0m\00"
@.str.4 = [14 x i8] c"gethostbyname\00"
@.str.5 = [21 x i8] c"Host %s:%d not found\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.6 = [7 x i8] c"socket\00"
@.str.7 = [8 x i8] c"connect\00"
@.str.8 = [23 x i8] c"Can't connect to %s:%d\00"
@.str.9 = [25 x i8] c"Connected to host %s:%d\0A\00"
@.str.11 = [5 x i8] c"send\00"
@.str.12 = [17 x i8] c"read from socket\00"
@.str.13 = [3 x i8] c"%s\00"
@str = [28 x i8] c"Lost connection with server\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
br label %5
5: ; preds = %24, %2
%6 = phi i8* [ %25, %24 ], [ null, %2 ]
%7 = phi i32 [ %10, %24 ], [ 1, %2 ]
%8 = phi i32 [ %13, %24 ], [ 6662, %2 ]
br label %9
9: ; preds = %12, %5
%10 = phi i32 [ %7, %5 ], [ 0, %12 ]
%11 = phi i32 [ %8, %5 ], [ %13, %12 ]
br label %12
12: ; preds = %9, %21
%13 = phi i32 [ %23, %21 ], [ %11, %9 ]
%14 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
switch i32 %14, label %30 [
i32 -1, label %33
i32 104, label %15
i32 118, label %18
i32 80, label %21
i32 72, label %24
i32 113, label %9
i32 63, label %26
i32 58, label %28
]
15: ; preds = %12
%16 = tail call i32 (...) @usage()
%17 = tail call i32 @exit(i32 0)
unreachable
18: ; preds = %12
%19 = tail call i32 (...) @version()
%20 = tail call i32 @exit(i32 0)
unreachable
21: ; preds = %12
%22 = load i8*, i8** @optarg
%23 = tail call i32 @atoi(i8* %22)
br label %12
24: ; preds = %12
%25 = load i8*, i8** @optarg
br label %5
26: ; preds = %12
%27 = tail call i32 @exit(i32 0)
unreachable
28: ; preds = %12
%29 = tail call i32 @exit(i32 0)
unreachable
30: ; preds = %12
%31 = tail call i32 (...) @usage()
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %12
%34 = load i32, i32* @optind
%35 = icmp slt i32 %34, %0
br i1 %35, label %41, label %36
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = tail call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%39 = tail call i32 (...) @usage()
%40 = tail call i32 @exit(i32 1)
unreachable
41: ; preds = %33
%42 = icmp eq i8* %6, null
%43 = select i1 %42, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %6
%44 = tail call %struct.hostent* @gethostbyname(i8* %43)
%45 = icmp eq %struct.hostent* %44, null
%46 = zext i1 %45 to i32
%47 = tail call i32 (i32, i32, i8*, i8*, i8*, ...) @assertf(i32 %46, i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %43, i32 %13)
%48 = bitcast %struct.sockaddr_in* %3 to i8*
%49 = call i32 @memset(i8* %48, i32 0, i32 12)
%50 = load i32, i32* @AF_INET
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %50, i32* %51
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%53 = getelementptr inbounds %struct.hostent, %struct.hostent* %44, i64 0, i32 1
%54 = load i32*, i32** %53
%55 = load i32, i32* %54
%56 = getelementptr inbounds %struct.hostent, %struct.hostent* %44, i64 0, i32 0
%57 = load i32, i32* %56
%58 = call i32 @memcpy(i32* %52, i32 %55, i32 %57)
%59 = call i32 @htons(i32 %13)
%60 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %59, i32* %60
%61 = load i32, i32* @AF_INET
%62 = load i32, i32* @SOCK_STREAM
%63 = call i32 @socket(i32 %61, i32 %62, i32 0)
%64 = lshr i32 %63, 31
%65 = call i32 (i32, i32, i8*, i8*, i8*, ...) @assertf(i32 %64, i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* null)
%66 = call i64 @connect(i32 %63, %struct.sockaddr_in* %3, i32 12)
%67 = lshr i64 %66, 63
%68 = trunc i64 %67 to i32
%69 = call i32 (i32, i32, i8*, i8*, i8*, ...) @assertf(i32 %68, i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %43, i32 %13)
%70 = icmp eq i32 %10, 0
br i1 %70, label %73, label %71
71: ; preds = %41
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i8* %43, i32 %13)
br label %73
73: ; preds = %41, %71
%74 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%75 = call i32 @memset(i8* %74, i32 0, i32 256)
%76 = load i32, i32* @optind
%77 = icmp slt i32 %76, %0
br i1 %77, label %78, label %113
78: ; preds = %73, %110
%79 = phi i32 [ %111, %110 ], [ %76, %73 ]
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8*, i8** %1, i64 %80
%82 = load i8*, i8** %81
%83 = call i32 @puts(i8* dereferenceable(1) %82)
%84 = call i32 @strlen(i8* %82)
%85 = call i64 @send(i32 %63, i8* %82, i32 %84, i32 0)
%86 = lshr i64 %85, 63
%87 = trunc i64 %86 to i32
%88 = call i32 (i32, i32, i8*, i8*, i8*, ...) @assertf(i32 %87, i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i8* null)
%89 = load i32, i32* @optind
%90 = add nsw i32 %89, 1
store i32 %90, i32* @optind
%91 = call i32 @memset(i8* %74, i32 0, i32 256)
%92 = call i64 @read(i32 %63, i8* %74, i32 256)
%93 = call i32 (i32, i32, i8*, i8*, i8*, ...) @assertf(i32 0, i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0), i8* null)
%94 = icmp eq i64 %92, 0
br i1 %94, label %107, label %95
95: ; preds = %78, %101
%96 = call i8* @strchr(i8* %74, i8 signext 47)
%97 = icmp eq i8* %96, null
br i1 %97, label %101, label %98
98: ; preds = %95
store i8 0, i8* %96
%99 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i8* %74)
%100 = call i32 @memset(i8* %74, i32 0, i32 256)
br label %110
101: ; preds = %95
%102 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i8* %74)
%103 = call i32 @memset(i8* %74, i32 0, i32 256)
%104 = call i64 @read(i32 %63, i8* %74, i32 256)
%105 = call i32 (i32, i32, i8*, i8*, i8*, ...) @assertf(i32 0, i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0), i8* null)
%106 = icmp eq i64 %104, 0
br i1 %106, label %107, label %95
107: ; preds = %101, %78
br i1 %70, label %110, label %108
108: ; preds = %107
%109 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %110
110: ; preds = %108, %98, %107
%111 = load i32, i32* @optind
%112 = icmp slt i32 %111, %0
br i1 %112, label %78, label %113
113: ; preds = %110, %73
ret i32 0
}