; LLVM IR from thepowersgang/mrustc :: src/hir_conv/constant_evaluation.ll (ZN3MIR4eval8RelocPtrD2Ev)

; 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.MIR::eval::AllocationPtr" = type { %"class.MIR::eval::RefCountPtr" }
%"class.MIR::eval::RefCountPtr" = type { ptr }
%"class.MIR::eval::ConstantPtr" = type { %"class.MIR::eval::RefCountPtr.0" }
%"class.MIR::eval::RefCountPtr.0" = type { ptr }
%"class.MIR::eval::StaticRefPtr" = type { %"class.MIR::eval::RefCountPtr.25" }
%"class.MIR::eval::RefCountPtr.25" = type { ptr }
%"class.MIR::eval::RelocPtr" = type { i64 }

; 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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3MIR4eval11RefCountPtrINS0_10AllocationEED2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN3MIR4eval11ConstantPtrC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3MIR4eval11RefCountPtrINS0_8ConstantEED2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN3MIR4eval13AllocationPtrC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN3MIR4eval12StaticRefPtrC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3MIR4eval11RefCountPtrINS0_9StaticRefEED2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3MIR4eval8RelocPtrD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %0) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca %"class.MIR::eval::AllocationPtr", align 8
  %4 = alloca %"class.MIR::eval::ConstantPtr", align 8
  %5 = alloca %"class.MIR::eval::StaticRefPtr", align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  %7 = getelementptr inbounds %"class.MIR::eval::RelocPtr", ptr %6, i32 0, i32 0
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = and i64 %8, 3
  switch i64 %9, label %26 [
    i64 0, label %10
    i64 1, label %15
    i64 2, label %20
    i64 3, label %25
  ]

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  invoke void @_ZN3MIR4eval13AllocationPtrC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %3)
          to label %11 unwind label %27

11:                                               ; preds = %10
  %12 = invoke noundef ptr @_ZNK3MIR4eval8RelocPtr13as_allocationEv(ptr noundef nonnull align 8 dereferenceable(8) %6)
          to label %13 unwind label %27

13:                                               ; preds = %11
  %14 = getelementptr inbounds %"class.MIR::eval::RefCountPtr", ptr %3, i32 0, i32 0
  store ptr %12, ptr %14, align 8, !tbaa !12
  call void @_ZN3MIR4eval11RefCountPtrINS0_10AllocationEED2Ev(ptr noundef nonnull align 8 dereferenceable(8) %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %26

15:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  invoke void @_ZN3MIR4eval11ConstantPtrC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %4)
          to label %16 unwind label %27

16:                                               ; preds = %15
  %17 = invoke noundef ptr @_ZNK3MIR4eval8RelocPtr11as_constantEv(ptr noundef nonnull align 8 dereferenceable(8) %6)
          to label %18 unwind label %27

18:                                               ; preds = %16
  %19 = getelementptr inbounds %"class.MIR::eval::RefCountPtr.0", ptr %4, i32 0, i32 0
  store ptr %17, ptr %19, align 8, !tbaa !14
  call void @_ZN3MIR4eval11RefCountPtrINS0_8ConstantEED2Ev(ptr noundef nonnull align 8 dereferenceable(8) %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %26

20:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  invoke void @_ZN3MIR4eval12StaticRefPtrC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %5)
          to label %21 unwind label %27

21:                                               ; preds = %20
  %22 = invoke noundef ptr @_ZNK3MIR4eval8RelocPtr12as_staticrefEv(ptr noundef nonnull align 8 dereferenceable(8) %6)
          to label %23 unwind label %27

23:                                               ; preds = %21
  %24 = getelementptr inbounds %"class.MIR::eval::RefCountPtr.25", ptr %5, i32 0, i32 0
  store ptr %22, ptr %24, align 8, !tbaa !16
  call void @_ZN3MIR4eval11RefCountPtrINS0_9StaticRefEED2Ev(ptr noundef nonnull align 8 dereferenceable(8) %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %26

25:                                               ; preds = %1
  br label %26

26:                                               ; preds = %25, %23, %18, %13, %1
  ret void

27:                                               ; preds = %21, %20, %16, %15, %11, %10
  %28 = landingpad { ptr, i32 }
          catch ptr null
  %29 = extractvalue { ptr, i32 } %28, 0
  call void @__clang_call_terminate(ptr %29) #5
  unreachable
}

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK3MIR4eval8RelocPtr13as_allocationEv(ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK3MIR4eval8RelocPtr11as_constantEv(ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK3MIR4eval8RelocPtr12as_staticrefEv(ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint 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 = { noinline noreturn nounwind uwtable "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 = { nounwind }
attributes #5 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTSN3MIR4eval8RelocPtrE", !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"_ZTSN3MIR4eval11RefCountPtrINS0_10AllocationEEE", !6, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"_ZTSN3MIR4eval11RefCountPtrINS0_8ConstantEEE", !6, i64 0}
!16 = !{!17, !6, i64 0}
!17 = !{!"_ZTSN3MIR4eval11RefCountPtrINS0_9StaticRefEEE", !6, i64 0}


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

%"class.MIR::eval::AllocationPtr" = type { %"class.MIR::eval::RefCountPtr" }
%"class.MIR::eval::RefCountPtr" = type { ptr }
%"class.MIR::eval::ConstantPtr" = type { %"class.MIR::eval::RefCountPtr.0" }
%"class.MIR::eval::RefCountPtr.0" = type { ptr }
%"class.MIR::eval::StaticRefPtr" = type { %"class.MIR::eval::RefCountPtr.25" }
%"class.MIR::eval::RefCountPtr.25" = type { ptr }

; 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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3MIR4eval11RefCountPtrINS0_10AllocationEED2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN3MIR4eval11ConstantPtrC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3MIR4eval11RefCountPtrINS0_8ConstantEED2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN3MIR4eval13AllocationPtrC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN3MIR4eval12StaticRefPtrC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3MIR4eval11RefCountPtrINS0_9StaticRefEED2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3MIR4eval8RelocPtrD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %0) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca %"class.MIR::eval::AllocationPtr", align 8
  %3 = alloca %"class.MIR::eval::ConstantPtr", align 8
  %4 = alloca %"class.MIR::eval::StaticRefPtr", align 8
  %5 = load i64, ptr %0, align 8, !tbaa !5
  %6 = and i64 %5, 3
  switch i64 %6, label %default.unreachable1 [
    i64 0, label %7
    i64 1, label %10
    i64 2, label %13
    i64 3, label %16
  ]

7:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  invoke void @_ZN3MIR4eval13AllocationPtrC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %2)
          to label %8 unwind label %17

8:                                                ; preds = %7
  %9 = call noundef ptr @_ZNK3MIR4eval8RelocPtr13as_allocationEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  store ptr %9, ptr %2, align 8, !tbaa !10
  call void @_ZN3MIR4eval11RefCountPtrINS0_10AllocationEED2Ev(ptr noundef nonnull align 8 dereferenceable(8) %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  br label %16

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  invoke void @_ZN3MIR4eval11ConstantPtrC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %3)
          to label %11 unwind label %17

11:                                               ; preds = %10
  %12 = call noundef ptr @_ZNK3MIR4eval8RelocPtr11as_constantEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  store ptr %12, ptr %3, align 8, !tbaa !13
  call void @_ZN3MIR4eval11RefCountPtrINS0_8ConstantEED2Ev(ptr noundef nonnull align 8 dereferenceable(8) %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  br label %16

13:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  invoke void @_ZN3MIR4eval12StaticRefPtrC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %4)
          to label %14 unwind label %17

14:                                               ; preds = %13
  %15 = call noundef ptr @_ZNK3MIR4eval8RelocPtr12as_staticrefEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  store ptr %15, ptr %4, align 8, !tbaa !15
  call void @_ZN3MIR4eval11RefCountPtrINS0_9StaticRefEED2Ev(ptr noundef nonnull align 8 dereferenceable(8) %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  br label %16

default.unreachable1:                             ; preds = %1
  unreachable

16:                                               ; preds = %1, %14, %11, %8
  ret void

17:                                               ; preds = %13, %10, %7
  %18 = landingpad { ptr, i32 }
          catch ptr null
  %19 = extractvalue { ptr, i32 } %18, 0
  call void @__clang_call_terminate(ptr %19) #5
  unreachable
}

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK3MIR4eval8RelocPtr13as_allocationEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK3MIR4eval8RelocPtr11as_constantEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK3MIR4eval8RelocPtr12as_staticrefEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint 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 = { noinline noreturn nounwind uwtable "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 = { nounwind }
attributes #5 = { 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, !7, i64 0}
!6 = !{!"_ZTSN3MIR4eval8RelocPtrE", !7, i64 0}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"_ZTSN3MIR4eval11RefCountPtrINS0_10AllocationEEE", !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_ZTSN3MIR4eval11RefCountPtrINS0_8ConstantEEE", !12, i64 0}
!15 = !{!16, !12, i64 0}
!16 = !{!"_ZTSN3MIR4eval11RefCountPtrINS0_9StaticRefEEE", !12, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SCCPPass,SROAPass,SimplifyCFGPass