; LLVM IR from Tunghohin/Competitive_Coding :: Luogu (p1024)

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

@a = external dso_local global double, align 8
@b = external dso_local global double, align 8
@c = external dso_local global double, align 8
@d = external dso_local global double, align 8
@sum = external dso_local global double, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z3fund(double noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @a, ptr noundef @b, ptr noundef @c, ptr noundef @d)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 -100, ptr %7, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %68, %0
  %11 = load i32, ptr %7, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 100
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  store i32 2, ptr %8, align 4
  br label %71

14:                                               ; preds = %10
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = sitofp i32 %15 to double
  store double %16, ptr %2, align 8, !tbaa !9
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  %19 = sitofp i32 %18 to double
  store double %19, ptr %3, align 8, !tbaa !9
  %20 = load double, ptr %2, align 8, !tbaa !9
  %21 = call noundef double @_Z3fund(double noundef %20)
  store double %21, ptr %4, align 8, !tbaa !9
  %22 = load double, ptr %3, align 8, !tbaa !9
  %23 = call noundef double @_Z3fund(double noundef %22)
  store double %23, ptr %5, align 8, !tbaa !9
  %24 = load double, ptr %4, align 8, !tbaa !9
  %25 = fcmp une double %24, 0.000000e+00
  br i1 %25, label %31, label %26

26:                                               ; preds = %14
  %27 = load double, ptr @sum, align 8, !tbaa !9
  %28 = fadd double %27, 1.000000e+00
  store double %28, ptr @sum, align 8, !tbaa !9
  %29 = load double, ptr %2, align 8, !tbaa !9
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %29)
  br label %31

31:                                               ; preds = %26, %14
  %32 = load double, ptr %4, align 8, !tbaa !9
  %33 = load double, ptr %5, align 8, !tbaa !9
  %34 = fmul double %32, %33
  %35 = fcmp olt double %34, 0.000000e+00
  br i1 %35, label %36, label %63

36:                                               ; preds = %31
  br label %37

37:                                               ; preds = %57, %36
  %38 = load double, ptr %3, align 8, !tbaa !9
  %39 = load double, ptr %2, align 8, !tbaa !9
  %40 = fsub double %38, %39
  %41 = fcmp oge double %40, 1.000000e-03
  br i1 %41, label %42, label %58

42:                                               ; preds = %37
  %43 = load double, ptr %2, align 8, !tbaa !9
  %44 = load double, ptr %3, align 8, !tbaa !9
  %45 = fadd double %43, %44
  %46 = fdiv double %45, 2.000000e+00
  store double %46, ptr %6, align 8, !tbaa !9
  %47 = load double, ptr %6, align 8, !tbaa !9
  %48 = call noundef double @_Z3fund(double noundef %47)
  %49 = load double, ptr %3, align 8, !tbaa !9
  %50 = call noundef double @_Z3fund(double noundef %49)
  %51 = fmul double %48, %50
  %52 = fcmp ole double %51, 0.000000e+00
  br i1 %52, label %53, label %55

53:                                               ; preds = %42
  %54 = load double, ptr %6, align 8, !tbaa !9
  store double %54, ptr %2, align 8, !tbaa !9
  br label %57

55:                                               ; preds = %42
  %56 = load double, ptr %6, align 8, !tbaa !9
  store double %56, ptr %3, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %55, %53
  br label %37, !llvm.loop !11

58:                                               ; preds = %37
  %59 = load double, ptr %3, align 8, !tbaa !9
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %59)
  %61 = load double, ptr @sum, align 8, !tbaa !9
  %62 = fadd double %61, 1.000000e+00
  store double %62, ptr @sum, align 8, !tbaa !9
  br label %63

63:                                               ; preds = %58, %31
  %64 = load double, ptr @sum, align 8, !tbaa !9
  %65 = fcmp oeq double %64, 3.000000e+00
  br i1 %65, label %66, label %67

66:                                               ; preds = %63
  store i32 2, ptr %8, align 4
  br label %71

67:                                               ; preds = %63
  br label %68

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

71:                                               ; preds = %66, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %72

72:                                               ; preds = %71
  store i32 0, ptr %1, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %73 = load i32, ptr %1, align 4
  ret i32 %73
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

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

declare i32 @printf(ptr noundef, ...) #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 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 #2 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !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"

@a = external dso_local global double, align 8
@b = external dso_local global double, align 8
@c = external dso_local global double, align 8
@d = external dso_local global double, align 8
@sum = external dso_local local_unnamed_addr global double, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

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

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @a, ptr noundef nonnull @b, ptr noundef nonnull @c, ptr noundef nonnull @d)
  br label %2

2:                                                ; preds = %30, %0
  %.0 = phi i32 [ -100, %0 ], [ %5, %30 ]
  %exitcond.not = icmp eq i32 %.0, 100
  br i1 %exitcond.not, label %33, label %3

3:                                                ; preds = %2
  %4 = sitofp i32 %.0 to double
  %5 = add nsw i32 %.0, 1
  %6 = sitofp i32 %5 to double
  %7 = tail call noundef double @_Z3fund(double noundef %4)
  %8 = tail call noundef double @_Z3fund(double noundef %6)
  %9 = fcmp une double %7, 0.000000e+00
  br i1 %9, label %14, label %10

10:                                               ; preds = %3
  %11 = load double, ptr @sum, align 8, !tbaa !5
  %12 = fadd double %11, 1.000000e+00
  store double %12, ptr @sum, align 8, !tbaa !5
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %4)
  br label %14

14:                                               ; preds = %10, %3
  %15 = fmul double %7, %8
  %16 = fcmp olt double %15, 0.000000e+00
  br i1 %16, label %.preheader, label %thread-pre-split

.preheader:                                       ; preds = %14
  %17 = fsub double %6, %4
  %18 = fcmp ult double %17, 1.000000e-03
  br i1 %18, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.01923 = phi double [ %.019., %.lr.ph ], [ %4, %.preheader ]
  %.02022 = phi double [ %..020, %.lr.ph ], [ %6, %.preheader ]
  %19 = fadd double %.02022, %.01923
  %20 = fmul double %19, 5.000000e-01
  %21 = tail call noundef double @_Z3fund(double noundef %20)
  %22 = tail call noundef double @_Z3fund(double noundef %.02022)
  %23 = fmul double %21, %22
  %24 = fcmp ugt double %23, 0.000000e+00
  %..020 = select i1 %24, double %20, double %.02022
  %.019. = select i1 %24, double %.01923, double %20
  %25 = fsub double %..020, %.019.
  %26 = fcmp ult double %25, 1.000000e-03
  br i1 %26, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.020.lcssa = phi double [ %6, %.preheader ], [ %..020, %.lr.ph ]
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %.020.lcssa)
  %28 = load double, ptr @sum, align 8, !tbaa !5
  %29 = fadd double %28, 1.000000e+00
  store double %29, ptr @sum, align 8, !tbaa !5
  br label %30

thread-pre-split:                                 ; preds = %14
  %.pr = load double, ptr @sum, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %thread-pre-split, %._crit_edge
  %31 = phi double [ %.pr, %thread-pre-split ], [ %29, %._crit_edge ]
  %32 = fcmp oeq double %31, 3.000000e+00
  br i1 %32, label %33, label %2, !llvm.loop !11

33:                                               ; preds = %30, %2
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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 norecurse 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 #2 = { 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" }

!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"}
!11 = distinct !{!11, !10}


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