#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*/ crStrlen(char const *);
char *crStrstr(char *, char const *);
int __numOccurrences(const char *str, const char *substr) {
  int ret = 0;
  char *temp = (char *)str;
  while ((temp = crStrstr(temp, substr)) != NULL) {
    temp += crStrlen(substr);
    ret++;
  }
  return ret;
}


x86 assembly (clang, -O0):
<__numOccurrences>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <crStrstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1181 <__numOccurrences+0x61>
mov    -0x10(%rbp),%rdi
call   1030 <crStrlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113f <__numOccurrences+0x1f>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__numOccurrences>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
call   1040 <crStrstr@plt>
test   %rax,%rax
je     1163 <__numOccurrences+0x43>
mov    %rax,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <crStrlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
add    $0x1,%ebp
mov    %r14,%rsi
call   1040 <crStrstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1140 <__numOccurrences+0x20>
jmp    1165 <__numOccurrences+0x45>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @__numOccurrences(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%7 = load i8*, i8** %3
store i8* %7, i8** %6
br label %8
8: ; preds = %13, %2
%9 = load i8*, i8** %6
%10 = load i8*, i8** %4
%11 = call i8* @crStrstr(i8* %9, i8* %10)
store i8* %11, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %21
13: ; preds = %8
%14 = load i8*, i8** %4
%15 = call i32 @crStrlen(i8* %14)
%16 = load i8*, i8** %6
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds i8, i8* %16, i64 %17
store i8* %18, i8** %6
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
br label %8
21: ; preds = %8
%22 = load i32, i32* %5
ret i32 %22
}

LLVM IR (-O2):
define i32 @__numOccurrences(i8* %0, i8* %1) {
%3 = tail call i8* @crStrstr(i8* %0, i8* %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %14, label %5
5: ; preds = %2, %5
%6 = phi i8* [ %12, %5 ], [ %3, %2 ]
%7 = phi i32 [ %11, %5 ], [ 0, %2 ]
%8 = tail call i32 @crStrlen(i8* %1)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %6, i64 %9
%11 = add nuw nsw i32 %7, 1
%12 = tail call i8* @crStrstr(i8* %10, i8* %1)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %5
14: ; preds = %5, %2
%15 = phi i32 [ 0, %2 ], [ %11, %5 ]
ret i32 %15
}