#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 */
char *strchr(char const *, char const);
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char const *, size_t);
char *strstr(char const *, char const *);
char *strstrc(const char *s, const char *p, const char t) {
  char *endptr;
  size_t slen, plen;
  endptr = strchr(s, t);
  if (!endptr)
    return strstr(s, p);
  plen = strlen(p);
  slen = endptr - s;
  while (slen >= plen) {
    if (*s == *p && strncmp(s + 1, p + 1, plen - 1) == 0)
      return (char *)s;
    s++;
    slen--;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<strstrc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x19(%rbp),%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1187 <strstrc+0x47>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x8(%rbp)
jmp    1220 <strstrc+0xe0>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jb     1218 <strstrc+0xd8>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11fb <strstrc+0xbb>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
mov    -0x38(%rbp),%rdx
sub    $0x1,%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11fb <strstrc+0xbb>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1220 <strstrc+0xe0>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
jmp    11a3 <strstrc+0x63>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstrc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1185 <strstrc+0x45>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %r15,%rbx
cmp    %rax,%rbx
jae    119e <strstrc+0x5e>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <strstr@plt>
mov    %rax,%r12
lea    0x1(%r14),%r13
lea    -0x1(%rax),%rbp
jmp    11bd <strstrc+0x7d>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15
add    $0xffffffffffffffff,%rbx
cmp    %r12,%rbx
jb     1170 <strstrc+0x30>
movzbl (%r15),%eax
cmp    (%r14),%al
jne    11b0 <strstrc+0x70>
lea    0x1(%r15),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11b0 <strstrc+0x70>
jmp    1173 <strstrc+0x33>

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

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