#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*/ REG_EXTENDED;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
scalar_t__ regcomp(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/);
int regexec(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/,
            int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int str_regcmp(const char *str, const char *regex) {
  assert(str != NULL);
  assert(regex != NULL);
  regex_t regex_comp;
  if (regcomp(&regex_comp, regex, REG_EXTENDED) != 0)
    return 1;
  int result = regexec(&regex_comp, str, 0, NULL, 0);
  regfree(&regex_comp);
  return result;
}


x86 assembly (clang, -O0):
<str_regcmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rsi
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rdi
call   1040 <regcomp@plt>
cmp    $0x0,%rax
je     11a0 <str_regcmp+0x60>
movl   $0x1,-0x4(%rbp)
jmp    11c9 <str_regcmp+0x89>
mov    -0x10(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1060 <regexec@plt>
mov    %eax,-0x20(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <regfree@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_regcmp>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
test   %rbp,%rbp
setne  %dil
call   1050 <assert@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rdi
mov    %rbp,%rsi
call   1040 <regcomp@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    11ab <str_regcmp+0x6b>
lea    0xc(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <regexec@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <regfree@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@REG_EXTENDED = global i32 0
define i32 @str_regcmp(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 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8*, i8** %5
%17 = load i32, i32* @REG_EXTENDED
%18 = call i64 @regcomp(i32* %6, i8* %16, i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %2
store i32 1, i32* %3
br label %26
21: ; preds = %2
%22 = load i8*, i8** %4
%23 = call i32 @regexec(i32* %6, i8* %22, i32 0, i32* null, i32 0)
store i32 %23, i32* %7
%24 = call i32 @regfree(i32* %6)
%25 = load i32, i32* %7
store i32 %25, i32* %3
br label %26
26: ; preds = %21, %20
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@REG_EXTENDED = global i32 0
define i32 @str_regcmp(i8* %0, i8* %1) {
%3 = alloca i32
%4 = icmp ne i8* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp ne i8* %1, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = bitcast i32* %3 to i8*
%11 = load i32, i32* @REG_EXTENDED
%12 = call i64 @regcomp(i32* %3, i8* %1, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @regexec(i32* %3, i8* %0, i32 0, i32* null, i32 0)
%16 = call i32 @regfree(i32* %3)
br label %17
17: ; preds = %2, %14
%18 = phi i32 [ %15, %14 ], [ 1, %2 ]
ret i32 %18
}