#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*/ memcmp(char *, char *, int);
char *find_bytes(char *src, int src_bytes, char *find, int bytes) {
  char *p;
  src_bytes -= bytes - 1;
  for (p = src; src_bytes >= 0; src_bytes--, p++) {
    if (!memcmp(p, find, bytes))
      return p;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<find_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     118b <find_bytes+0x7b>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
jne    116c <find_bytes+0x5c>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1193 <find_bytes+0x83>
jmp    1171 <find_bytes+0x61>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    113c <find_bytes+0x2c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_bytes>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
sub    %ecx,%ebp
mov    %ebp,%eax
inc    %eax
js     114d <find_bytes+0x3d>
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rdi,%rbx
add    $0x2,%ebp
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <memcmp@plt>
test   %eax,%eax
je     114f <find_bytes+0x3f>
add    $0x1,%rbx
add    $0xffffffff,%ebp
test   %ebp,%ebp
jg     1130 <find_bytes+0x20>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @find_bytes(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%11 = load i32, i32* %9
%12 = sub nsw i32 %11, 1
%13 = load i32, i32* %7
%14 = sub nsw i32 %13, %12
store i32 %14, i32* %7
%15 = load i8*, i8** %6
store i8* %15, i8** %10
br label %16
16: ; preds = %28, %4
%17 = load i32, i32* %7
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %33
19: ; preds = %16
%20 = load i8*, i8** %10
%21 = load i8*, i8** %8
%22 = load i32, i32* %9
%23 = call i32 @memcmp(i8* %20, i8* %21, i32 %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %19
%26 = load i8*, i8** %10
store i8* %26, i8** %5
br label %34
27: ; preds = %19
br label %28
28: ; preds = %27
%29 = load i32, i32* %7
%30 = add nsw i32 %29, -1
store i32 %30, i32* %7
%31 = load i8*, i8** %10
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %10
br label %16
33: ; preds = %16
store i8* null, i8** %5
br label %34
34: ; preds = %33, %25
%35 = load i8*, i8** %5
ret i8* %35
}

LLVM IR (-O2):
define i8* @find_bytes(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = add i32 %1, 1
%6 = sub i32 %5, %3
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %17
8: ; preds = %4, %13
%9 = phi i8* [ %15, %13 ], [ %0, %4 ]
%10 = phi i32 [ %14, %13 ], [ %6, %4 ]
%11 = tail call i32 @memcmp(i8* %9, i8* %2, i32 %3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = add nsw i32 %10, -1
%15 = getelementptr inbounds i8, i8* %9, i64 1
%16 = icmp sgt i32 %10, 0
br i1 %16, label %8, label %17
17: ; preds = %8, %13, %4
%18 = phi i8* [ null, %4 ], [ null, %13 ], [ %9, %8 ]
ret i8* %18
}