#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ hbuf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int NI_MAXHOST;
int /*<<< orphan*/ NI_NAMEREQD;
scalar_t__ getnameinfo(struct sockaddr *, int, char *, int,
                       int /*<<< orphan*/ *, int /*<<< orphan*/,
                       int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  struct sockaddr_in addr;
  memset(&addr, 0, sizeof(struct sockaddr_in));
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = inet_addr(argv[1]);
  socklen_t len = sizeof(struct sockaddr_in);
  char hbuf[NI_MAXHOST];
  if (getnameinfo((struct sockaddr *)&addr, len, hbuf, sizeof(hbuf), NULL, 0,
                  NI_NAMEREQD))
    printf("could not resolve hostname\n");
  else
    printf("host=%s\n", hbuf);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
movl   $0x8,-0x1c(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x38(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x30(%rbp)
lea    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    %eax,%ecx
mov    0x2e2b(%rip),%rax
mov    (%rax),%eax
xor    %r8d,%r8d
xor    %r9d,%r9d
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1050 <getnameinfo@plt>
add    $0x10,%rsp
cmp    $0x0,%rax
je     11fa <main+0xba>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120c <main+0xcc>
mov    -0x38(%rbp),%rsi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%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   %rbx
push   %rax
mov    %rsi,%rbx
lea    -0x20(%rbp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x8(%rbx),%rdi
call   1070 <inet_addr@plt>
mov    %rsp,%r15
mov    %eax,-0x20(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbx
mov    %rcx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
mov    %r14,%rdi
mov    $0x8,%esi
mov    %rbx,%rdx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   %rax
call   1060 <getnameinfo@plt>
add    $0x10,%rsp
test   %rax,%rax
je     11e3 <main+0x93>
lea    0xe2d(%rip),%rdi
call   1030 <puts@plt>
jmp    11f4 <main+0xa4>
lea    0xe16(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rsp
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@NI_MAXHOST = global i32 0
@NI_NAMEREQD = global i32 0
@.str = [28 x i8] c"could not resolve hostname\0A\00"
@.str.1 = [9 x i8] c"host=%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 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 8)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %11, i32* %12
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @inet_addr(i8* %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i32 %16, i32* %18
store i32 8, i32* %7
%19 = load i32, i32* @NI_MAXHOST
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %8
%22 = alloca i8, i64 %20
store i64 %20, i64* %9
%23 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%24 = load i32, i32* %7
%25 = trunc i64 %20 to i32
%26 = load i32, i32* @NI_NAMEREQD
%27 = call i64 @getnameinfo(%struct.sockaddr* %23, i32 %24, i8* %22, i32 %25, i32* null, i32 0, i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %2
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %33
31: ; preds = %2
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %33
33: ; preds = %31, %29
%34 = load i8*, i8** %8
%35 = load i32, i32* %3
ret i32 %35
}

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