#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 */
scalar_t__ gethostbyaddr_r(void const *, int /*<<< orphan*/, int,
                           struct hostent *, void *, int, struct hostent **,
                           int /*<<< orphan*/ *);
int /*<<< orphan*/ h_errno;
struct hostent *gethostbyaddr(const void *a, socklen_t l, int af) {
  static struct hostent h;
  static long buf[512 / sizeof(long)];
  struct hostent *res;
  if (gethostbyaddr_r(a, l, af, &h, (void *)buf, sizeof buf, &res, &h_errno))
    return 0;
  return &h;
}


x86 assembly (clang, -O0):
<gethostbyaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0x2f0d(%rip),%rcx
lea    0x2f16(%rip),%r8
mov    $0x200,%r9d
lea    -0x20(%rbp),%r10
mov    0x2e9d(%rip),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <gethostbyaddr_r@plt>
cmp    $0x0,%rax
je     1170 <gethostbyaddr+0x60>
movq   $0x0,-0x8(%rbp)
jmp    117b <gethostbyaddr+0x6b>
lea    0x2ec9(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethostbyaddr>:
push   %rbx
sub    $0x10,%rsp
mov    0x2ecc(%rip),%rax
lea    0x8(%rsp),%r10
lea    0x2f18(%rip),%rbx
lea    0x2f21(%rip),%r8
mov    %rbx,%rcx
mov    $0x200,%r9d
push   %rax
push   %r10
call   1030 <gethostbyaddr_r@plt>
add    $0x10,%rsp
xor    %ecx,%ecx
test   %rax,%rax
cmove  %rbx,%rcx
mov    %rcx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.hostent = type { i32 }
@gethostbyaddr.h = internal global %struct.hostent zeroinitializer
@gethostbyaddr.buf = internal global [64 x i64] zeroinitializer
@h_errno = global i32 0
define %struct.hostent* @gethostbyaddr(i8* %0, i32 %1, i32 %2) {
%4 = alloca %struct.hostent*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.hostent*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = load i32, i32* %6
%11 = load i32, i32* %7
%12 = call i64 @gethostbyaddr_r(i8* %9, i32 %10, i32 %11, %struct.hostent* @gethostbyaddr.h, i8* bitcast ([64 x i64]* @gethostbyaddr.buf to i8*), i32 512, %struct.hostent** %8, i32* @h_errno)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store %struct.hostent* null, %struct.hostent** %4
br label %16
15: ; preds = %3
store %struct.hostent* @gethostbyaddr.h, %struct.hostent** %4
br label %16
16: ; preds = %15, %14
%17 = load %struct.hostent*, %struct.hostent** %4
ret %struct.hostent* %17
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
@gethostbyaddr.h = internal global %struct.hostent zeroinitializer
@gethostbyaddr.buf = internal global [64 x i64] zeroinitializer
@h_errno = global i32 0
define %struct.hostent* @gethostbyaddr(i8* %0, i32 %1, i32 %2) {
%4 = alloca %struct.hostent*
%5 = bitcast %struct.hostent** %4 to i8*
%6 = call i64 @gethostbyaddr_r(i8* %0, i32 %1, i32 %2, %struct.hostent* @gethostbyaddr.h, i8* bitcast ([64 x i64]* @gethostbyaddr.buf to i8*), i32 512, %struct.hostent** %4, i32* @h_errno)
%7 = icmp eq i64 %6, 0
%8 = select i1 %7, %struct.hostent* @gethostbyaddr.h, %struct.hostent* null
ret %struct.hostent* %8
}