; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseHistogram.ll (ZN4Simd4Base28AbsSecondDerivativeHistogramEPKhmmmmmPj)

; 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"

@.str = external hidden unnamed_addr constant [60 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@__PRETTY_FUNCTION__._ZN4Simd4Base28AbsSecondDerivativeHistogramEPKhmmmmmPj = external hidden unnamed_addr constant [115 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base28AbsSecondDerivativeHistogramEPKhmmmmmPj(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5, ptr noundef %6) #0 {
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  %18 = alloca i64, align 8
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i64 %1, ptr %9, align 8, !tbaa !9
  store i64 %2, ptr %10, align 8, !tbaa !9
  store i64 %3, ptr %11, align 8, !tbaa !9
  store i64 %4, ptr %12, align 8, !tbaa !9
  store i64 %5, ptr %13, align 8, !tbaa !9
  store ptr %6, ptr %14, align 8, !tbaa !5
  %22 = load i64, ptr %9, align 8, !tbaa !9
  %23 = load i64, ptr %13, align 8, !tbaa !9
  %24 = mul i64 2, %23
  %25 = icmp ugt i64 %22, %24
  br i1 %25, label %26, label %35

26:                                               ; preds = %7
  %27 = load i64, ptr %10, align 8, !tbaa !9
  %28 = load i64, ptr %13, align 8, !tbaa !9
  %29 = mul i64 2, %28
  %30 = icmp ugt i64 %27, %29
  br i1 %30, label %31, label %35

31:                                               ; preds = %26
  %32 = load i64, ptr %13, align 8, !tbaa !9
  %33 = load i64, ptr %12, align 8, !tbaa !9
  %34 = icmp uge i64 %32, %33
  br label %35

35:                                               ; preds = %31, %26, %7
  %36 = phi i1 [ false, %26 ], [ false, %7 ], [ %34, %31 ]
  br i1 %36, label %37, label %38

37:                                               ; preds = %35
  br label %40

38:                                               ; preds = %35
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 39, ptr noundef @__PRETTY_FUNCTION__._ZN4Simd4Base28AbsSecondDerivativeHistogramEPKhmmmmmPj) #6
  unreachable

39:                                               ; No predecessors!
  br label %40

40:                                               ; preds = %39, %37
  %41 = load ptr, ptr %14, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 4 %41, i8 0, i64 1024, i1 false)
  %42 = load i64, ptr %13, align 8, !tbaa !9
  %43 = load i64, ptr %11, align 8, !tbaa !9
  %44 = add i64 %43, 1
  %45 = mul i64 %42, %44
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i64 %45
  store ptr %47, ptr %8, align 8, !tbaa !5
  %48 = load i64, ptr %13, align 8, !tbaa !9
  %49 = mul i64 2, %48
  %50 = load i64, ptr %10, align 8, !tbaa !9
  %51 = sub i64 %50, %49
  store i64 %51, ptr %10, align 8, !tbaa !9
  %52 = load i64, ptr %13, align 8, !tbaa !9
  %53 = mul i64 2, %52
  %54 = load i64, ptr %9, align 8, !tbaa !9
  %55 = sub i64 %54, %53
  store i64 %55, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #7
  %56 = load i64, ptr %12, align 8, !tbaa !9
  %57 = load i64, ptr %11, align 8, !tbaa !9
  %58 = mul i64 %56, %57
  store i64 %58, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #7
  store i64 0, ptr %16, align 8, !tbaa !9
  br label %59

59:                                               ; preds = %97, %40
  %60 = load i64, ptr %16, align 8, !tbaa !9
  %61 = load i64, ptr %10, align 8, !tbaa !9
  %62 = icmp ult i64 %60, %61
  br i1 %62, label %64, label %63

63:                                               ; preds = %59
  store i32 2, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #7
  br label %100

64:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #7
  store i64 0, ptr %18, align 8, !tbaa !9
  br label %65

65:                                               ; preds = %90, %64
  %66 = load i64, ptr %18, align 8, !tbaa !9
  %67 = load i64, ptr %9, align 8, !tbaa !9
  %68 = icmp ult i64 %66, %67
  br i1 %68, label %70, label %69

69:                                               ; preds = %65
  store i32 5, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #7
  br label %93

70:                                               ; preds = %65
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #7
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = load i64, ptr %18, align 8, !tbaa !9
  %73 = getelementptr inbounds i8, ptr %71, i64 %72
  %74 = load i64, ptr %12, align 8, !tbaa !9
  %75 = call noundef i32 @_ZN4Simd4Base19AbsSecondDerivativeEPKhl(ptr noundef %73, i64 noundef %74)
  store i32 %75, ptr %19, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #7
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = load i64, ptr %18, align 8, !tbaa !9
  %78 = getelementptr inbounds i8, ptr %76, i64 %77
  %79 = load i64, ptr %15, align 8, !tbaa !9
  %80 = call noundef i32 @_ZN4Simd4Base19AbsSecondDerivativeEPKhl(ptr noundef %78, i64 noundef %79)
  store i32 %80, ptr %20, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #7
  %81 = load i32, ptr %20, align 4, !tbaa !11
  %82 = load i32, ptr %19, align 4, !tbaa !11
  %83 = call noundef i32 @_ZN4Simd4Base5MaxU8Eii(i32 noundef %81, i32 noundef %82)
  store i32 %83, ptr %21, align 4, !tbaa !11
  %84 = load ptr, ptr %14, align 8, !tbaa !5
  %85 = load i32, ptr %21, align 4, !tbaa !11
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds i32, ptr %84, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !11
  %89 = add i32 %88, 1
  store i32 %89, ptr %87, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #7
  br label %90

