#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*/ error_msg_and_die(char *, char *);
int regcomp(int /*<<< orphan*/ *, char const *, int);
int regerror(int, int /*<<< orphan*/ *, char *, int);
char *xmalloc(int);
void xregcomp(regex_t *preg, const char *regex, int cflags) {
  int ret;
  if ((ret = regcomp(preg, regex, cflags)) != 0) {
    int errmsgsz = regerror(ret, preg, NULL, 0);
    char *errmsg = xmalloc(errmsgsz);
    regerror(ret, preg, errmsg, errmsgsz);
    error_msg_and_die("xregcomp: %s", errmsg);
  }
}


x86 assembly (clang, -O0):
<xregcomp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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   1040 <regcomp@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     11b3 <xregcomp+0x73>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <regerror@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <xmalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1060 <regerror@plt>
mov    -0x28(%rbp),%rsi
lea    0xe52(%rip),%rdi
call   1050 <error_msg_and_die@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xregcomp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <regcomp@plt>
test   %eax,%eax
je     1199 <xregcomp+0x59>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <regerror@plt>
mov    %eax,%r14d
mov    %eax,%edi
call   1030 <xmalloc@plt>
mov    %rax,%r15
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
mov    %r14d,%ecx
call   1060 <regerror@plt>
lea    0xe79(%rip),%rdi
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <error_msg_and_die@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"xregcomp: %s\00"
define void @xregcomp(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 %11, label %6
6: ; preds = %3
%7 = tail call i32 @regerror(i32 %4, i32* %0, i8* null, i32 0)
%8 = tail call i8* @xmalloc(i32 %7)
%9 = tail call i32 @regerror(i32 %4, i32* %0, i8* %8, i32 %7)
%10 = tail call i32 @error_msg_and_die(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %11
11: ; preds = %6, %3
ret void
}