; LLVM IR from Slingshot-Physics/slingshot-community :: common/math/src/heap_matrix.ll (ZNK10HeapMatrixeqERKS_)

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

%class.HeapMatrix = type { i32, i32, i32, i32, i32, [12 x i8], ptr, [8 x i8] }

; 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 uwtable
declare dso_local noundef float @_ZNK10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40), i32 noundef, i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK10HeapMatrixeqERKS_(ptr noundef nonnull align 16 dereferenceable(40) %0, ptr noundef nonnull align 16 dereferenceable(40) %1) #1 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %class.HeapMatrix, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 16, !tbaa !9
  %13 = getelementptr inbounds %class.HeapMatrix, ptr %9, i32 0, i32 0
  %14 = load i32, ptr %13, align 16, !tbaa !9
  %15 = icmp ne i32 %12, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  br label %62

17:                                               ; preds = %2
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %class.HeapMatrix, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !12
  %21 = getelementptr inbounds %class.HeapMatrix, ptr %9, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !12
  %23 = icmp ne i32 %20, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %17
  store i1 false, ptr %3, align 1
  br label %62

25:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !13
  br label %26

26:                                               ; preds = %56, %25
  %27 = load i32, ptr %6, align 4, !tbaa !13
  %28 = getelementptr inbounds %class.HeapMatrix, ptr %9, i32 0, i32 0
  %29 = load i32, ptr %28, align 16, !tbaa !9
  %30 = icmp ult i32 %27, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %26
  store i32 2, ptr %7, align 4
  br label %59

32:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !13
  br label %33

33:                                               ; preds = %50, %32
  %34 = load i32, ptr %8, align 4, !tbaa !13
  %35 = getelementptr inbounds %class.HeapMatrix, ptr %9, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !12
  %37 = icmp ult i32 %34, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %33
  store i32 5, ptr %7, align 4
  br label %53

39:                                               ; preds = %33
  %40 = load i32, ptr %6, align 4, !tbaa !13
  %41 = load i32, ptr %8, align 4, !tbaa !13
  %42 = call noundef float @_ZNK10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40) %9, i32 noundef %40, i32 noundef %41)
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !13
  %45 = load i32, ptr %8, align 4, !tbaa !13
  %46 = call noundef float @_ZNK10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40) %43, i32 noundef %44, i32 noundef %45)
  %47 = fcmp une float %42, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %39
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %53

49:                                               ; preds = %39
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %8, align 4, !tbaa !13
  %52 = add i32 %51, 1
  store i32 %52, ptr %8, align 4, !tbaa !13
  br label %33, !llvm.loop !14

53:                                               ; preds = %48, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %54 = load i32, ptr %7, align 4
  switch i32 %54, label %59 [
    i32 5, label %55
  ]

55:                                               ; preds = %53
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %6, align 4, !tbaa !13
  %58 = add i32 %57, 1
  store i32 %58, ptr %6, align 4, !tbaa !13
  br label %26, !llvm.loop !16

59:                                               ; preds = %53, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %60 = load i32, ptr %7, align 4
  switch i32 %60, label %64 [
    i32 2, label %61
    i32 1, label %62
  ]

61:                                               ; preds = %59
  store i1 true, ptr %3, align 1
  br label %62

62:                                               ; preds = %61, %59, %24, %16
  %63 = load i1, ptr %3, align 1
  ret i1 %63

64:                                               ; preds = %59
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !11, i64 0}
!10 = !{!"_ZTS10HeapMatrix", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!11, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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 uwtable
declare dso_local noundef float @_ZNK10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40), i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK10HeapMatrixeqERKS_(ptr noundef nonnull align 16 dereferenceable(40) %0, ptr noundef nonnull align 16 dereferenceable(40) %1) local_unnamed_addr #0 align 2 {
  %3 = load i32, ptr %1, align 16, !tbaa !5
  %4 = load i32, ptr %0, align 16, !tbaa !5
  %.not = icmp eq i32 %3, %4
  br i1 %.not, label %5, label %.thread

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %.not18 = icmp eq i32 %7, %9
  br i1 %.not18, label %.preheader21, label %.thread

.preheader21:                                     ; preds = %5
  %10 = icmp eq i32 %3, 0
  %.not27 = icmp eq i32 %7, 0
  %or.cond = or i1 %10, %.not27
  br i1 %or.cond, label %.thread, label %.preheader

.preheader:                                       ; preds = %.preheader21, %._crit_edge
  %11 = phi i32 [ %19, %._crit_edge ], [ %3, %.preheader21 ]
  %12 = phi i32 [ %20, %._crit_edge ], [ 1, %.preheader21 ]
  %.01526 = phi i32 [ %21, %._crit_edge ], [ 0, %.preheader21 ]
  %.not1924.not = icmp eq i32 %12, 0
  br i1 %.not1924.not, label %._crit_edge, label %.lr.ph

13:                                               ; preds = %.lr.ph
  %14 = add nuw i32 %.025, 1
  %15 = load i32, ptr %8, align 4, !tbaa !11
  %.not19 = icmp ult i32 %14, %15
  br i1 %.not19, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !12

.lr.ph:                                           ; preds = %.preheader, %13
  %.025 = phi i32 [ %14, %13 ], [ 0, %.preheader ]
  %16 = tail call noundef float @_ZNK10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40) %0, i32 noundef %.01526, i32 noundef %.025)
  %17 = tail call noundef float @_ZNK10HeapMatrixclEjj(ptr noundef nonnull align 16 dereferenceable(40) %1, i32 noundef %.01526, i32 noundef %.025)
  %18 = fcmp une float %16, %17
  br i1 %18, label %.thread, label %13

._crit_edge.loopexit:                             ; preds = %13
  %.pre = load i32, ptr %0, align 16, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %19 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %11, %.preheader ]
  %20 = phi i32 [ %15, %._crit_edge.loopexit ], [ 0, %.preheader ]
  %21 = add nuw i32 %.01526, 1
  %.not31 = icmp ult i32 %21, %19
  br i1 %.not31, label %.preheader, label %.thread, !llvm.loop !14

.thread:                                          ; preds = %._crit_edge, %.lr.ph, %.preheader21, %5, %2
  %.3 = phi i1 [ false, %2 ], [ false, %5 ], [ true, %.preheader21 ], [ false, %.lr.ph ], [ true, %._crit_edge ]
  ret i1 %.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" }

!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, !7, i64 0}
!6 = !{!"_ZTS10HeapMatrix", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13, !15}
!15 = !{!"llvm.loop.unswitch.partial.disable"}


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