; LLVM IR from jingweizhanghuai/Morn :: src/image/morn_image_geometry2.ll (EdgeBoundary)

; 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.MList = type { i32, ptr }
%struct.MChainNode = type { ptr, ptr, 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: nounwind uwtable
declare dso_local float @mPointVerticalDistance(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare ptr @mChainNode(ptr noundef, ptr noundef, i32 noundef) #2

declare void @mChainNodeInsert(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @_EdgeBoundary(ptr noundef %0, ptr noundef %1, ptr noundef %2, float noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca float, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca float, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca float, align 4
  %18 = alloca i32, align 4
  %19 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store float %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.MList, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  store ptr %22, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.MChainNode, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = load i32, ptr %25, align 4, !tbaa !16
  store i32 %26, ptr %10, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.MChainNode, ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !17
  %30 = getelementptr inbounds %struct.MChainNode, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %32 = load i32, ptr %31, align 4, !tbaa !16
  store i32 %32, ptr %11, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = load i32, ptr %10, align 4, !tbaa !16
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds ptr, ptr %33, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  store ptr %37, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = load i32, ptr %11, align 4, !tbaa !16
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.MList, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !18
  %43 = icmp eq i32 %39, %42
  br i1 %43, label %44, label %45

44:                                               ; preds = %4
  br label %47

45:                                               ; preds = %4
  %46 = load i32, ptr %11, align 4, !tbaa !16
  br label %47

47:                                               ; preds = %45, %44
  %48 = phi i32 [ 0, %44 ], [ %46, %45 ]
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds ptr, ptr %38, i64 %49
  %51 = load ptr, ptr %50, align 8, !tbaa !5
  store ptr %51, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store float 0.000000e+00, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %52 = load i32, ptr %10, align 4, !tbaa !16
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %16, align 4, !tbaa !16
  br label %54

54:                                               ; preds = %75, %47
  %55 = load i32, ptr %16, align 4, !tbaa !16
  %56 = load i32, ptr %11, align 4, !tbaa !16
  %57 = icmp slt i32 %55, %56
  br i1 %57, label %59, label %58

58:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  br label %78

59:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = load i32, ptr %16, align 4, !tbaa !16
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds ptr, ptr %60, i64 %62
  %64 = load ptr, ptr %63, align 8, !tbaa !5
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  %66 = load ptr, ptr %13, align 8, !tbaa !5
  %67 = call float @mPointVerticalDistance(ptr noundef %64, ptr noundef %65, ptr noundef %66, ptr noundef null)
  store float %67, ptr %17, align 4, !tbaa !9
  %68 = load float, ptr %17, align 4, !tbaa !9
  %69 = load float, ptr %14, align 4, !tbaa !9
  %70 = fcmp ogt float %68, %69
  br i1 %70, label %71, label %74

71:                                               ; preds = %59
  %72 = load float, ptr %17, align 4, !tbaa !9
  store float %72, ptr %14, align 4, !tbaa !9
  %73 = load i32, ptr %16, align 4, !tbaa !16
  store i32 %73, ptr %15, align 4, !tbaa !16
  br label %74

74:                                               ; preds = %71, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %16, align 4, !tbaa !16
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %16, align 4, !tbaa !16
  br label %54, !llvm.loop !19

78:                                               ; preds = %58
  %79 = load float, ptr %14, align 4, !tbaa !9
  %80 = load float, ptr %8, align 4, !tbaa !9
  %81 = fcmp olt float %79, %80
  br i1 %81, label %82, label %83

82:                                               ; preds = %78
  store i32 1, ptr %18, align 4
  br label %96

83:                                               ; preds = %78
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = call ptr @mChainNode(ptr noundef %84, ptr noundef %15, i32 noundef 4)
  store ptr %85, ptr %19, align 8, !tbaa !5
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = load ptr, ptr %19, align 8, !tbaa !5
  call void @mChainNodeInsert(ptr noundef %86, ptr noundef %87, ptr noundef null)
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = load float, ptr %8, align 4, !tbaa !9
  call void @_EdgeBoundary(ptr noundef %88, ptr noundef %89, ptr noundef %90, float noundef %91)
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = load ptr, ptr %19, align 8, !tbaa !5
  %95 = load float, ptr %8, align 4, !tbaa !9
  call void @_EdgeBoundary(ptr noundef %92, ptr noundef %93, ptr noundef %94, float noundef %95)
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  store i32 0, ptr %18, align 4
  br label %96

96:                                               ; preds = %83, %82
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %97 = load i32, ptr %18, align 4
  switch i32 %97, label %99 [
    i32 0, label %98
    i32 1, label %98
  ]

98:                                               ; preds = %96, %96
  ret void

99:                                               ; preds = %96
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"MList", !13, i64 0, !6, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"MChainNode", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!13, !13, i64 0}
!17 = !{!15, !6, i64 16}
!18 = !{!12, !13, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
declare dso_local float @mPointVerticalDistance(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @mChainNode(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @mChainNodeInsert(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @_EdgeBoundary(ptr noundef %0, ptr noundef %1, ptr noundef %2, float noundef %3) local_unnamed_addr #1 {
  %5 = alloca i32, align 4
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8, !tbaa !11
  %9 = load i32, ptr %8, align 4, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %2, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = load i32, ptr %12, align 4, !tbaa !13
  %14 = sext i32 %9 to i64
  %15 = getelementptr inbounds ptr, ptr %7, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  %17 = load i32, ptr %0, align 8, !tbaa !16
  %18 = icmp eq i32 %13, %17
  %19 = select i1 %18, i32 0, i32 %13
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds ptr, ptr %7, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %.03338 = add nsw i32 %9, 1
  %23 = icmp slt i32 %.03338, %13
  br i1 %23, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %4
  %24 = add nsw i64 %14, 1
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %4
  %.03337.lcssa = phi i32 [ undef, %4 ], [ %.03336, %.lr.ph ]
  %.0.lcssa = phi float [ 0.000000e+00, %4 ], [ %.1, %.lr.ph ]
  store i32 %.03337.lcssa, ptr %5, align 4, !tbaa !13
  %25 = fcmp olt float %.0.lcssa, %3
  br i1 %25, label %33, label %31

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %24, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.040 = phi float [ 0.000000e+00, %.lr.ph.preheader ], [ %.1, %.lr.ph ]
  %.0333739 = phi i32 [ undef, %.lr.ph.preheader ], [ %.03336, %.lr.ph ]
  %26 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  %28 = tail call float @mPointVerticalDistance(ptr noundef %27, ptr noundef %16, ptr noundef %22, ptr noundef null)
  %29 = fcmp ogt float %28, %.040
  %30 = trunc nsw i64 %indvars.iv to i32
  %.03336 = select i1 %29, i32 %30, i32 %.0333739
  %.1 = select i1 %29, float %28, float %.040
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
  %exitcond.not = icmp eq i32 %13, %lftr.wideiv
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17

31:                                               ; preds = %._crit_edge
  %32 = call ptr @mChainNode(ptr noundef %1, ptr noundef nonnull %5, i32 noundef 4) #3
  call void @mChainNodeInsert(ptr noundef nonnull %2, ptr noundef %32, ptr noundef null) #3
  call void @_EdgeBoundary(ptr noundef nonnull %0, ptr noundef %1, ptr noundef nonnull %2, float noundef %3)
  call void @_EdgeBoundary(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %32, float noundef %3)
  br label %33

33:                                               ; preds = %._crit_edge, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  ret void
}

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


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