; LLVM IR from brpapa/algorithms :: solutions/uva (11254)

; 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::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@_ZSt3cin = external global %"class.std::basic_istream", align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca double, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  store i32 0, ptr %1, align 4
  br label %6

6:                                                ; preds = %61, %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #6
  %7 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %8 = load double, ptr %2, align 8, !tbaa !5
  %9 = fcmp oeq double %8, -1.000000e+00
  br i1 %9, label %10, label %11

10:                                               ; preds = %6
  store i32 3, ptr %3, align 4
  br label %59

11:                                               ; preds = %6
  %12 = load double, ptr %2, align 8, !tbaa !5
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str, double noundef %12)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  %14 = load double, ptr %2, align 8, !tbaa !5
  %15 = fmul double 2.000000e+00, %14
  %16 = call double @sqrt(double noundef %15) #6
  %17 = fptosi double %16 to i32
  store i32 %17, ptr %4, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %54, %11
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = icmp sge i32 %19, 1
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  store i32 4, ptr %3, align 4
  br label %57

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %23 = load double, ptr %2, align 8, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = load i32, ptr %4, align 4, !tbaa !9
  %26 = mul nsw i32 %24, %25
  %27 = sitofp i32 %26 to double
  %28 = fneg double %27
  %29 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %23, double %28)
  %30 = load i32, ptr %4, align 4, !tbaa !9
  %31 = sitofp i32 %30 to double
  %32 = fadd double %29, %31
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = sitofp i32 %33 to double
  %35 = fmul double 2.000000e+00, %34
  %36 = fdiv double %32, %35
  store double %36, ptr %5, align 8, !tbaa !5
  %37 = load double, ptr %5, align 8, !tbaa !5
  %38 = load double, ptr %5, align 8, !tbaa !5
  %39 = fptosi double %38 to i32
  %40 = sitofp i32 %39 to double
  %41 = fcmp oeq double %37, %40
  br i1 %41, label %42, label %50

42:                                               ; preds = %22
  %43 = load double, ptr %5, align 8, !tbaa !5
  %44 = load double, ptr %5, align 8, !tbaa !5
  %45 = load i32, ptr %4, align 4, !tbaa !9
  %46 = sitofp i32 %45 to double
  %47 = fadd double %44, %46
  %48 = fsub double %47, 1.000000e+00
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %43, double noundef %48)
  store i32 4, ptr %3, align 4
  br label %51

50:                                               ; preds = %22
  store i32 0, ptr %3, align 4
  br label %51

51:                                               ; preds = %50, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  %52 = load i32, ptr %3, align 4
  switch i32 %52, label %57 [
    i32 0, label %53
  ]

53:                                               ; preds = %51
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %4, align 4, !tbaa !9
  %56 = add nsw i32 %55, -1
  store i32 %56, ptr %4, align 4, !tbaa !9
  br label %18, !llvm.loop !11

57:                                               ; preds = %51, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %58

58:                                               ; preds = %57
  store i32 0, ptr %3, align 4
  br label %59

59:                                               ; preds = %58, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #6
  %60 = load i32, ptr %3, align 4
  switch i32 %60, label %63 [
    i32 0, label %61
    i32 3, label %62
  ]

61:                                               ; preds = %59
  br label %6, !llvm.loop !13

62:                                               ; preds = %59
  ret i32 0

63:                                               ; preds = %59
  unreachable
}

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

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

declare i32 @printf(ptr noundef, ...) #3

; Function Attrs: nounwind
declare double @sqrt(double noundef) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #5

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

attributes #0 = { mustprogress norecurse 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 = { 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 = { "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 #4 = { nounwind "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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@_ZSt3cin = external global %"class.std::basic_istream", align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #6
  %2 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %1)
  %3 = load double, ptr %1, align 8, !tbaa !5
  %4 = fcmp oeq double %3, -1.000000e+00
  br i1 %4, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.loopexit
  %5 = phi double [ %33, %.loopexit ], [ %3, %0 ]
  %6 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %5)
  %7 = load double, ptr %1, align 8, !tbaa !5
  %8 = fmul double %7, 2.000000e+00
  %9 = call double @sqrt(double noundef %8) #6
  %10 = fptosi double %9 to i32
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.critedge.lr.ph, label %.loopexit

.critedge.lr.ph:                                  ; preds = %.lr.ph
  %12 = load double, ptr %1, align 8, !tbaa !5
  br label %.critedge

13:                                               ; preds = %.critedge
  %14 = add nsw i32 %.01218, -1
  %15 = icmp sgt i32 %.01218, 1
  br i1 %15, label %.critedge, label %.loopexit, !llvm.loop !9

.critedge:                                        ; preds = %.critedge.lr.ph, %13
  %.01218 = phi i32 [ %10, %.critedge.lr.ph ], [ %14, %13 ]
  %16 = mul nuw nsw i32 %.01218, %.01218
  %17 = uitofp nneg i32 %16 to double
  %18 = fneg double %17
  %19 = call double @llvm.fmuladd.f64(double %12, double 2.000000e+00, double %18)
  %20 = uitofp nneg i32 %.01218 to double
  %21 = fadd double %19, %20
  %22 = shl nuw i32 %.01218, 1
  %23 = uitofp i32 %22 to double
  %24 = fdiv double %21, %23
  %25 = fptosi double %24 to i32
  %26 = sitofp i32 %25 to double
  %27 = fcmp une double %24, %26
  br i1 %27, label %13, label %28

28:                                               ; preds = %.critedge
  %29 = fadd double %24, %20
  %30 = fadd double %29, -1.000000e+00
  %31 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %24, double noundef %30)
  br label %.loopexit

.loopexit:                                        ; preds = %13, %.lr.ph, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #6
  %32 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %1)
  %33 = load double, ptr %1, align 8, !tbaa !5
  %34 = fcmp oeq double %33, -1.000000e+00
  br i1 %34, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.loopexit, %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #6
  ret i32 0
}

; 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 uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2 align 2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #5

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

attributes #0 = { mustprogress norecurse 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 = { 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 = { nofree nounwind "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 #4 = { mustprogress nofree nounwind willreturn memory(write) "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 #5 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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