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

; 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::intvector" = type { 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 uwtable
define dso_local noundef i32 @_ZN4sptk5swipe5sieveENS0_9intvectorE(i32 %0, ptr %1) #1 {
  %3 = alloca %"struct.sptk::swipe::intvector", align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = getelementptr inbounds { i32, ptr }, ptr %3, i32 0, i32 0
  store i32 %0, ptr %8, align 8
  %9 = getelementptr inbounds { i32, ptr }, ptr %3, i32 0, i32 1
  store ptr %1, ptr %9, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %10 = getelementptr inbounds %"struct.sptk::swipe::intvector", ptr %3, i32 0, i32 0
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %11)
  %13 = call double @llvm.floor.f64(double %12)
  %14 = fptosi double %13 to i32
  store i32 %14, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %15 = getelementptr inbounds %"struct.sptk::swipe::intvector", ptr %3, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = getelementptr inbounds i32, ptr %16, i64 0
  store i32 0, ptr %17, align 4, !tbaa !5
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %55, %2
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %22, label %58

22:                                               ; preds = %18
  %23 = getelementptr inbounds %"struct.sptk::swipe::intvector", ptr %3, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i32, ptr %24, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %54

30:                                               ; preds = %22
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = add nsw i32 %31, %32
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %7, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %46, %30
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = getelementptr inbounds %"struct.sptk::swipe::intvector", ptr %3, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !9
  %39 = icmp slt i32 %36, %38
  br i1 %39, label %40, label %51

40:                                               ; preds = %35
  %41 = getelementptr inbounds %"struct.sptk::swipe::intvector", ptr %3, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !12
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i32, ptr %42, i64 %44
  store i32 0, ptr %45, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %40
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = add nsw i32 %49, %48
  store i32 %50, ptr %7, align 4, !tbaa !5
  br label %35, !llvm.loop !13

51:                                               ; preds = %35
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %4, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %51, %22
  br label %55

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

58:                                               ; preds = %18
  %59 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %59, ptr %6, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %77, %58
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = getelementptr inbounds %"struct.sptk::swipe::intvector", ptr %3, i32 0, i32 0
  %63 = load i32, ptr %62, align 8, !tbaa !9
  %64 = icmp slt i32 %61, %63
  br i1 %64, label %65, label %80

65:                                               ; preds = %60
  %66 = getelementptr inbounds %"struct.sptk::swipe::intvector", ptr %3, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !12
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i32, ptr %67, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = icmp eq i32 %71, 1
  br i1 %72, label %73, label %76

73:                                               ; preds = %65
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %4, align 4, !tbaa !5
  br label %76

76:                                               ; preds = %73, %65
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %6, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %6, align 4, !tbaa !5
  br label %60, !llvm.loop !16

80:                                               ; preds = %60
  %81 = load i32, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  ret i32 %81
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) #2

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN4sptk5swipe5sieveENS0_9intvectorE(i32 %0, ptr nocapture %1) local_unnamed_addr #0 {
  %3 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %0)
  %4 = tail call double @llvm.floor.f64(double %3)
  %5 = fptosi double %4 to i32
  store i32 0, ptr %1, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 1
  br i1 %6, label %.lr.ph31.preheader, label %.preheader

.lr.ph31.preheader:                               ; preds = %2
  %wide.trip.count = zext nneg i32 %5 to i64
  br label %.lr.ph31

.preheader:                                       ; preds = %31, %2
  %.023.lcssa = phi i32 [ 0, %2 ], [ %.124, %31 ]
  %7 = icmp slt i32 %5, %0
  br i1 %7, label %.lr.ph34.preheader, label %._crit_edge35

.lr.ph34.preheader:                               ; preds = %.preheader
  %8 = sext i32 %5 to i64
  %wide.trip.count48 = sext i32 %0 to i64
  %9 = sub nsw i64 %wide.trip.count48, %8
  %min.iters.check = icmp ult i64 %9, 8
  br i1 %min.iters.check, label %.lr.ph34.preheader52, label %vector.ph

.lr.ph34.preheader52:                             ; preds = %middle.block, %.lr.ph34.preheader
  %indvars.iv45.ph = phi i64 [ %8, %.lr.ph34.preheader ], [ %ind.end, %middle.block ]
  %.232.ph = phi i32 [ %.023.lcssa, %.lr.ph34.preheader ], [ %19, %middle.block ]
  br label %.lr.ph34

