#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_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sa;
typedef int /*<<< orphan*/ node;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int NI_MAXHOST;
int /*<<< orphan*/ NI_NAMEREQD;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
char *gai_strerror(int);
int getnameinfo(struct sockaddr *, int, char *, int, int /*<<< orphan*/ *,
                int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  char addr_to_find[1024];
  struct sockaddr_in sa;
  sa.sin_family = AF_INET;
  char node[NI_MAXHOST];
  strcpy(addr_to_find, "10.2.0.2");
  if (argc > 1)
    strcpy(addr_to_find, argv[1]);
  inet_pton(AF_INET, addr_to_find, &sa.sin_addr);
  int res = getnameinfo((struct sockaddr *)&sa, sizeof(sa), node, sizeof(node),
                        NULL, 0, NI_NAMEREQD);
  if (res) {
    fprintf(stderr, "could not find name info: %s - %s\n", addr_to_find,
            gai_strerror(res));
    node[0] = 0;
  }
  printf("%s\n", node);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x414(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x440(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x420(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x438(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x428(%rbp)
lea    -0x410(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1030 <strcpy@plt>
cmpl   $0x1,-0x8(%rbp)
jle    11f5 <main+0x95>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rsi
lea    -0x418(%rbp),%rdx
call   1080 <inet_pton@plt>
mov    -0x438(%rbp),%rdx
mov    -0x440(%rbp),%rax
lea    -0x418(%rbp),%rdi
mov    %eax,%ecx
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
mov    $0x8,%esi
xor    %r8d,%r8d
xor    %r9d,%r9d
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1060 <getnameinfo@plt>
add    $0x10,%rsp
mov    %eax,-0x42c(%rbp)
cmpl   $0x0,-0x42c(%rbp)
je     12ad <main+0x14d>
mov    0x2d6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44c(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x448(%rbp)
mov    -0x42c(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x44c(%rbp),%edi
mov    -0x448(%rbp),%rdx
mov    %rax,%rcx
lea    0xd6b(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x438(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x438(%rbp),%rsi
lea    0xd6d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x420(%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    $0x418,%rsp
mov    %rsi,%r15
mov    %edi,%r12d
mov    %rsp,-0x30(%rbp)
mov    0x2e5b(%rip),%r13
mov    0x0(%r13),%eax
mov    %eax,-0x34(%rbp)
mov    0x2e35(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe4f(%rip),%rsi
lea    -0x440(%rbp),%rdi
call   1030 <strcpy@plt>
cmp    $0x2,%r12d
jl     11d3 <main+0x73>
mov    0x8(%r15),%rsi
lea    -0x440(%rbp),%rdi
call   1030 <strcpy@plt>
mov    0x0(%r13),%edi
lea    -0x440(%rbp),%rsi
lea    -0x38(%rbp),%r15
mov    %r15,%rdx
call   1080 <inet_pton@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
mov    %r15,%rdi
mov    $0x8,%esi
mov    %rbx,%rdx
mov    %r14d,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   %rax
call   1060 <getnameinfo@plt>
add    $0x10,%rsp
test   %eax,%eax
je     1246 <main+0xe6>
mov    0x2db0(%rip),%rcx
mov    (%rcx),%r14d
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xdd8(%rip),%rsi
lea    -0x440(%rbp),%rdx
mov    %r14d,%edi
mov    %rax,%rcx
call   1070 <fprintf@plt>
movb   $0x0,(%rbx)
lea    0xddb(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@NI_MAXHOST = global i32 0
@.str = [9 x i8] c"10.2.0.2\00"
@NI_NAMEREQD = global i32 0
@stderr = global i32 0
@.str.1 = [35 x i8] c"could not find name info: %s - %s\0A\00"
@.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 [1024 x i8]
%7 = alloca %struct.sockaddr_in
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %11, i32* %12
%13 = load i32, i32* @NI_MAXHOST
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %8
%16 = alloca i8, i64 %14
store i64 %14, i64* %9
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 1
br i1 %20, label %21, label %27
21: ; preds = %2
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @strcpy(i8* %22, i8* %25)
br label %27
27: ; preds = %21, %2
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%31 = call i32 @inet_pton(i32 %28, i8* %29, i32* %30)
%32 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%33 = trunc i64 %14 to i32
%34 = load i32, i32* @NI_NAMEREQD
%35 = call i32 @getnameinfo(%struct.sockaddr* %32, i32 8, i8* %16, i32 %33, i32* null, i32 0, i32 %34)
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 = %27
%39 = load i32, i32* @stderr
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%41 = load i32, i32* %10
%42 = call i8* @gai_strerror(i32 %41)
%43 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %40, i8* %42)
%44 = getelementptr inbounds i8, i8* %16, i64 0
store i8 0, i8* %44
br label %45
45: ; preds = %38, %27
%46 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %16)
store i32 0, i32* %3
%47 = load i8*, i8** %8
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@NI_MAXHOST = global i32 0
@.str = [9 x i8] c"10.2.0.2\00"
@NI_NAMEREQD = global i32 0
@stderr = global i32 0
@.str.1 = [35 x i8] c"could not find name info: %s - %s\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %7, i32* %8
%9 = load i32, i32* @NI_MAXHOST
%10 = zext i32 %9 to i64
%11 = tail call i8* @llvm.stacksave()
%12 = alloca i8, i64 %10
%13 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%14 = icmp sgt i32 %0, 1
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @strcpy(i8* %5, i8* %17)
br label %19
19: ; preds = %15, %2
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%22 = call i32 @inet_pton(i32 %20, i8* %5, i32* %21)
%23 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%24 = load i32, i32* @NI_NAMEREQD
%25 = call i32 @getnameinfo(%struct.sockaddr* %23, i32 8, i8* %12, i32 %9, i32* null, i32 0, i32 %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %19
%28 = load i32, i32* @stderr
%29 = call i8* @gai_strerror(i32 %25)
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %29)
store i8 0, i8* %12
br label %31
31: ; preds = %27, %19
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %12)
ret i32 0
}