#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;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int regcomp(int /*<<< orphan*/ *, char const *, int);
size_t regerror(int, int /*<<< orphan*/ *, char *, size_t);
int /*<<< orphan*/ stderr;
void CompileRegex(regex_t *regex, const char *pattern, int flags) {
  int ret = regcomp(regex, pattern, flags);
  if (ret) {
    size_t len = regerror(ret, regex, NULL, 0);
    char errorStr[len];
    regerror(ret, regex, errorStr, len);
    fprintf(stderr, "Regex compilation failed - %s\n", errorStr);
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<CompileRegex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <regcomp@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11e1 <CompileRegex+0xa1>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1050 <regerror@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x38(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rcx
call   1050 <regerror@plt>
mov    -0x38(%rbp),%rdx
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CompileRegex>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <regcomp@plt>
test   %eax,%eax
jne    1161 <CompileRegex+0x21>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
mov    %eax,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <regerror@plt>
lea    0xf(%rax),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%r15
sub    %rcx,%r15
mov    %r15,%rsp
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %rax,%rcx
call   1050 <regerror@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
mov    %r15,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"Regex compilation failed - %s\0A\00"
define void @CompileRegex(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i32*, i32** %4
%12 = load i8*, i8** %5
%13 = load i32, i32* %6
%14 = call i32 @regcomp(i32* %11, i8* %12, i32 %13)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %31
17: ; preds = %3
%18 = load i32, i32* %7
%19 = load i32*, i32** %4
%20 = call i64 @regerror(i32 %18, i32* %19, i8* null, i64 0)
store i64 %20, i64* %8
%21 = load i64, i64* %8
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %9
%23 = alloca i8, i64 %21
store i64 %21, i64* %10
%24 = load i32, i32* %7
%25 = load i32*, i32** %4
%26 = load i64, i64* %8
%27 = call i64 @regerror(i32 %24, i32* %25, i8* %23, i64 %26)
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %23)
%30 = call i32 @exit(i32 -1)
unreachable
31: ; preds = %3
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"Regex compilation failed - %s\0A\00"
define void @CompileRegex(i32* %0, i8* %1, i32 %2) {
%4 = tail call i32 @regcomp(i32* %0, i8* %1, i32 %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = tail call i64 @regerror(i32 %4, i32* %0, i8* null, i64 0)
%8 = alloca i8, i64 %7
%9 = call i64 @regerror(i32 %4, i32* %0, i8* %8, i64 %7)
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %8)
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %3
ret void
}