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

/* Forward declarations */

/* Type definitions */
struct sockaddr_storage {
  int dummy;
};
struct addrinfo {
  int ai_flags;
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
};
typedef int /*<<< orphan*/ portstr;
typedef int /*<<< orphan*/ iporhost;
typedef int intmax_t;
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int AI_ADDRCONFIG;
int AI_NUMERICSERV;
int EINVAL;
int ENAMETOOLONG;
int ENOENT;
int /*<<< orphan*/ IPPROTO_TCP;
int MAXHOSTNAMELEN;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ PF_INET6;
int /*<<< orphan*/ PF_UNSPEC;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(struct addrinfo *, int);
int errno;
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memcpy(struct sockaddr_storage *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int numfromstr(char const *, int, int, int *);
int /*<<< orphan*/ pjdlog_debug(int, char *, char *, char *,
                                int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
char *strchr(char const *, char);
size_t strlcpy(char *, char const *, size_t);
scalar_t__ strncasecmp(char const *, char *, int);
char *strrchr(char const *, char);
int tcp_addr(const char *addr, int defport, struct sockaddr_storage *sap) {
  char iporhost[MAXHOSTNAMELEN], portstr[6];
  struct addrinfo hints;
  struct addrinfo *res;
  const char *pp;
  intmax_t port;
  size_t size;
  int error;
  if (addr == NULL)
    return (-1);
  bzero(&hints, sizeof(hints));
  hints.ai_flags = AI_ADDRCONFIG | AI_NUMERICSERV;
  hints.ai_family = PF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_protocol = IPPROTO_TCP;
  if (strncasecmp(addr, "tcp4://", 7) == 0) {
    addr += 7;
    hints.ai_family = PF_INET;
  } else if (strncasecmp(addr, "tcp6://", 7) == 0) {
    addr += 7;
    hints.ai_family = PF_INET6;
  } else if (strncasecmp(addr, "tcp://", 6) == 0) {
    addr += 6;
  } else {
  }
  pp = NULL;
  if (strchr(addr, ':') != strrchr(addr, ':')) {
    if (addr[0] == '[')
      pp = strrchr(addr, ':');
  } else {
    pp = strrchr(addr, ':');
  }
  if (pp == NULL) {
    port = defport;
  } else {
    if (numfromstr(pp + 1, 1, 65535, &port) == -1)
      return (errno);
  }
  (void)snprintf(portstr, sizeof(portstr), "%jd", (intmax_t)port);
  if (pp == NULL) {
    size = sizeof(iporhost);
    if (strlcpy(iporhost, addr, size) >= size)
      return (ENAMETOOLONG);
  } else if (addr[0] == '[' && pp[-1] == ']') {
    size = (size_t)(pp - addr - 2 + 1);
    if (size > sizeof(iporhost))
      return (ENAMETOOLONG);
    (void)strlcpy(iporhost, addr + 1, size);
  } else {
    size = (size_t)(pp - addr + 1);
    if (size > sizeof(iporhost))
      return (ENAMETOOLONG);
    (void)strlcpy(iporhost, addr, size);
  }
  error = getaddrinfo(iporhost, portstr, &hints, &res);
  if (error != 0) {
    pjdlog_debug(1, "getaddrinfo(%s, %s) failed: %s.", iporhost, portstr,
                 gai_strerror(error));
    return (EINVAL);
  }
  if (res == NULL)
    return (ENOENT);
  memcpy(sap, res->ai_addr, res->ai_addrlen);
  freeaddrinfo(res);
  return (0);
}


x86 assembly (clang, -O0):
<tcp_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x88(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1227 <tcp_addr+0x67>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x78(%rbp)
jmp    15e3 <tcp_addr+0x423>
lea    -0x50(%rbp),%rdi
mov    $0x18,%esi
call   10c0 <bzero@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%eax
mov    0x2db3(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x50(%rbp)
mov    0x2d8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xd87(%rip),%rsi
mov    $0x7,%edx
call   10a0 <strncasecmp@plt>
cmp    $0x0,%rax
jne    12aa <tcp_addr+0xea>
mov    -0x10(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x10(%rbp)
mov    0x2d08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    1325 <tcp_addr+0x165>
mov    -0x10(%rbp),%rdi
lea    0xd53(%rip),%rsi
mov    $0x7,%edx
call   10a0 <strncasecmp@plt>
cmp    $0x0,%rax
jne    12e6 <tcp_addr+0x126>
mov    -0x10(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x10(%rbp)
mov    0x2cfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    1320 <tcp_addr+0x160>
mov    -0x10(%rbp),%rdi
lea    0xd1f(%rip),%rsi
mov    $0x6,%edx
call   10a0 <strncasecmp@plt>
cmp    $0x0,%rax
jne    1316 <tcp_addr+0x156>
mov    -0x10(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x10(%rbp)
jmp    131b <tcp_addr+0x15b>
jmp    131b <tcp_addr+0x15b>
jmp    1320 <tcp_addr+0x160>
jmp    1325 <tcp_addr+0x165>
movq   $0x0,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x90(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strrchr@plt>
mov    %rax,%rcx
mov    -0x90(%rbp),%rax
cmp    %rcx,%rax
je     138a <tcp_addr+0x1ca>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
jne    1385 <tcp_addr+0x1c5>
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x60(%rbp)
jmp    139c <tcp_addr+0x1dc>
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    13b2 <tcp_addr+0x1f2>
mov    -0x14(%rbp),%eax
mov    %eax,-0x64(%rbp)
jmp    13f3 <tcp_addr+0x233>
mov    -0x60(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
mov    $0xffff,%edx
lea    -0x64(%rbp),%rcx
call   1070 <numfromstr@plt>
cmp    $0xffffffff,%eax
jne    13ee <tcp_addr+0x22e>
mov    0x2bd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x78(%rbp)
jmp    15e3 <tcp_addr+0x423>
jmp    13f3 <tcp_addr+0x233>
lea    -0x36(%rbp),%rdi
mov    -0x64(%rbp),%ecx
mov    $0x6,%esi
lea    0xc11(%rip),%rdx
call   1040 <snprintf@plt>
cmpq   $0x0,-0x60(%rbp)
jne    1459 <tcp_addr+0x299>
mov    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x70(%rbp),%rdx
call   10b0 <strlcpy@plt>
cmp    -0x70(%rbp),%rax
jb     1454 <tcp_addr+0x294>
mov    0x2b55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x78(%rbp)
jmp    15e3 <tcp_addr+0x423>
jmp    1526 <tcp_addr+0x366>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
jne    14d4 <tcp_addr+0x314>
mov    -0x60(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x5d,%eax
jne    14d4 <tcp_addr+0x314>
mov    -0x88(%rbp),%rax
mov    -0x60(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
sub    $0x2,%rcx
add    $0x1,%rcx
mov    %rcx,-0x70(%rbp)
cmp    %rax,-0x70(%rbp)
jbe    14ba <tcp_addr+0x2fa>
mov    0x2aef(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x78(%rbp)
jmp    15e3 <tcp_addr+0x423>
mov    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    -0x70(%rbp),%rdx
call   10b0 <strlcpy@plt>
jmp    1521 <tcp_addr+0x361>
mov    -0x88(%rbp),%rax
mov    -0x60(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
add    $0x1,%rcx
mov    %rcx,-0x70(%rbp)
cmp    %rax,-0x70(%rbp)
jbe    1510 <tcp_addr+0x350>
mov    0x2a99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x78(%rbp)
jmp    15e3 <tcp_addr+0x423>
mov    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x70(%rbp),%rdx
call   10b0 <strlcpy@plt>
jmp    1526 <tcp_addr+0x366>
mov    -0x80(%rbp),%rdi
lea    -0x36(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x58(%rbp),%rcx
call   10d0 <getaddrinfo@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
je     1592 <tcp_addr+0x3d2>
lea    -0x36(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x74(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x80(%rbp),%rdx
mov    -0x98(%rbp),%rcx
mov    %eax,%r8d
mov    $0x1,%edi
lea    0xaa6(%rip),%rsi
call   1080 <pjdlog_debug@plt>
mov    0x2a1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x78(%rbp)
jmp    15e3 <tcp_addr+0x423>
cmpq   $0x0,-0x58(%rbp)
jne    15b5 <tcp_addr+0x3f5>
mov    0x29e4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x78(%rbp)
jmp    15e3 <tcp_addr+0x423>
mov    -0x20(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%esi
mov    -0x58(%rbp),%rax
mov    0x4(%rax),%edx
call   1090 <memcpy@plt>
mov    -0x58(%rbp),%rdi
call   10e0 <freeaddrinfo@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x78(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcp_addr>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    0x2df8(%rip),%rax
mov    (%rax),%r12d
mov    %rsp,%r15
lea    0xf(%r12),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
test   %rdi,%rdi
je     12a1 <tcp_addr+0xe1>
mov    %rdx,%r14
mov    %esi,%r13d
mov    %rdi,%rbx
lea    -0x58(%rbp),%rdi
mov    $0x18,%esi
call   10c0 <bzero@plt>
mov    0x2d6c(%rip),%rax
mov    0x2ddd(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,-0x58(%rbp)
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
lea    0xdb3(%rip),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
call   10a0 <strncasecmp@plt>
test   %rax,%rax
mov    %r14,-0x60(%rbp)
mov    %r13d,-0x38(%rbp)
je     12ab <tcp_addr+0xeb>
lea    0xd9a(%rip),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
call   10a0 <strncasecmp@plt>
test   %rax,%rax
je     12b8 <tcp_addr+0xf8>
lea    0xd89(%rip),%rsi
mov    %rbx,%rdi
mov    $0x6,%edx
call   10a0 <strncasecmp@plt>
lea    0x6(%rbx),%rcx
test   %rax,%rax
cmove  %rcx,%rbx
jmp    12c8 <tcp_addr+0x108>
mov    $0xffffffff,%eax
jmp    13f3 <tcp_addr+0x233>
add    $0x7,%rbx
mov    0x2cf2(%rip),%rax
jmp    12c3 <tcp_addr+0x103>
add    $0x7,%rbx
mov    0x2d15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,%r13
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1060 <strrchr@plt>
mov    %rax,%r14
cmp    %rax,%r13
je     134f <tcp_addr+0x18f>
cmpb   $0x5b,(%rbx)
jne    1354 <tcp_addr+0x194>
test   %r14,%r14
je     1354 <tcp_addr+0x194>
lea    0x1(%r14),%rdi
lea    -0x2c(%rbp),%rcx
mov    $0x1,%esi
mov    $0xffff,%edx
call   1070 <numfromstr@plt>
cmp    $0xffffffff,%eax
je     1399 <tcp_addr+0x1d9>
mov    -0x2c(%rbp),%ecx
lea    0xcf6(%rip),%rdx
lea    -0x32(%rbp),%rdi
mov    $0x6,%esi
call   1040 <snprintf@plt>
cmpb   $0x5b,(%rbx)
jne    1384 <tcp_addr+0x1c4>
cmpb   $0x5d,-0x1(%r14)
jne    1384 <tcp_addr+0x1c4>
mov    %rbx,%rax
not    %rax
add    %rax,%r14
cmp    %r12,%r14
ja     1390 <tcp_addr+0x1d0>
add    $0x1,%rbx
jmp    13a2 <tcp_addr+0x1e2>
test   %r13,%r13
jne    12f7 <tcp_addr+0x137>
mov    -0x38(%rbp),%ecx
mov    %ecx,-0x2c(%rbp)
lea    0xcb6(%rip),%rdx
lea    -0x32(%rbp),%rdi
mov    $0x6,%esi
call   1040 <snprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   10b0 <strlcpy@plt>
cmp    %r12,%rax
jb     13b0 <tcp_addr+0x1f0>
jmp    1390 <tcp_addr+0x1d0>
sub    %rbx,%r14
add    $0x1,%r14
cmp    %r12,%r14
jbe    13a2 <tcp_addr+0x1e2>
mov    0x2c01(%rip),%rax
jmp    13f1 <tcp_addr+0x231>
mov    0x2c10(%rip),%rax
jmp    13f1 <tcp_addr+0x231>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10b0 <strlcpy@plt>
lea    -0x32(%rbp),%rsi
lea    -0x58(%rbp),%rdx
lea    -0x40(%rbp),%rcx
mov    %r15,%rdi
call   10d0 <getaddrinfo@plt>
test   %eax,%eax
je     1402 <tcp_addr+0x242>
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xc45(%rip),%rsi
lea    -0x32(%rbp),%rcx
mov    $0x1,%edi
mov    %r15,%rdx
mov    %eax,%r8d
call   1080 <pjdlog_debug@plt>
mov    0x2baf(%rip),%rax
mov    (%rax),%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    -0x40(%rbp),%rax
test   %rax,%rax
je     1427 <tcp_addr+0x267>
mov    0x4(%rax),%edx
mov    0x8(%rax),%esi
mov    -0x60(%rbp),%rdi
call   1090 <memcpy@plt>
mov    -0x40(%rbp),%rdi
call   10e0 <freeaddrinfo@plt>
xor    %eax,%eax
jmp    13f3 <tcp_addr+0x233>
mov    0x2b5a(%rip),%rax
jmp    13f1 <tcp_addr+0x231>

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32 }
@MAXHOSTNAMELEN = global i32 0
@AI_ADDRCONFIG = global i32 0
@AI_NUMERICSERV = global i32 0
@PF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [8 x i8] c"tcp4://\00"
@PF_INET = global i32 0
@.str.1 = [8 x i8] c"tcp6://\00"
@PF_INET6 = global i32 0
@.str.2 = [7 x i8] c"tcp://\00"
@errno = global i32 0
@.str.3 = [4 x i8] c"%jd\00"
@ENAMETOOLONG = global i32 0
@.str.4 = [32 x i8] c"getaddrinfo(%s, %s) failed: %s.\00"
@EINVAL = global i32 0
@ENOENT = global i32 0
define i32 @tcp_addr(i8* %0, i32 %1, %struct.sockaddr_storage* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.sockaddr_storage*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca [6 x i8]
%11 = alloca %struct.addrinfo
%12 = alloca %struct.addrinfo*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i64
%16 = alloca i32
%17 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store %struct.sockaddr_storage* %2, %struct.sockaddr_storage** %7
%18 = load i32, i32* @MAXHOSTNAMELEN
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %8
%21 = alloca i8, i64 %19
store i64 %19, i64* %9
%22 = load i8*, i8** %5
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %3
store i32 -1, i32* %4
store i32 1, i32* %17
br label %183
25: ; preds = %3
%26 = call i32 @bzero(%struct.addrinfo* %11, i32 24)
%27 = load i32, i32* @AI_ADDRCONFIG
%28 = load i32, i32* @AI_NUMERICSERV
%29 = or i32 %27, %28
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 0
store i32 %29, i32* %30
%31 = load i32, i32* @PF_UNSPEC
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 3
store i32 %31, i32* %32
%33 = load i32, i32* @SOCK_STREAM
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 5
store i32 %33, i32* %34
%35 = load i32, i32* @IPPROTO_TCP
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 4
store i32 %35, i32* %36
%37 = load i8*, i8** %5
%38 = call i64 @strncasecmp(i8* %37, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %25
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i64 7
store i8* %42, i8** %5
%43 = load i32, i32* @PF_INET
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 3
store i32 %43, i32* %44
br label %64
45: ; preds = %25
%46 = load i8*, i8** %5
%47 = call i64 @strncasecmp(i8* %46, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %45
%50 = load i8*, i8** %5
%51 = getelementptr inbounds i8, i8* %50, i64 7
store i8* %51, i8** %5
%52 = load i32, i32* @PF_INET6
%53 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 3
store i32 %52, i32* %53
br label %63
54: ; preds = %45
%55 = load i8*, i8** %5
%56 = call i64 @strncasecmp(i8* %55, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 6)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %54
%59 = load i8*, i8** %5
%60 = getelementptr inbounds i8, i8* %59, i64 6
store i8* %60, i8** %5
br label %62
61: ; preds = %54
br label %62
62: ; preds = %61, %58
br label %63
63: ; preds = %62, %49
br label %64
64: ; preds = %63, %40
store i8* null, i8** %13
%65 = load i8*, i8** %5
%66 = call i8* @strchr(i8* %65, i8 signext 58)
%67 = load i8*, i8** %5
%68 = call i8* @strrchr(i8* %67, i8 signext 58)
%69 = icmp ne i8* %66, %68
br i1 %69, label %70, label %80
70: ; preds = %64
%71 = load i8*, i8** %5
%72 = getelementptr inbounds i8, i8* %71, i64 0
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp eq i32 %74, 91
br i1 %75, label %76, label %79
76: ; preds = %70
%77 = load i8*, i8** %5
%78 = call i8* @strrchr(i8* %77, i8 signext 58)
store i8* %78, i8** %13
br label %79
79: ; preds = %76, %70
br label %83
80: ; preds = %64
%81 = load i8*, i8** %5
%82 = call i8* @strrchr(i8* %81, i8 signext 58)
store i8* %82, i8** %13
br label %83
83: ; preds = %80, %79
%84 = load i8*, i8** %13
%85 = icmp eq i8* %84, null
br i1 %85, label %86, label %88
86: ; preds = %83
%87 = load i32, i32* %6
store i32 %87, i32* %14
br label %96
88: ; preds = %83
%89 = load i8*, i8** %13
%90 = getelementptr inbounds i8, i8* %89, i64 1
%91 = call i32 @numfromstr(i8* %90, i32 1, i32 65535, i32* %14)
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %95
93: ; preds = %88
%94 = load i32, i32* @errno
store i32 %94, i32* %4
store i32 1, i32* %17
br label %183
95: ; preds = %88
br label %96
96: ; preds = %95, %86
%97 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
%98 = load i32, i32* %14
%99 = call i32 @snprintf(i8* %97, i32 6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %98)
%100 = load i8*, i8** %13
%101 = icmp eq i8* %100, null
br i1 %101, label %102, label %111
102: ; preds = %96
store i64 %19, i64* %15
%103 = load i8*, i8** %5
%104 = load i64, i64* %15
%105 = call i64 @strlcpy(i8* %21, i8* %103, i64 %104)
%106 = load i64, i64* %15
%107 = icmp uge i64 %105, %106
br i1 %107, label %108, label %110
108: ; preds = %102
%109 = load i32, i32* @ENAMETOOLONG
store i32 %109, i32* %4
store i32 1, i32* %17
br label %183
110: ; preds = %102
br label %156
111: ; preds = %96
%112 = load i8*, i8** %5
%113 = getelementptr inbounds i8, i8* %112, i64 0
%114 = load i8, i8* %113
%115 = sext i8 %114 to i32
%116 = icmp eq i32 %115, 91
br i1 %116, label %117, label %140
117: ; preds = %111
%118 = load i8*, i8** %13
%119 = getelementptr inbounds i8, i8* %118, i64 -1
%120 = load i8, i8* %119
%121 = sext i8 %120 to i32
%122 = icmp eq i32 %121, 93
br i1 %122, label %123, label %140
123: ; preds = %117
%124 = load i8*, i8** %13
%125 = load i8*, i8** %5
%126 = ptrtoint i8* %124 to i64
%127 = ptrtoint i8* %125 to i64
%128 = sub i64 %126, %127
%129 = sub nsw i64 %128, 2
%130 = add nsw i64 %129, 1
store i64 %130, i64* %15
%131 = load i64, i64* %15
%132 = icmp ugt i64 %131, %19
br i1 %132, label %133, label %135
133: ; preds = %123
%134 = load i32, i32* @ENAMETOOLONG
store i32 %134, i32* %4
store i32 1, i32* %17
br label %183
135: ; preds = %123
%136 = load i8*, i8** %5
%137 = getelementptr inbounds i8, i8* %136, i64 1
%138 = load i64, i64* %15
%139 = call i64 @strlcpy(i8* %21, i8* %137, i64 %138)
br label %155
140: ; preds = %117, %111
%141 = load i8*, i8** %13
%142 = load i8*, i8** %5
%143 = ptrtoint i8* %141 to i64
%144 = ptrtoint i8* %142 to i64
%145 = sub i64 %143, %144
%146 = add nsw i64 %145, 1
store i64 %146, i64* %15
%147 = load i64, i64* %15
%148 = icmp ugt i64 %147, %19
br i1 %148, label %149, label %151
149: ; preds = %140
%150 = load i32, i32* @ENAMETOOLONG
store i32 %150, i32* %4
store i32 1, i32* %17
br label %183
151: ; preds = %140
%152 = load i8*, i8** %5
%153 = load i64, i64* %15
%154 = call i64 @strlcpy(i8* %21, i8* %152, i64 %153)
br label %155
155: ; preds = %151, %135
br label %156
156: ; preds = %155, %110
%157 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
%158 = call i32 @getaddrinfo(i8* %21, i8* %157, %struct.addrinfo* %11, %struct.addrinfo** %12)
store i32 %158, i32* %16
%159 = load i32, i32* %16
%160 = icmp ne i32 %159, 0
br i1 %160, label %161, label %167
161: ; preds = %156
%162 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
%163 = load i32, i32* %16
%164 = call i32 @gai_strerror(i32 %163)
%165 = call i32 @pjdlog_debug(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %21, i8* %162, i32 %164)
%166 = load i32, i32* @EINVAL
store i32 %166, i32* %4
store i32 1, i32* %17
br label %183
167: ; preds = %156
%168 = load %struct.addrinfo*, %struct.addrinfo** %12
%169 = icmp eq %struct.addrinfo* %168, null
br i1 %169, label %170, label %172
170: ; preds = %167
%171 = load i32, i32* @ENOENT
store i32 %171, i32* %4
store i32 1, i32* %17
br label %183
172: ; preds = %167
%173 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %7
%174 = load %struct.addrinfo*, %struct.addrinfo** %12
%175 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %174, i32 0, i32 2
%176 = load i32, i32* %175
%177 = load %struct.addrinfo*, %struct.addrinfo** %12
%178 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %177, i32 0, i32 1
%179 = load i32, i32* %178
%180 = call i32 @memcpy(%struct.sockaddr_storage* %173, i32 %176, i32 %179)
%181 = load %struct.addrinfo*, %struct.addrinfo** %12
%182 = call i32 @freeaddrinfo(%struct.addrinfo* %181)
store i32 0, i32* %4
store i32 1, i32* %17
br label %183
183: ; preds = %172, %170, %161, %149, %133, %108, %93, %24
%184 = load i8*, i8** %8
%185 = load i32, i32* %4
ret i32 %185
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32 }
@MAXHOSTNAMELEN = global i32 0
@AI_ADDRCONFIG = global i32 0
@AI_NUMERICSERV = global i32 0
@PF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [8 x i8] c"tcp4://\00"
@PF_INET = global i32 0
@.str.1 = [8 x i8] c"tcp6://\00"
@PF_INET6 = global i32 0
@.str.2 = [7 x i8] c"tcp://\00"
@errno = global i32 0
@.str.3 = [4 x i8] c"%jd\00"
@ENAMETOOLONG = global i32 0
@.str.4 = [32 x i8] c"getaddrinfo(%s, %s) failed: %s.\00"
@EINVAL = global i32 0
@ENOENT = global i32 0
define i32 @tcp_addr(i8* %0, i32 %1, %struct.sockaddr_storage* %2) {
%4 = alloca [6 x i8]
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = alloca i32
%8 = load i32, i32* @MAXHOSTNAMELEN
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%12 = bitcast %struct.addrinfo* %5 to i8*
%13 = bitcast %struct.addrinfo** %6 to i8*
%14 = bitcast i32* %7 to i8*
%15 = icmp eq i8* %0, null
br i1 %15, label %118, label %16
16: ; preds = %3
%17 = call i32 @bzero(%struct.addrinfo* %5, i32 24)
%18 = load i32, i32* @AI_ADDRCONFIG
%19 = load i32, i32* @AI_NUMERICSERV
%20 = or i32 %19, %18
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 0
store i32 %20, i32* %21
%22 = load i32, i32* @PF_UNSPEC
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 3
store i32 %22, i32* %23
%24 = load i32, i32* @SOCK_STREAM
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 5
store i32 %24, i32* %25
%26 = load i32, i32* @IPPROTO_TCP
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 4
store i32 %26, i32* %27
%28 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %16
%31 = getelementptr inbounds i8, i8* %0, i64 7
%32 = load i32, i32* @PF_INET
store i32 %32, i32* %23
br label %44
33: ; preds = %16
%34 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = getelementptr inbounds i8, i8* %0, i64 7
%38 = load i32, i32* @PF_INET6
store i32 %38, i32* %23
br label %44
39: ; preds = %33
%40 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 6)
%41 = icmp eq i64 %40, 0
%42 = select i1 %41, i64 6, i64 0
%43 = getelementptr i8, i8* %0, i64 %42
br label %44
44: ; preds = %39, %36, %30
%45 = phi i8* [ %31, %30 ], [ %37, %36 ], [ %43, %39 ]
%46 = tail call i8* @strchr(i8* %45, i8 signext 58)
%47 = tail call i8* @strrchr(i8* %45, i8 signext 58)
%48 = icmp eq i8* %46, %47
br i1 %48, label %54, label %49
49: ; preds = %44
%50 = load i8, i8* %45
%51 = icmp ne i8 %50, 91
%52 = icmp eq i8* %47, null
%53 = select i1 %51, i1 true, i1 %52
br i1 %53, label %62, label %56
54: ; preds = %44
%55 = icmp eq i8* %46, null
br i1 %55, label %62, label %56
56: ; preds = %49, %54
%57 = getelementptr inbounds i8, i8* %47, i64 1
%58 = call i32 @numfromstr(i8* %57, i32 1, i32 65535, i32* %7)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %68
60: ; preds = %56
%61 = load i32, i32* @errno
br label %118
62: ; preds = %49, %54
store i32 %1, i32* %7
%63 = call i32 @snprintf(i8* %11, i32 6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %1)
%64 = call i64 @strlcpy(i8* %10, i8* %45, i64 %9)
%65 = icmp ult i64 %64, %9
br i1 %65, label %98, label %66
66: ; preds = %62
%67 = load i32, i32* @ENAMETOOLONG
br label %118
68: ; preds = %56
%69 = load i32, i32* %7
%70 = call i32 @snprintf(i8* %11, i32 6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %69)
%71 = load i8, i8* %45
%72 = icmp eq i8 %71, 91
br i1 %72, label %73, label %88
73: ; preds = %68
%74 = getelementptr inbounds i8, i8* %47, i64 -1
%75 = load i8, i8* %74
%76 = icmp eq i8 %75, 93
br i1 %76, label %77, label %88
77: ; preds = %73
%78 = ptrtoint i8* %47 to i64
%79 = ptrtoint i8* %45 to i64
%80 = xor i64 %79, -1
%81 = add i64 %78, %80
%82 = icmp ugt i64 %81, %9
br i1 %82, label %83, label %85
83: ; preds = %77
%84 = load i32, i32* @ENAMETOOLONG
br label %118
85: ; preds = %77
%86 = getelementptr inbounds i8, i8* %45, i64 1
%87 = call i64 @strlcpy(i8* %10, i8* %86, i64 %81)
br label %98
88: ; preds = %73, %68
%89 = ptrtoint i8* %47 to i64
%90 = ptrtoint i8* %45 to i64
%91 = sub i64 %89, %90
%92 = add nsw i64 %91, 1
%93 = icmp ugt i64 %92, %9
br i1 %93, label %94, label %96
94: ; preds = %88
%95 = load i32, i32* @ENAMETOOLONG
br label %118
96: ; preds = %88
%97 = call i64 @strlcpy(i8* %10, i8* %45, i64 %92)
br label %98
98: ; preds = %85, %96, %62
%99 = call i32 @getaddrinfo(i8* %10, i8* %11, %struct.addrinfo* %5, %struct.addrinfo** %6)
%100 = icmp eq i32 %99, 0
br i1 %100, label %105, label %101
101: ; preds = %98
%102 = call i32 @gai_strerror(i32 %99)
%103 = call i32 @pjdlog_debug(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %10, i8* %11, i32 %102)
%104 = load i32, i32* @EINVAL
br label %118
105: ; preds = %98
%106 = load %struct.addrinfo*, %struct.addrinfo** %6
%107 = icmp eq %struct.addrinfo* %106, null
br i1 %107, label %108, label %110
108: ; preds = %105
%109 = load i32, i32* @ENOENT
br label %118
110: ; preds = %105
%111 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %106, i64 0, i32 2
%112 = load i32, i32* %111
%113 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %106, i64 0, i32 1
%114 = load i32, i32* %113
%115 = call i32 @memcpy(%struct.sockaddr_storage* %2, i32 %112, i32 %114)
%116 = load %struct.addrinfo*, %struct.addrinfo** %6
%117 = call i32 @freeaddrinfo(%struct.addrinfo* %116)
br label %118
118: ; preds = %3, %110, %108, %101, %94, %83, %66, %60
%119 = phi i32 [ %67, %66 ], [ %104, %101 ], [ %109, %108 ], [ 0, %110 ], [ %84, %83 ], [ %95, %94 ], [ %61, %60 ], [ -1, %3 ]
ret i32 %119
}