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

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ EXIT_FAILURE;
int NI_MAXHOST;
int /*<<< orphan*/ NI_NUMERICHOST;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
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 getnameinfo(int /*<<< orphan*/, int /*<<< orphan*/, char *, int,
                int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(void) {
  struct addrinfo hints, *res;
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE;
  int status = getaddrinfo(NULL, "2222", &hints, &res);
  if (status != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
    exit(EXIT_FAILURE);
  }
  printf("IP addresses for a socket we are listening on:\n\n");
  for (struct addrinfo *p = res; p != NULL; p = p->ai_next) {
    char *ipver = NULL;
    if (p->ai_family == AF_INET)
      ipver = "IPv4";
    else if (p->ai_family == AF_INET6)
      ipver = "IPv6";
    else
      ipver = "IPv?";
    char buffer[NI_MAXHOST];
    int err = getnameinfo(p->ai_addr, p->ai_addrlen, buffer, NI_MAXHOST, NULL,
                          0, NI_NUMERICHOST);
    if (err != 0)
      fprintf(stderr, "Error in getnameinfo: %s\n", gai_strerror(err));
    else
      printf("  %s: %s\n", ipver, buffer);
  }
  freeaddrinfo(res);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe30(%rip),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1090 <getaddrinfo@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     121e <main+0x9e>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    -0x60(%rbp),%edi
mov    %rax,%rdx
lea    0xdfa(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     136d <main+0x1ed>
movq   $0x0,-0x48(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    0x2d8b(%rip),%rcx
cmp    (%rcx),%rax
jne    126e <main+0xee>
lea    0xde2(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    12a5 <main+0x125>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    0x2d5c(%rip),%rcx
cmp    (%rcx),%rax
jne    1295 <main+0x115>
lea    0xdc0(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    12a0 <main+0x120>
lea    0xdb5(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    12a5 <main+0x125>
mov    0x2cfc(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x68(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x58(%rbp)
mov    -0x40(%rbp),%rax
mov    0xc(%rax),%edi
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%esi
mov    0x2cc2(%rip),%rax
mov    (%rax),%ecx
mov    0x2cc9(%rip),%rax
mov    (%rax),%eax
xor    %r8d,%r8d
xor    %r9d,%r9d
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1060 <getnameinfo@plt>
add    $0x10,%rsp
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     133f <main+0x1bf>
mov    0x2cad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x5c(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    -0x6c(%rbp),%edi
mov    %rax,%rdx
lea    0xd21(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1355 <main+0x1d5>
mov    -0x68(%rbp),%rdx
mov    -0x48(%rbp),%rsi
lea    0xd22(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x50(%rbp),%rax
mov    %rax,%rsp
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    1234 <main+0xb4>
mov    -0x30(%rbp),%rdi
call   10a0 <freeaddrinfo@plt>
xor    %eax,%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
lea    -0x58(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
lea    0xe1f(%rip),%rsi
lea    -0x30(%rbp),%rcx
xor    %edi,%edi
mov    %rbx,%rdx
call   10a0 <getaddrinfo@plt>
test   %eax,%eax
jne    130d <main+0x17d>
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
mov    -0x30(%rbp),%r13
test   %r13,%r13
jne    1265 <main+0xd5>
xor    %edi,%edi
jmp    12f7 <main+0x167>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    %r14,%r12
lea    0xdf6(%rip),%rsi
lea    0xdea(%rip),%rax
cmove  %rax,%rsi
cmp    %r15,%r12
lea    0xdd7(%rip),%rax
cmove  %rax,%rsi
lea    0xdf5(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x38(%rbp),%rsp
mov    0x10(%r13),%r13
test   %r13,%r13
je     12f3 <main+0x163>
mov    %rsp,-0x38(%rbp)
mov    0x0(%r13),%r12
mov    0x2d6c(%rip),%rax
mov    (%rax),%r15
mov    0x2d5a(%rip),%rax
mov    (%rax),%r14
mov    0x2d20(%rip),%rcx
mov    (%rcx),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x8(%r13),%esi
mov    0xc(%r13),%edi
mov    (%rcx),%ecx
mov    0x2d0c(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
mov    %rbx,%rdx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   %rax
call   1070 <getnameinfo@plt>
add    $0x10,%rsp
test   %eax,%eax
je     1220 <main+0x90>
mov    0x2cf4(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1050 <gai_strerror@plt>
mov    %ebx,%edi
lea    0xd3f(%rip),%rsi
mov    %rax,%rdx
call   1080 <fprintf@plt>
jmp    1254 <main+0xc4>
mov    -0x30(%rbp),%rdi
call   10b0 <freeaddrinfo@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cb4(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xce1(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    0x2c7b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i64, i32, i32, %struct.addrinfo*, i32, i32 }
@AF_INET = global i64 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [5 x i8] c"2222\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [49 x i8] c"IP addresses for a socket we are listening on:\0A\0A\00"
@.str.3 = [5 x i8] c"IPv4\00"
@AF_INET6 = global i64 0
@.str.4 = [5 x i8] c"IPv6\00"
@.str.5 = [5 x i8] c"IPv?\00"
@NI_MAXHOST = global i32 0
@NI_NUMERICHOST = global i32 0
@.str.6 = [26 x i8] c"Error in getnameinfo: %s\0A\00"
@.str.7 = [10 x i8] c" %s: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.addrinfo
%3 = alloca %struct.addrinfo*
%4 = alloca i32
%5 = alloca %struct.addrinfo*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 @memset(%struct.addrinfo* %2, i32 0, i32 32)
%11 = load i64, i64* @AF_INET
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 0
store i64 %11, i64* %12
%13 = load i32, i32* @SOCK_STREAM
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 5
store i32 %13, i32* %14
%15 = load i32, i32* @AI_PASSIVE
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %2, i32 0, i32 4
store i32 %15, i32* %16
%17 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %2, %struct.addrinfo** %3)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %0
%21 = load i32, i32* @stderr
%22 = load i32, i32* %4
%23 = call i8* @gai_strerror(i32 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%29 = load %struct.addrinfo*, %struct.addrinfo** %3
store %struct.addrinfo* %29, %struct.addrinfo** %5
br label %30
30: ; preds = %75, %27
%31 = load %struct.addrinfo*, %struct.addrinfo** %5
%32 = icmp ne %struct.addrinfo* %31, null
br i1 %32, label %33, label %79
33: ; preds = %30
store i8* null, i8** %6
%34 = load %struct.addrinfo*, %struct.addrinfo** %5
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i32 0, i32 0
%36 = load i64, i64* %35
%37 = load i64, i64* @AF_INET
%38 = icmp eq i64 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %33
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %6
br label %49
40: ; preds = %33
%41 = load %struct.addrinfo*, %struct.addrinfo** %5
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i32 0, i32 0
%43 = load i64, i64* %42
%44 = load i64, i64* @AF_INET6
%45 = icmp eq i64 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %40
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %6
br label %48
47: ; preds = %40
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8** %6
br label %48
48: ; preds = %47, %46
br label %49
49: ; preds = %48, %39
%50 = load i32, i32* @NI_MAXHOST
%51 = zext i32 %50 to i64
%52 = call i8* @llvm.stacksave()
store i8* %52, i8** %7
%53 = alloca i8, i64 %51
store i64 %51, i64* %8
%54 = load %struct.addrinfo*, %struct.addrinfo** %5
%55 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %54, i32 0, i32 2
%56 = load i32, i32* %55
%57 = load %struct.addrinfo*, %struct.addrinfo** %5
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i32 0, i32 1
%59 = load i32, i32* %58
%60 = load i32, i32* @NI_MAXHOST
%61 = load i32, i32* @NI_NUMERICHOST
%62 = call i32 @getnameinfo(i32 %56, i32 %59, i8* %53, i32 %60, i32* null, i32 0, i32 %61)
store i32 %62, i32* %9
%63 = load i32, i32* %9
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %49
%66 = load i32, i32* @stderr
%67 = load i32, i32* %9
%68 = call i8* @gai_strerror(i32 %67)
%69 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %68)
br label %73
70: ; preds = %49
%71 = load i8*, i8** %6
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %71, i8* %53)
br label %73
73: ; preds = %70, %65
%74 = load i8*, i8** %7
br label %75
75: ; preds = %73
%76 = load %struct.addrinfo*, %struct.addrinfo** %5
%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** %5
br label %30
79: ; preds = %30
%80 = load %struct.addrinfo*, %struct.addrinfo** %3
%81 = call i32 @freeaddrinfo(%struct.addrinfo* %80)
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i32, i32, %struct.addrinfo*, i32, i32 }
@AF_INET = global i64 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [5 x i8] c"2222\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [5 x i8] c"IPv4\00"
@AF_INET6 = global i64 0
@.str.4 = [5 x i8] c"IPv6\00"
@.str.5 = [5 x i8] c"IPv?\00"
@NI_MAXHOST = global i32 0
@NI_NUMERICHOST = global i32 0
@.str.6 = [26 x i8] c"Error in getnameinfo: %s\0A\00"
@.str.7 = [10 x i8] c" %s: %s\0A\00"
@str = [48 x i8] c"IP addresses for a socket we are listening on:\0A\00"
define i32 @main() {
%1 = alloca %struct.addrinfo
%2 = alloca %struct.addrinfo*
%3 = bitcast %struct.addrinfo* %1 to i8*
%4 = bitcast %struct.addrinfo** %2 to i8*
%5 = call i32 @memset(%struct.addrinfo* %1, i32 0, i32 32)
%6 = load i64, i64* @AF_INET
%7 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 0
store i64 %6, i64* %7
%8 = load i32, i32* @SOCK_STREAM
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 5
store i32 %8, i32* %9
%10 = load i32, i32* @AI_PASSIVE
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 4
store i32 %10, i32* %11
%12 = 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)
%13 = icmp eq i32 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = call i8* @gai_strerror(i32 %12)
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %0
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
%22 = load %struct.addrinfo*, %struct.addrinfo** %2
%23 = icmp eq %struct.addrinfo* %22, null
br i1 %23, label %26, label %29
24: ; preds = %57
%25 = load %struct.addrinfo*, %struct.addrinfo** %2
br label %26
26: ; preds = %24, %20
%27 = phi %struct.addrinfo* [ %25, %24 ], [ null, %20 ]
%28 = call i32 @freeaddrinfo(%struct.addrinfo* %27)
ret i32 0
29: ; preds = %20, %57
%30 = phi %struct.addrinfo* [ %59, %57 ], [ %22, %20 ]
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i64 0, i32 0
%32 = load i64, i64* %31
%33 = load i64, i64* @AF_INET
%34 = load i64, i64* @AF_INET6
%35 = load i32, i32* @NI_MAXHOST
%36 = zext i32 %35 to i64
%37 = call i8* @llvm.stacksave()
%38 = alloca i8, i64 %36
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i64 0, i32 2
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i64 0, i32 1
%42 = load i32, i32* %41
%43 = load i32, i32* @NI_MAXHOST
%44 = load i32, i32* @NI_NUMERICHOST
%45 = call i32 @getnameinfo(i32 %40, i32 %42, i8* %38, i32 %43, i32* null, i32 0, i32 %44)
%46 = icmp eq i32 %45, 0
br i1 %46, label %51, label %47
47: ; preds = %29
%48 = load i32, i32* @stderr
%49 = call i8* @gai_strerror(i32 %45)
%50 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %49)
br label %57
51: ; preds = %29
%52 = icmp eq i64 %32, %33
%53 = icmp eq i64 %32, %34
%54 = select i1 %53, 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)
%55 = select i1 %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %54
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %55, i8* %38)
br label %57
57: ; preds = %51, %47
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i64 0, i32 3
%59 = load %struct.addrinfo*, %struct.addrinfo** %58
%60 = icmp eq %struct.addrinfo* %59, null
br i1 %60, label %24, label %29
}