#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int REG_EXTENDED;
int REG_ICASE;
int REG_NOMATCH;
int REG_NOSUB;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ puts(char *);
scalar_t__ regcomp(int /*<<< orphan*/ *, char *, int);
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(int argc, char *argv[]) {
  regex_t regex;
  int ret;
  if (argc < 3) {
    fprintf(stderr, "argv[1] -> pattern\n"
                    "argv[2] -> text\n");
    return EXIT_FAILURE;
  }
  if (regcomp(&regex, argv[1], REG_EXTENDED | REG_ICASE | REG_NOSUB)) {
    fprintf(stderr, "Could not compile regex\n");
    return EXIT_FAILURE;
  }
  ret = regexec(&regex, argv[2], 0, NULL, 0);
  if (!ret)
    puts("Match");
  else if (ret == REG_NOMATCH)
    puts("No match");
  else {
    char msgbuf[100];
    regerror(ret, &regex, msgbuf, sizeof(msgbuf));
    fprintf(stderr, "Regex match failed: %s\n", msgbuf);
    return EXIT_FAILURE;
  }
  regfree(&regex);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11ab <main+0x4b>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12c0 <main+0x160>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    0x2dfe(%rip),%rax
mov    (%rax),%edx
mov    0x2e25(%rip),%rax
or     (%rax),%edx
mov    0x2e04(%rip),%rax
or     (%rax),%edx
lea    -0x14(%rbp),%rdi
call   1050 <regcomp@plt>
cmp    $0x0,%rax
je     1209 <main+0xa9>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12c0 <main+0x160>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x14(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1080 <regexec@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1242 <main+0xe2>
lea    0xe05(%rip),%rdi
call   1030 <puts@plt>
jmp    12ab <main+0x14b>
mov    -0x18(%rbp),%eax
mov    0x2d94(%rip),%rcx
cmp    (%rcx),%eax
jne    1265 <main+0x105>
lea    0xde8(%rip),%rdi
call   1030 <puts@plt>
jmp    12a6 <main+0x146>
mov    -0x18(%rbp),%edi
lea    -0x80(%rbp),%rdx
lea    -0x14(%rbp),%rsi
mov    $0x64,%ecx
call   1070 <regerror@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rdx
lea    0xdbe(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12c0 <main+0x160>
jmp    12ab <main+0x14b>
lea    -0x14(%rbp),%rdi
call   1040 <regfree@plt>
mov    0x2cf5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
cmp    $0x2,%edi
jg     117f <main+0x1f>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
jmp    11c0 <main+0x60>
mov    %rsi,%rbx
mov    0x2e2f(%rip),%rax
mov    0x2e58(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x8(%rsi),%rsi
mov    0x2e31(%rip),%rax
or     (%rax),%edx
lea    0xc(%rsp),%rdi
call   1050 <regcomp@plt>
test   %rax,%rax
je     11d9 <main+0x79>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
add    $0x80,%rsp
pop    %rbx
ret
mov    0x10(%rbx),%rsi
lea    0xc(%rsp),%rdi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1080 <regexec@plt>
test   %eax,%eax
je     1206 <main+0xa6>
mov    0x2de7(%rip),%rcx
cmp    (%rcx),%eax
jne    1225 <main+0xc5>
lea    0xe3f(%rip),%rdi
jmp    120d <main+0xad>
lea    0xe30(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rdi
call   1040 <regfree@plt>
mov    0x2d8d(%rip),%rax
jmp    11ce <main+0x6e>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0x64,%ecx
call   1070 <regerror@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11c7 <main+0x67>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"argv[1] -> pattern\0Aargv[2] -> text\0A\00"
@EXIT_FAILURE = global i32 0
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
@REG_NOSUB = global i32 0
@.str.1 = [25 x i8] c"Could not compile regex\0A\00"
@.str.2 = [6 x i8] c"Match\00"
@REG_NOMATCH = global i32 0
@.str.3 = [9 x i8] c"No match\00"
@.str.4 = [24 x i8] c"Regex match failed: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %3
br label %57
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @REG_EXTENDED
%20 = load i32, i32* @REG_ICASE
%21 = or i32 %19, %20
%22 = load i32, i32* @REG_NOSUB
%23 = or i32 %21, %22
%24 = call i64 @regcomp(i32* %6, i8* %18, i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %15
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
store i32 %29, i32* %3
br label %57
30: ; preds = %15
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @regexec(i32* %6, i8* %33, i32 0, i32* null, i32 0)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = icmp ne i32 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %30
%38 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %54
39: ; preds = %30
%40 = load i32, i32* %7
%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.3, i64 0, i64 0))
br label %53
45: ; preds = %39
%46 = load i32, i32* %7
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%48 = call i32 @regerror(i32 %46, i32* %6, i8* %47, i32 100)
%49 = load i32, i32* @stderr
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %50)
%52 = load i32, i32* @EXIT_FAILURE
store i32 %52, i32* %3
br label %57
53: ; preds = %43
br label %54
54: ; preds = %53, %37
%55 = call i32 @regfree(i32* %6)
%56 = load i32, i32* @EXIT_SUCCESS
store i32 %56, i32* %3
br label %57
57: ; preds = %54, %45, %26, %11
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"argv[1] -> pattern\0Aargv[2] -> text\0A\00"
@EXIT_FAILURE = global i32 0
@REG_EXTENDED = global i32 0
@REG_ICASE = global i32 0
@REG_NOSUB = global i32 0
@.str.1 = [25 x i8] c"Could not compile regex\0A\00"
@.str.2 = [6 x i8] c"Match\00"
@REG_NOMATCH = global i32 0
@.str.3 = [9 x i8] c"No match\00"
@.str.4 = [24 x i8] c"Regex match failed: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = bitcast i32* %3 to i8*
%6 = icmp slt i32 %0, 3
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
br label %44
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @REG_EXTENDED
%15 = load i32, i32* @REG_ICASE
%16 = or i32 %15, %14
%17 = load i32, i32* @REG_NOSUB
%18 = or i32 %16, %17
%19 = call i64 @regcomp(i32* %3, i8* %13, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %11
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
br label %44
25: ; preds = %11
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @regexec(i32* %3, i8* %27, i32 0, i32* null, i32 0)
%29 = icmp eq i32 %28, 0
br i1 %29, label %39, label %30
30: ; preds = %25
%31 = load i32, i32* @REG_NOMATCH
%32 = icmp eq i32 %28, %31
br i1 %32, label %39, label %33
33: ; preds = %30
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%35 = call i32 @regerror(i32 %28, i32* %3, i8* %34, i32 100)
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %34)
%38 = load i32, i32* @EXIT_FAILURE
br label %44
39: ; preds = %30, %25
%40 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %25 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), %30 ]
%41 = call i32 @puts(i8* dereferenceable(1) %40)
%42 = call i32 @regfree(i32* %3)
%43 = load i32, i32* @EXIT_SUCCESS
br label %44
44: ; preds = %39, %33, %21, %7
%45 = phi i32 [ %10, %7 ], [ %24, %21 ], [ %43, %39 ], [ %38, %33 ]
ret i32 %45
}