#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;
  int /*<<< orphan*/ sin6_port;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
};
struct addrinfo {
  scalar_t__ ai_family;
  scalar_t__ ai_socktype;
  char *ai_canonname;
  struct addrinfo *ai_next;
  scalar_t__ ai_addr;
  scalar_t__ ai_flags;
};
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
scalar_t__ AF_INET6;
scalar_t__ AF_UNSPEC;
scalar_t__ SOCK_STREAM;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *gai_strerror(int);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ inet_ntop(scalar_t__, char *, char *, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
int main() {
  struct addrinfo hints, *ai, *aitop;
  int gaierr;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_UNSPEC;
  hints.ai_flags = 0;
  hints.ai_socktype = 0;
  if ((gaierr = getaddrinfo(NULL, "6010", &hints, &aitop)) != 0) {
    printf("error: %.100s\n", gai_strerror(gaierr));
    exit(0);
  }
  ai = aitop;
  while (ai) {
    printf("found host %s, port %d, family %s, socktype %s\n", ai->ai_canonname,
           ntohs(ai->ai_family == AF_INET6
                     ? ((struct sockaddr_in6 *)ai->ai_addr)->sin6_port
                     : ((struct sockaddr_in *)ai->ai_addr)->sin_port),
           ai->ai_family == AF_INET6 ? "PF_INET6" : "PF_INET",
           ai->ai_socktype == SOCK_STREAM ? "SOCK_STREAM" : "SOCK_DGRAM");
    {
      char buf[100];
      inet_ntop(ai->ai_family,
                ai->ai_family == AF_INET6
                    ? (char *)&(((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr)
                    : (char *)&(((struct sockaddr_in *)ai->ai_addr)->sin_addr),
                buf, 100);
      printf("  %s\n", buf);
    }
    ai = ai->ai_next;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1060 <memset@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe45(%rip),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   1090 <getaddrinfo@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0x0,%eax
je     11f4 <main+0x84>
mov    -0x4c(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    %rax,%rsi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1350 <main+0x1e0>
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0xb8(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    0x2dbc(%rip),%rcx
cmp    (%rcx),%rax
jne    1243 <main+0xd3>
mov    -0x40(%rbp),%rax
mov    0x20(%rax),%rax
mov    0x4(%rax),%eax
mov    %eax,-0xbc(%rbp)
jmp    1254 <main+0xe4>
mov    -0x40(%rbp),%rax
mov    0x20(%rax),%rax
mov    0x4(%rax),%eax
mov    %eax,-0xbc(%rbp)
mov    -0xbc(%rbp),%edi
call   1070 <ntohs@plt>
mov    -0xb8(%rbp),%rsi
mov    %eax,%edx
mov    -0x40(%rbp),%rax
mov    (%rax),%rdi
mov    0x2d6a(%rip),%rax
mov    (%rax),%r8
lea    0xdcd(%rip),%rcx
lea    0xdbd(%rip),%rax
cmp    %r8,%rdi
cmove  %rax,%rcx
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d33(%rip),%rax
mov    (%rax),%r9
lea    0xdba(%rip),%r8
lea    0xda7(%rip),%rax
cmp    %r9,%rdi
cmove  %rax,%r8
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xc8(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    0x2d01(%rip),%rcx
cmp    (%rcx),%rax
jne    12fc <main+0x18c>
mov    -0x40(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0xd0(%rbp)
jmp    130b <main+0x19b>
mov    -0x40(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0xd0(%rbp)
mov    -0xc8(%rbp),%rdi
mov    -0xd0(%rbp),%rsi
lea    -0xb0(%rbp),%rdx
mov    $0x64,%ecx
call   1030 <inet_ntop@plt>
lea    -0xb0(%rbp),%rsi
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x40(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    11fc <main+0x8c>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1060 <memset@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
movq   $0x0,0x38(%rsp)
movq   $0x0,0x18(%rsp)
lea    0xe43(%rip),%rsi
lea    0x8(%rsp),%rcx
xor    %edi,%edi
mov    %rbx,%rdx
call   1090 <getaddrinfo@plt>
test   %eax,%eax
jne    129c <main+0x12c>
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     1288 <main+0x118>
lea    0xe78(%rip),%rbp
lea    0xe24(%rip),%r14
lea    0x40(%rsp),%r12
lea    0xe70(%rip),%r15
nopl   0x0(%rax)
mov    0x10(%rbx),%r13
mov    0x20(%rbx),%rax
mov    0x4(%rax),%edi
call   1070 <ntohs@plt>
mov    (%rbx),%rcx
mov    0x8(%rbx),%rdx
mov    0x2dc2(%rip),%rsi
cmp    (%rsi),%rcx
lea    0xe25(%rip),%rcx
lea    0xe15(%rip),%rsi
cmove  %rsi,%rcx
mov    0x2d96(%rip),%rsi
cmp    (%rsi),%rdx
mov    %rbp,%r8
lea    0xe0e(%rip),%rdx
cmove  %rdx,%r8
mov    %r14,%rdi
mov    %r13,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rdi
mov    0x20(%rbx),%rsi
mov    %r12,%rdx
mov    $0x64,%ecx
call   1030 <inet_ntop@plt>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
jne    1200 <main+0x90>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xd5b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i64, i64, i8*, %struct.addrinfo*, i64, i64 }
%struct.sockaddr_in6 = type { i32, i32 }
%struct.sockaddr_in = type { i32, i32 }
@AF_UNSPEC = global i64 0
@.str = [5 x i8] c"6010\00"
@.str.1 = [15 x i8] c"error: %.100s\0A\00"
@.str.2 = [48 x i8] c"found host %s, port %d, family %s, socktype %s\0A\00"
@AF_INET6 = global i64 0
@.str.3 = [9 x i8] c"PF_INET6\00"
@.str.4 = [8 x i8] c"PF_INET\00"
@SOCK_STREAM = global i64 0
@.str.5 = [12 x i8] c"SOCK_STREAM\00"
@.str.6 = [11 x i8] c"SOCK_DGRAM\00"
@.str.7 = [6 x i8] c" %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.addrinfo
%3 = alloca %struct.addrinfo*
%4 = alloca %struct.addrinfo*
%5 = alloca i32
%6 = alloca [100 x i8]
store i32 0, i32* %1
%7 = call i32 @memset(%struct.addrinfo* %2, i32 0, i32 48)
%8 = load i64, i64* @AF_UNSPEC
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 0
store i64 %8, i64* %9
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 5
store i64 0, i64* %10
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 1
store i64 0, i64* %11
%12 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %2, %struct.addrinfo** %4)
store i32 %12, i32* %5
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %0
%15 = load i32, i32* %5
%16 = call i8* @gai_strerror(i32 %15)
%17 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %0
%20 = load %struct.addrinfo*, %struct.addrinfo** %4
store %struct.addrinfo* %20, %struct.addrinfo** %3
br label %21
21: ; preds = %87, %19
%22 = load %struct.addrinfo*, %struct.addrinfo** %3
%23 = icmp ne %struct.addrinfo* %22, null
br i1 %23, label %24, label %96
24: ; preds = %21
%25 = load %struct.addrinfo*, %struct.addrinfo** %3
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i32 0, i32 2
%27 = load i8*, i8** %26
%28 = load %struct.addrinfo*, %struct.addrinfo** %3
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i32 0, i32 0
%30 = load i64, i64* %29
%31 = load i64, i64* @AF_INET6
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %40
33: ; preds = %24
%34 = load %struct.addrinfo*, %struct.addrinfo** %3
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i32 0, i32 4
%36 = load i64, i64* %35
%37 = inttoptr i64 %36 to %struct.sockaddr_in6*
%38 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %37, i32 0, i32 1
%39 = load i32, i32* %38
br label %47
40: ; preds = %24
%41 = load %struct.addrinfo*, %struct.addrinfo** %3
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i32 0, i32 4
%43 = load i64, i64* %42
%44 = inttoptr i64 %43 to %struct.sockaddr_in*
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %44, i32 0, i32 1
%46 = load i32, i32* %45
br label %47
47: ; preds = %40, %33
%48 = phi i32 [ %39, %33 ], [ %46, %40 ]
%49 = call i32 @ntohs(i32 %48)
%50 = load %struct.addrinfo*, %struct.addrinfo** %3
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 0
%52 = load i64, i64* %51
%53 = load i64, i64* @AF_INET6
%54 = icmp eq i64 %52, %53
%55 = zext i1 %54 to i64
%56 = select i1 %54, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0)
%57 = load %struct.addrinfo*, %struct.addrinfo** %3
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i32 0, i32 1
%59 = load i64, i64* %58
%60 = load i64, i64* @SOCK_STREAM
%61 = icmp eq i64 %59, %60
%62 = zext i1 %61 to i64
%63 = select i1 %61, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0)
%64 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* %27, i32 %49, i8* %56, i8* %63)
%65 = load %struct.addrinfo*, %struct.addrinfo** %3
%66 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i32 0, i32 0
%67 = load i64, i64* %66
%68 = load %struct.addrinfo*, %struct.addrinfo** %3
%69 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %68, i32 0, i32 0
%70 = load i64, i64* %69
%71 = load i64, i64* @AF_INET6
%72 = icmp eq i64 %70, %71
br i1 %72, label %73, label %80
73: ; preds = %47
%74 = load %struct.addrinfo*, %struct.addrinfo** %3
%75 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %74, i32 0, i32 4
%76 = load i64, i64* %75
%77 = inttoptr i64 %76 to %struct.sockaddr_in6*
%78 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %77, i32 0, i32 0
%79 = bitcast i32* %78 to i8*
br label %87
80: ; preds = %47
%81 = load %struct.addrinfo*, %struct.addrinfo** %3
%82 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %81, i32 0, i32 4
%83 = load i64, i64* %82
%84 = inttoptr i64 %83 to %struct.sockaddr_in*
%85 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %84, i32 0, i32 0
%86 = bitcast i32* %85 to i8*
br label %87
87: ; preds = %80, %73
%88 = phi i8* [ %79, %73 ], [ %86, %80 ]
%89 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%90 = call i32 @inet_ntop(i64 %67, i8* %88, i8* %89, i32 100)
%91 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%92 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* %91)
%93 = load %struct.addrinfo*, %struct.addrinfo** %3
%94 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %93, i32 0, i32 3
%95 = load %struct.addrinfo*, %struct.addrinfo** %94
store %struct.addrinfo* %95, %struct.addrinfo** %3
br label %21
96: ; preds = %21
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i64, i8*, %struct.addrinfo*, i64, i64 }
%struct.sockaddr_in6 = type { i32, i32 }
%struct.sockaddr_in = type { i32, i32 }
@AF_UNSPEC = global i64 0
@.str = [5 x i8] c"6010\00"
@.str.1 = [15 x i8] c"error: %.100s\0A\00"
@.str.2 = [48 x i8] c"found host %s, port %d, family %s, socktype %s\0A\00"
@AF_INET6 = global i64 0
@.str.3 = [9 x i8] c"PF_INET6\00"
@.str.4 = [8 x i8] c"PF_INET\00"
@SOCK_STREAM = global i64 0
@.str.5 = [12 x i8] c"SOCK_STREAM\00"
@.str.6 = [11 x i8] c"SOCK_DGRAM\00"
@.str.7 = [6 x i8] c" %s\0A\00"
define i32 @main() {
%1 = alloca %struct.addrinfo
%2 = alloca %struct.addrinfo*
%3 = alloca [100 x i8]
%4 = bitcast %struct.addrinfo* %1 to i8*
%5 = bitcast %struct.addrinfo** %2 to i8*
%6 = call i32 @memset(%struct.addrinfo* %1, i32 0, i32 48)
%7 = load i64, i64* @AF_UNSPEC
%8 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 0
store i64 %7, i64* %8
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 5
store i64 0, i64* %9
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 1
store i64 0, i64* %10
%11 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %1, %struct.addrinfo** %2)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %0
%14 = load %struct.addrinfo*, %struct.addrinfo** %2
%15 = icmp eq %struct.addrinfo* %14, null
br i1 %15, label %58, label %16
16: ; preds = %13
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
br label %22
18: ; preds = %0
%19 = call i8* @gai_strerror(i32 %11)
%20 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %16, %22
%23 = phi %struct.addrinfo* [ %14, %16 ], [ %56, %22 ]
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 2
%25 = load i8*, i8** %24
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 0
%27 = load i64, i64* %26
%28 = load i64, i64* @AF_INET6
%29 = icmp eq i64 %27, %28
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 4
%31 = load i64, i64* %30
%32 = inttoptr i64 %31 to %struct.sockaddr_in6*
%33 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %32, i64 0, i32 1
%34 = inttoptr i64 %31 to %struct.sockaddr_in*
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %34, i64 0, i32 1
%36 = select i1 %29, i32* %33, i32* %35
%37 = load i32, i32* %36
%38 = call i32 @ntohs(i32 %37)
%39 = load i64, i64* %26
%40 = load i64, i64* @AF_INET6
%41 = icmp eq i64 %39, %40
%42 = select i1 %41, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0)
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 1
%44 = load i64, i64* %43
%45 = load i64, i64* @SOCK_STREAM
%46 = icmp eq i64 %44, %45
%47 = select i1 %46, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0)
%48 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* %25, i32 %38, i8* %42, i8* %47)
%49 = load i64, i64* %26
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 4
%51 = load i64, i64* %50
%52 = inttoptr i64 %51 to i8*
%53 = call i32 @inet_ntop(i64 %49, i8* %52, i8* %17, i32 100)
%54 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* %17)
%55 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 3
%56 = load %struct.addrinfo*, %struct.addrinfo** %55
%57 = icmp eq %struct.addrinfo* %56, null
br i1 %57, label %58, label %22
58: ; preds = %22, %13
ret i32 0
}