#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 in_addr {
  int dummy;
};
struct sockaddr_in {
  struct in_addr sin_addr;
  scalar_t__ sin_family;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addrtype;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ option;

/* Variables and functions */
scalar_t__ AF_INET;
int EINPROGRESS;
int EINVAL;
int ENOMEM;
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
long O_NONBLOCK;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_KEEPALIVE;
int atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int errno;
long fcntl(int, int /*<<< orphan*/, long);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_aton(char *, struct in_addr *);
char *inet_ntoa(struct in_addr);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
char *strdup(char *);
char *strerror(int);
int net_connect(char *name, int port, int flags) {
  int p, len, fd, se, option;
  char *ptr, *host;
  struct hostent *he;
  struct sockaddr_in sa;
  long opts;
  p = 7147;
  ptr = strchr(name, ':');
  if (ptr) {
    p = atoi(ptr + 1);
  }
  if (port) {
    p = port;
  }
  if (p == 0) {
    if (flags & 0x01)
      fprintf(stderr, "connect: unable to acquire a port number\n");
    errno = EINVAL;
    return -2;
  }
  if ((name[0] == '\0') || (name[0] == ':')) {
    if (flags & 0x01)
      fprintf(stderr, "connect: no destination address given\n");
    errno = EINVAL;
    return -2;
  } else {
    host = strdup(name);
    if (host == NULL) {
      if (flags & 0x01)
        fprintf(stderr, "connect: unable to duplicate string\n");
      errno = ENOMEM;
      return -1;
    }
    ptr = strchr(host, ':');
    if (ptr) {
      ptr[0] = '\0';
    }
    if (inet_aton(host, &(sa.sin_addr)) == 0) {
      he = gethostbyname(host);
      if ((he == NULL) || (he->h_addrtype != AF_INET)) {
        if (flags & 0x01)
          fprintf(stderr, "connect: unable to map %s to ipv4 address\n", host);
        free(host);
        errno = EINVAL;
        return -1;
      }
      sa.sin_addr = *(struct in_addr *)he->h_addr;
    }
    free(host);
  }
  sa.sin_port = htons(p);
  sa.sin_family = AF_INET;
  if (flags & 0x04) {
    fd = socket(AF_INET, SOCK_STREAM, 0);
    opts = fcntl(fd, F_GETFL, NULL);
    if (opts >= 0) {
      opts = fcntl(fd, F_SETFL, opts | O_NONBLOCK);
    }
  } else {
    fd = socket(AF_INET, SOCK_STREAM, 0);
  }
  if (fd < 0) {
    if (flags & 0x01) {
      se = errno;
      fprintf(stderr, "connect: unable to allocate socket: %s\n",
              strerror(errno));
      errno = se;
    }
    return -1;
  }
  if (flags & 0x02) {
    ptr = inet_ntoa(sa.sin_addr);
    fprintf(stderr, "connect: connecting to %s:%u\n", ptr, p);
  }
  if (flags & 0x08) {
    option = 1;
    if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &option, sizeof(option)) < 0) {
      fprintf(stderr, "connect: cannot set keepalive socket option\n");
      return -1;
    }
  }
  len = sizeof(struct sockaddr_in);
  if (connect(fd, (struct sockaddr *)(&sa), len)) {
    if (flags & 0x04) {
      if (errno == EINPROGRESS) {
        return fd;
      }
    }
    se = errno;
    close(fd);
    if (flags & 0x01) {
      ptr = inet_ntoa(sa.sin_addr);
      fprintf(stderr, "connect: connect to %s:%u failed: %s\n", ptr, p,
              strerror(errno));
    }
    errno = se;
    return -1;
  }
  if (flags & 0x02) {
    fprintf(stderr, "connect: established connection\n");
  }
  return fd;
}


