#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*/ memmem(char const *, int, char *, int);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
void test_memmem() {
  const char *haystack = "he\0l3lo";
  printf("%p\n", memmem(haystack, 7, "e", 1));
  printf("%p\n", memmem(haystack, 7, "l", 1));
  printf("%p\n", memmem("hello", 5, "l\0o", 3));
}


x86 assembly (clang, -O0):
<test_memmem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x7,%esi
lea    0xec9(%rip),%rdx
mov    $0x1,%ecx
call   1040 <memmem@plt>
mov    %eax,%esi
lea    0xeb2(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x7,%esi
lea    0xea3(%rip),%rdx
mov    $0x1,%ecx
call   1040 <memmem@plt>
mov    %eax,%esi
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
lea    0xe86(%rip),%rdi
mov    $0x5,%esi
lea    0xe80(%rip),%rdx
mov    $0x3,%ecx
call   1040 <memmem@plt>
mov    %eax,%esi
lea    0xe5f(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_memmem>:
push   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%r14
lea    0xeda(%rip),%rdx
mov    %r14,%rdi
mov    $0x7,%esi
mov    $0x1,%ecx
call   1040 <memmem@plt>
lea    0xebd(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
lea    0xeb2(%rip),%rdx
mov    %r14,%rdi
mov    $0x7,%esi
mov    $0x1,%ecx
call   1040 <memmem@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
lea    0xe91(%rip),%rdi
lea    0xe90(%rip),%rdx
mov    $0x5,%esi
mov    $0x3,%ecx
call   1040 <memmem@plt>
mov    %rbx,%rdi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"he\00l3lo\00"
@.str.1 = [4 x i8] c"%p\0A\00"
@.str.2 = [2 x i8] c"e\00"
@.str.3 = [2 x i8] c"l\00"
@.str.4 = [6 x i8] c"hello\00"
@.str.5 = [4 x i8] c"l\00o\00"
define void @test_memmem() {
%1 = alloca i8*
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %1
%2 = load i8*, i8** %1
%3 = call i32 @memmem(i8* %2, i32 7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%4 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = load i8*, i8** %1
%6 = call i32 @memmem(i8* %5, i32 7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%7 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = call i32 @memmem(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 3)
%9 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %8)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"he\00l3lo\00"
@.str.1 = [4 x i8] c"%p\0A\00"
@.str.2 = [2 x i8] c"e\00"
@.str.3 = [2 x i8] c"l\00"
@.str.4 = [6 x i8] c"hello\00"
@.str.5 = [4 x i8] c"l\00o\00"
define void @test_memmem() {
%1 = tail call i32 @memmem(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%3 = tail call i32 @memmem(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = tail call i32 @memmem(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 3)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %5)
ret void
}