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


x86 assembly (clang, -O0):
<strStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    115c <strStr+0x3c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    115c <strStr+0x3c>
movl   $0x0,-0x4(%rbp)
jmp    11d6 <strStr+0xb6>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11cf <strStr+0xaf>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11bc <strStr+0x9c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d6 <strStr+0xb6>
jmp    11c1 <strStr+0xa1>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1163 <strStr+0x43>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strStr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
cmpb   $0x0,(%rdi)
je     1171 <strStr+0x51>
mov    %rdi,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%r15,%rbx,1),%r12
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1178 <strStr+0x58>
cmpb   $0x0,0x1(%r15,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1140 <strStr+0x20>
mov    $0xffffffff,%ebx
jmp    1178 <strStr+0x58>
xor    %eax,%eax
cmp    (%r14),%al
sbb    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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