; LLVM IR from AlgoGenesis/C :: String Algorithms/Boyer Moore Algorithm (Program)

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

@.str = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @computeBadChar(ptr noundef, i32 noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @boyerMoore(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca [256 x i32], align 16
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = call i64 @strlen(ptr noundef %10) #5
  %12 = trunc i64 %11 to i32
  store i32 %12, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call i64 @strlen(ptr noundef %13) #5
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1024, ptr %7) #4
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = getelementptr inbounds [256 x i32], ptr %7, i64 0, i64 0
  call void @computeBadChar(ptr noundef %16, i32 noundef %17, ptr noundef %18)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %113, %2
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = sub nsw i32 %21, %22
  %24 = icmp sle i32 %20, %23
  br i1 %24, label %25, label %114

25:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = sub nsw i32 %26, 1
  store i32 %27, ptr %9, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %49, %25
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = icmp sge i32 %29, 0
  br i1 %30, label %31, label %47

31:                                               ; preds = %28
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i8, ptr %32, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = sext i8 %36 to i32
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = add nsw i32 %39, %40
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr %38, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !11
  %45 = sext i8 %44 to i32
  %46 = icmp eq i32 %37, %45
  br label %47

47:                                               ; preds = %31, %28
  %48 = phi i1 [ false, %28 ], [ %46, %31 ]
  br i1 %48, label %49, label %52

49:                                               ; preds = %47
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = add nsw i32 %50, -1
  store i32 %51, ptr %9, align 4, !tbaa !9
  br label %28, !llvm.loop !12

52:                                               ; preds = %47
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = icmp slt i32 %53, 0
  br i1 %54, label %55, label %81

55:                                               ; preds = %52
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %56)
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = add nsw i32 %58, %59
  %61 = load i32, ptr %5, align 4, !tbaa !9
  %62 = icmp slt i32 %60, %61
  br i1 %62, label %63, label %76

63:                                               ; preds = %55
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = load i32, ptr %8, align 4, !tbaa !9
  %67 = load i32, ptr %6, align 4, !tbaa !9
  %68 = add nsw i32 %66, %67
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i8, ptr %65, i64 %69
  %71 = load i8, ptr %70, align 1, !tbaa !11
  %72 = sext i8 %71 to i64
  %73 = getelementptr inbounds [256 x i32], ptr %7, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !9
  %75 = sub nsw i32 %64, %74
  br label %77

76:                                               ; preds = %55
  br label %77

77:                                               ; preds = %76, %63
  %78 = phi i32 [ %75, %63 ], [ 1, %76 ]
  %79 = load i32, ptr %8, align 4, !tbaa !9
  %80 = add nsw i32 %79, %78
  store i32 %80, ptr %8, align 4, !tbaa !9
  br label %113

81:                                               ; preds = %52
  %82 = load i32, ptr %9, align 4, !tbaa !9
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = load i32, ptr %8, align 4, !tbaa !9
  %85 = load i32, ptr %9, align 4, !tbaa !9
  %86 = add nsw i32 %84, %85
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds i8, ptr %83, i64 %87
  %89 = load i8, ptr %88, align 1, !tbaa !11
  %90 = sext i8 %89 to i64
  %91 = getelementptr inbounds [256 x i32], ptr %7, i64 0, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !9
  %93 = sub nsw i32 %82, %92
  %94 = icmp sgt i32 %93, 1
  br i1 %94, label %95, label %108

95:                                               ; preds = %81
  %96 = load i32, ptr %9, align 4, !tbaa !9
  %97 = load ptr, ptr %3, align 8, !tbaa !5
  %98 = load i32, ptr %8, align 4, !tbaa !9
  %99 = load i32, ptr %9, align 4, !tbaa !9
  %100 = add nsw i32 %98, %99
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds i8, ptr %97, i64 %101
  %103 = load i8, ptr %102, align 1, !tbaa !11
  %104 = sext i8 %103 to i64
  %105 = getelementptr inbounds [256 x i32], ptr %7, i64 0, i64 %104
  %106 = load i32, ptr %105, align 4, !tbaa !9
  %107 = sub nsw i32 %96, %106
  br label %109

108:                                              ; preds = %81
  br label %109

109:                                              ; preds = %108, %95
  %110 = phi i32 [ %107, %95 ], [ 1, %108 ]
  %111 = load i32, ptr %8, align 4, !tbaa !9
  %112 = add nsw i32 %111, %110
  store i32 %112, ptr %8, align 4, !tbaa !9
  br label %113

113:                                              ; preds = %109, %77
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %19, !llvm.loop !14

114:                                              ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 1024, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

declare i32 @printf(ptr noundef, ...) #3

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 = { nounwind }
attributes #5 = { 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/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"

@.str = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @computeBadChar(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @boyerMoore(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca [256 x i32], align 16
  %4 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #5
  %5 = trunc i64 %4 to i32
  %6 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #5
  %7 = trunc i64 %6 to i32
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %3) #6
  call void @computeBadChar(ptr noundef %1, i32 noundef %7, ptr noundef nonnull %3)
  %8 = sub nsw i32 %5, %7
  %.not37 = icmp slt i32 %8, 0
  br i1 %.not37, label %._crit_edge, label %.preheader.preheader

.preheader.preheader:                             ; preds = %2
  %sext = shl i64 %6, 32
  %9 = ashr exact i64 %sext, 32
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %39
  %.03338 = phi i32 [ %.1, %39 ], [ 0, %.preheader.preheader ]
  %10 = sext i32 %.03338 to i64
  %invariant.gep = getelementptr i8, ptr %0, i64 %10
  br label %11

11:                                               ; preds = %.preheader, %13
  %indvars.iv = phi i64 [ %9, %.preheader ], [ %indvars.iv.next, %13 ]
  %12 = icmp sgt i64 %indvars.iv, 0
  br i1 %12, label %13, label %18

13:                                               ; preds = %11
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %14 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %gep = getelementptr i8, ptr %invariant.gep, i64 %indvars.iv.next
  %16 = load i8, ptr %gep, align 1, !tbaa !5
  %17 = icmp eq i8 %15, %16
  br i1 %17, label %11, label %.critedge, !llvm.loop !8

18:                                               ; preds = %11
  %19 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %.03338)
  %20 = add nsw i32 %.03338, %7
  %21 = icmp slt i32 %20, %5
  br i1 %21, label %22, label %39

22:                                               ; preds = %18
  %23 = sext i32 %20 to i64
  %24 = getelementptr inbounds i8, ptr %0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %26 = sext i8 %25 to i64
  %27 = getelementptr inbounds [256 x i32], ptr %3, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !10
  %29 = sub nsw i32 %7, %28
  br label %39

.critedge:                                        ; preds = %13
  %30 = trunc nsw i64 %indvars.iv.next to i32
  %31 = add nsw i32 %.03338, %30
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i8, ptr %0, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !5
  %35 = sext i8 %34 to i64
  %36 = getelementptr inbounds [256 x i32], ptr %3, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !10
  %38 = sub nsw i32 %30, %37
  %spec.select = call i32 @llvm.smax.i32(i32 %38, i32 1)
  br label %39

39:                                               ; preds = %22, %18, %.critedge
  %.pn = phi i32 [ %spec.select, %.critedge ], [ %29, %22 ], [ 1, %18 ]
  %.1 = add nsw i32 %.pn, %.03338
  %.not = icmp sgt i32 %.1, %8
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !12

._crit_edge:                                      ; preds = %39, %2
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %3) #6
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(argmem: 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 #3 = { nofree nounwind "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind willreturn memory(read) }
attributes #6 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = distinct !{!12, !9}


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