#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_ICASE;
scalar_t__ regcomp(int /*<<< orphan*/ *, char *, int);
int regexec(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/,
            int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int preg_match(const char *string, char *pattern) {
  int status;
  regex_t re;
  regmatch_t match[2];
  if (regcomp(&re, pattern, REG_EXTENDED | REG_ICASE) != 0) {
    return (0);
  }
  status = regexec(&re, string, 0, NULL, 0);
  if (status != 0) {
    return (0);
  }
  regfree(&re);
  return (1);
}


x86 assembly (clang, -O0):
<preg_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    0x2e8d(%rip),%rax
mov    (%rax),%edx
mov    0x2e94(%rip),%rax
or     (%rax),%edx
lea    -0x20(%rbp),%rdi
call   1040 <regcomp@plt>
cmp    $0x0,%rax
je     1175 <preg_match+0x45>
movl   $0x0,-0x4(%rbp)
jmp    11b5 <preg_match+0x85>
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1050 <regexec@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11a5 <preg_match+0x75>
movl   $0x0,-0x4(%rbp)
jmp    11b5 <preg_match+0x85>
lea    -0x20(%rbp),%rdi
call   1030 <regfree@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<preg_match>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e9a(%rip),%rax
mov    0x2ea3(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0x4(%rsp),%rdi
call   1040 <regcomp@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    1183 <preg_match+0x53>
xor    %ebx,%ebx
lea    0x4(%rsp),%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <regexec@plt>
test   %eax,%eax
jne    1183 <preg_match+0x53>
lea    0x4(%rsp),%rdi
call   1030 <regfree@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
define i32 @preg_match(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [2 x i32]
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = load i32, i32* @REG_EXTENDED
%11 = load i32, i32* @REG_ICASE
%12 = or i32 %10, %11
%13 = call i64 @regcomp(i32* %7, i8* %9, i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 0, i32* %3
br label %24
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = call i32 @regexec(i32* %7, i8* %17, i32 0, i32* null, i32 0)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 0, i32* %3
br label %24
22: ; preds = %16
%23 = call i32 @regfree(i32* %7)
store i32 1, i32* %3
br label %24
24: ; preds = %22, %21, %15
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
define i32 @preg_match(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @REG_EXTENDED
%6 = load i32, i32* @REG_ICASE
%7 = or i32 %6, %5
%8 = call i64 @regcomp(i32* %3, i8* %1, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = call i32 @regexec(i32* %3, i8* %0, i32 0, i32* null, i32 0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @regfree(i32* %3)
br label %15
15: ; preds = %10, %2, %13
%16 = phi i32 [ 1, %13 ], [ 0, %2 ], [ 0, %10 ]
ret i32 %16
}