; LLVM IR from VAR-solutions/Algorithms :: Searching/string search/boyer-moore-horspool/cpp/bm-horspool.ll (Z11bm_horspoolPhPKcjj)

; 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.std::array" = type { [256 x i32] }

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z11bm_horspoolPhPKcjj(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %"struct.std::array", align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i8, align 1
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  %15 = load i32, ptr %9, align 4, !tbaa !9
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = icmp ugt i32 %15, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %4
  store ptr null, ptr %5, align 8
  br label %97

19:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 1024, ptr %10) #6
  %20 = call noundef ptr @_ZNSt5arrayIjLm256EE5beginEv(ptr noundef nonnull align 4 dereferenceable(1024) %10) #7
  %21 = call noundef ptr @_ZNSt5arrayIjLm256EE3endEv(ptr noundef nonnull align 4 dereferenceable(1024) %10) #7
  call void @_ZSt4fillIPjjEvT_S1_RKT0_(ptr noundef %20, ptr noundef %21, ptr noundef nonnull align 4 dereferenceable(4) %9)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %40, %19
  %23 = load i32, ptr %11, align 4, !tbaa !9
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = sub i32 %24, 1
  %26 = icmp ult i32 %23, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %43

28:                                               ; preds = %22
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = sub i32 %29, %30
  %32 = sub i32 %31, 1
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load i32, ptr %11, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds i8, ptr %33, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = sext i8 %37 to i64
  %39 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5arrayIjLm256EEixEm(ptr noundef nonnull align 4 dereferenceable(1024) %10, i64 noundef %38) #6
  store i32 %32, ptr %39, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %28
  %41 = load i32, ptr %11, align 4, !tbaa !9
  %42 = add i32 %41, 1
  store i32 %42, ptr %11, align 4, !tbaa !9
  br label %22, !llvm.loop !12

43:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %94, %43
  %45 = load i32, ptr %12, align 4, !tbaa !9
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = sub i32 %46, %47
  %49 = icmp ule i32 %45, %48
  br i1 %49, label %50, label %95

50:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #6
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load i32, ptr %12, align 4, !tbaa !9
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = add i32 %52, %53
  %55 = sub i32 %54, 1
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds i8, ptr %51, i64 %56
  %58 = load i8, ptr %57, align 1, !tbaa !11
  store i8 %58, ptr %13, align 1, !tbaa !11
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = sub i32 %60, 1
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds i8, ptr %59, i64 %62
  %64 = load i8, ptr %63, align 1, !tbaa !11
  %65 = sext i8 %64 to i32
  %66 = load i8, ptr %13, align 1, !tbaa !11
  %67 = zext i8 %66 to i32
  %68 = icmp eq i32 %65, %67
  br i1 %68, label %69, label %85

69:                                               ; preds = %50
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = load i32, ptr %12, align 4, !tbaa !9
  %73 = zext i32 %72 to i64
  %74 = getelementptr inbounds i8, ptr %71, i64 %73
  %75 = load i32, ptr %9, align 4, !tbaa !9
  %76 = sub i32 %75, 1
  %77 = zext i32 %76 to i64
  %78 = call i32 @memcmp(ptr noundef %70, ptr noundef %74, i64 noundef %77) #8
  %79 = icmp eq i32 %78, 0
  br i1 %79, label %80, label %85

80:                                               ; preds = %69
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = load i32, ptr %12, align 4, !tbaa !9
  %83 = zext i32 %82 to i64
  %84 = getelementptr inbounds i8, ptr %81, i64 %83
  store ptr %84, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %92

85:                                               ; preds = %69, %50
  %86 = load i8, ptr %13, align 1, !tbaa !11
  %87 = zext i8 %86 to i64
  %88 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5arrayIjLm256EEixEm(ptr noundef nonnull align 4 dereferenceable(1024) %10, i64 noundef %87) #6
  %89 = load i32, ptr %88, align 4, !tbaa !9
  %90 = load i32, ptr %12, align 4, !tbaa !9
  %91 = add i32 %90, %89
  store i32 %91, ptr %12, align 4, !tbaa !9
  store i32 0, ptr %14, align 4
  br label %92

92:                                               ; preds = %85, %80
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #6
  %93 = load i32, ptr %14, align 4
  switch i32 %93, label %96 [
    i32 0, label %94
  ]

94:                                               ; preds = %92
  br label %44, !llvm.loop !14

95:                                               ; preds = %44
  store ptr null, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %96

96:                                               ; preds = %95, %92
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 1024, ptr %10) #6
  br label %97

97:                                               ; preds = %96, %18
  %98 = load ptr, ptr %5, align 8
  ret ptr %98
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPjjEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) #2

; Function Attrs: mustprogress nounwind willreturn memory(none) uwtable
declare dso_local noundef ptr @_ZNSt5arrayIjLm256EE5beginEv(ptr noundef nonnull align 4 dereferenceable(1024)) #3 align 2

