; LLVM IR from Dimandragon/non-parametric-dsp :: 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 = sdiv i64 %11, 8
  store i64 %12, ptr %5, align 8, !tbaa !9
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = srem 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 nsw 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 = sdiv i64 %1, 8
  %4 = srem i64 %1, 8
  %5 = icmp sgt i64 %1, 7
  br i1 %5, label %.lr.ph.preheader, label %.loopexit23

.lr.ph.preheader:                                 ; preds = %2
  %min.iters.check = icmp ult i64 %3, 4
  br i1 %min.iters.check, label %.lr.ph.preheader34, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %3, 1152921504606846972
  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.phi32 = 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.load33 = 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.load33, %vec.phi32
  %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 %.loopexit23, label %.lr.ph.preheader34

.lr.ph.preheader34:                               ; preds = %middle.block, %.lr.ph.preheader
  %.025.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %.01924.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %11, %middle.block ]
  br label %.lr.ph

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

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

17:                                               ; preds = %.loopexit23
  %18 = shl nsw i64 %3, 3
  %19 = getelementptr inbounds i8, ptr %0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !14
  %21 = zext i8 %20 to i64
  %22 = or i64 %.120, %21
  %exitcond29.not = icmp eq i64 %4, 1
  br i1 %exitcond29.not, label %.loopexit, label %23, !llvm.loop !15

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

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

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

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

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

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

.loopexit:                                        ; preds = %17, %23, %28, %33, %38, %43, %48, %.loopexit23
  %.3 = phi i64 [ %.120, %.loopexit23 ], [ %22, %17 ], [ %27, %23 ], [ %32, %28 ], [ %37, %33 ], [ %42, %38 ], [ %47, %43 ], [ %52, %48 ]
  %53 = icmp eq i64 %.3, 0
  ret i1 %53
}

; 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,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass