#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 */
scalar_t__ strlen(char *);
char *strstr(char *, char *);
int pl_count(char *the_string, char *word) {
  char *pch = the_string;
  int count = 0;
  if (the_string == NULL || word == NULL) {
    return -1;
  }
  if (strlen(the_string) == 0 || strlen(word) == 0) {
    return -1;
  }
  do {
    pch = strstr(pch, word);
    if (pch != NULL) {
      pch += strlen(word);
      count++;
    }
  } while (pch != NULL);
  return count;
}


x86 assembly (clang, -O0):
<pl_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1155 <pl_count+0x35>
cmpq   $0x0,-0x18(%rbp)
jne    1161 <pl_count+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <pl_count+0xc4>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
je     1187 <pl_count+0x67>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jne    1193 <pl_count+0x73>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <pl_count+0xc4>
jmp    1198 <pl_count+0x78>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ce <pl_count+0xae>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d3 <pl_count+0xb3>
cmpq   $0x0,-0x20(%rbp)
jne    1198 <pl_count+0x78>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pl_count>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     118d <pl_count+0x6d>
mov    %rsi,%r14
test   %rsi,%rsi
je     118d <pl_count+0x6d>
cmpb   $0x0,(%rdi)
je     118d <pl_count+0x6d>
cmpb   $0x0,(%r14)
je     118d <pl_count+0x6d>
mov    %r14,%rsi
call   1040 <strstr@plt>
test   %rax,%rax
je     118b <pl_count+0x6b>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %r15,%rbx
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1170 <pl_count+0x50>
jmp    118d <pl_count+0x6d>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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