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


x86 assembly (clang, -O0):
<test_strstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xece(%rip),%rsi
call   1040 <strstr@plt>
mov    %eax,%esi
lea    0xebc(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1040 <strstr@plt>
mov    %eax,%esi
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
lea    0xe9a(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1040 <strstr@plt>
mov    %eax,%esi
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strstr>:
push   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%r14
lea    0xeda(%rip),%rsi
mov    %r14,%rdi
call   1040 <strstr@plt>
lea    0xec7(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
lea    0xebc(%rip),%rsi
mov    %r14,%rdi
call   1040 <strstr@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
lea    0xea5(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1040 <strstr@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_strstr() {
%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 @strstr(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%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 @strstr(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = call i32 @strstr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%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_strstr() {
%1 = tail call i32 @strstr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%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 @strstr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%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 @strstr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%6 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %5)
ret void
}