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

/* Variables and functions */
struct hostent *gethostbyaddr(void const *, int /*<<< orphan*/, int);
int gethostbyaddr_r(const void *addr, socklen_t len, int type,
                    struct hostent *ret, char *buf, size_t buflen,
                    struct hostent **result, int *h_errnop) {
  *result = gethostbyaddr(addr, len, type);
  if (*result)
    return 0;
  return -1;
}


x86 assembly (clang, -O0):
<gethostbyaddr_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <gethostbyaddr@plt>
mov    %rax,%rcx
mov    0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1169 <gethostbyaddr_r+0x59>
movl   $0x0,-0x4(%rbp)
jmp    1170 <gethostbyaddr_r+0x60>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethostbyaddr_r>:
push   %rbx
mov    0x10(%rsp),%rbx
call   1030 <gethostbyaddr@plt>
mov    %rax,(%rbx)
cmp    $0x1,%rax
sbb    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.hostent = type { i32 }
define i32 @gethostbyaddr_r(i8* %0, i32 %1, i32 %2, %struct.hostent* %3, i8* %4, i64 %5, %struct.hostent** %6, i32* %7) {
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.hostent*
%14 = alloca i8*
%15 = alloca i64
%16 = alloca %struct.hostent**
%17 = alloca i32*
store i8* %0, i8** %10
store i32 %1, i32* %11
store i32 %2, i32* %12
store %struct.hostent* %3, %struct.hostent** %13
store i8* %4, i8** %14
store i64 %5, i64* %15
store %struct.hostent** %6, %struct.hostent*** %16
store i32* %7, i32** %17
%18 = load i8*, i8** %10
%19 = load i32, i32* %11
%20 = load i32, i32* %12
%21 = call %struct.hostent* @gethostbyaddr(i8* %18, i32 %19, i32 %20)
%22 = load %struct.hostent**, %struct.hostent*** %16
store %struct.hostent* %21, %struct.hostent** %22
%23 = load %struct.hostent**, %struct.hostent*** %16
%24 = load %struct.hostent*, %struct.hostent** %23
%25 = icmp ne %struct.hostent* %24, null
br i1 %25, label %26, label %27
26: ; preds = %8
store i32 0, i32* %9
br label %28
27: ; preds = %8
store i32 -1, i32* %9
br label %28
28: ; preds = %27, %26
%29 = load i32, i32* %9
ret i32 %29
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
define i32 @gethostbyaddr_r(i8* %0, i32 %1, i32 %2, %struct.hostent* nocapture readnone %3, i8* nocapture readnone %4, i64 %5, %struct.hostent** nocapture writeonly %6, i32* nocapture readnone %7) {
%9 = tail call %struct.hostent* @gethostbyaddr(i8* %0, i32 %1, i32 %2)
store %struct.hostent* %9, %struct.hostent** %6
%10 = icmp eq %struct.hostent* %9, null
%11 = sext i1 %10 to i32
ret i32 %11
}