; LLVM IR from davidesantangelo/krep :: krep (select_search_algorithm)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.search_params = type { ptr, i64, ptr, ptr, i64, i8, i8, i8, i8, i8, i8, ptr, ptr, i64 }

@force_no_simd = external hidden global i8, align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @boyer_moore_search(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @regex_search(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @kmp_search(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @select_search_algorithm(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.search_params, ptr %8, i32 0, i32 6
  %10 = load i8, ptr %9, align 1, !tbaa !9, !range !13, !noundef !14
  %11 = trunc i8 %10 to i1
  br i1 %11, label %12, label %13

12:                                               ; preds = %1
  store ptr @regex_search, ptr %2, align 8
  br label %78

13:                                               ; preds = %1
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.search_params, ptr %14, i32 0, i32 4
  %16 = load i64, ptr %15, align 8, !tbaa !15
  %17 = icmp ugt i64 %16, 1
  br i1 %17, label %18, label %24

18:                                               ; preds = %13
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.search_params, ptr %19, i32 0, i32 6
  %21 = load i8, ptr %20, align 1, !tbaa !9, !range !13, !noundef !14
  %22 = trunc i8 %21 to i1
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  store ptr @aho_corasick_search, ptr %2, align 8
  br label %78

24:                                               ; preds = %18, %13
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  %25 = load i8, ptr @force_no_simd, align 1, !tbaa !16, !range !13, !noundef !14
  %26 = trunc i8 %25 to i1
  br i1 %26, label %33, label %27

27:                                               ; preds = %24
  br i1 false, label %28, label %33

28:                                               ; preds = %27
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.search_params, ptr %29, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !17
  %32 = icmp ule i64 %31, 0
  br label %33

33:                                               ; preds = %28, %27, %24
  %34 = phi i1 [ false, %27 ], [ false, %24 ], [ %32, %28 ]
  %35 = zext i1 %34 to i8
  store i8 %35, ptr %4, align 1, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 4, ptr %5, align 8, !tbaa !18
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.search_params, ptr %36, i32 0, i32 1
  %38 = load i64, ptr %37, align 8, !tbaa !17
  %39 = icmp eq i64 %38, 1
  br i1 %39, label %40, label %41

40:                                               ; preds = %33
  store ptr @memchr_search, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %77

41:                                               ; preds = %33
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.search_params, ptr %42, i32 0, i32 1
  %44 = load i64, ptr %43, align 8, !tbaa !17
  %45 = icmp ult i64 %44, 4
  br i1 %45, label %46, label %56

46:                                               ; preds = %41
  %47 = load i8, ptr %4, align 1, !tbaa !16, !range !13, !noundef !14
  %48 = trunc i8 %47 to i1
  br i1 %48, label %49, label %55

49:                                               ; preds = %46
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.search_params, ptr %50, i32 0, i32 5
  %52 = load i8, ptr %51, align 8, !tbaa !19, !range !13, !noundef !14
  %53 = trunc i8 %52 to i1
  br i1 %53, label %54, label %55

54:                                               ; preds = %49
  store ptr @memchr_short_search, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %77

55:                                               ; preds = %49, %46
  store ptr @memchr_short_search, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %77

56:                                               ; preds = %41
  br label %57

57:                                               ; preds = %56
  %58 = load i8, ptr %4, align 1, !tbaa !16, !range !13, !noundef !14
  %59 = trunc i8 %58 to i1
  br i1 %59, label %60, label %61

60:                                               ; preds = %57
  br label %61

61:                                               ; preds = %60, %57
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 8, ptr %7, align 8, !tbaa !18
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.search_params, ptr %62, i32 0, i32 1
  %64 = load i64, ptr %63, align 8, !tbaa !17
  %65 = icmp ult i64 %64, 8
  br i1 %65, label %66, label %75

66:                                               ; preds = %61
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.search_params, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !20
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.search_params, ptr %70, i32 0, i32 1
  %72 = load i64, ptr %71, align 8, !tbaa !17
  %73 = call zeroext i1 @is_repetitive_pattern(ptr noundef %69, i64 noundef %72)
  br i1 %73, label %74, label %75

74:                                               ; preds = %66
  store ptr @kmp_search, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %76

75:                                               ; preds = %66, %61
  store ptr @boyer_moore_search, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %76

76:                                               ; preds = %75, %74
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %77

77:                                               ; preds = %76, %55, %54, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  br label %78

78:                                               ; preds = %77, %23, %12
  %79 = load ptr, ptr %2, align 8
  ret ptr %79
}

declare i64 @aho_corasick_search(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @memchr_search(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @memchr_short_search(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @is_repetitive_pattern(ptr noundef, i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 41}
!10 = !{!"search_params", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !12, i64 40, !12, i64 41, !12, i64 42, !12, i64 43, !12, i64 44, !12, i64 45, !6, i64 48, !6, i64 56, !11, i64 64}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!10, !11, i64 32}
!16 = !{!12, !12, i64 0}
!17 = !{!10, !11, i64 8}
!18 = !{!11, !11, i64 0}
!19 = !{!10, !12, i64 40}
!20 = !{!10, !6, i64 0}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind uwtable
declare dso_local i64 @boyer_moore_search(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @regex_search(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @kmp_search(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local noundef nonnull ptr @select_search_algorithm(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 41
  %3 = load i8, ptr %2, align 1, !tbaa !5, !range !12, !noundef !13
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %21, label %5

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = load i64, ptr %6, align 8, !tbaa !14
  %8 = icmp ugt i64 %7, 1
  br i1 %8, label %21, label %9

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load i64, ptr %10, align 8, !tbaa !15
  %12 = icmp eq i64 %11, 1
  br i1 %12, label %21, label %13

13:                                               ; preds = %9
  %14 = icmp ult i64 %11, 4
  br i1 %14, label %21, label %15

15:                                               ; preds = %13
  %16 = icmp ult i64 %11, 8
  br i1 %16, label %17, label %20

17:                                               ; preds = %15
  %18 = load ptr, ptr %0, align 8, !tbaa !16
  %19 = tail call zeroext i1 @is_repetitive_pattern(ptr noundef %18, i64 noundef %11)
  br i1 %19, label %21, label %20

20:                                               ; preds = %17, %15
  br label %21

21:                                               ; preds = %9, %13, %17, %20, %5, %1
  %.2 = phi ptr [ @regex_search, %1 ], [ @aho_corasick_search, %5 ], [ @memchr_search, %9 ], [ @memchr_short_search, %13 ], [ @boyer_moore_search, %20 ], [ @kmp_search, %17 ]
  ret ptr %.2
}

declare i64 @aho_corasick_search(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @memchr_search(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @memchr_short_search(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @is_repetitive_pattern(ptr noundef, i64 noundef) local_unnamed_addr #0

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !11, i64 41}
!6 = !{!"search_params", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !11, i64 40, !11, i64 41, !11, i64 42, !11, i64 43, !11, i64 44, !11, i64 45, !7, i64 48, !7, i64 56, !10, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!6, !10, i64 32}
!15 = !{!6, !10, i64 8}
!16 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass