#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;
scalar_t__ regcomp(int /*<<< orphan*/ *, char const *, int);
scalar_t__ regexec(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/,
                   int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int rat_lib_regex_match(const char *regex, const char *str) {
  regex_t rgx;
  if (regcomp(&rgx, regex, REG_EXTENDED | REG_ICASE) != 0)
    goto exit_err;
  if (regexec(&rgx, str, 0, NULL, 0) == 0) {
    regfree(&rgx);
    return 0;
  }
  regfree(&rgx);
exit_err:
  return -1;
}


x86 assembly (clang, -O0):
<rat_lib_regex_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    0x2e8d(%rip),%rax
mov    (%rax),%edx
mov    0x2e94(%rip),%rax
or     (%rax),%edx
lea    -0x1c(%rbp),%rdi
call   1040 <regcomp@plt>
cmp    $0x0,%rax
je     116e <rat_lib_regex_match+0x3e>
jmp    11ad <rat_lib_regex_match+0x7d>
mov    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1050 <regexec@plt>
cmp    $0x0,%rax
jne    11a4 <rat_lib_regex_match+0x74>
lea    -0x1c(%rbp),%rdi
call   1030 <regfree@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b4 <rat_lib_regex_match+0x84>
lea    -0x1c(%rbp),%rdi
call   1030 <regfree@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rat_lib_regex_match>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rsi
mov    0x2e97(%rip),%rax
mov    0x2ea0(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0x4(%rsp),%rdi
call   1040 <regcomp@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    118a <rat_lib_regex_match+0x5a>
lea    0x4(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <regexec@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <regfree@plt>
neg    %rbx
sbb    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
define i32 @rat_lib_regex_match(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = load i32, i32* @REG_EXTENDED
%9 = load i32, i32* @REG_ICASE
%10 = or i32 %8, %9
%11 = call i64 @regcomp(i32* %6, i8* %7, i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
br label %22
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = call i64 @regexec(i32* %6, i8* %15, i32 0, i32* null, i32 0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @regfree(i32* %6)
store i32 0, i32* %3
br label %23
20: ; preds = %14
%21 = call i32 @regfree(i32* %6)
br label %22
22: ; preds = %20, %13
store i32 -1, i32* %3
br label %23
23: ; preds = %22, %18
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
define i32 @rat_lib_regex_match(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 = call i64 @regcomp(i32* %3, i8* %0, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = call i64 @regexec(i32* %3, i8* %1, i32 0, i32* null, i32 0)
%12 = icmp ne i64 %11, 0
%13 = call i32 @regfree(i32* %3)
%14 = sext i1 %12 to i32
br label %15
15: ; preds = %10, %2
%16 = phi i32 [ -1, %2 ], [ %14, %10 ]
ret i32 %16
}