#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 == NULL || !strlen(txt)) {
    return -1;
  }
  regcomp(&regex, er, REG_EXTENDED | REG_NOSUB);
  ret = regexec(&regex, txt, 0, NULL, 0);
  regfree(&regex);
  return ((ret == 0) ? 0 : -1);
}


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     116d <check_regex+0x2d>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jne    1179 <check_regex+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <check_regex+0x8e>
mov    -0x10(%rbp),%rsi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
mov    0x2e53(%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
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmove  %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,%ebp
test   %rsi,%rsi
je     11a6 <check_regex+0x66>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     11a6 <check_regex+0x66>
mov    0x2e6d(%rip),%rax
mov    0x2e6e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xc(%rsp),%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <regcomp@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <regexec@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <regfree@plt>
neg    %ebx
sbb    %ebp,%ebp
mov    %ebp,%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 eq i8* %8, null
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %10, %2
store i32 -1, i32* %3
br label %28
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = load i32, i32* @REG_EXTENDED
%18 = load i32, i32* @REG_NOSUB
%19 = or i32 %17, %18
%20 = call i32 @regcomp(i32* %6, i8* %16, i32 %19)
%21 = load i8*, i8** %5
%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 eq i32 %24, 0
%26 = zext i1 %25 to i64
%27 = select i1 %25, i32 0, i32 -1
store i32 %27, i32* %3
br label %28
28: ; preds = %15, %14
%29 = load i32, i32* %3
ret i32 %29
}

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 %18, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %18, label %9
9: ; preds = %6
%10 = load i32, i32* @REG_EXTENDED
%11 = load i32, i32* @REG_NOSUB
%12 = or i32 %11, %10
%13 = call i32 @regcomp(i32* %3, i8* %0, i32 %12)
%14 = call i32 @regexec(i32* %3, i8* %1, i32 0, i32* null, i32 0)
%15 = call i32 @regfree(i32* %3)
%16 = icmp ne i32 %14, 0
%17 = sext i1 %16 to i32
br label %18
18: ; preds = %2, %6, %9
%19 = phi i32 [ %17, %9 ], [ -1, %6 ], [ -1, %2 ]
ret i32 %19
}