#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;
scalar_t__ REG_NOMATCH;
int REG_NOSUB;
scalar_t__ regcomp(int /*<<< orphan*/ *, char *, int);
scalar_t__ regexec(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/,
                   int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int regmatch(const char *string, char *regex) {
  regex_t preg;
  int match = 0;
  if (regcomp(&preg, regex, REG_EXTENDED | REG_NOSUB) == 0) {
    if (regexec(&preg, string, 0, NULL, 0) != REG_NOMATCH)
      match = 1;
    regfree(&preg);
  }
  return match;
}


x86 assembly (clang, -O0):
<regmatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    0x2e7e(%rip),%rax
mov    (%rax),%edx
mov    0x2e7d(%rip),%rax
or     (%rax),%edx
lea    -0x14(%rbp),%rdi
call   1040 <regcomp@plt>
cmp    $0x0,%rax
jne    11a7 <regmatch+0x77>
mov    -0x8(%rbp),%rsi
lea    -0x14(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1050 <regexec@plt>
mov    0x2e5a(%rip),%rcx
cmp    (%rcx),%rax
je     119e <regmatch+0x6e>
movl   $0x1,-0x18(%rbp)
lea    -0x14(%rbp),%rdi
call   1030 <regfree@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regmatch>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2e8e(%rip),%rax
mov    0x2e8f(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xc(%rsp),%rdi
call   1040 <regcomp@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    118d <regmatch+0x5d>
lea    0xc(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <regexec@plt>
mov    0x2e6c(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%rax
setne  %bpl
mov    %r14,%rdi
call   1030 <regfree@plt>
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
@REG_NOMATCH = global i64 0
define i32 @regmatch(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
%7 = load i8*, i8** %4
%8 = load i32, i32* @REG_EXTENDED
%9 = load i32, i32* @REG_NOSUB
%10 = or i32 %8, %9
%11 = call i64 @regcomp(i32* %5, i8* %7, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = call i64 @regexec(i32* %5, i8* %14, i32 0, i32* null, i32 0)
%16 = load i64, i64* @REG_NOMATCH
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 1, i32* %6
br label %19
19: ; preds = %18, %13
%20 = call i32 @regfree(i32* %5)
br label %21
21: ; preds = %19, %2
%22 = load i32, i32* %6
ret i32 %22
}

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