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

/* Variables and functions */
int /*<<< orphan*/ REG_EXTENDED;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ regerror(int, int /*<<< orphan*/ *, char *, int);
scalar_t__ regexec(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ *,
                   int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int doesMatch(char *pzExp, char *pzStr) {
  regex_t exp;
  int ret;
  int match = 0;
  if ((ret = regcomp(&exp, pzExp, REG_EXTENDED))) {
    char errbuf[1024] = {
        0,
    };
    regerror(ret, &exp, errbuf, sizeof(errbuf));
    fprintf(stderr, "regexp error: %s", errbuf);
  } else {
    regmatch_t matches[1];
    if (regexec(&exp, pzStr, 1, matches, 0) == 0) {
      match = 1;
    }
  }
  regfree(&exp);
  return match;
}


x86 assembly (clang, -O0):
<doesMatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rdi
call   1050 <regcomp@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     11e8 <doesMatch+0x88>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%edi
lea    -0x420(%rbp),%rdx
lea    -0x14(%rbp),%rsi
mov    $0x400,%ecx
call   1070 <regerror@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xe22(%rip),%rsi
call   1060 <fprintf@plt>
jmp    121a <doesMatch+0xba>
mov    -0x10(%rbp),%rsi
lea    -0x424(%rbp),%rcx
lea    -0x14(%rbp),%rdi
mov    $0x1,%edx
xor    %r8d,%r8d
call   1080 <regexec@plt>
cmp    $0x0,%rax
jne    1215 <doesMatch+0xb5>
movl   $0x1,-0x1c(%rbp)
jmp    121a <doesMatch+0xba>
lea    -0x14(%rbp),%rdi
call   1030 <regfree@plt>
mov    -0x1c(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doesMatch>:
push   %rbp
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    %rsi,%rbx
mov    %rdi,%rsi
mov    0x2e60(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rdi
call   1050 <regcomp@plt>
test   %eax,%eax
je     11ce <doesMatch+0x6e>
mov    %eax,%ebp
lea    0x10(%rsp),%r14
xor    %ebx,%ebx
mov    $0x400,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    $0x400,%ecx
call   1070 <regerror@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
jmp    11f0 <doesMatch+0x90>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rcx
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %r8d,%r8d
call   1080 <regexec@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
lea    0xc(%rsp),%rdi
call   1030 <regfree@plt>
mov    %ebx,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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