#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 strlen(char *);
char *strstr(char *, char *);
int count_occurence_in_string(char *str_in, char *occurence) {
  char *p = str_in;
  int cpt = 0;
  p = (char *)strstr((char *)p, (char *)occurence);
  while (p && p - str_in < strlen((char *)str_in)) {
    cpt++;
    p += strlen((char *)occurence);
    p = strstr((char *)p, (char *)occurence);
  }
  return (int)cpt;
}


x86 assembly (clang, -O0):
<count_occurence_in_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x1d(%rbp)
je     118a <count_occurence_in_string+0x6a>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
setl   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    119a <count_occurence_in_string+0x7a>
jmp    11d2 <count_occurence_in_string+0xb2>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x18(%rbp)
jmp    1150 <count_occurence_in_string+0x30>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_occurence_in_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strstr@plt>
test   %rax,%rax
je     117b <count_occurence_in_string+0x5b>
mov    %rax,%rbx
xor    %r12d,%r12d
xchg   %ax,%ax
mov    %rbx,%rbp
sub    %r15,%rbp
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    117e <count_occurence_in_string+0x5e>
add    $0x1,%r12d
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1140 <count_occurence_in_string+0x20>
jmp    117e <count_occurence_in_string+0x5e>
xor    %r12d,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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