#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 {
  char **h_addr_list;
};
typedef int in_addr_t;

/* Variables and functions */
struct hostent *gethostbyname(char *);
unsigned int inet_addr(char *);
int innetgr(char *, char const *, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ memcmp(unsigned int *, char *, int);
scalar_t__ strcmp(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int rauthen_checkhost(unsigned int raddr, register char *lhost,
                      const char *rhost) {
  struct hostent *hp;
  unsigned int laddr;
  int negate = 1;
  char **pp;
  if (strncmp("+@", lhost, 2) == 0)
    return (innetgr(&lhost[2], rhost, NULL, NULL));
  if (strncmp("-@", lhost, 2) == 0)
    return (-innetgr(&lhost[2], rhost, NULL, NULL));
  if (strncmp("-", lhost, 1) == 0) {
    negate = -1;
    lhost++;
  } else if (strcmp("+", lhost) == 0) {
    return (1);
  }
  if (isdigit(*lhost) && (in_addr_t)(laddr = inet_addr(lhost)) != -1)
    return (negate * (!(raddr ^ laddr)));
  hp = gethostbyname(lhost);
  if (hp == NULL)
    return (0);
  for (pp = hp->h_addr_list; *pp; ++pp) {
    if (!memcmp(&raddr, *pp, sizeof(unsigned int)))
      return (negate);
  }
  return (0);
}


x86 assembly (clang, -O0):
<rauthen_checkhost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe6b(%rip),%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11c9 <rauthen_checkhost+0x59>
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1090 <innetgr@plt>
mov    %eax,-0x4(%rbp)
jmp    1341 <rauthen_checkhost+0x1d1>
mov    -0x10(%rbp),%rsi
lea    0xe2f(%rip),%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    120e <rauthen_checkhost+0x9e>
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1090 <innetgr@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1341 <rauthen_checkhost+0x1d1>
mov    -0x10(%rbp),%rsi
lea    0xded(%rip),%rdi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1245 <rauthen_checkhost+0xd5>
movl   $0xffffffff,-0x28(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1270 <rauthen_checkhost+0x100>
mov    -0x10(%rbp),%rsi
lea    0xdb8(%rip),%rdi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    126b <rauthen_checkhost+0xfb>
movl   $0x1,-0x4(%rbp)
jmp    1341 <rauthen_checkhost+0x1d1>
jmp    1270 <rauthen_checkhost+0x100>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     12be <rauthen_checkhost+0x14e>
mov    -0x10(%rbp),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     12be <rauthen_checkhost+0x14e>
mov    -0x28(%rbp),%eax
mov    -0x8(%rbp),%ecx
xor    -0x24(%rbp),%ecx
cmp    $0x0,%ecx
setne  %cl
xor    $0xff,%cl
and    $0x1,%cl
movzbl %cl,%ecx
imul   %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1341 <rauthen_checkhost+0x1d1>
mov    -0x10(%rbp),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12e2 <rauthen_checkhost+0x172>
movl   $0x0,-0x4(%rbp)
jmp    1341 <rauthen_checkhost+0x1d1>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
je     133a <rauthen_checkhost+0x1ca>
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
lea    -0x8(%rbp),%rdi
mov    $0x4,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%eax
jne    1324 <rauthen_checkhost+0x1b4>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1341 <rauthen_checkhost+0x1d1>
jmp    1329 <rauthen_checkhost+0x1b9>
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
jmp    12ed <rauthen_checkhost+0x17d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rauthen_checkhost>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %edi,%r15d
mov    %edi,0x4(%rsp)
lea    0xe75(%rip),%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11eb <rauthen_checkhost+0x7b>
lea    0xe62(%rip),%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1208 <rauthen_checkhost+0x98>
lea    0xe4c(%rip),%rdi
mov    $0x1,%r14d
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1223 <rauthen_checkhost+0xb3>
lea    0xe2f(%rip),%rdi
mov    %rbx,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    122d <rauthen_checkhost+0xbd>
jmp    12a1 <rauthen_checkhost+0x131>
add    $0x2,%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <innetgr@plt>
add    $0x2,%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1090 <innetgr@plt>
mov    %eax,%r14d
neg    %r14d
jmp    12a1 <rauthen_checkhost+0x131>
add    $0x1,%rbx
mov    $0xffffffff,%r14d
movsbl (%rbx),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     1252 <rauthen_checkhost+0xe2>
mov    %rbx,%rdi
call   1060 <inet_addr@plt>
cmp    $0xffffffff,%eax
je     1252 <rauthen_checkhost+0xe2>
xor    %ecx,%ecx
cmp    %r15d,%eax
cmovne %ecx,%r14d
jmp    12a1 <rauthen_checkhost+0x131>
mov    %rbx,%rdi
call   1080 <gethostbyname@plt>
test   %rax,%rax
je     129e <rauthen_checkhost+0x12e>
mov    (%rax),%rbp
mov    0x0(%rbp),%rsi
test   %rsi,%rsi
je     129e <rauthen_checkhost+0x12e>
add    $0x8,%rbp
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x4,%edx
call   1050 <memcmp@plt>
test   %eax,%eax
je     12a1 <rauthen_checkhost+0x131>
mov    0x0(%rbp),%rsi
add    $0x8,%rbp
test   %rsi,%rsi
jne    1280 <rauthen_checkhost+0x110>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i8** }
@.str = [3 x i8] c"+@\00"
@.str.1 = [3 x i8] c"-@\00"
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [2 x i8] c"+\00"
define i32 @rauthen_checkhost(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.hostent*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8**
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 1, i32* %10
%12 = load i8*, i8** %6
%13 = call i64 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %12, i32 2)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %3
%16 = load i8*, i8** %6
%17 = getelementptr inbounds i8, i8* %16, i64 2
%18 = load i8*, i8** %7
%19 = call i32 @innetgr(i8* %17, i8* %18, i32* null, i32* null)
store i32 %19, i32* %4
br label %87
20: ; preds = %3
%21 = load i8*, i8** %6
%22 = call i64 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 2)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 2
%27 = load i8*, i8** %7
%28 = call i32 @innetgr(i8* %26, i8* %27, i32* null, i32* null)
%29 = sub nsw i32 0, %28
store i32 %29, i32* %4
br label %87
30: ; preds = %20
%31 = load i8*, i8** %6
%32 = call i64 @strncmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %31, i32 1)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30
store i32 -1, i32* %10
%35 = load i8*, i8** %6
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %6
br label %43
37: ; preds = %30
%38 = load i8*, i8** %6
%39 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
store i32 1, i32* %4
br label %87
42: ; preds = %37
br label %43
43: ; preds = %42, %34
%44 = load i8*, i8** %6
%45 = load i8, i8* %44
%46 = call i64 @isdigit(i8 signext %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %61
48: ; preds = %43
%49 = load i8*, i8** %6
%50 = call i32 @inet_addr(i8* %49)
store i32 %50, i32* %9
%51 = icmp ne i32 %50, -1
br i1 %51, label %52, label %61
52: ; preds = %48
%53 = load i32, i32* %10
%54 = load i32, i32* %5
%55 = load i32, i32* %9
%56 = xor i32 %54, %55
%57 = icmp ne i32 %56, 0
%58 = xor i1 %57, true
%59 = zext i1 %58 to i32
%60 = mul nsw i32 %53, %59
store i32 %60, i32* %4
br label %87
61: ; preds = %48, %43
%62 = load i8*, i8** %6
%63 = call %struct.hostent* @gethostbyname(i8* %62)
store %struct.hostent* %63, %struct.hostent** %8
%64 = load %struct.hostent*, %struct.hostent** %8
%65 = icmp eq %struct.hostent* %64, null
br i1 %65, label %66, label %67
66: ; preds = %61
store i32 0, i32* %4
br label %87
67: ; preds = %61
%68 = load %struct.hostent*, %struct.hostent** %8
%69 = getelementptr inbounds %struct.hostent, %struct.hostent* %68, i32 0, i32 0
%70 = load i8**, i8*** %69
store i8** %70, i8*** %11
br label %71
71: ; preds = %83, %67
%72 = load i8**, i8*** %11
%73 = load i8*, i8** %72
%74 = icmp ne i8* %73, null
br i1 %74, label %75, label %86
75: ; preds = %71
%76 = load i8**, i8*** %11
%77 = load i8*, i8** %76
%78 = call i32 @memcmp(i32* %5, i8* %77, i32 4)
%79 = icmp ne i32 %78, 0
br i1 %79, label %82, label %80
80: ; preds = %75
%81 = load i32, i32* %10
store i32 %81, i32* %4
br label %87
82: ; preds = %75
br label %83
83: ; preds = %82
%84 = load i8**, i8*** %11
%85 = getelementptr inbounds i8*, i8** %84, i32 1
store i8** %85, i8*** %11
br label %71
86: ; preds = %71
store i32 0, i32* %4
br label %87
87: ; preds = %86, %80, %66, %52, %41, %24, %15
%88 = load i32, i32* %4
ret i32 %88
}

