#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 AF_INET6;
int AF_UNSPEC;
int EAFNOSUPPORT;
int NO_DATA;
int NSS_STATUS_NOTFOUND;
int NSS_STATUS_UNAVAIL;
int _fill_hostent(char const *, int, struct hostent *, char *, size_t, int *,
                  int *);
scalar_t__ strcmp(char *, char const *);
int strlen(char const *);
enum nss_status _nss_devenv_gethostbyname2_r(const char *name, int af,
                                             struct hostent *result,
                                             char *buffer, size_t buflen,
                                             int *errnop, int *h_errnop) {
  if (af == AF_UNSPEC) {
    af = AF_INET;
  }
  if (af != AF_INET && af != AF_INET6) {
    *errnop = EAFNOSUPPORT;
    *h_errnop = NO_DATA;
    return NSS_STATUS_UNAVAIL;
  }
  enum nss_status status = NSS_STATUS_NOTFOUND;
  int len;
  len = strlen(name);
  if (strcmp(".dev", name + len - 4) == 0) {
    status = _fill_hostent(name, af, result, buffer, buflen, errnop, h_errnop);
  }
  return status;
}


x86 assembly (clang, -O0):
<_nss_devenv_gethostbyname2_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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    0x2e7b(%rip),%rcx
cmp    (%rcx),%eax
jne    1171 <_nss_devenv_gethostbyname2_r+0x41>
mov    0x2e7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%eax
je     11c4 <_nss_devenv_gethostbyname2_r+0x94>
mov    -0x14(%rbp),%eax
mov    0x2e43(%rip),%rcx
cmp    (%rcx),%eax
je     11c4 <_nss_devenv_gethostbyname2_r+0x94>
mov    0x2e1c(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2e15(%rip),%rax
mov    (%rax),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    122e <_nss_devenv_gethostbyname2_r+0xfe>
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rsi
movslq -0x40(%rbp),%rax
add    %rax,%rsi
add    $0xfffffffffffffffc,%rsi
lea    0xe0e(%rip),%rdi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1228 <_nss_devenv_gethostbyname2_r+0xf8>
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),%rax
mov    %rax,(%rsp)
call   1050 <_fill_hostent@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_nss_devenv_gethostbyname2_r>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r13
mov    %rcx,%r15
mov    %rdx,%r12
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2e88(%rip),%rax
cmp    %esi,(%rax)
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
cmove  %eax,%ebp
cmp    %eax,%ebp
je     1196 <_nss_devenv_gethostbyname2_r+0x66>
mov    0x2e67(%rip),%rax
cmp    (%rax),%ebp
je     1196 <_nss_devenv_gethostbyname2_r+0x66>
mov    0x40(%rsp),%rax
mov    0x2e3f(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x0(%r13)
mov    0x2e3a(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,(%rax)
mov    0x2e4f(%rip),%rax
mov    (%rax),%r14d
jmp    11c7 <_nss_devenv_gethostbyname2_r+0x97>
mov    %r8,(%rsp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%r14d
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rsi
add    $0xfffffffffffffffc,%rsi
lea    0xe43(%rip),%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11d9 <_nss_devenv_gethostbyname2_r+0xa9>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
mov    %r15,%rcx
mov    (%rsp),%r8
mov    %r13,%r9
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <_fill_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
@NSS_STATUS_NOTFOUND = global i32 0
@.str = [5 x i8] c".dev\00"
define i32 @_nss_devenv_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 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
%18 = load i32, i32* %10
%19 = load i32, i32* @AF_UNSPEC
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %7
%22 = load i32, i32* @AF_INET
store i32 %22, i32* %10
br label %23
23: ; preds = %21, %7
%24 = load i32, i32* %10
%25 = load i32, i32* @AF_INET
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %37
27: ; preds = %23
%28 = load i32, i32* %10
%29 = load i32, i32* @AF_INET6
%30 = icmp ne i32 %28, %29
br i1 %30, label %31, label %37
31: ; preds = %27
%32 = load i32, i32* @EAFNOSUPPORT
%33 = load i32*, i32** %14
store i32 %32, i32* %33
%34 = load i32, i32* @NO_DATA
%35 = load i32*, i32** %15
store i32 %34, i32* %35
%36 = load i32, i32* @NSS_STATUS_UNAVAIL
store i32 %36, i32* %8
br label %59
37: ; preds = %27, %23
%38 = load i32, i32* @NSS_STATUS_NOTFOUND
store i32 %38, i32* %16
%39 = load i8*, i8** %9
%40 = call i32 @strlen(i8* %39)
store i32 %40, i32* %17
%41 = load i8*, i8** %9
%42 = load i32, i32* %17
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = getelementptr inbounds i8, i8* %44, i64 -4
%46 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %57
48: ; preds = %37
%49 = load i8*, i8** %9
%50 = load i32, i32* %10
%51 = load %struct.hostent*, %struct.hostent** %11
%52 = load i8*, i8** %12
%53 = load i64, i64* %13
%54 = load i32*, i32** %14
%55 = load i32*, i32** %15
%56 = call i32 @_fill_hostent(i8* %49, i32 %50, %struct.hostent* %51, i8* %52, i64 %53, i32* %54, i32* %55)
store i32 %56, i32* %16
br label %57
57: ; preds = %48, %37
%58 = load i32, i32* %16
store i32 %58, i32* %8
br label %59
59: ; preds = %57, %31
%60 = load i32, i32* %8
ret i32 %60
}

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
@NSS_STATUS_NOTFOUND = global i32 0
@.str = [5 x i8] c".dev\00"
define i32 @_nss_devenv_gethostbyname2_r(i8* %0, i32 %1, %struct.hostent* %2, i8* %3, i64 %4, i32* %5, i32* %6) {
%8 = load i32, i32* @AF_UNSPEC
%9 = icmp eq i32 %8, %1
%10 = load i32, i32* @AF_INET
%11 = select i1 %9, i32 %10, i32 %1
%12 = icmp eq i32 %11, %10
%13 = load i32, i32* @AF_INET6
%14 = icmp eq i32 %11, %13
%15 = select i1 %12, i1 true, i1 %14
br i1 %15, label %20, 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
%19 = load i32, i32* @NSS_STATUS_UNAVAIL
br label %30
20: ; preds = %7
%21 = load i32, i32* @NSS_STATUS_NOTFOUND
%22 = tail call i32 @strlen(i8* %0)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = getelementptr inbounds i8, i8* %24, i64 -4
%26 = tail call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = tail call i32 @_fill_hostent(i8* %0, i32 %11, %struct.hostent* %2, i8* %3, i64 %4, i32* %5, i32* %6)
br label %30
30: ; preds = %20, %28, %16
%31 = phi i32 [ %19, %16 ], [ %29, %28 ], [ %21, %20 ]
ret i32 %31
}