#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 */
typedef int /*<<< orphan*/ uint32_t;
struct hostent {
  int h_addrtype;
  char *h_name;
  char **h_aliases;
  size_t h_length;
  char **h_addr_list;
};
typedef enum nss_status { ____Placeholder_nss_status } nss_status;

/* Variables and functions */
int AF_INET;
int AF_INET6;
int ENOMEM;
int NO_RECOVERY;
int NSS_STATUS_SUCCESS;
int NSS_STATUS_TRYAGAIN;
size_t PROTO_ADDRESS_SIZE(int);
int /*<<< orphan*/ htonl(int);
char const in6addr_loopback;
int /*<<< orphan*/ memcpy(char *, char const *, int);
size_t strlen(char const *);
enum nss_status _fill_hostent(const char *name, int af, struct hostent *result,
                              char *buffer, size_t buflen, int *errnop,
                              int *h_errnop) {
  char *r_addr, *r_name, *r_aliases, *r_addr_list;
  size_t l, idx, ms, alen;
  alen = PROTO_ADDRESS_SIZE(af);
  l = strlen(name);
  ms = (((l + 1 + sizeof(void *) - 1) / sizeof(void *)) * sizeof(void *)) +
       sizeof(char *);
  if (buflen < ms) {
    *errnop = ENOMEM;
    *h_errnop = NO_RECOVERY;
    return NSS_STATUS_TRYAGAIN;
  }
  r_name = buffer;
  memcpy(r_name, name, l + 1);
  idx = (((l + 1 + sizeof(void *) - 1) / sizeof(void *)) * sizeof(void *));
  r_aliases = buffer + idx;
  *(char **)r_aliases = NULL;
  idx += sizeof(char *);
  r_addr = buffer + idx;
  if (af == AF_INET) {
    result->h_addrtype = AF_INET;
    *(uint32_t *)r_addr = (htonl(0x7F000002));
  } else {
    result->h_addrtype = AF_INET6;
    memcpy(r_addr, &in6addr_loopback, 16);
  }
  idx += (((alen + sizeof(void *) - 1) / sizeof(void *)) * sizeof(void *));
  r_addr_list = buffer + idx;
  ((char **)r_addr_list)[0] = r_addr;
  ((char **)r_addr_list)[1] = NULL;
  idx += 2 * sizeof(char *);
  result->h_name = r_name;
  result->h_aliases = (char **)r_aliases;
  result->h_length = alen;
  result->h_addr_list = (char **)r_addr_list;
  return NSS_STATUS_SUCCESS;
}


