// File: halfflat[P]tinyopt/test/googletest/googletest/src/gtest-port.cc
// Function: testing::internal::RE::Init(char const*)
void RE::Init(const char* regex) {
  pattern_ = regex;

  // NetBSD (and Android, which takes its regex implemntation from NetBSD) does
  // not include the GNU regex extensions (such as Perl style character classes
  // like \w) in REG_EXTENDED. REG_EXTENDED is only specified to include the
  // [[:alpha:]] style character classes. Enable REG_GNU wherever it is defined
  // so users can use those extensions.
#if defined(REG_GNU)
  constexpr int reg_flags = REG_EXTENDED | REG_GNU;
#else
  constexpr int reg_flags = REG_EXTENDED;
#endif

  // Reserves enough bytes to hold the regular expression used for a
  // full match.
  const size_t full_regex_len = strlen(regex) + 10;
  char* const full_pattern = new char[full_regex_len];

  snprintf(full_pattern, full_regex_len, "^(%s)$", regex);
  is_valid_ = regcomp(&full_regex_, full_pattern, reg_flags) == 0;
  // We want to call regcomp(&partial_regex_, ...) even if the
  // previous expression returns false.  Otherwise partial_regex_ may
  // not be properly initialized can may cause trouble when it's
  // freed.
  //
  // Some implementation of POSIX regex (e.g. on at least some
  // versions of Cygwin) doesn't accept the empty string as a valid
  // regex.  We change it to an equivalent form "()" to be safe.
  if (is_valid_) {
    const char* const partial_regex = (*regex == '\0') ? "()" : regex;
    is_valid_ = regcomp(&partial_regex_, partial_regex, reg_flags) == 0;
  }
  EXPECT_TRUE(is_valid_)
      << "Regular expression \"" << regex
      << "\" is not a valid POSIX Extended regular expression.";

  delete[] full_pattern;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x88(%rbp)
movq -0x10(%rbp), %rsi
callq 0x10b40
movl $0x1, -0x14(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10300
addq $0xa, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x10040
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rcx
leaq 0x50d69(%rip), %rdx     # 0xcdd28
movb $0x0, %al
callq 0x10d10
movq -0x88(%rbp), %rdi
addq $0x28, %rdi
movq -0x28(%rbp), %rsi
movl $0x1, %edx
callq 0x108d0
movl %eax, %ecx
movq -0x88(%rbp), %rax
cmpl $0x0, %ecx
sete %cl
andb $0x1, %cl
movb %cl, 0x20(%rax)
testb $0x1, 0x20(%rax)
je 0x7d05a
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x7d016
leaq 0x4bd34(%rip), %rax     # 0xc8d41
movq %rax, -0x90(%rbp)
jmp 0x7d021
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rdi
movq -0x90(%rbp), %rax
movq %rax, -0x30(%rbp)
addq $0x68, %rdi
movq -0x30(%rbp), %rsi
movl $0x1, %edx
callq 0x108d0
movl %eax, %ecx
movq -0x88(%rbp), %rax
cmpl $0x0, %ecx
sete %cl
andb $0x1, %cl
movb %cl, 0x20(%rax)
movq -0x88(%rbp), %rsi
addq $0x20, %rsi
xorl %eax, %eax
movl %eax, %edx
leaq -0x40(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x1d4a0
movq -0xa0(%rbp), %rdi
callq 0x1d4e0
movb %al, -0x91(%rbp)
jmp 0x7d08d
movb -0x91(%rbp), %al
testb $0x1, %al
jne 0x7d099
jmp 0x7d0af
jmp 0x7d1c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x7d1f7
leaq -0x58(%rbp), %rdi
callq 0x84210
jmp 0x7d0ba
leaq 0x50c6e(%rip), %rsi     # 0xcdd2f
leaq -0x58(%rbp), %rdi
callq 0xa40f0
movq %rax, -0xa8(%rbp)
jmp 0x7d0d3
movq -0xa8(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0xa2dc0
movq %rax, -0xb0(%rbp)
jmp 0x7d0ec
movq -0xb0(%rbp), %rdi
leaq 0x50c4a(%rip), %rsi     # 0xcdd44
callq 0xa4130
movq %rax, -0xb8(%rbp)
jmp 0x7d108
leaq 0x50cd1(%rip), %rdx     # 0xcdde0
leaq 0x4b339(%rip), %rcx     # 0xc844f
leaq 0x4b338(%rip), %r8      # 0xc8455
leaq -0x80(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x7d210
jmp 0x7d12c
leaq -0x80(%rbp), %rdi
callq 0x102c0
movq %rax, %r8
leaq 0x50c39(%rip), %rdx     # 0xcdd78
leaq -0x60(%rbp), %rdi
movl $0x1, %esi
movl $0x2da, %ecx            # imm = 0x2DA
callq 0x80580
jmp 0x7d154
movq -0xb8(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x7d370
jmp 0x7d166
leaq -0x60(%rbp), %rdi
callq 0x80600
leaq -0x80(%rbp), %rdi
callq 0x10fc8
leaq -0x58(%rbp), %rdi
callq 0x1d500
jmp 0x7d1c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x7d1bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x7d1b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x80600
leaq -0x80(%rbp), %rdi
callq 0x10fc8
leaq -0x58(%rbp), %rdi
callq 0x1d500
jmp 0x7d1f7
leaq -0x40(%rbp), %rdi
callq 0x1d520
movq -0x28(%rbp), %rax
movq %rax, -0xc0(%rbp)
cmpq $0x0, %rax
je 0x7d1ee
movq -0xc0(%rbp), %rdi
callq 0x10a80
addq $0xc0, %rsp
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x1d520
movq -0x48(%rbp), %rdi
callq 0x10e00
nopl (%rax)