#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*/ regmatch_t;
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
int /*<<< orphan*/ REG_EXTENDED;
int /*<<< orphan*/ error(char *);
scalar_t__ regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int regexec(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ *,
            int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int match(char *str, char *regex_str, regmatch_t *pmatch, int nmatch) {
  regex_t regex;
  if (regcomp(&regex, regex_str, REG_EXTENDED) != 0) {
    error("regcomp");
  }
  int ret = regexec(&regex, str, nmatch, pmatch, 0);
  regfree(&regex);
  return ret == 0;
}


x86 assembly (clang, -O0):
<match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
mov    0x2e7e(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rdi
call   1040 <regcomp@plt>
cmp    $0x0,%rax
je     1183 <match+0x43>
lea    0xe82(%rip),%rdi
call   1060 <error@plt>
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
xor    %r8d,%r8d
call   1050 <regexec@plt>
mov    %eax,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <regfree@plt>
cmpl   $0x0,-0x24(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rdi,%rbx
mov    0x2e89(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rdi
call   1040 <regcomp@plt>
test   %rax,%rax
je     1174 <match+0x34>
lea    0xe91(%rip),%rdi
call   1060 <error@plt>
lea    0x4(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    %r14,%rcx
xor    %r8d,%r8d
call   1050 <regexec@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <regfree@plt>
xor    %eax,%eax
test   %ebx,%ebx
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@REG_EXTENDED = global i32 0
@.str = [8 x i8] c"regcomp\00"
define i32 @match(i8* %0, i8* %1, i32* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32 %3, i32* %8
%11 = load i8*, i8** %6
%12 = load i32, i32* @REG_EXTENDED
%13 = call i64 @regcomp(i32* %9, i8* %11, i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = call i32 @error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %4
%18 = load i8*, i8** %5
%19 = load i32, i32* %8
%20 = load i32*, i32** %7
%21 = call i32 @regexec(i32* %9, i8* %18, i32 %19, i32* %20, i32 0)
store i32 %21, i32* %10
%22 = call i32 @regfree(i32* %9)
%23 = load i32, i32* %10
%24 = icmp eq i32 %23, 0
%25 = zext i1 %24 to i32
ret i32 %25
}

LLVM IR (-O2):
@REG_EXTENDED = global i32 0
@.str = [8 x i8] c"regcomp\00"
define i32 @match(i8* %0, i8* %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = load i32, i32* @REG_EXTENDED
%8 = call i64 @regcomp(i32* %5, i8* %1, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %4
%11 = call i32 @error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %4
%13 = call i32 @regexec(i32* %5, i8* %0, i32 %3, i32* %2, i32 0)
%14 = call i32 @regfree(i32* %5)
%15 = icmp eq i32 %13, 0
%16 = zext i1 %15 to i32
ret i32 %16
}