#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 KMP(char const *, int, int /*<<< orphan*/, char const *,
        int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ strlen(char const *);
int FindSubstring(const char *source, const char *substring, int start) {
  if (!source || !substring) {
    errno = EINVAL;
    return -2;
  }
  if (start < 0) {
    errno = EINVAL;
    return -2;
  }
  return KMP(source, start, strlen(source), substring, strlen(substring));
}


x86 assembly (clang, -O0):
<FindSubstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1149 <FindSubstring+0x29>
cmpq   $0x0,-0x18(%rbp)
jne    1167 <FindSubstring+0x47>
mov    0x2e88(%rip),%rax
mov    (%rax),%ecx
mov    0x2e87(%rip),%rax
mov    %ecx,(%rax)
movl   $0xfffffffe,-0x4(%rbp)
jmp    11d3 <FindSubstring+0xb3>
cmpl   $0x0,-0x1c(%rbp)
jge    118f <FindSubstring+0x6f>
mov    0x2e60(%rip),%rax
mov    (%rax),%ecx
mov    0x2e5f(%rip),%rax
mov    %ecx,(%rax)
movl   $0xfffffffe,-0x4(%rbp)
jmp    11d3 <FindSubstring+0xb3>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    %eax,%r8d
call   1040 <KMP@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FindSubstring>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     116c <FindSubstring+0x4c>
mov    %rsi,%rbx
test   %rsi,%rsi
je     116c <FindSubstring+0x4c>
mov    %edx,%r14d
test   %edx,%edx
js     116c <FindSubstring+0x4c>
mov    %rdi,%rbp
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %r15d,%edx
mov    %rbx,%rcx
mov    %eax,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <KMP@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    0x2e64(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xfffffffe,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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