#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;
};

/* Variables and functions */
int /*<<< orphan*/ ERANGE;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int copy_hostent(struct hostent *, void *, int);
int /*<<< orphan*/ errno;
struct hostent *gethostbyaddr(char const *, int, int);
int h_errno;
struct hostent *get_host_by_addr(const char *addr, int len, int type, void *buf,
                                 int buflen, int *h_err) {
  struct hostent *hptr;
  int n = 0;
  assert(addr != NULL);
  assert(buf != NULL);
  ;
  if ((hptr = gethostbyaddr(addr, len, type)))
    n = copy_hostent(hptr, buf, buflen);
  if (h_err)
    *h_err = h_errno;
  ;
  if (n < 0) {
    errno = ERANGE;
    return (NULL);
  }
  return (hptr ? (struct hostent *)buf : NULL);
}


x86 assembly (clang, -O0):
<get_host_by_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <gethostbyaddr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     11a9 <get_host_by_addr+0x79>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <copy_hostent@plt>
mov    %eax,-0x3c(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11c3 <get_host_by_addr+0x93>
mov    0x2e2d(%rip),%rax
mov    (%rax),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x3c(%rbp)
jge    11ec <get_host_by_addr+0xbc>
mov    0x2e0c(%rip),%rax
mov    (%rax),%ecx
mov    0x2df3(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    1217 <get_host_by_addr+0xe7>
cmpq   $0x0,-0x38(%rbp)
je     1204 <get_host_by_addr+0xd4>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    120f <get_host_by_addr+0xdf>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
jmp    120f <get_host_by_addr+0xdf>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_host_by_addr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8d,%r15d
mov    %rcx,%rbx
mov    %edx,%r12d
mov    %esi,%r13d
mov    %rdi,%rbp
xor    %edi,%edi
test   %rbp,%rbp
setne  %dil
call   1030 <assert@plt>
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
mov    %rbp,%rdi
mov    %r13d,%esi
mov    %r12d,%edx
call   1050 <gethostbyaddr@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11ab <get_host_by_addr+0x7b>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1040 <copy_hostent@plt>
test   %r14,%r14
je     119e <get_host_by_addr+0x6e>
mov    0x2e4f(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,(%r14)
test   %eax,%eax
js     11b4 <get_host_by_addr+0x84>
test   %rbp,%rbp
cmove  %rbp,%rbx
jmp    11c8 <get_host_by_addr+0x98>
xor    %eax,%eax
test   %r14,%r14
jne    1192 <get_host_by_addr+0x62>
jmp    119e <get_host_by_addr+0x6e>
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    0x2e0c(%rip),%rcx
mov    %eax,(%rcx)
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i32 }
@h_errno = global i32 0
@ERANGE = global i32 0
@errno = global i32 0
define %struct.hostent* @get_host_by_addr(i8* %0, i32 %1, i32 %2, i8* %3, i32 %4, i32* %5) {
%7 = alloca %struct.hostent*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32*
%14 = alloca %struct.hostent*
%15 = alloca i32
store i8* %0, i8** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store i32 %4, i32* %12
store i32* %5, i32** %13
store i32 0, i32* %15
%16 = load i8*, i8** %8
%17 = icmp ne i8* %16, null
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i8*, i8** %11
%21 = icmp ne i8* %20, null
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i8*, i8** %8
%25 = load i32, i32* %9
%26 = load i32, i32* %10
%27 = call %struct.hostent* @gethostbyaddr(i8* %24, i32 %25, i32 %26)
store %struct.hostent* %27, %struct.hostent** %14
%28 = icmp ne %struct.hostent* %27, null
br i1 %28, label %29, label %34
29: ; preds = %6
%30 = load %struct.hostent*, %struct.hostent** %14
%31 = load i8*, i8** %11
%32 = load i32, i32* %12
%33 = call i32 @copy_hostent(%struct.hostent* %30, i8* %31, i32 %32)
store i32 %33, i32* %15
br label %34
34: ; preds = %29, %6
%35 = load i32*, i32** %13
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* @h_errno
%39 = load i32*, i32** %13
store i32 %38, i32* %39
br label %40
40: ; preds = %37, %34
%41 = load i32, i32* %15
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = load i32, i32* @ERANGE
store i32 %44, i32* @errno
store %struct.hostent* null, %struct.hostent** %7
br label %54
45: ; preds = %40
%46 = load %struct.hostent*, %struct.hostent** %14
%47 = icmp ne %struct.hostent* %46, null
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i8*, i8** %11
%50 = bitcast i8* %49 to %struct.hostent*
br label %52
51: ; preds = %45
br label %52
52: ; preds = %51, %48
%53 = phi %struct.hostent* [ %50, %48 ], [ null, %51 ]
store %struct.hostent* %53, %struct.hostent** %7
br label %54
54: ; preds = %52, %43
%55 = load %struct.hostent*, %struct.hostent** %7
ret %struct.hostent* %55
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
@h_errno = global i32 0
@ERANGE = global i32 0
@errno = global i32 0
define %struct.hostent* @get_host_by_addr(i8* %0, i32 %1, i32 %2, i8* %3, i32 %4, i32* writeonly %5) {
%7 = icmp ne i8* %0, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = icmp ne i8* %3, null
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = tail call %struct.hostent* @gethostbyaddr(i8* %0, i32 %1, i32 %2)
%14 = icmp eq %struct.hostent* %13, null
br i1 %14, label %17, label %15
15: ; preds = %6
%16 = tail call i32 @copy_hostent(%struct.hostent* %13, i8* %3, i32 %4)
br label %17
17: ; preds = %15, %6
%18 = phi i32 [ %16, %15 ], [ 0, %6 ]
%19 = icmp eq i32* %5, null
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = load i32, i32* @h_errno
store i32 %21, i32* %5
br label %22
22: ; preds = %20, %17
%23 = icmp slt i32 %18, 0
br i1 %23, label %24, label %26
24: ; preds = %22
%25 = load i32, i32* @ERANGE
store i32 %25, i32* @errno
br label %29
26: ; preds = %22
%27 = bitcast i8* %3 to %struct.hostent*
%28 = select i1 %14, %struct.hostent* null, %struct.hostent* %27
br label %29
29: ; preds = %26, %24
%30 = phi %struct.hostent* [ null, %24 ], [ %28, %26 ]
ret %struct.hostent* %30
}