#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 /*<<< orphan*/ free(char *);
scalar_t__ logxor(char, char);
int /*<<< orphan*/ printf(char *, ...);
char strcasestr(char *, char *);
char *strchr(char *, char);
char *strdup(char *);
int keystr_match(char *msg, char *key) {
  char *andk = NULL, *actkey, *cur, op = 1;
  int ret = 1;
  if (!key || !msg)
    return 1;
  cur = actkey = strdup(key);
  if (*cur == '&') {
    cur++;
    op = ((*cur == '-') ? 0 : 1);
    cur++;
  }
  while (cur) {
    if (andk = strchr(cur, '&')) {
      *andk = 0;
      andk++;
    }
    printf("Process %s with %s strcasestr(msg,cur):%d op:%d res:%d... ", msg,
           cur, strcasestr(msg, cur), op, strcasestr(msg, cur) ^ op);
    if (logxor(strcasestr(msg, cur), op)) {
      ret = 0;
      printf("Not match\n");
      break;
    }
    printf("ok\n");
    cur = andk;
    if (cur) {
      op = ((*cur == '-') ? 0 : 1);
      cur++;
    }
  }
  free(actkey);
  return ret;
}


x86 assembly (clang, -O0):
<keystr_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movb   $0x1,-0x31(%rbp)
movl   $0x1,-0x38(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1199 <keystr_match+0x39>
cmpq   $0x0,-0x10(%rbp)
jne    11a5 <keystr_match+0x45>
movl   $0x1,-0x4(%rbp)
jmp    1328 <keystr_match+0x1c8>
mov    -0x18(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x26,%eax
jne    11f5 <keystr_match+0x95>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x2d,%edx
cmove  %ecx,%eax
mov    %al,-0x31(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11fa <keystr_match+0x9a>
cmpq   $0x0,-0x30(%rbp)
je     1319 <keystr_match+0x1b9>
mov    -0x30(%rbp),%rdi
mov    $0x26,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1234 <keystr_match+0xd4>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <strcasestr@plt>
movsbl %al,%eax
mov    %eax,-0x40(%rbp)
movsbl -0x31(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <strcasestr@plt>
mov    -0x50(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x40(%rbp),%ecx
mov    -0x3c(%rbp),%r8d
movsbl %al,%r9d
movsbl -0x31(%rbp),%eax
xor    %eax,%r9d
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <strcasestr@plt>
movsbl %al,%edi
movsbl -0x31(%rbp),%esi
call   1040 <logxor@plt>
cmp    $0x0,%rax
je     12d0 <keystr_match+0x170>
movl   $0x0,-0x38(%rbp)
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1319 <keystr_match+0x1b9>
lea    0xd6f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1314 <keystr_match+0x1b4>
mov    -0x30(%rbp),%rax
movsbl (%rax),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x2d,%edx
cmove  %ecx,%eax
mov    %al,-0x31(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11fa <keystr_match+0x9a>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<keystr_match>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%ebx
test   %rdi,%rdi
je     129b <keystr_match+0x12b>
test   %rsi,%rsi
je     129b <keystr_match+0x12b>
mov    %rdi,%r13
mov    %rsi,%rdi
call   1090 <strdup@plt>
mov    $0x1,%r12b
cmpb   $0x26,(%rax)
mov    %rax,%rbx
jne    11b7 <keystr_match+0x47>
cmpb   $0x2d,0x1(%rax)
setne  %r12b
mov    %rax,%rbx
add    $0x2,%rbx
mov    %rax,(%rsp)
lea    0xe3e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
and    $0x1,%r12b
mov    %rbx,%rdi
mov    $0x26,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1200 <keystr_match+0x90>
mov    %rax,%rbp
movb   $0x0,(%rax)
add    $0x1,%rbp
jmp    1202 <keystr_match+0x92>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %ebp,%ebp
mov    %r13,%rdi
mov    %rbx,%rsi
call   1080 <strcasestr@plt>
movsbl %al,%r14d
mov    %r13,%rdi
mov    %rbx,%rsi
call   1080 <strcasestr@plt>
movsbl %al,%r9d
movzbl %r12b,%r12d
xor    %r12d,%r9d
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
mov    %r12d,%r8d
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1080 <strcasestr@plt>
movsbl %al,%edi
mov    %r12d,%esi
call   1050 <logxor@plt>
test   %rax,%rax
jne    127d <keystr_match+0x10d>
lea    0xddc(%rip),%rdi
call   1040 <puts@plt>
test   %rbp,%rbp
je     128d <keystr_match+0x11d>
cmpb   $0x2d,0x0(%rbp)
setne  %r12b
add    $0x1,%rbp
mov    %rbp,%rbx
jmp    11d0 <keystr_match+0x60>
lea    0xdba(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    1292 <keystr_match+0x122>
mov    $0x1,%ebx
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [59 x i8] c"Process %s with %s strcasestr(msg,cur):%d op:%d res:%d... \00"
@.str.1 = [11 x i8] c"Not match\0A\00"
@.str.2 = [4 x i8] c"ok\0A\00"
define i32 @keystr_match(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
store i8 1, i8* %9
store i32 1, i32* %10
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %13, %2
store i32 1, i32* %3
br label %93
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = call i8* @strdup(i8* %18)
store i8* %19, i8** %7
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 38
br i1 %23, label %24, label %36
24: ; preds = %17
%25 = load i8*, i8** %8
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %8
%27 = load i8*, i8** %8
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 45
%31 = zext i1 %30 to i64
%32 = select i1 %30, i32 0, i32 1
%33 = trunc i32 %32 to i8
store i8 %33, i8* %9
%34 = load i8*, i8** %8
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %8
br label %36
36: ; preds = %24, %17
br label %37
37: ; preds = %88, %36
%38 = load i8*, i8** %8
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %89
40: ; preds = %37
%41 = load i8*, i8** %8
%42 = call i8* @strchr(i8* %41, i8 signext 38)
store i8* %42, i8** %6
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = load i8*, i8** %6
store i8 0, i8* %45
%46 = load i8*, i8** %6
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %6
br label %48
48: ; preds = %44, %40
%49 = load i8*, i8** %4
%50 = load i8*, i8** %8
%51 = load i8*, i8** %4
%52 = load i8*, i8** %8
%53 = call signext i8 @strcasestr(i8* %51, i8* %52)
%54 = sext i8 %53 to i32
%55 = load i8, i8* %9
%56 = sext i8 %55 to i32
%57 = load i8*, i8** %4
%58 = load i8*, i8** %8
%59 = call signext i8 @strcasestr(i8* %57, i8* %58)
%60 = sext i8 %59 to i32
%61 = load i8, i8* %9
%62 = sext i8 %61 to i32
%63 = xor i32 %60, %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %49, i8* %50, i32 %54, i32 %56, i32 %63)
%65 = load i8*, i8** %4
%66 = load i8*, i8** %8
%67 = call signext i8 @strcasestr(i8* %65, i8* %66)
%68 = load i8, i8* %9
%69 = call i64 @logxor(i8 signext %67, i8 signext %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %48
store i32 0, i32* %10
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %89
73: ; preds = %48
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%75 = load i8*, i8** %6
store i8* %75, i8** %8
%76 = load i8*, i8** %8
%77 = icmp ne i8* %76, null
br i1 %77, label %78, label %88
78: ; preds = %73
%79 = load i8*, i8** %8
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = icmp eq i32 %81, 45
%83 = zext i1 %82 to i64
%84 = select i1 %82, i32 0, i32 1
%85 = trunc i32 %84 to i8
store i8 %85, i8* %9
%86 = load i8*, i8** %8
%87 = getelementptr inbounds i8, i8* %86, i32 1
store i8* %87, i8** %8
br label %88
88: ; preds = %78, %73
br label %37
89: ; preds = %71, %37
%90 = load i8*, i8** %7
%91 = call i32 @free(i8* %90)
%92 = load i32, i32* %10
store i32 %92, i32* %3
br label %93
93: ; preds = %89, %16
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
@.str = [59 x i8] c"Process %s with %s strcasestr(msg,cur):%d op:%d res:%d... \00"
@str = [3 x i8] c"ok\00"
@str.3 = [10 x i8] c"Not match\00"
define i32 @keystr_match(i8* %0, i8* %1) {
%3 = icmp ne i8* %1, null
%4 = icmp ne i8* %0, null
%5 = and i1 %4, %3
br i1 %5, label %6, label %50
6: ; preds = %2
%7 = tail call i8* @strdup(i8* %1)
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 38
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %7, i64 1
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 45
%14 = getelementptr inbounds i8, i8* %7, i64 2
br label %15
15: ; preds = %10, %6
%16 = phi i1 [ true, %6 ], [ %13, %10 ]
%17 = phi i8* [ %7, %6 ], [ %14, %10 ]
br label %18
18: ; preds = %15, %43
%19 = phi i1 [ %45, %43 ], [ %16, %15 ]
%20 = phi i8* [ %46, %43 ], [ %17, %15 ]
%21 = zext i1 %19 to i8
%22 = tail call i8* @strchr(i8* %20, i8 signext 38)
%23 = icmp eq i8* %22, null
br i1 %23, label %26, label %24
24: ; preds = %18
store i8 0, i8* %22
%25 = getelementptr inbounds i8, i8* %22, i64 1
br label %26
26: ; preds = %24, %18
%27 = phi i8* [ %25, %24 ], [ null, %18 ]
%28 = tail call signext i8 @strcasestr(i8* %0, i8* %20)
%29 = sext i8 %28 to i32
%30 = zext i1 %19 to i32
%31 = tail call signext i8 @strcasestr(i8* %0, i8* %20)
%32 = sext i8 %31 to i32
%33 = xor i32 %32, %30
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %20, i32 %29, i32 %30, i32 %33)
%35 = tail call signext i8 @strcasestr(i8* %0, i8* %20)
%36 = tail call i64 @logxor(i8 signext %35, i8 signext %21)
%37 = icmp eq i64 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %26
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.3, i64 0, i64 0))
br label %47
40: ; preds = %26
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%42 = icmp eq i8* %27, null
br i1 %42, label %47, label %43
43: ; preds = %40
%44 = load i8, i8* %27
%45 = icmp ne i8 %44, 45
%46 = getelementptr inbounds i8, i8* %27, i64 1
br label %18
47: ; preds = %40, %38
%48 = phi i32 [ 0, %38 ], [ 1, %40 ]
%49 = tail call i32 @free(i8* %7)
br label %50
50: ; preds = %2, %47
%51 = phi i32 [ %48, %47 ], [ 1, %2 ]
ret i32 %51
}