#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_NOSUB;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
void *malloc(size_t);
int regcomp(int /*<<< orphan*/ *, char *, int);
size_t regerror(int, int /*<<< orphan*/ *, char *, size_t);
int /*<<< orphan*/ stderr;
regex_t *build_regex(char *re, int extra_flags) {
  regex_t *preg;
  int re_flags = REG_NOSUB | extra_flags;
  int status;
  preg = malloc(sizeof(regex_t));
  assert(NULL != preg);
  status = regcomp(preg, re, re_flags);
  if (0 != status) {
    size_t len = regerror(status, preg, NULL, 0);
    char *msg = malloc(len);
    assert(NULL != msg);
    regerror(status, preg, msg, len);
    fprintf(stderr, "Invalid regular expression: %s\n", msg);
    exit(-1);
  }
  return preg;
}


x86 assembly (clang, -O0):
<build_regex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <regcomp@plt>
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%eax
je     122b <build_regex+0xcb>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1060 <regerror@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1060 <regerror@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xde4(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_regex>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r14
mov    0x2e6d(%rip),%rax
or     (%rax),%ebp
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <regcomp@plt>
test   %eax,%eax
jne    11af <build_regex+0x4f>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <regerror@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <malloc@plt>
mov    %rax,%r15
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1040 <assert@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1060 <regerror@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@REG_NOSUB = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"Invalid regular expression: %s\0A\00"
define i32* @build_regex(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = load i32, i32* @REG_NOSUB
%11 = load i32, i32* %4
%12 = or i32 %10, %11
store i32 %12, i32* %6
%13 = call i8* @malloc(i64 4)
%14 = bitcast i8* %13 to i32*
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = icmp ne i32* null, %15
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32*, i32** %5
%20 = load i8*, i8** %3
%21 = load i32, i32* %6
%22 = call i32 @regcomp(i32* %19, i8* %20, i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp ne i32 0, %23
br i1 %24, label %25, label %44
25: ; preds = %2
%26 = load i32, i32* %7
%27 = load i32*, i32** %5
%28 = call i64 @regerror(i32 %26, i32* %27, i8* null, i64 0)
store i64 %28, i64* %8
%29 = load i64, i64* %8
%30 = call i8* @malloc(i64 %29)
store i8* %30, i8** %9
%31 = load i8*, i8** %9
%32 = icmp ne i8* null, %31
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = load i32, i32* %7
%36 = load i32*, i32** %5
%37 = load i8*, i8** %9
%38 = load i64, i64* %8
%39 = call i64 @regerror(i32 %35, i32* %36, i8* %37, i64 %38)
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %9
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %41)
%43 = call i32 @exit(i32 -1)
unreachable
44: ; preds = %2
%45 = load i32*, i32** %5
ret i32* %45
}

LLVM IR (-O2):
@REG_NOSUB = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"Invalid regular expression: %s\0A\00"
define i32* @build_regex(i8* %0, i32 %1) {
%3 = load i32, i32* @REG_NOSUB
%4 = or i32 %3, %1
%5 = tail call dereferenceable_or_null(4) i8* @malloc(i64 4)
%6 = bitcast i8* %5 to i32*
%7 = icmp ne i8* %5, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32 @regcomp(i32* %6, i8* %0, i32 %4)
%11 = icmp eq i32 %10, 0
br i1 %11, label %22, label %12
12: ; preds = %2
%13 = tail call i64 @regerror(i32 %10, i32* %6, i8* null, i64 0)
%14 = tail call i8* @malloc(i64 %13)
%15 = icmp ne i8* %14, null
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = tail call i64 @regerror(i32 %10, i32* %6, i8* %14, i64 %13)
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %14)
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %2
ret i32* %6
}