#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*/ LC_CTYPE;
int /*<<< orphan*/ REG_EXTENDED;
int /*<<< orphan*/ regcomp(int /*<<< orphan*/ *, char const *,
                           int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
size_t b_regex_compile(void *s) {
  regex_t re;
  size_t i;
  setlocale(LC_CTYPE, "");
  for (i = 0; i < 1000; i++) {
    regcomp(&re, (const char *)s, REG_EXTENDED);
    regfree(&re);
  }
}


x86 assembly (clang, -O0):
<b_regex_compile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%edi
lea    0xeb4(%rip),%rsi
call   1050 <setlocale@plt>
movq   $0x0,-0x20(%rbp)
cmpq   $0x3e8,-0x20(%rbp)
jae    1197 <b_regex_compile+0x67>
mov    -0x10(%rbp),%rsi
mov    0x2e66(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rdi
call   1040 <regcomp@plt>
lea    -0x14(%rbp),%rdi
call   1030 <regfree@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1159 <b_regex_compile+0x29>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b_regex_compile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2ea6(%rip),%rax
mov    (%rax),%edi
lea    0xeb5(%rip),%rsi
call   1050 <setlocale@plt>
mov    $0x3e8,%ebx
mov    0x2e7c(%rip),%r12
lea    0x4(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <regcomp@plt>
mov    %r15,%rdi
call   1030 <regfree@plt>
add    $0xffffffffffffffff,%rbx
jne    1170 <b_regex_compile+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
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_compile(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i32, i32* @LC_CTYPE
%7 = call i32 @setlocale(i32 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %5
br label %8
8: ; preds = %16, %1
%9 = load i64, i64* %5
%10 = icmp ult i64 %9, 1000
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load i8*, i8** %3
%13 = load i32, i32* @REG_EXTENDED
%14 = call i32 @regcomp(i32* %4, i8* %12, i32 %13)
%15 = call i32 @regfree(i32* %4)
br label %16
16: ; preds = %11
%17 = load i64, i64* %5
%18 = add i64 %17, 1
store i64 %18, i64* %5
br label %8
19: ; preds = %8
%20 = load i64, i64* %2
ret i64 %20
}

LLVM IR (-O2):
@LC_CTYPE = global i32 0
@.str = [1 x i8] zeroinitializer
@REG_EXTENDED = global i32 0
define i64 @b_regex_compile(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @LC_CTYPE
%5 = tail call i32 @setlocale(i32 %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %1, %6
%7 = phi i64 [ 0, %1 ], [ %11, %6 ]
%8 = load i32, i32* @REG_EXTENDED
%9 = call i32 @regcomp(i32* %2, i8* %0, i32 %8)
%10 = call i32 @regfree(i32* %2)
%11 = add nuw nsw i64 %7, 1
%12 = icmp eq i64 %11, 1000
br i1 %12, label %13, label %6
13: ; preds = %6
ret i64 undef
}