#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_NOSUB;
scalar_t__ regcomp(int /*<<< orphan*/ *, char *, int);
int regexec(int /*<<< orphan*/ *, char const *, size_t, int /*<<< orphan*/ *,
            int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
scalar_t__ strncmp(char *, char const *, int);
int regex_match(const char *string, const char *pattern) {
  int status;
  regex_t re;
  char *fix_pattern;
  if (strncmp("*", pattern, 1) != 0)
    fix_pattern = (char *)pattern;
  else
    fix_pattern = ".*";
  if (regcomp(&re, fix_pattern, REG_EXTENDED | REG_NOSUB) != 0)
    return 0;
  status = regexec(&re, string, (size_t)0, NULL, 0);
  regfree(&re);
  if (status != 0)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<regex_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xea6(%rip),%rdi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     117c <regex_match+0x3c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1187 <regex_match+0x47>
lea    0xe7d(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
mov    0x2e46(%rip),%rax
mov    (%rax),%edx
mov    0x2e45(%rip),%rax
or     (%rax),%edx
lea    -0x20(%rbp),%rdi
call   1050 <regcomp@plt>
cmp    $0x0,%rax
je     11bc <regex_match+0x7c>
movl   $0x0,-0x4(%rbp)
jmp    11fc <regex_match+0xbc>
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
mov    %rcx,%rdx
call   1060 <regexec@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <regfree@plt>
cmpl   $0x0,-0x1c(%rbp)
je     11f5 <regex_match+0xb5>
movl   $0x0,-0x4(%rbp)
jmp    11fc <regex_match+0xbc>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regex_match>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xeac(%rip),%rdi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
lea    0xe97(%rip),%rsi
cmovne %rbx,%rsi
mov    0x2e64(%rip),%rax
mov    0x2e65(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xc(%rsp),%rdi
call   1050 <regcomp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    11bb <regex_match+0x7b>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <regexec@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <regfree@plt>
xor    %eax,%eax
test   %ebp,%ebp
sete   %al
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"*\00"
@.str.1 = [3 x i8] c".*\00"
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
define i32 @regex_match(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i64 @strncmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %9, i32 1)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i8*, i8** %5
store i8* %13, i8** %8
br label %15
14: ; preds = %2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %15
15: ; preds = %14, %12
%16 = load i8*, i8** %8
%17 = load i32, i32* @REG_EXTENDED
%18 = load i32, i32* @REG_NOSUB
%19 = or i32 %17, %18
%20 = call i64 @regcomp(i32* %7, i8* %16, i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %15
store i32 0, i32* %3
br label %31
23: ; preds = %15
%24 = load i8*, i8** %4
%25 = call i32 @regexec(i32* %7, i8* %24, i64 0, i32* null, i32 0)
store i32 %25, i32* %6
%26 = call i32 @regfree(i32* %7)
%27 = load i32, i32* %6
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 0, i32* %3
br label %31
30: ; preds = %23
store i32 1, i32* %3
br label %31
31: ; preds = %30, %29, %22
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [2 x i8] c"*\00"
@.str.1 = [3 x i8] c".*\00"
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
define i32 @regex_match(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 @strncmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %1, i32 1)
%6 = icmp eq i64 %5, 0
%7 = select i1 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1
%8 = load i32, i32* @REG_EXTENDED
%9 = load i32, i32* @REG_NOSUB
%10 = or i32 %9, %8
%11 = call i64 @regcomp(i32* %3, i8* %7, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = call i32 @regexec(i32* %3, i8* %0, i64 0, i32* null, i32 0)
%15 = call i32 @regfree(i32* %3)
%16 = icmp eq i32 %14, 0
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %13, %2
%19 = phi i32 [ 0, %2 ], [ %17, %13 ]
ret i32 %19
}