#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 */
typedef int /*<<< orphan*/ ushort;

/* Variables and functions */
int cannawcstrlen(int /*<<< orphan*/ *);
scalar_t__ memcmp(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int cannawcnumstr(ushort *src, ushort *key) {
  int i, len1, len2, ret;
  len1 = cannawcstrlen(src);
  len2 = cannawcstrlen(key);
  ret = 0;
  for (i = 0; i <= len1 - len2;) {
    if (memcmp(&(src[i]), key, len2 * 2) == 0) {
      ret++;
      i += len2;
    } else {
      i++;
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<cannawcnumstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <cannawcstrlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <cannawcstrlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jg     11b4 <cannawcnumstr+0x94>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
shl    $0x1,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    11a6 <cannawcnumstr+0x86>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11af <cannawcnumstr+0x8f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1156 <cannawcnumstr+0x36>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cannawcnumstr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,(%rsp)
call   1030 <cannawcstrlen@plt>
mov    %eax,%r12d
mov    %rbx,%r15
mov    %rbx,%rdi
call   1030 <cannawcstrlen@plt>
sub    %eax,%r12d
js     1195 <cannawcnumstr+0x75>
mov    %eax,%r13d
mov    %eax,%ebx
add    %r13d,%ebx
xor    %ebp,%ebp
xor    %r14d,%r14d
jmp    116c <cannawcnumstr+0x4c>
nopl   0x0(%rax)
mov    %al,%cl
add    %ecx,%ebp
add    %edx,%r14d
cmp    %r12d,%r14d
jg     1197 <cannawcnumstr+0x77>
movslq %r14d,%rax
mov    (%rsp),%rcx
lea    (%rcx,%rax,4),%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <memcmp@plt>
xor    %ecx,%ecx
mov    %r13d,%edx
test   %rax,%rax
sete   %al
je     1160 <cannawcnumstr+0x40>
mov    $0x1,%edx
jmp    1160 <cannawcnumstr+0x40>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @cannawcnumstr(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%9 = load i32*, i32** %3
%10 = call i32 @cannawcstrlen(i32* %9)
store i32 %10, i32* %6
%11 = load i32*, i32** %4
%12 = call i32 @cannawcstrlen(i32* %11)
store i32 %12, i32* %7
store i32 0, i32* %8
store i32 0, i32* %5
br label %13
13: ; preds = %38, %2
%14 = load i32, i32* %5
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = sub nsw i32 %15, %16
%18 = icmp sle i32 %14, %17
br i1 %18, label %19, label %39
19: ; preds = %13
%20 = load i32*, i32** %3
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32*, i32** %4
%25 = load i32, i32* %7
%26 = mul nsw i32 %25, 2
%27 = call i64 @memcmp(i32* %23, i32* %24, i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %19
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
%32 = load i32, i32* %7
%33 = load i32, i32* %5
%34 = add nsw i32 %33, %32
store i32 %34, i32* %5
br label %38
35: ; preds = %19
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %38
38: ; preds = %35, %29
br label %13
39: ; preds = %13
%40 = load i32, i32* %8
ret i32 %40
}

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