#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*/ err(int, char *);
scalar_t__ regcomp(int /*<<< orphan*/ *, char const *, int);
int regexec(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/,
            int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int match(const char *pattern, const char *str) {
  regex_t re;
  if (regcomp(&re, pattern, REG_EXTENDED | REG_NOSUB) != 0)
    err(1, "regcomp");
  int status = regexec(&re, str, 0, 0, 0);
  regfree(&re);
  return !status;
}


x86 assembly (clang, -O0):
<match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
mov    0x2e7c(%rip),%rax
or     (%rax),%edx
lea    -0x14(%rbp),%rdi
call   1040 <regcomp@plt>
cmp    $0x0,%rax
je     118a <match+0x4a>
mov    $0x1,%edi
lea    0xe7b(%rip),%rsi
call   1050 <err@plt>
mov    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1060 <regexec@plt>
mov    %eax,-0x18(%rbp)
lea    -0x14(%rbp),%rdi
call   1030 <regfree@plt>
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rsi
mov    0x2e83(%rip),%rax
mov    0x2e84(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xc(%rsp),%rdi
call   1040 <regcomp@plt>
test   %rax,%rax
je     1180 <match+0x40>
lea    0xe8a(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <regexec@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <regfree@plt>
xor    %eax,%eax
test   %ebp,%ebp
sete   %al
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
@.str = [8 x i8] c"regcomp\00"
define i32 @match(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
%7 = load i8*, i8** %3
%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 ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = load i8*, i8** %4
%17 = call i32 @regexec(i32* %5, i8* %16, i32 0, i32 0, i32 0)
store i32 %17, i32* %6
%18 = call i32 @regfree(i32* %5)
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
%22 = zext i1 %21 to i32
ret i32 %22
}

LLVM IR (-O2):
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
@.str = [8 x i8] c"regcomp\00"
define i32 @match(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* %0, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = call i32 @regexec(i32* %3, i8* %1, i32 0, i32 0, i32 0)
%14 = call i32 @regfree(i32* %3)
%15 = icmp eq i32 %13, 0
%16 = zext i1 %15 to i32
ret i32 %16
}