; LLVM IR from HarshCasper/NeoAlgo :: C-Plus-Plus/dp/K-Tree.ll (Z15Number_of_Pathsiiib)

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

@dp = external dso_local global [105 x [2 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z15Number_of_Pathsiiib(i32 noundef %0, i32 noundef %1, i32 noundef %2, i1 noundef zeroext %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  %12 = zext i1 %3 to i8
  store i8 %12, ptr %9, align 1, !tbaa !9
  %13 = load i32, ptr %6, align 4, !tbaa !5
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %21

15:                                               ; preds = %4
  %16 = load i8, ptr %9, align 1, !tbaa !9, !range !11, !noundef !12
  %17 = trunc i8 %16 to i1
  %18 = zext i1 %17 to i32
  %19 = icmp eq i32 %18, 1
  %20 = zext i1 %19 to i32
  store i32 %20, ptr %5, align 4
  br label %90

21:                                               ; preds = %4
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [105 x [2 x i32]], ptr @dp, i64 0, i64 %23
  %25 = load i8, ptr %9, align 1, !tbaa !9, !range !11, !noundef !12
  %26 = trunc i8 %25 to i1
  %27 = zext i1 %26 to i64
  %28 = getelementptr inbounds [2 x i32], ptr %24, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = icmp ne i32 %29, -1
  br i1 %30, label %31, label %40

31:                                               ; preds = %21
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [105 x [2 x i32]], ptr @dp, i64 0, i64 %33
  %35 = load i8, ptr %9, align 1, !tbaa !9, !range !11, !noundef !12
  %36 = trunc i8 %35 to i1
  %37 = zext i1 %36 to i64
  %38 = getelementptr inbounds [2 x i32], ptr %34, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  store i32 %39, ptr %5, align 4
  br label %90

40:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 1, ptr %11, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %78, %40
  %42 = load i32, ptr %11, align 4, !tbaa !5
  %43 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = icmp sle i32 %42, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %81

47:                                               ; preds = %41
  %48 = load i32, ptr %11, align 4, !tbaa !5
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = icmp sge i32 %48, %49
  br i1 %50, label %51, label %63

51:                                               ; preds = %47
  %52 = load i32, ptr %10, align 4, !tbaa !5
  %53 = srem i32 %52, 1000000007
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = load i32, ptr %11, align 4, !tbaa !5
  %56 = sub nsw i32 %54, %55
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = call noundef i32 @_Z15Number_of_Pathsiiib(i32 noundef %56, i32 noundef %57, i32 noundef %58, i1 noundef zeroext true)
  %60 = srem i32 %59, 1000000007
  %61 = add nsw i32 %53, %60
  %62 = srem i32 %61, 1000000007
  store i32 %62, ptr %10, align 4, !tbaa !5
  br label %77

63:                                               ; preds = %47
  %64 = load i32, ptr %10, align 4, !tbaa !5
  %65 = srem i32 %64, 1000000007
  %66 = load i32, ptr %6, align 4, !tbaa !5
  %67 = load i32, ptr %11, align 4, !tbaa !5
  %68 = sub nsw i32 %66, %67
  %69 = load i32, ptr %7, align 4, !tbaa !5
  %70 = load i32, ptr %8, align 4, !tbaa !5
  %71 = load i8, ptr %9, align 1, !tbaa !9, !range !11, !noundef !12
  %72 = trunc i8 %71 to i1
  %73 = call noundef i32 @_Z15Number_of_Pathsiiib(i32 noundef %68, i32 noundef %69, i32 noundef %70, i1 noundef zeroext %72)
  %74 = srem i32 %73, 1000000007
  %75 = add nsw i32 %65, %74
  %76 = srem i32 %75, 1000000007
  store i32 %76, ptr %10, align 4, !tbaa !5
  br label %77

77:                                               ; preds = %63, %51
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %11, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %11, align 4, !tbaa !5
  br label %41, !llvm.loop !13

81:                                               ; preds = %46
  %82 = load i32, ptr %10, align 4, !tbaa !5
  %83 = load i32, ptr %6, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [105 x [2 x i32]], ptr @dp, i64 0, i64 %84
  %86 = load i8, ptr %9, align 1, !tbaa !9, !range !11, !noundef !12
  %87 = trunc i8 %86 to i1
  %88 = zext i1 %87 to i64
  %89 = getelementptr inbounds [2 x i32], ptr %85, i64 0, i64 %88
  store i32 %82, ptr %89, align 4, !tbaa !5
  store i32 %82, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %90

90:                                               ; preds = %81, %31, %15
  %91 = load i32, ptr %5, align 4
  ret i32 %91
}

; 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 nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

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

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


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

@dp = external dso_local local_unnamed_addr global [105 x [2 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z15Number_of_Pathsiiib(i32 noundef %0, i32 noundef %1, i32 noundef %2, i1 noundef zeroext %3) local_unnamed_addr #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  %7 = icmp eq i32 %0, 0
  br i1 %7, label %8, label %10

8:                                                ; preds = %4
  %9 = zext i1 %3 to i32
  br label %27

10:                                               ; preds = %4
  %11 = sext i32 %0 to i64
  %12 = zext i1 %3 to i64
  %13 = getelementptr inbounds [105 x [2 x i32]], ptr @dp, i64 0, i64 %11, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %.not = icmp eq i32 %14, -1
  br i1 %.not, label %.preheader, label %27

.preheader:                                       ; preds = %10
  %15 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %.not2325 = icmp slt i32 %16, 1
  br i1 %.not2325, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.017.lcssa = phi i32 [ 0, %.preheader ], [ %.1, %.lr.ph ]
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [105 x [2 x i32]], ptr @dp, i64 0, i64 %18, i64 %12
  store i32 %.017.lcssa, ptr %19, align 4, !tbaa !5
  br label %27

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.027 = phi i32 [ %24, %.lr.ph ], [ 1, %.preheader ]
  %.01726 = phi i32 [ %.1, %.lr.ph ], [ 0, %.preheader ]
  %.not24 = icmp sge i32 %.027, %2
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sub nsw i32 %20, %.027
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %. = or i1 %.not24, %3
  %23 = call noundef i32 @_Z15Number_of_Pathsiiib(i32 noundef %21, i32 noundef %22, i32 noundef %2, i1 noundef zeroext %.)
  %.pn = srem i32 %23, 1000000007
  %.1.in = add nsw i32 %.pn, %.01726
  %.1 = srem i32 %.1.in, 1000000007
  %24 = add nuw nsw i32 %.027, 1
  %25 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %.not23.not = icmp slt i32 %.027, %26
  br i1 %.not23.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

27:                                               ; preds = %10, %._crit_edge, %8
  %.018 = phi i32 [ %9, %8 ], [ %.017.lcssa, %._crit_edge ], [ %14, %10 ]
  ret i32 %.018
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

attributes #0 = { 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 #1 = { inlinehint 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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