#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;
  int ai_protocol;
  scalar_t__ ai_addr;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_flags;
  int /*<<< orphan*/ ai_socktype;
};
typedef int /*<<< orphan*/ ipstr;

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(int /*<<< orphan*/ *, 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];
  memset(&hint, 0, sizeof(struct addrinfo));
  hint.ai_family = AF_UNSPEC;
  hint.ai_socktype = SOCK_STREAM;
  hint.ai_flags = AI_PASSIVE;
  if (status = getaddrinfo(NULL, "http", &hint, &addr)) {
    fprintf(stderr, "[Error]%s\n", gai_strerror(status));
    exit(1);
  }
  printf("IP addresses for %s:\n\n", "localhost");
  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 | protocol: %d\n", ipver, ipstr, p->ai_protocol);
  }
  freeaddrinfo(addr);
  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)
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x90(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x58(%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,-0x60(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdf0(%rip),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1090 <getaddrinfo@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     125f <main+0xdf>
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x94(%rbp),%edi
mov    %rax,%rdx
lea    0xdb5(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xdaa(%rip),%rdi
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1332 <main+0x1b2>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2d43(%rip),%rcx
cmp    (%rcx),%rax
jne    12c2 <main+0x142>
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    0xd78(%rip),%rax
mov    %rax,-0x70(%rbp)
jmp    12e1 <main+0x161>
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    0xd59(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    -0x88(%rbp),%rdx
mov    -0x90(%rbp),%rax
mov    -0x28(%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
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%ecx
lea    0xd21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    127c <main+0xfc>
mov    -0x20(%rbp),%rdi
call   10a0 <freeaddrinfo@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x58(%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,%rbx
mov    0x2e4d(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r12
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    -0x60(%rbp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
lea    0xe11(%rip),%rsi
lea    -0x30(%rbp),%rcx
xor    %edi,%edi
mov    %r15,%rdx
call   1090 <getaddrinfo@plt>
test   %eax,%eax
jne    12b0 <main+0x130>
lea    0xe04(%rip),%rdi
lea    0xe14(%rip),%rsi
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x30(%rbp),%r13
test   %r13,%r13
je     1294 <main+0x114>
mov    %rbx,-0x38(%rbp)
lea    0xe0a(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%rdi
mov    0x10(%r13),%rsi
mov    0x2d89(%rip),%rax
cmp    (%rax),%rdi
lea    0xddd(%rip),%rbx
lea    0xdd1(%rip),%rax
cmove  %rax,%rbx
mov    %r12,%rdx
mov    %r14d,%ecx
call   1030 <inet_ntop@plt>
mov    0x8(%r13),%ecx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%r13),%r13
test   %r13,%r13
jne    1240 <main+0xc0>
mov    -0x30(%rbp),%r15
mov    -0x38(%rbp),%rbx
mov    %r15,%rdi
call   10a0 <freeaddrinfo@plt>
mov    %rbx,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d09(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xd3e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

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