#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_family;
  int ai_socktype;
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  struct addrinfo *ai_next;
};

/* Variables and functions */
int AF_UNSPEC;
int /*<<< orphan*/ EXIT_SUCCESS;
int NI_MAXHOST;
int NI_MAXSERV;
int /*<<< orphan*/ NI_NUMERICHOST;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int getaddrinfo(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                struct addrinfo **);
int getnameinfo(int /*<<< orphan*/, int /*<<< orphan*/, char *, int, char *,
                int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
void main(int args, char *argv[]) {
  struct addrinfo hints, *res, *rp;
  struct sockaddr_storage s_addr;
  hints.ai_family = AF_UNSPEC;
  char host_name[NI_MAXHOST], serv_name[NI_MAXSERV];
  printf("Requesting directions for %s\n", argv[1]);
  int stat = getaddrinfo(argv[1], NULL, NULL, &res);
  for (rp = res; rp != NULL; rp = rp->ai_next) {
    stat = getnameinfo(rp->ai_addr, rp->ai_addrlen, host_name, NI_MAXHOST,
                       serv_name, NI_MAXSERV, NI_NUMERICHOST);
    printf("host:%s\ttype:%i\tfamily:%i\n", host_name, rp->ai_socktype,
           rp->ai_family);
  }
  freeaddrinfo(res);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x30(%rbp),%rcx
mov    %rdx,%rsi
call   1060 <getaddrinfo@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1275 <main+0x125>
mov    -0x70(%rbp),%rdx
mov    -0x68(%rbp),%r8
mov    -0x38(%rbp),%rax
mov    0xc(%rax),%edi
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%esi
mov    0x2da3(%rip),%rax
mov    (%rax),%ecx
mov    0x2dba(%rip),%rax
mov    (%rax),%r9d
mov    0x2da0(%rip),%rax
mov    (%rax),%eax
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1040 <getnameinfo@plt>
mov    -0x70(%rbp),%rsi
add    $0x10,%rsp
mov    %eax,-0x5c(%rbp)
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x38(%rbp),%rax
mov    (%rax),%ecx
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    11f5 <main+0xa5>
mov    -0x30(%rbp),%rdi
call   1070 <freeaddrinfo@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    0x8(%rsi),%rsi
lea    0xe60(%rip),%rdi
xor    %r12d,%r12d
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x8(%r15),%rdi
lea    -0x30(%rbp),%rcx
xor    %esi,%esi
xor    %edx,%edx
call   1060 <getaddrinfo@plt>
mov    -0x30(%rbp),%r13
test   %r13,%r13
je     1233 <main+0xe3>
lea    0xe53(%rip),%r12
mov    0x2e16(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x8(%r13),%esi
mov    0xc(%r13),%edi
mov    0x2dd9(%rip),%rax
mov    (%rax),%ecx
mov    (%r15),%r9d
mov    0x2ddd(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
mov    %rbx,%rdx
mov    %r14,%r8
push   %rax
call   1040 <getnameinfo@plt>
add    $0x10,%rsp
mov    0x0(%r13),%ecx
mov    0x4(%r13),%edx
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x10(%r13),%r13
test   %r13,%r13
jne    11e0 <main+0x90>
mov    -0x30(%rbp),%r12
mov    %r12,%rdi
call   1070 <freeaddrinfo@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, %struct.addrinfo* }
%struct.sockaddr_storage = type { i32 }
@AF_UNSPEC = global i32 0
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@.str = [30 x i8] c"Requesting directions for %s\0A\00"
@NI_NUMERICHOST = global i32 0
@.str.1 = [27 x i8] c"host:%s\09type:%i\09family:%i\0A\00"
@EXIT_SUCCESS = global i32 0
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = alloca %struct.addrinfo*
%8 = alloca %struct.sockaddr_storage
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%13 = load i32, i32* @AF_UNSPEC
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i32 0, i32 0
store i32 %13, i32* %14
%15 = load i32, i32* @NI_MAXHOST
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %9
%18 = alloca i8, i64 %16
store i64 %16, i64* %10
%19 = load i32, i32* @NI_MAXSERV
%20 = zext i32 %19 to i64
%21 = alloca i8, i64 %20
store i64 %20, i64* %11
%22 = load i8**, i8*** %4
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i8**, i8*** %4
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @getaddrinfo(i8* %28, i32* null, i32* null, %struct.addrinfo** %6)
store i32 %29, i32* %12
%30 = load %struct.addrinfo*, %struct.addrinfo** %6
store %struct.addrinfo* %30, %struct.addrinfo** %7
br label %31
31: ; preds = %52, %2
%32 = load %struct.addrinfo*, %struct.addrinfo** %7
%33 = icmp ne %struct.addrinfo* %32, null
br i1 %33, label %34, label %56
34: ; preds = %31
%35 = load %struct.addrinfo*, %struct.addrinfo** %7
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i32 0, i32 3
%37 = load i32, i32* %36
%38 = load %struct.addrinfo*, %struct.addrinfo** %7
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i32 0, i32 2
%40 = load i32, i32* %39
%41 = load i32, i32* @NI_MAXHOST
%42 = load i32, i32* @NI_MAXSERV
%43 = load i32, i32* @NI_NUMERICHOST
%44 = call i32 @getnameinfo(i32 %37, i32 %40, i8* %18, i32 %41, i8* %21, i32 %42, i32 %43)
store i32 %44, i32* %12
%45 = load %struct.addrinfo*, %struct.addrinfo** %7
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %45, i32 0, i32 1
%47 = load i32, i32* %46
%48 = load %struct.addrinfo*, %struct.addrinfo** %7
%49 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %48, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %18, i32 %47, i32 %50)
br label %52
52: ; preds = %34
%53 = load %struct.addrinfo*, %struct.addrinfo** %7
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i32 0, i32 4
%55 = load %struct.addrinfo*, %struct.addrinfo** %54
store %struct.addrinfo* %55, %struct.addrinfo** %7
br label %31
56: ; preds = %31
%57 = load %struct.addrinfo*, %struct.addrinfo** %6
%58 = call i32 @freeaddrinfo(%struct.addrinfo* %57)
%59 = load i32, i32* @EXIT_SUCCESS
%60 = call i32 @exit(i32 %59)
unreachable
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, %struct.addrinfo* }
@AF_UNSPEC = global i32 0
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@.str = [30 x i8] c"Requesting directions for %s\0A\00"
@NI_NUMERICHOST = global i32 0
@.str.1 = [27 x i8] c"host:%s\09type:%i\09family:%i\0A\00"
@EXIT_SUCCESS = global i32 0
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo*
%4 = bitcast %struct.addrinfo** %3 to i8*
%5 = load i32, i32* @NI_MAXHOST
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = load i32, i32* @NI_MAXSERV
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %11
%15 = call i32 @getaddrinfo(i8* %14, i32* null, i32* null, %struct.addrinfo** %3)
%16 = load %struct.addrinfo*, %struct.addrinfo** %3
%17 = icmp eq %struct.addrinfo* %16, null
br i1 %17, label %38, label %18
18: ; preds = %2, %18
%19 = phi %struct.addrinfo* [ %34, %18 ], [ %16, %2 ]
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 3
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 2
%23 = load i32, i32* %22
%24 = load i32, i32* @NI_MAXHOST
%25 = load i32, i32* @NI_MAXSERV
%26 = load i32, i32* @NI_NUMERICHOST
%27 = call i32 @getnameinfo(i32 %21, i32 %23, i8* %7, i32 %24, i8* %10, i32 %25, i32 %26)
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 1
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %7, i32 %29, i32 %31)
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 4
%34 = load %struct.addrinfo*, %struct.addrinfo** %33
%35 = icmp eq %struct.addrinfo* %34, null
br i1 %35, label %36, label %18
36: ; preds = %18
%37 = load %struct.addrinfo*, %struct.addrinfo** %3
br label %38
38: ; preds = %36, %2
%39 = phi %struct.addrinfo* [ %37, %36 ], [ null, %2 ]
%40 = call i32 @freeaddrinfo(%struct.addrinfo* %39)
%41 = load i32, i32* @EXIT_SUCCESS
%42 = call i32 @exit(i32 %41)
unreachable
}