#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_NOSUB;
int /*<<< orphan*/ regcomp(int /*<<< orphan*/ *, char const *, int);
int regexec(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/,
            int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char const *);
int check_regex(const char *er, const char *txt) {
  regex_t regex;
  int ret;
  if (!txt || !strlen(txt) || !er || !strlen(er)) {
    return -1;
  }
  regcomp(&regex, er, REG_EXTENDED | REG_NOSUB);
  ret = regexec(&regex, txt, 0, NULL, 0);
  regfree(&regex);
  return ((ret != 0) ? -1 : 0);
}


x86 assembly (clang, -O0):
<check_regex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118a <check_regex+0x4a>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
je     118a <check_regex+0x4a>
cmpq   $0x0,-0x10(%rbp)
je     118a <check_regex+0x4a>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jne    1196 <check_regex+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    11eb <check_regex+0xab>
mov    -0x10(%rbp),%rsi
mov    0x2e37(%rip),%rax
mov    (%rax),%edx
mov    0x2e36(%rip),%rax
or     (%rax),%edx
lea    -0x1c(%rbp),%rdi
call   1050 <regcomp@plt>
mov    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1060 <regexec@plt>
mov    %eax,-0x20(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <regfree@plt>
mov    -0x20(%rbp),%edx
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_regex>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffff,%r14d
test   %rsi,%rsi
je     11b9 <check_regex+0x79>
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rsi,%rdi
call   1040 <strlen@plt>
test   %rbp,%rbp
je     11b9 <check_regex+0x79>
test   %eax,%eax
je     11b9 <check_regex+0x79>
mov    %rbp,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     11b9 <check_regex+0x79>
mov    0x2e5b(%rip),%rax
mov    0x2e5c(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xc(%rsp),%r14
mov    %r14,%rdi
mov    %rbp,%rsi
call   1050 <regcomp@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <regexec@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <regfree@plt>
neg    %ebx
sbb    %r14d,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
define i32 @check_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 = icmp ne i8* %8, null
br i1 %9, label %10, label %21
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = call i32 @strlen(i8* %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %17, %14, %10, %2
store i32 -1, i32* %3
br label %35
22: ; preds = %17
%23 = load i8*, i8** %4
%24 = load i32, i32* @REG_EXTENDED
%25 = load i32, i32* @REG_NOSUB
%26 = or i32 %24, %25
%27 = call i32 @regcomp(i32* %6, i8* %23, i32 %26)
%28 = load i8*, i8** %5
%29 = call i32 @regexec(i32* %6, i8* %28, i32 0, i32* null, i32 0)
store i32 %29, i32* %7
%30 = call i32 @regfree(i32* %6)
%31 = load i32, i32* %7
%32 = icmp ne i32 %31, 0
%33 = zext i1 %32 to i64
%34 = select i1 %32, i32 -1, i32 0
store i32 %34, i32* %3
br label %35
35: ; preds = %22, %21
%36 = load i32, i32* %3
ret i32 %36
}

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