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

; 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 @_ZN4TBox11ClosestSideERK7RVector(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %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 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %10 = call noundef i32 @_ZN4VBox6GetDimEv(ptr noundef nonnull align 8 dereferenceable(32) %9)
  store i32 %10, ptr %7, align 4, !tbaa !9
  store double 0x7FEFFFFFFFFFFFFF, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %67, %2
  %12 = load i32, ptr %8, align 4, !tbaa !9
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %70

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

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

46:                                               ; preds = %16
  %47 = getelementptr inbounds %class.VBox, ptr %9, i32 0, i32 1
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %47, i32 noundef %48)
  %50 = load double, ptr %49, align 8, !tbaa !11
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %51, i32 noundef %52)
  %54 = load double, ptr %53, align 8, !tbaa !11
  %55 = fsub double %50, %54
  br label %56

56:                                               ; preds = %46, %36
  %57 = phi double [ %45, %36 ], [ %55, %46 ]
  store double %57, ptr %6, align 8, !tbaa !11
  %58 = load double, ptr %5, align 8, !tbaa !11
  %59 = load double, ptr %6, align 8, !tbaa !11
  %60 = fcmp olt double %58, %59
  br i1 %60, label %61, label %63

61:                                               ; preds = %56
  %62 = load double, ptr %5, align 8, !tbaa !11
  br label %65

63:                                               ; preds = %56
  %64 = load double, ptr %6, align 8, !tbaa !11
  br label %65

65:                                               ; preds = %63, %61
  %66 = phi double [ %62, %61 ], [ %64, %63 ]
  store double %66, ptr %5, align 8, !tbaa !11
  br label %67

67:                                               ; preds = %65
  %68 = load i32, ptr %8, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %8, align 4, !tbaa !9
  br label %11, !llvm.loop !13

70:                                               ; preds = %15
  %71 = load double, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret double %71
}

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 @_ZN4TBox11ClosestSideERK7RVector(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) local_unnamed_addr #0 align 2 {
  %3 = tail call noundef i32 @_ZN4VBox6GetDimEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  br label %6

._crit_edge:                                      ; preds = %6, %2
  %.020.lcssa = phi double [ 0x7FEFFFFFFFFFFFFF, %2 ], [ %24, %6 ]
  ret double %.020.lcssa

6:                                                ; preds = %.lr.ph, %6
  %.022 = phi i32 [ 0, %.lr.ph ], [ %25, %6 ]
  %.02021 = phi double [ 0x7FEFFFFFFFFFFFFF, %.lr.ph ], [ %24, %6 ]
  %7 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %.022)
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.022)
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = fsub double %8, %10
  %12 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %5, i32 noundef %.022)
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %.022)
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = fsub double %13, %15
  %17 = fcmp olt double %11, %16
  %. = select i1 %17, ptr %1, ptr %5
  %.27 = select i1 %17, ptr %0, ptr %1
  %18 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RVectorclEi(ptr noundef nonnull align 8 dereferenceable(16) %., i32 noundef %.022)
  %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) %.27, i32 noundef %.022)
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = fsub double %19, %21
  %23 = fcmp olt double %.02021, %22
  %24 = select i1 %23, double %.02021, double %22
  %25 = add nuw nsw i32 %.022, 1
  %exitcond.not = icmp eq i32 %25, %3
  br i1 %exitcond.not, label %._crit_edge, label %6, !llvm.loop !9
}

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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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