#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*/ REG_EXTENDED;
int /*<<< orphan*/ printf(char *, char *, char *);
int regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ regerror(int, int /*<<< orphan*/ *, char *, int);
regex_t compile_regex(char *regex_text) {
  regex_t result;
  int status = regcomp(&result, regex_text, REG_EXTENDED);
  if (status != 0) {
    char error_message[0x1000];
    regerror(status, &result, error_message, 0x1000);
    printf("\033[31m"
           "Regex error compiling '%s': %s\n"
           "\033[0m",
           regex_text, error_message);
  }
  return result;
}


x86 assembly (clang, -O0):
<compile_regex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
mov    0x2e96(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rdi
call   1040 <regcomp@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1191 <compile_regex+0x61>
mov    -0x10(%rbp),%edi
lea    -0x1010(%rbp),%rdx
lea    -0xc(%rbp),%rsi
mov    $0x1000,%ecx
call   1050 <regerror@plt>
mov    -0x8(%rbp),%rsi
lea    -0x1010(%rbp),%rdx
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compile_regex>:
push   %r14
push   %rbx
sub    $0x1018,%rsp
mov    %rdi,%rbx
mov    0x2e9c(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
call   1040 <regcomp@plt>
test   %eax,%eax
je     1182 <compile_regex+0x52>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rdx
mov    $0x1000,%ecx
call   1050 <regerror@plt>
lea    0xe89(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    0xc(%rsp),%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@REG_EXTENDED = global i32 0
@.str = [41 x i8] c"\1B[31mRegex error compiling '%s': %s\0A\1B[0m\00"
define i32 @compile_regex(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [4096 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = load i32, i32* @REG_EXTENDED
%8 = call i32 @regcomp(i32* %3, i8* %6, i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %1
%12 = load i32, i32* %4
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%14 = call i32 @regerror(i32 %12, i32* %3, i8* %13, i32 4096)
%15 = load i8*, i8** %2
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %16)
br label %18
18: ; preds = %11, %1
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
@REG_EXTENDED = global i32 0
@.str = [41 x i8] c"\1B[31mRegex error compiling '%s': %s\0A\1B[0m\00"
define i32 @compile_regex(i8* %0) {
%2 = alloca i32
%3 = alloca [4096 x i8]
%4 = bitcast i32* %2 to i8*
%5 = load i32, i32* @REG_EXTENDED
%6 = call i32 @regcomp(i32* %2, i8* %0, i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%10 = call i32 @regerror(i32 %6, i32* %2, i8* %9, i32 4096)
%11 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %9)
br label %12
12: ; preds = %8, %1
%13 = load i32, i32* %2
ret i32 %13
}