#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_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  void *s_addr;
};
struct sockaddr_in6 {
  TYPE_1__ sin6_addr;
  void *sin6_port;
};
struct sockaddr_in {
  int sin_family;
  int sa_family;
  TYPE_1__ sin_addr;
  void *sin_port;
};
struct sockaddr {
  int sin_family;
  int sa_family;
  TYPE_1__ sin_addr;
  void *sin_port;
};
struct servent {
  int /*<<< orphan*/ s_port;
};
struct hostent {
  int h_addrtype;
  char **h_addr_list;
  int h_length;
  int /*<<< orphan*/ h_name;
};
struct addrinfo {
  scalar_t__ ai_family;
  scalar_t__ ai_socktype;
  int ai_flags;
  int /*<<< orphan*/ *ai_canonname;
  struct addrinfo *ai_next;
};

/* Variables and functions */
#define AF_INET 133
#define AF_INET6 132
#define HOST_NOT_FOUND 131
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ INADDR_LOOPBACK;
#define NO_DATA 130
#define NO_RECOVERY 129
scalar_t__ PF_INET;
scalar_t__ PF_INET6;
scalar_t__ PF_UNSPEC;
scalar_t__ SOCK_DGRAM;
scalar_t__ SOCK_STREAM;
#define TRY_AGAIN 128
struct addrinfo *dup_addrinfo(struct addrinfo *, struct sockaddr_in *, size_t);
scalar_t__ errno;
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
struct hostent *gethostbyname(char const *);
struct servent *getservbyname(char const *, char const *);
int h_errno;
void *htonl(int /*<<< orphan*/);
void *htons(int);
void *inet_addr(char const *);
scalar_t__ inet_pton(int, char const *, TYPE_1__ *);
scalar_t__ isdigit(char const);
int /*<<< orphan*/ *malloc(scalar_t__);
int /*<<< orphan*/ memcpy(TYPE_1__ *, char *, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ strlen(int /*<<< orphan*/);
int strtol(char const *, int /*<<< orphan*/ *, int);
int getaddrinfo(const char *nodename, const char *servname,
                const struct addrinfo *hints, struct addrinfo **res) {
  struct hostent *hp;
  struct servent *servent;
  const char *socktype;
  int port;
  struct addrinfo hint, result;
  struct addrinfo *ai, *sai, *eai;
  char **addrs;
  if (servname == NULL && nodename == NULL)
    return 8;
  memset(&result, 0, sizeof result);
  if (hints == NULL) {
    memset(&hint, 0, sizeof hint);
    hint.ai_family = PF_UNSPEC;
    hints = &hint;
  }
  if (servname == NULL)
    port = 0;
  else {
    if (hints->ai_socktype == SOCK_STREAM)
      socktype = "tcp";
    else if (hints->ai_socktype == SOCK_DGRAM)
      socktype = "udp";
    else
      return 9;
    result.ai_socktype = hints->ai_socktype;
    if (isdigit(*servname))
      port = strtol(servname, NULL, 10);
    else if ((servent = getservbyname(servname, socktype)) != NULL)
      port = ntohs(servent->s_port);
    else
      return 8;
  }
  if (nodename == NULL) {
    struct sockaddr_in sin;
    if (hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET)
      result.ai_family = AF_INET;
    else
      return 5;
    sin.sin_family = result.ai_family;
    sin.sin_port = htons(port);
    if (hints->ai_flags & 1)
      sin.sin_addr.s_addr = htonl(INADDR_ANY);
    else
      sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
    *res = dup_addrinfo(&result, &sin, sizeof sin);
    return (*res == NULL) ? 6 : 0;
  }
  if (hints->ai_flags & 4) {
    struct sockaddr_in sin;
    if (hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET)
      result.ai_family = AF_INET;
    else
      return 5;
    sin.sin_family = result.ai_family;
    sin.sin_port = htons(port);
    if (inet_pton(result.ai_family, nodename, &sin.sin_addr) == 0)
      return 8;
    sin.sin_addr.s_addr = inet_addr(nodename);
    *res = dup_addrinfo(&result, &sin, sizeof sin);
    return (*res == NULL) ? 6 : 0;
  }
  errno = 0;
  hp = gethostbyname(nodename);
  if (hp == NULL) {
    if (errno != 0) {
      return 11;
    }
    switch (h_errno) {
    case HOST_NOT_FOUND:
      return 7;
    case NO_DATA:
      return 7;
    case NO_RECOVERY:
      return 4;
    case TRY_AGAIN:
      return 2;
    default:
      return 4;
    }
    return 4;
  }
  switch (hp->h_addrtype) {
  case AF_INET:
    if (!(hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET))
      return 5;
    break;
  case AF_INET6:
    if (!(hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET6))
      return 5;
    break;
  default:
    return 5;
  }
  sai = eai = NULL;
  for (addrs = hp->h_addr_list; *addrs != NULL; addrs++) {
    struct sockaddr sa;
    size_t addrlen;
    if (hp->h_length < 1)
      continue;
    sa.sa_family = hp->h_addrtype;
    switch (hp->h_addrtype) {
    case AF_INET:
      ((struct sockaddr_in *)&sa)->sin_port = htons(port);
      memcpy(&((struct sockaddr_in *)&sa)->sin_addr, *addrs, hp->h_length);
      addrlen = sizeof(struct sockaddr_in);
      break;
    case AF_INET6:
      ((struct sockaddr_in6 *)&sa)->sin6_port = htons(port);
      memcpy(&((struct sockaddr_in6 *)&sa)->sin6_addr, *addrs, hp->h_length);
      addrlen = sizeof(struct sockaddr_in6);
      break;
    default:
      continue;
    }
    result.ai_family = hp->h_addrtype;
    ai = dup_addrinfo(&result, &sa, addrlen);
    if (ai == NULL) {
      freeaddrinfo(sai);
      return 6;
    }
    if (sai == NULL)
      sai = ai;
    else
      eai->ai_next = ai;
    eai = ai;
  }
  if (sai == NULL) {
    return 7;
  }
  if (hints->ai_flags & 2) {
    sai->ai_canonname = malloc(strlen(hp->h_name) + 1);
    if (sai->ai_canonname == NULL) {
      freeaddrinfo(sai);
      return 6;
    }
    strcpy(sai->ai_canonname, hp->h_name);
  }
  *res = sai;
  return 0;
}


x86 assembly (clang, -O0):
<getaddrinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    123d <getaddrinfo+0x3d>
cmpq   $0x0,-0x10(%rbp)
jne    123d <getaddrinfo+0x3d>
movl   $0x8,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
lea    -0x98(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1090 <memset@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1281 <getaddrinfo+0x81>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1090 <memset@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x70(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1298 <getaddrinfo+0x98>
movl   $0x0,-0x44(%rbp)
jmp    137c <getaddrinfo+0x17c>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2d09(%rip),%rcx
cmp    (%rcx),%rax
jne    12c0 <getaddrinfo+0xc0>
lea    0xd59(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    12f9 <getaddrinfo+0xf9>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2d01(%rip),%rcx
cmp    (%rcx),%rax
jne    12e8 <getaddrinfo+0xe8>
lea    0xd35(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    12f4 <getaddrinfo+0xf4>
movl   $0x9,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
jmp    12f9 <getaddrinfo+0xf9>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x90(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1338 <getaddrinfo+0x138>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10c0 <strtol@plt>
mov    %eax,-0x44(%rbp)
jmp    1377 <getaddrinfo+0x177>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1070 <getservbyname@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1366 <getaddrinfo+0x166>
mov    -0x38(%rbp),%rax
mov    (%rax),%edi
call   1100 <ntohs@plt>
mov    %eax,-0x44(%rbp)
jmp    1372 <getaddrinfo+0x172>
movl   $0x8,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
jmp    1377 <getaddrinfo+0x177>
jmp    137c <getaddrinfo+0x17c>
cmpq   $0x0,-0x10(%rbp)
jne    146e <getaddrinfo+0x26e>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2c53(%rip),%rcx
cmp    (%rcx),%rax
je     13b5 <getaddrinfo+0x1b5>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2bf4(%rip),%rcx
cmp    (%rcx),%rax
jne    13c5 <getaddrinfo+0x1c5>
movq   $0x85,-0x98(%rbp)
jmp    13d1 <getaddrinfo+0x1d1>
movl   $0x5,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
mov    -0x98(%rbp),%rax
mov    %eax,-0xd0(%rbp)
mov    -0x44(%rbp),%edi
call   1060 <htons@plt>
mov    %rax,-0xc0(%rbp)
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     141a <getaddrinfo+0x21a>
mov    0x2bd1(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %rax,-0xc8(%rbp)
jmp    142f <getaddrinfo+0x22f>
mov    0x2b9f(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %rax,-0xc8(%rbp)
lea    -0x98(%rbp),%rdi
lea    -0xd0(%rbp),%rsi
mov    $0x18,%edx
call   1110 <dup_addrinfo@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%rdx
xor    %eax,%eax
mov    $0x6,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1569 <getaddrinfo+0x369>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2b59(%rip),%rcx
cmp    (%rcx),%rax
je     14af <getaddrinfo+0x2af>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2afa(%rip),%rcx
cmp    (%rcx),%rax
jne    14bf <getaddrinfo+0x2bf>
movq   $0x85,-0x98(%rbp)
jmp    14cb <getaddrinfo+0x2cb>
movl   $0x5,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
mov    -0x98(%rbp),%rax
mov    %eax,-0xe8(%rbp)
mov    -0x44(%rbp),%edi
call   1060 <htons@plt>
mov    %rax,-0xd8(%rbp)
mov    -0x98(%rbp),%rax
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
lea    -0xe8(%rbp),%rdx
add    $0x8,%rdx
call   10e0 <inet_pton@plt>
cmp    $0x0,%rax
jne    151a <getaddrinfo+0x31a>
movl   $0x8,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
mov    -0x10(%rbp),%rdi
call   10a0 <inet_addr@plt>
mov    %rax,-0xe0(%rbp)
lea    -0x98(%rbp),%rdi
lea    -0xe8(%rbp),%rsi
mov    $0x18,%edx
call   1110 <dup_addrinfo@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%rdx
xor    %eax,%eax
mov    $0x6,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
mov    0x2a38(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   10b0 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    161d <getaddrinfo+0x41d>
mov    0x2a12(%rip),%rax
cmpq   $0x0,(%rax)
je     15ac <getaddrinfo+0x3ac>
movl   $0xb,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
mov    0x2a15(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x110(%rbp)
sub    $0x3,%eax
ja     1611 <getaddrinfo+0x411>
mov    -0x110(%rbp),%rax
lea    0xa28(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x7,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
movl   $0x7,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
movl   $0x4,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
movl   $0x2,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
movl   $0x4,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x114(%rbp)
sub    $0x84,%eax
je     168e <getaddrinfo+0x48e>
jmp    1639 <getaddrinfo+0x439>
mov    -0x114(%rbp),%eax
sub    $0x85,%eax
jne    16cd <getaddrinfo+0x4cd>
jmp    164f <getaddrinfo+0x44f>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x298b(%rip),%rcx
cmp    (%rcx),%rax
je     1689 <getaddrinfo+0x489>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x292c(%rip),%rcx
cmp    (%rcx),%rax
je     1689 <getaddrinfo+0x489>
movl   $0x5,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
jmp    16d9 <getaddrinfo+0x4d9>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x294c(%rip),%rcx
cmp    (%rcx),%rax
je     16c8 <getaddrinfo+0x4c8>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x292d(%rip),%rcx
cmp    (%rcx),%rax
je     16c8 <getaddrinfo+0x4c8>
movl   $0x5,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
jmp    16d9 <getaddrinfo+0x4d9>
movl   $0x5,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
movq   $0x0,-0xb0(%rbp)
movq   $0x0,-0xa8(%rbp)
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0xb8(%rbp)
mov    -0xb8(%rbp),%rax
cmpq   $0x0,(%rax)
je     188e <getaddrinfo+0x68e>
mov    -0x30(%rbp),%rax
cmpl   $0x1,0x10(%rax)
jge    1722 <getaddrinfo+0x522>
jmp    1877 <getaddrinfo+0x677>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xfc(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x118(%rbp)
sub    $0x84,%eax
je     17a0 <getaddrinfo+0x5a0>
jmp    174a <getaddrinfo+0x54a>
mov    -0x118(%rbp),%eax
sub    $0x85,%eax
jne    17dc <getaddrinfo+0x5dc>
jmp    1760 <getaddrinfo+0x560>
mov    -0x44(%rbp),%edi
call   1060 <htons@plt>
mov    %rax,-0xf0(%rbp)
lea    -0x100(%rbp),%rdi
add    $0x8,%rdi
mov    -0xb8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%edx
call   10d0 <memcpy@plt>
movq   $0x18,-0x108(%rbp)
jmp    17e1 <getaddrinfo+0x5e1>
mov    -0x44(%rbp),%edi
call   1060 <htons@plt>
mov    %rax,-0xf8(%rbp)
lea    -0x100(%rbp),%rdi
mov    -0xb8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%edx
call   10d0 <memcpy@plt>
movq   $0x10,-0x108(%rbp)
jmp    17e1 <getaddrinfo+0x5e1>
jmp    1877 <getaddrinfo+0x677>
mov    -0x30(%rbp),%rax
movslq (%rax),%rax
mov    %rax,-0x98(%rbp)
lea    -0x100(%rbp),%rsi
mov    -0x108(%rbp),%rdx
lea    -0x98(%rbp),%rdi
call   1110 <dup_addrinfo@plt>
mov    %rax,-0xa0(%rbp)
cmpq   $0x0,-0xa0(%rbp)
jne    1836 <getaddrinfo+0x636>
mov    -0xa8(%rbp),%rdi
call   1120 <freeaddrinfo@plt>
movl   $0x6,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
cmpq   $0x0,-0xa8(%rbp)
jne    1857 <getaddrinfo+0x657>
mov    -0xa0(%rbp),%rax
mov    %rax,-0xa8(%rbp)
jmp    1869 <getaddrinfo+0x669>
mov    -0xa0(%rbp),%rcx
mov    -0xb0(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    -0xa0(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0xb8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0xb8(%rbp)
jmp    16fe <getaddrinfo+0x4fe>
cmpq   $0x0,-0xa8(%rbp)
jne    18a8 <getaddrinfo+0x6a8>
movl   $0x7,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1922 <getaddrinfo+0x722>
mov    -0x30(%rbp),%rax
mov    0x14(%rax),%edi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   10f0 <malloc@plt>
mov    %rax,%rcx
mov    -0xa8(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0xa8(%rbp),%rax
cmpq   $0x0,0x18(%rax)
jne    190b <getaddrinfo+0x70b>
mov    -0xa8(%rbp),%rdi
call   1120 <freeaddrinfo@plt>
movl   $0x6,-0x4(%rbp)
jmp    1937 <getaddrinfo+0x737>
mov    -0xa8(%rbp),%rax
mov    0x18(%rax),%rdi
mov    -0x30(%rbp),%rax
mov    0x14(%rax),%esi
call   1040 <strcpy@plt>
mov    -0xa8(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getaddrinfo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    $0x8,%r14d
mov    %rdi,%rax
or     %rsi,%rax
jne    1234 <getaddrinfo+0x34>
mov    %r14d,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rcx,%r15
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0x48(%rsp),%rdi
xor    %r12d,%r12d
xor    %esi,%esi
mov    $0x28,%edx
call   1090 <memset@plt>
test   %r13,%r13
je     127e <getaddrinfo+0x7e>
test   %rbp,%rbp
je     12a6 <getaddrinfo+0xa6>
mov    0x8(%r13),%rax
mov    0x2d47(%rip),%rcx
cmp    (%rcx),%rax
jne    131f <getaddrinfo+0x11f>
lea    0xd87(%rip),%r14
jmp    133c <getaddrinfo+0x13c>
lea    0x70(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1090 <memset@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x70(%rsp)
test   %rbp,%rbp
jne    125e <getaddrinfo+0x5e>
test   %rbx,%rbx
je     13f7 <getaddrinfo+0x1f7>
testb  $0x4,0x10(%r13)
jne    1363 <getaddrinfo+0x163>
mov    0x2ce7(%rip),%rbp
movq   $0x0,0x0(%rbp)
mov    %rbx,%rdi
call   10b0 <gethostbyname@plt>
test   %rax,%rax
je     144a <getaddrinfo+0x24a>
mov    (%rax),%ecx
mov    $0x5,%r14d
cmp    $0x84,%ecx
mov    %rax,0x18(%rsp)
je     14c4 <getaddrinfo+0x2c4>
cmp    $0x85,%ecx
jne    121f <getaddrinfo+0x1f>
mov    0x0(%r13),%rax
mov    0x2cde(%rip),%rcx
cmp    (%rcx),%rax
je     14e4 <getaddrinfo+0x2e4>
mov    0x2c86(%rip),%rcx
jmp    14db <getaddrinfo+0x2db>
mov    0x2caa(%rip),%rcx
mov    $0x9,%r14d
cmp    (%rcx),%rax
jne    121f <getaddrinfo+0x1f>
lea    0xcc8(%rip),%r14
mov    %rax,0x50(%rsp)
movsbl 0x0(%rbp),%edi
call   1030 <isdigit@plt>
mov    %rbp,%rdi
test   %rax,%rax
je     13cd <getaddrinfo+0x1cd>
xor    %esi,%esi
mov    $0xa,%edx
call   10c0 <strtol@plt>
jmp    13eb <getaddrinfo+0x1eb>
mov    0x0(%r13),%rax
mov    0x2c7a(%rip),%rcx
cmp    (%rcx),%rax
je     1389 <getaddrinfo+0x189>
mov    0x2c26(%rip),%rcx
mov    $0x5,%r14d
cmp    (%rcx),%rax
jne    121f <getaddrinfo+0x1f>
movq   $0x85,0x48(%rsp)
movl   $0x85,(%rsp)
mov    %r12d,%edi
call   1060 <htons@plt>
mov    %rax,0x10(%rsp)
mov    0x48(%rsp),%edi
lea    0x8(%rsp),%rdx
mov    %rbx,%rsi
call   10e0 <inet_pton@plt>
test   %rax,%rax
je     15de <getaddrinfo+0x3de>
mov    %rbx,%rdi
call   10a0 <inet_addr@plt>
jmp    1496 <getaddrinfo+0x296>
mov    %r14,%rsi
call   1070 <getservbyname@plt>
mov    $0x8,%r14d
test   %rax,%rax
je     121f <getaddrinfo+0x1f>
mov    (%rax),%edi
call   1100 <ntohs@plt>
mov    %eax,%r12d
test   %rbx,%rbx
jne    12af <getaddrinfo+0xaf>
mov    0x0(%r13),%rax
mov    0x2be6(%rip),%rcx
cmp    (%rcx),%rax
je     141d <getaddrinfo+0x21d>
mov    0x2b92(%rip),%rcx
mov    $0x5,%r14d
cmp    (%rcx),%rax
jne    121f <getaddrinfo+0x1f>
movq   $0x85,0x48(%rsp)
movl   $0x85,(%rsp)
mov    %r12d,%edi
call   1060 <htons@plt>
mov    %rax,0x10(%rsp)
testb  $0x1,0x10(%r13)
jne    1488 <getaddrinfo+0x288>
mov    0x2b78(%rip),%rax
jmp    148f <getaddrinfo+0x28f>
mov    $0xb,%r14d
cmpq   $0x0,0x0(%rbp)
jne    121f <getaddrinfo+0x1f>
mov    0x2b66(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
mov    $0x4,%r14d
cmp    $0x4,%eax
jae    121f <getaddrinfo+0x1f>
cltq
lea    0xb89(%rip),%rcx
mov    (%rcx,%rax,4),%r14d
jmp    121f <getaddrinfo+0x1f>
mov    0x2b49(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %rax,0x8(%rsp)
lea    0x48(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x18,%edx
call   1110 <dup_addrinfo@plt>
mov    %rax,(%r15)
xor    %ecx,%ecx
test   %rax,%rax
mov    $0x6,%r14d
cmovne %ecx,%r14d
jmp    121f <getaddrinfo+0x1f>
mov    0x0(%r13),%rax
mov    0x2b19(%rip),%rcx
cmp    (%rcx),%rax
je     14e4 <getaddrinfo+0x2e4>
mov    0x2b05(%rip),%rcx
cmp    (%rcx),%rax
jne    121f <getaddrinfo+0x1f>
mov    %r15,0x40(%rsp)
mov    0x18(%rsp),%rbx
mov    0x8(%rbx),%r15
mov    $0x7,%r14d
cmpq   $0x0,(%r15)
je     121f <getaddrinfo+0x1f>
mov    %r13,0x38(%rsp)
add    $0x8,%r15
xor    %ebp,%ebp
mov    %rsp,%r13
xor    %ecx,%ecx
mov    %r12d,0x2c(%rsp)
jmp    1534 <getaddrinfo+0x334>
nopl   0x0(%rax)
mov    %rbp,%rax
cmpq   $0x0,(%r15)
lea    0x8(%r15),%r15
mov    %rax,%rbp
je     15e9 <getaddrinfo+0x3e9>
cmpl   $0x0,0x10(%rbx)
jle    1520 <getaddrinfo+0x320>
mov    (%rbx),%eax
mov    %eax,0x4(%rsp)
cmp    $0x85,%eax
je     1567 <getaddrinfo+0x367>
cmp    $0x84,%eax
jne    1520 <getaddrinfo+0x320>
mov    %rcx,0x20(%rsp)
mov    $0x10,%eax
mov    %rax,0x30(%rsp)
lea    0x8(%rsp),%r12
mov    %r13,%rbx
jmp    1580 <getaddrinfo+0x380>
mov    %rcx,0x20(%rsp)
mov    $0x18,%eax
mov    %rax,0x30(%rsp)
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%rbx
mov    0x2c(%rsp),%edi
call   1060 <htons@plt>
mov    %rax,(%r12)
mov    -0x8(%r15),%rsi
mov    0x18(%rsp),%rax
mov    0x10(%rax),%edx
mov    %rbx,%rdi
mov    %rax,%rbx
call   10d0 <memcpy@plt>
movslq (%rbx),%rax
mov    %rax,0x48(%rsp)
lea    0x48(%rsp),%rdi
mov    %r13,%rsi
mov    0x30(%rsp),%rdx
call   1110 <dup_addrinfo@plt>
test   %rax,%rax
je     163d <getaddrinfo+0x43d>
mov    0x20(%rsp),%rcx
test   %rcx,%rcx
je     15d6 <getaddrinfo+0x3d6>
mov    %rax,0x20(%rbp)
jmp    1523 <getaddrinfo+0x323>
mov    %rax,%rcx
jmp    1523 <getaddrinfo+0x323>
mov    $0x8,%r14d
jmp    121f <getaddrinfo+0x1f>
test   %rcx,%rcx
mov    0x40(%rsp),%rbx
mov    0x38(%rsp),%rax
je     121f <getaddrinfo+0x1f>
testb  $0x2,0x10(%rax)
je     1632 <getaddrinfo+0x432>
mov    0x18(%rsp),%rbp
mov    %rcx,%r14
mov    0x14(%rbp),%edi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   10f0 <malloc@plt>
mov    %rax,0x18(%r14)
test   %rax,%rax
je     1644 <getaddrinfo+0x444>
mov    0x14(%rbp),%esi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %r14,%rcx
mov    %rcx,(%rbx)
xor    %r14d,%r14d
jmp    121f <getaddrinfo+0x1f>
mov    0x20(%rsp),%rdi
jmp    1647 <getaddrinfo+0x447>
mov    %r14,%rdi
call   1120 <freeaddrinfo@plt>
mov    $0x6,%r14d
jmp    121f <getaddrinfo+0x1f>

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

LLVM IR (-O2):
%struct.addrinfo = type { i64, i64, i32, i32*, %struct.addrinfo* }
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_3__, i8* }
%struct.TYPE_3__ = type { i8* }
%struct.sockaddr = type { i32, i32, %struct.TYPE_3__, i8* }
%struct.servent = type { i32 }
%struct.hostent = type { i32, i8**, i32, i32 }
@PF_UNSPEC = global i64 0
@SOCK_STREAM = global i64 0
@.str = [4 x i8] c"tcp\00"
@SOCK_DGRAM = global i64 0
@.str.1 = [4 x i8] c"udp\00"
@PF_INET = global i64 0
@INADDR_ANY = global i32 0
@INADDR_LOOPBACK = global i32 0
@errno = global i64 0
@h_errno = global i32 0
@PF_INET6 = global i64 0
@switch.table.getaddrinfo = [4 x i32] [i32 2, i32 4, i32 7, i32 7]
define i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %2, %struct.addrinfo** nocapture writeonly %3) {
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr
%10 = bitcast %struct.addrinfo* %5 to i8*
%11 = bitcast %struct.addrinfo* %6 to i8*
%12 = icmp eq i8* %1, null
%13 = icmp eq i8* %0, null
%14 = and i1 %13, %12
br i1 %14, label %210, label %15
15: ; preds = %4
%16 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 40)
%17 = icmp eq %struct.addrinfo* %2, null
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = call i32 @memset(%struct.addrinfo* %5, i32 0, i32 40)
%20 = load i64, i64* @PF_UNSPEC
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 0
store i64 %20, i64* %21
br label %22
22: ; preds = %18, %15
%23 = phi %struct.addrinfo* [ %5, %18 ], [ %2, %15 ]
br i1 %12, label %47, label %24
24: ; preds = %22
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 1
%26 = load i64, i64* %25
%27 = load i64, i64* @SOCK_STREAM
%28 = icmp eq i64 %26, %27
br i1 %28, label %32, label %29
29: ; preds = %24
%30 = load i64, i64* @SOCK_DGRAM
%31 = icmp eq i64 %26, %30
br i1 %31, label %32, label %210
32: ; preds = %29, %24
%33 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %24 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %29 ]
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 1
store i64 %26, i64* %34
%35 = load i8, i8* %1
%36 = call i64 @isdigit(i8 signext %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %32
%39 = call i32 @strtol(i8* nocapture %1, i32* null, i32 10)
br label %47
40: ; preds = %32
%41 = call %struct.servent* @getservbyname(i8* %1, i8* %33)
%42 = icmp eq %struct.servent* %41, null
br i1 %42, label %210, label %43
43: ; preds = %40
%44 = getelementptr inbounds %struct.servent, %struct.servent* %41, i64 0, i32 0
%45 = load i32, i32* %44
%46 = call i32 @ntohs(i32 %45)
br label %47
47: ; preds = %22, %38, %43
%48 = phi i32 [ %39, %38 ], [ %46, %43 ], [ 0, %22 ]
br i1 %13, label %49, label %77
49: ; preds = %47
%50 = bitcast %struct.sockaddr_in* %7 to i8*
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 0
%52 = load i64, i64* %51
%53 = load i64, i64* @PF_UNSPEC
%54 = icmp eq i64 %52, %53
%55 = load i64, i64* @PF_INET
%56 = icmp eq i64 %52, %55
%57 = select i1 %54, i1 true, i1 %56
br i1 %57, label %58, label %75
58: ; preds = %49
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 0
store i64 133, i64* %59
%60 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0
store i32 133, i32* %60
%61 = call i8* @htons(i32 %48)
%62 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 3
store i8* %61, i8** %62
%63 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 2
%64 = load i32, i32* %63
%65 = and i32 %64, 1
%66 = icmp eq i32 %65, 0
%67 = load i32, i32* @INADDR_LOOPBACK
%68 = load i32, i32* @INADDR_ANY
%69 = select i1 %66, i32 %67, i32 %68
%70 = call i8* @htonl(i32 %69)
%71 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 2, i32 0
store i8* %70, i8** %71
%72 = call %struct.addrinfo* @dup_addrinfo(%struct.addrinfo* %6, %struct.sockaddr_in* %7, i64 24)
store %struct.addrinfo* %72, %struct.addrinfo** %3
%73 = icmp eq %struct.addrinfo* %72, null
%74 = select i1 %73, i32 6, i32 0
br label %75
75: ; preds = %49, %58
%76 = phi i32 [ %74, %58 ], [ 5, %49 ]
br label %210
77: ; preds = %47
%78 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 2
%79 = load i32, i32* %78
%80 = and i32 %79, 4
%81 = icmp eq i32 %80, 0
br i1 %81, label %109, label %82
82: ; preds = %77
%83 = bitcast %struct.sockaddr_in* %8 to i8*
%84 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 0
%85 = load i64, i64* %84
%86 = load i64, i64* @PF_UNSPEC
%87 = icmp eq i64 %85, %86
%88 = load i64, i64* @PF_INET
%89 = icmp eq i64 %85, %88
%90 = select i1 %87, i1 true, i1 %89
br i1 %90, label %91, label %107
91: ; preds = %82
%92 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 0
store i64 133, i64* %92
%93 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 0
store i32 133, i32* %93
%94 = call i8* @htons(i32 %48)
%95 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 3
store i8* %94, i8** %95
%96 = load i64, i64* %92
%97 = trunc i64 %96 to i32
%98 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 2
%99 = call i64 @inet_pton(i32 %97, i8* %0, %struct.TYPE_3__* %98)
%100 = icmp eq i64 %99, 0
br i1 %100, label %107, label %101
101: ; preds = %91
%102 = call i8* @inet_addr(i8* %0)
%103 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %98, i64 0, i32 0
store i8* %102, i8** %103
%104 = call %struct.addrinfo* @dup_addrinfo(%struct.addrinfo* %6, %struct.sockaddr_in* %8, i64 24)
store %struct.addrinfo* %104, %struct.addrinfo** %3
%105 = icmp eq %struct.addrinfo* %104, null
%106 = select i1 %105, i32 6, i32 0
br label %107
107: ; preds = %91, %82, %101
%108 = phi i32 [ %106, %101 ], [ 5, %82 ], [ 8, %91 ]
br label %210
109: ; preds = %77
store i64 0, i64* @errno
%110 = call %struct.hostent* @gethostbyname(i8* %0)
%111 = icmp eq %struct.hostent* %110, null
br i1 %111, label %112, label %119
112: ; preds = %109
%113 = load i64, i64* @errno
%114 = icmp eq i64 %113, 0
br i1 %114, label %115, label %210
115: ; preds = %112
%116 = load i32, i32* @h_errno
%117 = add i32 %116, -128
%118 = icmp ult i32 %117, 4
br i1 %118, label %206, label %210
119: ; preds = %109
%120 = getelementptr inbounds %struct.hostent, %struct.hostent* %110, i64 0, i32 0
%121 = load i32, i32* %120
switch i32 %121, label %210 [
i32 133, label %122
i32 132, label %130
]
122: ; preds = %119
%123 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 0
%124 = load i64, i64* %123
%125 = load i64, i64* @PF_UNSPEC
%126 = icmp eq i64 %124, %125
%127 = load i64, i64* @PF_INET
%128 = icmp eq i64 %124, %127
%129 = select i1 %126, i1 true, i1 %128
br i1 %129, label %138, label %210
130: ; preds = %119
%131 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 0
%132 = load i64, i64* %131
%133 = load i64, i64* @PF_UNSPEC
%134 = icmp eq i64 %132, %133
%135 = load i64, i64* @PF_INET6
%136 = icmp eq i64 %132, %135
%137 = select i1 %134, i1 true, i1 %136
br i1 %137, label %138, label %210
138: ; preds = %130, %122
%139 = getelementptr inbounds %struct.hostent, %struct.hostent* %110, i64 0, i32 1
%140 = load i8**, i8*** %139
%141 = load i8*, i8** %140
%142 = icmp eq i8* %141, null
br i1 %142, label %210, label %143
143: ; preds = %138
%144 = bitcast %struct.sockaddr* %9 to i8*
%145 = getelementptr inbounds %struct.hostent, %struct.hostent* %110, i64 0, i32 2
%146 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %9, i64 0, i32 1
%147 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %9, i64 0, i32 2, i32 0
%148 = bitcast %struct.sockaddr* %9 to %struct.TYPE_3__*
%149 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %9, i64 0, i32 3
%150 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %9, i64 0, i32 2
%151 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 0
%152 = bitcast %struct.sockaddr* %9 to %struct.sockaddr_in*
br label %153
153: ; preds = %143, %180
%154 = phi i8** [ %140, %143 ], [ %183, %180 ]
%155 = phi %struct.addrinfo* [ null, %143 ], [ %182, %180 ]
%156 = phi %struct.addrinfo* [ null, %143 ], [ %181, %180 ]
%157 = load i32, i32* %145
%158 = icmp slt i32 %157, 1
br i1 %158, label %180, label %159
159: ; preds = %153
%160 = load i32, i32* %120
store i32 %160, i32* %146
switch i32 %160, label %180 [
i32 133, label %162
i32 132, label %161
]
161: ; preds = %159
br label %162
162: ; preds = %159, %161
%163 = phi i8** [ %147, %161 ], [ %149, %159 ]
%164 = phi %struct.TYPE_3__* [ %148, %161 ], [ %150, %159 ]
%165 = phi i64 [ 16, %161 ], [ 24, %159 ]
%166 = call i8* @htons(i32 %48)
store i8* %166, i8** %163
%167 = load i8*, i8** %154
%168 = load i32, i32* %145
%169 = call i32 @memcpy(%struct.TYPE_3__* %164, i8* %167, i32 %168)
%170 = load i32, i32* %120
%171 = sext i32 %170 to i64
store i64 %171, i64* %151
%172 = call %struct.addrinfo* @dup_addrinfo(%struct.addrinfo* %6, %struct.sockaddr_in* %152, i64 %165)
%173 = icmp eq %struct.addrinfo* %172, null
br i1 %173, label %178, label %174
174: ; preds = %162
%175 = icmp eq %struct.addrinfo* %156, null
br i1 %175, label %180, label %176
176: ; preds = %174
%177 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %155, i64 0, i32 4
store %struct.addrinfo* %172, %struct.addrinfo** %177
br label %180
178: ; preds = %162
%179 = call i32 @freeaddrinfo(%struct.addrinfo* %156)
br label %210
180: ; preds = %153, %159, %174, %176
%181 = phi %struct.addrinfo* [ %172, %174 ], [ %156, %176 ], [ %156, %159 ], [ %156, %153 ]
%182 = phi %struct.addrinfo* [ %172, %174 ], [ %172, %176 ], [ %155, %159 ], [ %155, %153 ]
%183 = getelementptr inbounds i8*, i8** %154, i64 1
%184 = load i8*, i8** %183
%185 = icmp eq i8* %184, null
br i1 %185, label %186, label %153
186: ; preds = %180
%187 = icmp eq %struct.addrinfo* %181, null
br i1 %187, label %210, label %188
188: ; preds = %186
%189 = load i32, i32* %78
%190 = and i32 %189, 2
%191 = icmp eq i32 %190, 0
br i1 %191, label %205, label %192
192: ; preds = %188
%193 = getelementptr inbounds %struct.hostent, %struct.hostent* %110, i64 0, i32 3
%194 = load i32, i32* %193
%195 = call i64 @strlen(i32 %194)
%196 = add nsw i64 %195, 1
%197 = call i32* @malloc(i64 %196)
%198 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %181, i64 0, i32 3
store i32* %197, i32** %198
%199 = icmp eq i32* %197, null
br i1 %199, label %200, label %202
200: ; preds = %192
%201 = call i32 @freeaddrinfo(%struct.addrinfo* %181)
br label %210
202: ; preds = %192
%203 = load i32, i32* %193
%204 = call i32 @strcpy(i32* %197, i32 %203)
br label %205
205: ; preds = %202, %188
store %struct.addrinfo* %181, %struct.addrinfo** %3
br label %210
206: ; preds = %115
%207 = sext i32 %117 to i64
%208 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.getaddrinfo, i64 0, i64 %207
%209 = load i32, i32* %208
br label %210
210: ; preds = %115, %206, %138, %178, %186, %119, %130, %122, %112, %40, %29, %4, %205, %200, %107, %75
%211 = phi i32 [ %76, %75 ], [ %108, %107 ], [ 6, %178 ], [ 6, %200 ], [ 0, %205 ], [ 8, %4 ], [ 9, %29 ], [ 8, %40 ], [ 11, %112 ], [ 5, %122 ], [ 5, %130 ], [ 5, %119 ], [ 7, %186 ], [ 7, %138 ], [ %209, %206 ], [ 4, %115 ]
ret i32 %211
}