#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*/ URegularExpression;
typedef int /*<<< orphan*/ UErrorCode;
typedef int /*<<< orphan*/ UChar;

/* Variables and functions */
int U16_MAX_LENGTH;
scalar_t__ U_FAILURE(int /*<<< orphan*/);
int /*<<< orphan*/ U_SUCCESS(int /*<<< orphan*/);
int /*<<< orphan*/ U_ZERO_ERROR;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ u_strFromUTF8(int /*<<< orphan*/ *, int, int *, char *, int,
                                 int /*<<< orphan*/ *);
int /*<<< orphan*/ uregex_close(int /*<<< orphan*/ *);
int uregex_find(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ *uregex_open(int /*<<< orphan*/ *, int, int /*<<< orphan*/,
                                int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ uregex_setText(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                  int, int /*<<< orphan*/ *);
int matchRegex(char *pat, char *str) {
  int str_len = strlen(str);
  int strU16_cap = U16_MAX_LENGTH * (2 * str_len) + 1;
  UChar strU16[strU16_cap];
  int strU16_len;
  UErrorCode status = U_ZERO_ERROR;
  u_strFromUTF8(strU16, strU16_cap, &strU16_len, str, -1, &status);
  if (U_FAILURE(status))
    return 0;
  int pat_len = strlen(pat);
  int patU16_cap = U16_MAX_LENGTH * (2 * pat_len) + 1;
  UChar patU16[patU16_cap];
  int patU16_len;
  status = U_ZERO_ERROR;
  u_strFromUTF8(patU16, patU16_cap, &patU16_len, (char *)pat, -1, &status);
  if (U_FAILURE(status))
    return 0;
  status = U_ZERO_ERROR;
  URegularExpression *re = uregex_open(patU16, -1, 0, NULL, &status);
  if (U_FAILURE(status))
    return 0;
  status = U_ZERO_ERROR;
  uregex_setText(re, strU16, -1, &status);
  assert(U_SUCCESS(status));
  status = U_ZERO_ERROR;
  int matched = uregex_find(re, 0, &status);
  if (U_FAILURE(status))
    return 0;
  uregex_close(re);
  return matched;
}


x86 assembly (clang, -O0):
<matchRegex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    -0x1c(%rbp),%ecx
imul   %eax,%ecx
mov    %ecx,%eax
lea    0x1(%rax,%rax,1),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x70(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%rcx
lea    -0x34(%rbp),%rdx
mov    $0xffffffff,%r8d
lea    -0x38(%rbp),%r9
call   1090 <u_strFromUTF8@plt>
mov    -0x38(%rbp),%edi
call   1060 <U_FAILURE@plt>
cmp    $0x0,%rax
je     1239 <matchRegex+0xa9>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    139f <matchRegex+0x20f>
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x40(%rbp)
mov    0x2d8c(%rip),%rax
mov    (%rax),%eax
mov    -0x40(%rbp),%ecx
imul   %eax,%ecx
mov    %ecx,%eax
lea    0x1(%rax,%rax,1),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x78(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x50(%rbp)
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x44(%rbp),%esi
mov    -0x10(%rbp),%rcx
lea    -0x54(%rbp),%rdx
mov    $0xffffffff,%r8d
lea    -0x38(%rbp),%r9
call   1090 <u_strFromUTF8@plt>
mov    -0x38(%rbp),%edi
call   1060 <U_FAILURE@plt>
cmp    $0x0,%rax
je     12c8 <matchRegex+0x138>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    139f <matchRegex+0x20f>
mov    -0x78(%rbp),%rdi
mov    0x2d15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    $0xffffffff,%esi
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x38(%rbp),%r8
call   1050 <uregex_open@plt>
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%edi
call   1060 <U_FAILURE@plt>
cmp    $0x0,%rax
je     1315 <matchRegex+0x185>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    139f <matchRegex+0x20f>
mov    -0x70(%rbp),%rsi
mov    0x2cc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x60(%rbp),%rdi
mov    $0xffffffff,%edx
lea    -0x38(%rbp),%rcx
call   1040 <uregex_setText@plt>
mov    -0x38(%rbp),%edi
call   10b0 <U_SUCCESS@plt>
mov    %eax,%edi
call   10a0 <assert@plt>
mov    0x2c9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x60(%rbp),%rdi
xor    %esi,%esi
lea    -0x38(%rbp),%rdx
call   1080 <uregex_find@plt>
mov    %eax,-0x64(%rbp)
mov    -0x38(%rbp),%edi
call   1060 <U_FAILURE@plt>
cmp    $0x0,%rax
je     1389 <matchRegex+0x1f9>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    139f <matchRegex+0x20f>
mov    -0x60(%rbp),%rdi
call   1030 <uregex_close@plt>
mov    -0x64(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matchRegex>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1070 <strlen@plt>
mov    0x2e22(%rip),%r12
imul   (%r12),%eax
lea    (%rax,%rax,1),%esi
add    $0x1,%esi
lea    0xf(,%rsi,4),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r13
sub    %rax,%r13
mov    %r13,%rsp
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x34(%rbp),%rdx
lea    -0x2c(%rbp),%r9
mov    %r13,%rdi
mov    %rbx,%rcx
mov    $0xffffffff,%r8d
call   1090 <u_strFromUTF8@plt>
mov    -0x2c(%rbp),%edi
call   1060 <U_FAILURE@plt>
xor    %r15d,%r15d
test   %rax,%rax
jne    12fb <matchRegex+0x16b>
mov    %r14,%rdi
call   1070 <strlen@plt>
imul   (%r12),%eax
lea    (%rax,%rax,1),%esi
add    $0x1,%esi
lea    0xf(,%rsi,4),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2daa(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x30(%rbp),%rdx
lea    -0x2c(%rbp),%r9
mov    %r12,%rdi
mov    %r14,%rcx
mov    $0xffffffff,%r8d
call   1090 <u_strFromUTF8@plt>
mov    -0x2c(%rbp),%edi
call   1060 <U_FAILURE@plt>
xor    %r15d,%r15d
test   %rax,%rax
jne    12fb <matchRegex+0x16b>
mov    (%rbx),%eax
mov    %eax,-0x2c(%rbp)
xor    %r15d,%r15d
lea    -0x2c(%rbp),%r8
mov    %r12,%rdi
mov    $0xffffffff,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <uregex_open@plt>
mov    %rax,%r14
mov    -0x2c(%rbp),%edi
call   1060 <U_FAILURE@plt>
test   %rax,%rax
jne    12fb <matchRegex+0x16b>
mov    (%rbx),%eax
mov    %eax,-0x2c(%rbp)
mov    %rbx,%r15
lea    -0x2c(%rbp),%rbx
mov    %r14,%rdi
mov    %r13,%rsi
mov    $0xffffffff,%edx
mov    %rbx,%rcx
call   1040 <uregex_setText@plt>
mov    -0x2c(%rbp),%edi
call   10b0 <U_SUCCESS@plt>
mov    %eax,%edi
call   10a0 <assert@plt>
mov    (%r15),%eax
mov    %eax,-0x2c(%rbp)
xor    %r15d,%r15d
mov    %r14,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1080 <uregex_find@plt>
mov    %eax,%ebx
mov    -0x2c(%rbp),%edi
call   1060 <U_FAILURE@plt>
test   %rax,%rax
jne    12fb <matchRegex+0x16b>
mov    %r14,%rdi
call   1030 <uregex_close@plt>
mov    %ebx,%r15d
mov    %r15d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@U16_MAX_LENGTH = global i32 0
@U_ZERO_ERROR = global i32 0
define i32 @matchRegex(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i64
%16 = alloca i32
%17 = alloca i32*
%18 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%19 = load i8*, i8** %5
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* @U16_MAX_LENGTH
%22 = load i32, i32* %6
%23 = mul nsw i32 2, %22
%24 = mul nsw i32 %21, %23
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = zext i32 %26 to i64
%28 = call i8* @llvm.stacksave()
store i8* %28, i8** %8
%29 = alloca i32, i64 %27
store i64 %27, i64* %9
%30 = load i32, i32* @U_ZERO_ERROR
store i32 %30, i32* %11
%31 = load i32, i32* %7
%32 = load i8*, i8** %5
%33 = call i32 @u_strFromUTF8(i32* %29, i32 %31, i32* %10, i8* %32, i32 -1, i32* %11)
%34 = load i32, i32* %11
%35 = call i64 @U_FAILURE(i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %2
store i32 0, i32* %3
store i32 1, i32* %12
br label %82
38: ; preds = %2
%39 = load i8*, i8** %4
%40 = call i32 @strlen(i8* %39)
store i32 %40, i32* %13
%41 = load i32, i32* @U16_MAX_LENGTH
%42 = load i32, i32* %13
%43 = mul nsw i32 2, %42
%44 = mul nsw i32 %41, %43
%45 = add nsw i32 %44, 1
store i32 %45, i32* %14
%46 = load i32, i32* %14
%47 = zext i32 %46 to i64
%48 = alloca i32, i64 %47
store i64 %47, i64* %15
%49 = load i32, i32* @U_ZERO_ERROR
store i32 %49, i32* %11
%50 = load i32, i32* %14
%51 = load i8*, i8** %4
%52 = call i32 @u_strFromUTF8(i32* %48, i32 %50, i32* %16, i8* %51, i32 -1, i32* %11)
%53 = load i32, i32* %11
%54 = call i64 @U_FAILURE(i32 %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %38
store i32 0, i32* %3
store i32 1, i32* %12
br label %82
57: ; preds = %38
%58 = load i32, i32* @U_ZERO_ERROR
store i32 %58, i32* %11
%59 = call i32* @uregex_open(i32* %48, i32 -1, i32 0, i32* null, i32* %11)
store i32* %59, i32** %17
%60 = load i32, i32* %11
%61 = call i64 @U_FAILURE(i32 %60)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %57
store i32 0, i32* %3
store i32 1, i32* %12
br label %82
64: ; preds = %57
%65 = load i32, i32* @U_ZERO_ERROR
store i32 %65, i32* %11
%66 = load i32*, i32** %17
%67 = call i32 @uregex_setText(i32* %66, i32* %29, i32 -1, i32* %11)
%68 = load i32, i32* %11
%69 = call i32 @U_SUCCESS(i32 %68)
%70 = call i32 @assert(i32 %69)
%71 = load i32, i32* @U_ZERO_ERROR
store i32 %71, i32* %11
%72 = load i32*, i32** %17
%73 = call i32 @uregex_find(i32* %72, i32 0, i32* %11)
store i32 %73, i32* %18
%74 = load i32, i32* %11
%75 = call i64 @U_FAILURE(i32 %74)
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %78
77: ; preds = %64
store i32 0, i32* %3
store i32 1, i32* %12
br label %82
78: ; preds = %64
%79 = load i32*, i32** %17
%80 = call i32 @uregex_close(i32* %79)
%81 = load i32, i32* %18
store i32 %81, i32* %3
store i32 1, i32* %12
br label %82
82: ; preds = %78, %77, %63, %56, %37
%83 = load i8*, i8** %8
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@U16_MAX_LENGTH = global i32 0
@U_ZERO_ERROR = global i32 0
define i32 @matchRegex(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = tail call i32 @strlen(i8* %1)
%7 = load i32, i32* @U16_MAX_LENGTH
%8 = shl nsw i32 %6, 1
%9 = mul nsw i32 %8, %7
%10 = or i32 %9, 1
%11 = zext i32 %10 to i64
%12 = alloca i32, i64 %11
%13 = bitcast i32* %3 to i8*
%14 = bitcast i32* %4 to i8*
%15 = load i32, i32* @U_ZERO_ERROR
store i32 %15, i32* %4
%16 = call i32 @u_strFromUTF8(i32* %12, i32 %10, i32* %3, i8* %1, i32 -1, i32* %4)
%17 = load i32, i32* %4
%18 = call i64 @U_FAILURE(i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %55
20: ; preds = %2
%21 = call i32 @strlen(i8* %0)
%22 = load i32, i32* @U16_MAX_LENGTH
%23 = shl nsw i32 %21, 1
%24 = mul nsw i32 %23, %22
%25 = or i32 %24, 1
%26 = zext i32 %25 to i64
%27 = alloca i32, i64 %26
%28 = bitcast i32* %5 to i8*
%29 = load i32, i32* @U_ZERO_ERROR
store i32 %29, i32* %4
%30 = call i32 @u_strFromUTF8(i32* %27, i32 %25, i32* %5, i8* %0, i32 -1, i32* %4)
%31 = load i32, i32* %4
%32 = call i64 @U_FAILURE(i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %53
34: ; preds = %20
%35 = load i32, i32* @U_ZERO_ERROR
store i32 %35, i32* %4
%36 = call i32* @uregex_open(i32* %27, i32 -1, i32 0, i32* null, i32* %4)
%37 = load i32, i32* %4
%38 = call i64 @U_FAILURE(i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %53
40: ; preds = %34
%41 = load i32, i32* @U_ZERO_ERROR
store i32 %41, i32* %4
%42 = call i32 @uregex_setText(i32* %36, i32* %12, i32 -1, i32* %4)
%43 = load i32, i32* %4
%44 = call i32 @U_SUCCESS(i32 %43)
%45 = call i32 @assert(i32 %44)
%46 = load i32, i32* @U_ZERO_ERROR
store i32 %46, i32* %4
%47 = call i32 @uregex_find(i32* %36, i32 0, i32* %4)
%48 = load i32, i32* %4
%49 = call i64 @U_FAILURE(i32 %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %40
%52 = call i32 @uregex_close(i32* %36)
br label %53
53: ; preds = %34, %40, %51, %20
%54 = phi i32 [ 0, %20 ], [ 0, %34 ], [ %47, %51 ], [ 0, %40 ]
br label %55
55: ; preds = %2, %53
%56 = phi i32 [ %54, %53 ], [ 0, %2 ]
ret i32 %56
}