#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 sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ NI_NAMEREQD;
char *gai_strerror(int);
int getnameinfo(struct sockaddr *, int, char *, int, int /*<<< orphan*/ *,
                int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
void printhost(struct sockaddr *addr) {
  char hname[256];
  int ret;
  ret = getnameinfo(addr, sizeof(struct sockaddr_storage), hname, 255, NULL, 0,
                    NI_NAMEREQD);
  if (ret != 0) {
    printf("getnameinfo: %s\n", gai_strerror(ret));
    return;
  }
  printf("\t%s\n", hname);
}


x86 assembly (clang, -O0):
<printhost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rdx
mov    0x2e9f(%rip),%rax
mov    (%rax),%eax
mov    $0x4,%esi
mov    $0xff,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
mov    %eax,(%rsp)
call   1050 <getnameinfo@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
je     119d <printhost+0x6d>
mov    -0x114(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    %rax,%rsi
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
jmp    11b0 <printhost+0x80>
lea    -0x110(%rbp),%rsi
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printhost>:
sub    $0x118,%rsp
mov    0x2eb2(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
lea    0x10(%rsp),%rdx
mov    $0x4,%esi
mov    $0xff,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1050 <getnameinfo@plt>
test   %eax,%eax
je     1174 <printhost+0x44>
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xe91(%rip),%rdi
mov    %rax,%rsi
jmp    1180 <printhost+0x50>
lea    0xe96(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1030 <printf@plt>
add    $0x118,%rsp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@NI_NAMEREQD = global i32 0
@.str = [17 x i8] c"getnameinfo: %s\0A\00"
@.str.1 = [5 x i8] c"\09%s\0A\00"
define void @printhost(%struct.sockaddr* %0) {
%2 = alloca %struct.sockaddr*
%3 = alloca [256 x i8]
%4 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %2
%5 = load %struct.sockaddr*, %struct.sockaddr** %2
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @NI_NAMEREQD
%8 = call i32 @getnameinfo(%struct.sockaddr* %5, i32 4, i8* %6, i32 255, i32* null, i32 0, i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i32, i32* %4
%13 = call i8* @gai_strerror(i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %18
15: ; preds = %1
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %15, %11
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@NI_NAMEREQD = global i32 0
@.str = [17 x i8] c"getnameinfo: %s\0A\00"
@.str.1 = [5 x i8] c"\09%s\0A\00"
define void @printhost(%struct.sockaddr* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @NI_NAMEREQD
%5 = call i32 @getnameinfo(%struct.sockaddr* %0, i32 4, i8* %3, i32 255, i32* null, i32 0, i32 %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = call i8* @gai_strerror(i32 %5)
%9 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %12
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %12
12: ; preds = %10, %7
ret void
}