#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;
  if (strstr(haystack, "needlea") != NULL)
    return 1;
  printf("\tpassed.\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    11ad <test_strstr+0x8d>
mov    -0x18(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     119a <test_strstr+0x7a>
movl   $0x1,-0x4(%rbp)
jmp    11ad <test_strstr+0x8d>
lea    0xe84(%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    0xed8(%rip),%rdi
call   1040 <printf@plt>
lea    0xed4(%rip),%rdi
call   1030 <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 = [8 x i8] c"needlea\00"
@.str.4 = [10 x i8] c"\09passed.\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 %19
12: ; preds = %0
%13 = load i8*, i8** %3
%14 = call i8* @strstr(i8* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 1, i32* %1
br label %19
17: ; preds = %12
%18 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %19
19: ; preds = %17, %16, %11
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@.str.2 = [8 x i8] c"\09strstr\00"
@str = [9 x i8] c"\09passed.\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 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
ret i32 0
}