#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);
int strlen(char const *);
scalar_t__ strncmp(char const *, char const *, int);
int count_substrs(const char *s, const char *sub) {
  int count = 0;
  int sublen = strlen(sub);
  int left = strlen(s);
  assert(s != NULL && sub != NULL);
  while (left > sublen) {
    if (strncmp(s, sub, sublen) == 0)
      ++count;
    --left;
    ++s;
  }
  return count;
}


x86 assembly (clang, -O0):
<count_substrs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x1d(%rbp)
je     117a <count_substrs+0x4a>
cmpq   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    11d0 <count_substrs+0xa0>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11b6 <count_substrs+0x86>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1187 <count_substrs+0x57>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_substrs>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
test   %r12,%r12
setne  %al
test   %r14,%r14
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
xor    %ebx,%ebx
cmp    %r15d,%ebp
jle    11a1 <count_substrs+0x71>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <strncmp@plt>
cmp    $0x1,%rax
adc    $0x0,%ebx
add    $0xffffffff,%ebp
add    $0x1,%r12
cmp    %r15d,%ebp
jg     1180 <count_substrs+0x50>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @count_substrs(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
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
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %7
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br label %17
17: ; preds = %14, %2
%18 = phi i1 [ false, %2 ], [ %16, %14 ]
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
br label %21
21: ; preds = %34, %17
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %39
25: ; preds = %21
%26 = load i8*, i8** %3
%27 = load i8*, i8** %4
%28 = load i32, i32* %6
%29 = call i64 @strncmp(i8* %26, i8* %27, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %34
34: ; preds = %31, %25
%35 = load i32, i32* %7
%36 = add nsw i32 %35, -1
store i32 %36, i32* %7
%37 = load i8*, i8** %3
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %3
br label %21
39: ; preds = %21
%40 = load i32, i32* %5
ret i32 %40
}

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