#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;
typedef int /*<<< orphan*/ msgbuf;

/* Variables and functions */
int REG_NOMATCH;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ regerror(int, int /*<<< orphan*/ *, char *, int);
int regexec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
            int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int regexp_match(char *pattern, char *string) {
  regex_t regex;
  int ret;
  char msgbuf[100];
  ret = regcomp(&regex, pattern, 0);
  if (ret) {
    fprintf(stderr, "Could not compile regex\n");
    return 0;
  }
  ret = regexec(&regex, string, 0, NULL, 0);
  if (!ret) {
    return 1;
  } else if (ret == REG_NOMATCH) {
    return 0;
  } else {
    regerror(ret, &regex, msgbuf, sizeof(msgbuf));
    fprintf(stderr, "Regex match failed: %s\n", msgbuf);
    return 0;
  }
  regfree(&regex);
}


x86 assembly (clang, -O0):
<regexp_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
xor    %edx,%edx
call   1030 <regcomp@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1192 <regexp_match+0x52>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    121d <regexp_match+0xdd>
mov    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1060 <regexec@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    11c2 <regexp_match+0x82>
movl   $0x1,-0x4(%rbp)
jmp    121d <regexp_match+0xdd>
mov    -0x20(%rbp),%eax
mov    0x2e1c(%rip),%rcx
cmp    (%rcx),%eax
jne    11e0 <regexp_match+0xa0>
movl   $0x0,-0x4(%rbp)
jmp    121d <regexp_match+0xdd>
mov    -0x20(%rbp),%edi
lea    -0x90(%rbp),%rdx
lea    -0x1c(%rbp),%rsi
mov    $0x64,%ecx
call   1050 <regerror@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    -0x90(%rbp),%rdx
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regexp_match>:
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%r14
mov    %rdi,%rsi
lea    0xc(%rsp),%rdi
xor    %ebx,%ebx
xor    %edx,%edx
call   1030 <regcomp@plt>
test   %eax,%eax
je     1180 <regexp_match+0x40>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret
xor    %ebx,%ebx
lea    0xc(%rsp),%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <regexec@plt>
test   %eax,%eax
je     11dc <regexp_match+0x9c>
mov    0x2e47(%rip),%rcx
cmp    (%rcx),%eax
je     1176 <regexp_match+0x36>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rdx
mov    $0x64,%ecx
call   1050 <regerror@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
xor    %ebx,%ebx
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1176 <regexp_match+0x36>
mov    $0x1,%ebx
jmp    1176 <regexp_match+0x36>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"Could not compile regex\0A\00"
@REG_NOMATCH = global i32 0
@.str.1 = [24 x i8] c"Regex match failed: %s\0A\00"
define i32 @regexp_match(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [100 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i32 @regcomp(i32* %6, i8* %9, i32 0)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %34
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = call i32 @regexec(i32* %6, i8* %17, i32 0, i32* null, i32 0)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %16
store i32 1, i32* %3
br label %34
22: ; preds = %16
%23 = load i32, i32* %7
%24 = load i32, i32* @REG_NOMATCH
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 0, i32* %3
br label %34
27: ; preds = %22
%28 = load i32, i32* %7
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%30 = call i32 @regerror(i32 %28, i32* %6, i8* %29, i32 100)
%31 = load i32, i32* @stderr
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %32)
store i32 0, i32* %3
br label %34
34: ; preds = %27, %26, %21, %13
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"Could not compile regex\0A\00"
@REG_NOMATCH = global i32 0
@.str.1 = [24 x i8] c"Regex match failed: %s\0A\00"
define i32 @regexp_match(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%7 = call i32 @regcomp(i32* %3, i8* %0, i32 0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %22
12: ; preds = %2
%13 = call i32 @regexec(i32* %3, i8* %1, i32 0, i32* null, i32 0)
%14 = icmp eq i32 %13, 0
br i1 %14, label %22, label %15
15: ; preds = %12
%16 = load i32, i32* @REG_NOMATCH
%17 = icmp eq i32 %13, %16
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = call i32 @regerror(i32 %13, i32* %3, i8* %6, i32 100)
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %22
22: ; preds = %15, %12, %18, %9
%23 = phi i32 [ 0, %9 ], [ 0, %18 ], [ 1, %12 ], [ 0, %15 ]
ret i32 %23
}