#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 strlen(char *);
char *strstr(char *, char *);
int indexOf_shift(char *base, char *str, int startIndex) {
  int result;
  int baselen = strlen(base);
  if (strlen(str) > baselen || startIndex > baselen)
    result = -1;
  else {
    if (startIndex < 0)
      startIndex = 0;
    char *pos = strstr(base + startIndex, str);
    if (pos == NULL)
      result = -1;
    else
      result = pos - base;
  }
  return result;
}


x86 assembly (clang, -O0):
<indexOf_shift>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    -0x1c(%rbp),%eax
jg     115d <indexOf_shift+0x3d>
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    1169 <indexOf_shift+0x49>
movl   $0xffffffff,-0x18(%rbp)
jmp    11bc <indexOf_shift+0x9c>
cmpl   $0x0,-0x14(%rbp)
jge    117a <indexOf_shift+0x5a>
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a9 <indexOf_shift+0x89>
movl   $0xffffffff,-0x18(%rbp)
jmp    11b7 <indexOf_shift+0x97>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x18(%rbp)
jmp    11bc <indexOf_shift+0x9c>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<indexOf_shift>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ebp,%ebx
jl     116c <indexOf_shift+0x4c>
cmp    %ebx,%ecx
jg     116c <indexOf_shift+0x4c>
xor    %edi,%edi
test   %ebp,%ebp
cmovns %ebp,%edi
add    %r15,%rdi
mov    %r14,%rsi
call   1040 <strstr@plt>
mov    %eax,%ecx
sub    %r15d,%ecx
cmp    $0x1,%rax
sbb    %eax,%eax
or     %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @indexOf_shift(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp sgt i32 %5, %4
%7 = icmp slt i32 %4, %2
%8 = or i1 %7, %6
br i1 %8, label %21, label %9
9: ; preds = %3
%10 = icmp sgt i32 %2, 0
%11 = select i1 %10, i32 %2, i32 0
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = tail call i8* @strstr(i8* dereferenceable(1) %13, i8* dereferenceable(1) %1)
%15 = icmp eq i8* %14, null
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %0 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
%20 = select i1 %15, i32 -1, i32 %19
br label %21
21: ; preds = %3, %9
%22 = phi i32 [ %20, %9 ], [ -1, %3 ]
ret i32 %22
}