#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 strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int strStr0(char *haystack, char *needle) {
  int needleSize = strlen(needle);
  int haySize = strlen(haystack);
  if (haySize < needleSize)
    return -1;
  for (int i = 0; i <= haySize - needleSize; i++)
    if (strncmp(haystack + i, needle, needleSize) == 0)
      return i;
  return -1;
}


x86 assembly (clang, -O0):
<strStr0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1160 <strStr0+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <strStr0+0x9e>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jg     11b7 <strStr0+0x97>
mov    -0x10(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11a4 <strStr0+0x84>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11be <strStr0+0x9e>
jmp    11a9 <strStr0+0x89>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1167 <strStr0+0x47>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strStr0>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r13d
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    $0xffffffff,%r15d
sub    %r13d,%ebx
jl     1182 <strStr0+0x62>
add    $0x1,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
lea    (%r12,%rbp,1),%rdi
mov    %r14,%rsi
mov    %r13d,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     117f <strStr0+0x5f>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1160 <strStr0+0x40>
jmp    1182 <strStr0+0x62>
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 @strStr0(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %6
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 -1, i32* %3
br label %40
17: ; preds = %2
store i32 0, i32* %8
br label %18
18: ; preds = %36, %17
%19 = load i32, i32* %8
%20 = load i32, i32* %7
%21 = load i32, i32* %6
%22 = sub nsw i32 %20, %21
%23 = icmp sle i32 %19, %22
br i1 %23, label %24, label %39
24: ; preds = %18
%25 = load i8*, i8** %4
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8*, i8** %5
%30 = load i32, i32* %6
%31 = call i64 @strncmp(i8* %28, i8* %29, i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %24
%34 = load i32, i32* %8
store i32 %34, i32* %3
br label %40
35: ; preds = %24
br label %36
36: ; preds = %35
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %18
39: ; preds = %18
store i32 -1, i32* %3
br label %40
40: ; preds = %39, %33, %16
%41 = load i32, i32* %3
ret i32 %41
}

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