#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 evf_input_compare(int, char const *);
scalar_t__ evf_input_get_name(int, char *, int);
scalar_t__ evf_input_get_phys(int, char *, int);
int /*<<< orphan*/ strcasecmp(char *, char const *);
int /*<<< orphan*/ strcmp(char *, char const *);
int check_for_matching_rule(int fd, const char *type, const char *value) {
  char str_buf[2048];
  if (!strcasecmp("Device", type)) {
    int res = evf_input_compare(fd, value);
    if (res == -1)
      return -3;
    return res;
  }
  if (!strcasecmp("Name", type)) {
    if (evf_input_get_name(fd, str_buf, 2048) < 0)
      return -2;
    return !strcmp(str_buf, value);
  }
  if (!strcasecmp("Phys", type)) {
    if (evf_input_get_phys(fd, str_buf, 2048) < 0)
      return -2;
    return !strcmp(str_buf, value);
  }
  if (!strcasecmp("Bits", type)) {
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<check_for_matching_rule>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe8f(%rip),%rdi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    11b8 <check_for_matching_rule+0x68>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1060 <evf_input_compare@plt>
mov    %eax,-0x824(%rbp)
cmpl   $0xffffffff,-0x824(%rbp)
jne    11aa <check_for_matching_rule+0x5a>
movl   $0xfffffffd,-0x4(%rbp)
jmp    12b4 <check_for_matching_rule+0x164>
mov    -0x824(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12b4 <check_for_matching_rule+0x164>
mov    -0x10(%rbp),%rsi
lea    0xe44(%rip),%rdi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1220 <check_for_matching_rule+0xd0>
mov    -0x8(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x800,%edx
call   1040 <evf_input_get_name@plt>
cmp    $0x0,%rax
jge    11fb <check_for_matching_rule+0xab>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12b4 <check_for_matching_rule+0x164>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    12b4 <check_for_matching_rule+0x164>
mov    -0x10(%rbp),%rsi
lea    0xde1(%rip),%rdi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1288 <check_for_matching_rule+0x138>
mov    -0x8(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x800,%edx
call   1070 <evf_input_get_phys@plt>
cmp    $0x0,%rax
jge    1263 <check_for_matching_rule+0x113>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12b4 <check_for_matching_rule+0x164>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    12b4 <check_for_matching_rule+0x164>
mov    -0x10(%rbp),%rsi
lea    0xd7e(%rip),%rdi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    12ad <check_for_matching_rule+0x15d>
movl   $0x0,-0x4(%rbp)
jmp    12b4 <check_for_matching_rule+0x164>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_for_matching_rule>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe96(%rip),%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     11ae <check_for_matching_rule+0x5e>
lea    0xe8d(%rip),%rdi
mov    %rbx,%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     11c7 <check_for_matching_rule+0x77>
lea    0xe7f(%rip),%rdi
mov    %rbx,%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     11f1 <check_for_matching_rule+0xa1>
lea    0xe71(%rip),%rdi
mov    %rbx,%rsi
call   1030 <strcasecmp@plt>
neg    %eax
sbb    %eax,%eax
jmp    120a <check_for_matching_rule+0xba>
mov    %ebp,%edi
mov    %r14,%rsi
call   1060 <evf_input_compare@plt>
mov    %eax,%ecx
cmp    $0xffffffff,%eax
mov    $0xfffffffd,%eax
cmovne %ecx,%eax
jmp    120a <check_for_matching_rule+0xba>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x800,%edx
call   1040 <evf_input_get_name@plt>
test   %rax,%rax
js     1205 <check_for_matching_rule+0xb5>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
jmp    120a <check_for_matching_rule+0xba>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x800,%edx
call   1070 <evf_input_get_phys@plt>
test   %rax,%rax
jns    11db <check_for_matching_rule+0x8b>
mov    $0xfffffffe,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"Device\00"
@.str.1 = [5 x i8] c"Name\00"
@.str.2 = [5 x i8] c"Phys\00"
@.str.3 = [5 x i8] c"Bits\00"
define i32 @check_for_matching_rule(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [2048 x i8]
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %6
%11 = call i32 @strcasecmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %3
%14 = load i32, i32* %5
%15 = load i8*, i8** %7
%16 = call i32 @evf_input_compare(i32 %14, i8* %15)
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 -3, i32* %4
br label %62
20: ; preds = %13
%21 = load i32, i32* %9
store i32 %21, i32* %4
br label %62
22: ; preds = %3
%23 = load i8*, i8** %6
%24 = call i32 @strcasecmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %39, label %26
26: ; preds = %22
%27 = load i32, i32* %5
%28 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%29 = call i64 @evf_input_get_name(i32 %27, i8* %28, i32 2048)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 -2, i32* %4
br label %62
32: ; preds = %26
%33 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%34 = load i8*, i8** %7
%35 = call i32 @strcmp(i8* %33, i8* %34)
%36 = icmp ne i32 %35, 0
%37 = xor i1 %36, true
%38 = zext i1 %37 to i32
store i32 %38, i32* %4
br label %62
39: ; preds = %22
%40 = load i8*, i8** %6
%41 = call i32 @strcasecmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %56, label %43
43: ; preds = %39
%44 = load i32, i32* %5
%45 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%46 = call i64 @evf_input_get_phys(i32 %44, i8* %45, i32 2048)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %43
store i32 -2, i32* %4
br label %62
49: ; preds = %43
%50 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%51 = load i8*, i8** %7
%52 = call i32 @strcmp(i8* %50, i8* %51)
%53 = icmp ne i32 %52, 0
%54 = xor i1 %53, true
%55 = zext i1 %54 to i32
store i32 %55, i32* %4
br label %62
56: ; preds = %39
%57 = load i8*, i8** %6
%58 = call i32 @strcasecmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %57)
%59 = icmp ne i32 %58, 0
br i1 %59, label %61, label %60
60: ; preds = %56
store i32 0, i32* %4
br label %62
61: ; preds = %56
store i32 -1, i32* %4
br label %62
62: ; preds = %61, %60, %49, %48, %32, %31, %20, %19
%63 = load i32, i32* %4
ret i32 %63
}

LLVM IR (-O2):
@.str = [7 x i8] c"Device\00"
@.str.1 = [5 x i8] c"Name\00"
@.str.2 = [5 x i8] c"Phys\00"
@.str.3 = [5 x i8] c"Bits\00"
define i32 @check_for_matching_rule(i32 %0, i8* nocapture %1, i8* %2) {
%4 = alloca [2048 x i8]
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @strcasecmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = tail call i32 @evf_input_compare(i32 %0, i8* %2)
%10 = icmp eq i32 %9, -1
%11 = select i1 %10, i32 -3, i32 %9
br label %36
12: ; preds = %3
%13 = tail call i32 @strcasecmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = call i64 @evf_input_get_name(i32 %0, i8* %5, i32 2048)
%17 = icmp slt i64 %16, 0
br i1 %17, label %36, label %18
18: ; preds = %15
%19 = call i32 @strcmp(i8* %5, i8* dereferenceable(1) %2)
%20 = icmp eq i32 %19, 0
%21 = zext i1 %20 to i32
br label %36
22: ; preds = %12
%23 = tail call i32 @strcasecmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = call i64 @evf_input_get_phys(i32 %0, i8* %5, i32 2048)
%27 = icmp slt i64 %26, 0
br i1 %27, label %36, label %28
28: ; preds = %25
%29 = call i32 @strcmp(i8* %5, i8* dereferenceable(1) %2)
%30 = icmp eq i32 %29, 0
%31 = zext i1 %30 to i32
br label %36
32: ; preds = %22
%33 = tail call i32 @strcasecmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%34 = icmp ne i32 %33, 0
%35 = sext i1 %34 to i32
br label %36
36: ; preds = %32, %25, %15, %28, %18, %8
%37 = phi i32 [ %31, %28 ], [ %21, %18 ], [ %11, %8 ], [ -2, %15 ], [ -2, %25 ], [ %35, %32 ]
ret i32 %37
}