#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 {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int NI_NUMERICHOST;
int NI_NUMERICSERV;
int errno;
int getnameinfo(struct sockaddr *, int /*<<< orphan*/, char *, int, char *, int,
                int);
int socket_address_to_hostname(struct sockaddr *address,
                               socklen_t address_length, char *hostname,
                               int hostname_length, char *port,
                               int port_length) {
  int rc;
  rc = getnameinfo(address, address_length, hostname, hostname_length, port,
                   port_length, NI_NUMERICHOST | NI_NUMERICSERV);
  if (rc != 0) {
    errno = 72000000 + rc;
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<socket_address_to_hostname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x30(%rbp),%r8
mov    -0x34(%rbp),%r9d
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
mov    0x2e94(%rip),%r10
or     (%r10),%eax
mov    %eax,(%rsp)
call   1030 <getnameinfo@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     118a <socket_address_to_hostname+0x7a>
mov    -0x38(%rbp),%ecx
add    $0x44aa200,%ecx
mov    0x2e54(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1191 <socket_address_to_hostname+0x81>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_address_to_hostname>:
push   %rax
mov    0x2ec0(%rip),%r10
mov    0x2ec9(%rip),%rax
mov    (%rax),%eax
or     (%r10),%eax
mov    %eax,(%rsp)
call   1030 <getnameinfo@plt>
test   %eax,%eax
je     1145 <socket_address_to_hostname+0x35>
add    $0x44aa200,%eax
mov    0x2e94(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@NI_NUMERICHOST = global i32 0
@NI_NUMERICSERV = global i32 0
@errno = global i32 0
define i32 @socket_address_to_hostname(%struct.sockaddr* %0, i32 %1, i8* %2, i32 %3, i8* %4, i32 %5) {
%7 = alloca i32
%8 = alloca %struct.sockaddr*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i32 %5, i32* %13
%15 = load %struct.sockaddr*, %struct.sockaddr** %8
%16 = load i32, i32* %9
%17 = load i8*, i8** %10
%18 = load i32, i32* %11
%19 = load i8*, i8** %12
%20 = load i32, i32* %13
%21 = load i32, i32* @NI_NUMERICHOST
%22 = load i32, i32* @NI_NUMERICSERV
%23 = or i32 %21, %22
%24 = call i32 @getnameinfo(%struct.sockaddr* %15, i32 %16, i8* %17, i32 %18, i8* %19, i32 %20, i32 %23)
store i32 %24, i32* %14
%25 = load i32, i32* %14
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %6
%28 = load i32, i32* %14
%29 = add nsw i32 72000000, %28
store i32 %29, i32* @errno
store i32 -1, i32* %7
br label %31
30: ; preds = %6
store i32 0, i32* %7
br label %31
31: ; preds = %30, %27
%32 = load i32, i32* %7
ret i32 %32
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@NI_NUMERICHOST = global i32 0
@NI_NUMERICSERV = global i32 0
@errno = global i32 0
define i32 @socket_address_to_hostname(%struct.sockaddr* %0, i32 %1, i8* %2, i32 %3, i8* %4, i32 %5) {
%7 = load i32, i32* @NI_NUMERICHOST
%8 = load i32, i32* @NI_NUMERICSERV
%9 = or i32 %8, %7
%10 = tail call i32 @getnameinfo(%struct.sockaddr* %0, i32 %1, i8* %2, i32 %3, i8* %4, i32 %5, i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %6
%13 = add nsw i32 %10, 72000000
store i32 %13, i32* @errno
br label %14
14: ; preds = %6, %12
%15 = phi i32 [ -1, %12 ], [ 0, %6 ]
ret i32 %15
}