#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 */
unsigned int strlen(char *);
scalar_t__ strmatch(char *, char *);
int /*<<< orphan*/ substring(char *, char *, unsigned int, unsigned int);
int indexOf(char *strsource, char *strsubstring, unsigned int ii_start) {
  unsigned int strsubstring_len = strlen(strsubstring);
  unsigned int strsource_len = strlen(strsource);
  char strsourcesubstring[strsubstring_len];
  if (strsubstring_len > strsource_len)
    return -1;
  unsigned int ii = 0;
  for (ii = ii_start; ii <= strsource_len - strsubstring_len; ii++) {
    substring(strsourcesubstring, strsource, ii, strsubstring_len);
    if (strmatch(strsourcesubstring, strsubstring))
      return ii;
  }
  return -1;
}


x86 assembly (clang, -O0):
<indexOf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jbe    11a0 <indexOf+0x70>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    121b <indexOf+0xeb>
movl   $0x0,-0x40(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    -0x20(%rbp),%ecx
cmp    %ecx,%eax
ja     120d <indexOf+0xdd>
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x40(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1050 <substring@plt>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strmatch@plt>
cmp    $0x0,%rax
je     11fa <indexOf+0xca>
mov    -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    121b <indexOf+0xeb>
jmp    11ff <indexOf+0xcf>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11ad <indexOf+0x7d>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<indexOf>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %rdi,%r15
mov    %rsi,-0x30(%rbp)
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%r13d
mov    %r12d,%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    $0xffffffff,%eax
sub    %r12d,%r13d
jb     11c2 <indexOf+0x92>
mov    %r15,-0x38(%rbp)
mov    -0x30(%rbp),%r15
cmp    %ebx,%r13d
jb     11c2 <indexOf+0x92>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    -0x38(%rbp),%rsi
mov    %ebx,%edx
mov    %r12d,%ecx
call   1050 <substring@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strmatch@plt>
test   %rax,%rax
jne    11c0 <indexOf+0x90>
add    $0x1,%ebx
cmp    %r13d,%ebx
jbe    1190 <indexOf+0x60>
mov    $0xffffffff,%eax
jmp    11c2 <indexOf+0x92>
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @indexOf(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%14 = load i8*, i8** %6
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %8
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %9
%18 = load i32, i32* %8
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %10
%21 = alloca i8, i64 %19
store i64 %19, i64* %11
%22 = load i32, i32* %8
%23 = load i32, i32* %9
%24 = icmp ugt i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %3
store i32 -1, i32* %4
store i32 1, i32* %12
br label %49
26: ; preds = %3
store i32 0, i32* %13
%27 = load i32, i32* %7
store i32 %27, i32* %13
br label %28
28: ; preds = %45, %26
%29 = load i32, i32* %13
%30 = load i32, i32* %9
%31 = load i32, i32* %8
%32 = sub i32 %30, %31
%33 = icmp ule i32 %29, %32
br i1 %33, label %34, label %48
34: ; preds = %28
%35 = load i8*, i8** %5
%36 = load i32, i32* %13
%37 = load i32, i32* %8
%38 = call i32 @substring(i8* %21, i8* %35, i32 %36, i32 %37)
%39 = load i8*, i8** %6
%40 = call i64 @strmatch(i8* %21, i8* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %34
%43 = load i32, i32* %13
store i32 %43, i32* %4
store i32 1, i32* %12
br label %49
44: ; preds = %34
br label %45
45: ; preds = %44
%46 = load i32, i32* %13
%47 = add i32 %46, 1
store i32 %47, i32* %13
br label %28
48: ; preds = %28
store i32 -1, i32* %4
store i32 1, i32* %12
br label %49
49: ; preds = %48, %42, %25
%50 = load i8*, i8** %10
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
define i32 @indexOf(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = tail call i32 @strlen(i8* %0)
%6 = zext i32 %4 to i64
%7 = alloca i8, i64 %6
%8 = icmp ult i32 %5, %4
br i1 %8, label %20, label %9
9: ; preds = %3
%10 = sub i32 %5, %4
%11 = icmp ult i32 %10, %2
br i1 %11, label %20, label %12
12: ; preds = %9, %17
%13 = phi i32 [ %18, %17 ], [ %2, %9 ]
%14 = call i32 @substring(i8* %7, i8* %0, i32 %13, i32 %4)
%15 = call i64 @strmatch(i8* %7, i8* %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = add i32 %13, 1
%19 = icmp ugt i32 %18, %10
br i1 %19, label %20, label %12
20: ; preds = %17, %12, %9, %3
%21 = phi i32 [ -1, %3 ], [ -1, %9 ], [ -1, %17 ], [ %13, %12 ]
ret i32 %21
}