vector.ph:                                        ; preds = %.lr.ph34.preheader
  %n.vec = and i64 %9, -8
  %ind.end = add nsw i64 %n.vec, %8
  %10 = insertelement <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, i32 %.023.lcssa, i64 0
  %invariant.gep = getelementptr i32, ptr %1, i64 %8
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ %10, %vector.ph ], [ %16, %vector.body ]
  %vec.phi50 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %17, %vector.body ]
  %gep = getelementptr i32, ptr %invariant.gep, i64 %index
  %11 = getelementptr inbounds i8, ptr %gep, i64 16
  %wide.load = load <4 x i32>, ptr %gep, align 4, !tbaa !5
  %wide.load51 = load <4 x i32>, ptr %11, align 4, !tbaa !5
  %12 = icmp eq <4 x i32> %wide.load, <i32 1, i32 1, i32 1, i32 1>
  %13 = icmp eq <4 x i32> %wide.load51, <i32 1, i32 1, i32 1, i32 1>
  %14 = zext <4 x i1> %12 to <4 x i32>
  %15 = zext <4 x i1> %13 to <4 x i32>
  %16 = add <4 x i32> %vec.phi, %14
  %17 = add <4 x i32> %vec.phi50, %15
  %index.next = add nuw i64 %index, 8
  %18 = icmp eq i64 %index.next, %n.vec
  br i1 %18, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %17, %16
  %19 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %9, %n.vec
  br i1 %cmp.n, label %._crit_edge35, label %.lr.ph34.preheader52

.lr.ph31:                                         ; preds = %.lr.ph31.preheader, %31
  %indvars.iv42 = phi i64 [ 1, %.lr.ph31.preheader ], [ %indvars.iv.next43, %31 ]
  %indvars.iv37 = phi i64 [ 2, %.lr.ph31.preheader ], [ %indvars.iv.next38, %31 ]
  %indvars.iv = phi i64 [ 3, %.lr.ph31.preheader ], [ %indvars.iv.next, %31 ]
  %.02327 = phi i32 [ 0, %.lr.ph31.preheader ], [ %.124, %31 ]
  %20 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv42
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = icmp eq i32 %21, 1
  br i1 %22, label %23, label %31

23:                                               ; preds = %.lr.ph31
  %indvars.iv42.tr = trunc i64 %indvars.iv42 to i32
  %24 = shl i32 %indvars.iv42.tr, 1
  %25 = or disjoint i32 %24, 1
  %26 = icmp slt i32 %25, %0
  br i1 %26, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %23, %.lr.ph
  %indvars.iv39 = phi i64 [ %indvars.iv.next40, %.lr.ph ], [ %indvars.iv, %23 ]
  %27 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv39
  store i32 0, ptr %27, align 4, !tbaa !5
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, %indvars.iv37
  %28 = trunc nuw i64 %indvars.iv.next40 to i32
  %29 = icmp slt i32 %28, %0
  br i1 %29, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %23
  %30 = add nsw i32 %.02327, 1
  br label %31

31:                                               ; preds = %.lr.ph31, %._crit_edge
  %.124 = phi i32 [ %30, %._crit_edge ], [ %.02327, %.lr.ph31 ]
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next43, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %.lr.ph31, !llvm.loop !14

.lr.ph34:                                         ; preds = %.lr.ph34.preheader52, %.lr.ph34
  %indvars.iv45 = phi i64 [ %indvars.iv.next46, %.lr.ph34 ], [ %indvars.iv45.ph, %.lr.ph34.preheader52 ]
  %.232 = phi i32 [ %spec.select, %.lr.ph34 ], [ %.232.ph, %.lr.ph34.preheader52 ]
  %32 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv45
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = icmp eq i32 %33, 1
  %35 = zext i1 %34 to i32
  %spec.select = add nsw i32 %.232, %35
  %indvars.iv.next46 = add nsw i64 %indvars.iv45, 1
  %exitcond49.not = icmp eq i64 %indvars.iv.next46, %wide.trip.count48
  br i1 %exitcond49.not, label %._crit_edge35, label %.lr.ph34, !llvm.loop !15

._crit_edge35:                                    ; preds = %.lr.ph34, %middle.block, %.preheader
  %.2.lcssa = phi i32 [ %.023.lcssa, %.preheader ], [ %19, %middle.block ], [ %spec.select, %.lr.ph34 ]
  ret i32 %.2.lcssa
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #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" }
attributes #1 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10, !12, !11}


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