; LLVM IR from Tencent-RoboticsX/jbdl :: src/jbdl/experimental/qpoases/src/Utils.ll (ZN7qpOASES7getNormEPKdii)

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

@.str.4 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [100 x i8], align 1

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

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

declare noundef ptr @_ZN7qpOASES23getGlobalMessageHandlerEv() #1

declare noundef i32 @_ZN7qpOASES15MessageHandling10throwErrorENS_11returnValueEPKcS3_S3_mNS_16VisibilityStatusE(ptr noundef nonnull align 8 dereferenceable(28), i32 noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN7qpOASES7getNormEPKdii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store double 0.000000e+00, ptr %9, align 8, !tbaa !11
  %11 = load i32, ptr %7, align 4, !tbaa !9
  switch i32 %11, label %55 [
    i32 2, label %12
    i32 1, label %36
  ]

12:                                               ; preds = %3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %30, %12
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %17, label %33

17:                                               ; preds = %13
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds double, ptr %18, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !11
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds double, ptr %23, i64 %25
  %27 = load double, ptr %26, align 8, !tbaa !11
  %28 = load double, ptr %9, align 8, !tbaa !11
  %29 = call double @llvm.fmuladd.f64(double %22, double %27, double %28)
  store double %29, ptr %9, align 8, !tbaa !11
  br label %30

30:                                               ; preds = %17
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %8, align 4, !tbaa !9
  br label %13, !llvm.loop !13

33:                                               ; preds = %13
  %34 = load double, ptr %9, align 8, !tbaa !11
  %35 = call noundef double @_ZN7qpOASES7getSqrtEd(double noundef %34)
  store double %35, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %58

36:                                               ; preds = %3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %50, %36
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %41, label %53

41:                                               ; preds = %37
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds double, ptr %42, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !11
  %47 = call noundef double @_ZN7qpOASES6getAbsEd(double noundef %46)
  %48 = load double, ptr %9, align 8, !tbaa !11
  %49 = fadd double %48, %47
  store double %49, ptr %9, align 8, !tbaa !11
  br label %50

50:                                               ; preds = %41
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %8, align 4, !tbaa !9
  br label %37, !llvm.loop !15

53:                                               ; preds = %37
  %54 = load double, ptr %9, align 8, !tbaa !11
  store double %54, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %58

55:                                               ; preds = %3
  %56 = call noundef ptr @_ZN7qpOASES23getGlobalMessageHandlerEv()
  %57 = call noundef i32 @_ZN7qpOASES15MessageHandling10throwErrorENS_11returnValueEPKcS3_S3_mNS_16VisibilityStatusE(ptr noundef nonnull align 8 dereferenceable(28) %56, i32 noundef 3, ptr noundef null, ptr noundef @.str.4, ptr noundef @.str.5, i64 noundef 622, i32 noundef 1)
  store double -1.000000e+20, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %58

58:                                               ; preds = %55, %53, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %59 = load double, ptr %4, align 8
  ret double %59
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZN7qpOASES7getSqrtEd(double noundef) #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZN7qpOASES6getAbsEd(double noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #5 = { 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"}
!15 = distinct !{!15, !14}


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

@.str.4 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [100 x i8], align 1

declare noundef ptr @_ZN7qpOASES23getGlobalMessageHandlerEv() local_unnamed_addr #0

declare noundef i32 @_ZN7qpOASES15MessageHandling10throwErrorENS_11returnValueEPKcS3_S3_mNS_16VisibilityStatusE(ptr noundef nonnull align 8 dereferenceable(28), i32 noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN7qpOASES7getNormEPKdii(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  switch i32 %2, label %27 [
    i32 2, label %.preheader
    i32 1, label %.preheader20
  ]

.preheader20:                                     ; preds = %3
  %4 = icmp sgt i32 %1, 0
  br i1 %4, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.preheader20
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph

.preheader:                                       ; preds = %3
  %5 = icmp sgt i32 %1, 0
  br i1 %5, label %.lr.ph25.preheader, label %._crit_edge

.lr.ph25.preheader:                               ; preds = %.preheader
  %wide.trip.count32 = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count32, 3
  %6 = icmp ult i32 %1, 4
  br i1 %6, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph25.preheader.new

.lr.ph25.preheader.new:                           ; preds = %.lr.ph25.preheader
  %unroll_iter = and i64 %wide.trip.count32, 2147483644
  br label %.lr.ph25

.lr.ph25:                                         ; preds = %.lr.ph25, %.lr.ph25.preheader.new
  %indvars.iv29 = phi i64 [ 0, %.lr.ph25.preheader.new ], [ %indvars.iv.next30.3, %.lr.ph25 ]
  %.024 = phi double [ 0.000000e+00, %.lr.ph25.preheader.new ], [ %18, %.lr.ph25 ]
  %niter = phi i64 [ 0, %.lr.ph25.preheader.new ], [ %niter.next.3, %.lr.ph25 ]
  %7 = getelementptr inbounds double, ptr %0, i64 %indvars.iv29
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = tail call double @llvm.fmuladd.f64(double %8, double %8, double %.024)
  %indvars.iv.next30 = or disjoint i64 %indvars.iv29, 1
  %10 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next30
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = tail call double @llvm.fmuladd.f64(double %11, double %11, double %9)
  %indvars.iv.next30.1 = or disjoint i64 %indvars.iv29, 2
  %13 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next30.1
  %14 = load double, ptr %13, align 8, !tbaa !5
  %15 = tail call double @llvm.fmuladd.f64(double %14, double %14, double %12)
  %indvars.iv.next30.2 = or disjoint i64 %indvars.iv29, 3
  %16 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next30.2
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %15)
  %indvars.iv.next30.3 = add nuw nsw i64 %indvars.iv29, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph25, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph25, %.lr.ph25.preheader
  %.lcssa.ph = phi double [ poison, %.lr.ph25.preheader ], [ %18, %.lr.ph25 ]
  %indvars.iv29.unr = phi i64 [ 0, %.lr.ph25.preheader ], [ %indvars.iv.next30.3, %.lr.ph25 ]
  %.024.unr = phi double [ 0.000000e+00, %.lr.ph25.preheader ], [ %18, %.lr.ph25 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph25.epil

.lr.ph25.epil:                                    ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph25.epil
  %indvars.iv29.epil = phi i64 [ %indvars.iv.next30.epil, %.lr.ph25.epil ], [ %indvars.iv29.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.024.epil = phi double [ %21, %.lr.ph25.epil ], [ %.024.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph25.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %19 = getelementptr inbounds double, ptr %0, i64 %indvars.iv29.epil
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = tail call double @llvm.fmuladd.f64(double %20, double %20, double %.024.epil)
  %indvars.iv.next30.epil = add nuw nsw i64 %indvars.iv29.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph25.epil, !llvm.loop !11

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph25.epil, %.preheader
  %.0.lcssa = phi double [ 0.000000e+00, %.preheader ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %21, %.lr.ph25.epil ]
  %22 = tail call noundef double @_ZN7qpOASES7getSqrtEd(double noundef %.0.lcssa)
  br label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.122 = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %26, %.lr.ph ]
  %23 = getelementptr inbounds double, ptr %0, i64 %indvars.iv
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = tail call noundef double @_ZN7qpOASES6getAbsEd(double noundef %24)
  %26 = fadd double %.122, %25
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !13

27:                                               ; preds = %3
  %28 = tail call noundef ptr @_ZN7qpOASES23getGlobalMessageHandlerEv()
  %29 = tail call noundef i32 @_ZN7qpOASES15MessageHandling10throwErrorENS_11returnValueEPKcS3_S3_mNS_16VisibilityStatusE(ptr noundef nonnull align 8 dereferenceable(28) %28, i32 noundef 3, ptr noundef null, ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.5, i64 noundef 622, i32 noundef 1)
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %.preheader20, %27, %._crit_edge
  %.019 = phi double [ -1.000000e+20, %27 ], [ %22, %._crit_edge ], [ 0.000000e+00, %.preheader20 ], [ %26, %.lr.ph ]
  ret double %.019
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZN7qpOASES7getSqrtEd(double noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZN7qpOASES6getAbsEd(double noundef) local_unnamed_addr #3

attributes #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 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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" }

!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"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !10}


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