#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*/ pat_match(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
void main() {
  char *txt = "THIS IS A TEST TEXT";
  char *pat = "TEST";
  int i = 0;
  printf("\n text: %s", txt);
  printf("\n pattern: %s", pat);
  for (i = 0; i < strlen(txt); i++) {
    if (txt[i] == pat[0]) {
      printf("\njump index:=%d", i);
      pat_match(txt, pat, i);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    11eb <main+0xbb>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x10(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11d8 <main+0xa8>
mov    -0x14(%rbp),%esi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <pat_match@plt>
jmp    11dd <main+0xad>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1180 <main+0x50>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xed9(%rip),%rdi
lea    0xeb9(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xecc(%rip),%rdi
lea    0xeb5(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11d4 <main+0xa4>
mov    $0x4a401,%r13d
lea    0xe81(%rip),%r12
lea    0xeac(%rip),%r14
lea    0xe87(%rip),%r15
xor    %ebx,%ebx
jmp    11b3 <main+0x83>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11d4 <main+0xa4>
bt     %rbx,%r13
jae    11a0 <main+0x70>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <pat_match@plt>
jmp    11a0 <main+0x70>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"THIS IS A TEST TEXT\00"
@.str.1 = [5 x i8] c"TEST\00"
@.str.2 = [11 x i8] c"\0A text: %s\00"
@.str.3 = [14 x i8] c"\0A pattern: %s\00"
@.str.4 = [16 x i8] c"\0Ajump index:=%d\00"
define void @main() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8** %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %2
store i32 0, i32* %3
%4 = load i8*, i8** %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%6 = load i8*, i8** %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %6)
store i32 0, i32* %3
br label %8
8: ; preds = %33, %0
%9 = load i32, i32* %3
%10 = load i8*, i8** %1
%11 = call i32 @strlen(i8* %10)
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %36
13: ; preds = %8
%14 = load i8*, i8** %1
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %19, %23
br i1 %24, label %25, label %32
25: ; preds = %13
%26 = load i32, i32* %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = load i8*, i8** %1
%29 = load i8*, i8** %2
%30 = load i32, i32* %3
%31 = call i32 @pat_match(i8* %28, i8* %29, i32 %30)
br label %32
32: ; preds = %25, %13
br label %33
33: ; preds = %32
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %8
36: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"THIS IS A TEST TEXT\00"
@.str.1 = [5 x i8] c"TEST\00"
@.str.2 = [11 x i8] c"\0A text: %s\00"
@.str.3 = [14 x i8] c"\0A pattern: %s\00"
@.str.4 = [16 x i8] c"\0Ajump index:=%d\00"
define void @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %19
5: ; preds = %0, %14
%6 = phi i64 [ %15, %14 ], [ 0, %0 ]
%7 = lshr i64 304129, %6
%8 = and i64 %7, 1
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %5
%11 = trunc i64 %6 to i32
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %11)
%13 = tail call i32 @pat_match(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %14
14: ; preds = %5, %10
%15 = add nuw nsw i64 %6, 1
%16 = tail call i32 @strlen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %15, %17
br i1 %18, label %5, label %19
19: ; preds = %14, %0
ret void
}