#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 */
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) && (long)(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(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    12b0 <__icheckhost+0x150>
jmp    11dc <__icheckhost+0x7c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     122d <__icheckhost+0xcd>
mov    -0x10(%rbp),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
cltq
cmp    $0xffffffffffffffff,%rax
je     122d <__icheckhost+0xcd>
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    12b0 <__icheckhost+0x150>
mov    -0x10(%rbp),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1251 <__icheckhost+0xf1>
movl   $0x0,-0x4(%rbp)
jmp    12b0 <__icheckhost+0x150>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
je     12a9 <__icheckhost+0x149>
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
lea    -0x8(%rbp),%rdi
mov    $0x4,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%eax
jne    1293 <__icheckhost+0x133>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12b0 <__icheckhost+0x150>
jmp    1298 <__icheckhost+0x138>
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
jmp    125c <__icheckhost+0xfc>
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    1221 <__icheckhost+0xc1>
add    $0x1,%rbx
mov    $0xffffffff,%r14d
movsbl (%rbx),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     11d1 <__icheckhost+0x71>
mov    %rbx,%rdi
call   1060 <inet_addr@plt>
cmp    $0xffffffff,%eax
je     11d1 <__icheckhost+0x71>
xor    %ecx,%ecx
cmp    %ebp,%eax
cmovne %ecx,%r14d
jmp    1221 <__icheckhost+0xc1>
mov    %rbx,%rdi
call   1080 <gethostbyname@plt>
test   %rax,%rax
je     121e <__icheckhost+0xbe>
mov    (%rax),%rbp
mov    0x0(%rbp),%rsi
test   %rsi,%rsi
je     121e <__icheckhost+0xbe>
add    $0x8,%rbp
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x4,%edx
call   1050 <memcmp@plt>
test   %eax,%eax
je     1221 <__icheckhost+0xc1>
mov    0x0(%rbp),%rsi
add    $0x8,%rbp
test   %rsi,%rsi
jne    1200 <__icheckhost+0xa0>
xor    %r14d,%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"
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 = sext i32 %31 to i64
%33 = icmp ne i64 %32, -1
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"
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 %41, 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 %24, label %18
18: ; preds = %12
%19 = tail call i32 @inet_addr(i8* %13)
%20 = icmp eq i32 %19, -1
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = icmp eq i32 %19, %0
%23 = select i1 %22, i32 %14, i32 0
br label %41
24: ; preds = %18, %12
%25 = tail call %struct.hostent* @gethostbyname(i8* %13)
%26 = icmp eq %struct.hostent* %25, null
br i1 %26, label %41, label %27
27: ; preds = %24
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %25, i64 0, i32 0
%29 = load i8**, i8*** %28
%30 = load i8*, i8** %29
%31 = icmp eq i8* %30, null
br i1 %31, label %41, label %35
32: ; preds = %35
%33 = load i8*, i8** %40
%34 = icmp eq i8* %33, null
br i1 %34, label %41, label %35
35: ; preds = %27, %32
%36 = phi i8* [ %33, %32 ], [ %30, %27 ]
%37 = phi i8** [ %40, %32 ], [ %29, %27 ]
%38 = call i32 @memcmp(i32* %4, i8* %36, i32 4)
%39 = icmp eq i32 %38, 0
%40 = getelementptr inbounds i8*, i8** %37, i64 1
br i1 %39, label %41, label %32
41: ; preds = %35, %32, %27, %24, %9, %21
%42 = phi i32 [ %23, %21 ], [ 1, %9 ], [ 0, %24 ], [ 0, %27 ], [ %14, %35 ], [ 0, %32 ]
ret i32 %42
}