#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 addrinfo {
  scalar_t__ ai_family;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
};
typedef int /*<<< orphan*/ port;
typedef int /*<<< orphan*/ host;
typedef int /*<<< orphan*/ hint;
typedef int /*<<< orphan*/ error_buf;

/* Variables and functions */
scalar_t__ AF_INET6;
int /*<<< orphan*/ IPPROTO_TCP;
int NI_NUMERICHOST;
int NI_NUMERICSERV;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ getnameinfo(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                               int, char *, int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *, char *);
int safe_cat(char **, int *, int, char *);
char *strchr(char *, char);
char *strdup(char const *);
char *strerror_r(int /*<<< orphan*/, char *, int);
int strlen(char *);
char *strrchr(char *, char);
char *strstr(char *, char *);
char *strtok_r(char *, char *, char **);
char *resolve_addrs(const char *orig_str) {
  char *new_str;
  char *tok, *port_str, *saveptr = NULL;
  int len, pos;
  char *buf = strdup(orig_str);
  len = 128;
  new_str = (char *)malloc(len);
  pos = 0;
  tok = strtok_r(buf, ",", &saveptr);
  while (tok) {
    struct addrinfo hint;
    struct addrinfo *res, *ores;
    char *firstcolon, *lastcolon, *bracecolon;
    int r;
    int brackets = 0;
    firstcolon = strchr(tok, ':');
    lastcolon = strrchr(tok, ':');
    bracecolon = strstr(tok, "]:");
    port_str = 0;
    if (firstcolon && firstcolon == lastcolon) {
      *firstcolon = 0;
      port_str = firstcolon + 1;
    } else if (bracecolon) {
      port_str = bracecolon + 1;
      *port_str = 0;
      port_str++;
    }
    if (port_str && !*port_str)
      port_str = NULL;
    if (*tok == '[' && tok[strlen(tok) - 1] == ']') {
      tok[strlen(tok) - 1] = 0;
      tok++;
      brackets = 1;
    }
    memset(&hint, 0, sizeof(hint));
    hint.ai_socktype = SOCK_STREAM;
    hint.ai_protocol = IPPROTO_TCP;
    r = getaddrinfo(tok, port_str, &hint, &res);
    if (r < 0) {
      char error_buf[80];
      printf("server name not found: %s (%s)\n", tok,
             strerror_r(errno, error_buf, sizeof(error_buf)));
      free(new_str);
      free(buf);
      return 0;
    }
    ores = res;
    while (res) {
      char host[40], port[40];
      getnameinfo(res->ai_addr, res->ai_addrlen, host, sizeof(host), port,
                  sizeof(port), NI_NUMERICSERV | NI_NUMERICHOST);
      if (res->ai_family == AF_INET6)
        brackets = 1;
      if (brackets)
        pos = safe_cat(&new_str, &len, pos, "[");
      pos = safe_cat(&new_str, &len, pos, host);
      if (brackets)
        pos = safe_cat(&new_str, &len, pos, "]");
      if (port_str) {
        pos = safe_cat(&new_str, &len, pos, ":");
        pos = safe_cat(&new_str, &len, pos, port);
      }
      res = res->ai_next;
      if (res)
        pos = safe_cat(&new_str, &len, pos, ",");
    }
    freeaddrinfo(ores);
    tok = strtok_r(NULL, ",", &saveptr);
    if (tok)
      pos = safe_cat(&new_str, &len, pos, ",");
  }
  free(buf);
  return new_str;
}


