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

/* Variables and functions */
int NI_MAXHOST;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char const *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                struct addrinfo **);
int getnameinfo(int /*<<< orphan*/, int /*<<< orphan*/, char *, int,
                int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int domain2IpRange(const char *domain) {
  struct addrinfo *result;
  struct addrinfo *res;
  int status;
  char *hostname = malloc(sizeof(char) * NI_MAXHOST);
  status = getaddrinfo(domain, NULL, NULL, &result);
  if (status != 0) {
    fprintf(stderr, "getaddrinfo() error: %s\n", gai_strerror(status));
    if (hostname)
      free(hostname);
    return -1;
  }
  for (res = result; res != NULL; res = res->ai_next) {
    hostname = "";
    status = getnameinfo(res->ai_addr, res->ai_addrlen, hostname, NI_MAXHOST,
                         NULL, 0, 0);
    if (status != 0) {
      fprintf(stderr, "getnameinfo() error: %s\n", gai_strerror(status));
      continue;
    }
    if (hostname) {
      printf("hostname: %s\n", hostname);
    }
  }
  if (hostname)
    free(hostname);
  if (result)
    freeaddrinfo(result);
  return 0;
}


x86 assembly (clang, -O0):
<domain2IpRange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e45(%rip),%rax
movslq (%rax),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x18(%rbp),%rcx
mov    %rdx,%rsi
call   1090 <getaddrinfo@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     120c <domain2IpRange+0x8c>
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xe19(%rip),%rsi
call   1070 <fprintf@plt>
cmpq   $0x0,-0x30(%rbp)
je     1200 <domain2IpRange+0x80>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f0 <domain2IpRange+0x170>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12c1 <domain2IpRange+0x141>
lea    0xe19(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
mov    -0x30(%rbp),%rdx
mov    0x2d96(%rip),%rax
mov    (%rax),%ecx
xor    %eax,%eax
mov    %eax,%r8d
xor    %r9d,%r9d
movl   $0x0,(%rsp)
call   1060 <getnameinfo@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1290 <domain2IpRange+0x110>
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xd93(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12b0 <domain2IpRange+0x130>
cmpq   $0x0,-0x30(%rbp)
je     12ab <domain2IpRange+0x12b>
mov    -0x30(%rbp),%rsi
lea    0xd8c(%rip),%rdi
call   1040 <printf@plt>
jmp    12b0 <domain2IpRange+0x130>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1214 <domain2IpRange+0x94>
cmpq   $0x0,-0x30(%rbp)
je     12d5 <domain2IpRange+0x155>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x18(%rbp)
je     12e9 <domain2IpRange+0x169>
mov    -0x18(%rbp),%rdi
call   10a0 <freeaddrinfo@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<domain2IpRange>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbp
mov    0x2e40(%rip),%r12
mov    (%r12),%edi
call   1080 <malloc@plt>
mov    %rax,%r13
lea    0x10(%rsp),%rcx
mov    %rbp,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <getaddrinfo@plt>
test   %eax,%eax
je     11f5 <domain2IpRange+0x75>
mov    0x2e20(%rip),%rcx
mov    (%rcx),%ebp
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xe30(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebp
test   %r13,%r13
je     1295 <domain2IpRange+0x115>
mov    %r13,%rdi
call   1030 <free@plt>
jmp    1295 <domain2IpRange+0x115>
mov    0x10(%rsp),%rbx
test   %rbx,%rbx
je     1273 <domain2IpRange+0xf3>
lea    0xe39(%rip),%r13
mov    0x2dd3(%rip),%r14
lea    0xe05(%rip),%r15
jmp    1240 <domain2IpRange+0xc0>
cs nopw 0x0(%rax,%rax,1)
mov    (%r14),%ebp
mov    %eax,%edi
call   1050 <gai_strerror@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    0x8(%rbx),%rbx
test   %rbx,%rbx
je     1278 <domain2IpRange+0xf8>
mov    (%rbx),%esi
mov    0x4(%rbx),%edi
mov    (%r12),%ecx
movl   $0x0,(%rsp)
mov    %r13,%rdx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1060 <getnameinfo@plt>
test   %eax,%eax
jne    1220 <domain2IpRange+0xa0>
lea    0xdc9(%rip),%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
jmp    1237 <domain2IpRange+0xb7>
test   %r13,%r13
je     1293 <domain2IpRange+0x113>
mov    %r13,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
xor    %ebp,%ebp
test   %rdi,%rdi
je     1295 <domain2IpRange+0x115>
call   10a0 <freeaddrinfo@plt>
jmp    1295 <domain2IpRange+0x115>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, %struct.addrinfo* }
@NI_MAXHOST = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"getaddrinfo() error: %s\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [25 x i8] c"getnameinfo() error: %s\0A\00"
@.str.3 = [14 x i8] c"hostname: %s\0A\00"
define i32 @domain2IpRange(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.addrinfo*
%5 = alloca %struct.addrinfo*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
%8 = load i32, i32* @NI_MAXHOST
%9 = sext i32 %8 to i64
%10 = mul i64 1, %9
%11 = trunc i64 %10 to i32
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %7
%13 = load i8*, i8** %3
%14 = call i32 @getaddrinfo(i8* %13, i32* null, i32* null, %struct.addrinfo** %4)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %1
%18 = load i32, i32* @stderr
%19 = load i32, i32* %6
%20 = call i8* @gai_strerror(i32 %19)
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %7
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = load i8*, i8** %7
%26 = call i32 @free(i8* %25)
br label %27
27: ; preds = %24, %17
store i32 -1, i32* %2
br label %74
28: ; preds = %1
%29 = load %struct.addrinfo*, %struct.addrinfo** %4
store %struct.addrinfo* %29, %struct.addrinfo** %5
br label %30
30: ; preds = %57, %28
%31 = load %struct.addrinfo*, %struct.addrinfo** %5
%32 = icmp ne %struct.addrinfo* %31, null
br i1 %32, label %33, label %61
33: ; preds = %30
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %7
%34 = load %struct.addrinfo*, %struct.addrinfo** %5
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i32 0, i32 1
%36 = load i32, i32* %35
%37 = load %struct.addrinfo*, %struct.addrinfo** %5
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i32 0, i32 0
%39 = load i32, i32* %38
%40 = load i8*, i8** %7
%41 = load i32, i32* @NI_MAXHOST
%42 = call i32 @getnameinfo(i32 %36, i32 %39, i8* %40, i32 %41, i32* null, i32 0, i32 0)
store i32 %42, i32* %6
%43 = load i32, i32* %6
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %33
%46 = load i32, i32* @stderr
%47 = load i32, i32* %6
%48 = call i8* @gai_strerror(i32 %47)
%49 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %48)
br label %57
50: ; preds = %33
%51 = load i8*, i8** %7
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i8*, i8** %7
%55 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %53, %50
br label %57
57: ; preds = %56, %45
%58 = load %struct.addrinfo*, %struct.addrinfo** %5
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %58, i32 0, i32 2
%60 = load %struct.addrinfo*, %struct.addrinfo** %59
store %struct.addrinfo* %60, %struct.addrinfo** %5
br label %30
61: ; preds = %30
%62 = load i8*, i8** %7
%63 = icmp ne i8* %62, null
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i8*, i8** %7
%66 = call i32 @free(i8* %65)
br label %67
67: ; preds = %64, %61
%68 = load %struct.addrinfo*, %struct.addrinfo** %4
%69 = icmp ne %struct.addrinfo* %68, null
br i1 %69, label %70, label %73
70: ; preds = %67
%71 = load %struct.addrinfo*, %struct.addrinfo** %4
%72 = call i32 @freeaddrinfo(%struct.addrinfo* %71)
br label %73
73: ; preds = %70, %67
store i32 0, i32* %2
br label %74
74: ; preds = %73, %27
%75 = load i32, i32* %2
ret i32 %75
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, %struct.addrinfo* }
@NI_MAXHOST = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"getaddrinfo() error: %s\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [25 x i8] c"getnameinfo() error: %s\0A\00"
@.str.3 = [14 x i8] c"hostname: %s\0A\00"
define i32 @domain2IpRange(i8* %0) {
%2 = alloca %struct.addrinfo*
%3 = bitcast %struct.addrinfo** %2 to i8*
%4 = load i32, i32* @NI_MAXHOST
%5 = tail call i8* @malloc(i32 %4)
%6 = call i32 @getaddrinfo(i8* %0, i32* null, i32* null, %struct.addrinfo** %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load %struct.addrinfo*, %struct.addrinfo** %2
%10 = icmp eq %struct.addrinfo* %9, null
br i1 %10, label %37, label %18
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i8* @gai_strerror(i32 %6)
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = icmp eq i8* %5, null
br i1 %15, label %46, label %16
16: ; preds = %11
%17 = call i32 @free(i8* %5)
br label %46
18: ; preds = %8, %33
%19 = phi %struct.addrinfo* [ %35, %33 ], [ %9, %8 ]
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 1
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 0
%23 = load i32, i32* %22
%24 = load i32, i32* @NI_MAXHOST
%25 = call i32 @getnameinfo(i32 %21, i32 %23, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32* null, i32 0, i32 0)
%26 = icmp eq i32 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %18
%28 = load i32, i32* @stderr
%29 = call i8* @gai_strerror(i32 %25)
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %33
31: ; preds = %18
%32 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 2
%35 = load %struct.addrinfo*, %struct.addrinfo** %34
%36 = icmp eq %struct.addrinfo* %35, null
br i1 %36, label %39, label %18
37: ; preds = %8
%38 = icmp eq i8* %5, null
br i1 %38, label %46, label %39
39: ; preds = %33, %37
%40 = phi i8* [ %5, %37 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %33 ]
%41 = call i32 @free(i8* %40)
%42 = load %struct.addrinfo*, %struct.addrinfo** %2
%43 = icmp eq %struct.addrinfo* %42, null
br i1 %43, label %46, label %44
44: ; preds = %39
%45 = call i32 @freeaddrinfo(%struct.addrinfo* %42)
br label %46
46: ; preds = %37, %39, %44, %11, %16
%47 = phi i32 [ -1, %16 ], [ -1, %11 ], [ 0, %44 ], [ 0, %39 ], [ 0, %37 ]
ret i32 %47
}