#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*/ free(char *);
scalar_t__ strdup(char const *);
int strlen(char *);
char *strstr(char const *, char const *);
char *strstr_rs(const char *haystack, const char *needle) {
  char *end_address;
  char *new_needle;
  new_needle = (char *)strdup(needle);
  new_needle[strlen(new_needle) - 1] = '\0';
  end_address = strstr(haystack, new_needle);
  if (end_address) {
    end_address += strlen(new_needle);
    end_address = strstr(end_address, needle + strlen(new_needle));
  }
  if (end_address) {
    end_address += 1;
    do {
      if (*end_address == '\t' || *end_address == ' ') {
        end_address++;
      } else {
        break;
      }
    } while (*end_address != '\0');
  }
  free(new_needle);
  return (end_address);
}


x86 assembly (clang, -O0):
<strstr_rs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11e2 <strstr_rs+0xa2>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdi
cltq
add    %rax,%rsi
call   1060 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1249 <strstr_rs+0x109>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
je     1219 <strstr_rs+0xd9>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    122a <strstr_rs+0xea>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    122f <strstr_rs+0xef>
jmp    1244 <strstr_rs+0x104>
jmp    1234 <strstr_rs+0xf4>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11f9 <strstr_rs+0xb9>
jmp    1249 <strstr_rs+0x109>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstr_rs>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1050 <strdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     11c6 <strstr_rs+0x86>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     11c6 <strstr_rs+0x86>
mov    %rax,%rbx
add    $0x1,%rbx
mov    0x1(%rax),%al
jmp    11bc <strstr_rs+0x7c>
nop
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11c8 <strstr_rs+0x88>
cmp    $0x20,%al
je     11b0 <strstr_rs+0x70>
cmp    $0x9,%al
je     11b0 <strstr_rs+0x70>
jmp    11c8 <strstr_rs+0x88>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @strstr_rs(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i64 @strdup(i8* %7)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = load i8*, i8** %6
%12 = call i32 @strlen(i8* %11)
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %10, i64 %14
store i8 0, i8* %15
%16 = load i8*, i8** %3
%17 = load i8*, i8** %6
%18 = call i8* @strstr(i8* %16, i8* %17)
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %34
21: ; preds = %2
%22 = load i8*, i8** %6
%23 = call i32 @strlen(i8* %22)
%24 = load i8*, i8** %5
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8* %26, i8** %5
%27 = load i8*, i8** %5
%28 = load i8*, i8** %4
%29 = load i8*, i8** %6
%30 = call i32 @strlen(i8* %29)
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = call i8* @strstr(i8* %27, i8* %32)
store i8* %33, i8** %5
br label %34
34: ; preds = %21, %2
%35 = load i8*, i8** %5
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %61
37: ; preds = %34
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i64 1
store i8* %39, i8** %5
br label %40
40: ; preds = %55, %37
%41 = load i8*, i8** %5
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 9
br i1 %44, label %50, label %45
45: ; preds = %40
%46 = load i8*, i8** %5
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 32
br i1 %49, label %50, label %53
50: ; preds = %45, %40
%51 = load i8*, i8** %5
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %5
br label %54
53: ; preds = %45
br label %60
54: ; preds = %50
br label %55
55: ; preds = %54
%56 = load i8*, i8** %5
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp ne i32 %58, 0
br i1 %59, label %40, label %60
60: ; preds = %55, %53
br label %61
61: ; preds = %60, %34
%62 = load i8*, i8** %6
%63 = call i32 @free(i8* %62)
%64 = load i8*, i8** %5
ret i8* %64
}

LLVM IR (-O2):
define i8* @strstr_rs(i8* %0, i8* %1) {
%3 = tail call i64 @strdup(i8* %1)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @strlen(i8* %4)
%6 = add nsw i32 %5, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %4, i64 %7
store i8 0, i8* %8
%9 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %4)
%10 = icmp eq i8* %9, null
br i1 %10, label %30, label %11
11: ; preds = %2
%12 = tail call i32 @strlen(i8* %4)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %9, i64 %13
%15 = tail call i32 @strlen(i8* %4)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %1, i64 %16
%18 = tail call i8* @strstr(i8* %14, i8* dereferenceable(1) %17)
%19 = icmp eq i8* %18, null
br i1 %19, label %30, label %20
20: ; preds = %11
%21 = getelementptr inbounds i8, i8* %18, i64 1
%22 = load i8, i8* %21
br label %23
23: ; preds = %26, %20
%24 = phi i8 [ %28, %26 ], [ %22, %20 ]
%25 = phi i8* [ %27, %26 ], [ %21, %20 ]
switch i8 %24, label %30 [
i8 9, label %26
i8 32, label %26
]
26: ; preds = %23, %23
%27 = getelementptr inbounds i8, i8* %25, i64 1
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 0
br i1 %29, label %30, label %23
30: ; preds = %23, %26, %2, %11
%31 = phi i8* [ null, %11 ], [ null, %2 ], [ %25, %23 ], [ %27, %26 ]
%32 = tail call i32 @free(i8* %4)
ret i8* %31
}