#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 sockaddr_in6 {
  char sin6_addr;
};
struct sockaddr_in {
  int sin_family;
  char sin_addr;
};
struct hostent {
  char **h_addr_list;
  char **h_aliases;
  int h_addrtype;
  char *h_name;
};
typedef int socklen_t;

/* Variables and functions */
int AF_INET;
int AF_INET6;
int EAGAIN;
#define EAI_AGAIN 132
#define EAI_FAIL 131
#define EAI_MEMORY 130
#define EAI_OVERFLOW 129
#define EAI_SYSTEM 128
int EINVAL;
int ERANGE;
int NO_RECOVERY;
int TRY_AGAIN;
int errno;
int getnameinfo(void *, int, char *, size_t, int /*<<< orphan*/,
                int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, void const *, int);
int gethostbyaddr_r(const void *a, socklen_t l, int af, struct hostent *h,
                    char *buf, size_t buflen, struct hostent **res, int *err) {
  union {
    struct sockaddr_in sin;
    struct sockaddr_in6 sin6;
  } sa = {.sin.sin_family = af};
  socklen_t sl = af == AF_INET6 ? sizeof sa.sin6 : sizeof sa.sin;
  int i;
  *res = 0;
  if (af == AF_INET6 && l == 16)
    memcpy(&sa.sin6.sin6_addr, a, 16);
  else if (af == AF_INET && l == 4)
    memcpy(&sa.sin.sin_addr, a, 4);
  else {
    *err = NO_RECOVERY;
    return EINVAL;
  }
  i = (uintptr_t)buf & sizeof(char *) - 1;
  if (!i)
    i = sizeof(char *);
  if (buflen <= 5 * sizeof(char *) - i + l)
    return ERANGE;
  buf += sizeof(char *) - i;
  buflen -= 5 * sizeof(char *) - i + l;
  h->h_addr_list = (void *)buf;
  buf += 2 * sizeof(char *);
  h->h_aliases = (void *)buf;
  buf += 2 * sizeof(char *);
  h->h_addr_list[0] = buf;
  memcpy(h->h_addr_list[0], a, l);
  buf += l;
  h->h_addr_list[1] = 0;
  h->h_aliases[0] = buf;
  h->h_aliases[1] = 0;
  switch (getnameinfo((void *)&sa, sl, buf, buflen, 0, 0, 0)) {
  case EAI_AGAIN:
    *err = TRY_AGAIN;
    return EAGAIN;
  case EAI_OVERFLOW:
    return ERANGE;
  default:
  case EAI_MEMORY:
  case EAI_SYSTEM:
  case EAI_FAIL:
    *err = NO_RECOVERY;
    return errno;
  case 0:
    break;
  }
  h->h_addrtype = af;
  h->h_name = h->h_aliases[0];
  *res = h;
  return 0;
}


