#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 h_addrtype;
  int /*<<< orphan*/ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ bcmp(int /*<<< orphan*/, char const *, int);
int /*<<< orphan*/ endhostent();
struct hostent *gethostent();
int /*<<< orphan*/ sethostent(int /*<<< orphan*/);
struct hostent *_gethostbyhtaddr(const char *addr, int len, int af) {
  register struct hostent *p;
  sethostent(0);
  while ((p = gethostent()) != NULL)
    if (p->h_addrtype == af && !bcmp(p->h_addr, addr, len))
      break;
  endhostent();
  return (p);
}


x86 assembly (clang, -O0):
<_gethostbyhtaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
xor    %edi,%edi
call   1050 <sethostent@plt>
mov    $0x0,%al
call   1030 <gethostent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11a3 <_gethostbyhtaddr+0x63>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x10(%rbp),%eax
jne    119e <_gethostbyhtaddr+0x5e>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <bcmp@plt>
cmp    $0x0,%eax
jne    119e <_gethostbyhtaddr+0x5e>
jmp    11a3 <_gethostbyhtaddr+0x63>
jmp    1159 <_gethostbyhtaddr+0x19>
mov    $0x0,%al
call   1060 <endhostent@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_gethostbyhtaddr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <sethostent@plt>
xor    %eax,%eax
call   1030 <gethostent@plt>
test   %rax,%rax
je     1199 <_gethostbyhtaddr+0x59>
mov    %rax,%rbx
jmp    117f <_gethostbyhtaddr+0x3f>
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <gethostent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1197 <_gethostbyhtaddr+0x57>
cmp    %ebp,(%rbx)
jne    1170 <_gethostbyhtaddr+0x30>
mov    0x4(%rbx),%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <bcmp@plt>
test   %eax,%eax
jne    1170 <_gethostbyhtaddr+0x30>
jmp    1199 <_gethostbyhtaddr+0x59>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <endhostent@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.hostent = type { i32, i32 }
define %struct.hostent* @_gethostbyhtaddr(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 @sethostent(i32 0)
%5 = tail call %struct.hostent* (...) @gethostent()
%6 = icmp eq %struct.hostent* %5, null
br i1 %6, label %20, label %7
7: ; preds = %3, %17
%8 = phi %struct.hostent* [ %18, %17 ], [ %5, %3 ]
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i64 0, i32 0
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, %2
br i1 %11, label %12, label %17
12: ; preds = %7
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i64 0, i32 1
%14 = load i32, i32* %13
%15 = tail call i32 @bcmp(i32 %14, i8* %0, i32 %1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %12, %7
%18 = tail call %struct.hostent* (...) @gethostent()
%19 = icmp eq %struct.hostent* %18, null
br i1 %19, label %20, label %7
20: ; preds = %17, %12, %3
%21 = phi %struct.hostent* [ null, %3 ], [ %8, %12 ], [ null, %17 ]
%22 = tail call i32 (...) @endhostent()
ret %struct.hostent* %21
}