#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
void *malloc(size_t);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int regcomp(int /*<<< orphan*/ *, char *, int);
size_t regerror(int, int /*<<< orphan*/ *, char *, size_t);
int /*<<< orphan*/ stderr;
regex_t *compile_regexp(char *regexp_string) {
  int errcode;
  regex_t *preg = malloc(sizeof(regex_t));
  int cflags = 0;
  if (NULL == preg) {
    perror(NULL);
    exit(EXIT_FAILURE);
  }
  errcode = regcomp(preg, regexp_string, cflags);
  if (errcode) {
    size_t errbufsize = regerror(errcode, preg, NULL, 0);
    char *errbuf = malloc(errbufsize * sizeof(char));
    if (NULL == errbuf) {
      perror(NULL);
      exit(EXIT_FAILURE);
    }
    regerror(errcode, preg, errbuf, errbufsize);
    fprintf(stderr, "%s\n", errbuf);
    exit(EXIT_FAILURE);
  }
  return preg;
}


x86 assembly (clang, -O0):
<compile_regexp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11a4 <compile_regexp+0x44>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <perror@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <regcomp@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1247 <compile_regexp+0xe7>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1050 <regerror@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
shl    $0x0,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    120c <compile_regexp+0xac>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <perror@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <regerror@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xdcc(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compile_regexp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbp
mov    $0x4,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11bb <compile_regexp+0x5b>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
xor    %edx,%edx
call   1030 <regcomp@plt>
test   %eax,%eax
jne    119b <compile_regexp+0x3b>
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   1050 <regerror@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
jne    11c4 <compile_regexp+0x64>
xor    %edi,%edi
call   1070 <perror@plt>
jmp    11ef <compile_regexp+0x8f>
mov    %rax,%r14
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
mov    %r15,%rcx
call   1050 <regerror@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

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

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