#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 u_int32_t;
struct hostent {
  char **h_addr_list;
};

/* Variables and functions */
int INADDR_NONE;
struct hostent *gethostbyname(char *);
int inet_addr(char *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ memcmp(int *, char *, int);
scalar_t__ strcmp(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int __icheckhost(u_int32_t raddr, char *lhost, const char *rhost) {
  struct hostent *hp;
  u_int32_t laddr;
  int negate = 1;
  char **pp;
  if (strncmp("-", lhost, 1) == 0) {
    negate = -1;
    lhost++;
  } else if (strcmp("+", lhost) == 0) {
    return 1;
  }
  if (isdigit(*lhost) && (laddr = inet_addr(lhost)) != INADDR_NONE)
    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(u_int32_t)))
      return negate;
  return (0);
}


x86 assembly (clang, -O0):
<__icheckhost>:
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    0xe7b(%rip),%rdi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11b1 <__icheckhost+0x51>
movl   $0xffffffff,-0x28(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11dc <__icheckhost+0x7c>
mov    -0x10(%rbp),%rsi
lea    0xe46(%rip),%rdi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    11d7 <__icheckhost+0x77>
movl   $0x1,-0x4(%rbp)
jmp    12b3 <__icheckhost+0x153>
jmp    11dc <__icheckhost+0x7c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     1230 <__icheckhost+0xd0>
mov    -0x10(%rbp),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    0x2de3(%rip),%rcx
cmp    (%rcx),%eax
je     1230 <__icheckhost+0xd0>
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    12b3 <__icheckhost+0x153>
mov    -0x10(%rbp),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1254 <__icheckhost+0xf4>
movl   $0x0,-0x4(%rbp)
jmp    12b3 <__icheckhost+0x153>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
je     12ac <__icheckhost+0x14c>
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
lea    -0x8(%rbp),%rdi
mov    $0x4,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%eax
jne    1296 <__icheckhost+0x136>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12b3 <__icheckhost+0x153>
jmp    129b <__icheckhost+0x13b>
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
jmp    125f <__icheckhost+0xff>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__icheckhost>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %edi,0xc(%rsp)
lea    0xe88(%rip),%rdi
mov    $0x1,%r14d
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11a3 <__icheckhost+0x43>
lea    0xe6e(%rip),%rdi
mov    %rbx,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11ad <__icheckhost+0x4d>
jmp    121b <__icheckhost+0xbb>
add    $0x1,%rbx
mov    $0xffffffff,%r14d
movsbl (%rbx),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     11cd <__icheckhost+0x6d>
mov    %rbx,%rdi
call   1060 <inet_addr@plt>
mov    0x2e1f(%rip),%rcx
cmp    (%rcx),%eax
jne    1213 <__icheckhost+0xb3>
mov    %rbx,%rdi
call   1080 <gethostbyname@plt>
test   %rax,%rax
je     120e <__icheckhost+0xae>
mov    (%rax),%rbp
mov    0x0(%rbp),%rsi
test   %rsi,%rsi
je     120e <__icheckhost+0xae>
add    $0x8,%rbp
lea    0xc(%rsp),%rbx
nop
mov    %rbx,%rdi
mov    $0x4,%edx
call   1050 <memcmp@plt>
test   %eax,%eax
je     121b <__icheckhost+0xbb>
mov    0x0(%rbp),%rsi
add    $0x8,%rbp
test   %rsi,%rsi
jne    11f0 <__icheckhost+0x90>
xor    %r14d,%r14d
jmp    121b <__icheckhost+0xbb>
xor    %ecx,%ecx
cmp    %ebp,%eax
cmovne %ecx,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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