; LLVM IR from AnneLivia/Competitive-Programming :: Online Judges/URI/1558/main.ll (Z9resultTwoi)

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

@memo = external dso_local global [100001 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z9resultTwoi(i32 noundef %0) #0 {
  %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
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  br label %86

11:                                               ; preds = %1
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [100001 x i32], ptr @memo, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %22

17:                                               ; preds = %11
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [100001 x i32], ptr @memo, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  store i32 %21, ptr %2, align 4
  br label %86

22:                                               ; preds = %11
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = icmp eq i32 %23, 1
  br i1 %24, label %25, label %29

25:                                               ; preds = %22
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [100001 x i32], ptr @memo, i64 0, i64 %27
  store i32 1, ptr %28, align 4, !tbaa !5
  br label %81

29:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %76, %29
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = sitofp i32 %31 to double
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %33)
  %35 = fcmp ole double %32, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %30
  store i32 2, ptr %6, align 4
  br label %79

37:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %67, %37
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = sitofp i32 %39 to double
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %41)
  %43 = fcmp ole double %40, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %38
  store i32 5, ptr %6, align 4
  br label %70

45:                                               ; preds = %38
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = mul nsw i32 %46, %47
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = mul nsw i32 %49, %50
  %52 = add nsw i32 %48, %51
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = icmp eq i32 %52, %53
  br i1 %54, label %55, label %66

55:                                               ; preds = %45
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = mul nsw i32 %56, %57
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = mul nsw i32 %59, %60
  %62 = add nsw i32 %58, %61
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [100001 x i32], ptr @memo, i64 0, i64 %64
  store i32 %62, ptr %65, align 4, !tbaa !5
  store i32 1, ptr %4, align 4, !tbaa !5
  store i32 5, ptr %6, align 4
  br label %70

66:                                               ; preds = %45
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %7, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %7, align 4, !tbaa !5
  br label %38, !llvm.loop !9

70:                                               ; preds = %55, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %4, align 4, !tbaa !5
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %74, label %75

74:                                               ; preds = %71
  store i32 2, ptr %6, align 4
  br label %79

75:                                               ; preds = %71
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %5, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %5, align 4, !tbaa !5
  br label %30, !llvm.loop !11

79:                                               ; preds = %74, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %80

80:                                               ; preds = %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %81

81:                                               ; preds = %80, %25
  %82 = load i32, ptr %3, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [100001 x i32], ptr @memo, i64 0, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !5
  store i32 %85, ptr %2, align 4
  br label %86

86:                                               ; preds = %81, %17, %10
  %87 = load i32, ptr %2, align 4
  ret i32 %87
}

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

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

; 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 = { 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 = !{!"int", !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"

@memo = external dso_local local_unnamed_addr global [100001 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z9resultTwoi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp slt i32 %0, 0
  br i1 %2, label %28, label %3

3:                                                ; preds = %1
  %4 = zext nneg i32 %0 to i64
  %5 = getelementptr inbounds [100001 x i32], ptr @memo, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %28

7:                                                ; preds = %3
  %8 = icmp eq i32 %0, 1
  br i1 %8, label %.loopexit.sink.split, label %.preheader31

.preheader31:                                     ; preds = %7
  %9 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %0)
  %10 = fcmp ult double %9, 0.000000e+00
  br i1 %10, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %.preheader31, %.critedge
  %.02433 = phi i32 [ %23, %.critedge ], [ 0, %.preheader31 ]
  %11 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %0)
  %12 = fcmp ult double %11, 0.000000e+00
  br i1 %12, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %13 = mul nuw nsw i32 %.02433, %.02433
  br label %19

14:                                               ; preds = %19
  %15 = add nuw nsw i32 %.032, 1
  %16 = uitofp nneg i32 %15 to double
  %17 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %0)
  %18 = fcmp ult double %17, %16
  br i1 %18, label %.critedge, label %19, !llvm.loop !9

19:                                               ; preds = %.lr.ph, %14
  %.032 = phi i32 [ 0, %.lr.ph ], [ %15, %14 ]
  %20 = mul nuw nsw i32 %.032, %.032
  %21 = add nuw nsw i32 %20, %13
  %22 = icmp eq i32 %21, %0
  br i1 %22, label %.loopexit.sink.split, label %14

.critedge:                                        ; preds = %14, %.preheader
  %23 = add nuw nsw i32 %.02433, 1
  %24 = uitofp nneg i32 %23 to double
  %25 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %0)
  %26 = fcmp ult double %25, %24
  br i1 %26, label %.loopexit, label %.preheader, !llvm.loop !11

.loopexit.sink.split:                             ; preds = %19, %7
  %.sink = phi i32 [ 1, %7 ], [ %0, %19 ]
  store i32 %.sink, ptr %5, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.critedge, %.loopexit.sink.split, %.preheader31
  %27 = load i32, ptr %5, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %3, %1, %.loopexit
  %.026 = phi i32 [ %27, %.loopexit ], [ 0, %1 ], [ %6, %3 ]
  ret i32 %.026
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 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 = !{!6, !6, i64 0}
!6 = !{!"int", !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,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass