#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 *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int strStr(char *haystack, char *needle) {
  int i = 0;
  int len = strlen(needle);
  if (!*haystack && !*needle) {
    return 0;
  }
  while (*(haystack + i)) {
    if (!strncmp(haystack + i, needle, len)) {
      return i;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<strStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1169 <strStr+0x49>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1169 <strStr+0x49>
movl   $0x0,-0x4(%rbp)
jmp    11b7 <strStr+0x97>
jmp    116e <strStr+0x4e>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11b0 <strStr+0x90>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11ab <strStr+0x8b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b7 <strStr+0x97>
jmp    116e <strStr+0x4e>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strStr>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    (%rbx),%al
test   %al,%al
je     115d <strStr+0x3d>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1169 <strStr+0x49>
cmpb   $0x0,(%rbx)
jne    1140 <strStr+0x20>
mov    $0xffffffff,%eax
jmp    116b <strStr+0x4b>
cmpb   $0x0,(%r14)
je     1169 <strStr+0x49>
test   %al,%al
jne    1140 <strStr+0x20>
jmp    1156 <strStr+0x36>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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