#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*/ strcmp(char *, char *);
int strlen(char *);
char *subsequence(char *, int, int);
int contains(char string[], char substring[]) {
  int master_len = strlen(string);
  int slave_len = strlen(substring);
  int index = 0;
  char *sub;
  while (index + slave_len <= master_len) {
    sub = subsequence(string, index, index + slave_len);
    if (!strcmp(sub, substring))
      return index;
    index++;
  }
  return -1;
}


x86 assembly (clang, -O0):
<contains>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     11b3 <contains+0x83>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x24(%rbp),%edx
add    -0x20(%rbp),%edx
call   1040 <subsequence@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11a5 <contains+0x75>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ba <contains+0x8a>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115f <contains+0x2f>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<contains>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%r13d
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    $0xffffffff,%r15d
cmp    %r13d,%eax
jg     1193 <contains+0x63>
mov    %eax,%ebx
xor    %ebp,%ebp
lea    (%rbx,%rbp,1),%edx
mov    %r12,%rdi
mov    %ebp,%esi
call   1040 <subsequence@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1190 <contains+0x60>
lea    (%rbx,%rbp,1),%eax
add    $0x1,%eax
mov    %ebp,%ecx
add    $0x1,%ecx
mov    %ecx,%ebp
cmp    %r13d,%eax
jle    1160 <contains+0x30>
jmp    1193 <contains+0x63>
mov    %ebp,%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 @contains(i8* %0, i8* %1) {
%3 = alloca i32
%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
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %6
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %7
store i32 0, i32* %8
br label %14
14: ; preds = %33, %2
%15 = load i32, i32* %8
%16 = load i32, i32* %7
%17 = add nsw i32 %15, %16
%18 = load i32, i32* %6
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %36
20: ; preds = %14
%21 = load i8*, i8** %4
%22 = load i32, i32* %8
%23 = load i32, i32* %8
%24 = load i32, i32* %7
%25 = add nsw i32 %23, %24
%26 = call i8* @subsequence(i8* %21, i32 %22, i32 %25)
store i8* %26, i8** %9
%27 = load i8*, i8** %9
%28 = load i8*, i8** %5
%29 = call i32 @strcmp(i8* %27, i8* %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %20
%32 = load i32, i32* %8
store i32 %32, i32* %3
br label %37
33: ; preds = %20
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %14
36: ; preds = %14
store i32 -1, i32* %3
br label %37
37: ; preds = %36, %31
%38 = load i32, i32* %3
ret i32 %38
}

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