#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 /*<<< orphan*/ REG_EXTENDED;
int REG_NOMATCH;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ regerror(int, int /*<<< orphan*/ *, char *, int);
int regexec(int /*<<< orphan*/ *, char *, size_t, int /*<<< orphan*/ *,
            int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int rematch(char *string, char *re, size_t nmatch, regmatch_t *pmatch) {
  int re_err;
  char err_msg[1000];
  regex_t regex;
  int value;
  if ((re_err = regcomp(&regex, re, REG_EXTENDED))) {
    fprintf(stderr, "Could not compile regex: [%s]\n", re);
    exit(1);
  }
  if (!(re_err = regexec(&regex, string, nmatch, pmatch, 0)))
    value = 1;
  else if (re_err == REG_NOMATCH)
    value = 0;
  else {
    regerror(re_err, &regex, err_msg, 1000);
    fprintf(stderr, "Regex match failed: %s\n", err_msg);
    exit(1);
  }
  regfree(&regex);
  return value;
}


x86 assembly (clang, -O0):
<rematch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
lea    -0x414(%rbp),%rdi
call   1040 <regcomp@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     11c3 <rematch+0x63>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe4c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x414(%rbp),%rdi
xor    %r8d,%r8d
call   1070 <regexec@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jne    11f9 <rematch+0x99>
movl   $0x1,-0x418(%rbp)
jmp    1260 <rematch+0x100>
mov    -0x24(%rbp),%eax
mov    0x2de5(%rip),%rcx
cmp    (%rcx),%eax
jne    121a <rematch+0xba>
movl   $0x0,-0x418(%rbp)
jmp    125b <rematch+0xfb>
mov    -0x24(%rbp),%edi
lea    -0x410(%rbp),%rdx
lea    -0x414(%rbp),%rsi
mov    $0x3e8,%ecx
call   1060 <regerror@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xdd3(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1260 <rematch+0x100>
lea    -0x414(%rbp),%rdi
call   1030 <regfree@plt>
mov    -0x418(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rematch>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3f8,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    0x2e50(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rdi
call   1040 <regcomp@plt>
test   %eax,%eax
jne    1204 <rematch+0xa4>
lea    0xc(%rsp),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %r8d,%r8d
call   1070 <regexec@plt>
test   %eax,%eax
je     11e5 <rematch+0x85>
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%eax
je     11ea <rematch+0x8a>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0x3e8,%ecx
call   1060 <regerror@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
mov    %rbx,%rdx
jmp    1217 <rematch+0xb7>
mov    $0x1,%ebp
lea    0xc(%rsp),%rdi
call   1030 <regfree@plt>
mov    %ebp,%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
mov    %rbp,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

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