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

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ NI_NUMERICHOST;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *gai_strerror(int);
int getaddrinfo(char *, int /*<<< orphan*/ *, 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 *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  struct addrinfo hints;
  struct addrinfo *result, *rp;
  int sfd, s;
  struct sockaddr_storage peer_addr;
  socklen_t peer_addr_len;
  char buf[1024];
  if (argc != 2) {
    fprintf(stderr, "Usage: %s port\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = 0;
  hints.ai_protocol = 0;
  s = getaddrinfo(argv[1], NULL, &hints, &result);
  if (s != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
    exit(EXIT_FAILURE);
  }
  for (rp = result; rp != NULL; rp = rp->ai_next) {
    s = getnameinfo(rp->ai_addr, rp->ai_addrlen, buf, 1024, NULL, 0,
                    NI_NUMERICHOST);
    printf("%s\n", buf);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11bd <main+0x4d>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe56(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1090 <getaddrinfo@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
je     1255 <main+0xe5>
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x464(%rbp)
mov    -0x50(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    -0x464(%rbp),%edi
mov    %rax,%rdx
lea    0xdce(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     12bf <main+0x14f>
mov    -0x48(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x48(%rbp),%rax
mov    (%rax),%esi
lea    -0x460(%rbp),%rdx
mov    0x2d45(%rip),%rax
mov    (%rax),%eax
mov    $0x400,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
mov    %eax,(%rsp)
call   1060 <getnameinfo@plt>
mov    %eax,-0x50(%rbp)
lea    -0x460(%rbp),%rsi
lea    0xd74(%rip),%rdi
call   1030 <printf@plt>
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    125d <main+0xed>
mov    -0x4(%rbp),%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x448,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1244 <main+0xd4>
lea    0x18(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x3c(%rsp)
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x28(%rsp)
mov    0x8(%rbx),%rdi
lea    0x10(%rsp),%rcx
xor    %esi,%esi
mov    %r14,%rdx
call   1090 <getaddrinfo@plt>
test   %eax,%eax
jne    1259 <main+0xe9>
mov    0x10(%rsp),%rbx
test   %rbx,%rbx
je     1233 <main+0xc3>
mov    0x2ddc(%rip),%r12
lea    0x40(%rsp),%r15
lea    0xe25(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%esi
mov    0x4(%rbx),%edi
mov    (%r12),%eax
mov    %eax,(%rsp)
mov    %r15,%rdx
mov    $0x400,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1060 <getnameinfo@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
mov    0x8(%rbx),%rbx
test   %rbx,%rbx
jne    1200 <main+0x90>
xor    %eax,%eax
add    $0x448,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xda9(%rip),%rsi
jmp    1275 <main+0x105>
mov    0x2d70(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xda0(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, %struct.addrinfo*, i64, i64, i32, i32 }
%struct.sockaddr_storage = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"Usage: %s port\0A\00"
@EXIT_FAILURE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@NI_NUMERICHOST = global i32 0
@.str.2 = [4 x i8] c"%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 i32
%11 = alloca %struct.sockaddr_storage
%12 = alloca i32
%13 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %24
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %2
%25 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 40)
%26 = load i32, i32* @AF_UNSPEC
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 6
store i32 %26, i32* %27
%28 = load i32, i32* @SOCK_DGRAM
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 5
store i32 %28, i32* %29
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 4
store i64 0, i64* %30
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
store i64 0, i64* %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* %10
%36 = load i32, i32* %10
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %24
%39 = load i32, i32* @stderr
%40 = load i32, i32* %10
%41 = call i8* @gai_strerror(i32 %40)
%42 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %24
%46 = load %struct.addrinfo*, %struct.addrinfo** %7
store %struct.addrinfo* %46, %struct.addrinfo** %8
br label %47
47: ; preds = %62, %45
%48 = load %struct.addrinfo*, %struct.addrinfo** %8
%49 = icmp ne %struct.addrinfo* %48, null
br i1 %49, label %50, label %66
50: ; preds = %47
%51 = load %struct.addrinfo*, %struct.addrinfo** %8
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %51, i32 0, i32 1
%53 = load i32, i32* %52
%54 = load %struct.addrinfo*, %struct.addrinfo** %8
%55 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %54, i32 0, i32 0
%56 = load i32, i32* %55
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%58 = load i32, i32* @NI_NUMERICHOST
%59 = call i32 @getnameinfo(i32 %53, i32 %56, i8* %57, i32 1024, i32* null, i32 0, i32 %58)
store i32 %59, i32* %10
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%61 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %60)
br label %62
62: ; preds = %50
%63 = load %struct.addrinfo*, %struct.addrinfo** %8
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %63, i32 0, i32 2
%65 = load %struct.addrinfo*, %struct.addrinfo** %64
store %struct.addrinfo* %65, %struct.addrinfo** %8
br label %47
66: ; preds = %47
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, %struct.addrinfo*, i64, i64, i32, i32 }
@stderr = global i32 0
@.str = [16 x i8] c"Usage: %s port\0A\00"
@EXIT_FAILURE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@NI_NUMERICHOST = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca [1024 x i8]
%6 = bitcast %struct.addrinfo* %3 to i8*
%7 = bitcast %struct.addrinfo** %4 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 2
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 40)
%18 = load i32, i32* @AF_UNSPEC
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 6
store i32 %18, i32* %19
%20 = load i32, i32* @SOCK_DGRAM
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 5
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = bitcast i64* %22 to i8*
%25 = load i8*, i8** %23
%26 = call i32 @getaddrinfo(i8* %25, i32* null, %struct.addrinfo* %3, %struct.addrinfo** %4)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %16
%29 = load %struct.addrinfo*, %struct.addrinfo** %4
%30 = icmp eq %struct.addrinfo* %29, null
br i1 %30, label %49, label %37
31: ; preds = %16
%32 = load i32, i32* @stderr
%33 = call i8* @gai_strerror(i32 %26)
%34 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %28, %37
%38 = phi %struct.addrinfo* [ %47, %37 ], [ %29, %28 ]
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 1
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 0
%42 = load i32, i32* %41
%43 = load i32, i32* @NI_NUMERICHOST
%44 = call i32 @getnameinfo(i32 %40, i32 %42, i8* %8, i32 1024, i32* null, i32 0, i32 %43)
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 2
%47 = load %struct.addrinfo*, %struct.addrinfo** %46
%48 = icmp eq %struct.addrinfo* %47, null
br i1 %48, label %49, label %37
49: ; preds = %37, %28
ret i32 0
}