#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*/ assert(int /*<<< orphan*/);
char *strstr(char *, char *);
int strCount(char *string, char *search) {
  int c;
  char *pos;
  c = 0;
  assert(string != NULL);
  assert(search != NULL);
  pos = strstr(string, search);
  while (pos) {
    c++;
    pos = strstr(pos + 1, search);
  }
  return c;
}


x86 assembly (clang, -O0):
<strCount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     119a <strCount+0x7a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x20(%rbp)
jmp    116c <strCount+0x4c>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strCount>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rbp
xor    %edi,%edi
test   %rbp,%rbp
setne  %dil
call   1030 <assert@plt>
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <strstr@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1177 <strCount+0x57>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
add    $0x1,%rax
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strstr@plt>
test   %rax,%rax
jne    1160 <strCount+0x40>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @strCount(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
%8 = icmp ne i8* %7, null
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i8*, i8** %3
%16 = load i8*, i8** %4
%17 = call i8* @strstr(i8* %15, i8* %16)
store i8* %17, i8** %6
br label %18
18: ; preds = %21, %2
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8*, i8** %4
%27 = call i8* @strstr(i8* %25, i8* %26)
store i8* %27, i8** %6
br label %18
28: ; preds = %18
%29 = load i32, i32* %5
ret i32 %29
}

LLVM IR (-O2):
define i32 @strCount(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp ne i8* %1, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%10 = icmp eq i8* %9, null
br i1 %10, label %18, label %11
11: ; preds = %2, %11
%12 = phi i8* [ %16, %11 ], [ %9, %2 ]
%13 = phi i32 [ %14, %11 ], [ 0, %2 ]
%14 = add nuw nsw i32 %13, 1
%15 = getelementptr inbounds i8, i8* %12, 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 %11
18: ; preds = %11, %2
%19 = phi i32 [ 0, %2 ], [ %14, %11 ]
ret i32 %19
}