; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/364 Division 1/Problem A/A.ll (Z1fd)

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

@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@l = external dso_local global double, align 8
@v1 = external dso_local global double, align 8
@v2 = external dso_local global double, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z1fd(double noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  store double %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %10 = load i32, ptr @n, align 4, !tbaa !9
  store i32 %10, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store double 0.000000e+00, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store double 0.000000e+00, ptr %6, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %71, %1
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %14, label %72

14:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %15 = load double, ptr @l, align 8, !tbaa !5
  %16 = load double, ptr %5, align 8, !tbaa !5
  %17 = fsub double %15, %16
  store double %17, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %18 = load double, ptr %7, align 8, !tbaa !5
  %19 = load double, ptr @v1, align 8, !tbaa !5
  %20 = load double, ptr %3, align 8, !tbaa !5
  %21 = fneg double %19
  %22 = call double @llvm.fmuladd.f64(double %21, double %20, double %18)
  %23 = load double, ptr @v2, align 8, !tbaa !5
  %24 = load double, ptr @v1, align 8, !tbaa !5
  %25 = fsub double %23, %24
  %26 = fdiv double %22, %25
  store double %26, ptr %8, align 8, !tbaa !5
  %27 = load double, ptr %8, align 8, !tbaa !5
  %28 = load double, ptr %3, align 8, !tbaa !5
  %29 = fcmp ogt double %27, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %14
  store i1 false, ptr %2, align 1
  store i32 1, ptr %9, align 4
  br label %69

31:                                               ; preds = %14
  %32 = load double, ptr %8, align 8, !tbaa !5
  %33 = load double, ptr %3, align 8, !tbaa !5
  %34 = fsub double %33, %32
  store double %34, ptr %3, align 8, !tbaa !5
  %35 = load i32, ptr @k, align 4, !tbaa !9
  %36 = load i32, ptr %4, align 4, !tbaa !9
  %37 = sub nsw i32 %36, %35
  store i32 %37, ptr %4, align 4, !tbaa !9
  %38 = load i32, ptr %4, align 4, !tbaa !9
  %39 = icmp sle i32 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %31
  store i1 true, ptr %2, align 1
  store i32 1, ptr %9, align 4
  br label %69

41:                                               ; preds = %31
  %42 = load double, ptr %5, align 8, !tbaa !5
  %43 = load double, ptr @v2, align 8, !tbaa !5
  %44 = load double, ptr %8, align 8, !tbaa !5
  %45 = call double @llvm.fmuladd.f64(double %43, double %44, double %42)
  store double %45, ptr %6, align 8, !tbaa !5
  %46 = load double, ptr @v1, align 8, !tbaa !5
  %47 = load double, ptr %8, align 8, !tbaa !5
  %48 = load double, ptr %5, align 8, !tbaa !5
  %49 = call double @llvm.fmuladd.f64(double %46, double %47, double %48)
  store double %49, ptr %5, align 8, !tbaa !5
  %50 = load double, ptr %6, align 8, !tbaa !5
  %51 = load double, ptr %5, align 8, !tbaa !5
  %52 = fsub double %50, %51
  %53 = load double, ptr @v1, align 8, !tbaa !5
  %54 = load double, ptr @v2, align 8, !tbaa !5
  %55 = fadd double %53, %54
  %56 = fdiv double %52, %55
  store double %56, ptr %8, align 8, !tbaa !5
  %57 = load double, ptr %8, align 8, !tbaa !5
  %58 = load double, ptr %3, align 8, !tbaa !5
  %59 = fcmp ogt double %57, %58
  br i1 %59, label %60, label %61

60:                                               ; preds = %41
  store i1 false, ptr %2, align 1
  store i32 1, ptr %9, align 4
  br label %69

61:                                               ; preds = %41
  %62 = load double, ptr %8, align 8, !tbaa !5
  %63 = load double, ptr %3, align 8, !tbaa !5
  %64 = fsub double %63, %62
  store double %64, ptr %3, align 8, !tbaa !5
  %65 = load double, ptr %5, align 8, !tbaa !5
  %66 = load double, ptr @v1, align 8, !tbaa !5
  %67 = load double, ptr %8, align 8, !tbaa !5
  %68 = call double @llvm.fmuladd.f64(double %66, double %67, double %65)
  store double %68, ptr %6, align 8, !tbaa !5
  store double %68, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %9, align 4
  br label %69

69:                                               ; preds = %61, %60, %40, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %70 = load i32, ptr %9, align 4
  switch i32 %70, label %73 [
    i32 0, label %71
  ]

71:                                               ; preds = %69
  br label %11, !llvm.loop !11

72:                                               ; preds = %11
  store i1 true, ptr %2, align 1
  store i32 1, ptr %9, align 4
  br label %73

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

; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"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"}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@k = external dso_local local_unnamed_addr global i32, align 4
@l = external dso_local local_unnamed_addr global double, align 8
@v1 = external dso_local local_unnamed_addr global double, align 8
@v2 = external dso_local local_unnamed_addr global double, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z1fd(double noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %.thread

.lr.ph:                                           ; preds = %1
  %4 = load double, ptr @l, align 8, !tbaa !9
  %5 = load double, ptr @v1, align 8, !tbaa !9
  %6 = fneg double %5
  %7 = load double, ptr @v2, align 8, !tbaa !9
  %8 = fsub double %7, %5
  %9 = load i32, ptr @k, align 4
  %10 = fadd double %5, %7
  %11 = tail call double @llvm.fmuladd.f64(double %6, double %0, double %4)
  %12 = fdiv double %11, %8
  %13 = fcmp ogt double %12, %0
  br i1 %13, label %.thread, label %.lr.ph53

.lr.ph53:                                         ; preds = %.lr.ph, %24
  %14 = phi double [ %29, %24 ], [ %12, %.lr.ph ]
  %.0284152 = phi double [ %25, %24 ], [ %0, %.lr.ph ]
  %.0264251 = phi i32 [ %16, %24 ], [ %2, %.lr.ph ]
  %.0244350 = phi double [ %26, %24 ], [ 0.000000e+00, %.lr.ph ]
  %15 = fsub double %.0284152, %14
  %16 = sub nsw i32 %.0264251, %9
  %17 = icmp slt i32 %16, 1
  br i1 %17, label %.thread, label %18

18:                                               ; preds = %.lr.ph53
  %19 = tail call double @llvm.fmuladd.f64(double %7, double %14, double %.0244350)
  %20 = tail call double @llvm.fmuladd.f64(double %5, double %14, double %.0244350)
  %21 = fsub double %19, %20
  %22 = fdiv double %21, %10
  %23 = fcmp ogt double %22, %15
  br i1 %23, label %.thread, label %24

24:                                               ; preds = %18
  %25 = fsub double %15, %22
  %26 = tail call double @llvm.fmuladd.f64(double %5, double %22, double %20)
  %27 = fsub double %4, %26
  %28 = tail call double @llvm.fmuladd.f64(double %6, double %25, double %27)
  %29 = fdiv double %28, %8
  %30 = fcmp ogt double %29, %25
  br i1 %30, label %.thread, label %.lr.ph53

.thread:                                          ; preds = %18, %.lr.ph53, %24, %.lr.ph, %1
  %.2 = phi i1 [ true, %1 ], [ false, %.lr.ph ], [ %17, %24 ], [ %17, %.lr.ph53 ], [ %17, %18 ]
  ret i1 %.2
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) 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 speculatable willreturn memory(none) }

!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}


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