#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 */

/* Variables and functions */
int addr_match_list(char const *, char const *);
int match_hostname(char const *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char const *);
int match_host_and_ip(const char *host, const char *ipaddr,
                      const char *patterns) {
  int mhost, mip;
  if ((mip = addr_match_list(ipaddr, patterns)) == -2)
    return -1;
  else if (mip == -1)
    return 0;
  if ((mhost = match_hostname(host, patterns, strlen(patterns))) == -1)
    return 0;
  if (mhost == 0 && mip == 0)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<match_host_and_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <addr_match_list@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xfffffffe,%eax
jne    1169 <match_host_and_ip+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    11eb <match_host_and_ip+0xbb>
cmpl   $0xffffffff,-0x28(%rbp)
jne    117f <match_host_and_ip+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    11eb <match_host_and_ip+0xbb>
jmp    1184 <match_host_and_ip+0x54>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1050 <match_hostname@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    11c4 <match_host_and_ip+0x94>
movl   $0x0,-0x4(%rbp)
jmp    11eb <match_host_and_ip+0xbb>
cmpl   $0x0,-0x24(%rbp)
jne    11e4 <match_host_and_ip+0xb4>
cmpl   $0x0,-0x28(%rbp)
jne    11e4 <match_host_and_ip+0xb4>
movl   $0x0,-0x4(%rbp)
jmp    11eb <match_host_and_ip+0xbb>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_host_and_ip>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1040 <addr_match_list@plt>
cmp    $0xfffffffe,%eax
je     117b <match_host_and_ip+0x4b>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1177 <match_host_and_ip+0x47>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <match_hostname@plt>
cmp    $0xffffffff,%eax
je     1177 <match_host_and_ip+0x47>
mov    %eax,%ecx
xor    %eax,%eax
or     %ebx,%ecx
setne  %al
jmp    1180 <match_host_and_ip+0x50>
xor    %eax,%eax
jmp    1180 <match_host_and_ip+0x50>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @match_host_and_ip(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %6
%11 = load i8*, i8** %7
%12 = call i32 @addr_match_list(i8* %10, i8* %11)
store i32 %12, i32* %9
%13 = icmp eq i32 %12, -2
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %36
15: ; preds = %3
%16 = load i32, i32* %9
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 0, i32* %4
br label %36
19: ; preds = %15
br label %20
20: ; preds = %19
%21 = load i8*, i8** %5
%22 = load i8*, i8** %7
%23 = load i8*, i8** %7
%24 = call i32 @strlen(i8* %23)
%25 = call i32 @match_hostname(i8* %21, i8* %22, i32 %24)
store i32 %25, i32* %8
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %20
store i32 0, i32* %4
br label %36
28: ; preds = %20
%29 = load i32, i32* %8
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i32, i32* %9
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %31
store i32 0, i32* %4
br label %36
35: ; preds = %31, %28
store i32 1, i32* %4
br label %36
36: ; preds = %35, %34, %27, %18, %14
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
define i32 @match_host_and_ip(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @addr_match_list(i8* %1, i8* %2)
switch i32 %4, label %6 [
i32 -2, label %15
i32 -1, label %5
]
5: ; preds = %3
br label %15
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %2)
%8 = tail call i32 @match_hostname(i8* %0, i8* %2, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %15, label %10
10: ; preds = %6
%11 = icmp ne i32 %8, 0
%12 = icmp ne i32 %4, 0
%13 = select i1 %11, i1 true, i1 %12
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %10, %6, %3, %5
%16 = phi i32 [ 0, %5 ], [ -1, %3 ], [ 0, %6 ], [ %14, %10 ]
ret i32 %16
}