#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 {
  scalar_t__ ai_family;
  scalar_t__ ai_addr;
  struct addrinfo *ai_next;
};
typedef int /*<<< orphan*/ addr6;
typedef int /*<<< orphan*/ addr4;

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int INET6_ADDRSTRLEN;
int INET_ADDRSTRLEN;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
scalar_t__ getaddrinfo(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                       struct addrinfo **);
int /*<<< orphan*/ inet_ntop(scalar_t__, int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  struct addrinfo *info;
  struct addrinfo *res;
  char addr4[INET_ADDRSTRLEN], addr6[INET6_ADDRSTRLEN];
  if (argc < 2) {
    printf("Usage: %s <hostname>\n", argv[0]);
    exit(EXIT_SUCCESS);
  }
  if (getaddrinfo(argv[1], NULL, NULL, &info) < 0) {
    perror("getaddrinfo() ");
    exit(EXIT_FAILURE);
  }
  for (res = info; res != NULL; res = res->ai_next) {
    if (res->ai_family == AF_INET) {
      inet_ntop(AF_INET, &((struct sockaddr_in *)res->ai_addr)->sin_addr, addr4,
                sizeof(addr4));
      printf("%s\n", addr4);
    }
    if (res->ai_family == AF_INET6) {
      inet_ntop(AF_INET6, &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr,
                addr6, sizeof(addr6));
      printf("%s\n", addr6);
    }
  }
  freeaddrinfo(info);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x58(%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,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11fa <main+0x9a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe19(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x18(%rbp),%rcx
mov    %rdx,%rsi
call   1070 <getaddrinfo@plt>
cmp    $0x0,%rax
jge    1236 <main+0xd6>
lea    0xdf3(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12ef <main+0x18f>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2d89(%rip),%rcx
cmp    (%rcx),%rax
jne    1291 <main+0x131>
mov    -0x50(%rbp),%rdx
mov    -0x58(%rbp),%rax
mov    0x2d71(%rip),%rcx
mov    (%rcx),%rdi
mov    -0x20(%rbp),%rcx
mov    0x8(%rcx),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x50(%rbp),%rsi
lea    0xd99(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2d39(%rip),%rcx
cmp    (%rcx),%rax
jne    12d9 <main+0x179>
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rax
mov    0x2d21(%rip),%rcx
mov    (%rcx),%rdi
mov    -0x20(%rbp),%rcx
mov    0x8(%rcx),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x40(%rbp),%rsi
lea    0xd51(%rip),%rdi
call   1040 <printf@plt>
jmp    12de <main+0x17e>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    123e <main+0xde>
mov    -0x18(%rbp),%rdi
call   1080 <freeaddrinfo@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsp,%r15
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
mov    %rax,-0x48(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
mov    %rax,-0x40(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x1,%edi
jle    126d <main+0x10d>
mov    0x8(%rsi),%rdi
lea    -0x30(%rbp),%rcx
xor    %esi,%esi
xor    %edx,%edx
call   1070 <getaddrinfo@plt>
test   %rax,%rax
js     128a <main+0x12a>
mov    -0x30(%rbp),%r14
test   %r14,%r14
je     1252 <main+0xf2>
mov    %r15,-0x38(%rbp)
lea    0xe3e(%rip),%r13
mov    0x2dea(%rip),%r15
jmp    11f9 <main+0x99>
mov    0x10(%r14),%r14
test   %r14,%r14
je     1248 <main+0xe8>
mov    (%r14),%rdi
mov    0x2ddd(%rip),%rax
cmp    (%rax),%rdi
jne    1226 <main+0xc6>
mov    0x8(%r14),%rsi
mov    %r12,%rdx
mov    -0x48(%rbp),%rcx
call   1030 <inet_ntop@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    (%r14),%rdi
cmp    (%r15),%rdi
jne    11f0 <main+0x90>
mov    0x8(%r14),%rsi
mov    %rbx,%rdx
mov    -0x40(%rbp),%rcx
call   1030 <inet_ntop@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
jmp    11f0 <main+0x90>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%r15
jmp    1254 <main+0xf4>
xor    %edi,%edi
call   1080 <freeaddrinfo@plt>
mov    %r15,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsi),%rsi
lea    0xd89(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
lea    0xd85(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
%struct.addrinfo = type { i64, i64, %struct.addrinfo* }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@INET_ADDRSTRLEN = global i32 0
@INET6_ADDRSTRLEN = global i32 0
@.str = [22 x i8] c"Usage: %s <hostname>\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [15 x i8] c"getaddrinfo() \00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i64 0
@.str.2 = [4 x i8] c"%s\0A\00"
@AF_INET6 = global i64 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo*
%4 = bitcast %struct.addrinfo** %3 to i8*
%5 = load i32, i32* @INET_ADDRSTRLEN
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = load i32, i32* @INET6_ADDRSTRLEN
%10 = zext i32 %9 to i64
%11 = alloca i8, i64 %10
%12 = icmp slt i32 %0, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8*, i8** %1
%15 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_SUCCESS
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @getaddrinfo(i8* %20, i32* null, i32* null, %struct.addrinfo** %3)
%22 = icmp slt i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = load %struct.addrinfo*, %struct.addrinfo** %3
%25 = icmp eq %struct.addrinfo* %24, null
br i1 %25, label %61, label %30
26: ; preds = %18
%27 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %23, %55
%31 = phi %struct.addrinfo* [ %57, %55 ], [ %24, %23 ]
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i64 0, i32 0
%33 = load i64, i64* %32
%34 = load i64, i64* @AF_INET
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %44
36: ; preds = %30
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i64 0, i32 1
%38 = load i64, i64* %37
%39 = inttoptr i64 %38 to %struct.sockaddr_in*
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %39, i64 0, i32 0
%41 = call i32 @inet_ntop(i64 %33, i32* %40, i8* %8, i32 %5)
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%43 = load i64, i64* %32
br label %44
44: ; preds = %36, %30
%45 = phi i64 [ %43, %36 ], [ %33, %30 ]
%46 = load i64, i64* @AF_INET6
%47 = icmp eq i64 %45, %46
br i1 %47, label %48, label %55
48: ; preds = %44
%49 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i64 0, i32 1
%50 = load i64, i64* %49
%51 = inttoptr i64 %50 to %struct.sockaddr_in6*
%52 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %51, i64 0, i32 0
%53 = call i32 @inet_ntop(i64 %45, i32* %52, i8* %11, i32 %9)
%54 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %11)
br label %55
55: ; preds = %44, %48
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i64 0, i32 2
%57 = load %struct.addrinfo*, %struct.addrinfo** %56
%58 = icmp eq %struct.addrinfo* %57, null
br i1 %58, label %59, label %30
59: ; preds = %55
%60 = load %struct.addrinfo*, %struct.addrinfo** %3
br label %61
61: ; preds = %59, %23
%62 = phi %struct.addrinfo* [ %60, %59 ], [ null, %23 ]
%63 = call i32 @freeaddrinfo(%struct.addrinfo* %62)
ret i32 0
}