#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 *, char const *, char *, ...);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char const *, char const *);
char *strstr(char const *, char const *);
int _strstr_test(char const *str1, char const *str2, char const *expected) {
  int ret;
  char const *res;
  res = strstr(str1, str2);
  if (expected == NULL || res == NULL)
    ret = (res == expected) ? 0 : -1;
  else
    ret = (strcmp(res, expected) == 0) ? 0 : -1;
  printf("\"%s\", \"%s\" => %s%s%s", str1, str2, (res != NULL) ? "\"" : "",
         (res != NULL) ? res : "NULL", (res != NULL) ? "\"" : "");
  if (ret != 0)
    printf(" (expected: %s%s%s)", (expected != NULL) ? "\"" : "",
           (expected != NULL) ? expected : "NULL",
           (expected != NULL) ? "\"" : "");
  putc('\n', stdout);
  return ret;
}


x86 assembly (clang, -O0):
<_strstr_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     117b <_strstr_test+0x3b>
cmpq   $0x0,-0x28(%rbp)
jne    1198 <_strstr_test+0x58>
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rsi
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    %rsi,%rdx
cmove  %ecx,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b9 <_strstr_test+0x79>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@plt>
mov    %rax,%rdx
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdx
lea    0xe42(%rip),%rax
lea    0xe3a(%rip),%rcx
cmp    $0x0,%rdx
cmovne %rcx,%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ff <_strstr_test+0xbf>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    120f <_strstr_test+0xcf>
lea    0xe11(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    120f <_strstr_test+0xcf>
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%r8
mov    -0x28(%rbp),%rdi
lea    0xdec(%rip),%r9
lea    0xde4(%rip),%rax
cmp    $0x0,%rdi
cmovne %rax,%r9
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
je     12c7 <_strstr_test+0x187>
mov    -0x18(%rbp),%rdx
lea    0xdba(%rip),%rax
lea    0xdb2(%rip),%rcx
cmp    $0x0,%rdx
cmovne %rcx,%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1287 <_strstr_test+0x147>
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
jmp    1297 <_strstr_test+0x157>
lea    0xd89(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    1297 <_strstr_test+0x157>
mov    -0x50(%rbp),%rsi
mov    -0x58(%rbp),%rdx
mov    -0x18(%rbp),%rdi
lea    0xd6c(%rip),%rcx
lea    0xd64(%rip),%rax
cmp    $0x0,%rdi
cmovne %rax,%rcx
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d12(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1050 <putc@plt>
mov    -0x1c(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_strstr_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1060 <strstr@plt>
mov    %rax,%rbx
test   %r14,%r14
je     11fe <_strstr_test+0xbe>
test   %rbx,%rbx
je     11fe <_strstr_test+0xbe>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
mov    %rax,%r13
lea    0xe7d(%rip),%rdi
lea    0xe8b(%rip),%rcx
xor    %ebp,%ebp
mov    %r12,%rsi
mov    %r15,%rdx
mov    %rbx,%r8
mov    %rcx,%r9
xor    %eax,%eax
call   1030 <printf@plt>
test   %r13,%r13
je     11da <_strstr_test+0x9a>
test   %r14,%r14
lea    0xe68(%rip),%rax
lea    0xe60(%rip),%rcx
cmove  %rax,%rcx
lea    0xe57(%rip),%rdx
cmovne %r14,%rdx
lea    0xe51(%rip),%rdi
mov    %rcx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%ebp
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1050 <putc@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %rbx,%rbx
lea    0xe0e(%rip),%rax
lea    0xe06(%rip),%rcx
cmove  %rax,%rcx
lea    0xdfd(%rip),%r8
cmovne %rbx,%r8
lea    0xddb(%rip),%rdi
xor    %ebp,%ebp
mov    %r12,%rsi
mov    %r15,%rdx
mov    %rcx,%r9
xor    %eax,%eax
call   1030 <printf@plt>
cmp    %r14,%rbx
jne    11a4 <_strstr_test+0x64>
jmp    11da <_strstr_test+0x9a>

LLVM IR (-O0):
@.str = [21 x i8] c"\22%s\22, \22%s\22 => %s%s%s\00"
@.str.1 = [2 x i8] c"\22\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [5 x i8] c"NULL\00"
@.str.4 = [20 x i8] c" (expected: %s%s%s)\00"
@stdout = global i32 0
define i32 @_strstr_test(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i8* @strstr(i8* %9, i8* %10)
store i8* %11, i8** %8
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %3
%15 = load i8*, i8** %8
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %23
17: ; preds = %14, %3
%18 = load i8*, i8** %8
%19 = load i8*, i8** %6
%20 = icmp eq i8* %18, %19
%21 = zext i1 %20 to i64
%22 = select i1 %20, i32 0, i32 -1
store i32 %22, i32* %7
br label %30
23: ; preds = %14
%24 = load i8*, i8** %8
%25 = load i8*, i8** %6
%26 = call i64 @strcmp(i8* %24, i8* %25)
%27 = icmp eq i64 %26, 0
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 0, i32 -1
store i32 %29, i32* %7
br label %30
30: ; preds = %23, %17
%31 = load i8*, i8** %4
%32 = load i8*, i8** %5
%33 = load i8*, i8** %8
%34 = icmp ne i8* %33, null
%35 = zext i1 %34 to i64
%36 = select i1 %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%37 = load i8*, i8** %8
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %41
39: ; preds = %30
%40 = load i8*, i8** %8
br label %42
41: ; preds = %30
br label %42
42: ; preds = %41, %39
%43 = phi i8* [ %40, %39 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %41 ]
%44 = load i8*, i8** %8
%45 = icmp ne i8* %44, null
%46 = zext i1 %45 to i64
%47 = select i1 %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%48 = call i32 (i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %31, i8* %32, i8* %36, i8* %43, i8* %47)
%49 = load i32, i32* %7
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %68
51: ; preds = %42
%52 = load i8*, i8** %6
%53 = icmp ne i8* %52, null
%54 = zext i1 %53 to i64
%55 = select i1 %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%56 = load i8*, i8** %6
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %60
58: ; preds = %51
%59 = load i8*, i8** %6
br label %61
60: ; preds = %51
br label %61
61: ; preds = %60, %58
%62 = phi i8* [ %59, %58 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %60 ]
%63 = load i8*, i8** %6
%64 = icmp ne i8* %63, null
%65 = zext i1 %64 to i64
%66 = select i1 %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%67 = call i32 (i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %55, i8* %62, i8* %66)
br label %68
68: ; preds = %61, %42
%69 = load i32, i32* @stdout
%70 = call i32 @putc(i8 signext 10, i32 %69)
%71 = load i32, i32* %7
ret i32 %71
}

LLVM IR (-O2):
@.str = [21 x i8] c"\22%s\22, \22%s\22 => %s%s%s\00"
@.str.1 = [2 x i8] c"\22\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [5 x i8] c"NULL\00"
@.str.4 = [20 x i8] c" (expected: %s%s%s)\00"
@stdout = global i32 0
define i32 @_strstr_test(i8* %0, i8* %1, i8* %2) {
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%5 = icmp eq i8* %2, null
%6 = icmp eq i8* %4, null
%7 = select i1 %5, i1 true, i1 %6
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = icmp eq i8* %4, %2
%10 = select i1 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%11 = select i1 %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %4
%12 = tail call i32 (i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %10, i8* %11, i8* %10)
br i1 %9, label %21, label %17
13: ; preds = %3
%14 = tail call i64 @strcmp(i8* %4, i8* %2)
%15 = icmp eq i64 %14, 0
%16 = tail call i32 (i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br i1 %15, label %21, label %17
17: ; preds = %8, %13
%18 = select i1 %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%19 = select i1 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %2
%20 = tail call i32 (i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %18, i8* %19, i8* %18)
br label %21
21: ; preds = %8, %17, %13
%22 = phi i32 [ 0, %8 ], [ -1, %17 ], [ 0, %13 ]
%23 = load i32, i32* @stdout
%24 = tail call i32 @putc(i8 signext 10, i32 %23)
ret i32 %22
}