; LLVM IR from viveakrt/Competitive-programing :: Codeforces/1592A_Gamer_Hemose.ll (Z4phinx)

; 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: mustprogress uwtable
define dso_local noundef i64 @_Z4phinx(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = load i64, ptr %2, align 8, !tbaa !5
  store i64 %5, ptr %3, align 8, !tbaa !5
  %6 = load i64, ptr %2, align 8, !tbaa !5
  %7 = srem i64 %6, 2
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %9, label %20

9:                                                ; preds = %1
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = sdiv i64 %10, 2
  store i64 %11, ptr %3, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %16, %9
  %13 = load i64, ptr %2, align 8, !tbaa !5
  %14 = srem i64 %13, 2
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %19

16:                                               ; preds = %12
  %17 = load i64, ptr %2, align 8, !tbaa !5
  %18 = sdiv i64 %17, 2
  store i64 %18, ptr %2, align 8, !tbaa !5
  br label %12, !llvm.loop !9

19:                                               ; preds = %12
  br label %20

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

21:                                               ; preds = %51, %20
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = sitofp i64 %22 to double
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %25 = call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %24)
  %26 = fcmp ole double %23, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %54

28:                                               ; preds = %21
  %29 = load i64, ptr %2, align 8, !tbaa !5
  %30 = load i64, ptr %4, align 8, !tbaa !5
  %31 = srem i64 %29, %30
  %32 = icmp eq i64 %31, 0
  br i1 %32, label %33, label %50

33:                                               ; preds = %28
  br label %34

34:                                               ; preds = %39, %33
  %35 = load i64, ptr %2, align 8, !tbaa !5
  %36 = load i64, ptr %4, align 8, !tbaa !5
  %37 = srem i64 %35, %36
  %38 = icmp eq i64 %37, 0
  br i1 %38, label %39, label %43

39:                                               ; preds = %34
  %40 = load i64, ptr %4, align 8, !tbaa !5
  %41 = load i64, ptr %2, align 8, !tbaa !5
  %42 = sdiv i64 %41, %40
  store i64 %42, ptr %2, align 8, !tbaa !5
  br label %34, !llvm.loop !11

43:                                               ; preds = %34
  %44 = load i64, ptr %3, align 8, !tbaa !5
  %45 = load i64, ptr %4, align 8, !tbaa !5
  %46 = sdiv i64 %44, %45
  %47 = load i64, ptr %4, align 8, !tbaa !5
  %48 = sub nsw i64 %47, 1
  %49 = mul nsw i64 %46, %48
  store i64 %49, ptr %3, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %43, %28
  br label %51

51:                                               ; preds = %50
  %52 = load i64, ptr %4, align 8, !tbaa !5
  %53 = add nsw i64 %52, 2
  store i64 %53, ptr %4, align 8, !tbaa !5
  br label %21, !llvm.loop !12

54:                                               ; preds = %27
  %55 = load i64, ptr %2, align 8, !tbaa !5
  %56 = icmp sgt i64 %55, 1
  br i1 %56, label %57, label %64

57:                                               ; preds = %54
  %58 = load i64, ptr %3, align 8, !tbaa !5
  %59 = load i64, ptr %2, align 8, !tbaa !5
  %60 = sdiv i64 %58, %59
  %61 = load i64, ptr %2, align 8, !tbaa !5
  %62 = sub nsw i64 %61, 1
  %63 = mul nsw i64 %60, %62
  store i64 %63, ptr %3, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %57, %54
  %65 = load i64, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i64 %65
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = !{!"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}
!12 = distinct !{!12, !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: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z4phinx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = and i64 %0, 1
  %3 = icmp eq i64 %2, 0
  br i1 %3, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %1, %.preheader
  %.023 = phi i64 [ %6, %.preheader ], [ %0, %1 ]
  %4 = and i64 %.023, 1
  %5 = icmp eq i64 %4, 0
  %6 = ashr exact i64 %.023, 1
  br i1 %5, label %.preheader, label %.loopexit.loopexit, !llvm.loop !5

.loopexit.loopexit:                               ; preds = %.preheader
  %7 = ashr exact i64 %0, 1
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %1
  %.124 = phi i64 [ %0, %1 ], [ %.023, %.loopexit.loopexit ]
  %.022 = phi i64 [ %0, %1 ], [ %7, %.loopexit.loopexit ]
  %8 = tail call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %.124)
  %9 = fcmp ult double %8, 3.000000e+00
  br i1 %9, label %._crit_edge33, label %.lr.ph32

._crit_edge33:                                    ; preds = %19, %.loopexit
  %.225.lcssa = phi i64 [ %.124, %.loopexit ], [ %.4, %19 ]
  %.1.lcssa = phi i64 [ %.022, %.loopexit ], [ %.2, %19 ]
  %10 = icmp sgt i64 %.225.lcssa, 1
  br i1 %10, label %24, label %28

.lr.ph32:                                         ; preds = %.loopexit, %19
  %.030 = phi i64 [ %20, %19 ], [ 3, %.loopexit ]
  %.129 = phi i64 [ %.2, %19 ], [ %.022, %.loopexit ]
  %.22528 = phi i64 [ %.4, %19 ], [ %.124, %.loopexit ]
  %11 = srem i64 %.22528, %.030
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %.lr.ph, label %19

.lr.ph:                                           ; preds = %.lr.ph32, %.lr.ph
  %.32627 = phi i64 [ %13, %.lr.ph ], [ %.22528, %.lr.ph32 ]
  %13 = sdiv i64 %.32627, %.030
  %14 = srem i64 %13, %.030
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph
  %16 = sdiv i64 %.129, %.030
  %17 = add nsw i64 %.030, -1
  %18 = mul nsw i64 %16, %17
  br label %19

19:                                               ; preds = %.lr.ph32, %._crit_edge
  %.4 = phi i64 [ %13, %._crit_edge ], [ %.22528, %.lr.ph32 ]
  %.2 = phi i64 [ %18, %._crit_edge ], [ %.129, %.lr.ph32 ]
  %20 = add nuw nsw i64 %.030, 2
  %21 = uitofp nneg i64 %20 to double
  %22 = tail call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %.4)
  %23 = fcmp ult double %22, %21
  br i1 %23, label %._crit_edge33, label %.lr.ph32, !llvm.loop !8

24:                                               ; preds = %._crit_edge33
  %25 = sdiv i64 %.1.lcssa, %.225.lcssa
  %26 = add nsw i64 %.225.lcssa, -1
  %27 = mul nsw i64 %25, %26
  br label %28

28:                                               ; preds = %24, %._crit_edge33
  %.3 = phi i64 [ %27, %24 ], [ %.1.lcssa, %._crit_edge33 ]
  ret i64 %.3
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}
!8 = distinct !{!8, !6}


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