#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*/ regex_message;

/* Variables and functions */
int /*<<< orphan*/ REG_ICASE;
int REG_NOMATCH;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, 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() {
  regex_t regex;
  int regex_return;
  char regex_message[1000];
  regex_return = regcomp(&regex, "^a[[:alnum:]]", REG_ICASE);
  if (regex_return) {
    fprintf(stderr, "Can't compile regex\n", NULL, 0);
  }
  regex_return = regexec(&regex, "abcABC", 0, NULL, 0);
  if (regex_return == 0) {
    puts("Matched");
  } else if (regex_return == REG_NOMATCH) {
    puts("No Match");
  } else {
    regerror(regex_return, &regex, regex_message, sizeof(regex_message));
    fprintf(stderr, "Regex match failed: %s\n", regex_message);
    exit(regex_return);
  }
  regfree(&regex);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1050 <regcomp@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11c5 <main+0x55>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x8(%rbp),%rdi
lea    0xe53(%rip),%rsi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1080 <regexec@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11fd <main+0x8d>
lea    0xe37(%rip),%rdi
call   1030 <puts@plt>
jmp    1263 <main+0xf3>
mov    -0xc(%rbp),%eax
mov    0x2dd9(%rip),%rcx
cmp    (%rcx),%eax
jne    1220 <main+0xb0>
lea    0xe1c(%rip),%rdi
call   1030 <puts@plt>
jmp    125e <main+0xee>
mov    -0xc(%rbp),%edi
lea    -0x400(%rbp),%rdx
lea    -0x8(%rbp),%rsi
mov    $0x3e8,%ecx
call   1070 <regerror@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    -0x400(%rbp),%rdx
lea    0xdec(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xc(%rbp),%edi
call   1090 <exit@plt>
jmp    1263 <main+0xf3>
lea    -0x8(%rbp),%rdi
call   1040 <regfree@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x3f8,%rsp
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
lea    0xe76(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1050 <regcomp@plt>
test   %eax,%eax
je     11b3 <main+0x43>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe69(%rip),%rsi
lea    0xc(%rsp),%rdi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1080 <regexec@plt>
test   %eax,%eax
je     11e5 <main+0x75>
mov    %eax,%ebx
mov    0x2e08(%rip),%rax
cmp    (%rax),%ebx
jne    1208 <main+0x98>
lea    0xe4f(%rip),%rdi
jmp    11ec <main+0x7c>
lea    0xe3e(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rdi
call   1040 <regfree@plt>
xor    %eax,%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rdx
mov    $0x3e8,%ecx
call   1070 <regerror@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"^a[[:alnum:]]\00"
@REG_ICASE = global i32 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"Can't compile regex\0A\00"
@.str.2 = [7 x i8] c"abcABC\00"
@.str.3 = [8 x i8] c"Matched\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 i32
%4 = alloca [1000 x i8]
store i32 0, i32* %1
%5 = load i32, i32* @REG_ICASE
%6 = call i32 @regcomp(i32* %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* null, i32 0)
br label %12
12: ; preds = %9, %0
%13 = call i32 @regexec(i32* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 0, i32* null, i32 0)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %34
18: ; preds = %12
%19 = load i32, i32* %3
%20 = load i32, i32* @REG_NOMATCH
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %33
24: ; preds = %18
%25 = load i32, i32* %3
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%27 = call i32 @regerror(i32 %25, i32* %2, i8* %26, i32 1000)
%28 = load i32, i32* @stderr
%29 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%30 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %29)
%31 = load i32, i32* %3
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %22
br label %34
34: ; preds = %33, %16
%35 = call i32 @regfree(i32* %2)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"^a[[:alnum:]]\00"
@REG_ICASE = global i32 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"Can't compile regex\0A\00"
@.str.2 = [7 x i8] c"abcABC\00"
@.str.3 = [8 x i8] c"Matched\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 [1000 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @REG_ICASE
%6 = call i32 @regcomp(i32* %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* null, i32 0)
br label %11
11: ; preds = %8, %0
%12 = call i32 @regexec(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 0, i32* null, i32 0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %11
%15 = load i32, i32* @REG_NOMATCH
%16 = icmp eq i32 %12, %15
br i1 %16, label %22, label %17
17: ; preds = %14
%18 = call i32 @regerror(i32 %12, i32* %1, i8* %4, i32 1000)
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%21 = call i32 @exit(i32 %12)
unreachable
22: ; preds = %14, %11
%23 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), %11 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), %14 ]
%24 = call i32 @puts(i8* dereferenceable(1) %23)
%25 = call i32 @regfree(i32* %1)
ret i32 0
}