x86 assembly (clang, -O0):
<net_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x1beb,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1080 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1239 <net_connect+0x49>
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1249 <net_connect+0x59>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1297 <net_connect+0xa7>
mov    -0x18(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1279 <net_connect+0x89>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
lea    0xd8e(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2d10(%rip),%rax
mov    (%rax),%ecx
mov    0x2d17(%rip),%rax
mov    %ecx,(%rax)
movl   $0xfffffffe,-0x4(%rbp)
jmp    16f3 <net_connect+0x503>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12b7 <net_connect+0xc7>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    12fb <net_connect+0x10b>
mov    -0x18(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     12dd <net_connect+0xed>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
lea    0xd54(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2cac(%rip),%rax
mov    (%rax),%ecx
mov    0x2cb3(%rip),%rax
mov    %ecx,(%rax)
movl   $0xfffffffe,-0x4(%rbp)
jmp    16f3 <net_connect+0x503>
mov    -0x10(%rbp),%rdi
call   10f0 <strdup@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1357 <net_connect+0x167>
mov    -0x18(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1339 <net_connect+0x149>
mov    0x2c8f(%rip),%rax
mov    (%rax),%edi
lea    0xd1f(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2c80(%rip),%rax
mov    (%rax),%ecx
mov    0x2c57(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    16f3 <net_connect+0x503>
mov    -0x40(%rbp),%rdi
mov    $0x3a,%esi
call   1080 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     137b <net_connect+0x18b>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   10c0 <inet_aton@plt>
cmp    $0x0,%rax
jne    141f <net_connect+0x22f>
mov    -0x40(%rbp),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     13c1 <net_connect+0x1d1>
mov    -0x48(%rbp),%rax
mov    (%rax),%rax
mov    0x2c28(%rip),%rcx
cmp    (%rcx),%rax
je     1412 <net_connect+0x222>
mov    -0x18(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     13eb <net_connect+0x1fb>
mov    0x2be1(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rdx
lea    0xc92(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    0x2b95(%rip),%rax
mov    (%rax),%ecx
mov    0x2b9c(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    16f3 <net_connect+0x503>
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%edi
call   1070 <htons@plt>
mov    %eax,-0x50(%rbp)
mov    0x2ba6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     14b9 <net_connect+0x2c9>
mov    0x2b89(%rip),%rax
mov    (%rax),%rdi
mov    0x2b47(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2b21(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <fcntl@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jl     14b4 <net_connect+0x2c4>
mov    -0x24(%rbp),%edi
mov    0x2b15(%rip),%rax
mov    (%rax),%esi
mov    -0x68(%rbp),%rdx
mov    0x2b30(%rip),%rax
or     (%rax),%rdx
call   1050 <fcntl@plt>
mov    %rax,-0x68(%rbp)
jmp    14d6 <net_connect+0x2e6>
mov    0x2b20(%rip),%rax
mov    (%rax),%rdi
mov    0x2ade(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1541 <net_connect+0x351>
mov    -0x18(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1535 <net_connect+0x345>
mov    0x2aaa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2ab6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2a92(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    %rax,%rdx
lea    0xb7f(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x28(%rbp),%ecx
mov    0x2a6d(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    16f3 <net_connect+0x503>
mov    -0x18(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     157a <net_connect+0x38a>
mov    -0x60(%rbp),%edi
call   1060 <inet_ntoa@plt>
mov    %rax,-0x38(%rbp)
mov    0x2a55(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xb56(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x18(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     15e6 <net_connect+0x3f6>
movl   $0x1,-0x2c(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2a4e(%rip),%rax
mov    (%rax),%esi
mov    0x29dd(%rip),%rax
mov    (%rax),%edx
lea    -0x2c(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
jge    15e1 <net_connect+0x3f1>
mov    0x29f3(%rip),%rax
mov    (%rax),%edi
lea    0xb19(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16f3 <net_connect+0x503>
jmp    15e6 <net_connect+0x3f6>
movl   $0x18,-0x20(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   10e0 <connect@plt>
cmp    $0x0,%rax
je     16c7 <net_connect+0x4d7>
mov    -0x18(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     163d <net_connect+0x44d>
mov    0x2984(%rip),%rax
mov    (%rax),%eax
mov    0x29ab(%rip),%rcx
cmp    (%rcx),%eax
jne    1638 <net_connect+0x448>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    16f3 <net_connect+0x503>
jmp    163d <net_connect+0x44d>
mov    0x295c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     16af <net_connect+0x4bf>
mov    -0x60(%rbp),%edi
call   1060 <inet_ntoa@plt>
mov    %rax,-0x38(%rbp)
mov    0x2945(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    0x2913(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rdx
mov    -0x70(%rbp),%ecx
mov    %rax,%r8
lea    0xa6c(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x28(%rbp),%ecx
mov    0x28e7(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    16f3 <net_connect+0x503>
mov    -0x18(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     16ed <net_connect+0x4fd>
mov    0x28db(%rip),%rax
mov    (%rax),%edi
lea    0xa54(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<net_connect>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x3a,%esi
call   1080 <strchr@plt>
test   %rax,%rax
je     1224 <net_connect+0x34>
add    $0x1,%rax
mov    %rax,%rdi
call   10d0 <atoi@plt>
mov    %eax,%r15d
jmp    122a <net_connect+0x3a>
mov    $0x1beb,%r15d
test   %ebp,%ebp
cmovne %ebp,%r15d
test   %r15d,%r15d
je     1257 <net_connect+0x67>
mov    (%rbx),%al
cmp    $0x3a,%al
je     123f <net_connect+0x4f>
test   %al,%al
jne    129a <net_connect+0xaa>
test   $0x1,%r14b
je     1274 <net_connect+0x84>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
jmp    126d <net_connect+0x7d>
test   $0x1,%r14b
je     1274 <net_connect+0x84>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
lea    0xd93(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x2d15(%rip),%rax
mov    (%rax),%eax
mov    0x2d1c(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xfffffffe,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   10f0 <strdup@plt>
test   %rax,%rax
je     1443 <net_connect+0x253>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x3a,%esi
call   1080 <strchr@plt>
test   %rax,%rax
je     12c3 <net_connect+0xd3>
movb   $0x0,(%rax)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   10c0 <inet_aton@plt>
test   %rax,%rax
je     146c <net_connect+0x27c>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15d,%edi
call   1070 <htons@plt>
mov    %eax,0x18(%rsp)
mov    0x2cec(%rip),%rax
mov    (%rax),%rdi
mov    %rdi,0x10(%rsp)
mov    0x2ca5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,%ebx
test   $0x4,%r14b
je     1348 <net_connect+0x158>
mov    0x2c7d(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <fcntl@plt>
test   %rax,%rax
js     1348 <net_connect+0x158>
mov    0x2c7e(%rip),%rcx
mov    (%rcx),%esi
mov    0x2c9d(%rip),%rcx
or     (%rcx),%rax
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fcntl@plt>
test   %ebx,%ebx
js     1497 <net_connect+0x2a7>
test   $0x2,%r14b
je     137c <net_connect+0x18c>
mov    0x8(%rsp),%edi
call   1060 <inet_ntoa@plt>
mov    0x2c52(%rip),%rcx
mov    (%rcx),%edi
lea    0xd5a(%rip),%rsi
mov    %rax,%rdx
mov    %r15d,%ecx
xor    %eax,%eax
call   10b0 <fprintf@plt>
test   $0x8,%r14b
je     13b7 <net_connect+0x1c7>
movl   $0x1,0x4(%rsp)
mov    0x2c57(%rip),%rax
mov    (%rax),%esi
mov    0x2be6(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
js     1547 <net_connect+0x357>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x18,%edx
call   10e0 <connect@plt>
test   %rax,%rax
je     1521 <net_connect+0x331>
mov    0x2bc8(%rip),%r12
mov    (%r12),%ebp
test   $0x4,%r14b
je     13f1 <net_connect+0x201>
mov    0x2be7(%rip),%rax
cmp    (%rax),%ebp
je     128b <net_connect+0x9b>
mov    %ebx,%edi
call   1090 <close@plt>
test   $0x1,%r14b
je     1435 <net_connect+0x245>
mov    0x8(%rsp),%edi
call   1060 <inet_ntoa@plt>
mov    %rax,%r14
mov    0x2ba7(%rip),%rax
mov    (%rax),%ebx
mov    (%r12),%edi
call   1100 <strerror@plt>
lea    0xcf1(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %r15d,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %ebp,(%r12)
mov    $0xffffffff,%ebx
jmp    128b <net_connect+0x9b>
test   $0x1,%r14b
je     1460 <net_connect+0x270>
mov    0x2b68(%rip),%rax
mov    (%rax),%edi
lea    0xbf8(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x2b59(%rip),%rax
jmp    150c <net_connect+0x31c>
mov    %rbx,%rdi
call   10a0 <gethostbyname@plt>
test   %rax,%rax
je     14dd <net_connect+0x2ed>
mov    (%rax),%rcx
mov    0x2b5d(%rip),%rdx
cmp    (%rdx),%rcx
jne    14dd <net_connect+0x2ed>
mov    0x8(%rax),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
jmp    12d9 <net_connect+0xe9>
mov    $0xffffffff,%ebx
test   $0x1,%r14b
je     128b <net_connect+0x9b>
mov    0x2af3(%rip),%r15
mov    (%r15),%ebp
mov    0x2b01(%rip),%rax
mov    (%rax),%r14d
mov    %ebp,%edi
call   1100 <strerror@plt>
lea    0xbd9(%rip),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %ebp,(%r15)
jmp    128b <net_connect+0x9b>
test   $0x1,%r14b
je     14fd <net_connect+0x30d>
mov    0x2ace(%rip),%rax
mov    (%rax),%edi
lea    0xb83(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2a84(%rip),%rax
mov    (%rax),%eax
mov    0x2a8b(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebx
jmp    128b <net_connect+0x9b>
test   $0x2,%r14b
je     128b <net_connect+0x9b>
mov    0x2a86(%rip),%rax
mov    (%rax),%edi
lea    0xbff(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    128b <net_connect+0x9b>
mov    0x2a6a(%rip),%rax
mov    (%rax),%edi
lea    0xb90(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    128b <net_connect+0x9b>

LLVM IR (-O0):
%struct.hostent = type { i64, i64 }
%struct.sockaddr_in = type { %struct.in_addr, i64, i32 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [42 x i8] c"connect: unable to acquire a port number\0A\00"
@EINVAL = global i32 0
@errno = global i32 0
@.str.1 = [39 x i8] c"connect: no destination address given\0A\00"
@.str.2 = [37 x i8] c"connect: unable to duplicate string\0A\00"
@ENOMEM = global i32 0
@AF_INET = global i64 0
@.str.3 = [43 x i8] c"connect: unable to map %s to ipv4 address\0A\00"
@SOCK_STREAM = global i32 0
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i64 0
@.str.4 = [40 x i8] c"connect: unable to allocate socket: %s\0A\00"
@.str.5 = [30 x i8] c"connect: connecting to %s:%u\0A\00"
@SOL_SOCKET = global i32 0
@SO_KEEPALIVE = global i32 0
@.str.6 = [45 x i8] c"connect: cannot set keepalive socket option\0A\00"
@EINPROGRESS = global i32 0
@.str.7 = [38 x i8] c"connect: connect to %s:%u failed: %s\0A\00"
@.str.8 = [33 x i8] c"connect: established connection\0A\00"
define i32 @net_connect(i8* %0, i32 %1, i32 %2) {
%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 i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca %struct.hostent*
%16 = alloca %struct.sockaddr_in
%17 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 7147, i32* %8
%18 = load i8*, i8** %5
%19 = call i8* @strchr(i8* %18, i8 signext 58)
store i8* %19, i8** %13
%20 = load i8*, i8** %13
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %3
%23 = load i8*, i8** %13
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %8
br label %26
26: ; preds = %22, %3
%27 = load i32, i32* %6
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = load i32, i32* %6
store i32 %30, i32* %8
br label %31
31: ; preds = %29, %26
%32 = load i32, i32* %8
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %43
34: ; preds = %31
%35 = load i32, i32* %7
%36 = and i32 %35, 1
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %41
41: ; preds = %38, %34
%42 = load i32, i32* @EINVAL
store i32 %42, i32* @errno
store i32 -2, i32* %4
br label %243
43: ; preds = %31
%44 = load i8*, i8** %5
%45 = getelementptr inbounds i8, i8* %44, i64 0
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 0
br i1 %48, label %55, label %49
49: ; preds = %43
%50 = load i8*, i8** %5
%51 = getelementptr inbounds i8, i8* %50, i64 0
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 58
br i1 %54, label %55, label %64
55: ; preds = %49, %43
%56 = load i32, i32* %7
%57 = and i32 %56, 1
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %62
62: ; preds = %59, %55
%63 = load i32, i32* @EINVAL
store i32 %63, i32* @errno
store i32 -2, i32* %4
br label %243
64: ; preds = %49
%65 = load i8*, i8** %5
%66 = call i8* @strdup(i8* %65)
store i8* %66, i8** %14
%67 = load i8*, i8** %14
%68 = icmp eq i8* %67, null
br i1 %68, label %69, label %78
69: ; preds = %64
%70 = load i32, i32* %7
%71 = and i32 %70, 1
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %69
%74 = load i32, i32* @stderr
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %76
76: ; preds = %73, %69
%77 = load i32, i32* @ENOMEM
store i32 %77, i32* @errno
store i32 -1, i32* %4
br label %243
78: ; preds = %64
%79 = load i8*, i8** %14
%80 = call i8* @strchr(i8* %79, i8 signext 58)
store i8* %80, i8** %13
%81 = load i8*, i8** %13
%82 = icmp ne i8* %81, null
br i1 %82, label %83, label %86
83: ; preds = %78
%84 = load i8*, i8** %13
%85 = getelementptr inbounds i8, i8* %84, i64 0
store i8 0, i8* %85
br label %86
86: ; preds = %83, %78
%87 = load i8*, i8** %14
%88 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 0
%89 = call i64 @inet_aton(i8* %87, %struct.in_addr* %88)
%90 = icmp eq i64 %89, 0
br i1 %90, label %91, label %122
91: ; preds = %86
%92 = load i8*, i8** %14
%93 = call %struct.hostent* @gethostbyname(i8* %92)
store %struct.hostent* %93, %struct.hostent** %15
%94 = load %struct.hostent*, %struct.hostent** %15
%95 = icmp eq %struct.hostent* %94, null
br i1 %95, label %102, label %96
96: ; preds = %91
%97 = load %struct.hostent*, %struct.hostent** %15
%98 = getelementptr inbounds %struct.hostent, %struct.hostent* %97, i32 0, i32 0
%99 = load i64, i64* %98
%100 = load i64, i64* @AF_INET
%101 = icmp ne i64 %99, %100
br i1 %101, label %102, label %114
102: ; preds = %96, %91
%103 = load i32, i32* %7
%104 = and i32 %103, 1
%105 = icmp ne i32 %104, 0
br i1 %105, label %106, label %110
106: ; preds = %102
%107 = load i32, i32* @stderr
%108 = load i8*, i8** %14
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i8* %108)
br label %110
110: ; preds = %106, %102
%111 = load i8*, i8** %14
%112 = call i32 @free(i8* %111)
%113 = load i32, i32* @EINVAL
store i32 %113, i32* @errno
store i32 -1, i32* %4
br label %243
114: ; preds = %96
%115 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 0
%116 = load %struct.hostent*, %struct.hostent** %15
%117 = getelementptr inbounds %struct.hostent, %struct.hostent* %116, i32 0, i32 1
%118 = load i64, i64* %117
%119 = inttoptr i64 %118 to %struct.in_addr*
%120 = bitcast %struct.in_addr* %115 to i8*
%121 = bitcast %struct.in_addr* %119 to i8*
br label %122
122: ; preds = %114, %86
%123 = load i8*, i8** %14
%124 = call i32 @free(i8* %123)
br label %125
125: ; preds = %122
%126 = load i32, i32* %8
%127 = call i32 @htons(i32 %126)
%128 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 2
store i32 %127, i32* %128
%129 = load i64, i64* @AF_INET
%130 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 1
store i64 %129, i64* %130
%131 = load i32, i32* %7
%132 = and i32 %131, 4
%133 = icmp ne i32 %132, 0
br i1 %133, label %134, label %151
134: ; preds = %125
%135 = load i64, i64* @AF_INET
%136 = load i32, i32* @SOCK_STREAM
%137 = call i32 @socket(i64 %135, i32 %136, i32 0)
store i32 %137, i32* %10
%138 = load i32, i32* %10
%139 = load i32, i32* @F_GETFL
%140 = call i64 @fcntl(i32 %138, i32 %139, i64 0)
store i64 %140, i64* %17
%141 = load i64, i64* %17
%142 = icmp sge i64 %141, 0
br i1 %142, label %143, label %150
143: ; preds = %134
%144 = load i32, i32* %10
%145 = load i32, i32* @F_SETFL
%146 = load i64, i64* %17
%147 = load i64, i64* @O_NONBLOCK
%148 = or i64 %146, %147
%149 = call i64 @fcntl(i32 %144, i32 %145, i64 %148)
store i64 %149, i64* %17
br label %150
150: ; preds = %143, %134
br label %155
151: ; preds = %125
%152 = load i64, i64* @AF_INET
%153 = load i32, i32* @SOCK_STREAM
%154 = call i32 @socket(i64 %152, i32 %153, i32 0)
store i32 %154, i32* %10
br label %155
155: ; preds = %151, %150
%156 = load i32, i32* %10
%157 = icmp slt i32 %156, 0
br i1 %157, label %158, label %170
158: ; preds = %155
%159 = load i32, i32* %7
%160 = and i32 %159, 1
%161 = icmp ne i32 %160, 0
br i1 %161, label %162, label %169
162: ; preds = %158
%163 = load i32, i32* @errno
store i32 %163, i32* %11
%164 = load i32, i32* @stderr
%165 = load i32, i32* @errno
%166 = call i8* @strerror(i32 %165)
%167 = call i32 (i32, i8*, ...) @fprintf(i32 %164, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %166)
%168 = load i32, i32* %11
store i32 %168, i32* @errno
br label %169
169: ; preds = %162, %158
store i32 -1, i32* %4
br label %243
170: ; preds = %155
%171 = load i32, i32* %7
%172 = and i32 %171, 2
%173 = icmp ne i32 %172, 0
br i1 %173, label %174, label %183
174: ; preds = %170
%175 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 0
%176 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %175, i32 0, i32 0
%177 = load i32, i32* %176
%178 = call i8* @inet_ntoa(i32 %177)
store i8* %178, i8** %13
%179 = load i32, i32* @stderr
%180 = load i8*, i8** %13
%181 = load i32, i32* %8
%182 = call i32 (i32, i8*, ...) @fprintf(i32 %179, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %180, i32 %181)
br label %183
183: ; preds = %174, %170
%184 = load i32, i32* %7
%185 = and i32 %184, 8
%186 = icmp ne i32 %185, 0
br i1 %186, label %187, label %197
187: ; preds = %183
store i32 1, i32* %12
%188 = load i32, i32* %10
%189 = load i32, i32* @SOL_SOCKET
%190 = load i32, i32* @SO_KEEPALIVE
%191 = call i64 @setsockopt(i32 %188, i32 %189, i32 %190, i32* %12, i32 4)
%192 = icmp slt i64 %191, 0
br i1 %192, label %193, label %196
193: ; preds = %187
%194 = load i32, i32* @stderr
%195 = call i32 (i32, i8*, ...) @fprintf(i32 %194, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %4
br label %243
196: ; preds = %187
br label %197
197: ; preds = %196, %183
store i32 24, i32* %9
%198 = load i32, i32* %10
%199 = bitcast %struct.sockaddr_in* %16 to %struct.sockaddr*
%200 = load i32, i32* %9
%201 = call i64 @connect(i32 %198, %struct.sockaddr* %199, i32 %200)
%202 = icmp ne i64 %201, 0
br i1 %202, label %203, label %234
203: ; preds = %197
%204 = load i32, i32* %7
%205 = and i32 %204, 4
%206 = icmp ne i32 %205, 0
br i1 %206, label %207, label %214
207: ; preds = %203
%208 = load i32, i32* @errno
%209 = load i32, i32* @EINPROGRESS
%210 = icmp eq i32 %208, %209
br i1 %210, label %211, label %213
211: ; preds = %207
%212 = load i32, i32* %10
store i32 %212, i32* %4
br label %243
213: ; preds = %207
br label %214
214: ; preds = %213, %203
%215 = load i32, i32* @errno
store i32 %215, i32* %11
%216 = load i32, i32* %10
%217 = call i32 @close(i32 %216)
%218 = load i32, i32* %7
%219 = and i32 %218, 1
%220 = icmp ne i32 %219, 0
br i1 %220, label %221, label %232
221: ; preds = %214
%222 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 0
%223 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %222, i32 0, i32 0
%224 = load i32, i32* %223
%225 = call i8* @inet_ntoa(i32 %224)
store i8* %225, i8** %13
%226 = load i32, i32* @stderr
%227 = load i8*, i8** %13
%228 = load i32, i32* %8
%229 = load i32, i32* @errno
%230 = call i8* @strerror(i32 %229)
%231 = call i32 (i32, i8*, ...) @fprintf(i32 %226, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i8* %227, i32 %228, i8* %230)
br label %232
232: ; preds = %221, %214
%233 = load i32, i32* %11
store i32 %233, i32* @errno
store i32 -1, i32* %4
br label %243
234: ; preds = %197
%235 = load i32, i32* %7
%236 = and i32 %235, 2
%237 = icmp ne i32 %236, 0
br i1 %237, label %238, label %241
238: ; preds = %234
%239 = load i32, i32* @stderr
%240 = call i32 (i32, i8*, ...) @fprintf(i32 %239, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
br label %241
241: ; preds = %238, %234
%242 = load i32, i32* %10
store i32 %242, i32* %4
br label %243
243: ; preds = %241, %232, %211, %193, %169, %110, %76, %62, %41
%244 = load i32, i32* %4
ret i32 %244
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.in_addr, i64, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [42 x i8] c"connect: unable to acquire a port number\0A\00"
@EINVAL = global i32 0
@errno = global i32 0
@.str.1 = [39 x i8] c"connect: no destination address given\0A\00"
@.str.2 = [37 x i8] c"connect: unable to duplicate string\0A\00"
@ENOMEM = global i32 0
@AF_INET = global i64 0
@.str.3 = [43 x i8] c"connect: unable to map %s to ipv4 address\0A\00"
@SOCK_STREAM = global i32 0
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i64 0
@.str.4 = [40 x i8] c"connect: unable to allocate socket: %s\0A\00"
@.str.5 = [30 x i8] c"connect: connecting to %s:%u\0A\00"
@SOL_SOCKET = global i32 0
@SO_KEEPALIVE = global i32 0
@.str.6 = [45 x i8] c"connect: cannot set keepalive socket option\0A\00"
@EINPROGRESS = global i32 0
@.str.7 = [38 x i8] c"connect: connect to %s:%u failed: %s\0A\00"
@.str.8 = [33 x i8] c"connect: established connection\0A\00"
define i32 @net_connect(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = bitcast i32* %4 to i8*
%7 = bitcast %struct.sockaddr_in* %5 to i8*
%8 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = getelementptr inbounds i8, i8* %8, i64 1
%12 = tail call i32 @atoi(i8* %11)
br label %13
13: ; preds = %10, %3
%14 = phi i32 [ %12, %10 ], [ 7147, %3 ]
%15 = icmp eq i32 %1, 0
%16 = select i1 %15, i32 %14, i32 %1
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %13
%19 = and i32 %2, 1
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %21, %18
%25 = load i32, i32* @EINVAL
store i32 %25, i32* @errno
br label %154
26: ; preds = %13
%27 = load i8, i8* %0
switch i8 %27, label %36 [
i8 0, label %28
i8 58, label %28
]
28: ; preds = %26, %26
%29 = and i32 %2, 1
%30 = icmp eq i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %31, %28
%35 = load i32, i32* @EINVAL
store i32 %35, i32* @errno
br label %154
36: ; preds = %26
%37 = tail call i8* @strdup(i8* %0)
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %47
39: ; preds = %36
%40 = and i32 %2, 1
%41 = icmp eq i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %42, %39
%46 = load i32, i32* @ENOMEM
store i32 %46, i32* @errno
br label %154
47: ; preds = %36
%48 = tail call i8* @strchr(i8* %37, i8 signext 58)
%49 = icmp eq i8* %48, null
br i1 %49, label %51, label %50
50: ; preds = %47
store i8 0, i8* %48
br label %51
51: ; preds = %50, %47
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
%53 = call i64 @inet_aton(i8* %37, %struct.in_addr* %52)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %78
55: ; preds = %51
%56 = call %struct.hostent* @gethostbyname(i8* %37)
%57 = icmp eq %struct.hostent* %56, null
br i1 %57, label %63, label %58
58: ; preds = %55
%59 = getelementptr inbounds %struct.hostent, %struct.hostent* %56, i64 0, i32 0
%60 = load i64, i64* %59
%61 = load i64, i64* @AF_INET
%62 = icmp eq i64 %60, %61
br i1 %62, label %72, label %63
63: ; preds = %58, %55
%64 = and i32 %2, 1
%65 = icmp eq i32 %64, 0
br i1 %65, label %69, label %66
66: ; preds = %63
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i8* %37)
br label %69
69: ; preds = %66, %63
%70 = call i32 @free(i8* %37)
%71 = load i32, i32* @EINVAL
store i32 %71, i32* @errno
br label %154
72: ; preds = %58
%73 = getelementptr inbounds %struct.hostent, %struct.hostent* %56, i64 0, i32 1
%74 = load i64, i64* %73
%75 = inttoptr i64 %74 to i32*
%76 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
%77 = load i32, i32* %75
store i32 %77, i32* %76
br label %78
78: ; preds = %72, %51
%79 = call i32 @free(i8* %37)
%80 = call i32 @htons(i32 %16)
%81 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %80, i32* %81
%82 = load i64, i64* @AF_INET
%83 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i64 %82, i64* %83
%84 = and i32 %2, 4
%85 = icmp eq i32 %84, 0
%86 = load i32, i32* @SOCK_STREAM
%87 = call i32 @socket(i64 %82, i32 %86, i32 0)
br i1 %85, label %97, label %88
88: ; preds = %78
%89 = load i32, i32* @F_GETFL
%90 = call i64 @fcntl(i32 %87, i32 %89, i64 0)
%91 = icmp sgt i64 %90, -1
br i1 %91, label %92, label %97
92: ; preds = %88
%93 = load i32, i32* @F_SETFL
%94 = load i64, i64* @O_NONBLOCK
%95 = or i64 %94, %90
%96 = call i64 @fcntl(i32 %87, i32 %93, i64 %95)
br label %97
97: ; preds = %78, %88, %92
%98 = icmp slt i32 %87, 0
br i1 %98, label %99, label %107
99: ; preds = %97
%100 = and i32 %2, 1
%101 = icmp eq i32 %100, 0
br i1 %101, label %154, label %102
102: ; preds = %99
%103 = load i32, i32* @errno
%104 = load i32, i32* @stderr
%105 = call i8* @strerror(i32 %103)
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %105)
store i32 %103, i32* @errno
br label %154
107: ; preds = %97
%108 = and i32 %2, 2
%109 = icmp eq i32 %108, 0
br i1 %109, label %116, label %110
110: ; preds = %107
%111 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
%112 = load i32, i32* %111
%113 = call i8* @inet_ntoa(i32 %112)
%114 = load i32, i32* @stderr
%115 = call i32 (i32, i8*, ...) @fprintf(i32 %114, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %113, i32 %16)
br label %116
116: ; preds = %110, %107
%117 = and i32 %2, 8
%118 = icmp eq i32 %117, 0
br i1 %118, label %127, label %119
119: ; preds = %116
store i32 1, i32* %4
%120 = load i32, i32* @SOL_SOCKET
%121 = load i32, i32* @SO_KEEPALIVE
%122 = call i64 @setsockopt(i32 %87, i32 %120, i32 %121, i32* %4, i32 4)
%123 = icmp slt i64 %122, 0
br i1 %123, label %124, label %127
124: ; preds = %119
%125 = load i32, i32* @stderr
%126 = call i32 (i32, i8*, ...) @fprintf(i32 %125, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
br label %154
127: ; preds = %119, %116
%128 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%129 = call i64 @connect(i32 %87, %struct.sockaddr* %128, i32 24)
%130 = icmp eq i64 %129, 0
br i1 %130, label %150, label %131
131: ; preds = %127
%132 = load i32, i32* @errno
%133 = xor i1 %85, true
%134 = load i32, i32* @EINPROGRESS
%135 = icmp eq i32 %132, %134
%136 = select i1 %133, i1 %135, i1 false
br i1 %136, label %154, label %137
137: ; preds = %131
%138 = call i32 @close(i32 %87)
%139 = and i32 %2, 1
%140 = icmp eq i32 %139, 0
br i1 %140, label %149, label %141
141: ; preds = %137
%142 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
%143 = load i32, i32* %142
%144 = call i8* @inet_ntoa(i32 %143)
%145 = load i32, i32* @stderr
%146 = load i32, i32* @errno
%147 = call i8* @strerror(i32 %146)
%148 = call i32 (i32, i8*, ...) @fprintf(i32 %145, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i8* %144, i32 %16, i8* %147)
br label %149
149: ; preds = %141, %137
store i32 %132, i32* @errno
br label %154
150: ; preds = %127
br i1 %109, label %154, label %151
151: ; preds = %150
%152 = load i32, i32* @stderr
%153 = call i32 (i32, i8*, ...) @fprintf(i32 %152, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
br label %154
154: ; preds = %131, %150, %151, %99, %102, %149, %124, %69, %45, %34, %24
%155 = phi i32 [ -2, %24 ], [ -2, %34 ], [ -1, %45 ], [ -1, %69 ], [ -1, %124 ], [ -1, %149 ], [ -1, %102 ], [ -1, %99 ], [ %87, %151 ], [ %87, %150 ], [ %87, %131 ]
ret i32 %155
}