; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/320 Division 1/Problem C/C.ll (Z1fe)

; 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
@a = external dso_local global [200100 x x86_fp80], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef x86_fp80 @_Z1fe(x86_fp80 noundef %0) #0 {
  %2 = alloca x86_fp80, align 16
  %3 = alloca x86_fp80, align 16
  %4 = alloca x86_fp80, align 16
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca x86_fp80, align 16
  store x86_fp80 %0, ptr %2, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #3
  %8 = load x86_fp80, ptr %2, align 16, !tbaa !5
  %9 = fneg x86_fp80 %8
  %10 = load x86_fp80, ptr @a, align 16, !tbaa !5
  %11 = fadd x86_fp80 %9, %10
  store x86_fp80 %11, ptr %3, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #3
  %12 = load x86_fp80, ptr %3, align 16, !tbaa !5
  %13 = call noundef x86_fp80 @_ZSt3abse(x86_fp80 noundef %12)
  store x86_fp80 %13, ptr %4, align 16, !tbaa !5
  %14 = load x86_fp80, ptr %3, align 16, !tbaa !5
  %15 = fcmp olt x86_fp80 %14, 0xK00000000000000000000
  br i1 %15, label %16, label %17

16:                                               ; preds = %1
  store x86_fp80 0xK00000000000000000000, ptr %3, align 16, !tbaa !5
  br label %17

17:                                               ; preds = %16, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %39, %17
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = load i32, ptr @n, align 4, !tbaa !9
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %42

23:                                               ; preds = %18
  %24 = load x86_fp80, ptr %2, align 16, !tbaa !5
  %25 = fneg x86_fp80 %24
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [200100 x x86_fp80], ptr @a, i64 0, i64 %27
  %29 = load x86_fp80, ptr %28, align 16, !tbaa !5
  %30 = fadd x86_fp80 %25, %29
  %31 = load x86_fp80, ptr %3, align 16, !tbaa !5
  %32 = fadd x86_fp80 %31, %30
  store x86_fp80 %32, ptr %3, align 16, !tbaa !5
  %33 = load x86_fp80, ptr %3, align 16, !tbaa !5
  %34 = fcmp olt x86_fp80 %33, 0xK00000000000000000000
  br i1 %34, label %35, label %36

35:                                               ; preds = %23
  store x86_fp80 0xK00000000000000000000, ptr %3, align 16, !tbaa !5
  br label %36

36:                                               ; preds = %35, %23
  %37 = call noundef nonnull align 16 dereferenceable(16) ptr @_ZSt3maxIeERKT_S2_S2_(ptr noundef nonnull align 16 dereferenceable(16) %4, ptr noundef nonnull align 16 dereferenceable(16) %3)
  %38 = load x86_fp80, ptr %37, align 16, !tbaa !5
  store x86_fp80 %38, ptr %4, align 16, !tbaa !5
  br label %39

39:                                               ; preds = %36
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %5, align 4, !tbaa !9
  br label %18, !llvm.loop !11

42:                                               ; preds = %22
  %43 = load x86_fp80, ptr %2, align 16, !tbaa !5
  %44 = fneg x86_fp80 %43
  %45 = load x86_fp80, ptr @a, align 16, !tbaa !5
  %46 = fadd x86_fp80 %44, %45
  store x86_fp80 %46, ptr %3, align 16, !tbaa !5
  %47 = load x86_fp80, ptr %3, align 16, !tbaa !5
  %48 = fcmp ogt x86_fp80 %47, 0xK00000000000000000000
  br i1 %48, label %49, label %50

49:                                               ; preds = %42
  store x86_fp80 0xK00000000000000000000, ptr %3, align 16, !tbaa !5
  br label %50

50:                                               ; preds = %49, %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %74, %50
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = load i32, ptr @n, align 4, !tbaa !9
  %54 = icmp slt i32 %52, %53
  br i1 %54, label %56, label %55

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

56:                                               ; preds = %51
  %57 = load x86_fp80, ptr %2, align 16, !tbaa !5
  %58 = fneg x86_fp80 %57
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [200100 x x86_fp80], ptr @a, i64 0, i64 %60
  %62 = load x86_fp80, ptr %61, align 16, !tbaa !5
  %63 = fadd x86_fp80 %58, %62
  %64 = load x86_fp80, ptr %3, align 16, !tbaa !5
  %65 = fadd x86_fp80 %64, %63
  store x86_fp80 %65, ptr %3, align 16, !tbaa !5
  %66 = load x86_fp80, ptr %3, align 16, !tbaa !5
  %67 = fcmp ogt x86_fp80 %66, 0xK00000000000000000000
  br i1 %67, label %68, label %69

68:                                               ; preds = %56
  store x86_fp80 0xK00000000000000000000, ptr %3, align 16, !tbaa !5
  br label %69

69:                                               ; preds = %68, %56
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  %70 = load x86_fp80, ptr %3, align 16, !tbaa !5
  %71 = call noundef x86_fp80 @_ZSt3abse(x86_fp80 noundef %70)
  store x86_fp80 %71, ptr %7, align 16, !tbaa !5
  %72 = call noundef nonnull align 16 dereferenceable(16) ptr @_ZSt3maxIeERKT_S2_S2_(ptr noundef nonnull align 16 dereferenceable(16) %4, ptr noundef nonnull align 16 dereferenceable(16) %7)
  %73 = load x86_fp80, ptr %72, align 16, !tbaa !5
  store x86_fp80 %73, ptr %4, align 16, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  br label %74

74:                                               ; preds = %69
  %75 = load i32, ptr %6, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %6, align 4, !tbaa !9
  br label %51, !llvm.loop !13

