; LLVM IR from Deborah-Digges/mark-sweep-simulation :: 03-marksweep-Pointer-Reversal/vm.ll (ZN2VM4markEP6Object)

; 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.Object = type { i32, i32, ptr, %union.anon, i32 }
%union.anon = type { %struct.anon }
%struct.anon = type { 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: mustprogress nounwind uwtable
define dso_local void @_ZN2VM4markEP6Object(ptr noundef nonnull align 8 dereferenceable(180) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %10, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store ptr null, ptr %8, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %93, %2
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = icmp ne i32 %12, 0
  %14 = xor i1 %13, true
  br i1 %14, label %15, label %94

15:                                               ; preds = %11
  br label %16

16:                                               ; preds = %45, %15
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %25

19:                                               ; preds = %16
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Object, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = icmp ne i32 %22, 0
  %24 = xor i1 %23, true
  br label %25

25:                                               ; preds = %19, %16
  %26 = phi i1 [ false, %16 ], [ %24, %19 ]
  br i1 %26, label %27, label %46

27:                                               ; preds = %25
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Object, ptr %28, i32 0, i32 1
  store i32 1, ptr %29, align 4, !tbaa !11
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.Object, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !14
  %33 = icmp eq i32 %32, 1
  br i1 %33, label %34, label %45

34:                                               ; preds = %27
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.Object, ptr %35, i32 0, i32 3
  %37 = getelementptr inbounds %struct.anon, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  store ptr %38, ptr %8, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.Object, ptr %40, i32 0, i32 3
  %42 = getelementptr inbounds %struct.anon, ptr %41, i32 0, i32 0
  store ptr %39, ptr %42, align 8, !tbaa !15
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %43, ptr %7, align 8, !tbaa !5
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %44, ptr %6, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %34, %27
  br label %16, !llvm.loop !16

46:                                               ; preds = %25
  br label %47

47:                                               ; preds = %57, %46
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %55

50:                                               ; preds = %47
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.Object, ptr %51, i32 0, i32 4
  %53 = load i32, ptr %52, align 8, !tbaa !18
  %54 = icmp eq i32 %53, 1
  br label %55

55:                                               ; preds = %50, %47
  %56 = phi i1 [ false, %47 ], [ %54, %50 ]
  br i1 %56, label %57, label %70

57:                                               ; preds = %55
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.Object, ptr %58, i32 0, i32 4
  store i32 0, ptr %59, align 8, !tbaa !18
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Object, ptr %60, i32 0, i32 3
  %62 = getelementptr inbounds %struct.anon, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !15
  store ptr %63, ptr %8, align 8, !tbaa !5
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.Object, ptr %65, i32 0, i32 3
  %67 = getelementptr inbounds %struct.anon, ptr %66, i32 0, i32 1
  store ptr %64, ptr %67, align 8, !tbaa !15
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %68, ptr %6, align 8, !tbaa !5
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %69, ptr %7, align 8, !tbaa !5
  br label %47, !llvm.loop !19

70:                                               ; preds = %55
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = icmp eq ptr %71, null
  br i1 %72, label %73, label %74

73:                                               ; preds = %70
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %93

74:                                               ; preds = %70
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.Object, ptr %75, i32 0, i32 4
  store i32 1, ptr %76, align 8, !tbaa !18
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.Object, ptr %77, i32 0, i32 3
  %79 = getelementptr inbounds %struct.anon, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !15
  store ptr %80, ptr %8, align 8, !tbaa !5
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.Object, ptr %82, i32 0, i32 3
  %84 = getelementptr inbounds %struct.anon, ptr %83, i32 0, i32 0
  store ptr %81, ptr %84, align 8, !tbaa !15
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.Object, ptr %85, i32 0, i32 3
  %87 = getelementptr inbounds %struct.anon, ptr %86, i32 0, i32 1
  %88 = load ptr, ptr %87, align 8, !tbaa !15
  store ptr %88, ptr %6, align 8, !tbaa !5
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.Object, ptr %90, i32 0, i32 3
  %92 = getelementptr inbounds %struct.anon, ptr %91, i32 0, i32 1
  store ptr %89, ptr %92, align 8, !tbaa !15
  br label %93

93:                                               ; preds = %74, %73
  br label %11, !llvm.loop !20

94:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

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 = { 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 = !{!12, !10, i64 4}
!12 = !{!"_ZTS6Object", !13, i64 0, !10, i64 4, !6, i64 8, !7, i64 16, !10, i64 32}
!13 = !{!"_ZTS10ObjectType", !7, i64 0}
!14 = !{!12, !13, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!12, !10, i64 32}
!19 = distinct !{!19, !17}
!20 = distinct !{!20, !17}


; 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 nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN2VM4markEP6Object(ptr nocapture noundef nonnull readnone align 8 dereferenceable(180) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  br label %.preheader

.preheader:                                       ; preds = %.loopexit, %2
  %.056 = phi ptr [ null, %2 ], [ %.350, %.loopexit ]
  %.02955 = phi ptr [ %1, %2 ], [ %21, %.loopexit ]
  %.not3541 = icmp eq ptr %.02955, null
  br i1 %.not3541, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %11
  %.143 = phi ptr [ %.2, %11 ], [ %.056, %.preheader ]
  %.13042 = phi ptr [ %.231, %11 ], [ %.02955, %.preheader ]
  %3 = getelementptr inbounds i8, ptr %.13042, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %.not36 = icmp eq i32 %4, 0
  br i1 %.not36, label %5, label %.critedge

5:                                                ; preds = %.lr.ph
  store i32 1, ptr %3, align 4, !tbaa !5
  %6 = load i32, ptr %.13042, align 8, !tbaa !12
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %8, label %11

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %.13042, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  store ptr %.143, ptr %9, align 8, !tbaa !13
  br label %11

11:                                               ; preds = %8, %5
  %.231 = phi ptr [ %10, %8 ], [ %.13042, %5 ]
  %.2 = phi ptr [ %.13042, %8 ], [ %.143, %5 ]
  %.not35 = icmp eq ptr %.231, null
  br i1 %.not35, label %.critedge, label %.lr.ph, !llvm.loop !14

.critedge:                                        ; preds = %.lr.ph, %11, %.preheader
  %.130.lcssa = phi ptr [ null, %.preheader ], [ null, %11 ], [ %.13042, %.lr.ph ]
  %.1.lcssa = phi ptr [ %.056, %.preheader ], [ %.2, %11 ], [ %.143, %.lr.ph ]
  %cond48 = icmp eq ptr %.1.lcssa, null
  br i1 %cond48, label %.loopexit64, label %.lr.ph51

.lr.ph51:                                         ; preds = %.critedge, %15
  %.350 = phi ptr [ %17, %15 ], [ %.1.lcssa, %.critedge ]
  %.33249 = phi ptr [ %.350, %15 ], [ %.130.lcssa, %.critedge ]
  %12 = getelementptr inbounds i8, ptr %.350, i64 32
  %13 = load i32, ptr %12, align 8, !tbaa !16
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %15, label %.loopexit

15:                                               ; preds = %.lr.ph51
  store i32 0, ptr %12, align 8, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %.350, i64 24
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  store ptr %.33249, ptr %16, align 8, !tbaa !13
  %cond = icmp eq ptr %17, null
  br i1 %cond, label %.loopexit64, label %.lr.ph51, !llvm.loop !17

.loopexit:                                        ; preds = %.lr.ph51
  store i32 1, ptr %12, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %.350, i64 16
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  store ptr %.33249, ptr %18, align 8, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %.350, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  store ptr %19, ptr %20, align 8, !tbaa !13
  br label %.preheader, !llvm.loop !18

.loopexit64:                                      ; preds = %.critedge, %15
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !10, i64 4}
!6 = !{!"_ZTS6Object", !7, i64 0, !10, i64 4, !11, i64 8, !8, i64 16, !10, i64 32}
!7 = !{!"_ZTS10ObjectType", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!6, !10, i64 32}
!17 = distinct !{!17, !15}
!18 = distinct !{!18, !15}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass