#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 in6_addr {
  int dummy;
};
struct hostent {
  int h_addrtype;
  int /*<<< orphan*/ **h_addr_list;
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ **h_aliases;
  void *h_name;
};
typedef struct in6_addr in_addr_t;
typedef int /*<<< orphan*/ addr6;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
#define AF_INET 129
#define AF_INET6 128
int /*<<< orphan*/ IN6ADDRSZ;
int /*<<< orphan*/ INADDRSZ;
struct in6_addr inet_addr(char *);
int /*<<< orphan*/ inet_pton(int const, char *, struct in6_addr *);
void *malloc(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, struct in6_addr *, int);
int /*<<< orphan*/ strcpy(void *, char const *);
int strlen(char const *);
void dev_tld_fill_hostent(const char *name, int af, struct hostent *result) {
  result->h_name = malloc(sizeof(char) * strlen(name) + 1);
  strcpy(result->h_name, name);
  result->h_aliases = malloc(sizeof(char *));
  *result->h_aliases = NULL;
  result->h_addr_list = malloc(sizeof(char *) * 2);
  switch (af) {
  case AF_INET:
    result->h_addrtype = AF_INET;
    result->h_length = INADDRSZ;
    in_addr_t addr = inet_addr("127.0.0.1");
    *result->h_addr_list = malloc(sizeof(addr));
    memcpy(*result->h_addr_list, &addr, sizeof(addr));
    break;
  case AF_INET6:
    result->h_addrtype = AF_INET6;
    result->h_length = IN6ADDRSZ;
    struct in6_addr addr6 = {};
    inet_pton(AF_INET6, "::1", &addr6);
    *result->h_addr_list = malloc(sizeof(addr6));
    memcpy(*result->h_addr_list, &addr6, sizeof(addr6));
    break;
  }
  *(result->h_addr_list + 1) = NULL;
}


