; LLVM IR from ShahjalalShohag/code-library :: Number Theory/Power Tower.ll (Z3phix)

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

%"class.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<long long, std::pair<const long long, long long>, std::_Select1st<std::pair<const long long, long long>>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, std::pair<const long long, long long>, std::_Select1st<std::pair<const long long, long long>>, std::less<long long>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }

@mp = external dso_local global %"class.std::map", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z3phix(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  %7 = call noundef i64 @_ZNKSt3mapIxxSt4lessIxESaISt4pairIKxxEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48) @mp, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %8 = icmp ne i64 %7, 0
  br i1 %8, label %9, label %12

9:                                                ; preds = %1
  %10 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @mp, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %11 = load i64, ptr %10, align 8, !tbaa !5
  store i64 %11, ptr %2, align 8
  br label %61

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

15:                                               ; preds = %45, %12
  %16 = load i64, ptr %6, align 8, !tbaa !5
  %17 = load i64, ptr %6, align 8, !tbaa !5
  %18 = mul nsw i64 %16, %17
  %19 = load i64, ptr %5, align 8, !tbaa !5
  %20 = icmp sle i64 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %48

22:                                               ; preds = %15
  %23 = load i64, ptr %5, align 8, !tbaa !5
  %24 = load i64, ptr %6, align 8, !tbaa !5
  %25 = srem i64 %23, %24
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %27, label %44

27:                                               ; preds = %22
  br label %28

28:                                               ; preds = %33, %27
  %29 = load i64, ptr %5, align 8, !tbaa !5
  %30 = load i64, ptr %6, align 8, !tbaa !5
  %31 = srem i64 %29, %30
  %32 = icmp eq i64 %31, 0
  br i1 %32, label %33, label %37

33:                                               ; preds = %28
  %34 = load i64, ptr %6, align 8, !tbaa !5
  %35 = load i64, ptr %5, align 8, !tbaa !5
  %36 = sdiv i64 %35, %34
  store i64 %36, ptr %5, align 8, !tbaa !5
  br label %28, !llvm.loop !9

37:                                               ; preds = %28
  %38 = load i64, ptr %4, align 8, !tbaa !5
  %39 = load i64, ptr %6, align 8, !tbaa !5
  %40 = sdiv i64 %38, %39
  %41 = load i64, ptr %6, align 8, !tbaa !5
  %42 = sub nsw i64 %41, 1
  %43 = mul nsw i64 %40, %42
  store i64 %43, ptr %4, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %37, %22
  br label %45

45:                                               ; preds = %44
  %46 = load i64, ptr %6, align 8, !tbaa !5
  %47 = add nsw i64 %46, 1
  store i64 %47, ptr %6, align 8, !tbaa !5
  br label %15, !llvm.loop !11

48:                                               ; preds = %21
  %49 = load i64, ptr %5, align 8, !tbaa !5
  %50 = icmp sgt i64 %49, 1
  br i1 %50, label %51, label %58

51:                                               ; preds = %48
  %52 = load i64, ptr %4, align 8, !tbaa !5
  %53 = load i64, ptr %5, align 8, !tbaa !5
  %54 = sdiv i64 %52, %53
  %55 = load i64, ptr %5, align 8, !tbaa !5
  %56 = sub nsw i64 %55, 1
  %57 = mul nsw i64 %54, %56
  store i64 %57, ptr %4, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %51, %48
  %59 = load i64, ptr %4, align 8, !tbaa !5
  %60 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @mp, ptr noundef nonnull align 8 dereferenceable(8) %3)
  store i64 %59, ptr %60, align 8, !tbaa !5
  store i64 %59, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %61

61:                                               ; preds = %58, %9
  %62 = load i64, ptr %2, align 8
  ret i64 %62
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNKSt3mapIxxSt4lessIxESaISt4pairIKxxEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

; 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

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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple 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"

%"class.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<long long, std::pair<const long long, long long>, std::_Select1st<std::pair<const long long, long long>>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, std::pair<const long long, long long>, std::_Select1st<std::pair<const long long, long long>>, std::less<long long>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }

@mp = external dso_local global %"class.std::map", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z3phix(i64 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  %3 = call noundef i64 @_ZNKSt3mapIxxSt4lessIxESaISt4pairIKxxEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48) @mp, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %7, label %4

4:                                                ; preds = %1
  %5 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @mp, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %6 = load i64, ptr %5, align 8, !tbaa !5
  br label %27

7:                                                ; preds = %1
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %.not2426 = icmp slt i64 %8, 4
  br i1 %.not2426, label %._crit_edge32, label %.lr.ph31

._crit_edge32:                                    ; preds = %18, %7
  %.020.lcssa = phi i64 [ %8, %7 ], [ %.121, %18 ]
  %.019.lcssa = phi i64 [ %8, %7 ], [ %.2, %18 ]
  %9 = icmp sgt i64 %.019.lcssa, 1
  br i1 %9, label %21, label %25

.lr.ph31:                                         ; preds = %7, %18
  %.029 = phi i64 [ %19, %18 ], [ 2, %7 ]
  %.01928 = phi i64 [ %.2, %18 ], [ %8, %7 ]
  %.02027 = phi i64 [ %.121, %18 ], [ %8, %7 ]
  %10 = srem i64 %.01928, %.029
  %11 = icmp eq i64 %10, 0
  br i1 %11, label %.lr.ph, label %18

.lr.ph:                                           ; preds = %.lr.ph31, %.lr.ph
  %.125 = phi i64 [ %12, %.lr.ph ], [ %.01928, %.lr.ph31 ]
  %12 = sdiv i64 %.125, %.029
  %13 = srem i64 %12, %.029
  %14 = icmp eq i64 %13, 0
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph
  %15 = sdiv i64 %.02027, %.029
  %16 = add nsw i64 %.029, -1
  %17 = mul nsw i64 %15, %16
  br label %18

18:                                               ; preds = %.lr.ph31, %._crit_edge
  %.121 = phi i64 [ %17, %._crit_edge ], [ %.02027, %.lr.ph31 ]
  %.2 = phi i64 [ %12, %._crit_edge ], [ %.01928, %.lr.ph31 ]
  %19 = add nuw nsw i64 %.029, 1
  %20 = mul nuw nsw i64 %19, %19
  %.not24 = icmp sgt i64 %20, %.2
  br i1 %.not24, label %._crit_edge32, label %.lr.ph31, !llvm.loop !11

21:                                               ; preds = %._crit_edge32
  %22 = sdiv i64 %.020.lcssa, %.019.lcssa
  %23 = add nsw i64 %.019.lcssa, -1
  %24 = mul nsw i64 %22, %23
  br label %25

25:                                               ; preds = %21, %._crit_edge32
  %.222 = phi i64 [ %24, %21 ], [ %.020.lcssa, %._crit_edge32 ]
  %26 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @mp, ptr noundef nonnull align 8 dereferenceable(8) %2)
  store i64 %.222, ptr %26, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %25, %4
  %.023 = phi i64 [ %6, %4 ], [ %.222, %25 ]
  ret i64 %.023
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNKSt3mapIxxSt4lessIxESaISt4pairIKxxEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIxxSt4lessIxESaISt4pairIKxxEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

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

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


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