90:                                               ; preds = %70
  %91 = load i64, ptr %18, align 8, !tbaa !9
  %92 = add i64 %91, 1
  store i64 %92, ptr %18, align 8, !tbaa !9
  br label %65, !llvm.loop !13

93:                                               ; preds = %69
  %94 = load i64, ptr %11, align 8, !tbaa !9
  %95 = load ptr, ptr %8, align 8, !tbaa !5
  %96 = getelementptr inbounds i8, ptr %95, i64 %94
  store ptr %96, ptr %8, align 8, !tbaa !5
  br label %97

97:                                               ; preds = %93
  %98 = load i64, ptr %16, align 8, !tbaa !9
  %99 = add i64 %98, 1
  store i64 %99, ptr %16, align 8, !tbaa !9
  br label %59, !llvm.loop !15

100:                                              ; preds = %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #7
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef i32 @_ZN4Simd4Base19AbsSecondDerivativeEPKhl(ptr noundef, i64 noundef) #4

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4Simd4Base5MaxU8Eii(i32 noundef, i32 noundef) #5

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3

attributes #0 = { 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 #1 = { noreturn nounwind "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { alwaysinline 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 #5 = { alwaysinline 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 #6 = { noreturn nounwind }
attributes #7 = { 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 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !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"

@.str = external hidden unnamed_addr constant [60 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@__PRETTY_FUNCTION__._ZN4Simd4Base28AbsSecondDerivativeHistogramEPKhmmmmmPj = external hidden unnamed_addr constant [115 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base28AbsSecondDerivativeHistogramEPKhmmmmmPj(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5, ptr nocapture noundef %6) local_unnamed_addr #0 {
  %8 = shl i64 %5, 1
  %9 = icmp uge i64 %8, %1
  %10 = icmp uge i64 %8, %2
  %or.cond.not43 = or i1 %9, %10
  %.not = icmp ult i64 %5, %4
  %or.cond40 = or i1 %.not, %or.cond.not43
  br i1 %or.cond40, label %.critedge, label %.preheader.us.preheader

.critedge:                                        ; preds = %7
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 39, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4Simd4Base28AbsSecondDerivativeHistogramEPKhmmmmmPj) #6
  unreachable

.preheader.us.preheader:                          ; preds = %7
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1024) %6, i8 0, i64 1024, i1 false)
  %11 = sub i64 %2, %8
  %12 = sub i64 %1, %8
  %13 = mul i64 %4, %3
  %14 = add i64 %3, 1
  %15 = mul i64 %14, %5
  %16 = getelementptr inbounds i8, ptr %0, i64 %15
  %umax = tail call i64 @llvm.umax.i64(i64 %12, i64 1)
  %umax51 = tail call i64 @llvm.umax.i64(i64 %11, i64 1)
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.046.us = phi ptr [ %27, %._crit_edge.us ], [ %16, %.preheader.us.preheader ]
  %.03445.us = phi i64 [ %28, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  br label %17

17:                                               ; preds = %.preheader.us, %17
  %.03344.us = phi i64 [ 0, %.preheader.us ], [ %26, %17 ]
  %18 = getelementptr inbounds i8, ptr %.046.us, i64 %.03344.us
  %19 = tail call noundef i32 @_ZN4Simd4Base19AbsSecondDerivativeEPKhl(ptr noundef %18, i64 noundef %4)
  %20 = tail call noundef i32 @_ZN4Simd4Base19AbsSecondDerivativeEPKhl(ptr noundef %18, i64 noundef %13)
  %21 = tail call noundef i32 @_ZN4Simd4Base5MaxU8Eii(i32 noundef %20, i32 noundef %19)
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr %6, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = add i32 %24, 1
  store i32 %25, ptr %23, align 4, !tbaa !5
  %26 = add nuw i64 %.03344.us, 1
  %exitcond.not = icmp eq i64 %26, %umax
  br i1 %exitcond.not, label %._crit_edge.us, label %17, !llvm.loop !9

._crit_edge.us:                                   ; preds = %17
  %27 = getelementptr inbounds i8, ptr %.046.us, i64 %3
  %28 = add nuw i64 %.03445.us, 1
  %exitcond52.not = icmp eq i64 %28, %umax51
  br i1 %exitcond52.not, label %._crit_edge47, label %.preheader.us, !llvm.loop !11

._crit_edge47:                                    ; preds = %._crit_edge.us
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef i32 @_ZN4Simd4Base19AbsSecondDerivativeEPKhl(ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4Simd4Base5MaxU8Eii(i32 noundef, i32 noundef) local_unnamed_addr #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #5

attributes #0 = { 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 #1 = { noreturn nounwind "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 nounwind willreturn memory(argmem: write) }
attributes #3 = { alwaysinline 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 #4 = { alwaysinline 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { noreturn 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: ADCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass