; LLVM IR from kmilo17pet/qlibs :: qtypegeneric (qTypeGeneric_Swap)

; 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 void @qTypeGeneric_Swap(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 ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i8, align 1
  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
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %12, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %13, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i64 0, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %32, %3
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #2
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load i64, ptr %9, align 8, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %15, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !11
  store i8 %18, ptr %11, align 1, !tbaa !11
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = load i64, ptr %10, align 8, !tbaa !9
  %21 = getelementptr inbounds i8, ptr %19, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load i64, ptr %9, align 8, !tbaa !9
  %25 = add i64 %24, 1
  store i64 %25, ptr %9, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %23, i64 %24
  store i8 %22, ptr %26, align 1, !tbaa !11
  %27 = load i8, ptr %11, align 1, !tbaa !11
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = load i64, ptr %10, align 8, !tbaa !9
  %30 = add i64 %29, 1
  store i64 %30, ptr %10, align 8, !tbaa !9
  %31 = getelementptr inbounds i8, ptr %28, i64 %29
  store i8 %27, ptr %31, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #2
  br label %32

32:                                               ; preds = %14
  %33 = load i64, ptr %6, align 8, !tbaa !9
  %34 = add i64 %33, -1
  store i64 %34, ptr %6, align 8, !tbaa !9
  %35 = icmp ugt i64 %34, 0
  br i1 %35, label %14, label %36, !llvm.loop !12

36:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  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 void
}

; 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", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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: readwrite) uwtable
define dso_local void @qTypeGeneric_Swap(ptr nocapture noundef %0, ptr nocapture noundef %1, i64 noundef %2) local_unnamed_addr #0 {
iter.check:
  %min.iters.check = icmp ult i64 %2, 8
  br i1 %min.iters.check, label %vec.epilog.scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %iter.check
  %scevgep = getelementptr i8, ptr %0, i64 %2
  %scevgep13 = getelementptr i8, ptr %1, i64 %2
  %bound0 = icmp ugt ptr %scevgep13, %0
  %bound1 = icmp ugt ptr %scevgep, %1
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %vec.epilog.scalar.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %vector.memcheck
  %min.iters.check14 = icmp ult i64 %2, 32
  br i1 %min.iters.check14, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %2, -32
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %3 = getelementptr inbounds i8, ptr %0, i64 %index
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  %wide.load = load <16 x i8>, ptr %3, align 1, !tbaa !5, !alias.scope !8, !noalias !11
  %wide.load15 = load <16 x i8>, ptr %4, align 1, !tbaa !5, !alias.scope !8, !noalias !11
  %5 = getelementptr inbounds i8, ptr %1, i64 %index
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  %wide.load16 = load <16 x i8>, ptr %5, align 1, !tbaa !5, !alias.scope !11
  %wide.load17 = load <16 x i8>, ptr %6, align 1, !tbaa !5, !alias.scope !11
  store <16 x i8> %wide.load16, ptr %3, align 1, !tbaa !5, !alias.scope !8, !noalias !11
  store <16 x i8> %wide.load17, ptr %4, align 1, !tbaa !5, !alias.scope !8, !noalias !11
  store <16 x i8> %wide.load, ptr %5, align 1, !tbaa !5, !alias.scope !11
  store <16 x i8> %wide.load15, ptr %6, align 1, !tbaa !5, !alias.scope !11
  %index.next = add nuw i64 %index, 32
  %7 = icmp eq i64 %index.next, %n.vec
  br i1 %7, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %2
  br i1 %cmp.n, label %.loopexit, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %ind.end20 = and i64 %2, 31
  %n.vec.remaining = and i64 %2, 24
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %vec.epilog.scalar.ph.preheader, label %vec.epilog.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec19 = and i64 %2, -8
  %ind.end = and i64 %2, 7
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index22 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next25, %vec.epilog.vector.body ]
  %8 = getelementptr inbounds i8, ptr %0, i64 %index22
  %wide.load23 = load <8 x i8>, ptr %8, align 1, !tbaa !5, !alias.scope !17, !noalias !20
  %9 = getelementptr inbounds i8, ptr %1, i64 %index22
  %wide.load24 = load <8 x i8>, ptr %9, align 1, !tbaa !5, !alias.scope !20
  store <8 x i8> %wide.load24, ptr %8, align 1, !tbaa !5, !alias.scope !17, !noalias !20
  store <8 x i8> %wide.load23, ptr %9, align 1, !tbaa !5, !alias.scope !20
  %index.next25 = add nuw i64 %index22, 8
  %10 = icmp eq i64 %index.next25, %n.vec19
  br i1 %10, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !22

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

vec.epilog.scalar.ph.preheader:                   ; preds = %vec.epilog.middle.block, %vector.memcheck, %iter.check, %vec.epilog.iter.check
  %.012.ph = phi i64 [ 0, %iter.check ], [ 0, %vector.memcheck ], [ %n.vec, %vec.epilog.iter.check ], [ %n.vec19, %vec.epilog.middle.block ]
  %.0.ph = phi i64 [ %2, %iter.check ], [ %2, %vector.memcheck ], [ %ind.end20, %vec.epilog.iter.check ], [ %ind.end, %vec.epilog.middle.block ]
  %xtraiter = and i64 %.0.ph, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %vec.epilog.scalar.ph.prol.loopexit, label %vec.epilog.scalar.ph.prol

vec.epilog.scalar.ph.prol:                        ; preds = %vec.epilog.scalar.ph.preheader
  %11 = getelementptr inbounds i8, ptr %0, i64 %.012.ph
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %1, i64 %.012.ph
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = or disjoint i64 %.012.ph, 1
  store i8 %14, ptr %11, align 1, !tbaa !5
  store i8 %12, ptr %13, align 1, !tbaa !5
  %16 = add nsw i64 %.0.ph, -1
  br label %vec.epilog.scalar.ph.prol.loopexit

vec.epilog.scalar.ph.prol.loopexit:               ; preds = %vec.epilog.scalar.ph.prol, %vec.epilog.scalar.ph.preheader
  %.012.unr = phi i64 [ %.012.ph, %vec.epilog.scalar.ph.preheader ], [ %15, %vec.epilog.scalar.ph.prol ]
  %.0.unr = phi i64 [ %.0.ph, %vec.epilog.scalar.ph.preheader ], [ %16, %vec.epilog.scalar.ph.prol ]
  %17 = icmp eq i64 %.0.ph, 1
  br i1 %17, label %.loopexit, label %vec.epilog.scalar.ph

vec.epilog.scalar.ph:                             ; preds = %vec.epilog.scalar.ph.prol.loopexit, %vec.epilog.scalar.ph
  %.012 = phi i64 [ %27, %vec.epilog.scalar.ph ], [ %.012.unr, %vec.epilog.scalar.ph.prol.loopexit ]
  %.0 = phi i64 [ %28, %vec.epilog.scalar.ph ], [ %.0.unr, %vec.epilog.scalar.ph.prol.loopexit ]
  %18 = getelementptr inbounds i8, ptr %0, i64 %.012
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %1, i64 %.012
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %22 = add i64 %.012, 1
  store i8 %21, ptr %18, align 1, !tbaa !5
  store i8 %19, ptr %20, align 1, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %1, i64 %22
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %27 = add i64 %.012, 2
  store i8 %26, ptr %23, align 1, !tbaa !5
  store i8 %24, ptr %25, align 1, !tbaa !5
  %28 = add i64 %.0, -2
  %.not.1 = icmp eq i64 %28, 0
  br i1 %.not.1, label %.loopexit, label %vec.epilog.scalar.ph, !llvm.loop !23

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

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopLoadEliminationPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass