#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*/ string;
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 *, ...);
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*/ stderr;
int rematch(char *re, char *string, size_t nmatch, regmatch_t *pmatch) {
  int re_err;
  regex_t regex;
  int value;
  if ((re_err = regcomp(&regex, re, REG_EXTENDED))) {
    fprintf(stderr, "Could not compile regex\n");
    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, string, sizeof(string));
    fprintf(stderr, "Regex match failed: %s\n", string);
    exit(1);
  }
  return value;
}


x86 assembly (clang, -O0):
<rematch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rdi
call   1030 <regcomp@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     11ab <rematch+0x5b>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x28(%rbp),%rdi
xor    %r8d,%r8d
call   1060 <regexec@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jne    11db <rematch+0x8b>
movl   $0x1,-0x2c(%rbp)
jmp    1238 <rematch+0xe8>
mov    -0x24(%rbp),%eax
mov    0x2e03(%rip),%rcx
cmp    (%rcx),%eax
jne    11f9 <rematch+0xa9>
movl   $0x0,-0x2c(%rbp)
jmp    1233 <rematch+0xe3>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rdx
lea    -0x28(%rbp),%rsi
mov    $0x8,%ecx
call   1050 <regerror@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1238 <rematch+0xe8>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rematch>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%rsi
mov    0x2e66(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rdi
call   1030 <regcomp@plt>
test   %eax,%eax
jne    11eb <rematch+0x9b>
lea    0x4(%rsp),%rdi
xor    %ebp,%ebp
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
xor    %r8d,%r8d
call   1060 <regexec@plt>
test   %eax,%eax
je     11d9 <rematch+0x89>
mov    0x2e4b(%rip),%rcx
cmp    (%rcx),%eax
je     11de <rematch+0x8e>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
mov    %r14,%rdx
mov    $0x8,%ecx
call   1050 <regerror@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@REG_EXTENDED = global i32 0
@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 @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 i32
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32* %3, i32** %8
%12 = load i8*, i8** %5
%13 = load i32, i32* @REG_EXTENDED
%14 = call i32 @regcomp(i32* %10, i8* %12, i32 %13)
store i32 %14, i32* %9
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %4
%21 = load i8*, i8** %6
%22 = load i64, i64* %7
%23 = load i32*, i32** %8
%24 = call i32 @regexec(i32* %10, i8* %21, i64 %22, i32* %23, i32 0)
store i32 %24, i32* %9
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %20
store i32 1, i32* %11
br label %41
27: ; preds = %20
%28 = load i32, i32* %9
%29 = load i32, i32* @REG_NOMATCH
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 0, i32* %11
br label %40
32: ; preds = %27
%33 = load i32, i32* %9
%34 = load i8*, i8** %6
%35 = call i32 @regerror(i32 %33, i32* %10, i8* %34, i32 8)
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %6
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %31
br label %41
41: ; preds = %40, %26
%42 = load i32, i32* %11
ret i32 %42
}

LLVM IR (-O2):
@REG_EXTENDED = global i32 0
@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 @rematch(i8* %0, i8* %1, i64 %2, i32* %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = load i32, i32* @REG_EXTENDED
%8 = call i32 @regcomp(i32* %5, i8* %0, i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %4
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %4
%15 = call i32 @regexec(i32* %5, i8* %1, i64 %2, i32* %3, i32 0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %25, label %17
17: ; preds = %14
%18 = load i32, i32* @REG_NOMATCH
%19 = icmp eq i32 %15, %18
br i1 %19, label %25, label %20
20: ; preds = %17
%21 = call i32 @regerror(i32 %15, i32* %5, i8* %1, i32 8)
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %17, %14
%26 = phi i32 [ 1, %14 ], [ 0, %17 ]
ret i32 %26
}