#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 REG_NOMATCH;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, 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(int argc, char *argv[]) {
  regex_t regex;
  int reti;
  char msgbuf[100];
  reti = regcomp(&regex, "^a[[:alnum:]]", 0);
  if (reti) {
    fprintf(stderr, "Could not compile regex\n");
    exit(1);
  }
  reti = regexec(&regex, "abc", 0, NULL, 0);
  if (!reti) {
    puts("Match");
  } else if (reti == REG_NOMATCH) {
    puts("No match");
  } else {
    regerror(reti, &regex, msgbuf, sizeof(msgbuf));
    fprintf(stderr, "Regex match failed: %s\n", msgbuf);
    exit(1);
  }
  regfree(&regex);
  return 0;
}


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)
lea    -0x14(%rbp),%rdi
lea    0xe6c(%rip),%rsi
xor    %edx,%edx
call   1050 <regcomp@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11c9 <main+0x59>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x14(%rbp),%rdi
lea    0xe53(%rip),%rsi
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    1201 <main+0x91>
lea    0xe34(%rip),%rdi
call   1030 <puts@plt>
jmp    1263 <main+0xf3>
mov    -0x18(%rbp),%eax
mov    0x2ddd(%rip),%rcx
cmp    (%rcx),%eax
jne    1224 <main+0xb4>
lea    0xe17(%rip),%rdi
call   1030 <puts@plt>
jmp    125e <main+0xee>
mov    -0x18(%rbp),%edi
lea    -0x80(%rbp),%rdx
lea    -0x14(%rbp),%rsi
mov    $0x64,%ecx
call   1070 <regerror@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rdx
lea    0xded(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1263 <main+0xf3>
lea    -0x14(%rbp),%rdi
call   1040 <regfree@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
lea    0xe81(%rip),%rsi
lea    0xc(%rsp),%rdi
xor    %edx,%edx
call   1050 <regcomp@plt>
test   %eax,%eax
jne    11e0 <main+0x70>
lea    0xe91(%rip),%rsi
lea    0xc(%rsp),%rdi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1080 <regexec@plt>
test   %eax,%eax
je     11bf <main+0x4f>
mov    0x2e36(%rip),%rcx
cmp    (%rcx),%eax
jne    1201 <main+0x91>
lea    0xe74(%rip),%rdi
jmp    11c6 <main+0x56>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rdi
call   1040 <regfree@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0x64,%ecx
call   1070 <regerror@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

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

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