#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;
  scalar_t__ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ sai;
typedef int /*<<< orphan*/ hbuf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int NI_MAXHOST;
int /*<<< orphan*/ NI_NAMEREQD;
int /*<<< orphan*/ exit(int);
scalar_t__ getnameinfo(struct sockaddr *, int, char *, int,
                       int /*<<< orphan*/ *, int /*<<< orphan*/,
                       int /*<<< orphan*/);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, ...);
int main(int argc, char **argv) {
  struct sockaddr_in sai;
  socklen_t len;
  char hbuf[NI_MAXHOST];
  if (argc != 2) {
    printf("Usage:%s ip_address\n", argv[0]);
    exit(-1);
  }
  sai.sin_family = AF_INET;
  sai.sin_port = 0;
  inet_aton(argv[1], &sai.sin_addr);
  len = sizeof(sai);
  if (getnameinfo((struct sockaddr *)&sai, len, hbuf, sizeof(hbuf), NULL, 0,
                  NI_NAMEREQD))
    printf("could not resolve hostname for %s\n", argv[1]);
  else
    printf("host=%s,%s\n", hbuf, argv[1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x50(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11af <main+0x6f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <inet_aton@plt>
mov    -0x48(%rbp),%rdx
mov    -0x50(%rbp),%rax
movl   $0x18,-0x2c(%rbp)
lea    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    %eax,%ecx
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
xor    %r8d,%r8d
xor    %r9d,%r9d
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1040 <getnameinfo@plt>
add    $0x10,%rsp
cmp    $0x0,%rax
je     1230 <main+0xf0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124a <main+0x10a>
mov    -0x48(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x38(%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    $0x18,%rsp
mov    %rsi,%r14
mov    %rsp,%r13
mov    0x2e72(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%rbx
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x2,%edi
jne    120b <main+0xcb>
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    0x8(%r14),%rdi
lea    -0x40(%rbp),%r12
mov    %r12,%rsi
call   1050 <inet_aton@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
mov    %r12,%rdi
mov    $0x18,%esi
mov    %rbx,%rdx
mov    %r15d,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   %rax
call   1040 <getnameinfo@plt>
add    $0x10,%rsp
mov    0x8(%r14),%rdx
test   %rax,%rax
je     11e6 <main+0xa6>
lea    0xe3b(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11f7 <main+0xb7>
lea    0xe4b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r13,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%rsi
lea    0xdeb(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i64, i32 }
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@.str = [21 x i8] c"Usage:%s ip_address\0A\00"
@AF_INET = global i32 0
@NI_NAMEREQD = global i32 0
@.str.1 = [35 x i8] c"could not resolve hostname for %s\0A\00"
@.str.2 = [12 x i8] c"host=%s,%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @NI_MAXHOST
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %8
%13 = alloca i8, i64 %11
store i64 %11, i64* %9
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %2
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i64 0, i64* %25
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%30 = call i32 @inet_aton(i8* %28, i32* %29)
store i32 24, i32* %7
%31 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%32 = load i32, i32* %7
%33 = trunc i64 %11 to i32
%34 = load i32, i32* @NI_NAMEREQD
%35 = call i64 @getnameinfo(%struct.sockaddr* %31, i32 %32, i8* %13, i32 %33, i32* null, i32 0, i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %22
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %40)
br label %47
42: ; preds = %22
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %13, i8* %45)
br label %47
47: ; preds = %42, %37
store i32 0, i32* %3
%48 = load i8*, i8** %8
%49 = load i32, i32* %3
ret i32 %49
}

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