; LLVM IR from DionysiosB/CodeForces :: 0600-0699/679B-BearAndTowerOfCubes.ll (Z3reclllRSt4pairIllE)

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

%"struct.std::pair" = type { i64, i64 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z4cubel(i64 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3reclllRSt4pairIllE(i64 noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef nonnull align 8 dereferenceable(16) %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca %"struct.std::pair", align 8
  %10 = alloca i64, align 8
  store i64 %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !9
  %11 = load i64, ptr %5, align 8, !tbaa !5
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %23

13:                                               ; preds = %4
  %14 = load ptr, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #4
  %15 = call { i64, i64 } @_ZSt9make_pairIRlS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %16 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 0
  %17 = extractvalue { i64, i64 } %15, 0
  store i64 %17, ptr %16, align 8
  %18 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 1
  %19 = extractvalue { i64, i64 } %15, 1
  store i64 %19, ptr %18, align 8
  %20 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZSt3maxISt4pairIllEERKT_S4_S4_(ptr noundef nonnull align 8 dereferenceable(16) %14, ptr noundef nonnull align 8 dereferenceable(16) %9)
  %21 = load ptr, ptr %8, align 8, !tbaa !9
  %22 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt4pairIllEaSERKS0_(ptr noundef nonnull align 8 dereferenceable(16) %21, ptr noundef nonnull align 8 dereferenceable(16) %20)
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #4
  br label %64

23:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 1, ptr %10, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %30, %23
  %25 = load i64, ptr %10, align 8, !tbaa !5
  %26 = add nsw i64 %25, 1
  %27 = call noundef i64 @_Z4cubel(i64 noundef %26)
  %28 = load i64, ptr %5, align 8, !tbaa !5
  %29 = icmp sle i64 %27, %28
  br i1 %29, label %30, label %33

30:                                               ; preds = %24
  %31 = load i64, ptr %10, align 8, !tbaa !5
  %32 = add nsw i64 %31, 1
  store i64 %32, ptr %10, align 8, !tbaa !5
  br label %24, !llvm.loop !11

33:                                               ; preds = %24
  %34 = load i64, ptr %5, align 8, !tbaa !5
  %35 = load i64, ptr %10, align 8, !tbaa !5
  %36 = call noundef i64 @_Z4cubel(i64 noundef %35)
  %37 = sub nsw i64 %34, %36
  %38 = load i64, ptr %6, align 8, !tbaa !5
  %39 = add nsw i64 %38, 1
  %40 = load i64, ptr %7, align 8, !tbaa !5
  %41 = load i64, ptr %10, align 8, !tbaa !5
  %42 = call noundef i64 @_Z4cubel(i64 noundef %41)
  %43 = add nsw i64 %40, %42
  %44 = load ptr, ptr %8, align 8, !tbaa !9
  call void @_Z3reclllRSt4pairIllE(i64 noundef %37, i64 noundef %39, i64 noundef %43, ptr noundef nonnull align 8 dereferenceable(16) %44)
  %45 = load i64, ptr %10, align 8, !tbaa !5
  %46 = icmp sge i64 %45, 1
  br i1 %46, label %47, label %63

47:                                               ; preds = %33
  %48 = load i64, ptr %10, align 8, !tbaa !5
  %49 = call noundef i64 @_Z4cubel(i64 noundef %48)
  %50 = sub nsw i64 %49, 1
  %51 = load i64, ptr %10, align 8, !tbaa !5
  %52 = sub nsw i64 %51, 1
  %53 = call noundef i64 @_Z4cubel(i64 noundef %52)
  %54 = sub nsw i64 %50, %53
  %55 = load i64, ptr %6, align 8, !tbaa !5
  %56 = add nsw i64 %55, 1
  %57 = load i64, ptr %7, align 8, !tbaa !5
  %58 = load i64, ptr %10, align 8, !tbaa !5
  %59 = sub nsw i64 %58, 1
  %60 = call noundef i64 @_Z4cubel(i64 noundef %59)
  %61 = add nsw i64 %57, %60
  %62 = load ptr, ptr %8, align 8, !tbaa !9
  call void @_Z3reclllRSt4pairIllE(i64 noundef %54, i64 noundef %56, i64 noundef %61, ptr noundef nonnull align 8 dereferenceable(16) %62)
  br label %63

63:                                               ; preds = %47, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %64

64:                                               ; preds = %63, %13
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZSt3maxISt4pairIllEERKT_S4_S4_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #2

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

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i64 } @_ZSt9make_pairIRlS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #1

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

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

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 = { 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 #2 = { inlinehint 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

%"struct.std::pair" = type { i64, i64 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z4cubel(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3reclllRSt4pairIllE(i64 noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef nonnull align 8 dereferenceable(16) %3) local_unnamed_addr #1 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca %"struct.std::pair", align 8
  %8 = icmp eq i64 %0, 0
  br i1 %8, label %tailrecurse._crit_edge, label %.preheader

.preheader:                                       ; preds = %4, %tailrecurse
  %.tr1620 = phi i64 [ %29, %tailrecurse ], [ %2, %4 ]
  %.tr1519 = phi i64 [ %20, %tailrecurse ], [ %1, %4 ]
  %.tr18 = phi i64 [ %27, %tailrecurse ], [ %0, %4 ]
  br label %15

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %4
  %.tr16.lcssa = phi i64 [ %2, %4 ], [ %29, %tailrecurse ]
  %.tr15.lcssa = phi i64 [ %1, %4 ], [ %20, %tailrecurse ]
  store i64 %.tr15.lcssa, ptr %5, align 8, !tbaa !5
  store i64 %.tr16.lcssa, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #4
  %9 = call { i64, i64 } @_ZSt9make_pairIRlS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %6)
  %10 = extractvalue { i64, i64 } %9, 0
  store i64 %10, ptr %7, align 8
  %11 = getelementptr inbounds i8, ptr %7, i64 8
  %12 = extractvalue { i64, i64 } %9, 1
  store i64 %12, ptr %11, align 8
  %13 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZSt3maxISt4pairIllEERKT_S4_S4_(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull align 8 dereferenceable(16) %7)
  %14 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt4pairIllEaSERKS0_(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull align 8 dereferenceable(16) %13)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #4
  ret void

15:                                               ; preds = %.preheader, %15
  %.0 = phi i64 [ %16, %15 ], [ 1, %.preheader ]
  %16 = add nuw nsw i64 %.0, 1
  %17 = tail call noundef i64 @_Z4cubel(i64 noundef %16)
  %.not = icmp sgt i64 %17, %.tr18
  br i1 %.not, label %tailrecurse, label %15, !llvm.loop !9

tailrecurse:                                      ; preds = %15
  %18 = tail call noundef i64 @_Z4cubel(i64 noundef %.0)
  %19 = sub nsw i64 %.tr18, %18
  %20 = add nsw i64 %.tr1519, 1
  %21 = tail call noundef i64 @_Z4cubel(i64 noundef %.0)
  %22 = add nsw i64 %21, %.tr1620
  tail call void @_Z3reclllRSt4pairIllE(i64 noundef %19, i64 noundef %20, i64 noundef %22, ptr noundef nonnull align 8 dereferenceable(16) %3)
  %23 = tail call noundef i64 @_Z4cubel(i64 noundef %.0)
  %24 = add nsw i64 %.0, -1
  %25 = tail call noundef i64 @_Z4cubel(i64 noundef %24)
  %26 = xor i64 %25, -1
  %27 = add i64 %23, %26
  %28 = tail call noundef i64 @_Z4cubel(i64 noundef %24)
  %29 = add nsw i64 %28, %.tr1620
  %30 = icmp eq i64 %27, 0
  br i1 %30, label %tailrecurse._crit_edge, label %.preheader
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZSt3maxISt4pairIllEERKT_S4_S4_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2

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

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i64 } @_ZSt9make_pairIRlS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

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

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

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 = { 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 #2 = { inlinehint 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 #3 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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", !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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass