#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_ESPACE;
int /*<<< orphan*/ REG_EXTENDED;
scalar_t__ malloc(int);
int regcomp(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/);
int c_regcomp(void **preg_ptr, const char *regex) {
  int status;
  regex_t *p = (regex_t *)malloc(sizeof(regex_t));
  if (p == NULL) {
    *preg_ptr = NULL;
    return REG_ESPACE;
  }
  status = regcomp(p, regex, REG_EXTENDED);
  *preg_ptr = (void *)p;
  return status;
}


x86 assembly (clang, -O0):
<c_regcomp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1165 <c_regcomp+0x45>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    118f <c_regcomp+0x6f>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e64(%rip),%rax
mov    (%rax),%edx
call   1030 <regcomp@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_regcomp>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x4,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1156 <c_regcomp+0x36>
mov    %rax,%rbx
mov    0x2e94(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <regcomp@plt>
mov    %rbx,(%r15)
jmp    1166 <c_regcomp+0x46>
movq   $0x0,(%r15)
mov    0x2e84(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@REG_ESPACE = global i32 0
@REG_EXTENDED = global i32 0
define i32 @c_regcomp(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
store i8** %0, i8*** %4
store i8* %1, i8** %5
%8 = call i64 @malloc(i32 4)
%9 = inttoptr i64 %8 to i32*
store i32* %9, i32** %7
%10 = load i32*, i32** %7
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8**, i8*** %4
store i8* null, i8** %13
%14 = load i32, i32* @REG_ESPACE
store i32 %14, i32* %3
br label %24
15: ; preds = %2
%16 = load i32*, i32** %7
%17 = load i8*, i8** %5
%18 = load i32, i32* @REG_EXTENDED
%19 = call i32 @regcomp(i32* %16, i8* %17, i32 %18)
store i32 %19, i32* %6
%20 = load i32*, i32** %7
%21 = bitcast i32* %20 to i8*
%22 = load i8**, i8*** %4
store i8* %21, i8** %22
%23 = load i32, i32* %6
store i32 %23, i32* %3
br label %24
24: ; preds = %15, %12
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@REG_ESPACE = global i32 0
@REG_EXTENDED = global i32 0
define i32 @c_regcomp(i8** nocapture writeonly %0, i8* %1) {
%3 = tail call i64 @malloc(i32 4)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
store i8* null, i8** %0
%6 = load i32, i32* @REG_ESPACE
br label %12
7: ; preds = %2
%8 = inttoptr i64 %3 to i32*
%9 = load i32, i32* @REG_EXTENDED
%10 = tail call i32 @regcomp(i32* %8, i8* %1, i32 %9)
%11 = inttoptr i64 %3 to i8*
store i8* %11, i8** %0
br label %12
12: ; preds = %7, %5
%13 = phi i32 [ %6, %5 ], [ %10, %7 ]
ret i32 %13
}