#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;
  int /*<<< orphan*/ ai_socktype;
};

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_UNSPEC;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char *, int /*<<< orphan*/ *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ inet_ntop(scalar_t__, void *, char *, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  struct addrinfo hints, *res, *p;
  int status;
  char ipstr[INET6_ADDRSTRLEN];
  int i;
  if (argc < 2) {
    fprintf(stderr, "usage: dnstest hostname [hostname...]\n");
    return 1;
  }
  for (i = 1; i < argc; ++i) {
    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    if ((status = getaddrinfo(argv[i], NULL, &hints, &res)) != 0) {
      fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
      return 2;
    }
    printf("Resolved: %s\n", argv[i]);
    for (p = res; p != NULL; p = p->ai_next) {
      void *addr;
      if (p->ai_family == AF_INET) {
        struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
        addr = &(ipv4->sin_addr);
      } else {
        struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
        addr = &(ipv6->sin6_addr);
      }
      inet_ntop(p->ai_family, addr, ipstr, sizeof ipstr);
      printf("%s\n", ipstr);
    }
    freeaddrinfo(res);
  }
  return 0;
}


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    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x88(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x58(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11f0 <main+0x80>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x60(%rbp)
jmp    1369 <main+0x1f9>
movl   $0x1,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    135b <main+0x1eb>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1080 <getaddrinfo@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
je     1297 <main+0x127>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x44(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x8c(%rbp),%edi
mov    %rax,%rdx
lea    0xdaa(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x60(%rbp)
jmp    1369 <main+0x1f9>
mov    -0x10(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd8e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1344 <main+0x1d4>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    0x2d10(%rip),%rcx
cmp    (%rcx),%rax
jne    12f2 <main+0x182>
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
mov    %rax,-0x68(%rbp)
jmp    1306 <main+0x196>
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x80(%rbp),%rdx
mov    -0x88(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    (%rcx),%rdi
mov    -0x68(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x80(%rbp),%rsi
lea    0xd14(%rip),%rdi
call   1040 <printf@plt>
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    12b7 <main+0x147>
mov    -0x38(%rbp),%rdi
call   1090 <freeaddrinfo@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    11f7 <main+0x87>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x60(%rbp)
mov    -0x50(%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    $0x48,%rsp
mov    %rsi,-0x30(%rbp)
mov    %rsp,%r14
mov    0x2e59(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%rbx
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x2,%edi
jge    11c9 <main+0x59>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%eax
jmp    12cf <main+0x15f>
mov    %r14,-0x38(%rbp)
mov    %edi,%eax
mov    %rax,-0x48(%rbp)
mov    $0x1,%r12d
lea    0xe62(%rip),%r13
mov    -0x30(%rbp),%r14
jmp    1209 <main+0x99>
cs nopw 0x0(%rax,%rax,1)
xor    %edi,%edi
mov    -0x30(%rbp),%r14
call   1090 <freeaddrinfo@plt>
add    $0x1,%r12
cmp    -0x48(%rbp),%r12
je     129f <main+0x12f>
lea    -0x68(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x68(%rbp)
mov    0x2d9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    (%r14,%r12,8),%rdi
xor    %esi,%esi
lea    -0x68(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1080 <getaddrinfo@plt>
test   %eax,%eax
jne    12a3 <main+0x133>
mov    (%r14,%r12,8),%rsi
lea    0xde3(%rip),%rdi
call   1040 <printf@plt>
mov    -0x40(%rbp),%r14
test   %r14,%r14
je     11f0 <main+0x80>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14),%rdi
mov    0x8(%r14),%rsi
mov    %rbx,%rdx
mov    %r15d,%ecx
call   1030 <inet_ntop@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    0x10(%r14),%r14
test   %r14,%r14
jne    1270 <main+0x100>
mov    -0x40(%rbp),%rdi
jmp    11f2 <main+0x82>
xor    %eax,%eax
jmp    12cb <main+0x15b>
mov    0x2d26(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xd6d(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x2,%eax
mov    -0x38(%rbp),%r14
mov    %r14,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.addrinfo = type { i64, i64, %struct.addrinfo*, i32 }
@INET6_ADDRSTRLEN = global i32 0
@stderr = global i32 0
@.str = [39 x i8] c"usage: dnstest hostname [hostname...]\0A\00"
@AF_UNSPEC = global i64 0
@SOCK_STREAM = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [14 x i8] c"Resolved: %s\0A\00"
@AF_INET = global i64 0
@.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* @INET6_ADDRSTRLEN
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = icmp slt i32 %0, 2
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 0
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
%15 = zext i32 %0 to i64
br label %19
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %56
19: ; preds = %12, %51
%20 = phi i64 [ 1, %12 ], [ %54, %51 ]
%21 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 32)
%22 = load i64, i64* @AF_UNSPEC
store i64 %22, i64* %13
%23 = load i32, i32* @SOCK_STREAM
store i32 %23, i32* %14
%24 = getelementptr inbounds i8*, i8** %1, i64 %20
%25 = load i8*, i8** %24
%26 = call i32 @getaddrinfo(i8* %25, i32* null, %struct.addrinfo* %3, %struct.addrinfo** %4)
%27 = icmp eq i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %19
%29 = load i32, i32* @stderr
%30 = call i8* @gai_strerror(i32 %26)
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %30)
br label %56
32: ; preds = %19
%33 = load i8*, i8** %24
%34 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load %struct.addrinfo*, %struct.addrinfo** %4
%36 = icmp eq %struct.addrinfo* %35, null
br i1 %36, label %51, label %37
37: ; preds = %32, %37
%38 = phi %struct.addrinfo* [ %47, %37 ], [ %35, %32 ]
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 0
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 1
%41 = load i64, i64* %40
%42 = inttoptr i64 %41 to i8*
%43 = load i64, i64* %39
%44 = call i32 @inet_ntop(i64 %43, i8* %42, i8* %10, i32 %7)
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 2
%47 = load %struct.addrinfo*, %struct.addrinfo** %46
%48 = icmp eq %struct.addrinfo* %47, null
br i1 %48, label %49, label %37
49: ; preds = %37
%50 = load %struct.addrinfo*, %struct.addrinfo** %4
br label %51
51: ; preds = %49, %32
%52 = phi %struct.addrinfo* [ %50, %49 ], [ null, %32 ]
%53 = call i32 @freeaddrinfo(%struct.addrinfo* %52)
%54 = add nuw nsw i64 %20, 1
%55 = icmp eq i64 %54, %15
br i1 %55, label %56, label %19
56: ; preds = %51, %28, %16
%57 = phi i32 [ 1, %16 ], [ 2, %28 ], [ 0, %51 ]
ret i32 %57
}