; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseSobel.ll (ZN4Simd4Base14ContourMetricsEPKhmmmPtm)

; 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.1 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@__PRETTY_FUNCTION__._ZN4Simd4Base14ContourMetricsEPKhmmmPtm = external hidden unnamed_addr constant [93 x i8], align 1

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

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

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

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

21:                                               ; preds = %6
  br label %24

22:                                               ; preds = %6
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 213, ptr noundef @__PRETTY_FUNCTION__._ZN4Simd4Base14ContourMetricsEPKhmmmPtm) #4
  unreachable

23:                                               ; No predecessors!
  br label %24

24:                                               ; preds = %23, %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  store i64 0, ptr %16, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %104, %24
  %26 = load i64, ptr %16, align 8, !tbaa !9
  %27 = load i64, ptr %10, align 8, !tbaa !9
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  store i32 2, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  br label %107

30:                                               ; preds = %25
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load i64, ptr %8, align 8, !tbaa !9
  %33 = load i64, ptr %16, align 8, !tbaa !9
  %34 = sub i64 %33, 1
  %35 = mul i64 %32, %34
  %36 = getelementptr inbounds i8, ptr %31, i64 %35
  store ptr %36, ptr %13, align 8, !tbaa !5
  %37 = load ptr, ptr %13, align 8, !tbaa !5
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %37, i64 %38
  store ptr %39, ptr %14, align 8, !tbaa !5
  %40 = load ptr, ptr %14, align 8, !tbaa !5
  %41 = load i64, ptr %8, align 8, !tbaa !9
  %42 = getelementptr inbounds i8, ptr %40, i64 %41
  store ptr %42, ptr %15, align 8, !tbaa !5
  %43 = load i64, ptr %16, align 8, !tbaa !9
  %44 = icmp eq i64 %43, 0
  br i1 %44, label %45, label %47

45:                                               ; preds = %30
  %46 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %46, ptr %13, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %45, %30
  %48 = load i64, ptr %16, align 8, !tbaa !9
  %49 = load i64, ptr %10, align 8, !tbaa !9
  %50 = sub i64 %49, 1
  %51 = icmp eq i64 %48, %50
  br i1 %51, label %52, label %54

52:                                               ; preds = %47
  %53 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %53, ptr %15, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %52, %47
  %55 = load ptr, ptr %13, align 8, !tbaa !5
  %56 = load ptr, ptr %14, align 8, !tbaa !5
  %57 = load ptr, ptr %15, align 8, !tbaa !5
  %58 = call noundef i32 @_ZN4Simd4Base14ContourMetricsEPKhS2_S2_mmm(ptr noundef %55, ptr noundef %56, ptr noundef %57, i64 noundef 0, i64 noundef 0, i64 noundef 1)
  %59 = trunc i32 %58 to i16
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = getelementptr inbounds i16, ptr %60, i64 0
  store i16 %59, ptr %61, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #5
  store i64 1, ptr %18, align 8, !tbaa !9
  br label %62

62:                                               ; preds = %82, %54
  %63 = load i64, ptr %18, align 8, !tbaa !9
  %64 = load i64, ptr %9, align 8, !tbaa !9
  %65 = sub i64 %64, 1
  %66 = icmp ult i64 %63, %65
  br i1 %66, label %68, label %67

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

68:                                               ; preds = %62
  %69 = load ptr, ptr %13, align 8, !tbaa !5
  %70 = load ptr, ptr %14, align 8, !tbaa !5
  %71 = load ptr, ptr %15, align 8, !tbaa !5
  %72 = load i64, ptr %18, align 8, !tbaa !9
  %73 = sub i64 %72, 1
  %74 = load i64, ptr %18, align 8, !tbaa !9
  %75 = load i64, ptr %18, align 8, !tbaa !9
  %76 = add i64 %75, 1
  %77 = call noundef i32 @_ZN4Simd4Base14ContourMetricsEPKhS2_S2_mmm(ptr noundef %69, ptr noundef %70, ptr noundef %71, i64 noundef %73, i64 noundef %74, i64 noundef %76)
  %78 = trunc i32 %77 to i16
  %79 = load ptr, ptr %11, align 8, !tbaa !5
  %80 = load i64, ptr %18, align 8, !tbaa !9
  %81 = getelementptr inbounds i16, ptr %79, i64 %80
  store i16 %78, ptr %81, align 2, !tbaa !11
  br label %82

82:                                               ; preds = %68
  %83 = load i64, ptr %18, align 8, !tbaa !9
  %84 = add i64 %83, 1
  store i64 %84, ptr %18, align 8, !tbaa !9
  br label %62, !llvm.loop !13

