#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 regcomp(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/);
int regexec(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/,
            int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int match(const char *string, const char *pattern) {
  int r;
  regex_t expr;
  regmatch_t rm;
  if ((r = regcomp(&expr, pattern, REG_EXTENDED)) != 0)
    return 0;
  if ((r = regexec(&expr, string, 0, &rm, 0)) != 0) {
    regfree(&expr);
    return 0;
  }
  regfree(&expr);
  return 1;
}


x86 assembly (clang, -O0):
<match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    0x2e95(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rdi
call   1040 <regcomp@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     116e <match+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <match+0x86>
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdi
xor    %r8d,%r8d
lea    -0x24(%rbp),%rcx
mov    %r8d,%edx
call   1050 <regexec@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     11a6 <match+0x76>
lea    -0x20(%rbp),%rdi
call   1030 <regfree@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <match+0x86>
lea    -0x20(%rbp),%rdi
call   1030 <regfree@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2e9e(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
call   1040 <regcomp@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    117e <match+0x4e>
lea    0x8(%rsp),%r14
lea    0xc(%rsp),%rcx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %r8d,%r8d
call   1050 <regexec@plt>
xor    %ebp,%ebp
test   %eax,%eax
sete   %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
define i32 @match(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = load i32, i32* @REG_EXTENDED
%11 = call i32 @regcomp(i32* %7, i8* %9, i32 %10)
store i32 %11, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 0, i32* %3
br label %22
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i32 @regexec(i32* %7, i8* %15, i32 0, i32* %8, i32 0)
store i32 %16, i32* %6
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @regfree(i32* %7)
store i32 0, i32* %3
br label %22
20: ; preds = %14
%21 = call i32 @regfree(i32* %7)
store i32 1, i32* %3
br label %22
22: ; preds = %20, %18, %13
%23 = load i32, i32* %3
ret i32 %23
}

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