; LLVM IR from venumb/ZSPACE :: cpp/depends/alglib/cpp/src/ap.ll (ZN11alglib_impl14ae_check_zerosEPKvl)

; 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: 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
define dso_local noundef zeroext i1 @_ZN11alglib_impl14ae_check_zerosEPKvl(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !11
  %11 = load i64, ptr %4, align 8, !tbaa !9
  %12 = udiv i64 %11, 8
  store i64 %12, ptr %5, align 8, !tbaa !9
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = urem i64 %13, 8
  store i64 %14, ptr %6, align 8, !tbaa !9
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = icmp sgt i64 %15, 0
  br i1 %16, label %17, label %34

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %18, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %30, %17
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = icmp slt i64 %20, %21
  br i1 %22, label %23, label %33

23:                                               ; preds = %19
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = getelementptr inbounds i64, ptr %24, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !11
  %28 = load i64, ptr %8, align 8, !tbaa !11
  %29 = or i64 %28, %27
  store i64 %29, ptr %8, align 8, !tbaa !11
  br label %30

30:                                               ; preds = %23
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = add nsw i64 %31, 1
  store i64 %32, ptr %7, align 8, !tbaa !9
  br label %19, !llvm.loop !13

33:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %34

34:                                               ; preds = %33, %2
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = icmp sgt i64 %35, 0
  br i1 %36, label %37, label %58

37:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = load i64, ptr %5, align 8, !tbaa !9
  %40 = mul i64 %39, 8
  %41 = getelementptr inbounds i8, ptr %38, i64 %40
  store ptr %41, ptr %10, align 8, !tbaa !5
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %42

42:                                               ; preds = %54, %37
  %43 = load i64, ptr %7, align 8, !tbaa !9
  %44 = load i64, ptr %6, align 8, !tbaa !9
  %45 = icmp slt i64 %43, %44
  br i1 %45, label %46, label %57

46:                                               ; preds = %42
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = load i64, ptr %7, align 8, !tbaa !9
  %49 = getelementptr inbounds i8, ptr %47, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !15
  %51 = zext i8 %50 to i64
  %52 = load i64, ptr %8, align 8, !tbaa !11
  %53 = or i64 %52, %51
  store i64 %53, ptr %8, align 8, !tbaa !11
  br label %54

54:                                               ; preds = %46
  %55 = load i64, ptr %7, align 8, !tbaa !9
  %56 = add nsw i64 %55, 1
  store i64 %56, ptr %7, align 8, !tbaa !9
  br label %42, !llvm.loop !16

57:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %58

58:                                               ; preds = %57, %34
  %59 = load i64, ptr %8, align 8, !tbaa !11
  %60 = icmp eq i64 %59, 0
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i1 %60
}

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, !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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!7, !7, i64 0}
!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 nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef zeroext i1 @_ZN11alglib_impl14ae_check_zerosEPKvl(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = lshr i64 %1, 3
  %4 = and i64 %1, 7
  %5 = icmp ugt i64 %1, 7
  br i1 %5, label %.lr.ph.preheader, label %.loopexit24

.lr.ph.preheader:                                 ; preds = %2
  %min.iters.check = icmp ult i64 %1, 32
  br i1 %min.iters.check, label %.lr.ph.preheader35, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %3, 2305843009213693948
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %8, %vector.body ]
  %vec.phi33 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %9, %vector.body ]
  %6 = getelementptr inbounds i64, ptr %0, i64 %index
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  %wide.load = load <2 x i64>, ptr %6, align 8, !tbaa !5
  %wide.load34 = load <2 x i64>, ptr %7, align 8, !tbaa !5
  %8 = or <2 x i64> %wide.load, %vec.phi
  %9 = or <2 x i64> %wide.load34, %vec.phi33
  %index.next = add nuw i64 %index, 4
  %10 = icmp eq i64 %index.next, %n.vec
  br i1 %10, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = or <2 x i64> %9, %8
  %11 = tail call i64 @llvm.vector.reduce.or.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %3, %n.vec
  br i1 %cmp.n, label %.loopexit24, label %.lr.ph.preheader35

