#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*/ printf(char *, int, char *);
int strlen(char *);
void pat_match(char *txt, char *pat, int start_index) {
  int i = 0, j = 0;
  for (i = start_index; i < strlen(txt) && j < strlen(pat); i++) {
    if (txt[i] == pat[j]) {
      j++;
    } else {
      break;
    }
  }
  if (j == strlen(pat)) {
    printf("\nINFO: Pattern found at index:=%d in string:=%s", start_index,
           txt);
  }
}


x86 assembly (clang, -O0):
<pat_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x24(%rbp),%ecx
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x1d(%rbp)
jge    1184 <pat_match+0x64>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
setl   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1194 <pat_match+0x74>
jmp    11da <pat_match+0xba>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x10(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    11c2 <pat_match+0xa2>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c7 <pat_match+0xa7>
jmp    11da <pat_match+0xba>
jmp    11cc <pat_match+0xac>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1147 <pat_match+0x27>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jne    1209 <pat_match+0xe9>
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rdx
lea    0xdfc(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pat_match>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%r15
call   1030 <strlen@plt>
xor    %ebx,%ebx
cmp    %r14d,%eax
jle    1181 <pat_match+0x61>
movslq %r14d,%rbp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    1181 <pat_match+0x61>
movzbl (%r15,%rbp,1),%eax
cmp    (%r12,%rbx,1),%al
jne    1181 <pat_match+0x61>
add    $0x1,%rbx
add    $0x1,%rbp
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1150 <pat_match+0x30>
mov    %r12,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebx
jne    11a7 <pat_match+0x87>
lea    0xe6c(%rip),%rdi
mov    %r14d,%esi
mov    %r15,%rdx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [48 x i8] c"\0AINFO: Pattern found at index:=%d in string:=%s\00"
define void @pat_match(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%9 = load i32, i32* %6
store i32 %9, i32* %7
br label %10
10: ; preds = %41, %3
%11 = load i32, i32* %7
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i32, i32* %8
%17 = load i8*, i8** %5
%18 = call i32 @strlen(i8* %17)
%19 = icmp slt i32 %16, %18
br label %20
20: ; preds = %15, %10
%21 = phi i1 [ false, %10 ], [ %19, %15 ]
br i1 %21, label %22, label %44
22: ; preds = %20
%23 = load i8*, i8** %4
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = load i8*, i8** %5
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %28, %34
br i1 %35, label %36, label %39
36: ; preds = %22
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %40
39: ; preds = %22
br label %44
40: ; preds = %36
br label %41
41: ; preds = %40
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %10
44: ; preds = %39, %20
%45 = load i32, i32* %8
%46 = load i8*, i8** %5
%47 = call i32 @strlen(i8* %46)
%48 = icmp eq i32 %45, %47
br i1 %48, label %49, label %53
49: ; preds = %44
%50 = load i32, i32* %6
%51 = load i8*, i8** %4
%52 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %50, i8* %51)
br label %53
53: ; preds = %49, %44
ret void
}

LLVM IR (-O2):
@.str = [48 x i8] c"\0AINFO: Pattern found at index:=%d in string:=%s\00"
define void @pat_match(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, %2
br i1 %5, label %6, label %29
6: ; preds = %3
%7 = sext i32 %2 to i64
br label %8
8: ; preds = %6, %20
%9 = phi i64 [ %7, %6 ], [ %22, %20 ]
%10 = phi i64 [ 0, %6 ], [ %21, %20 ]
%11 = tail call i32 @strlen(i8* %1)
%12 = sext i32 %11 to i64
%13 = icmp slt i64 %10, %12
br i1 %13, label %14, label %26
14: ; preds = %8
%15 = getelementptr inbounds i8, i8* %0, i64 %9
%16 = load i8, i8* %15
%17 = getelementptr inbounds i8, i8* %1, i64 %10
%18 = load i8, i8* %17
%19 = icmp eq i8 %16, %18
br i1 %19, label %20, label %26
20: ; preds = %14
%21 = add nuw nsw i64 %10, 1
%22 = add nsw i64 %9, 1
%23 = tail call i32 @strlen(i8* %0)
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %8, label %26
26: ; preds = %20, %14, %8
%27 = phi i64 [ %10, %8 ], [ %10, %14 ], [ %21, %20 ]
%28 = trunc i64 %27 to i32
br label %29
29: ; preds = %26, %3
%30 = phi i32 [ 0, %3 ], [ %28, %26 ]
%31 = tail call i32 @strlen(i8* %1)
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = tail call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %2, i8* %0)
br label %35
35: ; preds = %33, %29
ret void
}