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

/* Variables and functions */
int /*<<< orphan*/ LC_CTYPE;
int /*<<< orphan*/ REG_EXTENDED;
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ regcomp(int /*<<< orphan*/ *, char const *,
                           int /*<<< orphan*/);
int /*<<< orphan*/ regexec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
size_t b_regex_search(void *s) {
  char buf[260000];
  regex_t re;
  size_t i;
  setlocale(LC_CTYPE, "");
  memset(buf, 'a', sizeof(buf) - 2);
  buf[sizeof buf - 2] = 'b';
  buf[sizeof buf - 1] = 0;
  regcomp(&re, (const char *)s, REG_EXTENDED);
  regexec(&re, buf, 0, 0, 0);
  regfree(&re);
}


x86 assembly (clang, -O0):
<b_regex_search>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3f7c0,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
call   1070 <setlocale@plt>
lea    -0x3f7b0(%rbp),%rdi
mov    $0x61,%esi
mov    $0x3f79e,%edx
call   1040 <memset@plt>
movb   $0x62,-0x12(%rbp)
movb   $0x0,-0x11(%rbp)
mov    -0x10(%rbp),%rsi
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
lea    -0x3f7b4(%rbp),%rdi
call   1050 <regcomp@plt>
lea    -0x3f7b0(%rbp),%rsi
lea    -0x3f7b4(%rbp),%rdi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1060 <regexec@plt>
lea    -0x3f7b4(%rbp),%rdi
call   1030 <regfree@plt>
mov    -0x8(%rbp),%rax
add    $0x3f7c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b_regex_search>:
push   %r15
push   %r14
push   %rbx
sub    $0x3f7b0,%rsp
mov    %rdi,%r15
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
call   1070 <setlocale@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x61,%esi
mov    $0x3f79e,%edx
call   1040 <memset@plt>
movw   $0x62,0x3f7ae(%rsp)
mov    0x2e3c(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <regcomp@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <regexec@plt>
mov    %rbx,%rdi
call   1030 <regfree@plt>
add    $0x3f7b0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@LC_CTYPE = global i32 0
@.str = [1 x i8] zeroinitializer
@REG_EXTENDED = global i32 0
define i64 @b_regex_search(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca [260000 x i8]
%5 = alloca i32
%6 = alloca i64
store i8* %0, i8** %3
%7 = load i32, i32* @LC_CTYPE
%8 = call i32 @setlocale(i32 %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [260000 x i8], [260000 x i8]* %4, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i8 signext 97, i32 259998)
%11 = getelementptr inbounds [260000 x i8], [260000 x i8]* %4, i64 0, i64 259998
store i8 98, i8* %11
%12 = getelementptr inbounds [260000 x i8], [260000 x i8]* %4, i64 0, i64 259999
store i8 0, i8* %12
%13 = load i8*, i8** %3
%14 = load i32, i32* @REG_EXTENDED
%15 = call i32 @regcomp(i32* %5, i8* %13, i32 %14)
%16 = getelementptr inbounds [260000 x i8], [260000 x i8]* %4, i64 0, i64 0
%17 = call i32 @regexec(i32* %5, i8* %16, i32 0, i32 0, i32 0)
%18 = call i32 @regfree(i32* %5)
%19 = load i64, i64* %2
ret i64 %19
}

LLVM IR (-O2):
@LC_CTYPE = global i32 0
@.str = [1 x i8] zeroinitializer
@REG_EXTENDED = global i32 0
define i64 @b_regex_search(i8* %0) {
%2 = alloca [260000 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [260000 x i8], [260000 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = load i32, i32* @LC_CTYPE
%7 = tail call i32 @setlocale(i32 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @memset(i8* %4, i8 signext 97, i32 259998)
%9 = getelementptr inbounds [260000 x i8], [260000 x i8]* %2, i64 0, i64 259998
store i8 98, i8* %9
%10 = getelementptr inbounds [260000 x i8], [260000 x i8]* %2, i64 0, i64 259999
store i8 0, i8* %10
%11 = load i32, i32* @REG_EXTENDED
%12 = call i32 @regcomp(i32* %3, i8* %0, i32 %11)
%13 = call i32 @regexec(i32* %3, i8* %4, i32 0, i32 0, i32 0)
%14 = call i32 @regfree(i32* %3)
ret i64 undef
}