; LLVM IR from MostafaTwfiq/C-DataStructures-And-Algorithms :: DataStructure/Tables/Sources (HashMap)

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

; 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
define dso_local i32 @calBPrime(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = sub nsw i32 %7, 1
  store i32 %8, ptr %4, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %44, %1
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = icmp sge i32 %10, 1
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  store i32 2, ptr %5, align 4
  br label %47

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = sdiv i32 %14, 2
  store i32 %15, ptr %6, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %38, %13
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = icmp sgt i32 %17, 1
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  store i32 5, ptr %5, align 4
  br label %41

20:                                               ; preds = %16
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = srem i32 %21, %22
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %20
  store i32 5, ptr %5, align 4
  br label %41

26:                                               ; preds = %20
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = srem i32 %27, %28
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %36

31:                                               ; preds = %26
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = icmp eq i32 %32, 2
  br i1 %33, label %34, label %36

34:                                               ; preds = %31
  %35 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %35, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %41

36:                                               ; preds = %31, %26
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = add nsw i32 %39, -1
  store i32 %40, ptr %6, align 4, !tbaa !5
  br label %16, !llvm.loop !9

41:                                               ; preds = %34, %25, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %42 = load i32, ptr %5, align 4
  switch i32 %42, label %47 [
    i32 5, label %43
  ]

43:                                               ; preds = %41
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = add nsw i32 %45, -1
  store i32 %46, ptr %4, align 4, !tbaa !5
  br label %9, !llvm.loop !11

47:                                               ; preds = %41, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %48 = load i32, ptr %5, align 4
  switch i32 %48, label %52 [
    i32 2, label %49
    i32 1, label %50
  ]

49:                                               ; preds = %47
  store i32 1, ptr %2, align 4
  br label %50

50:                                               ; preds = %49, %47
  %51 = load i32, ptr %2, align 4
  ret i32 %51

52:                                               ; preds = %47
  unreachable
}

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


; 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: nofree norecurse nosync nounwind memory(none) uwtable
define dso_local i32 @calBPrime(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp slt i32 %0, 2
  br i1 %2, label %.thread, label %.lr.ph30

.lr.ph30:                                         ; preds = %1, %._crit_edge
  %.01728.in = phi i32 [ %.01728, %._crit_edge ], [ %0, %1 ]
  %.01728 = add nsw i32 %.01728.in, -1
  %3 = icmp ugt i32 %.01728, 3
  br i1 %3, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.lr.ph30
  %4 = lshr i32 %.01728, 1
  %5 = urem i32 %.01728, %4
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %._crit_edge, label %.lr.ph38

.lr.ph:                                           ; preds = %.lr.ph38
  %7 = add nsw i32 %.02537, -1
  %8 = urem i32 %.01728, %7
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %._crit_edge, label %.lr.ph38, !llvm.loop !5

.lr.ph38:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %.02537 = phi i32 [ %7, %.lr.ph ], [ %4, %.lr.ph.preheader ]
  %10 = icmp eq i32 %.02537, 2
  br i1 %10, label %.thread, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph.preheader, %.lr.ph30
  %11 = icmp slt i32 %.01728.in, 3
  br i1 %11, label %.thread, label %.lr.ph30, !llvm.loop !7

.thread:                                          ; preds = %._crit_edge, %.lr.ph38, %1
  %spec.select = phi i32 [ 1, %1 ], [ %.01728, %.lr.ph38 ], [ 1, %._crit_edge ]
  ret i32 %spec.select
}

attributes #0 = { nofree norecurse nosync nounwind 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" }

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


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