#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 uint8_t;
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
int REG_EXTENDED;
int REG_NOSUB;
scalar_t__ regcomp(int /*<<< orphan*/ *, char *, int);
int regexec(int /*<<< orphan*/ *, char const *, size_t, int /*<<< orphan*/ *,
            int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
uint8_t validate(const char *string, char *pattern) {
  regex_t re;
  if (regcomp(&re, pattern, REG_EXTENDED | REG_NOSUB) == 0) {
    int status = regexec(&re, string, (size_t)0, NULL, 0);
    regfree(&re);
    return (status != 0) ? 0 : 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<validate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    0x2e8d(%rip),%rax
mov    (%rax),%edx
mov    0x2e8c(%rip),%rax
or     (%rax),%edx
lea    -0x1c(%rbp),%rdi
call   1040 <regcomp@plt>
cmp    $0x0,%rax
jne    11a4 <validate+0x74>
mov    -0x10(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
mov    %rcx,%rdx
call   1050 <regexec@plt>
mov    %eax,-0x20(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <regfree@plt>
mov    -0x20(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <validate+0x7b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e9a(%rip),%rax
mov    0x2e9b(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0x4(%rsp),%rdi
call   1040 <regcomp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1185 <validate+0x55>
lea    0x4(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <regexec@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <regfree@plt>
xor    %eax,%eax
test   %ebx,%ebx
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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