#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 *strstrc(const char *s, const char *p, const char t) {
  char *endptr;
  size_t slen, plen;
  endptr = strchr(s, t);
  if (!endptr)
    return NULL;
  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    116e <strstrc+0x3e>
movq   $0x0,-0x8(%rbp)
jmp    1207 <strstrc+0xd7>
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     11ff <strstrc+0xcf>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11e2 <strstrc+0xb2>
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    11e2 <strstrc+0xb2>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1207 <strstrc+0xd7>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
jmp    118a <strstrc+0x5a>
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     1160 <strstrc+0x30>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %r15,%rbx
cmp    %rax,%rbx
jae    1175 <strstrc+0x45>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rax,%r12
lea    0x1(%r14),%r13
lea    -0x1(%rax),%rbp
jmp    119d <strstrc+0x6d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r15
add    $0xffffffffffffffff,%rbx
cmp    %r12,%rbx
jb     1160 <strstrc+0x30>
movzbl (%r15),%eax
cmp    (%r14),%al
jne    1190 <strstrc+0x60>
lea    0x1(%r15),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1190 <strstrc+0x60>
jmp    1163 <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 %17, label %16
16: ; preds = %3
store i8* null, i8** %4
br label %54
17: ; preds = %3
%18 = load i8*, i8** %6
%19 = call i64 @strlen(i8* %18)
store i64 %19, i64* %10
%20 = load i8*, i8** %8
%21 = load i8*, i8** %5
%22 = ptrtoint i8* %20 to i64
%23 = ptrtoint i8* %21 to i64
%24 = sub i64 %22, %23
store i64 %24, i64* %9
br label %25
25: ; preds = %48, %17
%26 = load i64, i64* %9
%27 = load i64, i64* %10
%28 = icmp uge i64 %26, %27
br i1 %28, label %29, label %53
29: ; preds = %25
%30 = load i8*, i8** %5
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = load i8*, i8** %6
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %32, %35
br i1 %36, label %37, label %48
37: ; preds = %29
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8*, i8** %6
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = load i64, i64* %10
%43 = sub i64 %42, 1
%44 = call i64 @strncmp(i8* %39, i8* %41, i64 %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %37
%47 = load i8*, i8** %5
store i8* %47, i8** %4
br label %54
48: ; preds = %37, %29
%49 = load i8*, i8** %5
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %5
%51 = load i64, i64* %9
%52 = add i64 %51, -1
store i64 %52, i64* %9
br label %25
53: ; preds = %25
store i8* null, i8** %4
br label %54
54: ; preds = %53, %46, %16
%55 = load i8*, i8** %4
ret i8* %55
}

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 %29, label %6
6: ; preds = %3
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = ptrtoint i8* %4 to i64
%9 = ptrtoint i8* %0 to i64
%10 = sub i64 %8, %9
%11 = icmp ult i64 %10, %7
br i1 %11, label %29, label %12
12: ; preds = %6
%13 = getelementptr inbounds i8, i8* %1, i64 1
%14 = add i64 %7, -1
br label %15
15: ; preds = %12, %25
%16 = phi i64 [ %10, %12 ], [ %27, %25 ]
%17 = phi i8* [ %0, %12 ], [ %26, %25 ]
%18 = load i8, i8* %17
%19 = load i8, i8* %1
%20 = icmp eq i8 %18, %19
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = getelementptr inbounds i8, i8* %17, i64 1
%23 = tail call i64 @strncmp(i8* %22, i8* %13, i64 %14)
%24 = icmp eq i64 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %21, %15
%26 = getelementptr inbounds i8, i8* %17, i64 1
%27 = add i64 %16, -1
%28 = icmp ult i64 %27, %7
br i1 %28, label %29, label %15
29: ; preds = %21, %25, %6, %3
%30 = phi i8* [ null, %3 ], [ null, %6 ], [ %17, %21 ], [ null, %25 ]
ret i8* %30
}