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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, void const *, char *);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
void pack_hostent(struct hostent *result, char *buffer, size_t buflen,
                  const char *name, const void *addr) {
  char *aliases, *r_addr, *addrlist;
  size_t l, idx;
  l = strlen(name);
  result->h_name = buffer;
  memcpy(result->h_name, name, l);
  buffer[l] = '\0';
  idx = (((l + 1 + sizeof(void *) - 1) / sizeof(void *)) * sizeof(void *));
  aliases = buffer + idx;
  *(char **)aliases = NULL;
  idx += sizeof(char *);
  result->h_aliases = (char **)aliases;
  result->h_addrtype = AF_INET;
  result->h_length = sizeof(struct in_addr);
  r_addr = buffer + idx;
  inet_pton(AF_INET, addr, r_addr);
  idx += (((result->h_length + sizeof(void *) - 1) / sizeof(void *)) *
          sizeof(void *));
  addrlist = buffer + idx;
  ((char **)addrlist)[0] = r_addr;
  ((char **)addrlist)[1] = NULL;
  result->h_addr_list = (char **)addrlist;
}


x86 assembly (clang, -O0):
<pack_hostent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x48(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
add    $0x8,%rax
sub    $0x1,%rax
shr    $0x3,%rax
shl    $0x3,%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
add    -0x50(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x50(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    0x2e12(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x20(%rax)
mov    -0x8(%rbp),%rax
movl   $0x4,0x10(%rax)
mov    -0x10(%rbp),%rax
add    -0x50(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1050 <inet_pton@plt>
mov    -0x8(%rbp),%rax
movslq 0x10(%rax),%rax
add    $0x8,%rax
sub    $0x1,%rax
shr    $0x3,%rax
shl    $0x3,%rax
add    -0x50(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
add    -0x50(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x40(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x18(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pack_hostent>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %r8,%r12
mov    %rcx,%r13
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rcx,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r15,(%r14)
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rax,%rdx
call   1040 <memcpy@plt>
movb   $0x0,(%r15,%rbx,1)
add    $0x8,%rbx
and    $0xfffffffffffffff8,%rbx
lea    (%r15,%rbx,1),%rax
movq   $0x0,(%r15,%rbx,1)
mov    %rax,0x8(%r14)
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    %edi,0x20(%r14)
movl   $0x4,0x10(%r14)
lea    (%r15,%rbx,1),%r13
add    $0x8,%r13
mov    %r12,%rsi
mov    %r13,%rdx
call   1050 <inet_pton@plt>
movslq 0x10(%r14),%rax
add    $0x7,%rax
and    $0xfffffffffffffff8,%rax
add    %rbx,%rax
add    $0x8,%rax
lea    (%r15,%rax,1),%rcx
mov    %r13,(%r15,%rax,1)
movq   $0x0,0x8(%r15,%rax,1)
mov    %rcx,0x18(%r14)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.hostent = type { i8*, i8**, i32, i8**, i32 }
@AF_INET = global i32 0
define void @pack_hostent(%struct.hostent* %0, i8* %1, i64 %2, i8* %3, i8* %4) {
%6 = alloca %struct.hostent*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i64
store %struct.hostent* %0, %struct.hostent** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%16 = load i8*, i8** %9
%17 = call i64 @strlen(i8* %16)
store i64 %17, i64* %14
%18 = load i8*, i8** %7
%19 = load %struct.hostent*, %struct.hostent** %6
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %19, i32 0, i32 0
store i8* %18, i8** %20
%21 = load %struct.hostent*, %struct.hostent** %6
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = load i8*, i8** %9
%25 = load i64, i64* %14
%26 = call i32 @memcpy(i8* %23, i8* %24, i64 %25)
%27 = load i8*, i8** %7
%28 = load i64, i64* %14
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8 0, i8* %29
%30 = load i64, i64* %14
%31 = add i64 %30, 1
%32 = add i64 %31, 8
%33 = sub i64 %32, 1
%34 = udiv i64 %33, 8
%35 = mul i64 %34, 8
store i64 %35, i64* %15
%36 = load i8*, i8** %7
%37 = load i64, i64* %15
%38 = getelementptr inbounds i8, i8* %36, i64 %37
store i8* %38, i8** %11
%39 = load i8*, i8** %11
%40 = bitcast i8* %39 to i8**
store i8* null, i8** %40
%41 = load i64, i64* %15
%42 = add i64 %41, 8
store i64 %42, i64* %15
%43 = load i8*, i8** %11
%44 = bitcast i8* %43 to i8**
%45 = load %struct.hostent*, %struct.hostent** %6
%46 = getelementptr inbounds %struct.hostent, %struct.hostent* %45, i32 0, i32 1
store i8** %44, i8*** %46
%47 = load i32, i32* @AF_INET
%48 = load %struct.hostent*, %struct.hostent** %6
%49 = getelementptr inbounds %struct.hostent, %struct.hostent* %48, i32 0, i32 4
store i32 %47, i32* %49
%50 = load %struct.hostent*, %struct.hostent** %6
%51 = getelementptr inbounds %struct.hostent, %struct.hostent* %50, i32 0, i32 2
store i32 4, i32* %51
%52 = load i8*, i8** %7
%53 = load i64, i64* %15
%54 = getelementptr inbounds i8, i8* %52, i64 %53
store i8* %54, i8** %12
%55 = load i32, i32* @AF_INET
%56 = load i8*, i8** %10
%57 = load i8*, i8** %12
%58 = call i32 @inet_pton(i32 %55, i8* %56, i8* %57)
%59 = load %struct.hostent*, %struct.hostent** %6
%60 = getelementptr inbounds %struct.hostent, %struct.hostent* %59, i32 0, i32 2
%61 = load i32, i32* %60
%62 = sext i32 %61 to i64
%63 = add i64 %62, 8
%64 = sub i64 %63, 1
%65 = udiv i64 %64, 8
%66 = mul i64 %65, 8
%67 = load i64, i64* %15
%68 = add i64 %67, %66
store i64 %68, i64* %15
%69 = load i8*, i8** %7
%70 = load i64, i64* %15
%71 = getelementptr inbounds i8, i8* %69, i64 %70
store i8* %71, i8** %13
%72 = load i8*, i8** %12
%73 = load i8*, i8** %13
%74 = bitcast i8* %73 to i8**
%75 = getelementptr inbounds i8*, i8** %74, i64 0
store i8* %72, i8** %75
%76 = load i8*, i8** %13
%77 = bitcast i8* %76 to i8**
%78 = getelementptr inbounds i8*, i8** %77, i64 1
store i8* null, i8** %78
%79 = load i8*, i8** %13
%80 = bitcast i8* %79 to i8**
%81 = load %struct.hostent*, %struct.hostent** %6
%82 = getelementptr inbounds %struct.hostent, %struct.hostent* %81, i32 0, i32 3
store i8** %80, i8*** %82
ret void
}

LLVM IR (-O2):
%struct.hostent = type { i8*, i8**, i32, i8**, i32 }
@AF_INET = global i32 0
define void @pack_hostent(%struct.hostent* nocapture %0, i8* %1, i64 %2, i8* %3, i8* %4) {
%6 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%7 = getelementptr inbounds %struct.hostent, %struct.hostent* %0, i64 0, i32 0
store i8* %1, i8** %7
%8 = tail call i32 @memcpy(i8* %1, i8* %3, i64 %6)
%9 = getelementptr inbounds i8, i8* %1, i64 %6
store i8 0, i8* %9
%10 = add i64 %6, 8
%11 = and i64 %10, -8
%12 = getelementptr inbounds i8, i8* %1, i64 %11
%13 = bitcast i8* %12 to i8**
store i8* null, i8** %13
%14 = add i64 %11, 8
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %0, i64 0, i32 1
%16 = bitcast i8*** %15 to i8**
store i8* %12, i8** %16
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %0, i64 0, i32 4
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %0, i64 0, i32 2
store i32 4, i32* %19
%20 = getelementptr inbounds i8, i8* %1, i64 %14
%21 = tail call i32 @inet_pton(i32 %17, i8* %4, i8* %20)
%22 = load i32, i32* %19
%23 = sext i32 %22 to i64
%24 = add nsw i64 %23, 7
%25 = and i64 %24, -8
%26 = add i64 %25, %14
%27 = getelementptr inbounds i8, i8* %1, i64 %26
%28 = bitcast i8* %27 to i8**
store i8* %20, i8** %28
%29 = getelementptr inbounds i8, i8* %27, i64 8
%30 = bitcast i8* %29 to i8**
store i8* null, i8** %30
%31 = getelementptr inbounds %struct.hostent, %struct.hostent* %0, i64 0, i32 3
%32 = bitcast i8*** %31 to i8**
store i8* %27, i8** %32
ret void
}