#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_NEWLINE;
int REG_NOSUB;
int /*<<< orphan*/ die(char *);
scalar_t__ regcomp(int /*<<< orphan*/ *, char *, int);
int regexec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
            int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
bool matches_regex(char *str, char *exp) {
  regex_t re;
  int res;
  if (regcomp(&re, exp, REG_EXTENDED | REG_ICASE | REG_NOSUB | REG_NEWLINE))
    die("Could not compile search regex.");
  res = regexec(&re, str, 0, NULL, 0);
  regfree(&re);
  if (!res)
    return true;
  return false;
}


x86 assembly (clang, -O0):
<matches_regex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
mov    0x2e84(%rip),%rax
or     (%rax),%edx
mov    0x2e63(%rip),%rax
or     (%rax),%edx
mov    0x2e6a(%rip),%rax
or     (%rax),%edx
lea    -0x1c(%rbp),%rdi
call   1040 <regcomp@plt>
cmp    $0x0,%rax
je     1197 <matches_regex+0x57>
lea    0xe6e(%rip),%rdi
call   1060 <die@plt>
mov    -0x10(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1050 <regexec@plt>
mov    %eax,-0x20(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <regfree@plt>
cmpl   $0x0,-0x20(%rbp)
jne    11d0 <matches_regex+0x90>
movl   $0x1,-0x4(%rbp)
jmp    11d7 <matches_regex+0x97>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matches_regex>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e79(%rip),%rax
mov    0x2e92(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e6f(%rip),%rax
or     (%rax),%edx
mov    %rdi,%r14
mov    0x2e73(%rip),%rax
or     (%rax),%edx
lea    0xc(%rsp),%rdi
call   1040 <regcomp@plt>
test   %rax,%rax
je     118a <matches_regex+0x4a>
lea    0xe7b(%rip),%rdi
call   1060 <die@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <regexec@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <regfree@plt>
xor    %eax,%eax
test   %ebp,%ebp
sete   %al
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
@REG_NOSUB = global i32 0
@REG_NEWLINE = global i32 0
@.str = [32 x i8] c"Could not compile search regex.\00"
define i32 @matches_regex(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = load i32, i32* @REG_EXTENDED
%10 = load i32, i32* @REG_ICASE
%11 = or i32 %9, %10
%12 = load i32, i32* @REG_NOSUB
%13 = or i32 %11, %12
%14 = load i32, i32* @REG_NEWLINE
%15 = or i32 %13, %14
%16 = call i64 @regcomp(i32* %6, i8* %8, i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @die(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %2
%21 = load i8*, i8** %4
%22 = call i32 @regexec(i32* %6, i8* %21, i32 0, i32* null, i32 0)
store i32 %22, i32* %7
%23 = call i32 @regfree(i32* %6)
%24 = load i32, i32* %7
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %20
store i32 1, i32* %3
br label %28
27: ; preds = %20
store i32 0, i32* %3
br label %28
28: ; preds = %27, %26
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
@REG_NOSUB = global i32 0
@REG_NEWLINE = global i32 0
@.str = [32 x i8] c"Could not compile search regex.\00"
define i32 @matches_regex(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @REG_EXTENDED
%6 = load i32, i32* @REG_ICASE
%7 = or i32 %6, %5
%8 = load i32, i32* @REG_NOSUB
%9 = or i32 %7, %8
%10 = load i32, i32* @REG_NEWLINE
%11 = or i32 %9, %10
%12 = call i64 @regcomp(i32* %3, i8* %1, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = call i32 @die(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = call i32 @regexec(i32* %3, i8* %0, i32 0, i32* null, i32 0)
%18 = call i32 @regfree(i32* %3)
%19 = icmp eq i32 %17, 0
%20 = zext i1 %19 to i32
ret i32 %20
}