#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 scalar_t__ uint32_t;
typedef int int32_t;

/* Variables and functions */
scalar_t__ rex_matchme(char const *, char const *, scalar_t__ *);
int32_t rex_match(const char *re, const char *str, uint32_t *len) {
  if (*re == '^') {
    *len = 0;
    if (rex_matchme(re + 1, str, len))
      return 0;
    return -1;
  }
  int32_t pos = 0;
  do {
    *len = 0;
    if (rex_matchme(re, str + pos, len))
      return pos;
  } while (str[pos++] != '\0');
  return -1;
}


x86 assembly (clang, -O0):
<rex_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5e,%eax
jne    1176 <rex_match+0x66>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <rex_matchme@plt>
cmp    $0x0,%rax
je     116a <rex_match+0x5a>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <rex_match+0xd0>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e0 <rex_match+0xd0>
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
mov    -0x20(%rbp),%rdx
call   1030 <rex_matchme@plt>
cmp    $0x0,%rax
je     11b5 <rex_match+0xa5>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e0 <rex_match+0xd0>
jmp    11ba <rex_match+0xaa>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    117d <rex_match+0x6d>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rex_match>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
cmpb   $0x5e,(%rdi)
jne    1149 <rex_match+0x39>
movq   $0x0,(%r15)
add    $0x1,%r12
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <rex_matchme@plt>
cmp    $0x1,%rax
sbb    %r13d,%r13d
jmp    117d <rex_match+0x6d>
xor    %r13d,%r13d
nopl   0x0(%rax)
movq   $0x0,(%r15)
lea    (%r14,%r13,1),%rbx
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <rex_matchme@plt>
test   %rax,%rax
jne    117d <rex_match+0x6d>
add    $0x1,%r13
cmpb   $0x0,(%rbx)
jne    1150 <rex_match+0x40>
mov    $0xffffffff,%r13d
mov    %r13d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @rex_match(i8* %0, i8* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64* %2, i64** %7
%9 = load i8*, i8** %5
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 94
br i1 %12, label %13, label %23
13: ; preds = %3
%14 = load i64*, i64** %7
store i64 0, i64* %14
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8*, i8** %6
%18 = load i64*, i64** %7
%19 = call i64 @rex_matchme(i8* %16, i8* %17, i64* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %13
store i32 0, i32* %4
br label %47
22: ; preds = %13
store i32 -1, i32* %4
br label %47
23: ; preds = %3
store i32 0, i32* %8
br label %24
24: ; preds = %37, %23
%25 = load i64*, i64** %7
store i64 0, i64* %25
%26 = load i8*, i8** %5
%27 = load i8*, i8** %6
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i64*, i64** %7
%32 = call i64 @rex_matchme(i8* %26, i8* %30, i64* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %24
%35 = load i32, i32* %8
store i32 %35, i32* %4
br label %47
36: ; preds = %24
br label %37
37: ; preds = %36
%38 = load i8*, i8** %6
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
%41 = sext i32 %39 to i64
%42 = getelementptr inbounds i8, i8* %38, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 0
br i1 %45, label %24, label %46
46: ; preds = %37
store i32 -1, i32* %4
br label %47
47: ; preds = %46, %34, %22, %21
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
define i32 @rex_match(i8* %0, i8* %1, i64* %2) {
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 94
br i1 %5, label %6, label %11
6: ; preds = %3
store i64 0, i64* %2
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = tail call i64 @rex_matchme(i8* %7, i8* %1, i64* %2)
%9 = icmp eq i64 %8, 0
%10 = sext i1 %9 to i32
br label %22
11: ; preds = %3, %16
%12 = phi i64 [ %17, %16 ], [ 0, %3 ]
store i64 0, i64* %2
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = tail call i64 @rex_matchme(i8* %0, i8* %13, i64* %2)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = add nuw i64 %12, 1
%18 = load i8, i8* %13
%19 = icmp eq i8 %18, 0
br i1 %19, label %22, label %11
20: ; preds = %11
%21 = trunc i64 %12 to i32
br label %22
22: ; preds = %16, %20, %6
%23 = phi i32 [ %10, %6 ], [ %21, %20 ], [ -1, %16 ]
ret i32 %23
}