LLVM IR (-O2):
%struct.hostent = type { i8** }
@.str = [3 x i8] c"+@\00"
@.str.1 = [3 x i8] c"-@\00"
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [2 x i8] c"+\00"
define i32 @rauthen_checkhost(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
store i32 %0, i32* %4
%5 = tail call i64 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1, i32 2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = getelementptr inbounds i8, i8* %1, i64 2
%9 = tail call i32 @innetgr(i8* %8, i8* %2, i32* null, i32* null)
br label %54
10: ; preds = %3
%11 = tail call i64 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %1, i64 2
%15 = tail call i32 @innetgr(i8* %14, i8* %2, i32* null, i32* null)
%16 = sub nsw i32 0, %15
br label %54
17: ; preds = %10
%18 = tail call i64 @strncmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %1, i32 1)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = getelementptr inbounds i8, i8* %1, i64 1
br label %25
22: ; preds = %17
%23 = tail call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%24 = icmp eq i64 %23, 0
br i1 %24, label %54, label %25
25: ; preds = %22, %20
%26 = phi i8* [ %21, %20 ], [ %1, %22 ]
%27 = phi i32 [ -1, %20 ], [ 1, %22 ]
%28 = load i8, i8* %26
%29 = tail call i64 @isdigit(i8 signext %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %37, label %31
31: ; preds = %25
%32 = tail call i32 @inet_addr(i8* %26)
%33 = icmp eq i32 %32, -1
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = icmp eq i32 %32, %0
%36 = select i1 %35, i32 %27, i32 0
br label %54
37: ; preds = %31, %25
%38 = tail call %struct.hostent* @gethostbyname(i8* %26)
%39 = icmp eq %struct.hostent* %38, null
br i1 %39, label %54, label %40
40: ; preds = %37
%41 = getelementptr inbounds %struct.hostent, %struct.hostent* %38, i64 0, i32 0
%42 = load i8**, i8*** %41
%43 = load i8*, i8** %42
%44 = icmp eq i8* %43, null
br i1 %44, label %54, label %48
45: ; preds = %48
%46 = load i8*, i8** %53
%47 = icmp eq i8* %46, null
br i1 %47, label %54, label %48
48: ; preds = %40, %45
%49 = phi i8* [ %46, %45 ], [ %43, %40 ]
%50 = phi i8** [ %53, %45 ], [ %42, %40 ]
%51 = call i32 @memcmp(i32* %4, i8* %49, i32 4)
%52 = icmp eq i32 %51, 0
%53 = getelementptr inbounds i8*, i8** %50, i64 1
br i1 %52, label %54, label %45
54: ; preds = %48, %45, %40, %37, %22, %34, %13, %7
%55 = phi i32 [ %9, %7 ], [ %16, %13 ], [ %36, %34 ], [ 1, %22 ], [ 0, %37 ], [ 0, %40 ], [ %27, %48 ], [ 0, %45 ]
ret i32 %55
}