#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 */
char *strstr(char *, char *);
long indexOf(char *str1, char *str2) {
  char *p = str1;
  int i = 0;
  p = strstr(str1, str2);
  if (p == NULL)
    return -1;
  else {
    while (str1 != p) {
      str1++;
      i++;
    }
  }
  return i;
}


x86 assembly (clang, -O0):
<indexOf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1158 <indexOf+0x48>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1192 <indexOf+0x82>
jmp    115d <indexOf+0x4d>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     1185 <indexOf+0x75>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115d <indexOf+0x4d>
jmp    118a <indexOf+0x7a>
movslq -0x24(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<indexOf>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strstr@plt>
test   %rax,%rax
je     1127 <indexOf+0x17>
cmp    %rbx,%rax
je     1130 <indexOf+0x20>
sub    %ebx,%eax
pop    %rbx
ret
mov    $0xffffffffffffffff,%rax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @indexOf(i8* %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
store i8* %8, i8** %6
store i32 0, i32* %7
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i8* @strstr(i8* %9, i8* %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %2
store i64 -1, i64* %3
br label %29
15: ; preds = %2
br label %16
16: ; preds = %20, %15
%17 = load i8*, i8** %4
%18 = load i8*, i8** %6
%19 = icmp ne i8* %17, %18
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %4
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
br label %16
25: ; preds = %16
br label %26
26: ; preds = %25
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
store i64 %28, i64* %3
br label %29
29: ; preds = %26, %14
%30 = load i64, i64* %3
ret i64 %30
}

LLVM IR (-O2):
define i64 @indexOf(i8* %0, i8* nocapture %1) {
%3 = ptrtoint i8* %0 to i64
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%5 = ptrtoint i8* %4 to i64
%6 = icmp eq i8* %4, null
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = icmp eq i8* %4, %0
br i1 %8, label %12, label %9
9: ; preds = %7
%10 = sub i64 %5, %3
%11 = and i64 %10, 4294967295
br label %12
12: ; preds = %7, %9, %2
%13 = phi i64 [ -1, %2 ], [ 0, %7 ], [ %11, %9 ]
ret i64 %13
}