77:                                               ; preds = %55
  %78 = load x86_fp80, ptr %4, align 16, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #3
  ret x86_fp80 %78
}

; 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 x86_fp80 @_ZSt3abse(x86_fp80 noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 16 dereferenceable(16) ptr @_ZSt3maxIeERKT_S2_S2_(ptr noundef nonnull align 16 dereferenceable(16), ptr noundef nonnull align 16 dereferenceable(16)) #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 = !{!"long 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"

@n = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [200100 x x86_fp80], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef x86_fp80 @_Z1fe(x86_fp80 noundef %0) local_unnamed_addr #0 {
  %2 = alloca x86_fp80, align 16
  %3 = alloca x86_fp80, align 16
  %4 = alloca x86_fp80, align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #3
  %5 = load x86_fp80, ptr @a, align 16, !tbaa !5
  %6 = fsub x86_fp80 %5, %0
  store x86_fp80 %6, ptr %2, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #3
  %7 = tail call noundef x86_fp80 @_ZSt3abse(x86_fp80 noundef %6)
  store x86_fp80 %7, ptr %3, align 16, !tbaa !5
  %8 = fcmp olt x86_fp80 %6, 0xK00000000000000000000
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store x86_fp80 0xK00000000000000000000, ptr %2, align 16, !tbaa !5
  br label %10

10:                                               ; preds = %9, %1
  %11 = load i32, ptr @n, align 4, !tbaa !9
  %12 = icmp sgt i32 %11, 1
  br i1 %12, label %.lr.ph, label %._crit_edge16

._crit_edge:                                      ; preds = %.lr.ph
  %13 = icmp sgt i32 %25, 1
  %14 = load x86_fp80, ptr @a, align 16, !tbaa !5
  %15 = fsub x86_fp80 %14, %0
  %16 = fcmp ogt x86_fp80 %15, 0xK00000000000000000000
  %storemerge = select i1 %16, x86_fp80 0xK00000000000000000000, x86_fp80 %15
  store x86_fp80 %storemerge, ptr %2, align 16, !tbaa !5
  br i1 %13, label %.lr.ph15, label %._crit_edge16

.lr.ph:                                           ; preds = %10, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %10 ]
  %17 = getelementptr inbounds [200100 x x86_fp80], ptr @a, i64 0, i64 %indvars.iv
  %18 = load x86_fp80, ptr %17, align 16, !tbaa !5
  %19 = fsub x86_fp80 %18, %0
  %20 = load x86_fp80, ptr %2, align 16, !tbaa !5
  %21 = fadd x86_fp80 %20, %19
  %22 = fcmp olt x86_fp80 %21, 0xK00000000000000000000
  %storemerge11 = select i1 %22, x86_fp80 0xK00000000000000000000, x86_fp80 %21
  store x86_fp80 %storemerge11, ptr %2, align 16, !tbaa !5
  %23 = call noundef nonnull align 16 dereferenceable(16) ptr @_ZSt3maxIeERKT_S2_S2_(ptr noundef nonnull align 16 dereferenceable(16) %3, ptr noundef nonnull align 16 dereferenceable(16) %2)
  %24 = load x86_fp80, ptr %23, align 16, !tbaa !5
  store x86_fp80 %24, ptr %3, align 16, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = load i32, ptr @n, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = icmp slt i64 %indvars.iv.next, %26
  br i1 %27, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge16:                                    ; preds = %.lr.ph15, %10, %._crit_edge
  %28 = phi x86_fp80 [ %24, %._crit_edge ], [ %7, %10 ], [ %37, %.lr.ph15 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #3
  ret x86_fp80 %28

.lr.ph15:                                         ; preds = %._crit_edge, %.lr.ph15
  %indvars.iv18 = phi i64 [ %indvars.iv.next19, %.lr.ph15 ], [ 1, %._crit_edge ]
  %29 = getelementptr inbounds [200100 x x86_fp80], ptr @a, i64 0, i64 %indvars.iv18
  %30 = load x86_fp80, ptr %29, align 16, !tbaa !5
  %31 = fsub x86_fp80 %30, %0
  %32 = load x86_fp80, ptr %2, align 16, !tbaa !5
  %33 = fadd x86_fp80 %32, %31
  %34 = fcmp ogt x86_fp80 %33, 0xK00000000000000000000
  %storemerge10 = select i1 %34, x86_fp80 0xK00000000000000000000, x86_fp80 %33
  store x86_fp80 %storemerge10, ptr %2, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  %35 = call noundef x86_fp80 @_ZSt3abse(x86_fp80 noundef %storemerge10)
  store x86_fp80 %35, ptr %4, align 16, !tbaa !5
  %36 = call noundef nonnull align 16 dereferenceable(16) ptr @_ZSt3maxIeERKT_S2_S2_(ptr noundef nonnull align 16 dereferenceable(16) %3, ptr noundef nonnull align 16 dereferenceable(16) %4)
  %37 = load x86_fp80, ptr %36, align 16, !tbaa !5
  store x86_fp80 %37, ptr %3, align 16, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  %indvars.iv.next19 = add nuw nsw i64 %indvars.iv18, 1
  %38 = load i32, ptr @n, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = icmp slt i64 %indvars.iv.next19, %39
  br i1 %40, label %.lr.ph15, label %._crit_edge16, !llvm.loop !13
}

; Function Attrs: mustprogress 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 x86_fp80 @_ZSt3abse(x86_fp80 noundef) local_unnamed_addr #2

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

; 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 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 = !{!6, !6, i64 0}
!6 = !{!"long 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}


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