#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 */
typedef int /*<<< orphan*/ uint32_t;
struct in_addr {
  int /*<<< orphan*/ s_addr;
};
struct hostent {
  char **h_aliases;
  char *h_name;
  int h_length;
  char **h_addr_list;
  int /*<<< orphan*/ h_addrtype;
};
typedef enum nss_status { ____Placeholder_nss_status } nss_status;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EINVAL;
int NO_RECOVERY;
int NSS_STATUS_SUCCESS;
int NSS_STATUS_UNAVAIL;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                             int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, struct in_addr *);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/ *, int);
char *strchr(char *, char);
scalar_t__ strcmp(char const *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
scalar_t__ strncmp(char *, char *, int);
enum nss_status _nss_openvpn_gethostbyname_r(const char *name,
                                             struct hostent *result,
                                             char *buffer, size_t buflen,
                                             int *errnop, int *h_errnop) {
  FILE *fh = fopen("/var/run/openvpn.server.status", "r");
  char *t;
  char *current_ip;
  char *current_hostname;
  size_t idx, astart;
  char strbuf[256];
  if (!fh || strcmp(name + strlen(name) - 4, ".vpn") != 0) {
    if (fh) {
      fclose(fh);
    }
    *errnop = EINVAL;
    *h_errnop = NO_RECOVERY;
    return NSS_STATUS_UNAVAIL;
  }
  int in = 0;
  while (fgets(strbuf, 256, fh)) {
    if (strncmp(strbuf, "Virtual Address", 10) == 0) {
      in = 1;
      continue;
    }
    if (strncmp(strbuf, "GLOBAL STATS", 10) == 0) {
      in = 0;
      continue;
    }
    if (!in) {
      continue;
    }
    current_ip = strbuf;
    t = strchr(current_ip, ',');
    if (t == NULL) {
      continue;
    }
    *t = 0;
    current_hostname = current_ip + strlen(current_ip) + 1;
    t = strchr(current_hostname, ',');
    if (t == NULL) {
      continue;
    }
    *t = 0;
    if (strlen(current_hostname) + 5 > 256) {
      continue;
    }
    strcpy(t, ".vpn\0");
    if (strcmp(current_hostname, name) != 0) {
      continue;
    }
    *((char **)buffer) = NULL;
    result->h_aliases = (char **)buffer;
    idx = sizeof(char *);
    strcpy(buffer + idx, name);
    result->h_name = buffer + idx;
    idx += strlen(name) + 1;
    do {
      if (idx % sizeof(void *))
        idx += (sizeof(void *) - idx % sizeof(void *));
    } while (0);
    result->h_addrtype = AF_INET;
    result->h_length = sizeof(uint32_t);
    struct in_addr addr;
    inet_pton(AF_INET, current_ip, &addr);
    char a[2000];
    inet_ntop(AF_INET, &addr.s_addr, a, 2000);
    astart = idx;
    memcpy(buffer + astart, &addr.s_addr, sizeof(uint32_t));
    idx += sizeof(uint32_t);
    result->h_addr_list = (char **)(buffer + idx);
    result->h_addr_list[0] = buffer + astart;
    result->h_addr_list[1] = NULL;
    fclose(fh);
    return NSS_STATUS_SUCCESS;
  }
  fclose(fh);
  *errnop = EINVAL;
  *h_errnop = NO_RECOVERY;
  return NSS_STATUS_UNAVAIL;
}


x86 assembly (clang, -O0):
<_nss_openvpn_gethostbyname_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x960,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
lea    0xe26(%rip),%rdi
lea    0xe3e(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     122f <_nss_openvpn_gethostbyname_r+0x7f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x958(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x958(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe01(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1272 <_nss_openvpn_gethostbyname_r+0xc2>
cmpq   $0x0,-0x40(%rbp)
je     1243 <_nss_openvpn_gethostbyname_r+0x93>
mov    -0x40(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2d6f(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1565 <_nss_openvpn_gethostbyname_r+0x3b5>
movl   $0x0,-0x174(%rbp)
lea    -0x170(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    $0x100,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     1532 <_nss_openvpn_gethostbyname_r+0x382>
lea    -0x170(%rbp),%rdi
lea    0xd7d(%rip),%rsi
mov    $0xa,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12cc <_nss_openvpn_gethostbyname_r+0x11c>
movl   $0x1,-0x174(%rbp)
jmp    127c <_nss_openvpn_gethostbyname_r+0xcc>
lea    -0x170(%rbp),%rdi
lea    0xd5c(%rip),%rsi
mov    $0xa,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12fd <_nss_openvpn_gethostbyname_r+0x14d>
movl   $0x0,-0x174(%rbp)
jmp    127c <_nss_openvpn_gethostbyname_r+0xcc>
cmpl   $0x0,-0x174(%rbp)
jne    130f <_nss_openvpn_gethostbyname_r+0x15f>
jmp    127c <_nss_openvpn_gethostbyname_r+0xcc>
lea    -0x170(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    $0x2c,%esi
call   1080 <strchr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    133c <_nss_openvpn_gethostbyname_r+0x18c>
jmp    127c <_nss_openvpn_gethostbyname_r+0xcc>
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x50(%rbp),%rax
mov    %rax,-0x960(%rbp)
mov    -0x50(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x960(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    $0x2c,%esi
call   1080 <strchr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1390 <_nss_openvpn_gethostbyname_r+0x1e0>
jmp    127c <_nss_openvpn_gethostbyname_r+0xcc>
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x58(%rbp),%rdi
call   1070 <strlen@plt>
add    $0x5,%eax
cmp    $0x100,%eax
jle    13b3 <_nss_openvpn_gethostbyname_r+0x203>
jmp    127c <_nss_openvpn_gethostbyname_r+0xcc>
mov    -0x48(%rbp),%rdi
lea    0xc85(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     13df <_nss_openvpn_gethostbyname_r+0x22f>
jmp    127c <_nss_openvpn_gethostbyname_r+0xcc>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x8,-0x60(%rbp)
mov    -0x20(%rbp),%rdi
add    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x20(%rbp),%rcx
add    -0x60(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
add    $0x1,%eax
cltq
add    -0x60(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
je     145e <_nss_openvpn_gethostbyname_r+0x2ae>
mov    -0x60(%rbp),%rcx
and    $0x7,%rcx
mov    $0x8,%eax
sub    %rcx,%rax
add    -0x60(%rbp),%rax
mov    %rax,-0x60(%rbp)
jmp    1463 <_nss_openvpn_gethostbyname_r+0x2b3>
mov    0x2b7e(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x20(%rax)
mov    -0x18(%rbp),%rax
movl   $0x4,0x10(%rax)
mov    0x2b63(%rip),%rax
mov    (%rax),%edi
mov    -0x50(%rbp),%rsi
lea    -0x178(%rbp),%rdx
call   10c0 <inet_pton@plt>
mov    0x2b4a(%rip),%rax
mov    (%rax),%edi
lea    -0x178(%rbp),%rsi
lea    -0x950(%rbp),%rdx
mov    $0x7d0,%ecx
call   1030 <inet_ntop@plt>
mov    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rdi
add    -0x68(%rbp),%rdi
lea    -0x178(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <memcpy@plt>
mov    -0x60(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rcx
add    -0x60(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x20(%rbp),%rcx
add    -0x68(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
movq   $0x0,0x8(%rax)
mov    -0x40(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2ab0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1565 <_nss_openvpn_gethostbyname_r+0x3b5>
mov    -0x40(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2a7e(%rip),%rax
mov    (%rax),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2a77(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2a80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x960,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_nss_openvpn_gethostbyname_r>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x908,%rsp
mov    %r9,%rbp
mov    %r8,%r12
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r13
lea    0xe29(%rip),%rdi
lea    0xe41(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1216 <_nss_openvpn_gethostbyname_r+0x66>
mov    %rax,%r14
mov    %r13,%rdi
call   1070 <strlen@plt>
cltq
lea    (%rax,%r13,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe1d(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1234 <_nss_openvpn_gethostbyname_r+0x84>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r12)
mov    0x2d9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x0(%rbp)
jmp    1397 <_nss_openvpn_gethostbyname_r+0x1e7>
mov    %rbp,0x20(%rsp)
mov    %rbx,0x10(%rsp)
mov    %r15,0x18(%rsp)
lea    0x30(%rsp),%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1372 <_nss_openvpn_gethostbyname_r+0x1c2>
mov    $0x1,%bpl
lea    0xdbe(%rip),%rbx
lea    0x30(%rsp),%r15
mov    %r12,0x8(%rsp)
jmp    129b <_nss_openvpn_gethostbyname_r+0xeb>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ebp,%ebp
mov    %r15,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1372 <_nss_openvpn_gethostbyname_r+0x1c2>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1280 <_nss_openvpn_gethostbyname_r+0xd0>
mov    %r15,%rdi
lea    0xd7c(%rip),%rsi
mov    $0xa,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
sete   %al
or     %al,%bpl
test   $0x1,%bpl
mov    $0x1,%bpl
jne    1282 <_nss_openvpn_gethostbyname_r+0xd2>
mov    %r15,%rdi
mov    $0x2c,%esi
call   1080 <strchr@plt>
test   %rax,%rax
je     1280 <_nss_openvpn_gethostbyname_r+0xd0>
mov    %r13,%rbx
movb   $0x0,(%rax)
mov    %r15,%rdi
call   1070 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%r13
add    $0x31,%r13
mov    %r13,%rdi
mov    $0x2c,%esi
call   1080 <strchr@plt>
test   %rax,%rax
je     1327 <_nss_openvpn_gethostbyname_r+0x177>
mov    %rax,%r12
movb   $0x0,(%rax)
mov    %r13,%rdi
call   1070 <strlen@plt>
cmp    $0xfb,%eax
jle    133d <_nss_openvpn_gethostbyname_r+0x18d>
xor    %ebp,%ebp
mov    0x8(%rsp),%r12
mov    %rbx,%r13
lea    0xcee(%rip),%rbx
jmp    1282 <_nss_openvpn_gethostbyname_r+0xd2>
mov    %r12,%rdi
lea    0xcfc(%rip),%rsi
call   1050 <strcpy@plt>
mov    %r13,%rdi
mov    %rbx,%r13
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     13b2 <_nss_openvpn_gethostbyname_r+0x202>
xor    %ebp,%ebp
mov    0x8(%rsp),%r12
lea    0xcb9(%rip),%rbx
jmp    1282 <_nss_openvpn_gethostbyname_r+0xd2>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    0x2c3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r12)
mov    0x2c3a(%rip),%rax
mov    (%rax),%eax
mov    0x20(%rsp),%rcx
mov    %eax,(%rcx)
mov    0x2c42(%rip),%rax
mov    (%rax),%eax
add    $0x908,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,%rbx
mov    0x10(%rsp),%r13
movq   $0x0,0x0(%r13)
mov    0x18(%rsp),%r12
mov    %r13,(%r12)
lea    0x8(%r13),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <strcpy@plt>
mov    %rbp,0x8(%r12)
mov    %rbx,%rdi
call   1070 <strlen@plt>
movslq %eax,%rbp
lea    0x9(%rbp),%rax
mov    %eax,%ecx
and    $0x7,%ecx
sub    %rcx,%rbp
add    $0x11,%rbp
test   %rcx,%rcx
cmove  %rax,%rbp
mov    0x2be0(%rip),%r15
mov    (%r15),%edi
mov    %edi,0x20(%r12)
movl   $0x4,0x10(%r12)
lea    0x30(%rsp),%rsi
lea    0x28(%rsp),%rbx
mov    %rbx,%rdx
call   10c0 <inet_pton@plt>
mov    (%r15),%edi
lea    0x130(%rsp),%rdx
mov    %rbx,%rsi
mov    $0x7d0,%ecx
call   1030 <inet_ntop@plt>
mov    %r13,%r15
add    %rbp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   10b0 <memcpy@plt>
lea    0x4(,%rbp,1),%rax
add    %r13,%rax
mov    %rax,0x18(%r12)
mov    %r15,0x4(%r13,%rbp,1)
mov    0x18(%r12),%rax
movq   $0x0,0x8(%rax)
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    0x2b4e(%rip),%rax
jmp    139e <_nss_openvpn_gethostbyname_r+0x1ee>

LLVM IR (-O0):
%struct.hostent = type { i8**, i8*, i32, i8**, i32 }
%struct.in_addr = type { i32 }
@.str = [31 x i8] c"/var/run/openvpn.server.status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c".vpn\00"
@EINVAL = global i32 0
@NO_RECOVERY = global i32 0
@NSS_STATUS_UNAVAIL = global i32 0
@.str.3 = [16 x i8] c"Virtual Address\00"
@.str.4 = [13 x i8] c"GLOBAL STATS\00"
@.str.5 = [6 x i8] c".vpn\00\00"
@AF_INET = global i32 0
@NSS_STATUS_SUCCESS = global i32 0
define i32 @_nss_openvpn_gethostbyname_r(i8* %0, %struct.hostent* %1, i8* %2, i64 %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca %struct.hostent*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i64
%19 = alloca i64
%20 = alloca [256 x i8]
%21 = alloca i32
%22 = alloca %struct.in_addr
%23 = alloca [2000 x i8]
store i8* %0, i8** %8
store %struct.hostent* %1, %struct.hostent** %9
store i8* %2, i8** %10
store i64 %3, i64* %11
store i32* %4, i32** %12
store i32* %5, i32** %13
%24 = call i32* @fopen(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %14
%25 = load i32*, i32** %14
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %36
27: ; preds = %6
%28 = load i8*, i8** %8
%29 = load i8*, i8** %8
%30 = call i32 @strlen(i8* %29)
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = getelementptr inbounds i8, i8* %32, i64 -4
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %48
36: ; preds = %27, %6
%37 = load i32*, i32** %14
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32*, i32** %14
%41 = call i32 @fclose(i32* %40)
br label %42
42: ; preds = %39, %36
%43 = load i32, i32* @EINVAL
%44 = load i32*, i32** %12
store i32 %43, i32* %44
%45 = load i32, i32* @NO_RECOVERY
%46 = load i32*, i32** %13
store i32 %45, i32* %46
%47 = load i32, i32* @NSS_STATUS_UNAVAIL
store i32 %47, i32* %7
br label %186
48: ; preds = %27
store i32 0, i32* %21
br label %49
49: ; preds = %102, %94, %87, %74, %67, %63, %58, %48
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %20, i64 0, i64 0
%51 = load i32*, i32** %14
%52 = call i64 @fgets(i8* %50, i32 256, i32* %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %178
54: ; preds = %49
%55 = getelementptr inbounds [256 x i8], [256 x i8]* %20, i64 0, i64 0
%56 = call i64 @strncmp(i8* %55, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 10)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %54
store i32 1, i32* %21
br label %49
59: ; preds = %54
%60 = getelementptr inbounds [256 x i8], [256 x i8]* %20, i64 0, i64 0
%61 = call i64 @strncmp(i8* %60, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 10)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %59
store i32 0, i32* %21
br label %49
64: ; preds = %59
%65 = load i32, i32* %21
%66 = icmp ne i32 %65, 0
br i1 %66, label %68, label %67
67: ; preds = %64
br label %49
68: ; preds = %64
%69 = getelementptr inbounds [256 x i8], [256 x i8]* %20, i64 0, i64 0
store i8* %69, i8** %16
%70 = load i8*, i8** %16
%71 = call i8* @strchr(i8* %70, i8 signext 44)
store i8* %71, i8** %15
%72 = load i8*, i8** %15
%73 = icmp eq i8* %72, null
br i1 %73, label %74, label %75
74: ; preds = %68
br label %49
75: ; preds = %68
%76 = load i8*, i8** %15
store i8 0, i8* %76
%77 = load i8*, i8** %16
%78 = load i8*, i8** %16
%79 = call i32 @strlen(i8* %78)
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %77, i64 %80
%82 = getelementptr inbounds i8, i8* %81, i64 1
store i8* %82, i8** %17
%83 = load i8*, i8** %17
%84 = call i8* @strchr(i8* %83, i8 signext 44)
store i8* %84, i8** %15
%85 = load i8*, i8** %15
%86 = icmp eq i8* %85, null
br i1 %86, label %87, label %88
87: ; preds = %75
br label %49
88: ; preds = %75
%89 = load i8*, i8** %15
store i8 0, i8* %89
%90 = load i8*, i8** %17
%91 = call i32 @strlen(i8* %90)
%92 = add nsw i32 %91, 5
%93 = icmp sgt i32 %92, 256
br i1 %93, label %94, label %95
94: ; preds = %88
br label %49
95: ; preds = %88
%96 = load i8*, i8** %15
%97 = call i32 @strcpy(i8* %96, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%98 = load i8*, i8** %17
%99 = load i8*, i8** %8
%100 = call i64 @strcmp(i8* %98, i8* %99)
%101 = icmp ne i64 %100, 0
br i1 %101, label %102, label %103
102: ; preds = %95
br label %49
103: ; preds = %95
%104 = load i8*, i8** %10
%105 = bitcast i8* %104 to i8**
store i8* null, i8** %105
%106 = load i8*, i8** %10
%107 = bitcast i8* %106 to i8**
%108 = load %struct.hostent*, %struct.hostent** %9
%109 = getelementptr inbounds %struct.hostent, %struct.hostent* %108, i32 0, i32 0
store i8** %107, i8*** %109
store i64 8, i64* %18
%110 = load i8*, i8** %10
%111 = load i64, i64* %18
%112 = getelementptr inbounds i8, i8* %110, i64 %111
%113 = load i8*, i8** %8
%114 = call i32 @strcpy(i8* %112, i8* %113)
%115 = load i8*, i8** %10
%116 = load i64, i64* %18
%117 = getelementptr inbounds i8, i8* %115, i64 %116
%118 = load %struct.hostent*, %struct.hostent** %9
%119 = getelementptr inbounds %struct.hostent, %struct.hostent* %118, i32 0, i32 1
store i8* %117, i8** %119
%120 = load i8*, i8** %8
%121 = call i32 @strlen(i8* %120)
%122 = add nsw i32 %121, 1
%123 = sext i32 %122 to i64
%124 = load i64, i64* %18
%125 = add i64 %124, %123
store i64 %125, i64* %18
br label %126
126: ; preds = %103
%127 = load i64, i64* %18
%128 = urem i64 %127, 8
%129 = icmp ne i64 %128, 0
br i1 %129, label %130, label %136
130: ; preds = %126
%131 = load i64, i64* %18
%132 = urem i64 %131, 8
%133 = sub i64 8, %132
%134 = load i64, i64* %18
%135 = add i64 %134, %133
store i64 %135, i64* %18
br label %136
136: ; preds = %130, %126
br label %137
137: ; preds = %136
%138 = load i32, i32* @AF_INET
%139 = load %struct.hostent*, %struct.hostent** %9
%140 = getelementptr inbounds %struct.hostent, %struct.hostent* %139, i32 0, i32 4
store i32 %138, i32* %140
%141 = load %struct.hostent*, %struct.hostent** %9
%142 = getelementptr inbounds %struct.hostent, %struct.hostent* %141, i32 0, i32 2
store i32 4, i32* %142
%143 = load i32, i32* @AF_INET
%144 = load i8*, i8** %16
%145 = call i32 @inet_pton(i32 %143, i8* %144, %struct.in_addr* %22)
%146 = load i32, i32* @AF_INET
%147 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %22, i32 0, i32 0
%148 = getelementptr inbounds [2000 x i8], [2000 x i8]* %23, i64 0, i64 0
%149 = call i32 @inet_ntop(i32 %146, i32* %147, i8* %148, i32 2000)
%150 = load i64, i64* %18
store i64 %150, i64* %19
%151 = load i8*, i8** %10
%152 = load i64, i64* %19
%153 = getelementptr inbounds i8, i8* %151, i64 %152
%154 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %22, i32 0, i32 0
%155 = call i32 @memcpy(i8* %153, i32* %154, i32 4)
%156 = load i64, i64* %18
%157 = add i64 %156, 4
store i64 %157, i64* %18
%158 = load i8*, i8** %10
%159 = load i64, i64* %18
%160 = getelementptr inbounds i8, i8* %158, i64 %159
%161 = bitcast i8* %160 to i8**
%162 = load %struct.hostent*, %struct.hostent** %9
%163 = getelementptr inbounds %struct.hostent, %struct.hostent* %162, i32 0, i32 3
store i8** %161, i8*** %163
%164 = load i8*, i8** %10
%165 = load i64, i64* %19
%166 = getelementptr inbounds i8, i8* %164, i64 %165
%167 = load %struct.hostent*, %struct.hostent** %9
%168 = getelementptr inbounds %struct.hostent, %struct.hostent* %167, i32 0, i32 3
%169 = load i8**, i8*** %168
%170 = getelementptr inbounds i8*, i8** %169, i64 0
store i8* %166, i8** %170
%171 = load %struct.hostent*, %struct.hostent** %9
%172 = getelementptr inbounds %struct.hostent, %struct.hostent* %171, i32 0, i32 3
%173 = load i8**, i8*** %172
%174 = getelementptr inbounds i8*, i8** %173, i64 1
store i8* null, i8** %174
%175 = load i32*, i32** %14
%176 = call i32 @fclose(i32* %175)
%177 = load i32, i32* @NSS_STATUS_SUCCESS
store i32 %177, i32* %7
br label %186
178: ; preds = %49
%179 = load i32*, i32** %14
%180 = call i32 @fclose(i32* %179)
%181 = load i32, i32* @EINVAL
%182 = load i32*, i32** %12
store i32 %181, i32* %182
%183 = load i32, i32* @NO_RECOVERY
%184 = load i32*, i32** %13
store i32 %183, i32* %184
%185 = load i32, i32* @NSS_STATUS_UNAVAIL
store i32 %185, i32* %7
br label %186
186: ; preds = %178, %137, %42
%187 = load i32, i32* %7
ret i32 %187
}

LLVM IR (-O2):
%struct.hostent = type { i8**, i8*, i32, i8**, i32 }
%struct.in_addr = type { i32 }
@.str = [31 x i8] c"/var/run/openvpn.server.status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c".vpn\00"
@EINVAL = global i32 0
@NO_RECOVERY = global i32 0
@NSS_STATUS_UNAVAIL = global i32 0
@.str.3 = [16 x i8] c"Virtual Address\00"
@.str.4 = [13 x i8] c"GLOBAL STATS\00"
@.str.5 = [6 x i8] c".vpn\00\00"
@AF_INET = global i32 0
@NSS_STATUS_SUCCESS = global i32 0
define i32 @_nss_openvpn_gethostbyname_r(i8* %0, %struct.hostent* nocapture %1, i8* %2, i64 %3, i32* nocapture writeonly %4, i32* nocapture writeonly %5) {
%7 = alloca [256 x i8]
%8 = alloca %struct.in_addr
%9 = alloca [2000 x i8]
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%12 = icmp eq i32* %10, null
br i1 %12, label %25, label %13
13: ; preds = %6
%14 = tail call i32 @strlen(i8* %0)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = getelementptr inbounds i8, i8* %16, i64 -4
%18 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = call i64 @fgets(i8* %11, i32 256, i32* %10)
%22 = icmp eq i64 %21, 0
br i1 %22, label %92, label %29
23: ; preds = %13
%24 = tail call i32 @fclose(i32* %10)
br label %25
25: ; preds = %6, %23
%26 = load i32, i32* @EINVAL
store i32 %26, i32* %4
%27 = load i32, i32* @NO_RECOVERY
store i32 %27, i32* %5
%28 = load i32, i32* @NSS_STATUS_UNAVAIL
br label %97
29: ; preds = %20, %40
%30 = phi i1 [ %41, %40 ], [ true, %20 ]
%31 = call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 10)
%32 = icmp eq i64 %31, 0
br i1 %32, label %40, label %33
33: ; preds = %29
%34 = call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 10)
%35 = icmp eq i64 %34, 0
%36 = or i1 %30, %35
br i1 %36, label %40, label %37
37: ; preds = %33
%38 = call i8* @strchr(i8* %11, i8 signext 44)
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %44
40: ; preds = %37, %44, %51, %54, %29, %33
%41 = phi i1 [ false, %54 ], [ false, %51 ], [ false, %44 ], [ false, %37 ], [ false, %29 ], [ true, %33 ]
%42 = call i64 @fgets(i8* %11, i32 256, i32* %10)
%43 = icmp eq i64 %42, 0
br i1 %43, label %92, label %29
44: ; preds = %37
store i8 0, i8* %38
%45 = call i32 @strlen(i8* %11)
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %46
%48 = getelementptr inbounds i8, i8* %47, i64 1
%49 = call i8* @strchr(i8* %48, i8 signext 44)
%50 = icmp eq i8* %49, null
br i1 %50, label %40, label %51
51: ; preds = %44
store i8 0, i8* %49
%52 = call i32 @strlen(i8* %48)
%53 = icmp sgt i32 %52, 251
br i1 %53, label %40, label %54
54: ; preds = %51
%55 = call i32 @strcpy(i8* %49, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%56 = call i64 @strcmp(i8* %48, i8* %0)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %40
58: ; preds = %54
%59 = bitcast i8* %2 to i8**
store i8* null, i8** %59
%60 = bitcast %struct.hostent* %1 to i8**
store i8* %2, i8** %60
%61 = getelementptr inbounds i8, i8* %2, i64 8
%62 = call i32 @strcpy(i8* %61, i8* %0)
%63 = getelementptr inbounds %struct.hostent, %struct.hostent* %1, i64 0, i32 1
store i8* %61, i8** %63
%64 = call i32 @strlen(i8* %0)
%65 = sext i32 %64 to i64
%66 = add nsw i64 %65, 9
%67 = and i64 %66, 7
%68 = icmp eq i64 %67, 0
%69 = add nsw i64 %65, 17
%70 = sub nsw i64 %69, %67
%71 = select i1 %68, i64 %66, i64 %70
%72 = load i32, i32* @AF_INET
%73 = getelementptr inbounds %struct.hostent, %struct.hostent* %1, i64 0, i32 4
store i32 %72, i32* %73
%74 = getelementptr inbounds %struct.hostent, %struct.hostent* %1, i64 0, i32 2
store i32 4, i32* %74
%75 = bitcast %struct.in_addr* %8 to i8*
%76 = call i32 @inet_pton(i32 %72, i8* %11, %struct.in_addr* %8)
%77 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%78 = load i32, i32* @AF_INET
%79 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %8, i64 0, i32 0
%80 = call i32 @inet_ntop(i32 %78, i32* %79, i8* %77, i32 2000)
%81 = getelementptr inbounds i8, i8* %2, i64 %71
%82 = call i32 @memcpy(i8* %81, i32* %79, i32 4)
%83 = add nsw i64 %71, 4
%84 = getelementptr inbounds i8, i8* %2, i64 %83
%85 = bitcast i8* %84 to i8**
%86 = getelementptr inbounds %struct.hostent, %struct.hostent* %1, i64 0, i32 3
%87 = bitcast i8*** %86 to i8**
store i8* %84, i8** %87
store i8* %81, i8** %85
%88 = load i8**, i8*** %86
%89 = getelementptr inbounds i8*, i8** %88, i64 1
store i8* null, i8** %89
%90 = call i32 @fclose(i32* %10)
%91 = load i32, i32* @NSS_STATUS_SUCCESS
br label %97
92: ; preds = %40, %20
%93 = call i32 @fclose(i32* %10)
%94 = load i32, i32* @EINVAL
store i32 %94, i32* %4
%95 = load i32, i32* @NO_RECOVERY
store i32 %95, i32* %5
%96 = load i32, i32* @NSS_STATUS_UNAVAIL
br label %97
97: ; preds = %58, %92, %25
%98 = phi i32 [ %28, %25 ], [ %91, %58 ], [ %96, %92 ]
ret i32 %98
}