#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 in_addr {
  int dummy;
};
struct hostent {
  char *h_name;
  char **h_aliases;
  int h_length;
  char **h_addr_list;
  int /*<<< orphan*/ h_addrtype;
};
typedef scalar_t__ buf;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ ERANGE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
struct hostent *fake_hostent(const char *hostname, struct in_addr addr,
                             struct hostent *result, char *buf, int bufsize,
                             int *errval) {
  int len = strlen(hostname);
  char *name, *addr_ptr;
  if ((((char *)(((((long)((((char *)(((((long)((((char *)(((((long)(buf)-1) /
                                                             sizeof(char)) +
                                                            1) *
                                                           sizeof(char))) +
                                                 (len + 1) * sizeof(char))) -
                                         1) /
                                        sizeof(addr)) +
                                       1) *
                                      sizeof(addr))) +
                            (1) * sizeof(addr))) -
                    1) /
                   sizeof(char *)) +
                  1) *
                 sizeof(char *))) +
       (3) * sizeof(char *)) > buf + bufsize) {
    errno = ERANGE;
    return NULL;
  }
  strcpy(buf, hostname);
  name = buf;
  buf = ((char *)(((((long)(buf + len + 1) - 1) / sizeof(addr)) + 1) *
                  sizeof(addr)));
  *((struct in_addr *)buf) = addr;
  addr_ptr = buf;
  buf = ((char *)(((((long)(buf + sizeof(addr)) - 1) / sizeof(char *)) + 1) *
                  sizeof(char *)));
  ((char **)buf)[0] = addr_ptr;
  ((char **)buf)[1] = NULL;
  ((char **)buf)[2] = NULL;
  result->h_name = name;
  result->h_aliases = ((char **)buf) + 2;
  result->h_addrtype = AF_INET;
  result->h_length = sizeof(addr);
  result->h_addr_list = (char **)buf;
  return result;
}


x86 assembly (clang, -O0):
<fake_hostent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %esi,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
shr    $0x0,%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
shl    $0x0,%rcx
add    %rcx,%rax
sub    $0x1,%rax
shr    $0x2,%rax
add    $0x1,%rax
shl    $0x2,%rax
add    $0x4,%rax
sub    $0x1,%rax
shr    $0x3,%rax
add    $0x1,%rax
shl    $0x3,%rax
add    $0x18,%rax
mov    -0x28(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jbe    11ca <fake_hostent+0xaa>
mov    0x2e2e(%rip),%rax
mov    (%rax),%ecx
mov    0x2e15(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    129c <fake_hostent+0x17c>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
sub    $0x1,%rax
shr    $0x2,%rax
add    $0x1,%rax
shl    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rax
add    $0x4,%rax
sub    $0x1,%rax
shr    $0x3,%rax
add    $0x1,%rax
shl    $0x3,%rax
mov    %rax,-0x28(%rbp)
mov    -0x50(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0x48(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rcx
add    $0x10,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    0x2d74(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x20(%rax)
mov    -0x20(%rbp),%rax
movl   $0x4,0x10(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fake_hostent>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r12d
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%r13
call   1040 <strlen@plt>
movslq %eax,%rbp
lea    (%rbx,%rbp,1),%rax
add    $0x4,%rax
and    $0xfffffffffffffffc,%rax
add    $0xb,%rax
and    $0xfffffffffffffff8,%rax
add    $0x18,%rax
movslq %r12d,%rcx
add    %rbx,%rcx
cmp    %rcx,%rax
jbe    117c <fake_hostent+0x5c>
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
mov    0x2e5b(%rip),%rcx
mov    %eax,(%rcx)
xor    %r14d,%r14d
jmp    11cc <fake_hostent+0xac>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
lea    (%rbx,%rbp,1),%rax
add    $0x4,%rax
and    $0xfffffffffffffffc,%rax
mov    %r15d,(%rax)
lea    0xb(%rax),%rcx
and    $0xfffffffffffffff8,%rcx
mov    %rax,(%rcx)
lea    0x10(%rcx),%rax
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rcx)
mov    %rbx,(%r14)
mov    %rax,0x8(%r14)
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%r14)
movl   $0x4,0x10(%r14)
mov    %rcx,0x18(%r14)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.hostent = type { i8*, i8**, i32, i8**, i32 }
%struct.in_addr = type { i32 }
@ERANGE = global i32 0
@errno = global i32 0
@AF_INET = global i32 0
define %struct.hostent* @fake_hostent(i8* %0, i32 %1, %struct.hostent* writeonly %2, i8* %3, i32 %4, i32* nocapture readnone %5) {
%7 = tail call i32 @strlen(i8* %0)
%8 = add nsw i32 %7, 1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %3, i64 %9
%11 = ptrtoint i8* %10 to i64
%12 = add i64 %11, 3
%13 = and i64 %12, -4
%14 = inttoptr i64 %13 to i8*
%15 = getelementptr inbounds i8, i8* %14, i64 4
%16 = ptrtoint i8* %15 to i64
%17 = add i64 %16, 7
%18 = and i64 %17, -8
%19 = inttoptr i64 %18 to i8*
%20 = getelementptr inbounds i8, i8* %19, i64 24
%21 = sext i32 %4 to i64
%22 = getelementptr inbounds i8, i8* %3, i64 %21
%23 = icmp ugt i8* %20, %22
br i1 %23, label %24, label %26
24: ; preds = %6
%25 = load i32, i32* @ERANGE
store i32 %25, i32* @errno
br label %51
26: ; preds = %6
%27 = tail call i32 @strcpy(i8* %3, i8* %0)
%28 = sext i32 %7 to i64
%29 = getelementptr inbounds i8, i8* %3, i64 %28
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = ptrtoint i8* %30 to i64
%32 = add i64 %31, 3
%33 = and i64 %32, -4
%34 = inttoptr i64 %33 to i8*
%35 = inttoptr i64 %33 to %struct.in_addr*
%36 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %35, i64 0, i32 0
store i32 %1, i32* %36
%37 = getelementptr inbounds i8, i8* %34, i64 4
%38 = ptrtoint i8* %37 to i64
%39 = add i64 %38, 7
%40 = and i64 %39, -8
%41 = inttoptr i64 %40 to i8**
store i8* %34, i8** %41
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = getelementptr inbounds i8*, i8** %41, i64 2
%44 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 0
%45 = bitcast i8** %42 to i8*
store i8* %3, i8** %44
%46 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 1
store i8** %43, i8*** %46
%47 = load i32, i32* @AF_INET
%48 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 4
store i32 %47, i32* %48
%49 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 2
store i32 4, i32* %49
%50 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 3
store i8** %41, i8*** %50
br label %51
51: ; preds = %26, %24
%52 = phi %struct.hostent* [ null, %24 ], [ %2, %26 ]
ret %struct.hostent* %52
}