#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 */
size_t strlen(char *);
char *strstr(char const *, char *);
int strstr_count(const char *s, char *t) {
  int n = 0;
  size_t len;
  char *p;
  if (t == NULL || s == NULL)
    return n;
  len = strlen(t);
  p = strstr(s, t);
  while (p) {
    n++;
    p = strstr(p + len - 1, t);
  }
  return n;
}


x86 assembly (clang, -O0):
<strstr_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     114d <strstr_count+0x2d>
cmpq   $0x0,-0x10(%rbp)
jne    1158 <strstr_count+0x38>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <strstr_count+0x8e>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11a8 <strstr_count+0x88>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%rdi
add    -0x28(%rbp),%rdi
add    $0xffffffffffffffff,%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x30(%rbp)
jmp    1176 <strstr_count+0x56>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstr_count>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
test   %rdi,%rdi
je     1178 <strstr_count+0x58>
mov    %rsi,%r14
test   %rsi,%rsi
je     1178 <strstr_count+0x58>
mov    %rdi,%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <strstr@plt>
test   %rax,%rax
je     1178 <strstr_count+0x58>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
lea    (%rax,%r15,1),%rdi
add    $0xffffffffffffffff,%rdi
mov    %r14,%rsi
call   1040 <strstr@plt>
test   %rax,%rax
jne    1160 <strstr_count+0x40>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @strstr_count(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %11, %2
%15 = load i32, i32* %6
store i32 %15, i32* %3
br label %36
16: ; preds = %11
%17 = load i8*, i8** %5
%18 = call i64 @strlen(i8* %17)
store i64 %18, i64* %7
%19 = load i8*, i8** %4
%20 = load i8*, i8** %5
%21 = call i8* @strstr(i8* %19, i8* %20)
store i8* %21, i8** %8
br label %22
22: ; preds = %25, %16
%23 = load i8*, i8** %8
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
%28 = load i8*, i8** %8
%29 = load i64, i64* %7
%30 = getelementptr inbounds i8, i8* %28, i64 %29
%31 = getelementptr inbounds i8, i8* %30, i64 -1
%32 = load i8*, i8** %5
%33 = call i8* @strstr(i8* %31, i8* %32)
store i8* %33, i8** %8
br label %22
34: ; preds = %22
%35 = load i32, i32* %6
store i32 %35, i32* %3
br label %36
36: ; preds = %34, %14
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
define i32 @strstr_count(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
%4 = icmp eq i8* %0, null
%5 = or i1 %4, %3
br i1 %5, label %18, label %6
6: ; preds = %2
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %18, label %10
10: ; preds = %6, %10
%11 = phi i8* [ %16, %10 ], [ %8, %6 ]
%12 = phi i32 [ %13, %10 ], [ 0, %6 ]
%13 = add nuw nsw i32 %12, 1
%14 = getelementptr inbounds i8, i8* %11, i64 %7
%15 = getelementptr inbounds i8, i8* %14, i64 -1
%16 = tail call i8* @strstr(i8* %15, i8* dereferenceable(1) %1)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %10
18: ; preds = %10, %6, %2
%19 = phi i32 [ 0, %2 ], [ 0, %6 ], [ %13, %10 ]
ret i32 %19
}