x86 assembly (clang, -O0):
<resolve_addrs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   10f0 <strdup@plt>
mov    %rax,-0x40(%rbp)
movl   $0x80,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   10c0 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xdc7(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   10a0 <strtok_r@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     15e6 <resolve_addrs+0x3f6>
movl   $0x0,-0x90(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x78(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x3a,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x80(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xd78(%rip),%rsi
call   1100 <strstr@plt>
mov    %rax,-0x88(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     12cf <resolve_addrs+0xdf>
mov    -0x78(%rbp),%rax
cmp    -0x80(%rbp),%rax
jne    12cf <resolve_addrs+0xdf>
mov    -0x78(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x78(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1304 <resolve_addrs+0x114>
cmpq   $0x0,-0x88(%rbp)
je     12ff <resolve_addrs+0x10f>
mov    -0x88(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1304 <resolve_addrs+0x114>
cmpq   $0x0,-0x28(%rbp)
je     1324 <resolve_addrs+0x134>
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1324 <resolve_addrs+0x134>
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
jne    13a1 <resolve_addrs+0x1b1>
mov    -0x20(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x148(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5d,%eax
jne    13a1 <resolve_addrs+0x1b1>
mov    -0x20(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x150(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x90(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1080 <memset@plt>
mov    0x2c10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2c1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x60(%rbp),%rdx
lea    -0x68(%rbp),%rcx
call   10e0 <getaddrinfo@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
jge    144b <resolve_addrs+0x25b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x158(%rbp)
mov    0x2bb5(%rip),%rax
mov    (%rax),%edi
lea    -0xe0(%rbp),%rsi
mov    $0x50,%edx
call   10b0 <strerror_r@plt>
mov    -0x158(%rbp),%rsi
mov    %rax,%rdx
lea    0xbde(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    15f7 <resolve_addrs+0x407>
mov    -0x68(%rbp),%rax
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     159b <resolve_addrs+0x3ab>
mov    -0x68(%rbp),%rax
mov    0x14(%rax),%edi
mov    -0x68(%rbp),%rax
mov    0x10(%rax),%esi
lea    -0x110(%rbp),%rdx
lea    -0x140(%rbp),%r8
mov    0x2b67(%rip),%rax
mov    (%rax),%eax
mov    0x2b36(%rip),%rcx
or     (%rcx),%eax
mov    $0x28,%r9d
mov    %r9d,%ecx
mov    %eax,(%rsp)
call   1090 <getnameinfo@plt>
mov    -0x68(%rbp),%rax
mov    (%rax),%rax
mov    0x2b2d(%rip),%rcx
cmp    (%rcx),%rax
jne    14be <resolve_addrs+0x2ce>
movl   $0x1,-0x90(%rbp)
cmpl   $0x0,-0x90(%rbp)
je     14e5 <resolve_addrs+0x2f5>
mov    -0x38(%rbp),%edx
lea    -0x18(%rbp),%rdi
lea    -0x34(%rbp),%rsi
lea    0xb48(%rip),%rcx
call   10d0 <safe_cat@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edx
lea    -0x110(%rbp),%rcx
lea    -0x18(%rbp),%rdi
lea    -0x34(%rbp),%rsi
call   10d0 <safe_cat@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x90(%rbp)
je     1526 <resolve_addrs+0x336>
mov    -0x38(%rbp),%edx
lea    -0x18(%rbp),%rdi
lea    -0x34(%rbp),%rsi
lea    0xb09(%rip),%rcx
call   10d0 <safe_cat@plt>
mov    %eax,-0x38(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1565 <resolve_addrs+0x375>
mov    -0x38(%rbp),%edx
lea    -0x18(%rbp),%rdi
lea    -0x34(%rbp),%rsi
lea    0xac0(%rip),%rcx
call   10d0 <safe_cat@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edx
lea    -0x140(%rbp),%rcx
lea    -0x18(%rbp),%rdi
lea    -0x34(%rbp),%rsi
call   10d0 <safe_cat@plt>
mov    %eax,-0x38(%rbp)
mov    -0x68(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     1596 <resolve_addrs+0x3a6>
mov    -0x38(%rbp),%edx
lea    -0x18(%rbp),%rdi
lea    -0x34(%rbp),%rsi
lea    0xa72(%rip),%rcx
call   10d0 <safe_cat@plt>
mov    %eax,-0x38(%rbp)
jmp    1453 <resolve_addrs+0x263>
mov    -0x70(%rbp),%rdi
call   1110 <freeaddrinfo@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xa51(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   10a0 <strtok_r@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     15e1 <resolve_addrs+0x3f1>
mov    -0x38(%rbp),%edx
lea    -0x18(%rbp),%rdi
lea    -0x34(%rbp),%rsi
lea    0xa27(%rip),%rcx
call   10d0 <safe_cat@plt>
mov    %eax,-0x38(%rbp)
jmp    1246 <resolve_addrs+0x56>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolve_addrs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
movq   $0x0,0x38(%rsp)
call   10f0 <strdup@plt>
mov    %rax,%rbx
movl   $0x80,0x2c(%rsp)
mov    $0x80,%edi
call   10c0 <malloc@plt>
mov    %rax,0x20(%rsp)
lea    0xdd0(%rip),%rsi
lea    0x38(%rsp),%rdx
mov    %rbx,0x30(%rsp)
mov    %rbx,%rdi
call   10a0 <strtok_r@plt>
test   %rax,%rax
je     14d8 <resolve_addrs+0x2e8>
mov    %rax,%rbp
xor    %r13d,%r13d
lea    0x20(%rsp),%r14
lea    0x2c(%rsp),%r12
jmp    1269 <resolve_addrs+0x79>
nopl   (%rax)
test   %rbp,%rbp
je     14d8 <resolve_addrs+0x2e8>
mov    %rbp,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,%r15
mov    %rbp,%rdi
lea    0xd7f(%rip),%rsi
call   1100 <strstr@plt>
mov    %rax,%rbx
test   %r15,%r15
mov    %rbp,0x8(%rsp)
je     12a7 <resolve_addrs+0xb7>
mov    %rbp,%rdi
mov    $0x3a,%esi
call   1070 <strrchr@plt>
cmp    %rax,%r15
je     12d0 <resolve_addrs+0xe0>
test   %rbx,%rbx
je     12c0 <resolve_addrs+0xd0>
movb   $0x0,0x1(%rbx)
add    $0x2,%rbx
mov    %rbx,%r15
jmp    12d8 <resolve_addrs+0xe8>
nopl   0x0(%rax)
xor    %eax,%eax
jmp    12e5 <resolve_addrs+0xf5>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movb   $0x0,(%r15)
add    $0x1,%r15
cmpb   $0x0,(%r15)
mov    $0x0,%eax
cmovne %r15,%rax
mov    %rax,0x18(%rsp)
xor    %ebx,%ebx
mov    0x8(%rsp),%rbp
cmpb   $0x5b,0x0(%rbp)
jne    1325 <resolve_addrs+0x135>
mov    %rbp,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x5d,-0x1(%rax,%rbp,1)
jne    1325 <resolve_addrs+0x135>
mov    %rbp,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
add    $0x1,%rbp
mov    %rbp,0x8(%rsp)
mov    $0x1,%ebx
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1080 <memset@plt>
mov    0x2c88(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x5c(%rsp)
mov    0x2c93(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x58(%rsp)
mov    0x8(%rsp),%r15
mov    %r15,%rdi
mov    0x18(%rsp),%rsi
mov    %rbp,%rdx
lea    0x10(%rsp),%rcx
call   10e0 <getaddrinfo@plt>
test   %eax,%eax
js     14e9 <resolve_addrs+0x2f9>
mov    0x10(%rsp),%rax
test   %rax,%rax
mov    %rax,0x8(%rsp)
je     1493 <resolve_addrs+0x2a3>
mov    0x18(%rsp),%rbp
nopl   (%rax)
mov    0x10(%rax),%esi
mov    0x14(%rax),%edi
mov    0x2c23(%rip),%rax
mov    (%rax),%eax
mov    0x2c42(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
lea    0x90(%rsp),%r15
mov    %r15,%rdx
mov    $0x28,%ecx
lea    0x60(%rsp),%r8
mov    $0x28,%r9d
call   1090 <getnameinfo@plt>
mov    0x10(%rsp),%rax
mov    (%rax),%rax
mov    0x2bfe(%rip),%rcx
cmp    (%rcx),%rax
mov    $0x1,%eax
cmove  %eax,%ebx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
test   %ebx,%ebx
je     1420 <resolve_addrs+0x230>
lea    0xc2c(%rip),%rcx
call   10d0 <safe_cat@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %eax,%edx
mov    %r15,%rcx
call   10d0 <safe_cat@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %eax,%edx
lea    0xc0a(%rip),%rcx
jmp    1423 <resolve_addrs+0x233>
nop
mov    %r15,%rcx
call   10d0 <safe_cat@plt>
mov    %eax,%r13d
test   %rbp,%rbp
je     145a <resolve_addrs+0x26a>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
lea    0xbc3(%rip),%rcx
call   10d0 <safe_cat@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %eax,%edx
lea    0x60(%rsp),%rcx
call   10d0 <safe_cat@plt>
mov    %eax,%r13d
mov    0x10(%rsp),%rax
mov    0x8(%rax),%rax
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     1493 <resolve_addrs+0x2a3>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
lea    0xb83(%rip),%rcx
call   10d0 <safe_cat@plt>
mov    %eax,%r13d
mov    0x10(%rsp),%rax
test   %rax,%rax
jne    1390 <resolve_addrs+0x1a0>
mov    0x8(%rsp),%rdi
call   1110 <freeaddrinfo@plt>
xor    %edi,%edi
lea    0xb5a(%rip),%rbx
mov    %rbx,%rsi
lea    0x38(%rsp),%rdx
call   10a0 <strtok_r@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1260 <resolve_addrs+0x70>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
mov    %rbx,%rcx
call   10d0 <safe_cat@plt>
mov    %eax,%r13d
jmp    1260 <resolve_addrs+0x70>
mov    0x30(%rsp),%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rax
jmp    152c <resolve_addrs+0x33c>
mov    0x2ac8(%rip),%rax
mov    (%rax),%edi
lea    0x90(%rsp),%rsi
mov    $0x50,%edx
call   10b0 <strerror_r@plt>
lea    0xafa(%rip),%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1060 <printf@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    0x30(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.addrinfo = type { i64, %struct.addrinfo*, i32, i32, i32, i32 }
@.str = [2 x i8] c",\00"
@.str.1 = [3 x i8] c"]:\00"
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.2 = [32 x i8] c"server name not found: %s (%s)\0A\00"
@errno = global i32 0
@NI_NUMERICSERV = global i32 0
@NI_NUMERICHOST = global i32 0
@AF_INET6 = global i64 0
@.str.3 = [2 x i8] c"[\00"
@.str.4 = [2 x i8] c"]\00"
@.str.5 = [2 x i8] c":\00"
define i8* @resolve_addrs(i8* nocapture %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = alloca [80 x i8]
%8 = alloca [40 x i8]
%9 = alloca [40 x i8]
%10 = bitcast i8** %2 to i8*
%11 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%12 = bitcast i32* %4 to i8*
%13 = tail call i8* @strdup(i8* %0)
store i32 128, i32* %4
%14 = tail call i64 @malloc(i32 128)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %2
%16 = call i8* @strtok_r(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3)
%17 = bitcast %struct.addrinfo* %5 to i8*
%18 = bitcast %struct.addrinfo** %6 to i8*
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 5
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 4
%21 = getelementptr inbounds [40 x i8], [40 x i8]* %8, i64 0, i64 0
%22 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%23 = icmp eq i8* %16, null
br i1 %23, label %134, label %24
24: ; preds = %1, %131
%25 = phi i8* [ %127, %131 ], [ %16, %1 ]
%26 = phi i32 [ %132, %131 ], [ 0, %1 ]
%27 = call i8* @strchr(i8* %25, i8 signext 58)
%28 = call i8* @strstr(i8* %25, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i8* %27, null
br i1 %29, label %35, label %30
30: ; preds = %24
%31 = call i8* @strrchr(i8* %25, i8 signext 58)
%32 = icmp eq i8* %27, %31
br i1 %32, label %33, label %35
33: ; preds = %30
store i8 0, i8* %27
%34 = getelementptr inbounds i8, i8* %27, i64 1
br label %40
35: ; preds = %30, %24
%36 = icmp eq i8* %28, null
br i1 %36, label %45, label %37
37: ; preds = %35
%38 = getelementptr inbounds i8, i8* %28, i64 1
store i8 0, i8* %38
%39 = getelementptr inbounds i8, i8* %28, i64 2
br label %40
40: ; preds = %33, %37
%41 = phi i8* [ %39, %37 ], [ %34, %33 ]
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 0
%44 = select i1 %43, i8* null, i8* %41
br label %45
45: ; preds = %35, %40
%46 = phi i8* [ %44, %40 ], [ null, %35 ]
%47 = load i8, i8* %25
%48 = icmp eq i8 %47, 91
br i1 %48, label %49, label %62
49: ; preds = %45
%50 = call i32 @strlen(i8* %25)
%51 = add nsw i32 %50, -1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %25, i64 %52
%54 = load i8, i8* %53
%55 = icmp eq i8 %54, 93
br i1 %55, label %56, label %62
56: ; preds = %49
%57 = call i32 @strlen(i8* %25)
%58 = add nsw i32 %57, -1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %25, i64 %59
store i8 0, i8* %60
%61 = getelementptr inbounds i8, i8* %25, i64 1
br label %62
62: ; preds = %56, %49, %45
%63 = phi i8* [ %61, %56 ], [ %25, %49 ], [ %25, %45 ]
%64 = phi i32 [ 1, %56 ], [ 0, %49 ], [ 0, %45 ]
%65 = call i32 @memset(%struct.addrinfo* %5, i32 0, i32 32)
%66 = load i32, i32* @SOCK_STREAM
store i32 %66, i32* %19
%67 = load i32, i32* @IPPROTO_TCP
store i32 %67, i32* %20
%68 = call i32 @getaddrinfo(i8* %63, i8* %46, %struct.addrinfo* %5, %struct.addrinfo** %6)
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %78
70: ; preds = %62
%71 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%72 = load i32, i32* @errno
%73 = call i8* @strerror_r(i32 %72, i8* %71, i32 80)
%74 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %63, i8* %73)
%75 = load i8*, i8** %2
%76 = call i32 @free(i8* %75)
%77 = call i32 @free(i8* %13)
br label %137
78: ; preds = %62
%79 = load %struct.addrinfo*, %struct.addrinfo** %6
%80 = icmp eq %struct.addrinfo* %79, null
br i1 %80, label %124, label %81
81: ; preds = %78
%82 = icmp eq i8* %46, null
br label %83
83: ; preds = %81, %120
%84 = phi i32 [ %64, %81 ], [ %100, %120 ]
%85 = phi i32 [ %26, %81 ], [ %121, %120 ]
%86 = phi %struct.addrinfo* [ %79, %81 ], [ %122, %120 ]
%87 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %86, i64 0, i32 3
%88 = load i32, i32* %87
%89 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %86, i64 0, i32 2
%90 = load i32, i32* %89
%91 = load i32, i32* @NI_NUMERICSERV
%92 = load i32, i32* @NI_NUMERICHOST
%93 = or i32 %92, %91
%94 = call i32 @getnameinfo(i32 %88, i32 %90, i8* %21, i32 40, i8* %22, i32 40, i32 %93)
%95 = load %struct.addrinfo*, %struct.addrinfo** %6
%96 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %95, i64 0, i32 0
%97 = load i64, i64* %96
%98 = load i64, i64* @AF_INET6
%99 = icmp eq i64 %97, %98
%100 = select i1 %99, i32 1, i32 %84
%101 = icmp eq i32 %100, 0
br i1 %101, label %102, label %104
102: ; preds = %83
%103 = call i32 @safe_cat(i8** %2, i32* %4, i32 %85, i8* %21)
br label %108
104: ; preds = %83
%105 = call i32 @safe_cat(i8** %2, i32* %4, i32 %85, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%106 = call i32 @safe_cat(i8** %2, i32* %4, i32 %105, i8* %21)
%107 = call i32 @safe_cat(i8** %2, i32* %4, i32 %106, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %108
108: ; preds = %102, %104
%109 = phi i32 [ %107, %104 ], [ %103, %102 ]
br i1 %82, label %113, label %110
110: ; preds = %108
%111 = call i32 @safe_cat(i8** %2, i32* %4, i32 %109, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%112 = call i32 @safe_cat(i8** %2, i32* %4, i32 %111, i8* %22)
br label %113
113: ; preds = %110, %108
%114 = phi i32 [ %112, %110 ], [ %109, %108 ]
%115 = load %struct.addrinfo*, %struct.addrinfo** %6
%116 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %115, i64 0, i32 1
%117 = load %struct.addrinfo*, %struct.addrinfo** %116
store %struct.addrinfo* %117, %struct.addrinfo** %6
%118 = icmp eq %struct.addrinfo* %117, null
br i1 %118, label %119, label %120
119: ; preds = %113
br label %124
120: ; preds = %113
%121 = call i32 @safe_cat(i8** %2, i32* %4, i32 %114, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%122 = load %struct.addrinfo*, %struct.addrinfo** %6
%123 = icmp eq %struct.addrinfo* %122, null
br i1 %123, label %124, label %83
124: ; preds = %120, %119, %78
%125 = phi i32 [ %26, %78 ], [ %114, %119 ], [ %121, %120 ]
%126 = call i32 @freeaddrinfo(%struct.addrinfo* %79)
%127 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3)
%128 = icmp eq i8* %127, null
br i1 %128, label %131, label %129
129: ; preds = %124
%130 = call i32 @safe_cat(i8** %2, i32* %4, i32 %125, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %131
131: ; preds = %124, %129
%132 = phi i32 [ %130, %129 ], [ %125, %124 ]
%133 = icmp eq i8* %127, null
br i1 %133, label %134, label %24
134: ; preds = %131, %1
%135 = call i32 @free(i8* %13)
%136 = load i8*, i8** %2
br label %137
137: ; preds = %70, %134
%138 = phi i8* [ %136, %134 ], [ null, %70 ]
ret i8* %138
}