.lr.ph.preheader35:                               ; preds = %middle.block, %.lr.ph.preheader
  %.026.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %.01925.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %11, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader35, %.lr.ph
  %.026 = phi i64 [ %15, %.lr.ph ], [ %.026.ph, %.lr.ph.preheader35 ]
  %.01925 = phi i64 [ %14, %.lr.ph ], [ %.01925.ph, %.lr.ph.preheader35 ]
  %12 = getelementptr inbounds i64, ptr %0, i64 %.026
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = or i64 %13, %.01925
  %15 = add nuw nsw i64 %.026, 1
  %exitcond.not = icmp eq i64 %15, %3
  br i1 %exitcond.not, label %.loopexit24, label %.lr.ph, !llvm.loop !13

.loopexit24:                                      ; preds = %.lr.ph, %middle.block, %2
  %.120 = phi i64 [ 0, %2 ], [ %11, %middle.block ], [ %14, %.lr.ph ]
  %.not23 = icmp eq i64 %4, 0
  br i1 %.not23, label %.loopexit, label %16

16:                                               ; preds = %.loopexit24
  %17 = and i64 %1, -8
  %18 = getelementptr inbounds i8, ptr %0, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !14
  %20 = zext i8 %19 to i64
  %21 = or i64 %.120, %20
  %exitcond30.not = icmp eq i64 %4, 1
  br i1 %exitcond30.not, label %.loopexit, label %22, !llvm.loop !15

22:                                               ; preds = %16
  %23 = getelementptr inbounds i8, ptr %18, i64 1
  %24 = load i8, ptr %23, align 1, !tbaa !14
  %25 = zext i8 %24 to i64
  %26 = or i64 %21, %25
  %exitcond30.not.1 = icmp eq i64 %4, 2
  br i1 %exitcond30.not.1, label %.loopexit, label %27, !llvm.loop !15

27:                                               ; preds = %22
  %28 = getelementptr inbounds i8, ptr %18, i64 2
  %29 = load i8, ptr %28, align 1, !tbaa !14
  %30 = zext i8 %29 to i64
  %31 = or i64 %26, %30
  %exitcond30.not.2 = icmp eq i64 %4, 3
  br i1 %exitcond30.not.2, label %.loopexit, label %32, !llvm.loop !15

32:                                               ; preds = %27
  %33 = getelementptr inbounds i8, ptr %18, i64 3
  %34 = load i8, ptr %33, align 1, !tbaa !14
  %35 = zext i8 %34 to i64
  %36 = or i64 %31, %35
  %exitcond30.not.3 = icmp eq i64 %4, 4
  br i1 %exitcond30.not.3, label %.loopexit, label %37, !llvm.loop !15

37:                                               ; preds = %32
  %38 = getelementptr inbounds i8, ptr %18, i64 4
  %39 = load i8, ptr %38, align 1, !tbaa !14
  %40 = zext i8 %39 to i64
  %41 = or i64 %36, %40
  %exitcond30.not.4 = icmp eq i64 %4, 5
  br i1 %exitcond30.not.4, label %.loopexit, label %42, !llvm.loop !15

42:                                               ; preds = %37
  %43 = getelementptr inbounds i8, ptr %18, i64 5
  %44 = load i8, ptr %43, align 1, !tbaa !14
  %45 = zext i8 %44 to i64
  %46 = or i64 %41, %45
  %exitcond30.not.5 = icmp eq i64 %4, 6
  br i1 %exitcond30.not.5, label %.loopexit, label %47, !llvm.loop !15

47:                                               ; preds = %42
  %48 = getelementptr inbounds i8, ptr %18, i64 6
  %49 = load i8, ptr %48, align 1, !tbaa !14
  %50 = zext i8 %49 to i64
  %51 = or i64 %46, %50
  br label %.loopexit

.loopexit:                                        ; preds = %16, %22, %27, %32, %37, %42, %47, %.loopexit24
  %.3 = phi i64 [ %.120, %.loopexit24 ], [ %21, %16 ], [ %26, %22 ], [ %31, %27 ], [ %36, %32 ], [ %41, %37 ], [ %46, %42 ], [ %51, %47 ]
  %52 = icmp eq i64 %.3, 0
  ret i1 %52
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.vector.reduce.or.v2i64(<2 x i64>) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn 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" }
attributes #1 = { 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 = !{!"long long", !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, !12, !11}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !10}


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