#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 /*<<< orphan*/ regmatch_t;
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
int /*<<< orphan*/ REG_NOSUB;
int /*<<< orphan*/ free(char *);
char *normalize(char *);
int /*<<< orphan*/ regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ regexec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                           int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int evaluate_match_namespace(char *pattern, char *subject, int type) {
  regex_t compiled;
  regmatch_t match[1];
  int success = 2;
  char *patterntmp = normalize(pattern);
  char *subjecttmp = normalize(subject);
  if (!regcomp(&compiled, patterntmp, REG_NOSUB)) {
    if (!regexec(&compiled, subjecttmp, 0, match, 0)) {
      if (type)
        success = 0;
      else
        success = 1;
    }
  }
  regfree(&compiled);
  free(patterntmp);
  free(subjecttmp);
  return success;
}


x86 assembly (clang, -O0):
<evaluate_match_namespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x2,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <normalize@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <normalize@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rsi
mov    0x2e51(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
call   1050 <regcomp@plt>
cmp    $0x0,%eax
jne    11ea <evaluate_match_namespace+0x9a>
mov    -0x30(%rbp),%rsi
lea    -0x1c(%rbp),%rcx
lea    -0x18(%rbp),%rdi
xor    %r8d,%r8d
mov    %r8d,%edx
call   1070 <regexec@plt>
cmp    $0x0,%eax
jne    11e5 <evaluate_match_namespace+0x95>
cmpl   $0x0,-0x14(%rbp)
je     11d9 <evaluate_match_namespace+0x89>
movl   $0x0,-0x20(%rbp)
jmp    11e0 <evaluate_match_namespace+0x90>
movl   $0x1,-0x20(%rbp)
jmp    11e5 <evaluate_match_namespace+0x95>
jmp    11ea <evaluate_match_namespace+0x9a>
lea    -0x18(%rbp),%rdi
call   1040 <regfree@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evaluate_match_namespace>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%rbp
call   1060 <normalize@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1060 <normalize@plt>
mov    %rax,%r14
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1050 <regcomp@plt>
mov    $0x2,%ebp
test   %eax,%eax
jne    11af <evaluate_match_namespace+0x5f>
mov    %rsp,%rdi
lea    0x4(%rsp),%rcx
mov    %r14,%rsi
xor    %edx,%edx
xor    %r8d,%r8d
call   1070 <regexec@plt>
test   %eax,%eax
jne    11af <evaluate_match_namespace+0x5f>
xor    %ebp,%ebp
test   %r15d,%r15d
sete   %bpl
mov    %rsp,%rdi
call   1040 <regfree@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@REG_NOSUB = global i32 0
define i32 @evaluate_match_namespace(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1 x i32]
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 2, i32* %9
%12 = load i8*, i8** %4
%13 = call i8* @normalize(i8* %12)
store i8* %13, i8** %10
%14 = load i8*, i8** %5
%15 = call i8* @normalize(i8* %14)
store i8* %15, i8** %11
%16 = load i8*, i8** %10
%17 = load i32, i32* @REG_NOSUB
%18 = call i32 @regcomp(i32* %7, i8* %16, i32 %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %32, label %20
20: ; preds = %3
%21 = load i8*, i8** %11
%22 = getelementptr inbounds [1 x i32], [1 x i32]* %8, i64 0, i64 0
%23 = call i32 @regexec(i32* %7, i8* %21, i32 0, i32* %22, i32 0)
%24 = icmp ne i32 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %20
%26 = load i32, i32* %6
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 0, i32* %9
br label %30
29: ; preds = %25
store i32 1, i32* %9
br label %30
30: ; preds = %29, %28
br label %31
31: ; preds = %30, %20
br label %32
32: ; preds = %31, %3
%33 = call i32 @regfree(i32* %7)
%34 = load i8*, i8** %10
%35 = call i32 @free(i8* %34)
%36 = load i8*, i8** %11
%37 = call i32 @free(i8* %36)
%38 = load i32, i32* %9
ret i32 %38
}

LLVM IR (-O2):
@REG_NOSUB = global i32 0
define i32 @evaluate_match_namespace(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca [1 x i32]
%6 = bitcast i32* %4 to i8*
%7 = bitcast [1 x i32]* %5 to i8*
%8 = tail call i8* @normalize(i8* %0)
%9 = tail call i8* @normalize(i8* %1)
%10 = load i32, i32* @REG_NOSUB
%11 = call i32 @regcomp(i32* %4, i8* %8, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %3
%14 = getelementptr inbounds [1 x i32], [1 x i32]* %5, i64 0, i64 0
%15 = call i32 @regexec(i32* %4, i8* %9, i32 0, i32* %14, i32 0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = icmp eq i32 %2, 0
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %17, %13, %3
%21 = phi i32 [ 2, %3 ], [ 2, %13 ], [ %19, %17 ]
%22 = call i32 @regfree(i32* %4)
%23 = call i32 @free(i8* %8)
%24 = call i32 @free(i8* %9)
ret i32 %21
}