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


x86 assembly (clang, -O0):
<nq_regex_get_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     11d7 <nq_regex_get_match+0x87>
mov    -0x34(%rbp),%edi
lea    -0x440(%rbp),%rdx
lea    -0x444(%rbp),%rsi
mov    $0x400,%ecx
call   1050 <regerror@plt>
lea    -0x440(%rbp),%rsi
lea    0xe46(%rip),%rdi
call   1060 <nq_errmsg@plt>
lea    -0x444(%rbp),%rdi
call   1030 <regfree@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123d <nq_regex_get_match+0xed>
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%r8d
lea    -0x444(%rbp),%rdi
call   1070 <regexec@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    0x2de8(%rip),%rcx
cmp    (%rcx),%eax
jne    122a <nq_regex_get_match+0xda>
jmp    120d <nq_regex_get_match+0xbd>
jmp    1212 <nq_regex_get_match+0xc2>
lea    -0x444(%rbp),%rdi
call   1030 <regfree@plt>
movl   $0x1,-0x4(%rbp)
jmp    123d <nq_regex_get_match+0xed>
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_get_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     11b3 <nq_regex_get_match+0x63>
lea    0xc(%rsp),%rbx
lea    0x10(%rsp),%rbp
mov    %eax,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    $0x400,%ecx
call   1050 <regerror@plt>
lea    0xe64(%rip),%rdi
mov    %rbp,%rsi
call   1060 <nq_errmsg@plt>
mov    %rbx,%rdi
call   1030 <regfree@plt>
mov    $0xffffffff,%ebx
jmp    11e2 <nq_regex_get_match+0x92>
lea    0xc(%rsp),%r12
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %r15d,%r8d
call   1070 <regexec@plt>
mov    0x2e15(%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):
@.str = [12 x i8] c"regcomp: %s\00"
@REG_NOMATCH = global i32 0
define i32 @nq_regex_get_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 %29
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)
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%27 = call i32 @nq_errmsg(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = call i32 @regfree(i32* %16)
store i32 -1, i32* %7
br label %44
29: ; preds = %6
%30 = load i8*, i8** %8
%31 = load i64, i64* %12
%32 = load i32*, i32** %13
%33 = load i32, i32* %11
%34 = call i32 @regexec(i32* %16, i8* %30, i64 %31, i32* %32, i32 %33)
store i32 %34, i32* %14
%35 = load i32, i32* %14
%36 = load i32, i32* @REG_NOMATCH
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %42
38: ; preds = %29
br label %39
39: ; preds = %38
br label %40
40: ; preds = %39
%41 = call i32 @regfree(i32* %16)
store i32 1, i32* %7
br label %44
42: ; preds = %29
%43 = call i32 @regfree(i32* %16)
store i32 0, i32* %7
br label %44
44: ; preds = %42, %40, %22
%45 = load i32, i32* %7
ret i32 %45
}

LLVM IR (-O2):
@.str = [12 x i8] c"regcomp: %s\00"
@REG_NOMATCH = global i32 0
define i32 @nq_regex_get_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 %17, label %13
13: ; preds = %6
%14 = call i32 @regerror(i32 %11, i32* %8, i8* %9, i32 1024)
%15 = call i32 @nq_errmsg(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %9)
%16 = call i32 @regfree(i32* %8)
br label %23
17: ; preds = %6
%18 = call i32 @regexec(i32* %8, i8* %0, i64 %4, i32* %5, i32 %3)
%19 = load i32, i32* @REG_NOMATCH
%20 = icmp eq i32 %18, %19
%21 = call i32 @regfree(i32* %8)
%22 = zext i1 %20 to i32
br label %23
23: ; preds = %17, %13
%24 = phi i32 [ -1, %13 ], [ %22, %17 ]
ret i32 %24
}