#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 countHits(const char *line, const char *key) {
  int n = strlen(key);
  int k = strlen(line) - n;
  int i;
  int hits = 0;
  for (i = 0; i < k; i++, line++)
    if (*line == *key)
      if (strncmp(line, key, n) == 0)
        hits++;
  return hits;
}


x86 assembly (clang, -O0):
<countHits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
sub    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11c2 <countHits+0xa2>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    -0x10(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11a3 <countHits+0x83>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    119e <countHits+0x7e>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a3 <countHits+0x83>
jmp    11a8 <countHits+0x88>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1159 <countHits+0x39>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countHits>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
sub    %r15d,%eax
xor    %r12d,%r12d
test   %eax,%eax
jg     116c <countHits+0x4c>
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
nopl   0x0(%rax)
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    %ebp,%r15d
je     114d <countHits+0x2d>
movzbl (%rbx),%eax
cmp    (%r14),%al
jne    1160 <countHits+0x40>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <strncmp@plt>
cmp    $0x1,%rax
adc    $0x0,%r12d
jmp    1160 <countHits+0x40>

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

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