#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;
scalar_t__ regcomp(int /*<<< orphan*/ *, char *, int);
int regexec(int /*<<< orphan*/ *, char const *, size_t, int /*<<< orphan*/ *,
            int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int string_match_regex(const char *text, char *pattern) {
  int ret = 0;
  regex_t re;
  if (!pattern || !text)
    return 0;
  if (regcomp(&re, pattern, REG_EXTENDED | REG_NOSUB) != 0) {
    return 0;
  }
  ret = regexec(&re, text, (size_t)0, NULL, 0);
  regfree(&re);
  if (!ret)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<string_match_regex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     115d <string_match_regex+0x2d>
cmpq   $0x0,-0x10(%rbp)
jne    1169 <string_match_regex+0x39>
movl   $0x0,-0x4(%rbp)
jmp    11de <string_match_regex+0xae>
mov    -0x18(%rbp),%rsi
mov    0x2e64(%rip),%rax
mov    (%rax),%edx
mov    0x2e63(%rip),%rax
or     (%rax),%edx
lea    -0x20(%rbp),%rdi
call   1040 <regcomp@plt>
cmp    $0x0,%rax
je     119e <string_match_regex+0x6e>
movl   $0x0,-0x4(%rbp)
jmp    11de <string_match_regex+0xae>
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
mov    %rcx,%rdx
call   1050 <regexec@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <regfree@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    11d7 <string_match_regex+0xa7>
movl   $0x1,-0x4(%rbp)
jmp    11de <string_match_regex+0xae>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_match_regex>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
test   %rdi,%rdi
je     1190 <string_match_regex+0x60>
test   %rsi,%rsi
je     1190 <string_match_regex+0x60>
mov    %rdi,%r14
mov    0x2e8a(%rip),%rax
mov    0x2e8b(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xc(%rsp),%rdi
call   1040 <regcomp@plt>
test   %rax,%rax
jne    1190 <string_match_regex+0x60>
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    %ebx,%ebx
test   %ebp,%ebp
sete   %bl
mov    %ebx,%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 @string_match_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
store i32 0, i32* %6
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10, %2
store i32 0, i32* %3
br label %30
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = load i32, i32* @REG_EXTENDED
%17 = load i32, i32* @REG_NOSUB
%18 = or i32 %16, %17
%19 = call i64 @regcomp(i32* %7, i8* %15, i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %14
store i32 0, i32* %3
br label %30
22: ; preds = %14
%23 = load i8*, i8** %4
%24 = call i32 @regexec(i32* %7, i8* %23, i64 0, i32* null, i32 0)
store i32 %24, i32* %6
%25 = call i32 @regfree(i32* %7)
%26 = load i32, i32* %6
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %22
store i32 1, i32* %3
br label %30
29: ; preds = %22
store i32 0, i32* %3
br label %30
30: ; preds = %29, %28, %21, %13
%31 = load i32, i32* %3
ret i32 %31
}

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