#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_NEWLINE;
int regcomp(int /*<<< orphan*/ *, char const *, int);
int /*<<< orphan*/ regerror(int, int /*<<< orphan*/ *, char *, int);
int regexec(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ *,
            int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int handle_regex(char *text, const char *to_match, const int nmatch) {
  regex_t reg_comp;
  int status = regcomp(&reg_comp, to_match, REG_EXTENDED | REG_NEWLINE);
  if (status) {
    char err_msg[256];
    regerror(status, &reg_comp, err_msg, 256);
    return 0;
  }
  char *tmp = text;
  regmatch_t tmp_match[3];
  int res = regexec(&reg_comp, tmp, 2, tmp_match, 0);
  regfree(&reg_comp);
  return !res;
}


x86 assembly (clang, -O0):
<handle_regex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rsi
mov    0x2e77(%rip),%rax
mov    (%rax),%edx
mov    0x2e7e(%rip),%rax
or     (%rax),%edx
lea    -0x20(%rbp),%rdi
call   1040 <regcomp@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11a6 <handle_regex+0x66>
mov    -0x24(%rbp),%edi
lea    -0x130(%rbp),%rdx
lea    -0x20(%rbp),%rsi
mov    $0x100,%ecx
call   1050 <regerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <handle_regex+0xb3>
mov    -0x10(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rsi
lea    -0x144(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x2,%edx
xor    %r8d,%r8d
call   1060 <regexec@plt>
mov    %eax,-0x148(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <regfree@plt>
cmpl   $0x0,-0x148(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_regex>:
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%rbx
mov    0x2e84(%rip),%rax
mov    0x2e8d(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xc(%rsp),%rdi
call   1040 <regcomp@plt>
test   %eax,%eax
je     1187 <handle_regex+0x47>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %eax,%edi
mov    $0x100,%ecx
call   1050 <regerror@plt>
xor    %eax,%eax
jmp    11b5 <handle_regex+0x75>
lea    0xc(%rsp),%r14
lea    0x10(%rsp),%rcx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
xor    %r8d,%r8d
call   1060 <regexec@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <regfree@plt>
xor    %eax,%eax
test   %ebx,%ebx
sete   %al
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret

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

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