; LLVM IR from MRPT/mrpt :: 3rdparty/xspublic/xstypes (xsvector)

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

%struct.XsVector = type { ptr, i64, i64 }

; 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

; Function Attrs: nounwind uwtable
define dso_local void @XsVector_swap(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.XsVector, align 1
  %6 = alloca i64, align 8
  %7 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.XsVector, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 1, !tbaa !9
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %18

12:                                               ; preds = %2
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.XsVector, ptr %13, i32 0, i32 2
  %15 = load i64, ptr %14, align 1, !tbaa !12
  %16 = and i64 %15, 1
  %17 = icmp ne i64 %16, 0
  br i1 %17, label %18, label %69

18:                                               ; preds = %12, %2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.XsVector, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 1, !tbaa !9
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %29

23:                                               ; preds = %18
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.XsVector, ptr %24, i32 0, i32 2
  %26 = load i64, ptr %25, align 1, !tbaa !12
  %27 = and i64 %26, 1
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %29, label %69

29:                                               ; preds = %23, %18
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #2
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.XsVector, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 1, !tbaa !9
  %33 = getelementptr inbounds %struct.XsVector, ptr %5, i32 0, i32 0
  store ptr %32, ptr %33, align 1, !tbaa !5
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.XsVector, ptr %34, i32 0, i32 1
  %36 = load i64, ptr %35, align 1, !tbaa !13
  %37 = getelementptr inbounds %struct.XsVector, ptr %5, i32 0, i32 1
  store i64 %36, ptr %37, align 1, !tbaa !14
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.XsVector, ptr %38, i32 0, i32 2
  %40 = load i64, ptr %39, align 1, !tbaa !12
  %41 = getelementptr inbounds %struct.XsVector, ptr %5, i32 0, i32 2
  store i64 %40, ptr %41, align 1, !tbaa !14
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.XsVector, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 1, !tbaa !9
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.XsVector, ptr %45, i32 0, i32 0
  store ptr %44, ptr %46, align 1, !tbaa !5
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.XsVector, ptr %47, i32 0, i32 1
  %49 = load i64, ptr %48, align 1, !tbaa !13
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.XsVector, ptr %50, i32 0, i32 1
  store i64 %49, ptr %51, align 1, !tbaa !14
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.XsVector, ptr %52, i32 0, i32 2
  %54 = load i64, ptr %53, align 1, !tbaa !12
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.XsVector, ptr %55, i32 0, i32 2
  store i64 %54, ptr %56, align 1, !tbaa !14
  %57 = getelementptr inbounds %struct.XsVector, ptr %5, i32 0, i32 0
  %58 = load ptr, ptr %57, align 1, !tbaa !9
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.XsVector, ptr %59, i32 0, i32 0
  store ptr %58, ptr %60, align 1, !tbaa !5
  %61 = getelementptr inbounds %struct.XsVector, ptr %5, i32 0, i32 1
  %62 = load i64, ptr %61, align 1, !tbaa !13
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.XsVector, ptr %63, i32 0, i32 1
  store i64 %62, ptr %64, align 1, !tbaa !14
  %65 = getelementptr inbounds %struct.XsVector, ptr %5, i32 0, i32 2
  %66 = load i64, ptr %65, align 1, !tbaa !12
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.XsVector, ptr %67, i32 0, i32 2
  store i64 %66, ptr %68, align 1, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #2
  br label %104

69:                                               ; preds = %23, %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !14
  br label %70

70:                                               ; preds = %100, %69
  %71 = load i64, ptr %6, align 8, !tbaa !14
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.XsVector, ptr %72, i32 0, i32 1
  %74 = load i64, ptr %73, align 1, !tbaa !13
  %75 = icmp ult i64 %71, %74
  br i1 %75, label %76, label %103

76:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.XsVector, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 1, !tbaa !9
  %80 = load i64, ptr %6, align 8, !tbaa !14
  %81 = getelementptr inbounds double, ptr %79, i64 %80
  %82 = load double, ptr %81, align 8, !tbaa !15
  store double %82, ptr %7, align 8, !tbaa !15
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.XsVector, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 1, !tbaa !9
  %86 = load i64, ptr %6, align 8, !tbaa !14
  %87 = getelementptr inbounds double, ptr %85, i64 %86
  %88 = load double, ptr %87, align 8, !tbaa !15
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.XsVector, ptr %89, i32 0, i32 0
  %91 = load ptr, ptr %90, align 1, !tbaa !9
  %92 = load i64, ptr %6, align 8, !tbaa !14
  %93 = getelementptr inbounds double, ptr %91, i64 %92
  store double %88, ptr %93, align 8, !tbaa !15
  %94 = load double, ptr %7, align 8, !tbaa !15
  %95 = load ptr, ptr %4, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.XsVector, ptr %95, i32 0, i32 0
  %97 = load ptr, ptr %96, align 1, !tbaa !9
  %98 = load i64, ptr %6, align 8, !tbaa !14
  %99 = getelementptr inbounds double, ptr %97, i64 %98
  store double %94, ptr %99, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %100

100:                                              ; preds = %76
  %101 = load i64, ptr %6, align 8, !tbaa !14
  %102 = add i64 %101, 1
  store i64 %102, ptr %6, align 8, !tbaa !14
  br label %70, !llvm.loop !17

103:                                              ; preds = %70
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %104

104:                                              ; preds = %103, %29
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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, !6, i64 0}
!10 = !{!"XsVector", !6, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 16}
!13 = !{!10, !11, i64 8}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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(readwrite, inaccessiblemem: none) uwtable
define dso_local void @XsVector_swap(ptr nocapture noundef %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 1, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %8, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load i64, ptr %5, align 1, !tbaa !11
  %7 = and i64 %6, 1
  %.not27 = icmp eq i64 %7, 0
  br i1 %.not27, label %22, label %8

8:                                                ; preds = %4, %2
  %9 = load ptr, ptr %1, align 1, !tbaa !5
  %.not28 = icmp eq ptr %9, null
  br i1 %.not28, label %14, label %10

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %1, i64 16
  %12 = load i64, ptr %11, align 1, !tbaa !11
  %13 = and i64 %12, 1
  %.not29 = icmp eq i64 %13, 0
  br i1 %.not29, label %22, label %14

14:                                               ; preds = %10, %8
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %9, ptr %0, align 1, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %1, i64 8
  %18 = load i64, ptr %17, align 1, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %1, i64 16
  store ptr %3, ptr %1, align 1, !tbaa !12
  %20 = load <2 x i64>, ptr %15, align 1, !tbaa !14
  store i64 %18, ptr %15, align 1, !tbaa !14
  %21 = load i64, ptr %19, align 1, !tbaa !11
  store i64 %21, ptr %16, align 1, !tbaa !14
  store <2 x i64> %20, ptr %17, align 1, !tbaa !14
  br label %.loopexit

22:                                               ; preds = %10, %4
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  %24 = load i64, ptr %23, align 1, !tbaa !13
  %.not31 = icmp eq i64 %24, 0
  br i1 %.not31, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %22
  %25 = load ptr, ptr %1, align 1, !tbaa !5
  %min.iters.check = icmp ult i64 %24, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph
  %26 = shl i64 %24, 3
  %scevgep = getelementptr i8, ptr %3, i64 %26
  %scevgep32 = getelementptr i8, ptr %25, i64 %26
  %bound0 = icmp ult ptr %3, %scevgep32
  %bound1 = icmp ult ptr %25, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %24, -4
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %27 = getelementptr inbounds double, ptr %3, i64 %index
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  %wide.load = load <2 x double>, ptr %27, align 8, !tbaa !15, !alias.scope !17, !noalias !20
  %wide.load33 = load <2 x double>, ptr %28, align 8, !tbaa !15, !alias.scope !17, !noalias !20
  %29 = getelementptr inbounds double, ptr %25, i64 %index
  %30 = getelementptr inbounds i8, ptr %29, i64 16
  %wide.load34 = load <2 x double>, ptr %29, align 8, !tbaa !15, !alias.scope !20
  %wide.load35 = load <2 x double>, ptr %30, align 8, !tbaa !15, !alias.scope !20
  store <2 x double> %wide.load34, ptr %27, align 8, !tbaa !15, !alias.scope !17, !noalias !20
  store <2 x double> %wide.load35, ptr %28, align 8, !tbaa !15, !alias.scope !17, !noalias !20
  store <2 x double> %wide.load, ptr %29, align 8, !tbaa !15, !alias.scope !20
  store <2 x double> %wide.load33, ptr %30, align 8, !tbaa !15, !alias.scope !20
  %index.next = add nuw i64 %index, 4
  %31 = icmp eq i64 %index.next, %n.vec
  br i1 %31, label %middle.block, label %vector.body, !llvm.loop !22

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %24, %n.vec
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %.030.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %.neg = or disjoint i64 %.030.ph, 1
  %xtraiter = and i64 %24, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %32 = getelementptr inbounds double, ptr %3, i64 %.030.ph
  %33 = load double, ptr %32, align 8, !tbaa !15
  %34 = getelementptr inbounds double, ptr %25, i64 %.030.ph
  %35 = load double, ptr %34, align 8, !tbaa !15
  store double %35, ptr %32, align 8, !tbaa !15
  store double %33, ptr %34, align 8, !tbaa !15
  %36 = or disjoint i64 %.030.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.030.unr = phi i64 [ %.030.ph, %scalar.ph.preheader ], [ %36, %scalar.ph.prol ]
  %37 = icmp eq i64 %24, %.neg
  br i1 %37, label %.loopexit, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.030 = phi i64 [ %47, %scalar.ph ], [ %.030.unr, %scalar.ph.prol.loopexit ]
  %38 = getelementptr inbounds double, ptr %3, i64 %.030
  %39 = load double, ptr %38, align 8, !tbaa !15
  %40 = getelementptr inbounds double, ptr %25, i64 %.030
  %41 = load double, ptr %40, align 8, !tbaa !15
  store double %41, ptr %38, align 8, !tbaa !15
  store double %39, ptr %40, align 8, !tbaa !15
  %42 = add nuw i64 %.030, 1
  %43 = getelementptr inbounds double, ptr %3, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !15
  %45 = getelementptr inbounds double, ptr %25, i64 %42
  %46 = load double, ptr %45, align 8, !tbaa !15
  store double %46, ptr %43, align 8, !tbaa !15
  store double %44, ptr %45, align 8, !tbaa !15
  %47 = add nuw i64 %.030, 2
  %exitcond.not.1 = icmp eq i64 %47, %24
  br i1 %exitcond.not.1, label %.loopexit, label %scalar.ph, !llvm.loop !26

.loopexit:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %22, %14
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !7, i64 0}
!6 = !{!"XsVector", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !10, i64 8}
!14 = !{!10, !10, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !8, i64 0}
!17 = !{!18}
!18 = distinct !{!18, !19}
!19 = distinct !{!19, !"LVerDomain"}
!20 = !{!21}
!21 = distinct !{!21, !19}
!22 = distinct !{!22, !23, !24, !25}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!"llvm.loop.isvectorized", i32 1}
!25 = !{!"llvm.loop.unroll.runtime.disable"}
!26 = distinct !{!26, !23, !24}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass