#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 sin6_port;
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct addrinfo {
  scalar_t__ ai_family;
  scalar_t__ ai_addr;
  struct addrinfo *ai_next;
};

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
int /*<<< orphan*/ EXIT_FAILURE;
int INET6_ADDRSTRLEN;
int INET_ADDRSTRLEN;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ exiterror(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char *, int /*<<< orphan*/ *, struct addrinfo *,
                struct addrinfo **);
char *inet_ntop(scalar_t__, int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc < 1) {
    exiterror("Please pass the hostname");
  }
  struct addrinfo hints;
  struct addrinfo *result;
  struct addrinfo *tempnode;
  memset(&hints, 0, sizeof hints);
  int code = getaddrinfo(argv[1], NULL, &hints, &result);
  if (code != 0) {
    fprintf(stderr, "getaddrinfo error:  %s\n", gai_strerror(code));
    exit(EXIT_FAILURE);
  }
  for (tempnode = result; tempnode != NULL; tempnode = tempnode->ai_next) {
    if (tempnode->ai_family == AF_INET) {
      char ip4[INET_ADDRSTRLEN];
      struct sockaddr_in *addr4 = (struct sockaddr_in *)tempnode->ai_addr;
      printf("IP4 address: %s  Port: %d\n",
             inet_ntop(AF_INET, &addr4->sin_addr, ip4, INET_ADDRSTRLEN),
             addr4->sin_port);
    } else {
      char ip6[INET6_ADDRSTRLEN];
      struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)tempnode->ai_addr;
      printf("IP6 address: %s  Port: %d\n",
             inet_ntop(AF_INET6, &addr6->sin6_addr, ip6, INET6_ADDRSTRLEN),
             addr6->sin6_port);
    }
  }
  freeaddrinfo(result);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    11bf <main+0x2f>
lea    0xe46(%rip),%rdi
call   1040 <exiterror@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   10a0 <getaddrinfo@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     1229 <main+0x99>
mov    0x2dcc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x3c(%rbp),%edi
call   1060 <gai_strerror@plt>
mov    -0x74(%rbp),%edi
mov    %rax,%rdx
lea    0xe03(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     134e <main+0x1be>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    0x2d96(%rip),%rcx
cmp    (%rcx),%rax
jne    12c8 <main+0x138>
mov    0x2d66(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,%rsp
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x58(%rbp)
mov    0x2d52(%rip),%rax
mov    (%rax),%rdi
mov    -0x58(%rbp),%rsi
add    $0x4,%rsi
mov    0x2d20(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%rsi
mov    -0x58(%rbp),%rax
mov    (%rax),%edx
lea    0xd7a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
jmp    1338 <main+0x1a8>
mov    0x2d19(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,%rsp
mov    %rax,-0x68(%rbp)
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x70(%rbp)
mov    0x2cd5(%rip),%rax
mov    (%rax),%rdi
mov    -0x70(%rbp),%rsi
add    $0x4,%rsi
mov    0x2cd3(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%rsi
mov    -0x70(%rbp),%rax
mov    (%rax),%edx
lea    0xd20(%rip),%rdi
call   1050 <printf@plt>
mov    -0x60(%rbp),%rax
mov    %rax,%rsp
jmp    133d <main+0x1ad>
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    1231 <main+0xa1>
mov    -0x30(%rbp),%rdi
call   10b0 <freeaddrinfo@plt>
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    %rsi,%rbx
test   %edi,%edi
jg     11b4 <main+0x24>
lea    0xe51(%rip),%rdi
call   1040 <exiterror@plt>
lea    -0x48(%rbp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x8(%rbx),%rdi
lea    -0x30(%rbp),%rcx
xor    %esi,%esi
mov    %r14,%rdx
call   10a0 <getaddrinfo@plt>
test   %eax,%eax
jne    12b4 <main+0x124>
mov    -0x30(%rbp),%rbx
test   %rbx,%rbx
je     129c <main+0x10c>
mov    0x2deb(%rip),%r12
mov    0x2dec(%rip),%r14
jmp    1250 <main+0xc0>
xchg   %ax,%ax
mov    %rsp,%r15
mov    (%r14),%eax
mov    %rsp,%rdx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdx
mov    %rdx,%rsp
mov    0x8(%rbx),%r13
mov    0x2db6(%rip),%rax
mov    (%rax),%rdi
lea    0x4(%r13),%rsi
mov    (%r14),%ecx
call   1030 <inet_ntop@plt>
mov    0x0(%r13),%edx
lea    0xe10(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %r15,%rsp
mov    0x10(%rbx),%rbx
test   %rbx,%rbx
je     1296 <main+0x106>
mov    (%rbx),%rax
cmp    (%r12),%rax
jne    1200 <main+0x70>
mov    %rsp,%r15
mov    0x2d5d(%rip),%rcx
mov    (%rcx),%eax
mov    %rsp,%rdx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdx
mov    %rdx,%rsp
mov    0x8(%rbx),%r13
mov    (%r12),%rdi
lea    0x4(%r13),%rsi
mov    (%rcx),%ecx
call   1030 <inet_ntop@plt>
mov    0x0(%r13),%edx
lea    0xd9d(%rip),%rdi
jmp    123c <main+0xac>
mov    -0x30(%rbp),%rdi
jmp    129e <main+0x10e>
xor    %edi,%edi
call   10b0 <freeaddrinfo@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d0d(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1060 <gai_strerror@plt>
lea    0xd4e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

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

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