85:                                               ; preds = %67
  %86 = load ptr, ptr %13, align 8, !tbaa !5
  %87 = load ptr, ptr %14, align 8, !tbaa !5
  %88 = load ptr, ptr %15, align 8, !tbaa !5
  %89 = load i64, ptr %9, align 8, !tbaa !9
  %90 = sub i64 %89, 2
  %91 = load i64, ptr %9, align 8, !tbaa !9
  %92 = sub i64 %91, 1
  %93 = load i64, ptr %9, align 8, !tbaa !9
  %94 = sub i64 %93, 1
  %95 = call noundef i32 @_ZN4Simd4Base14ContourMetricsEPKhS2_S2_mmm(ptr noundef %86, ptr noundef %87, ptr noundef %88, i64 noundef %90, i64 noundef %92, i64 noundef %94)
  %96 = trunc i32 %95 to i16
  %97 = load ptr, ptr %11, align 8, !tbaa !5
  %98 = load i64, ptr %9, align 8, !tbaa !9
  %99 = sub i64 %98, 1
  %100 = getelementptr inbounds i16, ptr %97, i64 %99
  store i16 %96, ptr %100, align 2, !tbaa !11
  %101 = load i64, ptr %12, align 8, !tbaa !9
  %102 = load ptr, ptr %11, align 8, !tbaa !5
  %103 = getelementptr inbounds i16, ptr %102, i64 %101
  store ptr %103, ptr %11, align 8, !tbaa !5
  br label %104

104:                                              ; preds = %85
  %105 = load i64, ptr %16, align 8, !tbaa !9
  %106 = add i64 %105, 1
  store i64 %106, ptr %16, align 8, !tbaa !9
  br label %25, !llvm.loop !15

107:                                              ; preds = %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  ret void
}

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { noreturn nounwind }
attributes #5 = { 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 = !{!"short", !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.1 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@__PRETTY_FUNCTION__._ZN4Simd4Base14ContourMetricsEPKhmmmPtm = external hidden unnamed_addr constant [93 x i8], align 1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base14ContourMetricsEPKhmmmPtm(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef writeonly %4, i64 noundef %5) local_unnamed_addr #1 {
  %7 = icmp ugt i64 %2, 1
  br i1 %7, label %.preheader, label %37

.preheader:                                       ; preds = %6
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %._crit_edge51, label %.lr.ph50

.lr.ph50:                                         ; preds = %.preheader
  %8 = add i64 %3, -1
  %9 = add i64 %2, -1
  %10 = icmp ugt i64 %9, 1
  %11 = add i64 %2, -2
  br i1 %10, label %.lr.ph.us, label %.lr.ph50.split.preheader

.lr.ph50.split.preheader:                         ; preds = %.lr.ph50
  %12 = icmp eq i64 %8, 0
  %.041.idx.peel = select i1 %12, i64 0, i64 %1
  %.041.peel = getelementptr inbounds i8, ptr %0, i64 %.041.idx.peel
  %13 = tail call noundef i32 @_ZN4Simd4Base14ContourMetricsEPKhS2_S2_mmm(ptr noundef %0, ptr noundef %0, ptr noundef %.041.peel, i64 noundef 0, i64 noundef 0, i64 noundef 1)
  %14 = trunc i32 %13 to i16
  store i16 %14, ptr %4, align 2, !tbaa !5
  %15 = tail call noundef i32 @_ZN4Simd4Base14ContourMetricsEPKhS2_S2_mmm(ptr noundef %0, ptr noundef %0, ptr noundef %.041.peel, i64 noundef %11, i64 noundef %9, i64 noundef %9)
  %16 = trunc i32 %15 to i16
  %17 = getelementptr inbounds i16, ptr %4, i64 %9
  store i16 %16, ptr %17, align 2, !tbaa !5
  %exitcond.peel.not = icmp eq i64 %3, 1
  br i1 %exitcond.peel.not, label %._crit_edge51, label %.lr.ph50.split

.lr.ph.us:                                        ; preds = %.lr.ph50, %._crit_edge.us
  %.04049.us = phi i64 [ %36, %._crit_edge.us ], [ 0, %.lr.ph50 ]
  %.04248.us = phi ptr [ %35, %._crit_edge.us ], [ %4, %.lr.ph50 ]
  %18 = add i64 %.04049.us, -1
  %19 = mul i64 %18, %1
  %20 = getelementptr inbounds i8, ptr %0, i64 %19
  %21 = getelementptr inbounds i8, ptr %20, i64 %1
  %22 = icmp eq i64 %.04049.us, 0
  %spec.select.us = select i1 %22, ptr %21, ptr %20
  %23 = icmp eq i64 %.04049.us, %8
  %.041.idx.us = select i1 %23, i64 0, i64 %1
  %.041.us = getelementptr inbounds i8, ptr %21, i64 %.041.idx.us
  %24 = tail call noundef i32 @_ZN4Simd4Base14ContourMetricsEPKhS2_S2_mmm(ptr noundef %spec.select.us, ptr noundef %21, ptr noundef %.041.us, i64 noundef 0, i64 noundef 0, i64 noundef 1)
  %25 = trunc i32 %24 to i16
  store i16 %25, ptr %.04248.us, align 2, !tbaa !5
  br label %26

