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

/* Variables and functions */
int REG_EXTENDED;
int REG_ICASE;
int REG_NOMATCH;
int REG_NOSUB;
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ regcomp(int /*<<< orphan*/ *, char const *, int);
int regexec(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/,
            int /*<<< orphan*/ *, int /*<<< orphan*/);
int rx_compare(const char *s1, const char *s2) {
  regex_t *usrflt_regex = NULL;
  int regex_errcode = REG_NOMATCH;
  if ((s1) && (s2) && (usrflt_regex = (regex_t *)malloc(sizeof(regex_t))) &&
      !regcomp(usrflt_regex, s2, REG_EXTENDED | REG_ICASE | REG_NOSUB)) {
    regex_errcode = regexec(usrflt_regex, s1, 0, NULL, 0);
  }
  if (usrflt_regex)
    free(usrflt_regex);
  return regex_errcode;
}


x86 assembly (clang, -O0):
<rx_compare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11dd <rx_compare+0x9d>
cmpq   $0x0,-0x10(%rbp)
je     11dd <rx_compare+0x9d>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11dd <rx_compare+0x9d>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
mov    0x2e3e(%rip),%rax
or     (%rax),%edx
mov    0x2e1d(%rip),%rax
or     (%rax),%edx
call   1040 <regcomp@plt>
cmp    $0x0,%eax
jne    11dd <rx_compare+0x9d>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1060 <regexec@plt>
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11f1 <rx_compare+0xb1>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rx_compare>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e92(%rip),%rax
mov    (%rax),%r14d
test   %rdi,%rdi
je     11ba <rx_compare+0x7a>
mov    %rsi,%rbp
test   %rsi,%rsi
je     11ba <rx_compare+0x7a>
mov    %rdi,%rbx
mov    $0x4,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11ba <rx_compare+0x7a>
mov    %rax,%r15
mov    0x2e4e(%rip),%rax
mov    0x2e67(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e44(%rip),%rax
or     (%rax),%edx
mov    %r15,%rdi
mov    %rbp,%rsi
call   1040 <regcomp@plt>
test   %eax,%eax
jne    11b2 <rx_compare+0x72>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <regexec@plt>
mov    %eax,%r14d
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@REG_NOMATCH = global i32 0
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
@REG_NOSUB = global i32 0
define i32 @rx_compare(i8* %0, i8* %1) {
%3 = load i32, i32* @REG_NOMATCH
%4 = icmp ne i8* %0, null
%5 = icmp ne i8* %1, null
%6 = and i1 %4, %5
br i1 %6, label %7, label %24
7: ; preds = %2
%8 = tail call i64 @malloc(i32 4)
%9 = inttoptr i64 %8 to i32*
%10 = icmp eq i64 %8, 0
br i1 %10, label %24, label %11
11: ; preds = %7
%12 = load i32, i32* @REG_EXTENDED
%13 = load i32, i32* @REG_ICASE
%14 = or i32 %13, %12
%15 = load i32, i32* @REG_NOSUB
%16 = or i32 %14, %15
%17 = tail call i32 @regcomp(i32* %9, i8* %1, i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %11
%20 = tail call i32 @regexec(i32* %9, i8* %0, i32 0, i32* null, i32 0)
br label %21
21: ; preds = %11, %19
%22 = phi i32 [ %3, %11 ], [ %20, %19 ]
%23 = tail call i32 @free(i32* %9)
br label %24
24: ; preds = %2, %7, %21
%25 = phi i32 [ %22, %21 ], [ %3, %7 ], [ %3, %2 ]
ret i32 %25
}