#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*/ s;
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*/ 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 *, int /*<<< orphan*/,
            int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(void) {
  regex_t regex;
  char *re;
  char *s;
  int re_err;
  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, 0, NULL, 0)))
    puts("Match");
  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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe4a(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <d_s@plt>
mov    %rax,-0x10(%rbp)
lea    0xe57(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <d_s@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rdi
call   1070 <regcomp@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     1224 <main+0x84>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x18(%rbp),%rsi
lea    -0x8(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   10b0 <regexec@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    1258 <main+0xb8>
lea    0xe22(%rip),%rdi
call   1040 <puts@plt>
jmp    12ba <main+0x11a>
mov    -0x1c(%rbp),%eax
mov    0x2d86(%rip),%rcx
cmp    (%rcx),%eax
jne    127b <main+0xdb>
lea    0xe05(%rip),%rdi
call   1040 <puts@plt>
jmp    12b5 <main+0x115>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
lea    -0x8(%rbp),%rsi
mov    $0x8,%ecx
call   1090 <regerror@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xddb(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
jmp    12ba <main+0x11a>
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    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe55(%rip),%rdi
call   1060 <printf@plt>
call   10a0 <d_s@plt>
mov    %rax,%rbx
lea    0xe67(%rip),%rdi
call   1060 <printf@plt>
call   10a0 <d_s@plt>
mov    %rax,%r14
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rdi
mov    %rbx,%rsi
call   1070 <regcomp@plt>
test   %eax,%eax
jne    1242 <main+0xa2>
lea    0x4(%rsp),%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10b0 <regexec@plt>
test   %eax,%eax
je     1212 <main+0x72>
mov    0x2de3(%rip),%rcx
cmp    (%rcx),%eax
jne    1263 <main+0xc3>
lea    0xe66(%rip),%rdi
jmp    1219 <main+0x79>
lea    0xe57(%rip),%rdi
call   1040 <puts@plt>
lea    0x4(%rsp),%rdi
call   1050 <regfree@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
mov    %r14,%rdx
mov    $0x8,%ecx
call   1090 <regerror@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
lea    0xdf8(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>

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

LLVM IR (-O2):
@.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 = bitcast i32* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @d_s(i8* undef)
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i8* @d_s(i8* undef)
%7 = load i32, i32* @REG_EXTENDED
%8 = call i32 @regcomp(i32* %1, i8* %4, i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = call i32 @regexec(i32* %1, i8* %6, i32 0, i32* null, 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* %1, i8* %6, 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.5, i64 0, i64 0), i8* %6)
%24 = call i32 @exit(i32 2)
unreachable
25: ; preds = %17, %14
%26 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %14 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), %17 ]
%27 = call i32 @puts(i8* dereferenceable(1) %26)
%28 = call i32 @regfree(i32* %1)
%29 = call i32 @free(i8* %4)
%30 = call i32 @free(i8* %6)
ret i32 0
}