26:                                               ; preds = %.lr.ph.us, %26
  %.047.us = phi i64 [ 1, %.lr.ph.us ], [ %28, %26 ]
  %27 = add i64 %.047.us, -1
  %28 = add nuw i64 %.047.us, 1
  %29 = tail call noundef i32 @_ZN4Simd4Base14ContourMetricsEPKhS2_S2_mmm(ptr noundef %spec.select.us, ptr noundef %21, ptr noundef %.041.us, i64 noundef %27, i64 noundef %.047.us, i64 noundef %28)
  %30 = trunc i32 %29 to i16
  %31 = getelementptr inbounds i16, ptr %.04248.us, i64 %.047.us
  store i16 %30, ptr %31, align 2, !tbaa !5
  %exitcond54.not = icmp eq i64 %28, %9
  br i1 %exitcond54.not, label %._crit_edge.us, label %26, !llvm.loop !9

._crit_edge.us:                                   ; preds = %26
  %32 = tail call noundef i32 @_ZN4Simd4Base14ContourMetricsEPKhS2_S2_mmm(ptr noundef %spec.select.us, ptr noundef %21, ptr noundef %.041.us, i64 noundef %11, i64 noundef %9, i64 noundef %9)
  %33 = trunc i32 %32 to i16
  %34 = getelementptr inbounds i16, ptr %.04248.us, i64 %9
  store i16 %33, ptr %34, align 2, !tbaa !5
  %35 = getelementptr inbounds i16, ptr %.04248.us, i64 %5
  %36 = add nuw i64 %.04049.us, 1
  %exitcond55.not = icmp eq i64 %36, %3
  br i1 %exitcond55.not, label %._crit_edge51, label %.lr.ph.us, !llvm.loop !11

37:                                               ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 213, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4Simd4Base14ContourMetricsEPKhmmmPtm) #3
  unreachable

._crit_edge51:                                    ; preds = %.lr.ph50.split, %._crit_edge.us, %.lr.ph50.split.preheader, %.preheader
  ret void

.lr.ph50.split:                                   ; preds = %.lr.ph50.split.preheader, %.lr.ph50.split
  %.04049 = phi i64 [ %48, %.lr.ph50.split ], [ 1, %.lr.ph50.split.preheader ]
  %.04248.pn = phi ptr [ %.04248, %.lr.ph50.split ], [ %4, %.lr.ph50.split.preheader ]
  %.04248 = getelementptr inbounds i16, ptr %.04248.pn, i64 %5
  %38 = add i64 %.04049, -1
  %39 = mul i64 %38, %1
  %40 = getelementptr inbounds i8, ptr %0, i64 %39
  %41 = getelementptr inbounds i8, ptr %40, i64 %1
  %42 = icmp eq i64 %.04049, %8
  %.041.idx = select i1 %42, i64 0, i64 %1
  %.041 = getelementptr inbounds i8, ptr %41, i64 %.041.idx
  %43 = tail call noundef i32 @_ZN4Simd4Base14ContourMetricsEPKhS2_S2_mmm(ptr noundef %40, ptr noundef %41, ptr noundef %.041, i64 noundef 0, i64 noundef 0, i64 noundef 1)
  %44 = trunc i32 %43 to i16
  store i16 %44, ptr %.04248, align 2, !tbaa !5
  %45 = tail call noundef i32 @_ZN4Simd4Base14ContourMetricsEPKhS2_S2_mmm(ptr noundef %40, ptr noundef %41, ptr noundef %.041, i64 noundef %11, i64 noundef %9, i64 noundef %9)
  %46 = trunc i32 %45 to i16
  %47 = getelementptr inbounds i16, ptr %.04248, i64 %9
  store i16 %46, ptr %47, align 2, !tbaa !5
  %48 = add nuw i64 %.04049, 1
  %exitcond.not = icmp eq i64 %48, %3
  br i1 %exitcond.not, label %._crit_edge51, label %.lr.ph50.split, !llvm.loop !12
}

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

attributes #0 = { 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 #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 = { 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 #3 = { 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 = !{!"short", !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}
!12 = distinct !{!12, !10, !13}
!13 = !{!"llvm.loop.peeled.count", i32 1}


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