#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 */
scalar_t__ memchr(unsigned char const *, unsigned char const, size_t);
scalar_t__ memcmp(unsigned char const *, unsigned char const *, size_t);
unsigned char *_zip_memmem(const unsigned char *big, size_t biglen,
                           const unsigned char *little, size_t littlelen) {
  const unsigned char *p;
  if ((biglen < littlelen) || (littlelen == 0))
    return NULL;
  p = big - 1;
  while ((p = (const unsigned char *)memchr(
              p + 1, little[0],
              (size_t)(big - (p + 1)) + (size_t)(biglen - littlelen) + 1)) !=
         NULL) {
    if (memcmp(p + 1, little + 1, littlelen - 1) == 0)
      return (unsigned char *)p;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<_zip_memmem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jb     1151 <_zip_memmem+0x31>
cmpq   $0x0,-0x28(%rbp)
jne    115e <_zip_memmem+0x3e>
movq   $0x0,-0x8(%rbp)
jmp    11ed <_zip_memmem+0xcd>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    -0x10(%rbp),%rdx
mov    -0x30(%rbp),%rcx
add    $0x1,%rcx
sub    %rcx,%rdx
mov    -0x18(%rbp),%rcx
sub    -0x28(%rbp),%rcx
add    %rcx,%rdx
add    $0x1,%rdx
movzbl %al,%esi
call   1030 <memchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11e5 <_zip_memmem+0xc5>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0x28(%rbp),%rdx
sub    $0x1,%rdx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    11e0 <_zip_memmem+0xc0>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ed <_zip_memmem+0xcd>
jmp    116a <_zip_memmem+0x4a>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_zip_memmem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    -0x1(%rcx),%r13
cmp    %rsi,%r13
jae    1192 <_zip_memmem+0x72>
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rdi,%rbx
lea    (%rsi,%rdi,1),%r15
add    $0x1,%r15
add    $0xffffffffffffffff,%rbx
lea    0x1(%rdx),%rbp
nopl   (%rax)
movzbl (%r14),%esi
lea    (%rbx,%r12,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
mov    %r15,%rdx
sub    %rax,%rdx
mov    %rbx,%rdi
call   1030 <memchr@plt>
test   %rax,%rax
je     1192 <_zip_memmem+0x72>
mov    %rax,%rbx
mov    %rax,%rdi
add    $0x1,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
call   1040 <memcmp@plt>
test   %rax,%rax
jne    1150 <_zip_memmem+0x30>
mov    %rbx,%rax
jmp    1194 <_zip_memmem+0x74>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @_zip_memmem(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%11 = load i64, i64* %7
%12 = load i64, i64* %9
%13 = icmp ult i64 %11, %12
br i1 %13, label %17, label %14
14: ; preds = %4
%15 = load i64, i64* %9
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14, %4
store i8* null, i8** %5
br label %54
18: ; preds = %14
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i64 -1
store i8* %20, i8** %10
br label %21
21: ; preds = %52, %18
%22 = load i8*, i8** %10
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = load i8*, i8** %8
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = load i8*, i8** %6
%28 = load i8*, i8** %10
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = ptrtoint i8* %27 to i64
%31 = ptrtoint i8* %29 to i64
%32 = sub i64 %30, %31
%33 = load i64, i64* %7
%34 = load i64, i64* %9
%35 = sub i64 %33, %34
%36 = add i64 %32, %35
%37 = add i64 %36, 1
%38 = call i64 @memchr(i8* %23, i8 zeroext %26, i64 %37)
%39 = inttoptr i64 %38 to i8*
store i8* %39, i8** %10
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %53
41: ; preds = %21
%42 = load i8*, i8** %10
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8*, i8** %8
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = load i64, i64* %9
%47 = sub i64 %46, 1
%48 = call i64 @memcmp(i8* %43, i8* %45, i64 %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %41
%51 = load i8*, i8** %10
store i8* %51, i8** %5
br label %54
52: ; preds = %41
br label %21
53: ; preds = %21
store i8* null, i8** %5
br label %54
54: ; preds = %53, %50, %17
%55 = load i8*, i8** %5
ret i8* %55
}

LLVM IR (-O2):
define i8* @_zip_memmem(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = add i64 %3, -1
%6 = icmp ult i64 %5, %1
br i1 %6, label %7, label %29
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %0, i64 -1
%9 = ptrtoint i8* %0 to i64
%10 = add i64 %1, 1
%11 = add i64 %10, %9
%12 = getelementptr inbounds i8, i8* %2, i64 1
br label %13
13: ; preds = %23, %7
%14 = phi i8* [ %8, %7 ], [ %21, %23 ]
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %2
%17 = ptrtoint i8* %15 to i64
%18 = add i64 %17, %3
%19 = sub i64 %11, %18
%20 = tail call i64 @memchr(i8* %15, i8 zeroext %16, i64 %19)
%21 = inttoptr i64 %20 to i8*
%22 = icmp eq i64 %20, 0
br i1 %22, label %29, label %23
23: ; preds = %13
%24 = getelementptr inbounds i8, i8* %21, i64 1
%25 = tail call i64 @memcmp(i8* %24, i8* %12, i64 %5)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %13
27: ; preds = %23
%28 = inttoptr i64 %20 to i8*
br label %29
29: ; preds = %13, %27, %4
%30 = phi i8* [ null, %4 ], [ %28, %27 ], [ null, %13 ]
ret i8* %30
}