#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 */
struct re_pattern_buffer {
  int dummy;
};
typedef int /*<<< orphan*/ r;

/* Variables and functions */
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ memset(struct re_pattern_buffer *, int /*<<< orphan*/, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ re_compile_pattern(char *, int, struct re_pattern_buffer *);
int /*<<< orphan*/ re_search(struct re_pattern_buffer *, char const *,
                             int /*<<< orphan*/, int /*<<< orphan*/,
                             int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ *setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strlen(char const *);
int do_test(void) {
  struct re_pattern_buffer r;
  const char *s = "\xe1\x80\x80\xe1\x80\xbb\xe1\x80\xbd\xe1\x80\x94\xe1\x80\xba"
                  "\xe1\x80\xaf\xe1\x80\x95\xe1\x80\xbax";
  if (setlocale(LC_ALL, "en_US.UTF-8") == NULL) {
    puts("setlocale failed");
    return 1;
  }
  memset(&r, 0, sizeof(r));
  re_compile_pattern("[^x]x", 5, &r);
  re_search(&r, s, strlen(s), 0, strlen(s), 0);
  return 0;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
call   1070 <setlocale@plt>
cmp    $0x0,%rax
jne    11aa <do_test+0x4a>
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    120c <do_test+0xac>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    0xe76(%rip),%rdi
mov    $0x5,%esi
lea    -0x8(%rbp),%rdx
call   1080 <re_compile_pattern@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    %eax,%r8d
lea    -0x8(%rbp),%rdi
xor    %r9d,%r9d
mov    %r9d,%ecx
call   1060 <re_search@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
call   1070 <setlocale@plt>
test   %rax,%rax
je     11da <do_test+0x7a>
mov    %rsp,%r14
xor    %r15d,%r15d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    0xe9a(%rip),%rdi
mov    $0x5,%esi
mov    %r14,%rdx
call   1080 <re_compile_pattern@plt>
lea    0xe4f(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
mov    %eax,%r8d
xor    %r9d,%r9d
call   1060 <re_search@plt>
jmp    11ec <do_test+0x8c>
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.re_pattern_buffer = type { i32 }
@.str = [26 x i8] c"\E1\80\80\E1\80\BB\E1\80\BD\E1\80\94\E1\80\BA\E1\80\AF\E1\80\95\E1\80\BAx\00"
@LC_ALL = global i32 0
@.str.1 = [12 x i8] c"en_US.UTF-8\00"
@.str.2 = [17 x i8] c"setlocale failed\00"
@.str.3 = [6 x i8] c"[^x]x\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca %struct.re_pattern_buffer
%3 = alloca i8*
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8** %3
%4 = load i32, i32* @LC_ALL
%5 = call i32* @setlocale(i32 %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %18
9: ; preds = %0
%10 = call i32 @memset(%struct.re_pattern_buffer* %2, i32 0, i32 4)
%11 = call i32 @re_compile_pattern(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5, %struct.re_pattern_buffer* %2)
%12 = load i8*, i8** %3
%13 = load i8*, i8** %3
%14 = call i32 @strlen(i8* %13)
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @re_search(%struct.re_pattern_buffer* %2, i8* %12, i32 %14, i32 0, i32 %16, i32 0)
store i32 0, i32* %1
br label %18
18: ; preds = %9, %7
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
%struct.re_pattern_buffer = type { i32 }
@.str = [26 x i8] c"\E1\80\80\E1\80\BB\E1\80\BD\E1\80\94\E1\80\BA\E1\80\AF\E1\80\95\E1\80\BAx\00"
@LC_ALL = global i32 0
@.str.1 = [12 x i8] c"en_US.UTF-8\00"
@.str.2 = [17 x i8] c"setlocale failed\00"
@.str.3 = [6 x i8] c"[^x]x\00"
define i32 @do_test() {
%1 = alloca %struct.re_pattern_buffer
%2 = bitcast %struct.re_pattern_buffer* %1 to i8*
%3 = load i32, i32* @LC_ALL
%4 = tail call i32* @setlocale(i32 %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %14
8: ; preds = %0
%9 = call i32 @memset(%struct.re_pattern_buffer* %1, i32 0, i32 4)
%10 = call i32 @re_compile_pattern(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5, %struct.re_pattern_buffer* %1)
%11 = call i32 @strlen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @strlen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @re_search(%struct.re_pattern_buffer* %1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %11, i32 0, i32 %12, i32 0)
br label %14
14: ; preds = %8, %6
%15 = phi i32 [ 1, %6 ], [ 0, %8 ]
ret i32 %15
}