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

/* Variables and functions */
int AF_INET;
int AF_INET6;
int AF_UNSPEC;
int EAFNOSUPPORT;
int NO_DATA;
int NSS_STATUS_UNAVAIL;
int get_hostent(char const *, int, struct hostent *, char *, size_t, int *,
                int *, int /*<<< orphan*/ *, char **);
enum nss_status _nss_ddnss_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) {
  if (af == AF_UNSPEC)
    af = AF_INET;
  if (af != AF_INET && af != AF_INET6) {
    *errnop = EAFNOSUPPORT;
    *h_errnop = NO_DATA;
    return NSS_STATUS_UNAVAIL;
  }
  return get_hostent(name, af, host, buffer, buflen, errnop, h_errnop, ttlp,
                     canonp);
}


x86 assembly (clang, -O0):
<_nss_ddnss_gethostbyname3_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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    -0x14(%rbp),%eax
mov    0x2e93(%rip),%rcx
cmp    (%rcx),%eax
jne    1159 <_nss_ddnss_gethostbyname3_r+0x49>
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e85(%rip),%rcx
cmp    (%rcx),%eax
je     11ac <_nss_ddnss_gethostbyname3_r+0x9c>
mov    -0x14(%rbp),%eax
mov    0x2e5b(%rip),%rcx
cmp    (%rcx),%eax
je     11ac <_nss_ddnss_gethostbyname3_r+0x9c>
mov    0x2e34(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2e2d(%rip),%rax
mov    (%rax),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11e5 <_nss_ddnss_gethostbyname3_r+0xd5>
mov    -0x10(%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
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1030 <get_hostent@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_nss_ddnss_gethostbyname3_r>:
mov    0x2ec1(%rip),%rax
cmp    %esi,(%rax)
mov    0x2ec8(%rip),%rax
mov    (%rax),%eax
cmove  %eax,%esi
cmp    %eax,%esi
je     115a <_nss_ddnss_gethostbyname3_r+0x4a>
mov    0x2ea0(%rip),%rax
cmp    (%rax),%esi
je     115a <_nss_ddnss_gethostbyname3_r+0x4a>
mov    0x8(%rsp),%rax
mov    0x2e78(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,(%r9)
mov    0x2e74(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,(%rax)
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
ret
jmp    1030 <get_hostent@plt>

LLVM IR (-O0):
%struct.hostent = type { i32 }
@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
define i32 @_nss_ddnss_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**
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
%20 = load i32, i32* %12
%21 = load i32, i32* @AF_UNSPEC
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %9
%24 = load i32, i32* @AF_INET
store i32 %24, i32* %12
br label %25
25: ; preds = %23, %9
%26 = load i32, i32* %12
%27 = load i32, i32* @AF_INET
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %39
29: ; preds = %25
%30 = load i32, i32* %12
%31 = load i32, i32* @AF_INET6
%32 = icmp ne i32 %30, %31
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = load i32, i32* @EAFNOSUPPORT
%35 = load i32*, i32** %16
store i32 %34, i32* %35
%36 = load i32, i32* @NO_DATA
%37 = load i32*, i32** %17
store i32 %36, i32* %37
%38 = load i32, i32* @NSS_STATUS_UNAVAIL
store i32 %38, i32* %10
br label %50
39: ; preds = %29, %25
%40 = load i8*, i8** %11
%41 = load i32, i32* %12
%42 = load %struct.hostent*, %struct.hostent** %13
%43 = load i8*, i8** %14
%44 = load i64, i64* %15
%45 = load i32*, i32** %16
%46 = load i32*, i32** %17
%47 = load i32*, i32** %18
%48 = load i8**, i8*** %19
%49 = call i32 @get_hostent(i8* %40, i32 %41, %struct.hostent* %42, i8* %43, i64 %44, i32* %45, i32* %46, i32* %47, i8** %48)
store i32 %49, i32* %10
br label %50
50: ; preds = %39, %33
%51 = load i32, i32* %10
ret i32 %51
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
@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
define i32 @_nss_ddnss_gethostbyname3_r(i8* %0, i32 %1, %struct.hostent* %2, i8* %3, i64 %4, i32* %5, i32* %6, i32* %7, i8** %8) {
%10 = load i32, i32* @AF_UNSPEC
%11 = icmp eq i32 %10, %1
%12 = load i32, i32* @AF_INET
%13 = select i1 %11, i32 %12, i32 %1
%14 = icmp eq i32 %13, %12
%15 = load i32, i32* @AF_INET6
%16 = icmp eq i32 %13, %15
%17 = select i1 %14, i1 true, i1 %16
br i1 %17, label %22, label %18
18: ; preds = %9
%19 = load i32, i32* @EAFNOSUPPORT
store i32 %19, i32* %5
%20 = load i32, i32* @NO_DATA
store i32 %20, i32* %6
%21 = load i32, i32* @NSS_STATUS_UNAVAIL
br label %24
22: ; preds = %9
%23 = tail call i32 @get_hostent(i8* %0, i32 %13, %struct.hostent* %2, i8* %3, i64 %4, i32* %5, i32* %6, i32* %7, i8** %8)
br label %24
24: ; preds = %22, %18
%25 = phi i32 [ %21, %18 ], [ %23, %22 ]
ret i32 %25
}