#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 socket_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct socket_in {
  int /*<<< orphan*/ sin_addr;
};
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;
typedef int /*<<< orphan*/ hints;

/* 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 const *, 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 const *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char const *argv[]) {
  if (argc != 2) {
    fprintf(stderr, "Usage: showip <hostname>\n");
    return 1;
  }
  struct addrinfo hints, *res, *it_res;
  int status;
  char ipstr[INET6_ADDRSTRLEN];
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  if ((status = getaddrinfo(argv[1], NULL, &hints, &res)) != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
    return 2;
  }
  printf("IP addesses for %s:\n\n", argv[1]);
  for (it_res = res; it_res != NULL; it_res = it_res->ai_next) {
    void *addr;
    char *ipver;
    if (it_res->ai_family == AF_INET) {
      struct sockaddr_in *ipv4_addr = (struct socket_in *)it_res->ai_addr;
      addr = &(ipv4_addr->sin_addr);
      ipver = "IPv4";
    } else {
      struct sockaddr_in6 *ipv6_addr = (struct socket_in6 *)it_res->ai_addr;
      addr = &(ipv6_addr->sin6_addr);
      ipver = "IPv6";
    }
    inet_ntop(it_res->ai_family, addr, ipstr, sizeof(ipstr));
    printf("\t%s: %s\n", ipver, ipstr);
  }
  freeaddrinfo(res);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b6 <main+0x46>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1367 <main+0x1f7>
mov    0x2e2b(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x90(%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,-0x88(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x58(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%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     127c <main+0x10c>
mov    0x2d86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    -0x44(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x94(%rbp),%edi
mov    %rax,%rdx
lea    0xdb8(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    1360 <main+0x1f0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xda0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1349 <main+0x1d9>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    0x2d2d(%rip),%rcx
cmp    (%rcx),%rax
jne    12e0 <main+0x170>
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    0xd6a(%rip),%rax
mov    %rax,-0x70(%rbp)
jmp    12ff <main+0x18f>
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    0xd4b(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    -0x88(%rbp),%rdx
mov    -0x90(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    (%rcx),%rdi
mov    -0x68(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x88(%rbp),%rdx
mov    -0x70(%rbp),%rsi
lea    0xd1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    129a <main+0x12a>
mov    -0x38(%rbp),%rdi
call   1090 <freeaddrinfo@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x5c(%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
cmp    $0x2,%edi
jne    121b <main+0xab>
mov    %rsi,%r15
mov    %rsp,%r12
mov    0x2e51(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r13
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    -0x58(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x8(%r15),%rdi
lea    -0x30(%rbp),%rcx
xor    %esi,%esi
mov    %rbx,%rdx
call   1080 <getaddrinfo@plt>
test   %eax,%eax
je     123c <main+0xcc>
mov    0x2dd3(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xe15(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x2,%ebx
jmp    12ca <main+0x15a>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%ebx
jmp    12cd <main+0x15d>
mov    0x8(%r15),%rsi
lea    0xde4(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x30(%rbp),%r15
test   %r15,%r15
je     12c3 <main+0x153>
mov    %r12,-0x38(%rbp)
lea    0xde7(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15),%rdi
mov    0x8(%r15),%rsi
mov    0x2d62(%rip),%rax
cmp    (%rax),%rdi
lea    0xdbe(%rip),%rbx
lea    0xdb2(%rip),%rax
cmove  %rax,%rbx
mov    %r13,%rdx
mov    %r14d,%ecx
call   1030 <inet_ntop@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r15),%r15
test   %r15,%r15
jne    1270 <main+0x100>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%r12
xor    %ebx,%ebx
jmp    12c5 <main+0x155>
xor    %edi,%edi
call   1090 <freeaddrinfo@plt>
mov    %r12,%rsp
mov    %ebx,%eax
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 }
%struct.socket_in = type { i32 }
%struct.socket_in6 = type { i32 }
@stderr = global i32 0
@.str = [26 x i8] c"Usage: showip <hostname>\0A\00"
@INET6_ADDRSTRLEN = global i32 0
@AF_UNSPEC = global i64 0
@SOCK_STREAM = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [22 x i8] c"IP addesses for %s:\0A\0A\00"
@AF_INET = global i64 0
@.str.3 = [5 x i8] c"IPv4\00"
@.str.4 = [5 x i8] c"IPv6\00"
@.str.5 = [9 x i8] c"\09%s: %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 i8*
%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* %4
%18 = icmp ne i32 %17, 2
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %93
22: ; preds = %2
%23 = load i32, i32* @INET6_ADDRSTRLEN
%24 = zext i32 %23 to i64
%25 = call i8* @llvm.stacksave()
store i8* %25, i8** %10
%26 = alloca i8, i64 %24
store i64 %24, i64* %11
%27 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 32)
%28 = load i64, i64* @AF_UNSPEC
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 0
store i64 %28, i64* %29
%30 = load i32, i32* @SOCK_STREAM
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, 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, i32* null, %struct.addrinfo* %6, %struct.addrinfo** %7)
store i32 %35, i32* %9
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %22
%38 = load i32, i32* @stderr
%39 = load i32, i32* %9
%40 = call i8* @gai_strerror(i32 %39)
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %40)
store i32 2, i32* %3
store i32 1, i32* %12
br label %91
42: ; preds = %22
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %45)
%47 = load %struct.addrinfo*, %struct.addrinfo** %7
store %struct.addrinfo* %47, %struct.addrinfo** %8
br label %48
48: ; preds = %84, %42
%49 = load %struct.addrinfo*, %struct.addrinfo** %8
%50 = icmp ne %struct.addrinfo* %49, null
br i1 %50, label %51, label %88
51: ; preds = %48
%52 = load %struct.addrinfo*, %struct.addrinfo** %8
%53 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %52, i32 0, i32 0
%54 = load i64, i64* %53
%55 = load i64, i64* @AF_INET
%56 = icmp eq i64 %54, %55
br i1 %56, label %57, label %66
57: ; preds = %51
%58 = load %struct.addrinfo*, %struct.addrinfo** %8
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %58, i32 0, i32 1
%60 = load i64, i64* %59
%61 = inttoptr i64 %60 to %struct.socket_in*
%62 = bitcast %struct.socket_in* %61 to %struct.sockaddr_in*
store %struct.sockaddr_in* %62, %struct.sockaddr_in** %15
%63 = load %struct.sockaddr_in*, %struct.sockaddr_in** %15
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %63, i32 0, i32 0
%65 = bitcast i32* %64 to i8*
store i8* %65, i8** %13
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %14
br label %75
66: ; preds = %51
%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.socket_in6*
%71 = bitcast %struct.socket_in6* %70 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %71, %struct.sockaddr_in6** %16
%72 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %16
%73 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %72, i32 0, i32 0
%74 = bitcast i32* %73 to i8*
store i8* %74, i8** %13
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %14
br label %75
75: ; preds = %66, %57
%76 = load %struct.addrinfo*, %struct.addrinfo** %8
%77 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %76, i32 0, i32 0
%78 = load i64, i64* %77
%79 = load i8*, i8** %13
%80 = trunc i64 %24 to i32
%81 = call i32 @inet_ntop(i64 %78, i8* %79, i8* %26, i32 %80)
%82 = load i8*, i8** %14
%83 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %82, i8* %26)
br label %84
84: ; preds = %75
%85 = load %struct.addrinfo*, %struct.addrinfo** %8
%86 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %85, i32 0, i32 2
%87 = load %struct.addrinfo*, %struct.addrinfo** %86
store %struct.addrinfo* %87, %struct.addrinfo** %8
br label %48
88: ; preds = %48
%89 = load %struct.addrinfo*, %struct.addrinfo** %7
%90 = call i32 @freeaddrinfo(%struct.addrinfo* %89)
store i32 0, i32* %3
store i32 1, i32* %12
br label %91
91: ; preds = %88, %37
%92 = load i8*, i8** %10
br label %93
93: ; preds = %91, %19
%94 = load i32, i32* %3
ret i32 %94
}

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