; LLVM IR from AlgoGenesis/C :: String Algorithms/BNDM 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 [64 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @preprocess(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 @bndm(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca [256 x i32], align 16
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = icmp sgt i32 %14, 32
  br i1 %15, label %16, label %18

16:                                               ; preds = %4
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef 32)
  br label %80

18:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 1024, ptr %9) #3
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = getelementptr inbounds [256 x i32], ptr %9, i64 0, i64 0
  call void @preprocess(ptr noundef %19, i32 noundef %20, ptr noundef %21)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = sub nsw i32 %22, 1
  store i32 %23, ptr %10, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %78, %18
  %25 = load i32, ptr %10, align 4, !tbaa !9
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %79

28:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = sub nsw i32 %29, 1
  store i32 %30, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 -1, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %31 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %31, ptr %13, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %68, %28
  %33 = load i32, ptr %12, align 4, !tbaa !9
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %38

35:                                               ; preds = %32
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = icmp sge i32 %36, 0
  br label %38

38:                                               ; preds = %35, %32
  %39 = phi i1 [ false, %32 ], [ %37, %35 ]
  br i1 %39, label %40, label %71

40:                                               ; preds = %38
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %41, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !11
  %46 = zext i8 %45 to i64
  %47 = getelementptr inbounds [256 x i32], ptr %9, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = load i32, ptr %12, align 4, !tbaa !9
  %50 = and i32 %49, %48
  store i32 %50, ptr %12, align 4, !tbaa !9
  %51 = load i32, ptr %10, align 4, !tbaa !9
  %52 = add nsw i32 %51, -1
  store i32 %52, ptr %10, align 4, !tbaa !9
  %53 = load i32, ptr %11, align 4, !tbaa !9
  %54 = add nsw i32 %53, -1
  store i32 %54, ptr %11, align 4, !tbaa !9
  %55 = load i32, ptr %12, align 4, !tbaa !9
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %68

57:                                               ; preds = %40
  %58 = load i32, ptr %11, align 4, !tbaa !9
  %59 = icmp slt i32 %58, 0
  br i1 %59, label %60, label %66

60:                                               ; preds = %57
  %61 = load i32, ptr %10, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %62)
  %64 = load i32, ptr %13, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %10, align 4, !tbaa !9
  br label %71

66:                                               ; preds = %57
  %67 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %67, ptr %13, align 4, !tbaa !9
  br label %68

68:                                               ; preds = %66, %40
  %69 = load i32, ptr %12, align 4, !tbaa !9
  %70 = shl i32 %69, 1
  store i32 %70, ptr %12, align 4, !tbaa !9
  br label %32, !llvm.loop !12

71:                                               ; preds = %60, %38
  %72 = load i32, ptr %12, align 4, !tbaa !9
  %73 = icmp eq i32 %72, 0
  br i1 %73, label %74, label %78

74:                                               ; preds = %71
  %75 = load i32, ptr %13, align 4, !tbaa !9
  %76 = load i32, ptr %8, align 4, !tbaa !9
  %77 = add nsw i32 %75, %76
  store i32 %77, ptr %10, align 4, !tbaa !9
  br label %78

78:                                               ; preds = %74, %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %24, !llvm.loop !14

79:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1024, ptr %9) #3
  br label %80

80:                                               ; preds = %79, %16
  ret void
}

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

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 = { "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, !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 [64 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @preprocess(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 @bndm(ptr nocapture noundef readonly %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca [256 x i32], align 16
  %6 = icmp sgt i32 %3, 32
  br i1 %6, label %7, label %9

7:                                                ; preds = %4
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 32)
  br label %39

9:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %5) #3
  call void @preprocess(ptr noundef %2, i32 noundef %3, ptr noundef nonnull %5)
  %10 = add nsw i32 %3, -1
  %.not = icmp sgt i32 %3, %1
  br i1 %.not, label %._crit_edge43, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %9
  %11 = icmp sgt i32 %3, 0
  br i1 %11, label %.preheader.us, label %.preheader

.preheader.us:                                    ; preds = %.preheader.lr.ph, %26
  %.02642.us = phi i32 [ %27, %26 ], [ %10, %.preheader.lr.ph ]
  %12 = sext i32 %.02642.us to i64
  br label %13

13:                                               ; preds = %.preheader.us, %29
  %indvars.iv = phi i64 [ %12, %.preheader.us ], [ %indvars.iv.next, %29 ]
  %.023.fr39.us = phi i32 [ -1, %.preheader.us ], [ %31, %29 ]
  %.038.us = phi i32 [ %.02642.us, %.preheader.us ], [ %30, %29 ]
  %.02537.us = phi i32 [ %10, %.preheader.us ], [ %20, %29 ]
  %14 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = zext i8 %15 to i64
  %17 = getelementptr inbounds [256 x i32], ptr %5, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !8
  %.fr45 = freeze i32 %18
  %19 = and i32 %.fr45, %.023.fr39.us
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %20 = add nsw i32 %.02537.us, -1
  %.not.us = icmp eq i32 %19, 0
  br i1 %.not.us, label %._crit_edge.us, label %21

21:                                               ; preds = %13
  %22 = icmp eq i32 %.02537.us, 0
  br i1 %22, label %.thread.us, label %29

.thread.us:                                       ; preds = %21
  %23 = trunc nsw i64 %indvars.iv to i32
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %23)
  %25 = add nsw i32 %.038.us, 1
  br label %26

26:                                               ; preds = %.thread.us, %._crit_edge.us
  %27 = phi i32 [ %25, %.thread.us ], [ %spec.select.us, %._crit_edge.us ]
  %28 = icmp slt i32 %27, %1
  br i1 %28, label %.preheader.us, label %._crit_edge43, !llvm.loop !10

29:                                               ; preds = %21
  %30 = trunc nsw i64 %indvars.iv.next to i32
  %31 = shl i32 %19, 1
  %32 = icmp ne i32 %31, 0
  %33 = icmp sgt i32 %.02537.us, 0
  %34 = select i1 %32, i1 %33, i1 false
  br i1 %34, label %13, label %._crit_edge.us, !llvm.loop !12

._crit_edge.us:                                   ; preds = %29, %13
  %35 = phi i32 [ 0, %13 ], [ %31, %29 ]
  %.1.us52 = phi i32 [ %.038.us, %13 ], [ %30, %29 ]
  %36 = trunc nsw i64 %indvars.iv.next to i32
  %37 = icmp eq i32 %35, 0
  %38 = add nsw i32 %.1.us52, %3
  %spec.select.us = select i1 %37, i32 %38, i32 %36
  br label %26

.preheader:                                       ; preds = %.preheader.lr.ph, %.preheader
  br label %.preheader

._crit_edge43:                                    ; preds = %26, %9
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %5) #3
  br label %39

39:                                               ; preds = %._crit_edge43, %7
  ret void
}

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

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


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