#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 const *);
char *strstr(char const *, char const *);
int fset_config_count_substring(const char *string, const char *substring) {
  int count, length;
  const char *pos;
  count = 0;
  length = strlen(substring);
  pos = string;
  while (pos && pos[0]) {
    pos = strstr(pos, substring);
    if (!pos)
      break;
    count++;
    pos += length;
  }
  return count;
}


x86 assembly (clang, -O0):
<fset_config_count_substring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x21(%rbp)
je     116b <fset_config_count_substring+0x4b>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    117b <fset_config_count_substring+0x5b>
jmp    11bb <fset_config_count_substring+0x9b>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119c <fset_config_count_substring+0x7c>
jmp    11bb <fset_config_count_substring+0x9b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    114b <fset_config_count_substring+0x2b>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fset_config_count_substring>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
xor    %ebp,%ebp
test   %rbx,%rbx
je     1170 <fset_config_count_substring+0x50>
cmpb   $0x0,(%rbx)
je     1170 <fset_config_count_substring+0x50>
movslq %eax,%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strstr@plt>
test   %rax,%rax
je     1170 <fset_config_count_substring+0x50>
add    $0x1,%ebp
mov    %rax,%rbx
add    %r15,%rbx
cmpb   $0x0,(%rax,%r15,1)
jne    1150 <fset_config_count_substring+0x30>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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