x86 assembly (clang, -O0):
<_fill_hostent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <PROTO_ADDRESS_SIZE@plt>
mov    %rax,-0x78(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
add    $0x1,%rax
add    $0x8,%rax
sub    $0x1,%rax
shr    $0x3,%rax
shl    $0x3,%rax
add    $0x8,%rax
mov    %rax,-0x70(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x70(%rbp),%rax
jae    11dc <_fill_hostent+0x9c>
mov    0x2e0c(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2ded(%rip),%rax
mov    (%rax),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1329 <_fill_hostent+0x1e9>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x60(%rbp),%rax
add    $0x1,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x60(%rbp),%rax
add    $0x1,%rax
add    $0x8,%rax
sub    $0x1,%rax
shr    $0x3,%rax
shl    $0x3,%rax
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rax
add    -0x68(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x68(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rax
add    -0x68(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2d98(%rip),%rcx
cmp    (%rcx),%eax
jne    127e <_fill_hostent+0x13e>
mov    0x2d89(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x7f000002,%edi
call   1040 <htonl@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,(%rax)
jmp    12a2 <_fill_hostent+0x162>
mov    0x2d53(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rdi
mov    0x2d48(%rip),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    -0x78(%rbp),%rax
add    $0x8,%rax
sub    $0x1,%rax
shr    $0x3,%rax
shl    $0x3,%rax
add    -0x68(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rax
add    -0x68(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x40(%rbp),%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x58(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x68(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x68(%rbp)
mov    -0x48(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x50(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x78(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x58(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    0x2cac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_fill_hostent>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,0x8(%rsp)
mov    %r8,%r15
mov    %rcx,%rbx
mov    %rdx,(%rsp)
mov    %esi,%r13d
mov    %rdi,%rbp
mov    %esi,%edi
call   1060 <PROTO_ADDRESS_SIZE@plt>
mov    %rax,0x10(%rsp)
mov    %rbp,%rdi
call   1030 <strlen@plt>
lea    0x8(%rax),%r14
and    $0xfffffffffffffff8,%r14
lea    0x8(%r14),%r12
cmp    %r15,%r12
jbe    11b4 <_fill_hostent+0x74>
mov    0x50(%rsp),%rax
mov    0x2e2c(%rip),%rcx
mov    (%rcx),%ecx
mov    0x8(%rsp),%rdx
mov    %ecx,(%rdx)
mov    0x2e0c(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,(%rax)
mov    0x2e09(%rip),%rax
jmp    1256 <_fill_hostent+0x116>
add    $0x1,%eax
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <memcpy@plt>
lea    (%rbx,%r14,1),%r15
movq   $0x0,(%rbx,%r14,1)
lea    (%rbx,%r12,1),%r14
mov    0x2e0d(%rip),%rax
cmp    %r13d,(%rax)
jne    11f7 <_fill_hostent+0xb7>
mov    (%rsp),%rbp
mov    %r13d,0x0(%rbp)
mov    $0x7f000002,%edi
call   1040 <htonl@plt>
mov    %eax,(%r14)
jmp    121b <_fill_hostent+0xdb>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    (%rsp),%rbp
mov    %eax,0x0(%rbp)
mov    0x2dd2(%rip),%rsi
mov    %r14,%rdi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    0x10(%rsp),%rcx
mov    %rcx,%rax
add    $0x7,%rax
and    $0xfffffffffffffff8,%rax
add    %rax,%r12
lea    (%rbx,%r12,1),%rax
mov    %r14,(%rbx,%r12,1)
movq   $0x0,0x8(%rbx,%r12,1)
mov    %rbx,0x8(%rbp)
mov    %r15,0x10(%rbp)
mov    %rcx,0x18(%rbp)
mov    %rax,0x20(%rbp)
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i32, i8*, i8**, i64, i8** }
@ENOMEM = global i32 0
@NO_RECOVERY = global i32 0
@NSS_STATUS_TRYAGAIN = global i32 0
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@in6addr_loopback = constant i8 0
@NSS_STATUS_SUCCESS = global i32 0
define i32 @_fill_hostent(i8* %0, i32 %1, %struct.hostent* %2, i8* %3, i64 %4, i32* %5, i32* %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca %struct.hostent*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i64
%21 = alloca i64
%22 = alloca i64
%23 = alloca i64
store i8* %0, i8** %9
store i32 %1, i32* %10
store %struct.hostent* %2, %struct.hostent** %11
store i8* %3, i8** %12
store i64 %4, i64* %13
store i32* %5, i32** %14
store i32* %6, i32** %15
%24 = load i32, i32* %10
%25 = call i64 @PROTO_ADDRESS_SIZE(i32 %24)
store i64 %25, i64* %23
%26 = load i8*, i8** %9
%27 = call i64 @strlen(i8* %26)
store i64 %27, i64* %20
%28 = load i64, i64* %20
%29 = add i64 %28, 1
%30 = add i64 %29, 8
%31 = sub i64 %30, 1
%32 = udiv i64 %31, 8
%33 = mul i64 %32, 8
%34 = add i64 %33, 8
store i64 %34, i64* %22
%35 = load i64, i64* %13
%36 = load i64, i64* %22
%37 = icmp ult i64 %35, %36
br i1 %37, label %38, label %44
38: ; preds = %7
%39 = load i32, i32* @ENOMEM
%40 = load i32*, i32** %14
store i32 %39, i32* %40
%41 = load i32, i32* @NO_RECOVERY
%42 = load i32*, i32** %15
store i32 %41, i32* %42
%43 = load i32, i32* @NSS_STATUS_TRYAGAIN
store i32 %43, i32* %8
br label %119
44: ; preds = %7
%45 = load i8*, i8** %12
store i8* %45, i8** %17
%46 = load i8*, i8** %17
%47 = load i8*, i8** %9
%48 = load i64, i64* %20
%49 = add i64 %48, 1
%50 = trunc i64 %49 to i32
%51 = call i32 @memcpy(i8* %46, i8* %47, i32 %50)
%52 = load i64, i64* %20
%53 = add i64 %52, 1
%54 = add i64 %53, 8
%55 = sub i64 %54, 1
%56 = udiv i64 %55, 8
%57 = mul i64 %56, 8
store i64 %57, i64* %21
%58 = load i8*, i8** %12
%59 = load i64, i64* %21
%60 = getelementptr inbounds i8, i8* %58, i64 %59
store i8* %60, i8** %18
%61 = load i8*, i8** %18
%62 = bitcast i8* %61 to i8**
store i8* null, i8** %62
%63 = load i64, i64* %21
%64 = add i64 %63, 8
store i64 %64, i64* %21
%65 = load i8*, i8** %12
%66 = load i64, i64* %21
%67 = getelementptr inbounds i8, i8* %65, i64 %66
store i8* %67, i8** %16
%68 = load i32, i32* %10
%69 = load i32, i32* @AF_INET
%70 = icmp eq i32 %68, %69
br i1 %70, label %71, label %78
71: ; preds = %44
%72 = load i32, i32* @AF_INET
%73 = load %struct.hostent*, %struct.hostent** %11
%74 = getelementptr inbounds %struct.hostent, %struct.hostent* %73, i32 0, i32 0
store i32 %72, i32* %74
%75 = call i32 @htonl(i32 2130706434)
%76 = load i8*, i8** %16
%77 = bitcast i8* %76 to i32*
store i32 %75, i32* %77
br label %84
78: ; preds = %44
%79 = load i32, i32* @AF_INET6
%80 = load %struct.hostent*, %struct.hostent** %11
%81 = getelementptr inbounds %struct.hostent, %struct.hostent* %80, i32 0, i32 0
store i32 %79, i32* %81
%82 = load i8*, i8** %16
%83 = call i32 @memcpy(i8* %82, i8* @in6addr_loopback, i32 16)
br label %84
84: ; preds = %78, %71
%85 = load i64, i64* %23
%86 = add i64 %85, 8
%87 = sub i64 %86, 1
%88 = udiv i64 %87, 8
%89 = mul i64 %88, 8
%90 = load i64, i64* %21
%91 = add i64 %90, %89
store i64 %91, i64* %21
%92 = load i8*, i8** %12
%93 = load i64, i64* %21
%94 = getelementptr inbounds i8, i8* %92, i64 %93
store i8* %94, i8** %19
%95 = load i8*, i8** %16
%96 = load i8*, i8** %19
%97 = bitcast i8* %96 to i8**
%98 = getelementptr inbounds i8*, i8** %97, i64 0
store i8* %95, i8** %98
%99 = load i8*, i8** %19
%100 = bitcast i8* %99 to i8**
%101 = getelementptr inbounds i8*, i8** %100, i64 1
store i8* null, i8** %101
%102 = load i64, i64* %21
%103 = add i64 %102, 16
store i64 %103, i64* %21
%104 = load i8*, i8** %17
%105 = load %struct.hostent*, %struct.hostent** %11
%106 = getelementptr inbounds %struct.hostent, %struct.hostent* %105, i32 0, i32 1
store i8* %104, i8** %106
%107 = load i8*, i8** %18
%108 = bitcast i8* %107 to i8**
%109 = load %struct.hostent*, %struct.hostent** %11
%110 = getelementptr inbounds %struct.hostent, %struct.hostent* %109, i32 0, i32 2
store i8** %108, i8*** %110
%111 = load i64, i64* %23
%112 = load %struct.hostent*, %struct.hostent** %11
%113 = getelementptr inbounds %struct.hostent, %struct.hostent* %112, i32 0, i32 3
store i64 %111, i64* %113
%114 = load i8*, i8** %19
%115 = bitcast i8* %114 to i8**
%116 = load %struct.hostent*, %struct.hostent** %11
%117 = getelementptr inbounds %struct.hostent, %struct.hostent* %116, i32 0, i32 4
store i8** %115, i8*** %117
%118 = load i32, i32* @NSS_STATUS_SUCCESS
store i32 %118, i32* %8
br label %119
119: ; preds = %84, %38
%120 = load i32, i32* %8
ret i32 %120
}

LLVM IR (-O2):
%struct.hostent = type { i32, i8*, i8**, i64, i8** }
@ENOMEM = global i32 0
@NO_RECOVERY = global i32 0
@NSS_STATUS_TRYAGAIN = global i32 0
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@in6addr_loopback = constant i8 0
@NSS_STATUS_SUCCESS = global i32 0
define i32 @_fill_hostent(i8* %0, i32 %1, %struct.hostent* nocapture writeonly %2, i8* %3, i64 %4, i32* nocapture writeonly %5, i32* nocapture writeonly %6) {
%8 = tail call i64 @PROTO_ADDRESS_SIZE(i32 %1)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%10 = add i64 %9, 8
%11 = and i64 %10, -8
%12 = add i64 %11, 8
%13 = icmp ugt i64 %12, %4
br i1 %13, label %14, label %17
14: ; preds = %7
%15 = load i32, i32* @ENOMEM
store i32 %15, i32* %5
%16 = load i32, i32* @NO_RECOVERY
store i32 %16, i32* %6
br label %48
17: ; preds = %7
%18 = trunc i64 %9 to i32
%19 = add i32 %18, 1
%20 = tail call i32 @memcpy(i8* %3, i8* %0, i32 %19)
%21 = getelementptr inbounds i8, i8* %3, i64 %11
%22 = bitcast i8* %21 to i8**
store i8* null, i8** %22
%23 = getelementptr inbounds i8, i8* %3, i64 %12
%24 = load i32, i32* @AF_INET
%25 = icmp eq i32 %24, %1
br i1 %25, label %26, label %30
26: ; preds = %17
%27 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 0
store i32 %1, i32* %27
%28 = tail call i32 @htonl(i32 2130706434)
%29 = bitcast i8* %23 to i32*
store i32 %28, i32* %29
br label %34
30: ; preds = %17
%31 = load i32, i32* @AF_INET6
%32 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 0
store i32 %31, i32* %32
%33 = tail call i32 @memcpy(i8* %23, i8* @in6addr_loopback, i32 16)
br label %34
34: ; preds = %30, %26
%35 = add i64 %8, 7
%36 = and i64 %35, -8
%37 = add i64 %12, %36
%38 = getelementptr inbounds i8, i8* %3, i64 %37
%39 = bitcast i8* %38 to i8**
store i8* %23, i8** %39
%40 = getelementptr inbounds i8, i8* %38, i64 8
%41 = bitcast i8* %40 to i8**
store i8* null, i8** %41
%42 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 1
store i8* %3, i8** %42
%43 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 2
%44 = bitcast i8*** %43 to i8**
store i8* %21, i8** %44
%45 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 3
store i64 %8, i64* %45
%46 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 4
%47 = bitcast i8*** %46 to i8**
store i8* %38, i8** %47
br label %48
48: ; preds = %34, %14
%49 = phi i32* [ @NSS_STATUS_TRYAGAIN, %14 ], [ @NSS_STATUS_SUCCESS, %34 ]
%50 = load i32, i32* %49
ret i32 %50
}