; LLVM IR from Derek-TH-Wang/quadruped_ctrl :: src/osqp/lin_sys/direct/qdldl/qdldl_sources/tests (qdldl_tester)

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

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

10:                                               ; preds = %43, %3
  %11 = load i64, ptr %9, align 8, !tbaa !9
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = icmp slt i64 %11, %12
  br i1 %13, label %14, label %46

14:                                               ; preds = %10
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load i64, ptr %9, align 8, !tbaa !9
  %17 = getelementptr inbounds double, ptr %15, i64 %16
  %18 = load double, ptr %17, align 8, !tbaa !11
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load i64, ptr %9, align 8, !tbaa !9
  %21 = getelementptr inbounds double, ptr %19, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !11
  %23 = fsub double %18, %22
  store double %23, ptr %8, align 8, !tbaa !11
  %24 = load double, ptr %8, align 8, !tbaa !11
  %25 = load double, ptr %7, align 8, !tbaa !11
  %26 = fcmp ogt double %24, %25
  br i1 %26, label %27, label %29

27:                                               ; preds = %14
  %28 = load double, ptr %8, align 8, !tbaa !11
  br label %41

29:                                               ; preds = %14
  %30 = load double, ptr %8, align 8, !tbaa !11
  %31 = fneg double %30
  %32 = load double, ptr %7, align 8, !tbaa !11
  %33 = fcmp ogt double %31, %32
  br i1 %33, label %34, label %37

34:                                               ; preds = %29
  %35 = load double, ptr %8, align 8, !tbaa !11
  %36 = fneg double %35
  br label %39

37:                                               ; preds = %29
  %38 = load double, ptr %7, align 8, !tbaa !11
  br label %39

39:                                               ; preds = %37, %34
  %40 = phi double [ %36, %34 ], [ %38, %37 ]
  br label %41

41:                                               ; preds = %39, %27
  %42 = phi double [ %28, %27 ], [ %40, %39 ]
  store double %42, ptr %7, align 8, !tbaa !11
  br label %43

43:                                               ; preds = %41
  %44 = load i64, ptr %9, align 8, !tbaa !9
  %45 = add nsw i64 %44, 1
  store i64 %45, ptr %9, align 8, !tbaa !9
  br label %10, !llvm.loop !13

46:                                               ; preds = %10
  %47 = load double, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret double %47
}

; 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

attributes #0 = { 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 willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !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: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local double @vec_diff_norm(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i64 %2, 0
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %xtraiter = and i64 %2, 1
  %5 = icmp eq i64 %2, 1
  br i1 %5, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %2, 9223372036854775806
  br label %.lr.ph

.lr.ph:                                           ; preds = %28, %.lr.ph.preheader.new
  %.017 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %30, %28 ]
  %.01416 = phi double [ 0.000000e+00, %.lr.ph.preheader.new ], [ %29, %28 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %28 ]
  %6 = getelementptr inbounds double, ptr %0, i64 %.017
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds double, ptr %1, i64 %.017
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = fsub double %7, %9
  %11 = fcmp ogt double %10, %.01416
  br i1 %11, label %.lr.ph.1, label %12

12:                                               ; preds = %.lr.ph
  %13 = fneg double %10
  %14 = fcmp olt double %.01416, %13
  %15 = select i1 %14, double %13, double %.01416
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph, %12
  %16 = phi double [ %15, %12 ], [ %10, %.lr.ph ]
  %17 = or disjoint i64 %.017, 1
  %18 = getelementptr inbounds double, ptr %0, i64 %17
  %19 = load double, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds double, ptr %1, i64 %17
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = fsub double %19, %21
  %23 = fcmp ogt double %22, %16
  br i1 %23, label %28, label %24

24:                                               ; preds = %.lr.ph.1
  %25 = fneg double %22
  %26 = fcmp olt double %16, %25
  %27 = select i1 %26, double %25, double %16
  br label %28

28:                                               ; preds = %24, %.lr.ph.1
  %29 = phi double [ %27, %24 ], [ %22, %.lr.ph.1 ]
  %30 = add nuw nsw i64 %.017, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %28, %.lr.ph.preheader
  %.lcssa.ph = phi double [ poison, %.lr.ph.preheader ], [ %29, %28 ]
  %.017.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %30, %28 ]
  %.01416.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %29, %28 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %31 = getelementptr inbounds double, ptr %0, i64 %.017.unr
  %32 = load double, ptr %31, align 8, !tbaa !5
  %33 = getelementptr inbounds double, ptr %1, i64 %.017.unr
  %34 = load double, ptr %33, align 8, !tbaa !5
  %35 = fsub double %32, %34
  %36 = fcmp ogt double %35, %.01416.unr
  br i1 %36, label %._crit_edge, label %37

37:                                               ; preds = %.lr.ph.epil
  %38 = fneg double %35
  %39 = fcmp olt double %.01416.unr, %38
  %40 = select i1 %39, double %38, double %.01416.unr
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %37, %.lr.ph.epil, %3
  %.014.lcssa = phi double [ 0.000000e+00, %3 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %40, %37 ], [ %35, %.lr.ph.epil ]
  ret double %.014.lcssa
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: read) 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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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