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


x86 assembly (clang, -O0):
<compile_regex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e86(%rip),%rax
mov    (%rax),%edx
mov    0x2e8d(%rip),%rax
or     (%rax),%edx
call   1040 <regcomp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11aa <compile_regex+0x7a>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x1020(%rbp),%rdx
mov    $0x1000,%ecx
call   1050 <regerror@plt>
mov    -0x18(%rbp),%rsi
lea    -0x1020(%rbp),%rdx
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11b1 <compile_regex+0x81>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compile_regex>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e8f(%rip),%rax
mov    0x2e98(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
call   1040 <regcomp@plt>
test   %eax,%eax
je     118b <compile_regex+0x5b>
mov    %rsp,%r15
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    $0x1000,%ecx
call   1050 <regerror@plt>
lea    0xe87(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <printf@plt>
mov    $0x1,%eax
jmp    118d <compile_regex+0x5d>
xor    %eax,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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