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

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_UNSPEC;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char *, char *, 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) {
  int status;
  struct addrinfo *addr, *p;
  struct addrinfo hint;
  char ipstr[INET6_ADDRSTRLEN];
  if (argc != 2) {
    fprintf(stderr, "usage: showip <hostname>\n");
    exit(1);
  }
  memset(&hint, 0, sizeof(struct addrinfo));
  hint.ai_family = AF_UNSPEC;
  hint.ai_socktype = SOCK_STREAM;
  if (status = getaddrinfo(argv[1], "http", &hint, &addr)) {
    fprintf(stderr, "[Error]%s\n", gai_strerror(status));
    exit(1);
  }
  printf("IP addresses for %s:\n\n", argv[1]);
  for (p = addr; p != NULL; p = p->ai_next) {
    void *addr;
    char *ipver;
    if (p->ai_family == AF_INET) {
      struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
      addr = &(ipv4->sin_addr);
      ipver = "IPv4";
    } else {
      struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
      addr = &(ipv6->sin6_addr);
      ipver = "IPv6";
    }
    inet_ntop(p->ai_family, addr, ipstr, sizeof(ipstr));
    printf("  %s: %s\n", ipver, ipstr);
  }
  freeaddrinfo(addr);
  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    0x2e48(%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)
je     11f7 <main+0x77>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdea(%rip),%rsi
lea    -0x48(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1090 <getaddrinfo@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     1281 <main+0x101>
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x8c(%rbp),%edi
mov    %rax,%rdx
lea    0xdaf(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1348 <main+0x1c8>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2d28(%rip),%rcx
cmp    (%rcx),%rax
jne    12e5 <main+0x165>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    0xd65(%rip),%rax
mov    %rax,-0x68(%rbp)
jmp    1304 <main+0x184>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    0xd46(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    -0x80(%rbp),%rdx
mov    -0x88(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rcx),%rdi
mov    -0x60(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x80(%rbp),%rdx
mov    -0x68(%rbp),%rsi
lea    0xd1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    129f <main+0x11f>
mov    -0x20(%rbp),%rdi
call   10a0 <freeaddrinfo@plt>
movl   $0x0,-0x4(%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    $0x38,%rsp
mov    %rsp,%rcx
mov    0x2e4d(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r13
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
cmp    $0x2,%edi
jne    1298 <main+0x118>
mov    %rsi,%r15
mov    %rcx,-0x38(%rbp)
lea    -0x58(%rbp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x8(%r15),%rdi
lea    0xe23(%rip),%rsi
lea    -0x30(%rbp),%rcx
mov    %r12,%rdx
call   1090 <getaddrinfo@plt>
test   %eax,%eax
jne    12b9 <main+0x139>
mov    0x8(%r15),%rsi
lea    0xe14(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x30(%rbp),%rbx
test   %rbx,%rbx
je     127b <main+0xfb>
lea    0xe1b(%rip),%r15
mov    (%rbx),%rdi
mov    0x8(%rbx),%rsi
mov    0x2da2(%rip),%rax
cmp    (%rax),%rdi
lea    0xdfe(%rip),%r12
lea    0xdf2(%rip),%rax
cmove  %rax,%r12
mov    %r13,%rdx
mov    %r14d,%ecx
call   1030 <inet_ntop@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%rbx
test   %rbx,%rbx
jne    1230 <main+0xb0>
mov    -0x30(%rbp),%r15
mov    %r15,%rdi
call   10a0 <freeaddrinfo@plt>
mov    -0x38(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
lea    0xd58(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2d08(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xd4f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

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