; LLVM IR from aspuru-guzik-group/qtorch :: nlopt-2.4.2/stogo/tools.ll (ZN4TBox11LongestSideEPi)

; 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.VBox = type { %class.RVector, %class.RVector }
%class.RVector = type { i32, ptr }

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN4VBox6GetDimEv(ptr noundef nonnull align 8 dereferenceable(32)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #1 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN4TBox11LongestSideEPi(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %10 = call noundef i32 @_ZN4VBox6GetDimEv(ptr noundef nonnull align 8 dereferenceable(32) %9)
  store i32 %10, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %11 = getelementptr inbounds %class.VBox, ptr %9, i32 0, i32 1
  %12 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %11, i32 noundef 0)
  %13 = load double, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds %class.VBox, ptr %9, i32 0, i32 0
  %15 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %14, i32 noundef 0)
  %16 = load double, ptr %15, align 8, !tbaa !11
  %17 = fsub double %13, %16
  store double %17, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %47, %2
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = load i32, ptr %5, 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 %8) #3
  br label %50

23:                                               ; preds = %18
  %24 = getelementptr inbounds %class.VBox, ptr %9, i32 0, i32 1
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %24, i32 noundef %25)
  %27 = load double, ptr %26, align 8, !tbaa !11
  %28 = getelementptr inbounds %class.VBox, ptr %9, i32 0, i32 0
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %28, i32 noundef %29)
  %31 = load double, ptr %30, align 8, !tbaa !11
  %32 = fsub double %27, %31
  %33 = load double, ptr %7, align 8, !tbaa !11
  %34 = fcmp ogt double %32, %33
  br i1 %34, label %35, label %46

35:                                               ; preds = %23
  %36 = getelementptr inbounds %class.VBox, ptr %9, i32 0, i32 1
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %36, i32 noundef %37)
  %39 = load double, ptr %38, align 8, !tbaa !11
  %40 = getelementptr inbounds %class.VBox, ptr %9, i32 0, i32 0
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %40, i32 noundef %41)
  %43 = load double, ptr %42, align 8, !tbaa !11
  %44 = fsub double %39, %43
  store double %44, ptr %7, align 8, !tbaa !11
  %45 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %45, ptr %6, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %35, %23
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %8, align 4, !tbaa !9
  br label %18, !llvm.loop !13

50:                                               ; preds = %22
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 %51, ptr %52, align 4, !tbaa !9
  %53 = load double, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret double %53
}

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 uwtable
declare dso_local noundef i32 @_ZN4VBox6GetDimEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN4TBox11LongestSideEPi(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 align 2 {
  %3 = tail call noundef i32 @_ZN4VBox6GetDimEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %4, i32 noundef 0)
  %6 = load double, ptr %5, align 8, !tbaa !5
  %7 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef 0)
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = fsub double %6, %8
  %10 = icmp sgt i32 %3, 1
  br i1 %10, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %23, %2
  %.013.lcssa = phi i32 [ 0, %2 ], [ %.114, %23 ]
  %.012.lcssa = phi double [ %9, %2 ], [ %.1, %23 ]
  store i32 %.013.lcssa, ptr %1, align 4, !tbaa !9
  ret double %.012.lcssa

.lr.ph:                                           ; preds = %2, %23
  %.017 = phi i32 [ %24, %23 ], [ 1, %2 ]
  %.01216 = phi double [ %.1, %23 ], [ %9, %2 ]
  %.01315 = phi i32 [ %.114, %23 ], [ 0, %2 ]
  %11 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %4, i32 noundef %.017)
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.017)
  %14 = load double, ptr %13, align 8, !tbaa !5
  %15 = fsub double %12, %14
  %16 = fcmp ogt double %15, %.01216
  br i1 %16, label %17, label %23

17:                                               ; preds = %.lr.ph
  %18 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %4, i32 noundef %.017)
  %19 = load double, ptr %18, align 8, !tbaa !5
  %20 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.017)
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = fsub double %19, %21
  br label %23

23:                                               ; preds = %.lr.ph, %17
  %.114 = phi i32 [ %.017, %17 ], [ %.01315, %.lr.ph ]
  %.1 = phi double [ %22, %17 ], [ %.01216, %.lr.ph ]
  %24 = add nuw nsw i32 %.017, 1
  %exitcond.not = icmp eq i32 %24, %3
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11
}

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 = { 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" }

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


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