#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 *);
scalar_t__ strncmp(char const *, char const *, int);
int find_all_count(const char *needle, const char *haystack) {
  int i, c = 0;
  for (i = 0; i < strlen(haystack) - strlen(needle); i++) {
    if (strncmp(haystack + i, needle, strlen(needle)) == 0)
      c++;
  }
  return c;
}


x86 assembly (clang, -O0):
<find_all_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%ecx
mov    %eax,%edx
mov    -0x1c(%rbp),%eax
sub    %edx,%ecx
cmp    %ecx,%eax
jge    11c0 <find_all_count+0xa0>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11ad <find_all_count+0x8d>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b2 <find_all_count+0x92>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <find_all_count+0x1e>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_all_count>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r12,%rdi
call   1040 <strlen@plt>
xor    %r13d,%r13d
cmp    %eax,%r15d
jle    11a1 <find_all_count+0x81>
xor    %ebp,%ebp
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r14,%rbp,1),%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x1,%rax
adc    $0x0,%r13d
add    $0x1,%rbp
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebx
movslq %ebx,%rax
cmp    %rax,%rbp
jl     1160 <find_all_count+0x40>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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