#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*/ regex;

/* Variables and functions */
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ memset(struct re_pattern_buffer *, char, int);
int /*<<< orphan*/ printf(char *, int, int, int);
int /*<<< orphan*/ puts(char *);
char *re_compile_pattern(char *, int, struct re_pattern_buffer *);
int re_search_2(struct re_pattern_buffer *, char *, int, char *, int, int, int,
                int /*<<< orphan*/ *, int);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int main(void) {
  struct re_pattern_buffer regex;
  const char *s;
  int match[3];
  int result = 0;
  memset(&regex, '\0', sizeof(regex));
  setlocale(LC_ALL, "C");
  s = re_compile_pattern("ab[cde]", 7, &regex);
  if (s != NULL) {
    puts("re_compile_pattern returned non-NULL value");
    result = 1;
  } else {
    match[0] = re_search_2(&regex, "xyabez", 6, "", 0, 1, 5, NULL, 6);
    match[1] = re_search_2(&regex, NULL, 0, "abc", 3, 0, 3, NULL, 3);
    match[2] = re_search_2(&regex, "xya", 3, "bd", 2, 2, 3, NULL, 5);
    if (match[0] != 2 || match[1] != 0 || match[2] != 2) {
      printf("re_search_2 returned %d,%d,%d, expected 2,0,2\n", match[0],
             match[1], match[2]);
      result = 1;
    } else
      puts(" -> OK");
  }
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
call   1070 <setlocale@plt>
lea    0xe60(%rip),%rdi
mov    $0x7,%esi
lea    -0x8(%rbp),%rdx
call   1080 <re_compile_pattern@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d7 <main+0x77>
lea    0xe44(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x20(%rbp)
jmp    12e6 <main+0x186>
lea    -0x8(%rbp),%rdi
lea    0xe53(%rip),%rsi
mov    $0x6,%edx
lea    0xe87(%rip),%rcx
xor    %r8d,%r8d
mov    $0x1,%r9d
xor    %eax,%eax
movl   $0x5,(%rsp)
movq   $0x0,0x8(%rsp)
movl   $0x6,0x10(%rsp)
call   1060 <re_search_2@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %r9d,%r9d
lea    0xe11(%rip),%rcx
mov    $0x3,%r8d
mov    %r9d,%edx
movl   $0x3,(%rsp)
movq   $0x0,0x8(%rsp)
movl   $0x3,0x10(%rsp)
call   1060 <re_search_2@plt>
mov    %eax,-0x18(%rbp)
lea    -0x8(%rbp),%rdi
lea    0xde1(%rip),%rsi
mov    $0x3,%edx
lea    0xdd9(%rip),%rcx
mov    $0x2,%r9d
xor    %eax,%eax
mov    %r9d,%r8d
movl   $0x3,(%rsp)
movq   $0x0,0x8(%rsp)
movl   $0x5,0x10(%rsp)
call   1060 <re_search_2@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jne    12b4 <main+0x154>
cmpl   $0x0,-0x18(%rbp)
jne    12b4 <main+0x154>
cmpl   $0x2,-0x14(%rbp)
je     12d5 <main+0x175>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xd83(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x20(%rbp)
jmp    12e1 <main+0x181>
lea    0xd9a(%rip),%rdi
call   1030 <puts@plt>
jmp    12e6 <main+0x186>
mov    -0x20(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
call   1070 <setlocale@plt>
lea    0xe6d(%rip),%rdi
mov    $0x7,%esi
mov    %rbx,%rdx
call   1080 <re_compile_pattern@plt>
test   %rax,%rax
je     11bd <main+0x5d>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    128f <main+0x12f>
sub    $0x8,%rsp
lea    0xe6d(%rip),%rsi
lea    0xea6(%rip),%rcx
lea    0x8(%rsp),%r14
mov    $0x1,%ebx
mov    %r14,%rdi
mov    $0x6,%edx
xor    %r8d,%r8d
mov    $0x1,%r9d
push   $0x6
push   $0x0
push   $0x5
call   1060 <re_search_2@plt>
add    $0x20,%rsp
mov    %eax,%r15d
sub    $0x8,%rsp
lea    0xe35(%rip),%rcx
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    $0x3,%r8d
xor    %r9d,%r9d
push   $0x3
push   $0x0
push   $0x3
call   1060 <re_search_2@plt>
add    $0x20,%rsp
mov    %eax,%ebp
sub    $0x8,%rsp
lea    0xe0d(%rip),%rsi
lea    0xe0a(%rip),%rcx
mov    %r14,%rdi
mov    $0x3,%edx
mov    $0x2,%r8d
mov    $0x2,%r9d
push   $0x5
push   $0x0
push   $0x3
call   1060 <re_search_2@plt>
add    $0x20,%rsp
cmp    $0x2,%r15d
jne    127c <main+0x11c>
test   %ebp,%ebp
jne    127c <main+0x11c>
cmp    $0x2,%eax
jne    127c <main+0x11c>
lea    0xe03(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    128f <main+0x12f>
lea    0xdc4(%rip),%rdi
mov    %r15d,%esi
mov    %ebp,%edx
mov    %eax,%ecx
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.re_pattern_buffer = type { i32 }
@LC_ALL = global i32 0
@.str = [2 x i8] c"C\00"
@.str.1 = [8 x i8] c"ab[cde]\00"
@.str.2 = [43 x i8] c"re_compile_pattern returned non-NULL value\00"
@.str.3 = [7 x i8] c"xyabez\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [4 x i8] c"abc\00"
@.str.6 = [4 x i8] c"xya\00"
@.str.7 = [3 x i8] c"bd\00"
@.str.8 = [47 x i8] c"re_search_2 returned %d,%d,%d, expected 2,0,2\0A\00"
@.str.9 = [7 x i8] c" -> OK\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.re_pattern_buffer
%3 = alloca i8*
%4 = alloca [3 x i32]
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
%6 = call i32 @memset(%struct.re_pattern_buffer* %2, i8 signext 0, i32 4)
%7 = load i32, i32* @LC_ALL
%8 = call i32 @setlocale(i32 %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = call i8* @re_compile_pattern(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7, %struct.re_pattern_buffer* %2)
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @puts(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %5
br label %43
14: ; preds = %0
%15 = call i32 @re_search_2(%struct.re_pattern_buffer* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i32 0, i32 1, i32 5, i32* null, i32 6)
%16 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
store i32 %15, i32* %16
%17 = call i32 @re_search_2(%struct.re_pattern_buffer* %2, i8* null, i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 3, i32 0, i32 3, i32* null, i32 3)
%18 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 1
store i32 %17, i32* %18
%19 = call i32 @re_search_2(%struct.re_pattern_buffer* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 2, i32 2, i32 3, i32* null, i32 5)
%20 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 2
store i32 %19, i32* %20
%21 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
%22 = load i32, i32* %21
%23 = icmp ne i32 %22, 2
br i1 %23, label %32, label %24
24: ; preds = %14
%25 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 1
%26 = load i32, i32* %25
%27 = icmp ne i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 2
%30 = load i32, i32* %29
%31 = icmp ne i32 %30, 2
br i1 %31, label %32, label %40
32: ; preds = %28, %24, %14
%33 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
%34 = load i32, i32* %33
%35 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 1
%36 = load i32, i32* %35
%37 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 2
%38 = load i32, i32* %37
%39 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.8, i64 0, i64 0), i32 %34, i32 %36, i32 %38)
store i32 1, i32* %5
br label %42
40: ; preds = %28
%41 = call i32 @puts(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
br label %42
42: ; preds = %40, %32
br label %43
43: ; preds = %42, %12
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
%struct.re_pattern_buffer = type { i32 }
@LC_ALL = global i32 0
@.str = [2 x i8] c"C\00"
@.str.1 = [8 x i8] c"ab[cde]\00"
@.str.2 = [43 x i8] c"re_compile_pattern returned non-NULL value\00"
@.str.3 = [7 x i8] c"xyabez\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [4 x i8] c"abc\00"
@.str.6 = [4 x i8] c"xya\00"
@.str.7 = [3 x i8] c"bd\00"
@.str.8 = [47 x i8] c"re_search_2 returned %d,%d,%d, expected 2,0,2\0A\00"
@.str.9 = [7 x i8] c" -> OK\00"
define i32 @main() {
%1 = alloca %struct.re_pattern_buffer
%2 = bitcast %struct.re_pattern_buffer* %1 to i8*
%3 = call i32 @memset(%struct.re_pattern_buffer* %1, i8 signext 0, i32 4)
%4 = load i32, i32* @LC_ALL
%5 = call i32 @setlocale(i32 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = call i8* @re_compile_pattern(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7, %struct.re_pattern_buffer* %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
br label %23
10: ; preds = %0
%11 = call i32 @re_search_2(%struct.re_pattern_buffer* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i32 0, i32 1, i32 5, i32* null, i32 6)
%12 = call i32 @re_search_2(%struct.re_pattern_buffer* %1, i8* null, i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 3, i32 0, i32 3, i32* null, i32 3)
%13 = call i32 @re_search_2(%struct.re_pattern_buffer* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 2, i32 2, i32 3, i32* null, i32 5)
%14 = icmp ne i32 %11, 2
%15 = icmp ne i32 %12, 0
%16 = select i1 %14, i1 true, i1 %15
%17 = icmp ne i32 %13, 2
%18 = select i1 %16, i1 true, i1 %17
br i1 %18, label %19, label %21
19: ; preds = %10
%20 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.8, i64 0, i64 0), i32 %11, i32 %12, i32 %13)
br label %23
21: ; preds = %10
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
br label %23
23: ; preds = %19, %21, %8
%24 = phi i32 [ 1, %8 ], [ 1, %19 ], [ 0, %21 ]
ret i32 %24
}