#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 EAGAIN;
int NO_RECOVERY;
int NSS_STATUS_TRYAGAIN;
int _nss_openvpn_gethostbyname_r(char const *, struct hostent *, char *, size_t,
                                 int *, int *);
enum nss_status _nss_openvpn_gethostbyname2_r(const char *name, int af,
                                              struct hostent *result,
                                              char *buffer, size_t buflen,
                                              int *errnop, int *h_errnop) {
  if (af != AF_INET) {
    *errnop = EAGAIN;
    *h_errnop = NO_RECOVERY;
    return NSS_STATUS_TRYAGAIN;
  } else {
    return _nss_openvpn_gethostbyname_r(name, result, buffer, buflen, errnop,
                                        h_errnop);
  }
}


x86 assembly (clang, -O0):
<_nss_openvpn_gethostbyname2_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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    0x2eab(%rip),%rcx
cmp    (%rcx),%eax
je     1174 <_nss_openvpn_gethostbyname2_r+0x64>
mov    0x2e74(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2e75(%rip),%rax
mov    (%rax),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1194 <_nss_openvpn_gethostbyname2_r+0x84>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    0x10(%rbp),%r9
call   1030 <_nss_openvpn_gethostbyname_r@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_nss_openvpn_gethostbyname2_r>:
mov    0x8(%rsp),%r10
mov    0x2ecc(%rip),%rax
cmp    %esi,(%rax)
jne    1134 <_nss_openvpn_gethostbyname2_r+0x24>
mov    %rdx,%rsi
mov    %rcx,%rdx
mov    %r8,%rcx
mov    %r9,%r8
mov    %r10,%r9
jmp    1030 <_nss_openvpn_gethostbyname_r@plt>
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r9)
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r10)
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
ret

LLVM IR (-O0):
%struct.hostent = type { i32 }
@AF_INET = global i32 0
@EAGAIN = global i32 0
@NO_RECOVERY = global i32 0
@NSS_STATUS_TRYAGAIN = global i32 0
define i32 @_nss_openvpn_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*
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
%16 = load i32, i32* %10
%17 = load i32, i32* @AF_INET
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %25
19: ; preds = %7
%20 = load i32, i32* @EAGAIN
%21 = load i32*, i32** %14
store i32 %20, i32* %21
%22 = load i32, i32* @NO_RECOVERY
%23 = load i32*, i32** %15
store i32 %22, i32* %23
%24 = load i32, i32* @NSS_STATUS_TRYAGAIN
store i32 %24, i32* %8
br label %33
25: ; preds = %7
%26 = load i8*, i8** %9
%27 = load %struct.hostent*, %struct.hostent** %11
%28 = load i8*, i8** %12
%29 = load i64, i64* %13
%30 = load i32*, i32** %14
%31 = load i32*, i32** %15
%32 = call i32 @_nss_openvpn_gethostbyname_r(i8* %26, %struct.hostent* %27, i8* %28, i64 %29, i32* %30, i32* %31)
store i32 %32, i32* %8
br label %33
33: ; preds = %25, %19
%34 = load i32, i32* %8
ret i32 %34
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
@AF_INET = global i32 0
@EAGAIN = global i32 0
@NO_RECOVERY = global i32 0
@NSS_STATUS_TRYAGAIN = global i32 0
define i32 @_nss_openvpn_gethostbyname2_r(i8* %0, i32 %1, %struct.hostent* %2, i8* %3, i64 %4, i32* %5, i32* %6) {
%8 = load i32, i32* @AF_INET
%9 = icmp eq i32 %8, %1
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = load i32, i32* @EAGAIN
store i32 %11, i32* %5
%12 = load i32, i32* @NO_RECOVERY
store i32 %12, i32* %6
%13 = load i32, i32* @NSS_STATUS_TRYAGAIN
br label %16
14: ; preds = %7
%15 = tail call i32 @_nss_openvpn_gethostbyname_r(i8* %0, %struct.hostent* %2, i8* %3, i64 %4, i32* %5, i32* %6)
br label %16
16: ; preds = %14, %10
%17 = phi i32 [ %13, %10 ], [ %15, %14 ]
ret i32 %17
}