#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 *);
char const *strstr(char const *, char const *);
int test_strstr(void) {
  const char *needle = "needle";
  const char *haystack = " needl needle needle";
  printf("\tstrstr");
  if (strstr(haystack, needle) != &haystack[7])
    return 1;
  else
    printf(".");
  if (strstr(haystack, "needlea") != NULL)
    return 1;
  else
    printf(".");
  printf(" passed.\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_strstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xedf(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xec6(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xed0(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strstr@plt>
mov    -0x18(%rbp),%rcx
add    $0x7,%rcx
cmp    %rcx,%rax
je     1174 <test_strstr+0x54>
movl   $0x1,-0x4(%rbp)
jmp    11c5 <test_strstr+0xa5>
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe94(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     11a6 <test_strstr+0x86>
movl   $0x1,-0x4(%rbp)
jmp    11c5 <test_strstr+0xa5>
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strstr>:
push   %rax
lea    0xec8(%rip),%rdi
call   1050 <printf@plt>
mov    $0x2e,%edi
call   1030 <putchar@plt>
mov    $0x2e,%edi
call   1030 <putchar@plt>
lea    0xeb0(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"needle\00"
@.str.1 = [21 x i8] c" needl needle needle\00"
@.str.2 = [8 x i8] c"\09strstr\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [8 x i8] c"needlea\00"
@.str.5 = [10 x i8] c" passed.\0A\00"
define i32 @test_strstr() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8** %3
%4 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%5 = load i8*, i8** %3
%6 = load i8*, i8** %2
%7 = call i8* @strstr(i8* %5, i8* %6)
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 7
%10 = icmp ne i8* %7, %9
br i1 %10, label %11, label %12
11: ; preds = %0
store i32 1, i32* %1
br label %23
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %14
14: ; preds = %12
%15 = load i8*, i8** %3
%16 = call i8* @strstr(i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 1, i32* %1
br label %23
19: ; preds = %14
%20 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19
%22 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %23
23: ; preds = %21, %18, %11
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str.2 = [8 x i8] c"\09strstr\00"
@str = [9 x i8] c" passed.\00"
define i32 @test_strstr() {
%1 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%2 = tail call i32 @putchar(i32 46)
%3 = tail call i32 @putchar(i32 46)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
ret i32 0
}