#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 int /*<<< orphan*/ int32_t;
typedef int /*<<< orphan*/ hn;
typedef enum nss_status { ____Placeholder_nss_status } nss_status;

/* Variables and functions */
int AF_INET;
int AF_INET6;
int AF_UNSPEC;
int EAFNOSUPPORT;
int ENOENT;
int /*<<< orphan*/ HOST_NAME_MAX;
int HOST_NOT_FOUND;
int NO_DATA;
int NO_RECOVERY;
int NSS_STATUS_NOTFOUND;
int NSS_STATUS_UNAVAIL;
int errno;
int fill_in_hostent(char *, int, struct hostent *, char *, size_t, int *, int *,
                    int /*<<< orphan*/ *, char **);
scalar_t__ gethostname(char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ strcasecmp(char const *, char *);
enum nss_status _nss_myhostname_gethostbyname3_r(const char *name, int af,
                                                 struct hostent *host,
                                                 char *buffer, size_t buflen,
                                                 int *errnop, int *h_errnop,
                                                 int32_t *ttlp, char **canonp) {
  char hn[HOST_NAME_MAX + 1];
  if (af == AF_UNSPEC)
    af = AF_INET;
  if (af != AF_INET && af != AF_INET6) {
    *errnop = EAFNOSUPPORT;
    *h_errnop = NO_DATA;
    return NSS_STATUS_UNAVAIL;
  }
  memset(hn, 0, sizeof(hn));
  if (gethostname(hn, sizeof(hn) - 1) < 0) {
    *errnop = errno;
    *h_errnop = NO_RECOVERY;
    return NSS_STATUS_UNAVAIL;
  }
  if (strcasecmp(name, hn) != 0) {
    *errnop = ENOENT;
    *h_errnop = HOST_NOT_FOUND;
    return NSS_STATUS_NOTFOUND;
  }
  return fill_in_hostent(hn, af, host, buffer, buflen, errnop, h_errnop, ttlp,
                         canonp);
}


x86 assembly (clang, -O0):
<_nss_myhostname_gethostbyname3_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
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    0x2e5e(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,-0x60(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e30(%rip),%rcx
cmp    (%rcx),%eax
jne    11bc <_nss_myhostname_gethostbyname3_r+0x7c>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e22(%rip),%rcx
cmp    (%rcx),%eax
je     1216 <_nss_myhostname_gethostbyname3_r+0xd6>
mov    -0x14(%rbp),%eax
mov    0x2df0(%rip),%rcx
cmp    (%rcx),%eax
je     1216 <_nss_myhostname_gethostbyname3_r+0xd6>
mov    0x2db1(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2daa(%rip),%rax
mov    (%rax),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2ddb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    130f <_nss_myhostname_gethostbyname3_r+0x1cf>
mov    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%rax
sub    $0x1,%rax
mov    %eax,%esi
call   1060 <gethostname@plt>
cmp    $0x0,%rax
jge    127a <_nss_myhostname_gethostbyname3_r+0x13a>
mov    0x2d5d(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2d56(%rip),%rax
mov    (%rax),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2d77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    130f <_nss_myhostname_gethostbyname3_r+0x1cf>
mov    -0x58(%rbp),%rsi
mov    -0x10(%rbp),%rdi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
je     12c7 <_nss_myhostname_gethostbyname3_r+0x187>
mov    0x2ce8(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2d19(%rip),%rax
mov    (%rax),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2cda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    130f <_nss_myhostname_gethostbyname3_r+0x1cf>
mov    -0x58(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x38(%rbp),%r9
mov    0x10(%rbp),%r11
mov    0x18(%rbp),%r10
mov    0x20(%rbp),%rax
sub    $0x20,%rsp
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1040 <fill_in_hostent@plt>
add    $0x20,%rsp
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_nss_myhostname_gethostbyname3_r>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r13
mov    %rdx,%r9
mov    %esi,%ebx
mov    %rdi,%r14
mov    0x10(%rbp),%rsi
mov    0x2e69(%rip),%rax
mov    (%rax),%r12d
lea    0x1(%r12),%edx
mov    %rsp,%r15
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    0x2e51(%rip),%rax
cmp    %ebx,(%rax)
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
cmove  %eax,%ebx
cmp    %eax,%ebx
je     11be <_nss_myhostname_gethostbyname3_r+0x7e>
mov    0x2e28(%rip),%rax
cmp    (%rax),%ebx
je     11be <_nss_myhostname_gethostbyname3_r+0x7e>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x0(%r13)
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsi)
jmp    1235 <_nss_myhostname_gethostbyname3_r+0xf5>
mov    %r9,-0x30(%rbp)
mov    %rcx,-0x38(%rbp)
mov    %r8,-0x40(%rbp)
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %r15,%rdi
mov    %r12d,%esi
call   1060 <gethostname@plt>
test   %rax,%rax
js     1219 <_nss_myhostname_gethostbyname3_r+0xd9>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     124d <_nss_myhostname_gethostbyname3_r+0x10d>
mov    0x2d85(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x0(%r13)
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
mov    0x10(%rbp),%rcx
mov    %eax,(%rcx)
mov    0x2d79(%rip),%rax
jmp    123c <_nss_myhostname_gethostbyname3_r+0xfc>
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x0(%r13)
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
mov    0x10(%rbp),%rcx
mov    %eax,(%rcx)
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
sub    $0x8,%rsp
mov    %r15,%rdi
mov    %ebx,%esi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%r8
mov    %r13,%r9
push   0x20(%rbp)
push   0x18(%rbp)
push   0x10(%rbp)
call   1040 <fill_in_hostent@plt>
add    $0x20,%rsp
jmp    123e <_nss_myhostname_gethostbyname3_r+0xfe>

LLVM IR (-O0):
%struct.hostent = type { i32 }
@HOST_NAME_MAX = global i32 0
@AF_UNSPEC = global i32 0
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@EAFNOSUPPORT = global i32 0
@NO_DATA = global i32 0
@NSS_STATUS_UNAVAIL = global i32 0
@errno = global i32 0
@NO_RECOVERY = global i32 0
@ENOENT = global i32 0
@HOST_NOT_FOUND = global i32 0
@NSS_STATUS_NOTFOUND = global i32 0
define i32 @_nss_myhostname_gethostbyname3_r(i8* %0, i32 %1, %struct.hostent* %2, i8* %3, i64 %4, i32* %5, i32* %6, i32* %7, i8** %8) {
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca %struct.hostent*
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca i8**
%20 = alloca i8*
%21 = alloca i64
%22 = alloca i32
store i8* %0, i8** %11
store i32 %1, i32* %12
store %struct.hostent* %2, %struct.hostent** %13
store i8* %3, i8** %14
store i64 %4, i64* %15
store i32* %5, i32** %16
store i32* %6, i32** %17
store i32* %7, i32** %18
store i8** %8, i8*** %19
%23 = load i32, i32* @HOST_NAME_MAX
%24 = add nsw i32 %23, 1
%25 = zext i32 %24 to i64
%26 = call i8* @llvm.stacksave()
store i8* %26, i8** %20
%27 = alloca i8, i64 %25
store i64 %25, i64* %21
%28 = load i32, i32* %12
%29 = load i32, i32* @AF_UNSPEC
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %9
%32 = load i32, i32* @AF_INET
store i32 %32, i32* %12
br label %33
33: ; preds = %31, %9
%34 = load i32, i32* %12
%35 = load i32, i32* @AF_INET
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %47
37: ; preds = %33
%38 = load i32, i32* %12
%39 = load i32, i32* @AF_INET6
%40 = icmp ne i32 %38, %39
br i1 %40, label %41, label %47
41: ; preds = %37
%42 = load i32, i32* @EAFNOSUPPORT
%43 = load i32*, i32** %16
store i32 %42, i32* %43
%44 = load i32, i32* @NO_DATA
%45 = load i32*, i32** %17
store i32 %44, i32* %45
%46 = load i32, i32* @NSS_STATUS_UNAVAIL
store i32 %46, i32* %10
store i32 1, i32* %22
br label %80
47: ; preds = %37, %33
%48 = trunc i64 %25 to i32
%49 = call i32 @memset(i8* %27, i32 0, i32 %48)
%50 = sub i64 %25, 1
%51 = trunc i64 %50 to i32
%52 = call i64 @gethostname(i8* %27, i32 %51)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %60
54: ; preds = %47
%55 = load i32, i32* @errno
%56 = load i32*, i32** %16
store i32 %55, i32* %56
%57 = load i32, i32* @NO_RECOVERY
%58 = load i32*, i32** %17
store i32 %57, i32* %58
%59 = load i32, i32* @NSS_STATUS_UNAVAIL
store i32 %59, i32* %10
store i32 1, i32* %22
br label %80
60: ; preds = %47
%61 = load i8*, i8** %11
%62 = call i64 @strcasecmp(i8* %61, i8* %27)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %70
64: ; preds = %60
%65 = load i32, i32* @ENOENT
%66 = load i32*, i32** %16
store i32 %65, i32* %66
%67 = load i32, i32* @HOST_NOT_FOUND
%68 = load i32*, i32** %17
store i32 %67, i32* %68
%69 = load i32, i32* @NSS_STATUS_NOTFOUND
store i32 %69, i32* %10
store i32 1, i32* %22
br label %80
70: ; preds = %60
%71 = load i32, i32* %12
%72 = load %struct.hostent*, %struct.hostent** %13
%73 = load i8*, i8** %14
%74 = load i64, i64* %15
%75 = load i32*, i32** %16
%76 = load i32*, i32** %17
%77 = load i32*, i32** %18
%78 = load i8**, i8*** %19
%79 = call i32 @fill_in_hostent(i8* %27, i32 %71, %struct.hostent* %72, i8* %73, i64 %74, i32* %75, i32* %76, i32* %77, i8** %78)
store i32 %79, i32* %10
store i32 1, i32* %22
br label %80
80: ; preds = %70, %64, %54, %41
%81 = load i8*, i8** %20
%82 = load i32, i32* %10
ret i32 %82
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
@HOST_NAME_MAX = global i32 0
@AF_UNSPEC = global i32 0
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@EAFNOSUPPORT = global i32 0
@NO_DATA = global i32 0
@NSS_STATUS_UNAVAIL = global i32 0
@errno = global i32 0
@NO_RECOVERY = global i32 0
@ENOENT = global i32 0
@HOST_NOT_FOUND = global i32 0
@NSS_STATUS_NOTFOUND = global i32 0
define i32 @_nss_myhostname_gethostbyname3_r(i8* nocapture %0, i32 %1, %struct.hostent* %2, i8* %3, i64 %4, i32* %5, i32* %6, i32* %7, i8** %8) {
%10 = load i32, i32* @HOST_NAME_MAX
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = alloca i8, i64 %12
%14 = load i32, i32* @AF_UNSPEC
%15 = icmp eq i32 %14, %1
%16 = load i32, i32* @AF_INET
%17 = select i1 %15, i32 %16, i32 %1
%18 = icmp eq i32 %17, %16
%19 = load i32, i32* @AF_INET6
%20 = icmp eq i32 %17, %19
%21 = select i1 %18, i1 true, i1 %20
br i1 %21, label %26, label %22
22: ; preds = %9
%23 = load i32, i32* @EAFNOSUPPORT
store i32 %23, i32* %5
%24 = load i32, i32* @NO_DATA
store i32 %24, i32* %6
%25 = load i32, i32* @NSS_STATUS_UNAVAIL
br label %43
26: ; preds = %9
%27 = call i32 @memset(i8* %13, i32 0, i32 %11)
%28 = call i64 @gethostname(i8* %13, i32 %10)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i32, i32* @errno
store i32 %31, i32* %5
%32 = load i32, i32* @NO_RECOVERY
store i32 %32, i32* %6
%33 = load i32, i32* @NSS_STATUS_UNAVAIL
br label %43
34: ; preds = %26
%35 = call i64 @strcasecmp(i8* %0, i8* %13)
%36 = icmp eq i64 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %34
%38 = load i32, i32* @ENOENT
store i32 %38, i32* %5
%39 = load i32, i32* @HOST_NOT_FOUND
store i32 %39, i32* %6
%40 = load i32, i32* @NSS_STATUS_NOTFOUND
br label %43
41: ; preds = %34
%42 = call i32 @fill_in_hostent(i8* %13, i32 %17, %struct.hostent* %2, i8* %3, i64 %4, i32* %5, i32* %6, i32* %7, i8** %8)
br label %43
43: ; preds = %41, %37, %30, %22
%44 = phi i32 [ %25, %22 ], [ %33, %30 ], [ %40, %37 ], [ %42, %41 ]
ret i32 %44
}