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

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int KMPReversed(char const *, int /*<<< orphan*/, char const *,
                int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ strlen(char const *);
int StrIndex(const char *text, const char *pattern) {
  if (!text || !pattern) {
    errno = EINVAL;
    return -2;
  }
  return KMPReversed(text, strlen(text), pattern, strlen(pattern));
}


x86 assembly (clang, -O0):
<StrIndex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1146 <StrIndex+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1164 <StrIndex+0x44>
mov    0x2e8b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e8a(%rip),%rax
mov    %ecx,(%rax)
movl   $0xfffffffe,-0x4(%rbp)
jmp    119e <StrIndex+0x7e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    %eax,%ecx
call   1040 <KMPReversed@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StrIndex>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     1156 <StrIndex+0x36>
mov    %rsi,%r14
test   %rsi,%rsi
je     1156 <StrIndex+0x36>
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
mov    %eax,%ecx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <KMPReversed@plt>
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    0x2e7a(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xfffffffe,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @StrIndex(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %8, %2
%12 = load i32, i32* @EINVAL
store i32 %12, i32* @errno
store i32 -2, i32* %3
br label %21
13: ; preds = %8
%14 = load i8*, i8** %4
%15 = load i8*, i8** %4
%16 = call i32 @strlen(i8* %15)
%17 = load i8*, i8** %5
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @KMPReversed(i8* %14, i32 %16, i8* %17, i32 %19)
store i32 %20, i32* %3
br label %21
21: ; preds = %13, %11
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @StrIndex(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = load i32, i32* @EINVAL
store i32 %7, i32* @errno
br label %12
8: ; preds = %2
%9 = tail call i32 @strlen(i8* %0)
%10 = tail call i32 @strlen(i8* %1)
%11 = tail call i32 @KMPReversed(i8* %0, i32 %9, i8* %1, i32 %10)
br label %12
12: ; preds = %8, %6
%13 = phi i32 [ %11, %8 ], [ -2, %6 ]
ret i32 %13
}