#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 */
char *initial_strstr(char const *, char const *);
size_t strlen(char const *);
size_t count_initial_substrings(const char *str, const char *sub_str) {
  size_t n_strs = 0;
  const char *cur_str = str;
  size_t sub_str_len = strlen(sub_str);
  while ((cur_str = initial_strstr(cur_str, sub_str)) != NULL) {
    n_strs++;
    cur_str += sub_str_len;
  }
  return (n_strs);
}


x86 assembly (clang, -O0):
<count_initial_substrings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <initial_strstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1185 <count_initial_substrings+0x65>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    114d <count_initial_substrings+0x2d>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_initial_substrings>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <initial_strstr@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1167 <count_initial_substrings+0x47>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
add    %r15,%rax
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <initial_strstr@plt>
test   %rax,%rax
jne    1150 <count_initial_substrings+0x30>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i64 @count_initial_substrings(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = tail call i8* @initial_strstr(i8* %0, i8* %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %13, label %6
6: ; preds = %2, %6
%7 = phi i8* [ %11, %6 ], [ %4, %2 ]
%8 = phi i64 [ %9, %6 ], [ 0, %2 ]
%9 = add i64 %8, 1
%10 = getelementptr inbounds i8, i8* %7, i64 %3
%11 = tail call i8* @initial_strstr(i8* %10, i8* %1)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %6
13: ; preds = %6, %2
%14 = phi i64 [ 0, %2 ], [ %9, %6 ]
ret i64 %14
}