#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 addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_family;
};
typedef int /*<<< orphan*/ sa_family_t;
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int getaddrinfo(char const *, int /*<<< orphan*/ *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, char, int);
scalar_t__ ruserok2_sa(int /*<<< orphan*/, int /*<<< orphan*/, int,
                       char const *, char const *, char const *);
int ruserok_af(const char *rhost, int superuser, const char *ruser,
               const char *luser, sa_family_t af) {
  struct addrinfo hints, *res, *res0;
  int gai;
  int ret;
  memset(&hints, '\0', sizeof(hints));
  hints.ai_family = af;
  gai = getaddrinfo(rhost, NULL, &hints, &res0);
  if (gai)
    return -1;
  ret = -1;
  for (res = res0; res; res = res->ai_next)
    if (ruserok2_sa(res->ai_addr, res->ai_addrlen, superuser, ruser, luser,
                    rhost) == 0) {
      ret = 0;
      break;
    }
  freeaddrinfo(res0);
  return (ret);
}


x86 assembly (clang, -O0):
<ruserok_af>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x48(%rbp),%rdx
lea    -0x58(%rbp),%rcx
call   1050 <getaddrinfo@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     119f <ruserok_af+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1215 <ruserok_af+0xd5>
movl   $0xffffffff,-0x60(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     1206 <ruserok_af+0xc6>
mov    -0x50(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x50(%rbp),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x10(%rbp),%r9
call   1030 <ruserok2_sa@plt>
cmp    $0x0,%rax
jne    11f0 <ruserok_af+0xb0>
movl   $0x0,-0x60(%rbp)
jmp    1206 <ruserok_af+0xc6>
jmp    11f5 <ruserok_af+0xb5>
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    11ae <ruserok_af+0x6e>
mov    -0x58(%rbp),%rdi
call   1060 <freeaddrinfo@plt>
mov    -0x60(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ruserok_af>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%r12d
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%r13d
mov    %rdi,%rbx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    %r12d,0x20(%rsp)
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
xor    %esi,%esi
mov    %rbp,%rdx
call   1050 <getaddrinfo@plt>
mov    $0xffffffff,%r12d
test   %eax,%eax
jne    11e4 <ruserok_af+0xa4>
mov    0x8(%rsp),%rbp
test   %rbp,%rbp
je     11cd <ruserok_af+0x8d>
nopl   0x0(%rax)
mov    0x0(%rbp),%esi
mov    0x4(%rbp),%edi
mov    %r13d,%edx
mov    %r15,%rcx
mov    %r14,%r8
mov    %rbx,%r9
call   1030 <ruserok2_sa@plt>
test   %rax,%rax
je     11d7 <ruserok_af+0x97>
mov    0x8(%rbp),%rbp
test   %rbp,%rbp
jne    11a0 <ruserok_af+0x60>
mov    $0xffffffff,%r12d
jmp    11da <ruserok_af+0x9a>
mov    $0xffffffff,%r12d
xor    %edi,%edi
jmp    11df <ruserok_af+0x9f>
xor    %r12d,%r12d
mov    0x8(%rsp),%rdi
call   1060 <freeaddrinfo@plt>
mov    %r12d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, %struct.addrinfo*, i32 }
define i32 @ruserok_af(i8* %0, i32 %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca %struct.addrinfo
%13 = alloca %struct.addrinfo*
%14 = alloca %struct.addrinfo*
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%17 = call i32 @memset(%struct.addrinfo* %12, i8 signext 0, i32 24)
%18 = load i32, i32* %11
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %12, i32 0, i32 3
store i32 %18, i32* %19
%20 = load i8*, i8** %7
%21 = call i32 @getaddrinfo(i8* %20, i32* null, %struct.addrinfo* %12, %struct.addrinfo** %14)
store i32 %21, i32* %15
%22 = load i32, i32* %15
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %5
store i32 -1, i32* %6
br label %53
25: ; preds = %5
store i32 -1, i32* %16
%26 = load %struct.addrinfo*, %struct.addrinfo** %14
store %struct.addrinfo* %26, %struct.addrinfo** %13
br label %27
27: ; preds = %45, %25
%28 = load %struct.addrinfo*, %struct.addrinfo** %13
%29 = icmp ne %struct.addrinfo* %28, null
br i1 %29, label %30, label %49
30: ; preds = %27
%31 = load %struct.addrinfo*, %struct.addrinfo** %13
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i32 0, i32 1
%33 = load i32, i32* %32
%34 = load %struct.addrinfo*, %struct.addrinfo** %13
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = load i32, i32* %8
%38 = load i8*, i8** %9
%39 = load i8*, i8** %10
%40 = load i8*, i8** %7
%41 = call i64 @ruserok2_sa(i32 %33, i32 %36, i32 %37, i8* %38, i8* %39, i8* %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %30
store i32 0, i32* %16
br label %49
44: ; preds = %30
br label %45
45: ; preds = %44
%46 = load %struct.addrinfo*, %struct.addrinfo** %13
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i32 0, i32 2
%48 = load %struct.addrinfo*, %struct.addrinfo** %47
store %struct.addrinfo* %48, %struct.addrinfo** %13
br label %27
49: ; preds = %43, %27
%50 = load %struct.addrinfo*, %struct.addrinfo** %14
%51 = call i32 @freeaddrinfo(%struct.addrinfo* %50)
%52 = load i32, i32* %16
store i32 %52, i32* %6
br label %53
53: ; preds = %49, %24
%54 = load i32, i32* %6
ret i32 %54
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, %struct.addrinfo*, i32 }
define i32 @ruserok_af(i8* %0, i32 %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca %struct.addrinfo
%7 = alloca %struct.addrinfo*
%8 = bitcast %struct.addrinfo* %6 to i8*
%9 = bitcast %struct.addrinfo** %7 to i8*
%10 = call i32 @memset(%struct.addrinfo* %6, i8 signext 0, i32 24)
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 3
store i32 %4, i32* %11
%12 = call i32 @getaddrinfo(i8* %0, i32* null, %struct.addrinfo* %6, %struct.addrinfo** %7)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %36
14: ; preds = %5
%15 = load %struct.addrinfo*, %struct.addrinfo** %7
%16 = icmp eq %struct.addrinfo* %15, null
br i1 %16, label %32, label %21
17: ; preds = %21
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %22, i64 0, i32 2
%19 = load %struct.addrinfo*, %struct.addrinfo** %18
%20 = icmp eq %struct.addrinfo* %19, null
br i1 %20, label %29, label %21
21: ; preds = %14, %17
%22 = phi %struct.addrinfo* [ %19, %17 ], [ %15, %14 ]
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %22, i64 0, i32 1
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %22, i64 0, i32 0
%26 = load i32, i32* %25
%27 = call i64 @ruserok2_sa(i32 %24, i32 %26, i32 %1, i8* %2, i8* %3, i8* %0)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %17
29: ; preds = %21, %17
%30 = phi i32 [ -1, %17 ], [ 0, %21 ]
%31 = load %struct.addrinfo*, %struct.addrinfo** %7
br label %32
32: ; preds = %29, %14
%33 = phi %struct.addrinfo* [ null, %14 ], [ %31, %29 ]
%34 = phi i32 [ -1, %14 ], [ %30, %29 ]
%35 = call i32 @freeaddrinfo(%struct.addrinfo* %33)
br label %36
36: ; preds = %5, %32
%37 = phi i32 [ %34, %32 ], [ -1, %5 ]
ret i32 %37
}