#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 */
typedef int uint64_t;
typedef int uint32_t;
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct addrinfo {
  int ai_family;
  struct addrinfo *ai_next;
  scalar_t__ ai_addr;
  int /*<<< orphan*/ ai_flags;
  int /*<<< orphan*/ ai_socktype;
};
typedef int /*<<< orphan*/ reverse;
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
#define AF_INET6 129
int /*<<< orphan*/ AI_CANONNAME;
#define PF_INET 128
int PF_INET6;
int PF_UNSPEC;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int /*<<< orphan*/);
int getaddrinfo(char const *, int /*<<< orphan*/ *, struct addrinfo *,
                struct addrinfo **);
int getnameinfo(scalar_t__, int, char *, int, int /*<<< orphan*/ *,
                int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ inet_ntop(int, void *, char *, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int ntohl(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *);
int /*<<< orphan*/ stderr;
int lookup_host(const char *hostname, uint64_t *iplist, uint32_t *num_ip) {
  struct addrinfo hints, *res, *r;
  int errcode, i, len;
  char addrstr[128];
  char reverse[256];
  void *ptr;
  printf("Resolving %s ...\n", hostname);
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = PF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags |= AI_CANONNAME;
  errcode = getaddrinfo(hostname, NULL, &hints, &res);
  if (errcode != 0) {
    fprintf(stderr, "Failed to resolve IP address for %s: %s\n", hostname,
            gai_strerror(errno));
    return 0;
  }
  *num_ip = 0;
  r = res;
  i = 0;
  while (res) {
    if (*num_ip >= 512) {
      printf("Too man IP addresses in DNS response\n");
      return 1;
    }
    switch (res->ai_family) {
    case PF_INET:
      ptr = &(((struct sockaddr_in *)res->ai_addr)->sin_addr);
      iplist[i++] = 0;
      iplist[i++] = ntohl(*(uint32_t *)ptr) & 0xffffffffLL;
      len = sizeof(struct sockaddr_in);
      break;
    case AF_INET6:
      ptr = &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr;
      iplist[i++] = (((uint64_t)ntohl(((uint64_t *)ptr)[0])) << 32) +
                    ntohl((((uint64_t *)ptr)[0]) >> 32);
      iplist[i++] = (((uint64_t)ntohl(((uint64_t *)ptr)[1])) << 32) +
                    ntohl((((uint64_t *)ptr)[1]) >> 32);
      len = sizeof(struct sockaddr_in6);
      break;
    default: {
      res = res->ai_next;
      continue;
    }
    }
    inet_ntop(res->ai_family, ptr, addrstr, 100);
    addrstr[99] = '\0';
    if ((errcode = getnameinfo(res->ai_addr, len, reverse, sizeof(reverse),
                               NULL, 0, 0)) != 0) {
      snprintf(reverse, sizeof(reverse) - 1, "<reverse lookup failed>");
    }
    printf("IPv%d address: %s (%s)\n", res->ai_family == PF_INET6 ? 6 : 4,
           addrstr, reverse);
    res = res->ai_next;
    (*num_ip)++;
  }
  freeaddrinfo(r);
  return 1;
}


x86 assembly (clang, -O0):
<lookup_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   10a0 <getaddrinfo@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     1272 <lookup_host+0xd2>
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1f4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x1f0(%rbp)
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
call   1060 <gai_strerror@plt>
mov    -0x1f4(%rbp),%edi
mov    -0x1f0(%rbp),%rdx
mov    %rax,%rcx
lea    0xdb1(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    14f9 <lookup_host+0x359>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x58(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     14e9 <lookup_host+0x349>
mov    -0x20(%rbp),%rax
cmpl   $0x200,(%rax)
jl     12c0 <lookup_host+0x120>
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14f9 <lookup_host+0x359>
mov    -0x48(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1f8(%rbp)
sub    $0x80,%eax
je     12f2 <lookup_host+0x152>
jmp    12dc <lookup_host+0x13c>
mov    -0x1f8(%rbp),%eax
sub    $0x81,%eax
je     135a <lookup_host+0x1ba>
jmp    1411 <lookup_host+0x271>
mov    -0x48(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x1e8(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x58(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x58(%rbp)
movslq %ecx,%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x1e8(%rbp),%rax
mov    (%rax),%edi
call   10b0 <ntohl@plt>
cltq
movabs $0xffffffff,%rcx
and    %rcx,%rax
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x58(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x58(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
movl   $0x4,-0x5c(%rbp)
jmp    1422 <lookup_host+0x282>
mov    -0x48(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x1e8(%rbp)
mov    -0x1e8(%rbp),%rax
mov    (%rax),%edi
call   10b0 <ntohl@plt>
mov    $0x20,%ecx
shl    %cl,%eax
mov    %eax,-0x200(%rbp)
mov    -0x1e8(%rbp),%rax
mov    (%rax),%edi
mov    $0x20,%ecx
sar    %cl,%edi
call   10b0 <ntohl@plt>
mov    -0x200(%rbp),%edx
add    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x58(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x58(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1e8(%rbp),%rax
mov    0x4(%rax),%edi
call   10b0 <ntohl@plt>
mov    $0x20,%ecx
shl    %cl,%eax
mov    %eax,-0x1fc(%rbp)
mov    -0x1e8(%rbp),%rax
mov    0x4(%rax),%edi
mov    $0x20,%ecx
sar    %cl,%edi
call   10b0 <ntohl@plt>
mov    -0x1fc(%rbp),%edx
add    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x58(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x58(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
movl   $0x4,-0x5c(%rbp)
jmp    1422 <lookup_host+0x282>
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    128b <lookup_host+0xeb>
mov    -0x48(%rbp),%rax
mov    (%rax),%edi
mov    -0x1e8(%rbp),%rsi
lea    -0xe0(%rbp),%rdx
mov    $0x64,%ecx
call   1030 <inet_ntop@plt>
movb   $0x0,-0x7d(%rbp)
mov    -0x48(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x5c(%rbp),%esi
lea    -0x1e0(%rbp),%rdx
mov    $0x100,%ecx
xor    %eax,%eax
mov    %eax,%r8d
xor    %r9d,%r9d
movl   $0x0,(%rsp)
call   1080 <getnameinfo@plt>
mov    %eax,-0x54(%rbp)
cmp    $0x0,%eax
je     1493 <lookup_host+0x2f3>
lea    -0x1e0(%rbp),%rdi
mov    $0xff,%esi
lea    0xbd3(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x48(%rbp),%rax
mov    (%rax),%ecx
mov    0x2b40(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
mov    $0x6,%eax
cmp    %edx,%ecx
cmove  %eax,%esi
lea    -0xe0(%rbp),%rdx
lea    -0x1e0(%rbp),%rcx
lea    0xbb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    128b <lookup_host+0xeb>
mov    -0x50(%rbp),%rdi
call   10c0 <freeaddrinfo@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lookup_host>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1d8,%rsp
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe2f(%rip),%rdi
xor    %r15d,%r15d
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1080 <memset@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4c(%rsp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
or     %eax,0x48(%rsp)
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
xor    %esi,%esi
mov    %rbp,%rdx
call   10b0 <getaddrinfo@plt>
test   %eax,%eax
je     125f <lookup_host+0xaf>
mov    0x2d92(%rip),%rax
mov    (%rax),%ebp
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   1070 <gai_strerror@plt>
lea    0xdc5(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   10a0 <fprintf@plt>
jmp    1401 <lookup_host+0x251>
mov    %r14,0x28(%rsp)
movl   $0x0,(%r12)
mov    0x10(%rsp),%r14
test   %r14,%r14
je     13f3 <lookup_host+0x243>
lea    0x50(%rsp),%r13
xor    %eax,%eax
xor    %ebx,%ebx
mov    %r14,%r15
cmp    $0x1ff,%eax
jg     1416 <lookup_host+0x266>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15),%eax
cmp    $0x80,%eax
je     12d0 <lookup_host+0x120>
cmp    $0x81,%eax
je     1320 <lookup_host+0x170>
mov    0x8(%r15),%r15
mov    %r15,0x10(%rsp)
test   %r15,%r15
jne    12a0 <lookup_host+0xf0>
jmp    13f3 <lookup_host+0x243>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x10(%r15),%rbp
mov    %r12,0x20(%rsp)
mov    %r14,0x18(%rsp)
lea    0x0(,%rbx,4),%r14
mov    %r13,%r12
mov    0x28(%rsp),%r13
movl   $0x0,0x0(%r13,%rbx,4)
mov    0x0(%rbp),%edi
call   10c0 <ntohl@plt>
or     $0x4,%r14
mov    %eax,0x0(%r13,%r14,1)
mov    %r12,%r13
mov    0x18(%rsp),%r14
mov    0x20(%rsp),%r12
mov    (%r15),%edi
jmp    133e <lookup_host+0x18e>
nopw   0x0(%rax,%rax,1)
mov    0x10(%r15),%rbp
mov    0x0(%rbp),%edi
call   10c0 <ntohl@plt>
call   10c0 <ntohl@plt>
mov    0x4(%rbp),%edi
call   10c0 <ntohl@plt>
mov    $0x81,%edi
mov    %rbp,%rsi
mov    %r13,%rdx
mov    $0x64,%ecx
call   1030 <inet_ntop@plt>
movb   $0x0,0xb3(%rsp)
mov    0x10(%rsp),%rax
mov    0x10(%rax),%rdi
movl   $0x0,(%rsp)
mov    $0x4,%esi
lea    0xd0(%rsp),%rbp
mov    %rbp,%rdx
mov    $0x100,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1090 <getnameinfo@plt>
test   %eax,%eax
je     139e <lookup_host+0x1ee>
mov    %rbp,%rdi
mov    $0xff,%esi
lea    0xca2(%rip),%rdx
call   1060 <snprintf@plt>
add    $0x2,%rbx
mov    0x10(%rsp),%rax
mov    (%rax),%eax
xor    %ecx,%ecx
mov    0x2c2e(%rip),%rdx
cmp    (%rdx),%eax
sete   %cl
lea    (%rcx,%rcx,1),%esi
add    $0x4,%esi
lea    0xc8f(%rip),%rdi
mov    %r13,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%rax
mov    0x8(%rax),%r15
mov    %r15,0x10(%rsp)
mov    (%r12),%eax
add    $0x1,%eax
mov    %eax,(%r12)
test   %r15,%r15
jne    1286 <lookup_host+0xd6>
mov    %r14,%rdi
call   10d0 <freeaddrinfo@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x1d8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc4e(%rip),%rdi
call   1040 <puts@plt>
jmp    13fb <lookup_host+0x24b>

LLVM IR (-O0):
%struct.addrinfo = type { i32, %struct.addrinfo*, i64, i32, i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@.str = [18 x i8] c"Resolving %s ...\0A\00"
@PF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_CANONNAME = global i32 0
@stderr = global i32 0
@.str.1 = [41 x i8] c"Failed to resolve IP address for %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [38 x i8] c"Too man IP addresses in DNS response\0A\00"
@.str.3 = [24 x i8] c"<reverse lookup failed>\00"
@.str.4 = [24 x i8] c"IPv%d address: %s (%s)\0A\00"
@PF_INET6 = global i32 0
define i32 @lookup_host(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca %struct.addrinfo
%9 = alloca %struct.addrinfo*
%10 = alloca %struct.addrinfo*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [128 x i8]
%15 = alloca [256 x i8]
%16 = alloca i8*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%17 = load i8*, i8** %5
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @memset(%struct.addrinfo* %8, i32 0, i32 32)
%20 = load i32, i32* @PF_UNSPEC
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 0
store i32 %20, i32* %21
%22 = load i32, i32* @SOCK_STREAM
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 4
store i32 %22, i32* %23
%24 = load i32, i32* @AI_CANONNAME
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 3
%26 = load i32, i32* %25
%27 = or i32 %26, %24
store i32 %27, i32* %25
%28 = load i8*, i8** %5
%29 = call i32 @getaddrinfo(i8* %28, i32* null, %struct.addrinfo* %8, %struct.addrinfo** %9)
store i32 %29, i32* %11
%30 = load i32, i32* %11
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %3
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %5
%35 = load i32, i32* @errno
%36 = call i8* @gai_strerror(i32 %35)
%37 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %34, i8* %36)
store i32 0, i32* %4
br label %163
38: ; preds = %3
%39 = load i32*, i32** %7
store i32 0, i32* %39
%40 = load %struct.addrinfo*, %struct.addrinfo** %9
store %struct.addrinfo* %40, %struct.addrinfo** %10
store i32 0, i32* %12
br label %41
41: ; preds = %143, %121, %38
%42 = load %struct.addrinfo*, %struct.addrinfo** %9
%43 = icmp ne %struct.addrinfo* %42, null
br i1 %43, label %44, label %160
44: ; preds = %41
%45 = load i32*, i32** %7
%46 = load i32, i32* %45
%47 = icmp sge i32 %46, 512
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %4
br label %163
50: ; preds = %44
%51 = load %struct.addrinfo*, %struct.addrinfo** %9
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %51, i32 0, i32 0
%53 = load i32, i32* %52
switch i32 %53, label %121 [
i32 128, label %54
i32 129, label %78
]
54: ; preds = %50
%55 = load %struct.addrinfo*, %struct.addrinfo** %9
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %55, i32 0, i32 2
%57 = load i64, i64* %56
%58 = inttoptr i64 %57 to %struct.sockaddr_in*
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %58, i32 0, i32 0
%60 = bitcast i32* %59 to i8*
store i8* %60, i8** %16
%61 = load i32*, i32** %6
%62 = load i32, i32* %12
%63 = add nsw i32 %62, 1
store i32 %63, i32* %12
%64 = sext i32 %62 to i64
%65 = getelementptr inbounds i32, i32* %61, i64 %64
store i32 0, i32* %65
%66 = load i8*, i8** %16
%67 = bitcast i8* %66 to i32*
%68 = load i32, i32* %67
%69 = call i32 @ntohl(i32 %68)
%70 = sext i32 %69 to i64
%71 = and i64 %70, 4294967295
%72 = trunc i64 %71 to i32
%73 = load i32*, i32** %6
%74 = load i32, i32* %12
%75 = add nsw i32 %74, 1
store i32 %75, i32* %12
%76 = sext i32 %74 to i64
%77 = getelementptr inbounds i32, i32* %73, i64 %76
store i32 %72, i32* %77
store i32 4, i32* %13
br label %125
78: ; preds = %50
%79 = load %struct.addrinfo*, %struct.addrinfo** %9
%80 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %79, i32 0, i32 2
%81 = load i64, i64* %80
%82 = inttoptr i64 %81 to %struct.sockaddr_in6*
%83 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %82, i32 0, i32 0
%84 = bitcast i32* %83 to i8*
store i8* %84, i8** %16
%85 = load i8*, i8** %16
%86 = bitcast i8* %85 to i32*
%87 = getelementptr inbounds i32, i32* %86, i64 0
%88 = load i32, i32* %87
%89 = call i32 @ntohl(i32 %88)
%90 = shl i32 %89, 32
%91 = load i8*, i8** %16
%92 = bitcast i8* %91 to i32*
%93 = getelementptr inbounds i32, i32* %92, i64 0
%94 = load i32, i32* %93
%95 = ashr i32 %94, 32
%96 = call i32 @ntohl(i32 %95)
%97 = add nsw i32 %90, %96
%98 = load i32*, i32** %6
%99 = load i32, i32* %12
%100 = add nsw i32 %99, 1
store i32 %100, i32* %12
%101 = sext i32 %99 to i64
%102 = getelementptr inbounds i32, i32* %98, i64 %101
store i32 %97, i32* %102
%103 = load i8*, i8** %16
%104 = bitcast i8* %103 to i32*
%105 = getelementptr inbounds i32, i32* %104, i64 1
%106 = load i32, i32* %105
%107 = call i32 @ntohl(i32 %106)
%108 = shl i32 %107, 32
%109 = load i8*, i8** %16
%110 = bitcast i8* %109 to i32*
%111 = getelementptr inbounds i32, i32* %110, i64 1
%112 = load i32, i32* %111
%113 = ashr i32 %112, 32
%114 = call i32 @ntohl(i32 %113)
%115 = add nsw i32 %108, %114
%116 = load i32*, i32** %6
%117 = load i32, i32* %12
%118 = add nsw i32 %117, 1
store i32 %118, i32* %12
%119 = sext i32 %117 to i64
%120 = getelementptr inbounds i32, i32* %116, i64 %119
store i32 %115, i32* %120
store i32 4, i32* %13
br label %125
121: ; preds = %50
%122 = load %struct.addrinfo*, %struct.addrinfo** %9
%123 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %122, i32 0, i32 1
%124 = load %struct.addrinfo*, %struct.addrinfo** %123
store %struct.addrinfo* %124, %struct.addrinfo** %9
br label %41
125: ; preds = %78, %54
%126 = load %struct.addrinfo*, %struct.addrinfo** %9
%127 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %126, i32 0, i32 0
%128 = load i32, i32* %127
%129 = load i8*, i8** %16
%130 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%131 = call i32 @inet_ntop(i32 %128, i8* %129, i8* %130, i32 100)
%132 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 99
store i8 0, i8* %132
%133 = load %struct.addrinfo*, %struct.addrinfo** %9
%134 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %133, i32 0, i32 2
%135 = load i64, i64* %134
%136 = load i32, i32* %13
%137 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%138 = call i32 @getnameinfo(i64 %135, i32 %136, i8* %137, i32 256, i32* null, i32 0, i32 0)
store i32 %138, i32* %11
%139 = icmp ne i32 %138, 0
br i1 %139, label %140, label %143
140: ; preds = %125
%141 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%142 = call i32 @snprintf(i8* %141, i32 255, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %143
143: ; preds = %140, %125
%144 = load %struct.addrinfo*, %struct.addrinfo** %9
%145 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %144, i32 0, i32 0
%146 = load i32, i32* %145
%147 = load i32, i32* @PF_INET6
%148 = icmp eq i32 %146, %147
%149 = zext i1 %148 to i64
%150 = select i1 %148, i32 6, i32 4
%151 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%152 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%153 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %150, i8* %151, i8* %152)
%154 = load %struct.addrinfo*, %struct.addrinfo** %9
%155 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %154, i32 0, i32 1
%156 = load %struct.addrinfo*, %struct.addrinfo** %155
store %struct.addrinfo* %156, %struct.addrinfo** %9
%157 = load i32*, i32** %7
%158 = load i32, i32* %157
%159 = add nsw i32 %158, 1
store i32 %159, i32* %157
br label %41
160: ; preds = %41
%161 = load %struct.addrinfo*, %struct.addrinfo** %10
%162 = call i32 @freeaddrinfo(%struct.addrinfo* %161)
store i32 1, i32* %4
br label %163
163: ; preds = %160, %48, %32
%164 = load i32, i32* %4
ret i32 %164
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, %struct.addrinfo*, i64, i32, i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@.str = [18 x i8] c"Resolving %s ...\0A\00"
@PF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_CANONNAME = global i32 0
@stderr = global i32 0
@.str.1 = [41 x i8] c"Failed to resolve IP address for %s: %s\0A\00"
@errno = global i32 0
@.str.3 = [24 x i8] c"<reverse lookup failed>\00"
@.str.4 = [24 x i8] c"IPv%d address: %s (%s)\0A\00"
@PF_INET6 = global i32 0
@str = [37 x i8] c"Too man IP addresses in DNS response\00"
define i32 @lookup_host(i8* %0, i32* nocapture writeonly %1, i32* nocapture %2) {
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
%6 = alloca [128 x i8]
%7 = alloca [256 x i8]
%8 = bitcast %struct.addrinfo* %4 to i8*
%9 = bitcast %struct.addrinfo** %5 to i8*
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0)
%13 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 32)
%14 = load i32, i32* @PF_UNSPEC
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 0
store i32 %14, i32* %15
%16 = load i32, i32* @SOCK_STREAM
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 4
store i32 %16, i32* %17
%18 = load i32, i32* @AI_CANONNAME
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 3
%20 = load i32, i32* %19
%21 = or i32 %20, %18
store i32 %21, i32* %19
%22 = call i32 @getaddrinfo(i8* %0, i32* null, %struct.addrinfo* %4, %struct.addrinfo** %5)
%23 = icmp eq i32 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %3
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = call i8* @gai_strerror(i32 %26)
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %27)
br label %101
29: ; preds = %3
store i32 0, i32* %2
%30 = load %struct.addrinfo*, %struct.addrinfo** %5
%31 = icmp eq %struct.addrinfo* %30, null
br i1 %31, label %99, label %32
32: ; preds = %29
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 99
br label %34
34: ; preds = %32, %85
%35 = phi i32 [ 0, %32 ], [ %97, %85 ]
%36 = phi i64 [ 0, %32 ], [ %75, %85 ]
%37 = phi %struct.addrinfo* [ %30, %32 ], [ %95, %85 ]
%38 = icmp sgt i32 %35, 511
br i1 %38, label %43, label %39
39: ; preds = %34, %68
%40 = phi %struct.addrinfo* [ %70, %68 ], [ %37, %34 ]
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 0
%42 = load i32, i32* %41
switch i32 %42, label %68 [
i32 128, label %45
i32 129, label %57
]
43: ; preds = %34
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
br label %101
45: ; preds = %39
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 0
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 2
%48 = load i64, i64* %47
%49 = inttoptr i64 %48 to %struct.sockaddr_in*
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %49, i64 0, i32 0
%51 = or i64 %36, 1
%52 = getelementptr inbounds i32, i32* %1, i64 %36
store i32 0, i32* %52
%53 = load i32, i32* %50
%54 = call i32 @ntohl(i32 %53)
%55 = getelementptr inbounds i32, i32* %1, i64 %51
store i32 %54, i32* %55
%56 = load i32, i32* %46
br label %72
57: ; preds = %39
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 2
%59 = load i64, i64* %58
%60 = inttoptr i64 %59 to %struct.sockaddr_in6*
%61 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %60, i64 0, i32 0
%62 = load i32, i32* %61
%63 = call i32 @ntohl(i32 %62)
%64 = call i32 @ntohl(i32 poison)
%65 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %60, i64 1, i32 0
%66 = load i32, i32* %65
%67 = call i32 @ntohl(i32 %66)
br label %72
68: ; preds = %39
%69 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 1
%70 = load %struct.addrinfo*, %struct.addrinfo** %69
store %struct.addrinfo* %70, %struct.addrinfo** %5
%71 = icmp eq %struct.addrinfo* %70, null
br i1 %71, label %99, label %39
72: ; preds = %57, %45
%73 = phi i32 [ 129, %57 ], [ %56, %45 ]
%74 = phi i64 [ %59, %57 ], [ %48, %45 ]
%75 = add nuw i64 %36, 2
%76 = inttoptr i64 %74 to i8*
%77 = call i32 @inet_ntop(i32 %73, i8* %76, i8* %10, i32 100)
store i8 0, i8* %33
%78 = load %struct.addrinfo*, %struct.addrinfo** %5
%79 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %78, i64 0, i32 2
%80 = load i64, i64* %79
%81 = call i32 @getnameinfo(i64 %80, i32 4, i8* %11, i32 256, i32* null, i32 0, i32 0)
%82 = icmp eq i32 %81, 0
br i1 %82, label %85, label %83
83: ; preds = %72
%84 = call i32 @snprintf(i8* %11, i32 255, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %85
85: ; preds = %83, %72
%86 = load %struct.addrinfo*, %struct.addrinfo** %5
%87 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %86, i64 0, i32 0
%88 = load i32, i32* %87
%89 = load i32, i32* @PF_INET6
%90 = icmp eq i32 %88, %89
%91 = select i1 %90, i32 6, i32 4
%92 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %91, i8* %10, i8* %11)
%93 = load %struct.addrinfo*, %struct.addrinfo** %5
%94 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %93, i64 0, i32 1
%95 = load %struct.addrinfo*, %struct.addrinfo** %94
store %struct.addrinfo* %95, %struct.addrinfo** %5
%96 = load i32, i32* %2
%97 = add nsw i32 %96, 1
store i32 %97, i32* %2
%98 = icmp eq %struct.addrinfo* %95, null
br i1 %98, label %99, label %34
99: ; preds = %85, %68, %29
%100 = call i32 @freeaddrinfo(%struct.addrinfo* %30)
br label %101
101: ; preds = %99, %43, %24
%102 = phi i32 [ 0, %24 ], [ 1, %43 ], [ 1, %99 ]
ret i32 %102
}