; Function Attrs: mustprogress nounwind willreturn memory(none) uwtable
declare dso_local noundef ptr @_ZNSt5arrayIjLm256EE3endEv(ptr noundef nonnull align 4 dereferenceable(1024)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5arrayIjLm256EEixEm(ptr noundef nonnull align 4 dereferenceable(1024), i64 noundef) #4 align 2

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #5

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress 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 #3 = { mustprogress nounwind willreturn memory(none) 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 #4 = { mustprogress 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 #5 = { nounwind willreturn memory(read) "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(none) }
attributes #8 = { nounwind willreturn memory(read) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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"

%"struct.std::array" = type { [256 x i32] }

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z11bm_horspoolPhPKcjj(ptr noundef readonly %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca i32, align 4
  %6 = alloca %"struct.std::array", align 4
  store i32 %3, ptr %5, align 4, !tbaa !5
  %7 = icmp ugt i32 %3, %2
  br i1 %7, label %47, label %8

8:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %6) #6
  %9 = call noundef ptr @_ZNSt5arrayIjLm256EE5beginEv(ptr noundef nonnull align 4 dereferenceable(1024) %6) #7
  %10 = call noundef ptr @_ZNSt5arrayIjLm256EE3endEv(ptr noundef nonnull align 4 dereferenceable(1024) %6) #7
  call void @_ZSt4fillIPjjEvT_S1_RKT0_(ptr noundef %9, ptr noundef %10, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %.not30 = icmp eq i32 %11, 1
  br i1 %.not30, label %.preheader.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %8, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %8 ]
  %12 = phi i32 [ %20, %.lr.ph ], [ %11, %8 ]
  %13 = trunc nuw i64 %indvars.iv to i32
  %14 = xor i32 %13, -1
  %15 = add i32 %12, %14
  %16 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = sext i8 %17 to i64
  %19 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5arrayIjLm256EEixEm(ptr noundef nonnull align 4 dereferenceable(1024) %6, i64 noundef %18) #6
  store i32 %15, ptr %19, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = add i32 %20, -1
  %22 = zext i32 %21 to i64
  %23 = icmp ult i64 %indvars.iv.next, %22
  br i1 %23, label %.lr.ph, label %.preheader.preheader, !llvm.loop !10

.preheader.preheader:                             ; preds = %.lr.ph, %8
  %.ph = phi i32 [ 1, %8 ], [ %20, %.lr.ph ]
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %40
  %24 = phi i32 [ %45, %40 ], [ %.ph, %.preheader.preheader ]
  %.02129 = phi i32 [ %44, %40 ], [ 0, %.preheader.preheader ]
  %25 = add i32 %24, -1
  %26 = add i32 %25, %.02129
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %0, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !9
  %30 = zext i32 %25 to i64
  %31 = getelementptr inbounds i8, ptr %1, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = sext i8 %32 to i32
  %34 = zext i8 %29 to i32
  %35 = icmp eq i32 %33, %34
  br i1 %35, label %36, label %40

36:                                               ; preds = %.preheader
  %37 = zext i32 %.02129 to i64
  %38 = getelementptr inbounds i8, ptr %0, i64 %37
  %bcmp = call i32 @bcmp(ptr nonnull %1, ptr %38, i64 %30)
  %39 = icmp eq i32 %bcmp, 0
  br i1 %39, label %.thread, label %40

40:                                               ; preds = %.preheader, %36
  %41 = zext i8 %29 to i64
  %42 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5arrayIjLm256EEixEm(ptr noundef nonnull align 4 dereferenceable(1024) %6, i64 noundef %41) #6
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = add i32 %43, %.02129
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = sub i32 %2, %45
  %.not = icmp ugt i32 %44, %46
  br i1 %.not, label %.thread, label %.preheader, !llvm.loop !12

.thread:                                          ; preds = %36, %40
  %.2 = phi ptr [ null, %40 ], [ %38, %36 ]
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %6) #6
  br label %47

47:                                               ; preds = %4, %.thread
  %.3 = phi ptr [ %.2, %.thread ], [ null, %4 ]
  ret ptr %.3
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPjjEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare dso_local noundef ptr @_ZNSt5arrayIjLm256EE5beginEv(ptr noundef nonnull align 4 dereferenceable(1024)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare dso_local noundef ptr @_ZNSt5arrayIjLm256EE3endEv(ptr noundef nonnull align 4 dereferenceable(1024)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5arrayIjLm256EEixEm(ptr noundef nonnull align 4 dereferenceable(1024), i64 noundef) local_unnamed_addr #4 align 2

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

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #5

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress 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 #3 = { mustprogress nofree nosync nounwind willreturn memory(none) 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 #4 = { mustprogress 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 #5 = { nofree nounwind willreturn memory(argmem: read) }
attributes #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(none) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass