#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 *, int);
unsigned char *_zip_memmem(const unsigned char *big, int biglen,
                           const unsigned char *little, int 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) + 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    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jl     114c <_zip_memmem+0x2c>
cmpl   $0x0,-0x24(%rbp)
jne    1159 <_zip_memmem+0x39>
movq   $0x0,-0x8(%rbp)
jmp    11e9 <_zip_memmem+0xc9>
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
movslq -0x14(%rbp),%rcx
add    %rcx,%rdx
movslq -0x24(%rbp),%rcx
sub    %rcx,%rdx
add    $0x1,%rdx
movzbl %al,%esi
call   1030 <memchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11e1 <_zip_memmem+0xc1>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0x24(%rbp),%edx
sub    $0x1,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    11dc <_zip_memmem+0xbc>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e9 <_zip_memmem+0xc9>
jmp    1165 <_zip_memmem+0x45>
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
xor    %eax,%eax
cmp    %ecx,%esi
jl     11a3 <_zip_memmem+0x83>
mov    %ecx,%ebp
test   %ecx,%ecx
je     11a3 <_zip_memmem+0x83>
mov    %rdx,%r14
mov    %rdi,%rbx
movslq %esi,%rax
movslq %ebp,%r13
lea    (%rdi,%rax,1),%r15
add    $0x1,%r15
add    $0xffffffffffffffff,%rbx
lea    0x1(%rdx),%r12
add    $0xffffffff,%ebp
cs nopw 0x0(%rax,%rax,1)
movzbl (%r14),%esi
lea    (%rbx,%r13,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     11a1 <_zip_memmem+0x81>
mov    %rax,%rbx
mov    %rax,%rdi
add    $0x1,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
jne    1160 <_zip_memmem+0x40>
mov    %rbx,%rax
jmp    11a3 <_zip_memmem+0x83>
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, 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* %7
%12 = load i32, i32* %9
%13 = icmp slt i32 %11, %12
br i1 %13, label %17, label %14
14: ; preds = %4
%15 = load i32, i32* %9
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14, %4
store i8* null, i8** %5
br label %56
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 = %54, %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 i32, i32* %7
%34 = sext i32 %33 to i64
%35 = add nsw i64 %32, %34
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = sub nsw i64 %35, %37
%39 = add nsw i64 %38, 1
%40 = call i64 @memchr(i8* %23, i8 zeroext %26, i64 %39)
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %10
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %55
43: ; preds = %21
%44 = load i8*, i8** %10
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = load i8*, i8** %8
%47 = getelementptr inbounds i8, i8* %46, i64 1
%48 = load i32, i32* %9
%49 = sub nsw i32 %48, 1
%50 = call i64 @memcmp(i8* %45, i8* %47, i32 %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %43
%53 = load i8*, i8** %10
store i8* %53, i8** %5
br label %56
54: ; preds = %43
br label %21
55: ; preds = %21
store i8* null, i8** %5
br label %56
56: ; preds = %55, %52, %17
%57 = load i8*, i8** %5
ret i8* %57
}

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