#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 */
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char const *, size_t);
int String_index_of_str(const char *str, const char *chars) {
  const char *pch = str;
  size_t len = strlen(str);
  size_t len2 = strlen(chars);
  int pos = 0;
  while (len >= len2) {
    if (strncmp(pch, chars, len2) == 0) {
      return pos;
    }
    pos++;
    pch++;
    len--;
  }
  return -1;
}


x86 assembly (clang, -O0):
<String_index_of_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jb     11b3 <String_index_of_str+0x93>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    118d <String_index_of_str+0x6d>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ba <String_index_of_str+0x9a>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    1159 <String_index_of_str+0x39>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<String_index_of_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %rax,%rbp
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    $0xffffffff,%r15d
cmp    %rax,%rbp
jb     1186 <String_index_of_str+0x66>
mov    %rax,%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r12,%rbx,1),%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1183 <String_index_of_str+0x63>
add    $0xffffffffffffffff,%rbp
add    $0x1,%rbx
cmp    %r13,%rbp
jae    1160 <String_index_of_str+0x40>
jmp    1186 <String_index_of_str+0x66>
mov    %ebx,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @String_index_of_str(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = icmp ult i64 %3, %4
br i1 %5, label %17, label %6
6: ; preds = %2, %12
%7 = phi i32 [ %13, %12 ], [ 0, %2 ]
%8 = phi i64 [ %15, %12 ], [ %3, %2 ]
%9 = phi i8* [ %14, %12 ], [ %0, %2 ]
%10 = tail call i64 @strncmp(i8* %9, i8* %1, i64 %4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %6
%13 = add nuw nsw i32 %7, 1
%14 = getelementptr inbounds i8, i8* %9, i64 1
%15 = add i64 %8, -1
%16 = icmp ult i64 %15, %4
br i1 %16, label %17, label %6
17: ; preds = %6, %12, %2
%18 = phi i32 [ -1, %2 ], [ -1, %12 ], [ %7, %6 ]
ret i32 %18
}