; LLVM IR from ADJA/algos :: DP/ConvexHullTrick.ll (Z6setCurx)

; 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::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@mvals = external dso_local global %"class.std::vector", align 8
@bvals = external dso_local global %"class.std::vector", align 8
@cur = external dso_local global i32, align 4

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6setCurx(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  %3 = load i32, ptr @cur, align 4, !tbaa !9
  %4 = call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @mvals) #2
  %5 = trunc i64 %4 to i32
  %6 = sub nsw i32 %5, 1
  %7 = icmp sgt i32 %3, %6
  br i1 %7, label %8, label %12

8:                                                ; preds = %1
  %9 = call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @mvals) #2
  %10 = trunc i64 %9 to i32
  %11 = sub nsw i32 %10, 1
  store i32 %11, ptr @cur, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %8, %1
  br label %13

13:                                               ; preds = %53, %12
  %14 = load i32, ptr @cur, align 4, !tbaa !9
  %15 = call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @mvals) #2
  %16 = trunc i64 %15 to i32
  %17 = sub nsw i32 %16, 1
  %18 = icmp slt i32 %14, %17
  br i1 %18, label %19, label %51

19:                                               ; preds = %13
  %20 = load i32, ptr @cur, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  %22 = sext i32 %21 to i64
  %23 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @mvals, i64 noundef %22) #2
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = sitofp i64 %24 to double
  %26 = fmul double 1.000000e+00, %25
  %27 = load i64, ptr %2, align 8, !tbaa !5
  %28 = sitofp i64 %27 to double
  %29 = load i32, ptr @cur, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  %31 = sext i32 %30 to i64
  %32 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @bvals, i64 noundef %31) #2
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = sitofp i64 %33 to double
  %35 = call double @llvm.fmuladd.f64(double %26, double %28, double %34)
  %36 = load i32, ptr @cur, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @mvals, i64 noundef %37) #2
  %39 = load i64, ptr %38, align 8, !tbaa !5
  %40 = sitofp i64 %39 to double
  %41 = fmul double 1.000000e+00, %40
  %42 = load i64, ptr %2, align 8, !tbaa !5
  %43 = sitofp i64 %42 to double
  %44 = load i32, ptr @cur, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @bvals, i64 noundef %45) #2
  %47 = load i64, ptr %46, align 8, !tbaa !5
  %48 = sitofp i64 %47 to double
  %49 = call double @llvm.fmuladd.f64(double %41, double %43, double %48)
  %50 = fcmp ole double %35, %49
  br label %51

51:                                               ; preds = %19, %13
  %52 = phi i1 [ false, %13 ], [ %50, %19 ]
  br i1 %52, label %53, label %56

53:                                               ; preds = %51
  %54 = load i32, ptr @cur, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr @cur, align 4, !tbaa !9
  br label %13, !llvm.loop !11

56:                                               ; preds = %51
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 speculatable willreturn memory(none) }
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, !6, i64 0}
!6 = !{!"long long", !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"

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@mvals = external dso_local global %"class.std::vector", align 8
@bvals = external dso_local global %"class.std::vector", align 8
@cur = external dso_local local_unnamed_addr global i32, align 4

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6setCurx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @cur, align 4, !tbaa !5
  %3 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @mvals) #2
  %4 = trunc i64 %3 to i32
  %.not = icmp slt i32 %2, %4
  br i1 %.not, label %._crit_edge, label %5

._crit_edge:                                      ; preds = %1
  %.pre = load i32, ptr @cur, align 4, !tbaa !5
  br label %9

5:                                                ; preds = %1
  %6 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @mvals) #2
  %7 = trunc i64 %6 to i32
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr @cur, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %._crit_edge, %5
  %10 = phi i32 [ %.pre, %._crit_edge ], [ %8, %5 ]
  %11 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @mvals) #2
  %12 = trunc i64 %11 to i32
  %13 = add nsw i32 %12, -1
  %14 = icmp slt i32 %10, %13
  br i1 %14, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %9
  %15 = sitofp i64 %0 to double
  br label %16

16:                                               ; preds = %.lr.ph, %42
  %17 = load i32, ptr @cur, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  %19 = sext i32 %18 to i64
  %20 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @mvals, i64 noundef %19) #2
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = sitofp i64 %21 to double
  %23 = load i32, ptr @cur, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @bvals, i64 noundef %25) #2
  %27 = load i64, ptr %26, align 8, !tbaa !9
  %28 = sitofp i64 %27 to double
  %29 = tail call double @llvm.fmuladd.f64(double %22, double %15, double %28)
  %30 = load i32, ptr @cur, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @mvals, i64 noundef %31) #2
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = sitofp i64 %33 to double
  %35 = load i32, ptr @cur, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @bvals, i64 noundef %36) #2
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = sitofp i64 %38 to double
  %40 = tail call double @llvm.fmuladd.f64(double %34, double %15, double %39)
  %41 = fcmp ugt double %29, %40
  br i1 %41, label %.critedge, label %42

42:                                               ; preds = %16
  %43 = load i32, ptr @cur, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr @cur, align 4, !tbaa !5
  %45 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @mvals) #2
  %46 = trunc i64 %45 to i32
  %47 = add nsw i32 %46, -1
  %48 = icmp slt i32 %44, %47
  br i1 %48, label %16, label %.critedge, !llvm.loop !11

.critedge:                                        ; preds = %16, %42, %9
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 speculatable willreturn memory(none) }
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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass