#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 const *);
scalar_t__ strncmp(char const *, char const *, size_t);
int String_contains_str_count(const char *str, const char *chars) {
  const char *pch = str;
  size_t len = strlen(str);
  size_t len2 = strlen(chars);
  int count = 0;
  while (len >= len2) {
    if (strncmp(pch, chars, len2) == 0) {
      count++;
    }
    pch++;
    len--;
  }
  return count;
}


x86 assembly (clang, -O0):
<String_contains_str_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jb     11a8 <String_contains_str_count+0x88>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    118b <String_contains_str_count+0x6b>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1159 <String_contains_str_count+0x39>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<String_contains_str_count>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
xor    %ebp,%ebp
cmp    %rax,%rbx
jb     1172 <String_contains_str_count+0x52>
mov    %rax,%r12
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1030 <strncmp@plt>
cmp    $0x1,%rax
adc    $0x0,%ebp
add    $0x1,%r15
add    $0xffffffffffffffff,%rbx
cmp    %r12,%rbx
jae    1150 <String_contains_str_count+0x30>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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