#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*/ assert(char *);
unsigned int strings_length(char *);
int strings_index_of_string_imp(char *string, char *substring,
                                bool (*equals_function)(char *, char *,
                                                        unsigned int)) {
  assert(string);
  assert(substring);
  unsigned int string_length = strings_length(string),
               substring_length = strings_length(substring);
  for (unsigned int k = 0; k < string_length - substring_length + 1; k++) {
    if (equals_function(&string[k], substring, substring_length))
      return (int)k;
  }
  return -1;
}


x86 assembly (clang, -O0):
<strings_index_of_string_imp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strings_length@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strings_length@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    -0x28(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jae    11b7 <strings_index_of_string_imp+0x97>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%ecx
add    %rcx,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   *%rax
cmp    $0x0,%eax
je     11a4 <strings_index_of_string_imp+0x84>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11be <strings_index_of_string_imp+0x9e>
jmp    11a9 <strings_index_of_string_imp+0x89>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1165 <strings_index_of_string_imp+0x45>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strings_index_of_string_imp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,(%rsp)
mov    %rsi,%r15
mov    %rdi,%r12
call   1040 <assert@plt>
mov    %r15,%rdi
call   1040 <assert@plt>
mov    %r12,%rdi
call   1030 <strings_length@plt>
mov    %eax,%r13d
mov    %r15,%rdi
call   1030 <strings_length@plt>
mov    %eax,%r14d
sub    %eax,%r13d
mov    $0xffffffff,%eax
inc    %r13d
je     1192 <strings_index_of_string_imp+0x72>
mov    %r13d,%r13d
xor    %ebx,%ebx
mov    (%rsp),%rbp
xchg   %ax,%ax
lea    (%r12,%rbx,1),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   *%rbp
test   %eax,%eax
jne    1190 <strings_index_of_string_imp+0x70>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1170 <strings_index_of_string_imp+0x50>
mov    $0xffffffff,%eax
jmp    1192 <strings_index_of_string_imp+0x72>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @strings_index_of_string_imp(i8* %0, i8* %1, i32 (i8*, i8*, i32)* nocapture %2) {
%4 = tail call i32 @assert(i8* %0)
%5 = tail call i32 @assert(i8* %1)
%6 = tail call i32 @strings_length(i8* %0)
%7 = tail call i32 @strings_length(i8* %1)
%8 = add i32 %6, 1
%9 = sub i32 %8, %7
%10 = icmp eq i32 %9, 0
br i1 %10, label %23, label %11
11: ; preds = %3
%12 = zext i32 %9 to i64
br label %13
13: ; preds = %11, %18
%14 = phi i64 [ 0, %11 ], [ %19, %18 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = tail call i32 %2(i8* %15, i8* %1, i32 %7)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = add nuw nsw i64 %14, 1
%20 = icmp eq i64 %19, %12
br i1 %20, label %23, label %13
21: ; preds = %13
%22 = trunc i64 %14 to i32
br label %23
23: ; preds = %18, %21, %3
%24 = phi i32 [ -1, %3 ], [ %22, %21 ], [ -1, %18 ]
ret i32 %24
}