#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
scalar_t__ memcmp(int /*<<< orphan*/ const *, int /*<<< orphan*/ const *,
                  unsigned int);
const uint8_t *service_strstr(const uint8_t *haystack, unsigned haystack_len,
                              const uint8_t *needle, unsigned needle_len) {
  const uint8_t *p;
  const uint8_t *h_end = haystack + haystack_len;
  for (p = haystack; h_end - p >= (int)needle_len; p++) {
    if (memcmp(p, needle, needle_len) == 0) {
      return p;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<service_strstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
movslq -0x24(%rbp),%rcx
cmp    %rcx,%rax
jl     1199 <service_strstr+0x89>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    1183 <service_strstr+0x73>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a1 <service_strstr+0x91>
jmp    1188 <service_strstr+0x78>
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
jmp    1140 <service_strstr+0x30>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<service_strstr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%eax
movslq %ecx,%r12
cmp    %r12,%rax
jl     1167 <service_strstr+0x57>
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rdi,%rbx
lea    -0x4(,%rax,4),%rbp
ff
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     1169 <service_strstr+0x59>
add    $0x4,%rbx
mov    %rbp,%rax
sar    $0x2,%rax
add    $0xfffffffffffffffc,%rbp
cmp    %r12,%rax
jge    1140 <service_strstr+0x30>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32* @service_strstr(i32* %0, i32 %1, i32* %2, i32 %3) {
%5 = zext i32 %1 to i64
%6 = getelementptr inbounds i32, i32* %0, i64 %5
%7 = ptrtoint i32* %6 to i64
%8 = sext i32 %3 to i64
%9 = icmp slt i64 %5, %8
br i1 %9, label %20, label %10
10: ; preds = %4, %14
%11 = phi i32* [ %15, %14 ], [ %0, %4 ]
%12 = tail call i64 @memcmp(i32* %11, i32* %2, i32 %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %10
%15 = getelementptr inbounds i32, i32* %11, i64 1
%16 = ptrtoint i32* %15 to i64
%17 = sub i64 %7, %16
%18 = ashr exact i64 %17, 2
%19 = icmp slt i64 %18, %8
br i1 %19, label %20, label %10
20: ; preds = %10, %14, %4
%21 = phi i32* [ null, %4 ], [ null, %14 ], [ %11, %10 ]
ret i32* %21
}