; LLVM IR from sp-nitech/SPTK :: third_party/SWIPE/vector.ll (ZN4sptk5swipe4im2mENS0_9intmatrixE)

; 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.sptk::swipe::matrix" = type { i32, i32, ptr }
%"struct.sptk::swipe::intmatrix" = type { i32, i32, ptr }

; 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: mustprogress nounwind uwtable
declare dso_local { i64, ptr } @_ZN4sptk5swipe5makemEii(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local { i64, ptr } @_ZN4sptk5swipe4im2mENS0_9intmatrixE(i64 %0, ptr %1) #1 {
  %3 = alloca %"struct.sptk::swipe::matrix", align 8
  %4 = alloca %"struct.sptk::swipe::intmatrix", align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = getelementptr inbounds { i64, ptr }, ptr %4, i32 0, i32 0
  store i64 %0, ptr %7, align 8
  %8 = getelementptr inbounds { i64, ptr }, ptr %4, i32 0, i32 1
  store ptr %1, ptr %8, align 8
  %9 = getelementptr inbounds %"struct.sptk::swipe::intmatrix", ptr %4, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds %"struct.sptk::swipe::intmatrix", ptr %4, i32 0, i32 1
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = call { i64, ptr } @_ZN4sptk5swipe5makemEii(i32 noundef %10, i32 noundef %12)
  %14 = getelementptr inbounds { i64, ptr }, ptr %3, i32 0, i32 0
  %15 = extractvalue { i64, ptr } %13, 0
  store i64 %15, ptr %14, align 8
  %16 = getelementptr inbounds { i64, ptr }, ptr %3, i32 0, i32 1
  %17 = extractvalue { i64, ptr } %13, 1
  store ptr %17, ptr %16, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %5, align 4, !tbaa !12
  br label %18

18:                                               ; preds = %54, %2
  %19 = load i32, ptr %5, align 4, !tbaa !12
  %20 = getelementptr inbounds %"struct.sptk::swipe::intmatrix", ptr %4, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !5
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %23, label %57

23:                                               ; preds = %18
  store i32 0, ptr %6, align 4, !tbaa !12
  br label %24

24:                                               ; preds = %50, %23
  %25 = load i32, ptr %6, align 4, !tbaa !12
  %26 = getelementptr inbounds %"struct.sptk::swipe::intmatrix", ptr %4, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !11
  %28 = icmp slt i32 %25, %27
  br i1 %28, label %29, label %53

29:                                               ; preds = %24
  %30 = getelementptr inbounds %"struct.sptk::swipe::intmatrix", ptr %4, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = load i32, ptr %5, align 4, !tbaa !12
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds ptr, ptr %31, i64 %33
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = load i32, ptr %6, align 4, !tbaa !12
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %35, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !12
  %40 = sitofp i32 %39 to double
  %41 = getelementptr inbounds %"struct.sptk::swipe::matrix", ptr %3, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !15
  %43 = load i32, ptr %5, align 4, !tbaa !12
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds ptr, ptr %42, i64 %44
  %46 = load ptr, ptr %45, align 8, !tbaa !14
  %47 = load i32, ptr %6, align 4, !tbaa !12
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds double, ptr %46, i64 %48
  store double %40, ptr %49, align 8, !tbaa !17
  br label %50

50:                                               ; preds = %29
  %51 = load i32, ptr %6, align 4, !tbaa !12
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %6, align 4, !tbaa !12
  br label %24, !llvm.loop !19

53:                                               ; preds = %24
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %5, align 4, !tbaa !12
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %5, align 4, !tbaa !12
  br label %18, !llvm.loop !21

57:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  %58 = load { i64, ptr }, ptr %3, align 8
  ret { i64, ptr } %58
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !7, i64 0}
!6 = !{!"_ZTSN4sptk5swipe9intmatrixE", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !10, i64 8}
!14 = !{!10, !10, i64 0}
!15 = !{!16, !10, i64 8}
!16 = !{!"_ZTSN4sptk5swipe6matrixE", !7, i64 0, !7, i64 4, !10, i64 8}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !8, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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 nounwind uwtable
declare dso_local { i64, ptr } @_ZN4sptk5swipe5makemEii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local { i64, ptr } @_ZN4sptk5swipe4im2mENS0_9intmatrixE(i64 %0, ptr nocapture readonly %1) local_unnamed_addr #0 {
  %.sroa.0.0.extract.trunc = trunc i64 %0 to i32
  %.sroa.3.0.extract.shift = lshr i64 %0, 32
  %.sroa.3.0.extract.trunc = trunc nuw i64 %.sroa.3.0.extract.shift to i32
  %3 = tail call { i64, ptr } @_ZN4sptk5swipe5makemEii(i32 noundef %.sroa.0.0.extract.trunc, i32 noundef %.sroa.3.0.extract.trunc)
  %4 = extractvalue { i64, ptr } %3, 1
  %5 = icmp sgt i32 %.sroa.0.0.extract.trunc, 0
  %6 = icmp sgt i32 %.sroa.3.0.extract.trunc, 0
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge14

.preheader.us.preheader:                          ; preds = %2
  %wide.trip.count20 = and i64 %0, 2147483647
  %min.iters.check = icmp ult i64 %0, 17179869184
  %n.vec = and i64 %.sroa.3.0.extract.shift, 2147483644
  %cmp.n = icmp eq i64 %.sroa.3.0.extract.shift, %n.vec
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv17 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next18, %._crit_edge.us ]
  %7 = getelementptr inbounds ptr, ptr %1, i64 %indvars.iv17
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds ptr, ptr %4, i64 %indvars.iv17
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %.preheader.us, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.preheader.us ]
  %11 = getelementptr inbounds i32, ptr %8, i64 %index
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %wide.load = load <2 x i32>, ptr %11, align 4, !tbaa !9
  %wide.load22 = load <2 x i32>, ptr %12, align 4, !tbaa !9
  %13 = sitofp <2 x i32> %wide.load to <2 x double>
  %14 = sitofp <2 x i32> %wide.load22 to <2 x double>
  %15 = getelementptr inbounds double, ptr %10, i64 %index
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  store <2 x double> %13, ptr %15, align 8, !tbaa !11
  store <2 x double> %14, ptr %16, align 8, !tbaa !11
  %index.next = add nuw i64 %index, 4
  %17 = icmp eq i64 %index.next, %n.vec
  br i1 %17, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader.us
  %indvars.iv.ph = phi i64 [ 0, %.preheader.us ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %18 = getelementptr inbounds i32, ptr %8, i64 %indvars.iv
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = sitofp i32 %19 to double
  %21 = getelementptr inbounds double, ptr %10, i64 %indvars.iv
  store double %20, ptr %21, align 8, !tbaa !11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %.sroa.3.0.extract.shift
  br i1 %exitcond.not, label %._crit_edge.us, label %scalar.ph, !llvm.loop !17

._crit_edge.us:                                   ; preds = %scalar.ph, %middle.block
  %indvars.iv.next18 = add nuw nsw i64 %indvars.iv17, 1
  %exitcond21.not = icmp eq i64 %indvars.iv.next18, %wide.trip.count20
  br i1 %exitcond21.not, label %._crit_edge14, label %.preheader.us, !llvm.loop !18

._crit_edge14:                                    ; preds = %._crit_edge.us, %2
  ret { i64, ptr } %3
}

attributes #0 = { 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 = !{!"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, !15, !16}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = distinct !{!17, !14, !16, !15}
!18 = distinct !{!18, !14}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass