; LLVM IR from mackorone/mms :: old/v2/src/sim (BufferInterface)

; 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.std::pair.133" = type { i32, i32 }
%"class.sim::BufferInterface" = type { %"struct.std::pair.133", ptr, ptr, %"class.sim::TileGraphicTextCache" }
%"class.sim::TileGraphicTextCache" = type { %"class.sim::Meters", %"class.sim::Meters", %"struct.std::pair.133", %"class.std::map.135", %"class.std::map.140" }
%"class.sim::Meters" = type { %"class.sim::Distance" }
%"class.sim::Distance" = type { ptr, double }
%"class.std::map.135" = type { %"class.std::_Rb_tree.136" }
%"class.std::_Rb_tree.136" = type { %"struct.std::_Rb_tree<char, std::pair<const char, std::pair<double, double>>, std::_Select1st<std::pair<const char, std::pair<double, double>>>, std::less<char>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<char, std::pair<const char, std::pair<double, double>>, std::_Select1st<std::pair<const char, std::pair<double, double>>>, std::less<char>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"class.std::map.140" = type { %"class.std::_Rb_tree.141" }
%"class.std::_Rb_tree.141" = type { %"struct.std::_Rb_tree<std::pair<std::pair<int, int>, std::pair<int, int>>, std::pair<const std::pair<std::pair<int, int>, std::pair<int, int>>, std::pair<sim::Cartesian, sim::Cartesian>>, std::_Select1st<std::pair<const std::pair<std::pair<int, int>, std::pair<int, int>>, std::pair<sim::Cartesian, sim::Cartesian>>>, std::less<std::pair<std::pair<int, int>, std::pair<int, int>>>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<std::pair<std::pair<int, int>, std::pair<int, int>>, std::pair<const std::pair<std::pair<int, int>, std::pair<int, int>>, std::pair<sim::Cartesian, sim::Cartesian>>, std::_Select1st<std::pair<const std::pair<std::pair<int, int>, std::pair<int, int>>, std::pair<sim::Cartesian, sim::Cartesian>>>, std::less<std::pair<std::pair<int, int>, std::pair<int, int>>>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }

@_ZZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols = external hidden global %"struct.std::pair.133", align 4
@_ZGVZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols = external hidden global i64, align 8
@_ZZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE23triangleTexturesPerTile = external hidden global i32, align 4
@_ZGVZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE23triangleTexturesPerTile = external hidden global i64, align 8

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZN3sim15BufferInterface25getTileGraphicTextMaxSizeEv(ptr noundef nonnull align 8 dereferenceable(160)) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiii(ptr noundef nonnull align 8 dereferenceable(160) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #0 align 2 personality ptr @__gxx_personality_v0 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %13 = load ptr, ptr %6, align 8
  %14 = load atomic i8, ptr @_ZGVZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols acquire, align 8
  %15 = icmp eq i8 %14, 0
  br i1 %15, label %16, label %22, !prof !11

16:                                               ; preds = %5
  %17 = call i32 @__cxa_guard_acquire(ptr @_ZGVZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols) #1
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %22

19:                                               ; preds = %16
  %20 = invoke i64 @_ZN3sim15BufferInterface25getTileGraphicTextMaxSizeEv(ptr noundef nonnull align 8 dereferenceable(160) %13)
          to label %21 unwind label %50

21:                                               ; preds = %19
  store i64 %20, ptr @_ZZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols, align 4
  call void @__cxa_guard_release(ptr @_ZGVZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols) #1
  br label %22

22:                                               ; preds = %21, %16, %5
  %23 = load atomic i8, ptr @_ZGVZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE23triangleTexturesPerTile acquire, align 8
  %24 = icmp eq i8 %23, 0
  br i1 %24, label %25, label %33, !prof !11

25:                                               ; preds = %22
  %26 = call i32 @__cxa_guard_acquire(ptr @_ZGVZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE23triangleTexturesPerTile) #1
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %33

28:                                               ; preds = %25
  %29 = load i32, ptr @_ZZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols, align 4, !tbaa !12
  %30 = mul nsw i32 2, %29
  %31 = load i32, ptr getelementptr inbounds (%"struct.std::pair.133", ptr @_ZZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols, i32 0, i32 1), align 4, !tbaa !14
  %32 = mul nsw i32 %30, %31
  store i32 %32, ptr @_ZZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE23triangleTexturesPerTile, align 4, !tbaa !9
  call void @__cxa_guard_release(ptr @_ZGVZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE23triangleTexturesPerTile) #1
  br label %33

33:                                               ; preds = %28, %25, %22
  %34 = load i32, ptr @_ZZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE23triangleTexturesPerTile, align 4, !tbaa !9
  %35 = getelementptr inbounds %"class.sim::BufferInterface", ptr %13, i32 0, i32 0
  %36 = getelementptr inbounds %"struct.std::pair.133", ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !15
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = mul nsw i32 %37, %38
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = add nsw i32 %39, %40
  %42 = mul nsw i32 %34, %41
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = load i32, ptr getelementptr inbounds (%"struct.std::pair.133", ptr @_ZZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols, i32 0, i32 1), align 4, !tbaa !14
  %45 = mul nsw i32 %43, %44
  %46 = load i32, ptr %10, align 4, !tbaa !9
  %47 = add nsw i32 %45, %46
  %48 = mul nsw i32 2, %47
  %49 = add nsw i32 %42, %48
  ret i32 %49

50:                                               ; preds = %19
  %51 = landingpad { ptr, i32 }
          cleanup
  %52 = extractvalue { ptr, i32 } %51, 0
  store ptr %52, ptr %11, align 8
  %53 = extractvalue { ptr, i32 } %51, 1
  store i32 %53, ptr %12, align 4
  call void @__cxa_guard_abort(ptr @_ZGVZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols) #1
  br label %54

54:                                               ; preds = %50
  %55 = load ptr, ptr %11, align 8
  %56 = load i32, ptr %12, align 4
  %57 = insertvalue { ptr, i32 } poison, ptr %55, 0
  %58 = insertvalue { ptr, i32 } %57, i32 %56, 1
  resume { ptr, i32 } %58
}

; Function Attrs: nounwind
declare i32 @__cxa_guard_acquire(ptr) #1

; Function Attrs: nounwind
declare void @__cxa_guard_abort(ptr) #1

; Function Attrs: nounwind
declare void @__cxa_guard_release(ptr) #1

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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!"branch_weights", i32 1, i32 1048575}
!12 = !{!13, !10, i64 0}
!13 = !{!"_ZTSSt4pairIiiE", !10, i64 0, !10, i64 4}
!14 = !{!13, !10, i64 4}
!15 = !{!16, !10, i64 4}
!16 = !{!"_ZTSN3sim15BufferInterfaceE", !13, i64 0, !6, i64 8, !6, i64 16, !17, i64 24}
!17 = !{!"_ZTSN3sim20TileGraphicTextCacheE", !18, i64 0, !18, i64 16, !13, i64 32, !21, i64 40, !30, i64 88}
!18 = !{!"_ZTSN3sim6MetersE", !19, i64 0}
!19 = !{!"_ZTSN3sim8DistanceE", !20, i64 8}
!20 = !{!"double", !7, i64 0}
!21 = !{!"_ZTSSt3mapIcSt4pairIddESt4lessIcESaIS0_IKcS1_EEE", !22, i64 0}
!22 = !{!"_ZTSSt8_Rb_treeIcSt4pairIKcS0_IddEESt10_Select1stIS3_ESt4lessIcESaIS3_EE", !23, i64 0}
!23 = !{!"_ZTSNSt8_Rb_treeIcSt4pairIKcS0_IddEESt10_Select1stIS3_ESt4lessIcESaIS3_EE13_Rb_tree_implIS7_Lb1EEE", !24, i64 0, !26, i64 8}
!24 = !{!"_ZTSSt20_Rb_tree_key_compareISt4lessIcEE", !25, i64 0}
!25 = !{!"_ZTSSt4lessIcE"}
!26 = !{!"_ZTSSt15_Rb_tree_header", !27, i64 0, !29, i64 32}
!27 = !{!"_ZTSSt18_Rb_tree_node_base", !28, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!28 = !{!"_ZTSSt14_Rb_tree_color", !7, i64 0}
!29 = !{!"long", !7, i64 0}
!30 = !{!"_ZTSSt3mapISt4pairIS0_IiiES1_ES0_IN3sim9CartesianES4_ESt4lessIS2_ESaIS0_IKS2_S5_EEE", !31, i64 0}
!31 = !{!"_ZTSSt8_Rb_treeISt4pairIS0_IiiES1_ES0_IKS2_S0_IN3sim9CartesianES5_EESt10_Select1stIS7_ESt4lessIS2_ESaIS7_EE", !32, i64 0}
!32 = !{!"_ZTSNSt8_Rb_treeISt4pairIS0_IiiES1_ES0_IKS2_S0_IN3sim9CartesianES5_EESt10_Select1stIS7_ESt4lessIS2_ESaIS7_EE13_Rb_tree_implISB_Lb1EEE", !33, i64 0, !26, i64 8}
!33 = !{!"_ZTSSt20_Rb_tree_key_compareISt4lessISt4pairIS1_IiiES2_EEE", !34, i64 0}
!34 = !{!"_ZTSSt4lessISt4pairIS0_IiiES1_EE"}


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

%"struct.std::pair.133" = type { i32, i32 }

@_ZZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols = external hidden local_unnamed_addr global %"struct.std::pair.133", align 4
@_ZGVZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols = external hidden global i64, align 8
@_ZZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE23triangleTexturesPerTile = external hidden local_unnamed_addr global i32, align 4
@_ZGVZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE23triangleTexturesPerTile = external hidden global i64, align 8

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZN3sim15BufferInterface25getTileGraphicTextMaxSizeEv(ptr noundef nonnull align 8 dereferenceable(160)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiii(ptr noundef nonnull align 8 dereferenceable(160) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %6 = load atomic i8, ptr @_ZGVZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols acquire, align 8
  %7 = icmp eq i8 %6, 0
  br i1 %7, label %8, label %13, !prof !5

8:                                                ; preds = %5
  %9 = tail call i32 @__cxa_guard_acquire(ptr nonnull @_ZGVZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols) #2
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %13, label %10

10:                                               ; preds = %8
  %11 = invoke i64 @_ZN3sim15BufferInterface25getTileGraphicTextMaxSizeEv(ptr noundef nonnull align 8 dereferenceable(160) %0)
          to label %12 unwind label %35

12:                                               ; preds = %10
  store i64 %11, ptr @_ZZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols, align 4
  tail call void @__cxa_guard_release(ptr nonnull @_ZGVZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols) #2
  br label %13

13:                                               ; preds = %12, %8, %5
  %14 = load atomic i8, ptr @_ZGVZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE23triangleTexturesPerTile acquire, align 8
  %15 = icmp eq i8 %14, 0
  br i1 %15, label %16, label %23, !prof !5

16:                                               ; preds = %13
  %17 = tail call i32 @__cxa_guard_acquire(ptr nonnull @_ZGVZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE23triangleTexturesPerTile) #2
  %.not6 = icmp eq i32 %17, 0
  br i1 %.not6, label %23, label %18

18:                                               ; preds = %16
  %19 = load i32, ptr @_ZZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols, align 4, !tbaa !6
  %20 = shl nsw i32 %19, 1
  %21 = load i32, ptr getelementptr inbounds (i8, ptr @_ZZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols, i64 4), align 4, !tbaa !11
  %22 = mul nsw i32 %20, %21
  store i32 %22, ptr @_ZZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE23triangleTexturesPerTile, align 4, !tbaa !12
  tail call void @__cxa_guard_release(ptr nonnull @_ZGVZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE23triangleTexturesPerTile) #2
  br label %23

23:                                               ; preds = %18, %16, %13
  %24 = load i32, ptr @_ZZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE23triangleTexturesPerTile, align 4, !tbaa !12
  %25 = getelementptr inbounds i8, ptr %0, i64 4
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = mul nsw i32 %26, %1
  %28 = add nsw i32 %27, %2
  %29 = mul nsw i32 %28, %24
  %30 = load i32, ptr getelementptr inbounds (i8, ptr @_ZZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols, i64 4), align 4, !tbaa !11
  %31 = mul nsw i32 %30, %3
  %32 = add nsw i32 %31, %4
  %33 = shl nsw i32 %32, 1
  %34 = add nsw i32 %33, %29
  ret i32 %34

35:                                               ; preds = %10
  %36 = landingpad { ptr, i32 }
          cleanup
  tail call void @__cxa_guard_abort(ptr nonnull @_ZGVZN3sim15BufferInterface31getTileGraphicTextStartingIndexEiiiiE14maxRowsAndCols) #2
  resume { ptr, i32 } %36
}

; Function Attrs: nofree nounwind
declare i32 @__cxa_guard_acquire(ptr) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare void @__cxa_guard_abort(ptr) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare void @__cxa_guard_release(ptr) local_unnamed_addr #1

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 = { nofree nounwind }
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 = !{!"branch_weights", i32 1, i32 1048575}
!6 = !{!7, !8, i64 0}
!7 = !{!"_ZTSSt4pairIiiE", !8, i64 0, !8, i64 4}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!7, !8, i64 4}
!12 = !{!8, !8, i64 0}
!13 = !{!14, !8, i64 4}
!14 = !{!"_ZTSN3sim15BufferInterfaceE", !7, i64 0, !15, i64 8, !15, i64 16, !16, i64 24}
!15 = !{!"any pointer", !9, i64 0}
!16 = !{!"_ZTSN3sim20TileGraphicTextCacheE", !17, i64 0, !17, i64 16, !7, i64 32, !20, i64 40, !29, i64 88}
!17 = !{!"_ZTSN3sim6MetersE", !18, i64 0}
!18 = !{!"_ZTSN3sim8DistanceE", !19, i64 8}
!19 = !{!"double", !9, i64 0}
!20 = !{!"_ZTSSt3mapIcSt4pairIddESt4lessIcESaIS0_IKcS1_EEE", !21, i64 0}
!21 = !{!"_ZTSSt8_Rb_treeIcSt4pairIKcS0_IddEESt10_Select1stIS3_ESt4lessIcESaIS3_EE", !22, i64 0}
!22 = !{!"_ZTSNSt8_Rb_treeIcSt4pairIKcS0_IddEESt10_Select1stIS3_ESt4lessIcESaIS3_EE13_Rb_tree_implIS7_Lb1EEE", !23, i64 0, !25, i64 8}
!23 = !{!"_ZTSSt20_Rb_tree_key_compareISt4lessIcEE", !24, i64 0}
!24 = !{!"_ZTSSt4lessIcE"}
!25 = !{!"_ZTSSt15_Rb_tree_header", !26, i64 0, !28, i64 32}
!26 = !{!"_ZTSSt18_Rb_tree_node_base", !27, i64 0, !15, i64 8, !15, i64 16, !15, i64 24}
!27 = !{!"_ZTSSt14_Rb_tree_color", !9, i64 0}
!28 = !{!"long", !9, i64 0}
!29 = !{!"_ZTSSt3mapISt4pairIS0_IiiES1_ES0_IN3sim9CartesianES4_ESt4lessIS2_ESaIS0_IKS2_S5_EEE", !30, i64 0}
!30 = !{!"_ZTSSt8_Rb_treeISt4pairIS0_IiiES1_ES0_IKS2_S0_IN3sim9CartesianES5_EESt10_Select1stIS7_ESt4lessIS2_ESaIS7_EE", !31, i64 0}
!31 = !{!"_ZTSNSt8_Rb_treeISt4pairIS0_IiiES1_ES0_IKS2_S0_IN3sim9CartesianES5_EESt10_Select1stIS7_ESt4lessIS2_ESaIS7_EE13_Rb_tree_implISB_Lb1EEE", !32, i64 0, !25, i64 8}
!32 = !{!"_ZTSSt20_Rb_tree_key_compareISt4lessISt4pairIS1_IiiES2_EEE", !33, i64 0}
!33 = !{!"_ZTSSt4lessISt4pairIS0_IiiES1_EE"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass