; LLVM IR from ayush-tulsyan/ACM-ICPC-Handbook :: code/Geometry.ll (Z17ComputeSignedAreaRKSt6vectorI2PTSaIS0_EE)

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

%struct.PT = type { double, double }

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

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI2PTSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorI2PTSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

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

6:                                                ; preds = %50, %1
  %7 = load i32, ptr %4, align 4, !tbaa !11
  %8 = sext i32 %7 to i64
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = call noundef i64 @_ZNKSt6vectorI2PTSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %9) #3
  %11 = icmp ult i64 %8, %10
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %14 = load i32, ptr %4, align 4, !tbaa !11
  %15 = add nsw i32 %14, 1
  %16 = sext i32 %15 to i64
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = call noundef i64 @_ZNKSt6vectorI2PTSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %17) #3
  %19 = urem i64 %16, %18
  %20 = trunc i64 %19 to i32
  store i32 %20, ptr %5, align 4, !tbaa !11
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !11
  %23 = sext i32 %22 to i64
  %24 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorI2PTSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %21, i64 noundef %23) #3
  %25 = getelementptr inbounds %struct.PT, ptr %24, i32 0, i32 0
  %26 = load double, ptr %25, align 8, !tbaa !13
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !11
  %29 = sext i32 %28 to i64
  %30 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorI2PTSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %27, i64 noundef %29) #3
  %31 = getelementptr inbounds %struct.PT, ptr %30, i32 0, i32 1
  %32 = load double, ptr %31, align 8, !tbaa !15
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !11
  %35 = sext i32 %34 to i64
  %36 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorI2PTSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %33, i64 noundef %35) #3
  %37 = getelementptr inbounds %struct.PT, ptr %36, i32 0, i32 0
  %38 = load double, ptr %37, align 8, !tbaa !13
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !11
  %41 = sext i32 %40 to i64
  %42 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorI2PTSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %39, i64 noundef %41) #3
  %43 = getelementptr inbounds %struct.PT, ptr %42, i32 0, i32 1
  %44 = load double, ptr %43, align 8, !tbaa !15
  %45 = fmul double %38, %44
  %46 = fneg double %45
  %47 = call double @llvm.fmuladd.f64(double %26, double %32, double %46)
  %48 = load double, ptr %3, align 8, !tbaa !9
  %49 = fadd double %48, %47
  store double %49, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %50

50:                                               ; preds = %13
  %51 = load i32, ptr %4, align 4, !tbaa !11
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %4, align 4, !tbaa !11
  br label %6, !llvm.loop !16

53:                                               ; preds = %12
  %54 = load double, ptr %3, align 8, !tbaa !9
  %55 = fdiv double %54, 2.000000e+00
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret double %55
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTS2PT", !10, i64 0, !10, i64 8}
!15 = !{!14, !10, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"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"

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI2PTSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorI2PTSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z17ComputeSignedAreaRKSt6vectorI2PTSaIS0_EE(ptr noundef nonnull align 8 dereferenceable(24) %0) local_unnamed_addr #1 {
  %2 = tail call noundef i64 @_ZNKSt6vectorI2PTSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %3 = fmul double %19, 5.000000e-01
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.0.lcssa = phi double [ 0.000000e+00, %1 ], [ %3, %._crit_edge.loopexit ]
  ret double %.0.lcssa

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %1 ]
  %.017 = phi double [ %19, %.lr.ph ], [ 0.000000e+00, %1 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %4 = tail call noundef i64 @_ZNKSt6vectorI2PTSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2
  %5 = urem i64 %indvars.iv.next, %4
  %6 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorI2PTSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv) #2
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorI2PTSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %5) #2
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  %10 = load double, ptr %9, align 8, !tbaa !10
  %11 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorI2PTSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %5) #2
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorI2PTSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv) #2
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  %15 = load double, ptr %14, align 8, !tbaa !10
  %16 = fneg double %12
  %17 = fmul double %15, %16
  %18 = tail call double @llvm.fmuladd.f64(double %7, double %10, double %17)
  %19 = fadd double %.017, %18
  %20 = tail call noundef i64 @_ZNKSt6vectorI2PTSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2
  %21 = icmp ugt i64 %20, %indvars.iv.next
  br i1 %21, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !11
}

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


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