#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;
};
typedef enum nss_status { ____Placeholder_nss_status } nss_status;

/* Variables and functions */
int AF_INET;
int EAFNOSUPPORT;
int ENOENT;
int HOST_NOT_FOUND;
int NO_DATA;
int NSS_STATUS_NOTFOUND;
int NSS_STATUS_SUCCESS;
int NSS_STATUS_UNAVAIL;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int errno;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ pack_hostent(struct hostent *, char *, size_t, char const *,
                                char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
enum nss_status _nss_etcd_gethostbyname2_r(const char *name, int af,
                                           struct hostent *result, char *buffer,
                                           size_t buflen, int *errnop,
                                           int *h_errnop) {
  int pid, pipes[2], rv;
  char addr[256];
  int last_err;
  char **args;
  if (af != AF_INET) {
    *errnop = EAFNOSUPPORT;
    *h_errnop = NO_DATA;
    return NSS_STATUS_UNAVAIL;
  }
  pipe(pipes);
  if (0 == (pid = fork())) {
    args = (char **)calloc(sizeof(char *), 4);
    if (args < 0)
      goto CHILD_ERR;
    args[0] = (char *)calloc(sizeof(char), 8);
    strcpy(args[0], "etcdctl");
    args[1] = (char *)calloc(sizeof(char), 4);
    strcpy(args[1], "get");
    args[2] = (char *)calloc(sizeof(char), strlen(name) + 7);
    strcpy(args[2], "/hosts/");
    strcpy(args[2] + 7, name);
    args[3] = NULL;
    close(pipes[0]);
    close(0);
    close(2);
    dup2(pipes[1], 1);
    execvp("etcdctl", args);
  CHILD_ERR:
    last_err = errno;
    perror("etcdctl");
    exit(last_err);
  } else if (pid > 0) {
    close(pipes[1]);
    if (0 > read(pipes[0], addr, 255)) {
      last_err = errno;
      perror("read");
      *errnop = last_err;
      *h_errnop = NO_DATA;
      return NSS_STATUS_NOTFOUND;
    } else {
      int len = strlen(addr);
      addr[len - 1] = '\0';
    }
    waitpid(pid, &rv, 0);
    if (rv) {
      *errnop = ENOENT;
      *h_errnop = HOST_NOT_FOUND;
      return NSS_STATUS_NOTFOUND;
    }
  } else {
    last_err = errno;
    perror("fork");
    *errnop = last_err;
    *h_errnop = NO_DATA;
    return NSS_STATUS_UNAVAIL;
  }
  pack_hostent(result, buffer, buflen, name, addr);
  return NSS_STATUS_SUCCESS;
}


x86 assembly (clang, -O0):
<_nss_etcd_gethostbyname2_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%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),%eax
mov    0x2de8(%rip),%rcx
cmp    (%rcx),%eax
je     1237 <_nss_etcd_gethostbyname2_r+0x67>
mov    0x2da1(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2d9a(%rip),%rax
mov    (%rax),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1508 <_nss_etcd_gethostbyname2_r+0x338>
lea    -0x44(%rbp),%rdi
call   1080 <pipe@plt>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x3c(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jne    13a8 <_nss_etcd_gethostbyname2_r+0x1d8>
mov    $0x8,%edi
mov    $0x4,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x160(%rbp)
cmpq   $0x0,-0x160(%rbp)
jae    127f <_nss_etcd_gethostbyname2_r+0xaf>
jmp    1382 <_nss_etcd_gethostbyname2_r+0x1b2>
mov    $0x1,%edi
mov    $0x8,%esi
call   10a0 <calloc@plt>
mov    %rax,%rcx
mov    -0x160(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x160(%rbp),%rax
mov    (%rax),%rdi
lea    0xd54(%rip),%rsi
call   1030 <strcpy@plt>
mov    $0x1,%edi
mov    $0x4,%esi
call   10a0 <calloc@plt>
mov    %rax,%rcx
mov    -0x160(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x160(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd28(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%esi
add    $0x7,%esi
mov    $0x1,%edi
call   10a0 <calloc@plt>
mov    %rax,%rcx
mov    -0x160(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x160(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xcef(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x160(%rbp),%rax
mov    0x10(%rax),%rdi
add    $0x7,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x160(%rbp),%rax
movq   $0x0,0x18(%rax)
mov    -0x44(%rbp),%edi
call   1070 <close@plt>
xor    %edi,%edi
call   1070 <close@plt>
mov    $0x2,%edi
call   1070 <close@plt>
mov    -0x40(%rbp),%edi
mov    $0x1,%esi
call   1060 <dup2@plt>
mov    -0x160(%rbp),%rsi
lea    0xc83(%rip),%rdi
call   10d0 <execvp@plt>
mov    0x2c37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x154(%rbp)
lea    0xc68(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x154(%rbp),%edi
call   10e0 <exit@plt>
cmpl   $0x0,-0x3c(%rbp)
jle    1494 <_nss_etcd_gethostbyname2_r+0x2c4>
mov    -0x40(%rbp),%edi
call   1070 <close@plt>
mov    -0x44(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0xff,%edx
call   1090 <read@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    1423 <_nss_etcd_gethostbyname2_r+0x253>
mov    0x2bdd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x154(%rbp)
lea    0xc22(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x154(%rbp),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2bae(%rip),%rax
mov    (%rax),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2b8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1508 <_nss_etcd_gethostbyname2_r+0x338>
lea    -0x150(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x164(%rbp)
mov    -0x164(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x150(%rbp,%rax,1)
mov    -0x3c(%rbp),%edi
lea    -0x48(%rbp),%rsi
xor    %edx,%edx
call   10b0 <waitpid@plt>
cmpl   $0x0,-0x48(%rbp)
je     148f <_nss_etcd_gethostbyname2_r+0x2bf>
mov    0x2b31(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2b62(%rip),%rax
mov    (%rax),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2b23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1508 <_nss_etcd_gethostbyname2_r+0x338>
jmp    14db <_nss_etcd_gethostbyname2_r+0x30b>
mov    0x2b25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x154(%rbp)
lea    0xb6f(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x154(%rbp),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2af6(%rip),%rax
mov    (%rax),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2b0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1508 <_nss_etcd_gethostbyname2_r+0x338>
jmp    14e0 <_nss_etcd_gethostbyname2_r+0x310>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x150(%rbp),%r8
call   1040 <pack_hostent@plt>
mov    0x2acd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_nss_etcd_gethostbyname2_r>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %r9,%rbx
mov    %rcx,%r12
mov    0x160(%rsp),%rcx
mov    0x2df2(%rip),%rax
cmp    %esi,(%rax)
jne    12a1 <_nss_etcd_gethostbyname2_r+0xd1>
mov    %r8,%r15
mov    %rdx,%r13
mov    %rdi,%r14
lea    0xc(%rsp),%rdi
call   1080 <pipe@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     1340 <_nss_etcd_gethostbyname2_r+0x170>
jle    12f3 <_nss_etcd_gethostbyname2_r+0x123>
mov    %eax,%ebp
mov    %r14,0x18(%rsp)
mov    0x10(%rsp),%edi
call   1070 <close@plt>
mov    0xc(%rsp),%edi
lea    0x20(%rsp),%r14
mov    %r14,%rsi
mov    $0xff,%edx
call   1090 <read@plt>
test   %rax,%rax
js     131d <_nss_etcd_gethostbyname2_r+0x14d>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
lea    0x14(%rsp),%rsi
mov    %ebp,%edi
xor    %edx,%edx
call   10b0 <waitpid@plt>
cmpl   $0x0,0x14(%rsp)
je     12c0 <_nss_etcd_gethostbyname2_r+0xf0>
mov    0x2d17(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rbx)
mov    0x2d4c(%rip),%rax
mov    (%rax),%eax
mov    0x160(%rsp),%rcx
mov    %eax,(%rcx)
mov    0x2d09(%rip),%rax
jmp    12df <_nss_etcd_gethostbyname2_r+0x10f>
mov    0x2d08(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rbx)
mov    0x2d05(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rcx)
mov    0x2d22(%rip),%rax
jmp    12df <_nss_etcd_gethostbyname2_r+0x10f>
lea    0x20(%rsp),%r8
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    0x18(%rsp),%rcx
call   1040 <pack_hostent@plt>
mov    0x2cf1(%rip),%rax
mov    (%rax),%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cc6(%rip),%rax
mov    (%rax),%ebp
lea    0xd16(%rip),%rdi
call   10c0 <perror@plt>
mov    %ebp,(%rbx)
mov    0x2ca7(%rip),%rax
mov    (%rax),%eax
mov    0x160(%rsp),%rcx
jmp    12b5 <_nss_etcd_gethostbyname2_r+0xe5>
mov    0x2c9c(%rip),%rax
mov    (%rax),%ebp
lea    0xce7(%rip),%rdi
call   10c0 <perror@plt>
mov    %ebp,(%rbx)
mov    0x2c7d(%rip),%rax
jmp    128c <_nss_etcd_gethostbyname2_r+0xbc>
mov    $0x8,%edi
mov    $0x4,%esi
call   10a0 <calloc@plt>
mov    %rax,%rbx
mov    $0x1,%edi
mov    $0x8,%esi
call   10a0 <calloc@plt>
mov    %rax,(%rbx)
lea    0xc95(%rip),%r15
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    $0x1,%edi
mov    $0x4,%esi
call   10a0 <calloc@plt>
mov    %rax,0x8(%rbx)
lea    0xc78(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x7(%rax),%esi
mov    $0x1,%edi
call   10a0 <calloc@plt>
mov    %rax,0x10(%rbx)
lea    0xc54(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    0x10(%rbx),%rdi
add    $0x7,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
movq   $0x0,0x18(%rbx)
mov    0xc(%rsp),%edi
call   1070 <close@plt>
xor    %edi,%edi
call   1070 <close@plt>
mov    $0x2,%edi
call   1070 <close@plt>
mov    0x10(%rsp),%edi
mov    $0x1,%esi
call   1060 <dup2@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10d0 <execvp@plt>
mov    0x2bae(%rip),%rax
mov    (%rax),%ebx
mov    %r15,%rdi
call   10c0 <perror@plt>
mov    %ebx,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i32 }
@AF_INET = global i32 0
@EAFNOSUPPORT = global i32 0
@NO_DATA = global i32 0
@NSS_STATUS_UNAVAIL = global i32 0
@.str = [8 x i8] c"etcdctl\00"
@.str.1 = [4 x i8] c"get\00"
@.str.2 = [8 x i8] c"/hosts/\00"
@errno = global i32 0
@.str.3 = [5 x i8] c"read\00"
@NSS_STATUS_NOTFOUND = global i32 0
@ENOENT = global i32 0
@HOST_NOT_FOUND = global i32 0
@.str.4 = [5 x i8] c"fork\00"
@NSS_STATUS_SUCCESS = global i32 0
define i32 @_nss_etcd_gethostbyname2_r(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 i32
%17 = alloca [2 x i32]
%18 = alloca i32
%19 = alloca [256 x i8]
%20 = alloca i32
%21 = alloca i8**
%22 = alloca i32
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
%23 = load i32, i32* %10
%24 = load i32, i32* @AF_INET
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %32
26: ; preds = %7
%27 = load i32, i32* @EAFNOSUPPORT
%28 = load i32*, i32** %14
store i32 %27, i32* %28
%29 = load i32, i32* @NO_DATA
%30 = load i32*, i32** %15
store i32 %29, i32* %30
%31 = load i32, i32* @NSS_STATUS_UNAVAIL
store i32 %31, i32* %8
br label %150
32: ; preds = %7
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %17, i64 0, i64 0
%34 = call i32 @pipe(i32* %33)
%35 = call i32 (...) @fork()
store i32 %35, i32* %16
%36 = icmp eq i32 0, %35
br i1 %36, label %37, label %94
37: ; preds = %32
%38 = call i64 @calloc(i32 8, i32 4)
%39 = inttoptr i64 %38 to i8**
store i8** %39, i8*** %21
%40 = load i8**, i8*** %21
%41 = icmp ult i8** %40, null
br i1 %41, label %42, label %43
42: ; preds = %37
br label %89
43: ; preds = %37
%44 = call i64 @calloc(i32 1, i32 8)
%45 = inttoptr i64 %44 to i8*
%46 = load i8**, i8*** %21
%47 = getelementptr inbounds i8*, i8** %46, i64 0
store i8* %45, i8** %47
%48 = load i8**, i8*** %21
%49 = getelementptr inbounds i8*, i8** %48, i64 0
%50 = load i8*, i8** %49
%51 = call i32 @strcpy(i8* %50, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%52 = call i64 @calloc(i32 1, i32 4)
%53 = inttoptr i64 %52 to i8*
%54 = load i8**, i8*** %21
%55 = getelementptr inbounds i8*, i8** %54, i64 1
store i8* %53, i8** %55
%56 = load i8**, i8*** %21
%57 = getelementptr inbounds i8*, i8** %56, i64 1
%58 = load i8*, i8** %57
%59 = call i32 @strcpy(i8* %58, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%60 = load i8*, i8** %9
%61 = call i32 @strlen(i8* %60)
%62 = add nsw i32 %61, 7
%63 = call i64 @calloc(i32 1, i32 %62)
%64 = inttoptr i64 %63 to i8*
%65 = load i8**, i8*** %21
%66 = getelementptr inbounds i8*, i8** %65, i64 2
store i8* %64, i8** %66
%67 = load i8**, i8*** %21
%68 = getelementptr inbounds i8*, i8** %67, i64 2
%69 = load i8*, i8** %68
%70 = call i32 @strcpy(i8* %69, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%71 = load i8**, i8*** %21
%72 = getelementptr inbounds i8*, i8** %71, i64 2
%73 = load i8*, i8** %72
%74 = getelementptr inbounds i8, i8* %73, i64 7
%75 = load i8*, i8** %9
%76 = call i32 @strcpy(i8* %74, i8* %75)
%77 = load i8**, i8*** %21
%78 = getelementptr inbounds i8*, i8** %77, i64 3
store i8* null, i8** %78
%79 = getelementptr inbounds [2 x i32], [2 x i32]* %17, i64 0, i64 0
%80 = load i32, i32* %79
%81 = call i32 @close(i32 %80)
%82 = call i32 @close(i32 0)
%83 = call i32 @close(i32 2)
%84 = getelementptr inbounds [2 x i32], [2 x i32]* %17, i64 0, i64 1
%85 = load i32, i32* %84
%86 = call i32 @dup2(i32 %85, i32 1)
%87 = load i8**, i8*** %21
%88 = call i32 @execvp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %87)
br label %89
89: ; preds = %43, %42
%90 = load i32, i32* @errno
store i32 %90, i32* %20
%91 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%92 = load i32, i32* %20
%93 = call i32 @exit(i32 %92)
unreachable
94: ; preds = %32
%95 = load i32, i32* %16
%96 = icmp sgt i32 %95, 0
br i1 %96, label %97, label %133
97: ; preds = %94
%98 = getelementptr inbounds [2 x i32], [2 x i32]* %17, i64 0, i64 1
%99 = load i32, i32* %98
%100 = call i32 @close(i32 %99)
%101 = getelementptr inbounds [2 x i32], [2 x i32]* %17, i64 0, i64 0
%102 = load i32, i32* %101
%103 = getelementptr inbounds [256 x i8], [256 x i8]* %19, i64 0, i64 0
%104 = call i64 @read(i32 %102, i8* %103, i32 255)
%105 = icmp sgt i64 0, %104
br i1 %105, label %106, label %114
106: ; preds = %97
%107 = load i32, i32* @errno
store i32 %107, i32* %20
%108 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%109 = load i32, i32* %20
%110 = load i32*, i32** %14
store i32 %109, i32* %110
%111 = load i32, i32* @NO_DATA
%112 = load i32*, i32** %15
store i32 %111, i32* %112
%113 = load i32, i32* @NSS_STATUS_NOTFOUND
store i32 %113, i32* %8
br label %150
114: ; preds = %97
%115 = getelementptr inbounds [256 x i8], [256 x i8]* %19, i64 0, i64 0
%116 = call i32 @strlen(i8* %115)
store i32 %116, i32* %22
%117 = load i32, i32* %22
%118 = sub nsw i32 %117, 1
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds [256 x i8], [256 x i8]* %19, i64 0, i64 %119
store i8 0, i8* %120
br label %121
121: ; preds = %114
%122 = load i32, i32* %16
%123 = call i32 @waitpid(i32 %122, i32* %18, i32 0)
%124 = load i32, i32* %18
%125 = icmp ne i32 %124, 0
br i1 %125, label %126, label %132
126: ; preds = %121
%127 = load i32, i32* @ENOENT
%128 = load i32*, i32** %14
store i32 %127, i32* %128
%129 = load i32, i32* @HOST_NOT_FOUND
%130 = load i32*, i32** %15
store i32 %129, i32* %130
%131 = load i32, i32* @NSS_STATUS_NOTFOUND
store i32 %131, i32* %8
br label %150
132: ; preds = %121
br label %141
133: ; preds = %94
%134 = load i32, i32* @errno
store i32 %134, i32* %20
%135 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%136 = load i32, i32* %20
%137 = load i32*, i32** %14
store i32 %136, i32* %137
%138 = load i32, i32* @NO_DATA
%139 = load i32*, i32** %15
store i32 %138, i32* %139
%140 = load i32, i32* @NSS_STATUS_UNAVAIL
store i32 %140, i32* %8
br label %150
141: ; preds = %132
br label %142
142: ; preds = %141
%143 = load %struct.hostent*, %struct.hostent** %11
%144 = load i8*, i8** %12
%145 = load i64, i64* %13
%146 = load i8*, i8** %9
%147 = getelementptr inbounds [256 x i8], [256 x i8]* %19, i64 0, i64 0
%148 = call i32 @pack_hostent(%struct.hostent* %143, i8* %144, i64 %145, i8* %146, i8* %147)
%149 = load i32, i32* @NSS_STATUS_SUCCESS
store i32 %149, i32* %8
br label %150
150: ; preds = %142, %133, %126, %106, %26
%151 = load i32, i32* %8
ret i32 %151
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
@AF_INET = global i32 0
@EAFNOSUPPORT = global i32 0
@NO_DATA = global i32 0
@NSS_STATUS_UNAVAIL = global i32 0
@.str = [8 x i8] c"etcdctl\00"
@.str.1 = [4 x i8] c"get\00"
@.str.2 = [8 x i8] c"/hosts/\00"
@errno = global i32 0
@.str.3 = [5 x i8] c"read\00"
@NSS_STATUS_NOTFOUND = global i32 0
@ENOENT = global i32 0
@HOST_NOT_FOUND = global i32 0
@.str.4 = [5 x i8] c"fork\00"
@NSS_STATUS_SUCCESS = global i32 0
define i32 @_nss_etcd_gethostbyname2_r(i8* %0, i32 %1, %struct.hostent* %2, i8* %3, i64 %4, i32* nocapture writeonly %5, i32* nocapture writeonly %6) {
%8 = alloca [2 x i32]
%9 = alloca i32
%10 = alloca [256 x i8]
%11 = bitcast [2 x i32]* %8 to i8*
%12 = bitcast i32* %9 to i8*
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%14 = load i32, i32* @AF_INET
%15 = icmp eq i32 %14, %1
br i1 %15, label %19, label %16
16: ; preds = %7
%17 = load i32, i32* @EAFNOSUPPORT
store i32 %17, i32* %5
%18 = load i32, i32* @NO_DATA
store i32 %18, i32* %6
br label %85
19: ; preds = %7
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%21 = call i32 @pipe(i32* %20)
%22 = call i32 (...) @fork()
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %55
24: ; preds = %19
%25 = call i64 @calloc(i32 8, i32 4)
%26 = inttoptr i64 %25 to i8**
%27 = call i64 @calloc(i32 1, i32 8)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %26
%29 = call i32 @strcpy(i8* %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%30 = call i64 @calloc(i32 1, i32 4)
%31 = inttoptr i64 %30 to i8*
%32 = getelementptr inbounds i8*, i8** %26, i64 1
store i8* %31, i8** %32
%33 = call i32 @strcpy(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @strlen(i8* %0)
%35 = add nsw i32 %34, 7
%36 = call i64 @calloc(i32 1, i32 %35)
%37 = inttoptr i64 %36 to i8*
%38 = getelementptr inbounds i8*, i8** %26, i64 2
store i8* %37, i8** %38
%39 = call i32 @strcpy(i8* %37, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%40 = load i8*, i8** %38
%41 = getelementptr inbounds i8, i8* %40, i64 7
%42 = call i32 @strcpy(i8* %41, i8* %0)
%43 = getelementptr inbounds i8*, i8** %26, i64 3
store i8* null, i8** %43
%44 = load i32, i32* %20
%45 = call i32 @close(i32 %44)
%46 = call i32 @close(i32 0)
%47 = call i32 @close(i32 2)
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%49 = load i32, i32* %48
%50 = call i32 @dup2(i32 %49, i32 1)
%51 = call i32 @execvp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %26)
%52 = load i32, i32* @errno
%53 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%54 = call i32 @exit(i32 %52)
unreachable
55: ; preds = %19
%56 = icmp sgt i32 %22, 0
br i1 %56, label %57, label %79
57: ; preds = %55
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%59 = load i32, i32* %58
%60 = call i32 @close(i32 %59)
%61 = load i32, i32* %20
%62 = call i64 @read(i32 %61, i8* %13, i32 255)
%63 = icmp slt i64 %62, 0
br i1 %63, label %64, label %68
64: ; preds = %57
%65 = load i32, i32* @errno
%66 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 %65, i32* %5
%67 = load i32, i32* @NO_DATA
store i32 %67, i32* %6
br label %85
68: ; preds = %57
%69 = call i32 @strlen(i8* %13)
%70 = add nsw i32 %69, -1
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %71
store i8 0, i8* %72
%73 = call i32 @waitpid(i32 %22, i32* %9, i32 0)
%74 = load i32, i32* %9
%75 = icmp eq i32 %74, 0
br i1 %75, label %83, label %76
76: ; preds = %68
%77 = load i32, i32* @ENOENT
store i32 %77, i32* %5
%78 = load i32, i32* @HOST_NOT_FOUND
store i32 %78, i32* %6
br label %85
79: ; preds = %55
%80 = load i32, i32* @errno
%81 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store i32 %80, i32* %5
%82 = load i32, i32* @NO_DATA
store i32 %82, i32* %6
br label %85
83: ; preds = %68
%84 = call i32 @pack_hostent(%struct.hostent* %2, i8* %3, i64 %4, i8* %0, i8* %13)
br label %85
85: ; preds = %83, %79, %76, %64, %16
%86 = phi i32* [ @NSS_STATUS_UNAVAIL, %16 ], [ @NSS_STATUS_NOTFOUND, %64 ], [ @NSS_STATUS_NOTFOUND, %76 ], [ @NSS_STATUS_SUCCESS, %83 ], [ @NSS_STATUS_UNAVAIL, %79 ]
%87 = load i32, i32* %86
ret i32 %87
}