#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_NOMATCH;
int regcomp(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ regerror(int, int /*<<< orphan*/ *, char *, int);
int regexec(int /*<<< orphan*/ *, char *, size_t, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int nq_regex_match(char *s, char *pattern, int cflags, int eflags,
                   size_t nmatch, regmatch_t *offset) {
  int ret_val;
  char errbuff[1024];
  regex_t regex;
  ret_val = regcomp(&regex, pattern, cflags);
  if (ret_val) {
    regerror(ret_val, &regex, errbuff, 1024);
    do {
    } while (0);
    return -1;
  }
  ret_val = regexec(&regex, s, nmatch, offset, eflags);
  if (ret_val == REG_NOMATCH) {
    do {
    } while (0);
    regfree(&regex);
    return 1;
  }
  regfree(&regex);
  return 0;
}


x86 assembly (clang, -O0):
<nq_regex_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x444(%rbp),%rdi
call   1040 <regcomp@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11ad <nq_regex_match+0x6d>
mov    -0x34(%rbp),%edi
lea    -0x440(%rbp),%rdx
lea    -0x444(%rbp),%rsi
mov    $0x400,%ecx
call   1050 <regerror@plt>
jmp    11a1 <nq_regex_match+0x61>
movl   $0xffffffff,-0x4(%rbp)
jmp    1213 <nq_regex_match+0xd3>
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%r8d
lea    -0x444(%rbp),%rdi
call   1060 <regexec@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    0x2e12(%rip),%rcx
cmp    (%rcx),%eax
jne    1200 <nq_regex_match+0xc0>
jmp    11e3 <nq_regex_match+0xa3>
jmp    11e8 <nq_regex_match+0xa8>
lea    -0x444(%rbp),%rdi
call   1030 <regfree@plt>
movl   $0x1,-0x4(%rbp)
jmp    1213 <nq_regex_match+0xd3>
lea    -0x444(%rbp),%rdi
call   1030 <regfree@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nq_regex_match>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
mov    %r9,%r14
mov    %r8,%rbx
mov    %ecx,%r15d
mov    %rdi,%rbp
lea    0xc(%rsp),%rdi
call   1040 <regcomp@plt>
test   %eax,%eax
je     1186 <nq_regex_match+0x46>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %eax,%edi
mov    $0x400,%ecx
call   1050 <regerror@plt>
mov    $0xffffffff,%ebx
jmp    11b5 <nq_regex_match+0x75>
lea    0xc(%rsp),%r12
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %r15d,%r8d
call   1060 <regexec@plt>
mov    0x2e42(%rip),%rcx
xor    %ebx,%ebx
cmp    (%rcx),%eax
sete   %bl
mov    %r12,%rdi
call   1030 <regfree@plt>
mov    %ebx,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@REG_NOMATCH = global i32 0
define i32 @nq_regex_match(i8* %0, i8* %1, i32 %2, i32 %3, i64 %4, i32* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i32*
%14 = alloca i32
%15 = alloca [1024 x i8]
%16 = alloca i32
store i8* %0, i8** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i64 %4, i64* %12
store i32* %5, i32** %13
%17 = load i8*, i8** %9
%18 = load i32, i32* %10
%19 = call i32 @regcomp(i32* %16, i8* %17, i32 %18)
store i32 %19, i32* %14
%20 = load i32, i32* %14
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %6
%23 = load i32, i32* %14
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%25 = call i32 @regerror(i32 %23, i32* %16, i8* %24, i32 1024)
br label %26
26: ; preds = %22
br label %27
27: ; preds = %26
store i32 -1, i32* %7
br label %43
28: ; preds = %6
%29 = load i8*, i8** %8
%30 = load i64, i64* %12
%31 = load i32*, i32** %13
%32 = load i32, i32* %11
%33 = call i32 @regexec(i32* %16, i8* %29, i64 %30, i32* %31, i32 %32)
store i32 %33, i32* %14
%34 = load i32, i32* %14
%35 = load i32, i32* @REG_NOMATCH
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %41
37: ; preds = %28
br label %38
38: ; preds = %37
br label %39
39: ; preds = %38
%40 = call i32 @regfree(i32* %16)
store i32 1, i32* %7
br label %43
41: ; preds = %28
%42 = call i32 @regfree(i32* %16)
store i32 0, i32* %7
br label %43
43: ; preds = %41, %39, %27
%44 = load i32, i32* %7
ret i32 %44
}

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