x86 assembly (clang, -O0):
<gethostbyaddr_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x38(%rbp)
movb   $0x0,-0x34(%rbp)
mov    -0x18(%rbp),%edx
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
mov    $0x8,%eax
mov    $0x1,%ecx
cmp    %esi,%edx
cmove  %rcx,%rax
mov    %eax,-0x3c(%rbp)
mov    0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%eax
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%eax
jne    11ad <gethostbyaddr_r+0x8d>
cmpl   $0x10,-0x14(%rbp)
jne    11ad <gethostbyaddr_r+0x8d>
lea    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
jmp    1209 <gethostbyaddr_r+0xe9>
mov    -0x18(%rbp),%eax
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%eax
jne    11e4 <gethostbyaddr_r+0xc4>
cmpl   $0x4,-0x14(%rbp)
jne    11e4 <gethostbyaddr_r+0xc4>
lea    -0x38(%rbp),%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
jmp    1204 <gethostbyaddr_r+0xe4>
mov    0x2dd5(%rip),%rax
mov    (%rax),%ecx
mov    0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    141f <gethostbyaddr_r+0x2ff>
jmp    1209 <gethostbyaddr_r+0xe9>
mov    -0x28(%rbp),%rax
and    $0x7,%rax
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jne    1225 <gethostbyaddr_r+0x105>
movl   $0x8,-0x40(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x40(%rbp),%rdx
mov    $0x28,%ecx
sub    %rdx,%rcx
movslq -0x14(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
ja     1256 <gethostbyaddr_r+0x136>
mov    0x2d8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    141f <gethostbyaddr_r+0x2ff>
movslq -0x40(%rbp),%rcx
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
movslq -0x40(%rbp),%rcx
movslq -0x14(%rbp),%rdx
mov    -0x30(%rbp),%rax
sub    %rdx,%rcx
lea    -0x28(%rax,%rcx,1),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x28(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
movslq -0x14(%rbp),%rcx
mov    -0x28(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movq   $0x0,0x8(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
movq   $0x0,0x8(%rax)
mov    -0x3c(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    %rsp,%rax
movl   $0x0,(%rax)
lea    -0x38(%rbp),%rdi
xor    %r9d,%r9d
mov    %r9d,%r8d
call   1030 <getnameinfo@plt>
mov    %eax,%ecx
mov    %ecx,-0x44(%rbp)
test   %eax,%eax
je     13eb <gethostbyaddr_r+0x2cb>
jmp    1346 <gethostbyaddr_r+0x226>
mov    -0x44(%rbp),%eax
sub    $0x80,%eax
je     13cb <gethostbyaddr_r+0x2ab>
jmp    1359 <gethostbyaddr_r+0x239>
mov    -0x44(%rbp),%eax
sub    $0x81,%eax
je     13b5 <gethostbyaddr_r+0x295>
jmp    136c <gethostbyaddr_r+0x24c>
mov    -0x44(%rbp),%eax
add    $0xffffff7e,%eax
sub    $0x2,%eax
jb     13cb <gethostbyaddr_r+0x2ab>
jmp    1382 <gethostbyaddr_r+0x262>
mov    -0x44(%rbp),%eax
sub    $0x84,%eax
jne    13c6 <gethostbyaddr_r+0x2a6>
jmp    1395 <gethostbyaddr_r+0x275>
mov    0x2c2c(%rip),%rax
mov    (%rax),%ecx
mov    0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2bf5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    141f <gethostbyaddr_r+0x2ff>
mov    0x2c1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    141f <gethostbyaddr_r+0x2ff>
jmp    13cb <gethostbyaddr_r+0x2ab>
mov    0x2bee(%rip),%rax
mov    (%rax),%ecx
mov    0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2bd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    141f <gethostbyaddr_r+0x2ff>
jmp    13f0 <gethostbyaddr_r+0x2d0>
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x20(%rbp),%rcx
mov    0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethostbyaddr_r>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r12
mov    %edx,%r13d
mov    %esi,%r15d
mov    %rdi,%rsi
mov    0x68(%rsp),%rdx
mov    0x60(%rsp),%rbx
mov    %r13d,0x10(%rsp)
movb   $0x0,0x14(%rsp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
cmp    %r13d,%eax
mov    $0x1,%edi
mov    $0x8,%ebp
cmove  %edi,%ebp
movq   $0x0,(%rbx)
cmp    $0x10,%r15d
jne    1193 <gethostbyaddr_r+0x73>
cmp    %r13d,%eax
jne    1193 <gethostbyaddr_r+0x73>
mov    %ebp,0xc(%rsp)
mov    %rcx,0x20(%rsp)
lea    0x10(%rsp),%rdi
mov    %rsi,0x18(%rsp)
mov    $0x10,%edx
jmp    11c5 <gethostbyaddr_r+0xa5>
cmp    $0x4,%r15d
jne    12ad <gethostbyaddr_r+0x18d>
mov    0x2e44(%rip),%rax
cmp    %r13d,(%rax)
jne    12ad <gethostbyaddr_r+0x18d>
mov    %ebp,0xc(%rsp)
mov    %rcx,0x20(%rsp)
lea    0x14(%rsp),%rdi
mov    %rsi,0x18(%rsp)
mov    $0x4,%edx
mov    %r9,%rbp
call   1040 <memcpy@plt>
mov    %rbp,%rbx
mov    %r12d,%ecx
and    $0x7,%ecx
mov    $0x8,%eax
cmovne %ecx,%eax
mov    %r15d,%r14d
mov    %r14,%rcx
sub    %rax,%rcx
add    $0x28,%rcx
cmp    %rbp,%rcx
jae    12a4 <gethostbyaddr_r+0x184>
sub    %rax,%r12
lea    0x8(%r12),%rax
sub    %rcx,%rbx
mov    0x20(%rsp),%rbp
mov    %rax,0x0(%rbp)
lea    0x18(%r12),%rax
mov    %rax,0x8(%rbp)
lea    0x28(%r12),%rax
mov    %rax,0x8(%r12)
mov    0x0(%rbp),%rax
mov    (%rax),%rdi
mov    0x18(%rsp),%rsi
mov    %r15d,%edx
mov    %rbx,%r15
call   1040 <memcpy@plt>
lea    (%r12,%r14,1),%rdx
add    $0x28,%rdx
mov    0x0(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    0x8(%rbp),%rax
mov    %rdx,(%rax)
mov    0x8(%rbp),%rax
movq   $0x0,0x8(%rax)
movl   $0x0,(%rsp)
lea    0x10(%rsp),%rdi
xor    %ebx,%ebx
mov    0xc(%rsp),%esi
mov    %r15,%rcx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <getnameinfo@plt>
test   %eax,%eax
je     12c1 <gethostbyaddr_r+0x1a1>
cmp    $0x81,%eax
je     12a4 <gethostbyaddr_r+0x184>
cmp    $0x84,%eax
mov    0x68(%rsp),%rcx
jne    12da <gethostbyaddr_r+0x1ba>
mov    0x2d31(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rcx)
mov    0x2cfe(%rip),%rax
jmp    12ec <gethostbyaddr_r+0x1cc>
mov    0x2d2d(%rip),%rax
jmp    12ec <gethostbyaddr_r+0x1cc>
mov    0x2d0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rdx)
mov    0x2cf1(%rip),%rax
jmp    12ec <gethostbyaddr_r+0x1cc>
mov    %r13d,0x10(%rbp)
mov    0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,0x18(%rbp)
mov    0x60(%rsp),%rax
mov    %rbp,(%rax)
jmp    12ee <gethostbyaddr_r+0x1ce>
mov    0x2cdf(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rcx)
mov    0x2ccc(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i8**, i8**, i32, i8* }
%union.anon = type { %struct.sockaddr_in }
%struct.sockaddr_in = type { i32, i8 }
%struct.sockaddr_in6 = type { i8 }
@AF_INET6 = global i32 0
@AF_INET = global i32 0
@NO_RECOVERY = global i32 0
@EINVAL = global i32 0
@ERANGE = global i32 0
@TRY_AGAIN = global i32 0
@EAGAIN = global i32 0
@errno = global i32 0
define i32 @gethostbyaddr_r(i8* %0, i32 %1, i32 %2, %struct.hostent* %3, i8* %4, i64 %5, %struct.hostent** %6, i32* %7) {
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.hostent*
%14 = alloca i8*
%15 = alloca i64
%16 = alloca %struct.hostent**
%17 = alloca i32*
%18 = alloca %union.anon
%19 = alloca i32
%20 = alloca i32
store i8* %0, i8** %10
store i32 %1, i32* %11
store i32 %2, i32* %12
store %struct.hostent* %3, %struct.hostent** %13
store i8* %4, i8** %14
store i64 %5, i64* %15
store %struct.hostent** %6, %struct.hostent*** %16
store i32* %7, i32** %17
%21 = bitcast %union.anon* %18 to %struct.sockaddr_in*
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %21, i32 0, i32 0
%23 = load i32, i32* %12
store i32 %23, i32* %22
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %21, i32 0, i32 1
store i8 0, i8* %24
%25 = load i32, i32* %12
%26 = load i32, i32* @AF_INET6
%27 = icmp eq i32 %25, %26
%28 = zext i1 %27 to i64
%29 = select i1 %27, i64 1, i64 8
%30 = trunc i64 %29 to i32
store i32 %30, i32* %19
%31 = load %struct.hostent**, %struct.hostent*** %16
store %struct.hostent* null, %struct.hostent** %31
%32 = load i32, i32* %12
%33 = load i32, i32* @AF_INET6
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %43
35: ; preds = %8
%36 = load i32, i32* %11
%37 = icmp eq i32 %36, 16
br i1 %37, label %38, label %43
38: ; preds = %35
%39 = bitcast %union.anon* %18 to %struct.sockaddr_in6*
%40 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %39, i32 0, i32 0
%41 = load i8*, i8** %10
%42 = call i32 @memcpy(i8* %40, i8* %41, i32 16)
br label %60
43: ; preds = %35, %8
%44 = load i32, i32* %12
%45 = load i32, i32* @AF_INET
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %55
47: ; preds = %43
%48 = load i32, i32* %11
%49 = icmp eq i32 %48, 4
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = bitcast %union.anon* %18 to %struct.sockaddr_in*
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %51, i32 0, i32 1
%53 = load i8*, i8** %10
%54 = call i32 @memcpy(i8* %52, i8* %53, i32 4)
br label %59
55: ; preds = %47, %43
%56 = load i32, i32* @NO_RECOVERY
%57 = load i32*, i32** %17
store i32 %56, i32* %57
%58 = load i32, i32* @EINVAL
store i32 %58, i32* %9
br label %165
59: ; preds = %50
br label %60
60: ; preds = %59, %38
%61 = load i8*, i8** %14
%62 = ptrtoint i8* %61 to i64
%63 = and i64 %62, 7
%64 = trunc i64 %63 to i32
store i32 %64, i32* %20
%65 = load i32, i32* %20
%66 = icmp ne i32 %65, 0
br i1 %66, label %68, label %67
67: ; preds = %60
store i32 8, i32* %20
br label %68
68: ; preds = %67, %60
%69 = load i64, i64* %15
%70 = load i32, i32* %20
%71 = sext i32 %70 to i64
%72 = sub i64 40, %71
%73 = load i32, i32* %11
%74 = sext i32 %73 to i64
%75 = add i64 %72, %74
%76 = icmp ule i64 %69, %75
br i1 %76, label %77, label %79
77: ; preds = %68
%78 = load i32, i32* @ERANGE
store i32 %78, i32* %9
br label %165
79: ; preds = %68
%80 = load i32, i32* %20
%81 = sext i32 %80 to i64
%82 = sub i64 8, %81
%83 = load i8*, i8** %14
%84 = getelementptr inbounds i8, i8* %83, i64 %82
store i8* %84, i8** %14
%85 = load i32, i32* %20
%86 = sext i32 %85 to i64
%87 = sub i64 40, %86
%88 = load i32, i32* %11
%89 = sext i32 %88 to i64
%90 = add i64 %87, %89
%91 = load i64, i64* %15
%92 = sub i64 %91, %90
store i64 %92, i64* %15
%93 = load i8*, i8** %14
%94 = bitcast i8* %93 to i8**
%95 = load %struct.hostent*, %struct.hostent** %13
%96 = getelementptr inbounds %struct.hostent, %struct.hostent* %95, i32 0, i32 0
store i8** %94, i8*** %96
%97 = load i8*, i8** %14
%98 = getelementptr inbounds i8, i8* %97, i64 16
store i8* %98, i8** %14
%99 = load i8*, i8** %14
%100 = bitcast i8* %99 to i8**
%101 = load %struct.hostent*, %struct.hostent** %13
%102 = getelementptr inbounds %struct.hostent, %struct.hostent* %101, i32 0, i32 1
store i8** %100, i8*** %102
%103 = load i8*, i8** %14
%104 = getelementptr inbounds i8, i8* %103, i64 16
store i8* %104, i8** %14
%105 = load i8*, i8** %14
%106 = load %struct.hostent*, %struct.hostent** %13
%107 = getelementptr inbounds %struct.hostent, %struct.hostent* %106, i32 0, i32 0
%108 = load i8**, i8*** %107
%109 = getelementptr inbounds i8*, i8** %108, i64 0
store i8* %105, i8** %109
%110 = load %struct.hostent*, %struct.hostent** %13
%111 = getelementptr inbounds %struct.hostent, %struct.hostent* %110, i32 0, i32 0
%112 = load i8**, i8*** %111
%113 = getelementptr inbounds i8*, i8** %112, i64 0
%114 = load i8*, i8** %113
%115 = load i8*, i8** %10
%116 = load i32, i32* %11
%117 = call i32 @memcpy(i8* %114, i8* %115, i32 %116)
%118 = load i32, i32* %11
%119 = load i8*, i8** %14
%120 = sext i32 %118 to i64
%121 = getelementptr inbounds i8, i8* %119, i64 %120
store i8* %121, i8** %14
%122 = load %struct.hostent*, %struct.hostent** %13
%123 = getelementptr inbounds %struct.hostent, %struct.hostent* %122, i32 0, i32 0
%124 = load i8**, i8*** %123
%125 = getelementptr inbounds i8*, i8** %124, i64 1
store i8* null, i8** %125
%126 = load i8*, i8** %14
%127 = load %struct.hostent*, %struct.hostent** %13
%128 = getelementptr inbounds %struct.hostent, %struct.hostent* %127, i32 0, i32 1
%129 = load i8**, i8*** %128
%130 = getelementptr inbounds i8*, i8** %129, i64 0
store i8* %126, i8** %130
%131 = load %struct.hostent*, %struct.hostent** %13
%132 = getelementptr inbounds %struct.hostent, %struct.hostent* %131, i32 0, i32 1
%133 = load i8**, i8*** %132
%134 = getelementptr inbounds i8*, i8** %133, i64 1
store i8* null, i8** %134
%135 = bitcast %union.anon* %18 to i8*
%136 = load i32, i32* %19
%137 = load i8*, i8** %14
%138 = load i64, i64* %15
%139 = call i32 @getnameinfo(i8* %135, i32 %136, i8* %137, i64 %138, i32 0, i32 0, i32 0)
switch i32 %139, label %146 [
i32 132, label %140
i32 129, label %144
i32 130, label %147
i32 128, label %147
i32 131, label %147
i32 0, label %151
]
140: ; preds = %79
%141 = load i32, i32* @TRY_AGAIN
%142 = load i32*, i32** %17
store i32 %141, i32* %142
%143 = load i32, i32* @EAGAIN
store i32 %143, i32* %9
br label %165
144: ; preds = %79
%145 = load i32, i32* @ERANGE
store i32 %145, i32* %9
br label %165
146: ; preds = %79
br label %147
147: ; preds = %79, %79, %79, %146
%148 = load i32, i32* @NO_RECOVERY
%149 = load i32*, i32** %17
store i32 %148, i32* %149
%150 = load i32, i32* @errno
store i32 %150, i32* %9
br label %165
151: ; preds = %79
br label %152
152: ; preds = %151
%153 = load i32, i32* %12
%154 = load %struct.hostent*, %struct.hostent** %13
%155 = getelementptr inbounds %struct.hostent, %struct.hostent* %154, i32 0, i32 2
store i32 %153, i32* %155
%156 = load %struct.hostent*, %struct.hostent** %13
%157 = getelementptr inbounds %struct.hostent, %struct.hostent* %156, i32 0, i32 1
%158 = load i8**, i8*** %157
%159 = getelementptr inbounds i8*, i8** %158, i64 0
%160 = load i8*, i8** %159
%161 = load %struct.hostent*, %struct.hostent** %13
%162 = getelementptr inbounds %struct.hostent, %struct.hostent* %161, i32 0, i32 3
store i8* %160, i8** %162
%163 = load %struct.hostent*, %struct.hostent** %13
%164 = load %struct.hostent**, %struct.hostent*** %16
store %struct.hostent* %163, %struct.hostent** %164
store i32 0, i32* %9
br label %165
165: ; preds = %152, %147, %144, %140, %77, %55
%166 = load i32, i32* %9
ret i32 %166
}

LLVM IR (-O2):
%struct.hostent = type { i8**, i8**, i32, i8* }
%union.anon = type { %struct.sockaddr_in }
%struct.sockaddr_in = type { i32, i8 }
@AF_INET6 = global i32 0
@AF_INET = global i32 0
@NO_RECOVERY = global i32 0
@EINVAL = global i32 0
@ERANGE = global i32 0
@TRY_AGAIN = global i32 0
@EAGAIN = global i32 0
@errno = global i32 0
define i32 @gethostbyaddr_r(i8* %0, i32 %1, i32 %2, %struct.hostent* %3, i8* %4, i64 %5, %struct.hostent** nocapture writeonly %6, i32* nocapture writeonly %7) {
%9 = alloca %union.anon
%10 = bitcast %union.anon* %9 to i8*
%11 = getelementptr inbounds %union.anon, %union.anon* %9, i64 0, i32 0, i32 0
store i32 %2, i32* %11
%12 = getelementptr inbounds %union.anon, %union.anon* %9, i64 0, i32 0, i32 1
store i8 0, i8* %12
%13 = load i32, i32* @AF_INET6
%14 = icmp eq i32 %13, %2
%15 = select i1 %14, i32 1, i32 8
store %struct.hostent* null, %struct.hostent** %6
%16 = icmp eq i32 %1, 16
%17 = and i1 %16, %14
br i1 %17, label %18, label %20
18: ; preds = %8
%19 = call i32 @memcpy(i8* %10, i8* %0, i32 16)
br label %30
20: ; preds = %8
%21 = load i32, i32* @AF_INET
%22 = icmp eq i32 %21, %2
%23 = icmp eq i32 %1, 4
%24 = and i1 %23, %22
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @memcpy(i8* %12, i8* %0, i32 4)
br label %30
27: ; preds = %20
%28 = load i32, i32* @NO_RECOVERY
store i32 %28, i32* %7
%29 = load i32, i32* @EINVAL
br label %77
30: ; preds = %25, %18
%31 = ptrtoint i8* %4 to i64
%32 = trunc i64 %31 to i32
%33 = and i32 %32, 7
%34 = icmp eq i32 %33, 0
%35 = select i1 %34, i32 8, i32 %33
%36 = zext i32 %35 to i64
%37 = sub nuw nsw i64 40, %36
%38 = zext i32 %1 to i64
%39 = add nuw nsw i64 %37, %38
%40 = icmp ult i64 %39, %5
br i1 %40, label %43, label %41
41: ; preds = %30
%42 = load i32, i32* @ERANGE
br label %77
43: ; preds = %30
%44 = sub nuw nsw i64 8, %36
%45 = getelementptr inbounds i8, i8* %4, i64 %44
%46 = sub i64 %5, %39
%47 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 0
%48 = bitcast %struct.hostent* %3 to i8**
store i8* %45, i8** %48
%49 = getelementptr inbounds i8, i8* %45, i64 16
%50 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 1
%51 = bitcast i8*** %50 to i8**
store i8* %49, i8** %51
%52 = getelementptr inbounds i8, i8* %49, i64 16
%53 = bitcast i8* %45 to i8**
store i8* %52, i8** %53
%54 = load i8**, i8*** %47
%55 = load i8*, i8** %54
%56 = call i32 @memcpy(i8* %55, i8* %0, i32 %1)
%57 = getelementptr inbounds i8, i8* %52, i64 %38
%58 = load i8**, i8*** %47
%59 = getelementptr inbounds i8*, i8** %58, i64 1
store i8* null, i8** %59
%60 = load i8**, i8*** %50
store i8* %57, i8** %60
%61 = load i8**, i8*** %50
%62 = getelementptr inbounds i8*, i8** %61, i64 1
store i8* null, i8** %62
%63 = call i32 @getnameinfo(i8* %10, i32 %15, i8* %57, i64 %46, i32 0, i32 0, i32 0)
switch i32 %63, label %69 [
i32 132, label %64
i32 129, label %67
i32 0, label %72
]
64: ; preds = %43
%65 = load i32, i32* @TRY_AGAIN
store i32 %65, i32* %7
%66 = load i32, i32* @EAGAIN
br label %77
67: ; preds = %43
%68 = load i32, i32* @ERANGE
br label %77
69: ; preds = %43
%70 = load i32, i32* @NO_RECOVERY
store i32 %70, i32* %7
%71 = load i32, i32* @errno
br label %77
72: ; preds = %43
%73 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 2
store i32 %2, i32* %73
%74 = load i8**, i8*** %50
%75 = load i8*, i8** %74
%76 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 3
store i8* %75, i8** %76
store %struct.hostent* %3, %struct.hostent** %6
br label %77
77: ; preds = %72, %69, %67, %64, %41, %27
%78 = phi i32 [ %42, %41 ], [ %71, %69 ], [ 0, %72 ], [ %68, %67 ], [ %66, %64 ], [ %29, %27 ]
ret i32 %78
}