#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 {
  int dummy;
};
struct addrinfo {
  int ai_socktype;
  int ai_flags;
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  struct addrinfo *ai_next;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_family;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int AI_ADDRCONFIG;
int AI_ALL;
int AI_V4MAPPED;
int /*<<< orphan*/ EXIT_FAILURE;
int NI_MAXHOST;
int NI_MAXSERV;
int /*<<< orphan*/ NI_NUMERICHOST;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *gai_strerror(int);
int getaddrinfo(char *, int /*<<< orphan*/ *, struct addrinfo *,
                struct addrinfo **);
int getnameinfo(int /*<<< orphan*/, int /*<<< orphan*/, char *, int, char *,
                int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
char *strerror(int);
int main(int args, char *argv[0]) {
  struct addrinfo *res, *rp, hints;
  struct sockaddr addr;
  char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
  hints.ai_family = AF_INET6;
  hints.ai_protocol = 0;
  hints.ai_socktype = 0;
  hints.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED | AI_ALL;
  int stat = getaddrinfo(argv[1], NULL, &hints, &res);
  if (stat != 0) {
    int errn = errno;
    printf("getaddrinfo: %s\n", strerror(errn));
    exit(EXIT_FAILURE);
  }
  socklen_t clen = sizeof(addr);
  for (rp = res; rp != NULL; rp = rp->ai_next) {
    int s = getnameinfo(rp->ai_addr, rp->ai_addrlen, hbuf, NI_MAXHOST, sbuf,
                        NI_MAXSERV, NI_NUMERICHOST);
    if (s == 0)
      printf("host=%s, serv=%s, socktype: %d\n", hbuf, sbuf, rp->ai_socktype);
    else {
      perror("getnameinfo");
      printf("%s\n", gai_strerror(s));
      exit(EXIT_FAILURE);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x88(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x60(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x68(%rbp)
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x48(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    0x2de0(%rip),%rcx
or     (%rcx),%eax
mov    0x2db7(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x48(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1080 <getaddrinfo@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
je     126f <main+0xff>
mov    0x2d75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
mov    -0x70(%rbp),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movl   $0x4,-0x74(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1348 <main+0x1d8>
mov    -0x80(%rbp),%r8
mov    -0x88(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%edi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%esi
mov    0x2cff(%rip),%rax
mov    (%rax),%ecx
mov    0x2d2e(%rip),%rax
mov    (%rax),%r9d
mov    0x2d04(%rip),%rax
mov    (%rax),%eax
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1050 <getnameinfo@plt>
add    $0x10,%rsp
mov    %eax,-0x78(%rbp)
cmpl   $0x0,-0x78(%rbp)
jne    12ff <main+0x18f>
mov    -0x80(%rbp),%rdx
mov    -0x88(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
lea    0xd1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1332 <main+0x1c2>
lea    0xd2b(%rip),%rdi
call   1060 <perror@plt>
mov    -0x78(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    %rax,%rsi
lea    0xcf0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    1337 <main+0x1c7>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    127e <main+0x10e>
mov    -0x58(%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    $0x38,%rsp
mov    %rsp,-0x30(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x60(%rbp)
mov    0x2dbd(%rip),%rax
mov    0x2e06(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2ddb(%rip),%rax
or     (%rax),%ecx
mov    %ecx,-0x5c(%rbp)
mov    0x8(%rsi),%rdi
lea    -0x60(%rbp),%rdx
lea    -0x38(%rbp),%rcx
xor    %esi,%esi
call   1080 <getaddrinfo@plt>
test   %eax,%eax
jne    12c2 <main+0x152>
mov    -0x38(%rbp),%r13
test   %r13,%r13
je     1279 <main+0x109>
lea    0xdf4(%rip),%r15
nopl   (%rax)
mov    0x8(%r13),%esi
mov    0xc(%r13),%edi
mov    0x2d79(%rip),%rax
mov    (%rax),%ecx
mov    0x2da8(%rip),%rax
mov    (%rax),%r9d
mov    0x2d7e(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
mov    %r14,%rdx
mov    %r12,%r8
push   %rax
call   1050 <getnameinfo@plt>
add    $0x10,%rsp
test   %eax,%eax
jne    128e <main+0x11e>
mov    0x0(%r13),%ecx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x10(%r13),%r13
test   %r13,%r13
jne    1220 <main+0xb0>
mov    -0x30(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
lea    0xd9a(%rip),%rdi
call   1060 <perror@plt>
mov    %ebx,%edi
call   1040 <gai_strerror@plt>
lea    0xd63(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2cef(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd29(%rip),%rdi
jmp    12aa <main+0x13a>

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

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, %struct.addrinfo*, i64, i32 }
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@AF_INET6 = global i32 0
@AI_ADDRCONFIG = global i32 0
@AI_V4MAPPED = global i32 0
@AI_ALL = global i32 0
@errno = global i32 0
@.str = [17 x i8] c"getaddrinfo: %s\0A\00"
@EXIT_FAILURE = global i32 0
@NI_NUMERICHOST = global i32 0
@.str.1 = [32 x i8] c"host=%s, serv=%s, socktype: %d\0A\00"
@.str.2 = [12 x i8] c"getnameinfo\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo*
%4 = alloca %struct.addrinfo
%5 = bitcast %struct.addrinfo** %3 to i8*
%6 = bitcast %struct.addrinfo* %4 to i8*
%7 = load i32, i32* @NI_MAXHOST
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = load i32, i32* @NI_MAXSERV
%12 = zext i32 %11 to i64
%13 = alloca i8, i64 %12
%14 = load i32, i32* @AF_INET6
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 6
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 5
store i64 0, i64* %16
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 0
store i32 0, i32* %17
%18 = load i32, i32* @AI_ADDRCONFIG
%19 = load i32, i32* @AI_V4MAPPED
%20 = or i32 %19, %18
%21 = load i32, i32* @AI_ALL
%22 = or i32 %20, %21
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 1
store i32 %22, i32* %23
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @getaddrinfo(i8* %25, i32* null, %struct.addrinfo* %4, %struct.addrinfo** %3)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %2
%29 = load %struct.addrinfo*, %struct.addrinfo** %3
%30 = icmp eq %struct.addrinfo* %29, null
br i1 %30, label %61, label %37
31: ; preds = %2
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %28, %48
%38 = phi %struct.addrinfo* [ %53, %48 ], [ %29, %28 ]
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 3
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 2
%42 = load i32, i32* %41
%43 = load i32, i32* @NI_MAXHOST
%44 = load i32, i32* @NI_MAXSERV
%45 = load i32, i32* @NI_NUMERICHOST
%46 = call i32 @getnameinfo(i32 %40, i32 %42, i8* %10, i32 %43, i8* %13, i32 %44, i32 %45)
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %55
48: ; preds = %37
%49 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 0
%50 = load i32, i32* %49
%51 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %10, i8* %13, i32 %50)
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 4
%53 = load %struct.addrinfo*, %struct.addrinfo** %52
%54 = icmp eq %struct.addrinfo* %53, null
br i1 %54, label %61, label %37
55: ; preds = %37
%56 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%57 = call i8* @gai_strerror(i32 %46)
%58 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %57)
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %48, %28
ret i32 0
}