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

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int /*<<< orphan*/ SOCK_STREAM;
int _host_gaierror(char *, int);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int getaddrinfo(char *, int /*<<< orphan*/ *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ *inet_ntop(int, int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *, char *);
int _host(int family, char *hostname) {
  struct addrinfo hints;
  struct addrinfo *ai;
  int res;
  struct addrinfo *p;
  char buf[128];
  struct sockaddr_in *sa;
  struct sockaddr_in6 *sa6;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = family;
  hints.ai_socktype = SOCK_STREAM;
  if ((res = getaddrinfo(hostname, NULL, &hints, &ai)) != 0)
    return _host_gaierror(hostname, res);
  for (p = ai; p != NULL; p = p->ai_next)
    switch (p->ai_family) {
    case AF_INET:
      sa = (struct sockaddr_in *)p->ai_addr;
      if (inet_ntop(p->ai_family, &sa->sin_addr, buf, sizeof(buf)) != NULL)
        printf("%s has address %s\n", hostname, buf);
      break;
    case AF_INET6:
      sa6 = (struct sockaddr_in6 *)p->ai_addr;
      if (inet_ntop(p->ai_family, &sa6->sin6_addr, buf, sizeof(buf)) != NULL)
        printf("%s has IPv6 address %s\n", hostname, buf);
      break;
    }
  freeaddrinfo(ai);
  return 0;
}


x86 assembly (clang, -O0):
<_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1070 <getaddrinfo@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
je     11c9 <_host+0x69>
mov    -0x10(%rbp),%rdi
mov    -0x3c(%rbp),%esi
call   1060 <_host_gaierror@plt>
mov    %eax,-0x4(%rbp)
jmp    12da <_host+0x17a>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     12ca <_host+0x16a>
mov    -0x48(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xe4(%rbp)
sub    $0x80,%eax
je     1261 <_host+0x101>
jmp    11f8 <_host+0x98>
mov    -0xe4(%rbp),%eax
sub    $0x81,%eax
jne    12b4 <_host+0x154>
jmp    120e <_host+0xae>
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0xd8(%rbp)
mov    -0x48(%rbp),%rax
mov    (%rax),%edi
mov    -0xd8(%rbp),%rsi
lea    -0xd0(%rbp),%rdx
mov    $0x80,%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
je     125c <_host+0xfc>
mov    -0x10(%rbp),%rsi
lea    -0xd0(%rbp),%rdx
lea    0xda9(%rip),%rdi
call   1040 <printf@plt>
jmp    12b4 <_host+0x154>
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0xe0(%rbp)
mov    -0x48(%rbp),%rax
mov    (%rax),%edi
mov    -0xe0(%rbp),%rsi
lea    -0xd0(%rbp),%rdx
mov    $0x80,%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
je     12af <_host+0x14f>
mov    -0x10(%rbp),%rsi
lea    -0xd0(%rbp),%rdx
lea    0xd69(%rip),%rdi
call   1040 <printf@plt>
jmp    12b4 <_host+0x154>
jmp    12b9 <_host+0x159>
mov    -0x48(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    11d1 <_host+0x71>
mov    -0x38(%rbp),%rdi
call   1080 <freeaddrinfo@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_host>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    %rsi,%r15
mov    %edi,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    %ebx,0x10(%rsp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
lea    0x8(%rsp),%rcx
mov    %r15,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1070 <getaddrinfo@plt>
test   %eax,%eax
je     11c3 <_host+0x63>
mov    %r15,%rdi
mov    %eax,%esi
call   1060 <_host_gaierror@plt>
mov    %eax,%r14d
jmp    1269 <_host+0x109>
mov    0x8(%rsp),%rbx
xor    %r14d,%r14d
test   %rbx,%rbx
je     1262 <_host+0x102>
lea    0x30(%rsp),%r12
lea    0xe33(%rip),%r13
lea    0xe19(%rip),%rbp
jmp    11f9 <_host+0x99>
nopl   0x0(%rax)
mov    0x10(%rbx),%rbx
test   %rbx,%rbx
je     125b <_host+0xfb>
mov    (%rbx),%eax
cmp    $0x80,%eax
je     1230 <_host+0xd0>
cmp    $0x81,%eax
jne    11f0 <_host+0x90>
mov    0x8(%rbx),%rsi
mov    $0x81,%edi
mov    %r12,%rdx
mov    $0x80,%ecx
call   1030 <inet_ntop@plt>
mov    %rbp,%rdi
test   %rax,%rax
jne    124e <_host+0xee>
jmp    11f0 <_host+0x90>
nopl   0x0(%rax)
mov    0x8(%rbx),%rsi
mov    $0x80,%edi
mov    %r12,%rdx
mov    $0x80,%ecx
call   1030 <inet_ntop@plt>
mov    %r13,%rdi
test   %rax,%rax
je     11f0 <_host+0x90>
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <printf@plt>
jmp    11f0 <_host+0x90>
mov    0x8(%rsp),%rdi
jmp    1264 <_host+0x104>
xor    %edi,%edi
call   1080 <freeaddrinfo@plt>
mov    %r14d,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i64, %struct.addrinfo*, i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@SOCK_STREAM = global i32 0
@.str = [19 x i8] c"%s has address %s\0A\00"
@.str.1 = [24 x i8] c"%s has IPv6 address %s\0A\00"
define i32 @_host(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.addrinfo
%7 = alloca %struct.addrinfo*
%8 = alloca i32
%9 = alloca %struct.addrinfo*
%10 = alloca [128 x i8]
%11 = alloca %struct.sockaddr_in*
%12 = alloca %struct.sockaddr_in6*
store i32 %0, i32* %4
store i8* %1, i8** %5
%13 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 32)
%14 = load i32, i32* %4
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 0
store i32 %14, i32* %15
%16 = load i32, i32* @SOCK_STREAM
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
store i32 %16, i32* %17
%18 = load i8*, i8** %5
%19 = call i32 @getaddrinfo(i8* %18, i32* null, %struct.addrinfo* %6, %struct.addrinfo** %7)
store i32 %19, i32* %8
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %2
%22 = load i8*, i8** %5
%23 = load i32, i32* %8
%24 = call i32 @_host_gaierror(i8* %22, i32 %23)
store i32 %24, i32* %3
br label %78
25: ; preds = %2
%26 = load %struct.addrinfo*, %struct.addrinfo** %7
store %struct.addrinfo* %26, %struct.addrinfo** %9
br label %27
27: ; preds = %71, %25
%28 = load %struct.addrinfo*, %struct.addrinfo** %9
%29 = icmp ne %struct.addrinfo* %28, null
br i1 %29, label %30, label %75
30: ; preds = %27
%31 = load %struct.addrinfo*, %struct.addrinfo** %9
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i32 0, i32 0
%33 = load i32, i32* %32
switch i32 %33, label %70 [
i32 129, label %34
i32 128, label %52
]
34: ; preds = %30
%35 = load %struct.addrinfo*, %struct.addrinfo** %9
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i32 0, i32 1
%37 = load i64, i64* %36
%38 = inttoptr i64 %37 to %struct.sockaddr_in*
store %struct.sockaddr_in* %38, %struct.sockaddr_in** %11
%39 = load %struct.addrinfo*, %struct.addrinfo** %9
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i32 0, i32 0
%41 = load i32, i32* %40
%42 = load %struct.sockaddr_in*, %struct.sockaddr_in** %11
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %42, i32 0, i32 0
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%45 = call i32* @inet_ntop(i32 %41, i32* %43, i8* %44, i32 128)
%46 = icmp ne i32* %45, null
br i1 %46, label %47, label %51
47: ; preds = %34
%48 = load i8*, i8** %5
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%50 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %48, i8* %49)
br label %51
51: ; preds = %47, %34
br label %70
52: ; preds = %30
%53 = load %struct.addrinfo*, %struct.addrinfo** %9
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i32 0, i32 1
%55 = load i64, i64* %54
%56 = inttoptr i64 %55 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %56, %struct.sockaddr_in6** %12
%57 = load %struct.addrinfo*, %struct.addrinfo** %9
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i32 0, i32 0
%59 = load i32, i32* %58
%60 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %12
%61 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %60, i32 0, i32 0
%62 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%63 = call i32* @inet_ntop(i32 %59, i32* %61, i8* %62, i32 128)
%64 = icmp ne i32* %63, null
br i1 %64, label %65, label %69
65: ; preds = %52
%66 = load i8*, i8** %5
%67 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%68 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %66, i8* %67)
br label %69
69: ; preds = %65, %52
br label %70
70: ; preds = %30, %69, %51
br label %71
71: ; preds = %70
%72 = load %struct.addrinfo*, %struct.addrinfo** %9
%73 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %72, i32 0, i32 2
%74 = load %struct.addrinfo*, %struct.addrinfo** %73
store %struct.addrinfo* %74, %struct.addrinfo** %9
br label %27
75: ; preds = %27
%76 = load %struct.addrinfo*, %struct.addrinfo** %7
%77 = call i32 @freeaddrinfo(%struct.addrinfo* %76)
store i32 0, i32* %3
br label %78
78: ; preds = %75, %21
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i64, %struct.addrinfo*, i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@SOCK_STREAM = global i32 0
@.str = [19 x i8] c"%s has address %s\0A\00"
@.str.1 = [24 x i8] c"%s has IPv6 address %s\0A\00"
define i32 @_host(i32 %0, i8* %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca [128 x i8]
%6 = bitcast %struct.addrinfo* %3 to i8*
%7 = bitcast %struct.addrinfo** %4 to i8*
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%9 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 32)
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 0
store i32 %0, i32* %10
%11 = load i32, i32* @SOCK_STREAM
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %11, i32* %12
%13 = call i32 @getaddrinfo(i8* %1, i32* null, %struct.addrinfo* %3, %struct.addrinfo** %4)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load %struct.addrinfo*, %struct.addrinfo** %4
%17 = icmp eq %struct.addrinfo* %16, null
br i1 %17, label %47, label %20
18: ; preds = %2
%19 = call i32 @_host_gaierror(i8* %1, i32 %13)
br label %50
20: ; preds = %15, %41
%21 = phi %struct.addrinfo* [ %43, %41 ], [ %16, %15 ]
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %21, i64 0, i32 0
%23 = load i32, i32* %22
switch i32 %23, label %41 [
i32 129, label %24
i32 128, label %31
]
24: ; preds = %20
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %21, i64 0, i32 1
%26 = load i64, i64* %25
%27 = inttoptr i64 %26 to %struct.sockaddr_in*
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %27, i64 0, i32 0
%29 = call i32* @inet_ntop(i32 129, i32* %28, i8* %8, i32 128)
%30 = icmp eq i32* %29, null
br i1 %30, label %41, label %38
31: ; preds = %20
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %21, i64 0, i32 1
%33 = load i64, i64* %32
%34 = inttoptr i64 %33 to %struct.sockaddr_in6*
%35 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %34, i64 0, i32 0
%36 = call i32* @inet_ntop(i32 128, i32* %35, i8* %8, i32 128)
%37 = icmp eq i32* %36, null
br i1 %37, label %41, label %38
38: ; preds = %31, %24
%39 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %24 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %31 ]
%40 = call i32 @printf(i8* %39, i8* %1, i8* %8)
br label %41
41: ; preds = %38, %20, %24, %31
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %21, i64 0, i32 2
%43 = load %struct.addrinfo*, %struct.addrinfo** %42
%44 = icmp eq %struct.addrinfo* %43, null
br i1 %44, label %45, label %20
45: ; preds = %41
%46 = load %struct.addrinfo*, %struct.addrinfo** %4
br label %47
47: ; preds = %45, %15
%48 = phi %struct.addrinfo* [ %46, %45 ], [ null, %15 ]
%49 = call i32 @freeaddrinfo(%struct.addrinfo* %48)
br label %50
50: ; preds = %47, %18
%51 = phi i32 [ %19, %18 ], [ 0, %47 ]
ret i32 %51
}