#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 char uint8_t;
typedef int uint32_t;
typedef int /*<<< orphan*/ text;
typedef int /*<<< orphan*/ string;

/* Variables and functions */
int /*<<< orphan*/ boyer_moore_search(char *, int, char *, int, int *, int *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  uint8_t text[] = "This is a test of word searching. Have a nice year!";
  uint32_t text_len = sizeof(text) - 1;
  uint8_t string[] = "ear";
  uint32_t str_len = sizeof(string) - 1;
  uint32_t hit_index[255];
  uint32_t hit_num = 0;
  uint32_t i = 0;
  printf("text    : %s\n", text);
  printf("text_len: %u\n", text_len);
  printf("string  : %s\n", string);
  printf("str_len : %u\n", str_len);
  printf("\n");
  boyer_moore_search(text, text_len, string, str_len, &hit_num, hit_index);
  printf("hit_num : %u\n", hit_num);
  for (i = 0; i < hit_num; i++)
    printf("hit_index[%u] = %u\n", i, hit_index[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xeb3(%rip),%rsi
mov    $0x34,%edx
call   1050 <memcpy@plt>
movl   $0x33,-0x44(%rbp)
mov    0xed0(%rip),%eax
mov    %eax,-0x48(%rbp)
movl   $0x3,-0x4c(%rbp)
movl   $0x0,-0x454(%rbp)
movl   $0x0,-0x458(%rbp)
lea    -0x40(%rbp),%rsi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x44(%rbp),%esi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x48(%rbp),%rsi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4c(%rbp),%esi
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
lea    -0x48(%rbp),%rdx
mov    -0x4c(%rbp),%ecx
lea    -0x450(%rbp),%r9
lea    -0x454(%rbp),%r8
call   1030 <boyer_moore_search@plt>
mov    -0x454(%rbp),%esi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x458(%rbp)
mov    -0x458(%rbp),%eax
cmp    -0x454(%rbp),%eax
jge    125d <main+0x12d>
mov    -0x458(%rbp),%esi
movslq -0x458(%rbp),%rax
mov    -0x450(%rbp,%rax,4),%edx
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x458(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x458(%rbp)
jmp    1215 <main+0xe5>
xor    %eax,%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x458,%rsp
movaps 0xedf(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xec3(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xea7(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x217261,0x40(%rsp)
movl   $0x726165,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xeb7(%rip),%rdi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeaf(%rip),%rdi
mov    $0x33,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeaa(%rip),%rdi
lea    0xc(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea2(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x8(%rsp),%r8
lea    0x50(%rsp),%r9
mov    %r14,%rdi
mov    $0x33,%esi
mov    %rbx,%rdx
mov    $0x3,%ecx
call   1040 <boyer_moore_search@plt>
mov    0x8(%rsp),%esi
lea    0xe70(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    123e <main+0x10e>
lea    0xe69(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x50(%rsp,%rbx,4),%edx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
cmp    %rax,%rbx
jl     1220 <main+0xf0>
xor    %eax,%eax
add    $0x458,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.text = [52 x i8] c"This is a test of word searching. Have a nice year!\00"
@__const.main.string = [4 x i8] c"ear\00"
@.str = [14 x i8] c"text : %s\0A\00"
@.str.1 = [14 x i8] c"text_len: %u\0A\00"
@.str.2 = [14 x i8] c"string : %s\0A\00"
@.str.3 = [14 x i8] c"str_len : %u\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [14 x i8] c"hit_num : %u\0A\00"
@.str.6 = [20 x i8] c"hit_index[%u] = %u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [52 x i8]
%3 = alloca i32
%4 = alloca [4 x i8]
%5 = alloca i32
%6 = alloca [255 x i32]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = bitcast [52 x i8]* %2 to i8*
store i32 51, i32* %3
%10 = bitcast [4 x i8]* %4 to i8*
store i32 3, i32* %5
store i32 0, i32* %7
store i32 0, i32* %8
%11 = getelementptr inbounds [52 x i8], [52 x i8]* %2, i64 0, i64 0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = load i32, i32* %5
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%20 = getelementptr inbounds [52 x i8], [52 x i8]* %2, i64 0, i64 0
%21 = load i32, i32* %3
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%23 = load i32, i32* %5
%24 = getelementptr inbounds [255 x i32], [255 x i32]* %6, i64 0, i64 0
%25 = call i32 @boyer_moore_search(i8* %20, i32 %21, i8* %22, i32 %23, i32* %7, i32* %24)
%26 = load i32, i32* %7
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %26)
store i32 0, i32* %8
br label %28
28: ; preds = %39, %0
%29 = load i32, i32* %8
%30 = load i32, i32* %7
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %42
32: ; preds = %28
%33 = load i32, i32* %8
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [255 x i32], [255 x i32]* %6, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %33, i32 %37)
br label %39
39: ; preds = %32
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %28
42: ; preds = %28
ret i32 0
}

LLVM IR (-O2):
@__const.main.text = [52 x i8] c"This is a test of word searching. Have a nice year!\00"
@.str = [14 x i8] c"text : %s\0A\00"
@.str.1 = [14 x i8] c"text_len: %u\0A\00"
@.str.2 = [14 x i8] c"string : %s\0A\00"
@.str.3 = [14 x i8] c"str_len : %u\0A\00"
@.str.5 = [14 x i8] c"hit_num : %u\0A\00"
@.str.6 = [20 x i8] c"hit_index[%u] = %u\0A\00"
define i32 @main() {
%1 = alloca [52 x i8]
%2 = alloca i32
%3 = alloca [255 x i32]
%4 = alloca i32
%5 = getelementptr inbounds [52 x i8], [52 x i8]* %1, i64 0, i64 0
%6 = bitcast i32* %2 to i8*
store i32 7496037, i32* %2
%7 = bitcast [255 x i32]* %3 to i8*
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %5)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 51)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 3)
%13 = call i32 @putchar(i32 10)
%14 = getelementptr inbounds [255 x i32], [255 x i32]* %3, i64 0, i64 0
%15 = call i32 @boyer_moore_search(i8* %5, i32 51, i8* %6, i32 3, i32* %4, i32* %14)
%16 = load i32, i32* %4
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %0, %20
%21 = phi i64 [ %26, %20 ], [ 0, %0 ]
%22 = getelementptr inbounds [255 x i32], [255 x i32]* %3, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = trunc i64 %21 to i32
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %24, i32 %23)
%26 = add nuw nsw i64 %21, 1
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %26, %28
br i1 %29, label %20, label %30
30: ; preds = %20, %0
ret i32 0
}