; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/5778.ll (Z5solvex)

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

@ans = external dso_local global i64, align 8
@n = external dso_local global i64, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5solvex(i64 noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = icmp slt i64 %8, 2
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  br label %53

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

13:                                               ; preds = %38, %11
  %14 = load i64, ptr %5, align 8, !tbaa !5
  %15 = load i64, ptr %5, align 8, !tbaa !5
  %16 = mul nsw i64 %14, %15
  %17 = load i64, ptr %3, align 8, !tbaa !5
  %18 = icmp sle i64 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %13
  store i32 2, ptr %6, align 4
  br label %41

20:                                               ; preds = %13
  %21 = load i64, ptr %3, align 8, !tbaa !5
  %22 = load i64, ptr %5, align 8, !tbaa !5
  %23 = srem i64 %21, %22
  %24 = icmp eq i64 %23, 0
  br i1 %24, label %25, label %37

25:                                               ; preds = %20
  %26 = load i64, ptr %3, align 8, !tbaa !5
  %27 = load i64, ptr %5, align 8, !tbaa !5
  %28 = load i64, ptr %5, align 8, !tbaa !5
  %29 = mul nsw i64 %27, %28
  %30 = srem i64 %26, %29
  %31 = icmp eq i64 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %25
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %41

33:                                               ; preds = %25
  %34 = load i64, ptr %5, align 8, !tbaa !5
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = sdiv i64 %35, %34
  store i64 %36, ptr %3, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %33, %20
  br label %38

38:                                               ; preds = %37
  %39 = load i64, ptr %5, align 8, !tbaa !5
  %40 = add nsw i64 %39, 1
  store i64 %40, ptr %5, align 8, !tbaa !5
  br label %13, !llvm.loop !9

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

43:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %44 = load i64, ptr %4, align 8, !tbaa !5
  %45 = load i64, ptr %4, align 8, !tbaa !5
  %46 = mul nsw i64 %44, %45
  %47 = load i64, ptr @n, align 8, !tbaa !5
  %48 = sub nsw i64 %46, %47
  %49 = call noundef i64 @_ZSt3absx(i64 noundef %48)
  store i64 %49, ptr %7, align 8, !tbaa !5
  %50 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) @ans, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %51 = load i64, ptr %50, align 8, !tbaa !5
  store i64 %51, ptr @ans, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  store i1 true, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %52

52:                                               ; preds = %43, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %53

53:                                               ; preds = %52, %10
  %54 = load i1, ptr %2, align 1
  ret i1 %54
}

; 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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) #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" }
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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

@ans = external dso_local global i64, align 8
@n = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z5solvex(i64 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  %3 = icmp slt i64 %0, 2
  br i1 %3, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %1
  %.not22 = icmp ult i64 %0, 4
  br i1 %.not22, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %11
  %4 = phi i64 [ %13, %11 ], [ 4, %.preheader ]
  %.01624 = phi i64 [ %12, %11 ], [ 2, %.preheader ]
  %.01823 = phi i64 [ %.119, %11 ], [ %0, %.preheader ]
  %5 = srem i64 %.01823, %.01624
  %6 = sdiv i64 %.01823, %.01624
  %7 = icmp eq i64 %5, 0
  br i1 %7, label %8, label %11

8:                                                ; preds = %.lr.ph
  %9 = srem i64 %.01823, %4
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %.loopexit, label %11

11:                                               ; preds = %8, %.lr.ph
  %.119 = phi i64 [ %.01823, %.lr.ph ], [ %6, %8 ]
  %12 = add nuw nsw i64 %.01624, 1
  %13 = mul nuw nsw i64 %12, %12
  %.not = icmp sgt i64 %13, %.119
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !5

.critedge:                                        ; preds = %11, %.preheader
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %14 = mul nuw nsw i64 %0, %0
  %15 = load i64, ptr @n, align 8, !tbaa !7
  %16 = sub nsw i64 %14, %15
  %17 = tail call noundef i64 @_ZSt3absx(i64 noundef %16)
  store i64 %17, ptr %2, align 8, !tbaa !7
  %18 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) @ans, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %19 = load i64, ptr %18, align 8, !tbaa !7
  store i64 %19, ptr @ans, align 8, !tbaa !7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  br label %.loopexit

.loopexit:                                        ; preds = %8, %.critedge, %1
  %.2 = phi i1 [ false, %1 ], [ true, %.critedge ], [ false, %8 ]
  ret i1 %.2
}

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

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

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

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

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


; Effective O3 passes: CorrelatedValuePropagationPass,DivRemPairsPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass