#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;
int REG_ICASE;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ regcomp(int /*<<< orphan*/ *, char *, int);
scalar_t__ regexec(int /*<<< orphan*/ *, char *, size_t, int /*<<< orphan*/ *,
                   int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int match_regex(char *string, char *regex, regmatch_t *pmatch, size_t nmatch) {
  ;
  ;
  regex_t preg;
  if (regcomp(&preg, regex, REG_EXTENDED | REG_ICASE) != 0) {
    fprintf(stderr, "Failed to compile regex %s\n", regex);
    exit(1);
  };
  if (regexec(&preg, string, nmatch, pmatch, 0) == 0) {
    ;
    regfree(&preg);
    return 0;
  };
  regfree(&preg);
  return 1;
}


x86 assembly (clang, -O0):
<match_regex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rsi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
mov    0x2e6c(%rip),%rax
or     (%rax),%edx
lea    -0x2c(%rbp),%rdi
call   1040 <regcomp@plt>
cmp    $0x0,%rax
je     11b4 <match_regex+0x64>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe5b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x2c(%rbp),%rdi
xor    %r8d,%r8d
call   1060 <regexec@plt>
cmp    $0x0,%rax
jne    11eb <match_regex+0x9b>
lea    -0x2c(%rbp),%rdi
call   1030 <regfree@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fb <match_regex+0xab>
lea    -0x2c(%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_regex>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    0x2e65(%rip),%rax
mov    0x2e76(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0x4(%rsp),%rdi
call   1040 <regcomp@plt>
test   %rax,%rax
jne    11bc <match_regex+0x6c>
lea    0x4(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %r8d,%r8d
call   1060 <regexec@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
mov    %r12,%rdi
call   1030 <regfree@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
mov    %r12,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
@stderr = global i32 0
@.str = [28 x i8] c"Failed to compile regex %s\0A\00"
define i32 @match_regex(i8* %0, i8* %1, i32* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i64 %3, i64* %9
%11 = load i8*, i8** %7
%12 = load i32, i32* @REG_EXTENDED
%13 = load i32, i32* @REG_ICASE
%14 = or i32 %12, %13
%15 = call i64 @regcomp(i32* %10, i8* %11, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %4
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %7
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %4
%23 = load i8*, i8** %6
%24 = load i64, i64* %9
%25 = load i32*, i32** %8
%26 = call i64 @regexec(i32* %10, i8* %23, i64 %24, i32* %25, i32 0)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @regfree(i32* %10)
store i32 0, i32* %5
br label %32
30: ; preds = %22
%31 = call i32 @regfree(i32* %10)
store i32 1, i32* %5
br label %32
32: ; preds = %30, %28
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
@stderr = global i32 0
@.str = [28 x i8] c"Failed to compile regex %s\0A\00"
define i32 @match_regex(i8* %0, i8* %1, i32* %2, i64 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = load i32, i32* @REG_EXTENDED
%8 = load i32, i32* @REG_ICASE
%9 = or i32 %8, %7
%10 = call i64 @regcomp(i32* %5, i8* %1, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %4
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %1)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %4
%17 = call i64 @regexec(i32* %5, i8* %0, i64 %3, i32* %2, i32 0)
%18 = icmp ne i64 %17, 0
%19 = call i32 @regfree(i32* %5)
%20 = zext i1 %18 to i32
ret i32 %20
}