#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*/ regex_t;

/* Variables and functions */
int REG_EXTENDED;
int REG_ICASE;
int REG_NEWLINE;
int REG_NOTBOL;
int REG_NOTEOL;
scalar_t__ regcomp(int /*<<< orphan*/ *, char const *, int);
scalar_t__ regexec(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/,
                   int /*<<< orphan*/ *, int);
short int regexp_match(const char *string, const char *regexp,
                       short int casess) {
  regex_t preg;
  int flags = 0;
  flags = REG_NEWLINE | REG_EXTENDED;
  if (!casess)
    flags |= REG_ICASE;
  if (regcomp(&preg, regexp, flags) != 0)
    return (-1);
  if (regexec(&preg, string, 0, NULL, REG_NOTBOL | REG_NOTEOL) != 0)
    return (1);
  return (0);
}


x86 assembly (clang, -O0):
<regexp_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dx,%ax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %ax,-0x1a(%rbp)
movl   $0x0,-0x24(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
mov    0x2e72(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x24(%rbp)
cmpw   $0x0,-0x1a(%rbp)
jne    116d <regexp_match+0x4d>
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    -0x20(%rbp),%rdi
call   1030 <regcomp@plt>
cmp    $0x0,%rax
je     1192 <regexp_match+0x72>
movw   $0xffff,-0x2(%rbp)
jmp    11d4 <regexp_match+0xb4>
mov    -0x10(%rbp),%rsi
mov    0x2e43(%rip),%rax
mov    (%rax),%r8d
mov    0x2e31(%rip),%rax
or     (%rax),%r8d
lea    -0x20(%rbp),%rdi
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <regexec@plt>
cmp    $0x0,%rax
je     11ce <regexp_match+0xae>
movw   $0x1,-0x2(%rbp)
jmp    11d4 <regexp_match+0xb4>
movw   $0x0,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regexp_match>:
push   %rbx
sub    $0x10,%rsp
mov    %edx,%eax
mov    %rdi,%rbx
mov    0x2e9f(%rip),%rcx
mov    0x2e88(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
xor    %ecx,%ecx
test   %ax,%ax
jne    114c <regexp_match+0x2c>
mov    0x2e9e(%rip),%rax
mov    (%rax),%ecx
or     %ecx,%edx
lea    0xc(%rsp),%rdi
call   1030 <regcomp@plt>
mov    %rax,%rcx
mov    $0xffff,%ax
test   %rcx,%rcx
jne    1194 <regexp_match+0x74>
mov    0x2e75(%rip),%rax
mov    0x2e66(%rip),%rcx
mov    (%rcx),%r8d
or     (%rax),%r8d
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <regexec@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@REG_NEWLINE = global i32 0
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
@REG_NOTBOL = global i32 0
@REG_NOTEOL = global i32 0
define signext i16 @regexp_match(i8* %0, i8* %1, i16 signext %2) {
%4 = alloca i16
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i16
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i16 %2, i16* %7
store i32 0, i32* %9
%10 = load i32, i32* @REG_NEWLINE
%11 = load i32, i32* @REG_EXTENDED
%12 = or i32 %10, %11
store i32 %12, i32* %9
%13 = load i16, i16* %7
%14 = icmp ne i16 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %3
%16 = load i32, i32* @REG_ICASE
%17 = load i32, i32* %9
%18 = or i32 %17, %16
store i32 %18, i32* %9
br label %19
19: ; preds = %15, %3
%20 = load i8*, i8** %6
%21 = load i32, i32* %9
%22 = call i64 @regcomp(i32* %8, i8* %20, i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i16 -1, i16* %4
br label %34
25: ; preds = %19
%26 = load i8*, i8** %5
%27 = load i32, i32* @REG_NOTBOL
%28 = load i32, i32* @REG_NOTEOL
%29 = or i32 %27, %28
%30 = call i64 @regexec(i32* %8, i8* %26, i32 0, i32* null, i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %25
store i16 1, i16* %4
br label %34
33: ; preds = %25
store i16 0, i16* %4
br label %34
34: ; preds = %33, %32, %24
%35 = load i16, i16* %4
ret i16 %35
}

LLVM IR (-O2):
@REG_NEWLINE = global i32 0
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
@REG_NOTBOL = global i32 0
@REG_NOTEOL = global i32 0
define signext i16 @regexp_match(i8* %0, i8* %1, i16 signext %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = load i32, i32* @REG_NEWLINE
%7 = load i32, i32* @REG_EXTENDED
%8 = or i32 %7, %6
%9 = icmp eq i16 %2, 0
%10 = load i32, i32* @REG_ICASE
%11 = select i1 %9, i32 %10, i32 0
%12 = or i32 %8, %11
%13 = call i64 @regcomp(i32* %4, i8* %1, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %3
%16 = load i32, i32* @REG_NOTBOL
%17 = load i32, i32* @REG_NOTEOL
%18 = or i32 %17, %16
%19 = call i64 @regexec(i32* %4, i8* %0, i32 0, i32* null, i32 %18)
%20 = icmp ne i64 %19, 0
%21 = zext i1 %20 to i16
br label %22
22: ; preds = %15, %3
%23 = phi i16 [ -1, %3 ], [ %21, %15 ]
ret i16 %23
}