#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__ _strstr_test(char *, char *, char *);
int /*<<< orphan*/ printf(char *, char const *, char *);
int _strstr(char const *progname) {
  printf("%s: Testing %s\n", progname, "strstr()");
  if (_strstr_test("haystack", "needle", NULL) != 0 ||
      _strstr_test("needle", "needle", "needle") != 0 ||
      _strstr_test("needle ", "needle", "needle ") != 0 ||
      _strstr_test("needle again", "needle", "needle again") != 0 ||
      _strstr_test("haystack with a needle", "needle", "needle") != 0 ||
      _strstr_test("haystack with a needle ", "needle", "needle ") != 0 ||
      _strstr_test("haystack with a needle again", "needle", "needle again") !=
          0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<_strstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xec9(%rip),%rdi
lea    0xed2(%rip),%rdx
call   1040 <printf@plt>
lea    0xecf(%rip),%rdi
lea    0xee1(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <_strstr_test@plt>
cmp    $0x0,%rax
jne    1228 <_strstr+0x108>
lea    0xec7(%rip),%rdx
mov    %rdx,%rdi
mov    %rdx,%rsi
call   1030 <_strstr_test@plt>
cmp    $0x0,%rax
jne    1228 <_strstr+0x108>
lea    0xec2(%rip),%rdx
lea    0xea4(%rip),%rsi
mov    %rdx,%rdi
call   1030 <_strstr_test@plt>
cmp    $0x0,%rax
jne    1228 <_strstr+0x108>
lea    0xeba(%rip),%rdx
lea    0xe84(%rip),%rsi
mov    %rdx,%rdi
call   1030 <_strstr_test@plt>
cmp    $0x0,%rax
jne    1228 <_strstr+0x108>
lea    0xe5b(%rip),%rdi
lea    0xe64(%rip),%rdx
mov    %rdx,%rsi
call   1030 <_strstr_test@plt>
cmp    $0x0,%rax
jne    1228 <_strstr+0x108>
lea    0xe52(%rip),%rdi
lea    0xe44(%rip),%rsi
lea    0xe54(%rip),%rdx
call   1030 <_strstr_test@plt>
cmp    $0x0,%rax
jne    1228 <_strstr+0x108>
lea    0xe46(%rip),%rdi
lea    0xe20(%rip),%rsi
lea    0xe48(%rip),%rdx
call   1030 <_strstr_test@plt>
cmp    $0x0,%rax
je     1234 <_strstr+0x114>
movl   $0xffffffff,-0x4(%rbp)
jmp    123b <_strstr+0x11b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_strstr>:
push   %rbx
mov    %rdi,%rsi
lea    0xed5(%rip),%rdi
lea    0xede(%rip),%rdx
call   1040 <printf@plt>
lea    0xedb(%rip),%rdi
lea    0xeed(%rip),%rsi
xor    %edx,%edx
call   1030 <_strstr_test@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    1204 <_strstr+0xe4>
lea    0xed1(%rip),%rdi
mov    %rdi,%rsi
mov    %rdi,%rdx
call   1030 <_strstr_test@plt>
test   %rax,%rax
jne    1204 <_strstr+0xe4>
lea    0xeb6(%rip),%rsi
lea    0xec6(%rip),%rdi
mov    %rdi,%rdx
call   1030 <_strstr_test@plt>
test   %rax,%rax
jne    1204 <_strstr+0xe4>
lea    0xe9b(%rip),%rsi
lea    0xec3(%rip),%rdi
mov    %rdi,%rdx
call   1030 <_strstr_test@plt>
test   %rax,%rax
jne    1204 <_strstr+0xe4>
lea    0xe70(%rip),%rdi
lea    0xe79(%rip),%rdx
mov    %rdx,%rsi
call   1030 <_strstr_test@plt>
test   %rax,%rax
jne    1204 <_strstr+0xe4>
lea    0xe6c(%rip),%rdi
lea    0xe5e(%rip),%rsi
lea    0xe6e(%rip),%rdx
call   1030 <_strstr_test@plt>
test   %rax,%rax
jne    1204 <_strstr+0xe4>
lea    0xe65(%rip),%rdi
lea    0xe3f(%rip),%rsi
lea    0xe67(%rip),%rdx
call   1030 <_strstr_test@plt>
neg    %rax
sbb    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"%s: Testing %s\0A\00"
@.str.1 = [9 x i8] c"strstr()\00"
@.str.2 = [9 x i8] c"haystack\00"
@.str.3 = [7 x i8] c"needle\00"
@.str.4 = [8 x i8] c"needle \00"
@.str.5 = [13 x i8] c"needle again\00"
@.str.6 = [23 x i8] c"haystack with a needle\00"
@.str.7 = [24 x i8] c"haystack with a needle \00"
@.str.8 = [29 x i8] c"haystack with a needle again\00"
define i32 @_strstr(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%6 = call i64 @_strstr_test(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* null)
%7 = icmp ne i64 %6, 0
br i1 %7, label %26, label %8
8: ; preds = %1
%9 = call i64 @_strstr_test(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%10 = icmp ne i64 %9, 0
br i1 %10, label %26, label %11
11: ; preds = %8
%12 = call i64 @_strstr_test(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%13 = icmp ne i64 %12, 0
br i1 %13, label %26, label %14
14: ; preds = %11
%15 = call i64 @_strstr_test(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %14
%18 = call i64 @_strstr_test(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %17
%21 = call i64 @_strstr_test(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = call i64 @_strstr_test(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23, %20, %17, %14, %11, %8, %1
store i32 -1, i32* %2
br label %28
27: ; preds = %23
store i32 0, i32* %2
br label %28
28: ; preds = %27, %26
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [16 x i8] c"%s: Testing %s\0A\00"
@.str.1 = [9 x i8] c"strstr()\00"
@.str.2 = [9 x i8] c"haystack\00"
@.str.3 = [7 x i8] c"needle\00"
@.str.4 = [8 x i8] c"needle \00"
@.str.5 = [13 x i8] c"needle again\00"
@.str.6 = [23 x i8] c"haystack with a needle\00"
@.str.7 = [24 x i8] c"haystack with a needle \00"
@.str.8 = [29 x i8] c"haystack with a needle again\00"
define i32 @_strstr(i8* %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i64 @_strstr_test(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* null)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %24
5: ; preds = %1
%6 = tail call i64 @_strstr_test(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %5
%9 = tail call i64 @_strstr_test(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %8
%12 = tail call i64 @_strstr_test(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = tail call i64 @_strstr_test(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = tail call i64 @_strstr_test(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = tail call i64 @_strstr_test(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
%23 = sext i1 %22 to i32
br label %24
24: ; preds = %20, %1, %5, %8, %11, %14, %17
%25 = phi i32 [ -1, %17 ], [ -1, %14 ], [ -1, %11 ], [ -1, %8 ], [ -1, %5 ], [ -1, %1 ], [ %23, %20 ]
ret i32 %25
}