#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ s;
struct TYPE_3__ {
  scalar_t__ rm_eo;
  int /*<<< orphan*/ rm_so;
};
typedef TYPE_1__ regmatch_t;
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
int /*<<< orphan*/ REG_EXTENDED;
int REG_NOMATCH;
char *d_s(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ o_printer(char *, int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ regerror(int, int /*<<< orphan*/ *, char *, int);
int regexec(int /*<<< orphan*/ *, char *, size_t, TYPE_1__ *,
            int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(void) {
  regex_t regex;
  char *re;
  char *s;
  int re_err;
  size_t nmatch = 2;
  regmatch_t pmatch[2];
  printf("Enter a Regular Expression sequence: ");
  re = d_s(re);
  printf("Enter a test string to check the regex against: ");
  s = d_s(s);
  if ((re_err = regcomp(&regex, re, REG_EXTENDED))) {
    fprintf(stderr, "Could not compile regex\n");
    exit(1);
  }
  if (!(re_err = regexec(&regex, s, nmatch, pmatch, 0))) {
    puts("Match");
    o_printer(s, pmatch[1].rm_so, pmatch[1].rm_eo - 1);
  } else if (re_err == REG_NOMATCH)
    puts("No match");
  else {
    regerror(re_err, &regex, s, sizeof(s));
    fprintf(stderr, "Regex match failed: %s\n", s);
    exit(2);
  }
  regfree(&regex);
  free(re);
  free(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x2,-0x28(%rbp)
lea    0xe32(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <d_s@plt>
mov    %rax,-0x10(%rbp)
lea    0xe3f(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <d_s@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    0x2dcc(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rdi
call   1070 <regcomp@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     123c <main+0x8c>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    -0x50(%rbp),%rcx
lea    -0x8(%rbp),%rdi
xor    %r8d,%r8d
call   10b0 <regexec@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    1285 <main+0xd5>
lea    0xe09(%rip),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    -0x40(%rbp),%rdx
sub    $0x1,%rdx
call   10c0 <o_printer@plt>
jmp    12e7 <main+0x137>
mov    -0x1c(%rbp),%eax
mov    0x2d59(%rip),%rcx
cmp    (%rcx),%eax
jne    12a8 <main+0xf8>
lea    0xdd8(%rip),%rdi
call   1040 <puts@plt>
jmp    12e2 <main+0x132>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
lea    -0x8(%rbp),%rsi
mov    $0x8,%ecx
call   1090 <regerror@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdae(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>
jmp    12e7 <main+0x137>
lea    -0x8(%rbp),%rdi
call   1050 <regfree@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
lea    0xe42(%rip),%rdi
call   1060 <printf@plt>
call   10a0 <d_s@plt>
mov    %rax,%rbx
lea    0xe54(%rip),%rdi
call   1060 <printf@plt>
call   10a0 <d_s@plt>
mov    %rax,%r14
mov    0x2dea(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
call   1070 <regcomp@plt>
test   %eax,%eax
jne    1275 <main+0xc5>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rcx
mov    $0x2,%edx
mov    %r14,%rsi
xor    %r8d,%r8d
call   10b0 <regexec@plt>
test   %eax,%eax
je     1230 <main+0x80>
mov    0x2dca(%rip),%rcx
cmp    (%rcx),%eax
jne    1296 <main+0xe6>
lea    0xe4d(%rip),%rdi
call   1040 <puts@plt>
jmp    1251 <main+0xa1>
lea    0xe39(%rip),%rdi
call   1040 <puts@plt>
mov    0x28(%rsp),%esi
mov    0x20(%rsp),%rdx
add    $0xffffffffffffffff,%rdx
mov    %r14,%rdi
call   10c0 <o_printer@plt>
lea    0xc(%rsp),%rdi
call   1050 <regfree@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
lea    0xdd2(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
mov    %r14,%rdx
mov    $0x8,%ecx
call   1090 <regerror@plt>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
lea    0xdc5(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i32 }
@.str = [38 x i8] c"Enter a Regular Expression sequence: \00"
@.str.1 = [49 x i8] c"Enter a test string to check the regex against: \00"
@REG_EXTENDED = global i32 0
@stderr = global i32 0
@.str.2 = [25 x i8] c"Could not compile regex\0A\00"
@.str.3 = [6 x i8] c"Match\00"
@REG_NOMATCH = global i32 0
@.str.4 = [9 x i8] c"No match\00"
@.str.5 = [24 x i8] c"Regex match failed: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca [2 x %struct.TYPE_3__]
store i32 0, i32* %1
store i64 2, i64* %6
%8 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%9 = load i8*, i8** %3
%10 = call i8* @d_s(i8* %9)
store i8* %10, i8** %3
%11 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%12 = load i8*, i8** %4
%13 = call i8* @d_s(i8* %12)
store i8* %13, i8** %4
%14 = load i8*, i8** %3
%15 = load i32, i32* @REG_EXTENDED
%16 = call i32 @regcomp(i32* %2, i8* %14, i32 %15)
store i32 %16, i32* %5
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %0
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %0
%23 = load i8*, i8** %4
%24 = load i64, i64* %6
%25 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %7, i64 0, i64 0
%26 = call i32 @regexec(i32* %2, i8* %23, i64 %24, %struct.TYPE_3__* %25, i32 0)
store i32 %26, i32* %5
%27 = icmp ne i32 %26, 0
br i1 %27, label %39, label %28
28: ; preds = %22
%29 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%30 = load i8*, i8** %4
%31 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %7, i64 0, i64 1
%32 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %31, i32 0, i32 1
%33 = load i32, i32* %32
%34 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %7, i64 0, i64 1
%35 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %34, i32 0, i32 0
%36 = load i64, i64* %35
%37 = sub nsw i64 %36, 1
%38 = call i32 @o_printer(i8* %30, i32 %33, i64 %37)
br label %54
39: ; preds = %22
%40 = load i32, i32* %5
%41 = load i32, i32* @REG_NOMATCH
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %53
45: ; preds = %39
%46 = load i32, i32* %5
%47 = load i8*, i8** %4
%48 = call i32 @regerror(i32 %46, i32* %2, i8* %47, i32 8)
%49 = load i32, i32* @stderr
%50 = load i8*, i8** %4
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %50)
%52 = call i32 @exit(i32 2)
unreachable
53: ; preds = %43
br label %54
54: ; preds = %53, %28
%55 = call i32 @regfree(i32* %2)
%56 = load i8*, i8** %3
%57 = call i32 @free(i8* %56)
%58 = load i8*, i8** %4
%59 = call i32 @free(i8* %58)
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i32 }
@.str = [38 x i8] c"Enter a Regular Expression sequence: \00"
@.str.1 = [49 x i8] c"Enter a test string to check the regex against: \00"
@REG_EXTENDED = global i32 0
@stderr = global i32 0
@.str.2 = [25 x i8] c"Could not compile regex\0A\00"
@.str.3 = [6 x i8] c"Match\00"
@REG_NOMATCH = global i32 0
@.str.4 = [9 x i8] c"No match\00"
@.str.5 = [24 x i8] c"Regex match failed: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x %struct.TYPE_3__]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [2 x %struct.TYPE_3__]* %2 to i8*
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%6 = tail call i8* @d_s(i8* undef)
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i8* @d_s(i8* undef)
%9 = load i32, i32* @REG_EXTENDED
%10 = call i32 @regcomp(i32* %1, i8* %6, i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %2, i64 0, i64 0
%18 = call i32 @regexec(i32* %1, i8* %8, i64 2, %struct.TYPE_3__* %17, i32 0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%22 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %2, i64 0, i64 1, i32 1
%23 = load i32, i32* %22
%24 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %2, i64 0, i64 1, i32 0
%25 = load i64, i64* %24
%26 = add nsw i64 %25, -1
%27 = call i32 @o_printer(i8* %8, i32 %23, i64 %26)
br label %38
28: ; preds = %16
%29 = load i32, i32* @REG_NOMATCH
%30 = icmp eq i32 %18, %29
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %38
33: ; preds = %28
%34 = call i32 @regerror(i32 %18, i32* %1, i8* %8, i32 8)
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%37 = call i32 @exit(i32 2)
unreachable
38: ; preds = %31, %20
%39 = call i32 @regfree(i32* %1)
%40 = call i32 @free(i8* %6)
%41 = call i32 @free(i8* %8)
ret i32 0
}