x86 assembly (clang, -O0):
<dev_tld_fill_hostent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    -0x18(%rbp),%rax
mov    0x20(%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    $0x8,%edi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
movq   $0x0,(%rax)
mov    $0x10,%edi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x80,%eax
je     1273 <dev_tld_fill_hostent+0x103>
jmp    1201 <dev_tld_fill_hostent+0x91>
mov    -0x2c(%rbp),%eax
sub    $0x81,%eax
jne    12e3 <dev_tld_fill_hostent+0x173>
jmp    1214 <dev_tld_fill_hostent+0xa4>
mov    -0x18(%rbp),%rax
movl   $0x81,(%rax)
mov    0x2dbb(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x10(%rax)
lea    0xdcb(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x20(%rbp)
mov    $0x4,%edi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
jmp    12e3 <dev_tld_fill_hostent+0x173>
mov    -0x18(%rbp),%rax
movl   $0x80,(%rax)
mov    0x2d4c(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x10(%rax)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    $0x80,%edi
lea    0xd61(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1080 <inet_pton@plt>
mov    $0x4,%edi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
movq   $0x0,0x8(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dev_tld_fill_hostent>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%rbp
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
mov    %rax,0x20(%rbx)
mov    %rax,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    $0x8,%edi
call   1080 <malloc@plt>
mov    %rax,0x18(%rbx)
movq   $0x0,(%rax)
mov    $0x10,%edi
call   1080 <malloc@plt>
mov    %rax,0x8(%rbx)
cmp    $0x80,%r14d
je     1207 <dev_tld_fill_hostent+0xa7>
cmp    $0x81,%r14d
jne    125c <dev_tld_fill_hostent+0xfc>
movl   $0x81,(%rbx)
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rbx)
lea    0xe21(%rip),%rdi
call   1050 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    0x8(%rbx),%rcx
mov    %rax,(%rcx)
mov    0x8(%rbx),%rax
mov    (%rax),%rdi
lea    0x8(%rsp),%rsi
jmp    1252 <dev_tld_fill_hostent+0xf2>
movl   $0x80,(%rbx)
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rbx)
movl   $0x0,(%rsp)
lea    0xde3(%rip),%rsi
mov    %rsp,%rbp
mov    $0x80,%edi
mov    %rbp,%rdx
call   1070 <inet_pton@plt>
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    0x8(%rbx),%rcx
mov    %rax,(%rcx)
mov    0x8(%rbx),%rax
mov    (%rax),%rdi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    0x8(%rbx),%rax
movq   $0x0,0x8(%rax)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i32, i32**, i32, i32**, i8* }
%struct.in6_addr = type { i32 }
@INADDRSZ = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@IN6ADDRSZ = global i32 0
@.str.1 = [4 x i8] c"::1\00"
define void @dev_tld_fill_hostent(i8* %0, i32 %1, %struct.hostent* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.hostent*
%7 = alloca %struct.in6_addr
%8 = alloca %struct.in6_addr
store i8* %0, i8** %4
store i32 %1, i32* %5
store %struct.hostent* %2, %struct.hostent** %6
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = sext i32 %10 to i64
%12 = mul i64 1, %11
%13 = add i64 %12, 1
%14 = trunc i64 %13 to i32
%15 = call i8* @malloc(i32 %14)
%16 = load %struct.hostent*, %struct.hostent** %6
%17 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i32 0, i32 4
store i8* %15, i8** %17
%18 = load %struct.hostent*, %struct.hostent** %6
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %18, i32 0, i32 4
%20 = load i8*, i8** %19
%21 = load i8*, i8** %4
%22 = call i32 @strcpy(i8* %20, i8* %21)
%23 = call i8* @malloc(i32 8)
%24 = bitcast i8* %23 to i32**
%25 = load %struct.hostent*, %struct.hostent** %6
%26 = getelementptr inbounds %struct.hostent, %struct.hostent* %25, i32 0, i32 3
store i32** %24, i32*** %26
%27 = load %struct.hostent*, %struct.hostent** %6
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %27, i32 0, i32 3
%29 = load i32**, i32*** %28
store i32* null, i32** %29
%30 = call i8* @malloc(i32 16)
%31 = bitcast i8* %30 to i32**
%32 = load %struct.hostent*, %struct.hostent** %6
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %32, i32 0, i32 1
store i32** %31, i32*** %33
%34 = load i32, i32* %5
switch i32 %34, label %71 [
i32 129, label %35
i32 128, label %53
]
35: ; preds = %3
%36 = load %struct.hostent*, %struct.hostent** %6
%37 = getelementptr inbounds %struct.hostent, %struct.hostent* %36, i32 0, i32 0
store i32 129, i32* %37
%38 = load i32, i32* @INADDRSZ
%39 = load %struct.hostent*, %struct.hostent** %6
%40 = getelementptr inbounds %struct.hostent, %struct.hostent* %39, i32 0, i32 2
store i32 %38, i32* %40
%41 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%42 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %7, i32 0, i32 0
store i32 %41, i32* %42
%43 = call i8* @malloc(i32 4)
%44 = bitcast i8* %43 to i32*
%45 = load %struct.hostent*, %struct.hostent** %6
%46 = getelementptr inbounds %struct.hostent, %struct.hostent* %45, i32 0, i32 1
%47 = load i32**, i32*** %46
store i32* %44, i32** %47
%48 = load %struct.hostent*, %struct.hostent** %6
%49 = getelementptr inbounds %struct.hostent, %struct.hostent* %48, i32 0, i32 1
%50 = load i32**, i32*** %49
%51 = load i32*, i32** %50
%52 = call i32 @memcpy(i32* %51, %struct.in6_addr* %7, i32 4)
br label %71
53: ; preds = %3
%54 = load %struct.hostent*, %struct.hostent** %6
%55 = getelementptr inbounds %struct.hostent, %struct.hostent* %54, i32 0, i32 0
store i32 128, i32* %55
%56 = load i32, i32* @IN6ADDRSZ
%57 = load %struct.hostent*, %struct.hostent** %6
%58 = getelementptr inbounds %struct.hostent, %struct.hostent* %57, i32 0, i32 2
store i32 %56, i32* %58
%59 = bitcast %struct.in6_addr* %8 to i8*
%60 = call i32 @inet_pton(i32 128, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %struct.in6_addr* %8)
%61 = call i8* @malloc(i32 4)
%62 = bitcast i8* %61 to i32*
%63 = load %struct.hostent*, %struct.hostent** %6
%64 = getelementptr inbounds %struct.hostent, %struct.hostent* %63, i32 0, i32 1
%65 = load i32**, i32*** %64
store i32* %62, i32** %65
%66 = load %struct.hostent*, %struct.hostent** %6
%67 = getelementptr inbounds %struct.hostent, %struct.hostent* %66, i32 0, i32 1
%68 = load i32**, i32*** %67
%69 = load i32*, i32** %68
%70 = call i32 @memcpy(i32* %69, %struct.in6_addr* %8, i32 4)
br label %71
71: ; preds = %3, %53, %35
%72 = load %struct.hostent*, %struct.hostent** %6
%73 = getelementptr inbounds %struct.hostent, %struct.hostent* %72, i32 0, i32 1
%74 = load i32**, i32*** %73
%75 = getelementptr inbounds i32*, i32** %74, i64 1
store i32* null, i32** %75
ret void
}

LLVM IR (-O2):
%struct.hostent = type { i32, i32**, i32, i32**, i8* }
%struct.in6_addr = type { i32 }
@INADDRSZ = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@IN6ADDRSZ = global i32 0
@.str.1 = [4 x i8] c"::1\00"
define void @dev_tld_fill_hostent(i8* %0, i32 %1, %struct.hostent* nocapture %2) {
%4 = alloca %struct.in6_addr
%5 = alloca %struct.in6_addr
%6 = tail call i32 @strlen(i8* %0)
%7 = add i32 %6, 1
%8 = tail call i8* @malloc(i32 %7)
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 4
store i8* %8, i8** %9
%10 = tail call i32 @strcpy(i8* %8, i8* %0)
%11 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%12 = bitcast i8* %11 to i32**
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 3
%14 = bitcast i32*** %13 to i8**
store i8* %11, i8** %14
store i32* null, i32** %12
%15 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%16 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 1
%17 = bitcast i32*** %16 to i8**
store i8* %15, i8** %17
switch i32 %1, label %43 [
i32 129, label %18
i32 128, label %30
]
18: ; preds = %3
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 0
store i32 129, i32* %19
%20 = load i32, i32* @INADDRSZ
%21 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 2
store i32 %20, i32* %21
%22 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%23 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %4, i64 0, i32 0
store i32 %22, i32* %23
%24 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
%25 = bitcast i32*** %16 to i8***
%26 = load i8**, i8*** %25
store i8* %24, i8** %26
%27 = load i32**, i32*** %16
%28 = load i32*, i32** %27
%29 = call i32 @memcpy(i32* %28, %struct.in6_addr* %4, i32 4)
br label %43
30: ; preds = %3
%31 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 0
store i32 128, i32* %31
%32 = load i32, i32* @IN6ADDRSZ
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 2
store i32 %32, i32* %33
%34 = bitcast %struct.in6_addr* %5 to i8*
%35 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i64 0, i32 0
store i32 0, i32* %35
%36 = call i32 @inet_pton(i32 128, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %struct.in6_addr* %5)
%37 = call dereferenceable_or_null(4) i8* @malloc(i32 4)
%38 = bitcast i32*** %16 to i8***
%39 = load i8**, i8*** %38
store i8* %37, i8** %39
%40 = load i32**, i32*** %16
%41 = load i32*, i32** %40
%42 = call i32 @memcpy(i32* %41, %struct.in6_addr* %5, i32 4)
br label %43
43: ; preds = %3, %30, %18
%44 = load i32**, i32*** %16
%45 = getelementptr inbounds i32*, i32** %44, i64 1
store i32* null, i32** %45
ret void
}