#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 REG_EXTENDED;
size_t regcomp(int /*<<< orphan*/ *, char *, int);
size_t regexec(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ *,
               int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int reg_match(char *expression, char *match, int flags) {
  regex_t preg;
  size_t r;
  regmatch_t pmatch[4];
  if ((r = regcomp(&preg, expression, (flags | REG_EXTENDED))))
    return r;
  r = regexec(&preg, match, 4, pmatch, 0);
  regfree(&preg);
  return r;
}


x86 assembly (clang, -O0):
<reg_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    0x2e8f(%rip),%rax
or     (%rax),%edx
lea    -0x20(%rbp),%rdi
call   1040 <regcomp@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1176 <reg_match+0x46>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11a3 <reg_match+0x73>
mov    -0x18(%rbp),%rsi
lea    -0x40(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x4,%edx
xor    %r8d,%r8d
call   1050 <regexec@plt>
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <regfree@plt>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reg_match>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%rsi
mov    0x2e9a(%rip),%rax
or     (%rax),%edx
lea    0xc(%rsp),%rdi
call   1040 <regcomp@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1182 <reg_match+0x52>
lea    0xc(%rsp),%r15
lea    0x10(%rsp),%rcx
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
xor    %r8d,%r8d
call   1050 <regexec@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <regfree@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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