; LLVM IR from achilles288/robot-monitor-graphics :: src/base/internal/context_load.ll (ZN3rmg8internal12PendingStack3popEv)

; 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.rmg::internal::Pending" = type { ptr, ptr }
%"class.rmg::internal::PendingStack" = type <{ ptr, %"class.rmg::internal::Pending", i32, [4 x i8] }>
%"struct.rmg::internal::PendingStack::Node" = type { ptr, %"class.rmg::internal::Pending" }

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN3rmg8internal7PendingaSERKS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN3rmg8internal7PendingaSEOS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #4 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3rmg8internal12PendingStack3popEv(ptr noundef nonnull align 8 dereferenceable(28) %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca %"class.rmg::internal::Pending", align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  %6 = getelementptr inbounds %"class.rmg::internal::PendingStack", ptr %5, i32 0, i32 2
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  br label %41

10:                                               ; preds = %1
  %11 = getelementptr inbounds %"class.rmg::internal::PendingStack", ptr %5, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %34

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %15 = getelementptr inbounds %"class.rmg::internal::PendingStack", ptr %5, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = getelementptr inbounds %"struct.rmg::internal::PendingStack::Node", ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  store ptr %18, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %"class.rmg::internal::PendingStack", ptr %5, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = getelementptr inbounds %"struct.rmg::internal::PendingStack::Node", ptr %20, i32 0, i32 0
  store ptr null, ptr %21, align 8, !tbaa !14
  %22 = getelementptr inbounds %"class.rmg::internal::PendingStack", ptr %5, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = getelementptr inbounds %"struct.rmg::internal::PendingStack::Node", ptr %23, i32 0, i32 1
  %25 = getelementptr inbounds %"class.rmg::internal::PendingStack", ptr %5, i32 0, i32 1
  %26 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN3rmg8internal7PendingaSERKS1_(ptr noundef nonnull align 8 dereferenceable(16) %25, ptr noundef nonnull align 8 dereferenceable(16) %24)
  %27 = getelementptr inbounds %"class.rmg::internal::PendingStack", ptr %5, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = icmp eq ptr %28, null
  br i1 %29, label %31, label %30

30:                                               ; preds = %14
  call void @_ZN3rmg8internal12PendingStack4NodeD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %28) #5
  call void @_ZdlPvm(ptr noundef %28, i64 noundef 24) #6
  br label %31

31:                                               ; preds = %30, %14
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %"class.rmg::internal::PendingStack", ptr %5, i32 0, i32 0
  store ptr %32, ptr %33, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  br label %37

34:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #5
  call void @llvm.memset.p0.i64(ptr align 8 %4, i8 0, i64 16, i1 false)
  call void @_ZN3rmg8internal7PendingC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %4) #5
  %35 = getelementptr inbounds %"class.rmg::internal::PendingStack", ptr %5, i32 0, i32 1
  %36 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN3rmg8internal7PendingaSEOS1_(ptr noundef nonnull align 8 dereferenceable(16) %35, ptr noundef nonnull align 8 dereferenceable(16) %4) #5
  call void @_ZN3rmg8internal7PendingD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %4) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #5
  br label %37

37:                                               ; preds = %34, %31
  %38 = getelementptr inbounds %"class.rmg::internal::PendingStack", ptr %5, i32 0, i32 2
  %39 = load i32, ptr %38, align 8, !tbaa !9
  %40 = add i32 %39, -1
  store i32 %40, ptr %38, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %37, %9
  ret void
}

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

declare void @_ZN3rmg8internal7PendingD1Ev(ptr)

declare void @_ZN3rmg8internal12PendingStack4NodeD1Ev(ptr)

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { nobuiltin nounwind "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { builtin 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, !12, i64 24}
!10 = !{!"_ZTSN3rmg8internal12PendingStackE", !6, i64 0, !11, i64 8, !12, i64 24}
!11 = !{!"_ZTSN3rmg8internal7PendingE", !6, i64 0, !6, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"_ZTSN3rmg8internal12PendingStack4NodeE", !6, i64 0, !11, i64 8}


; 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.rmg::internal::Pending" = type { ptr, ptr }

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN3rmg8internal7PendingaSERKS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN3rmg8internal7PendingaSEOS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3rmg8internal12PendingStack3popEv(ptr noundef nonnull align 8 dereferenceable(28) %0) local_unnamed_addr #3 align 2 {
  %2 = alloca %"class.rmg::internal::Pending", align 8
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %22, label %6

6:                                                ; preds = %1
  %7 = load ptr, ptr %0, align 8, !tbaa !12
  %.not = icmp eq ptr %7, null
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  br i1 %.not, label %17, label %9

9:                                                ; preds = %6
  %10 = load ptr, ptr %7, align 8, !tbaa !13
  store ptr null, ptr %7, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %7, i64 8
  %12 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZN3rmg8internal7PendingaSERKS1_(ptr noundef nonnull align 8 dereferenceable(16) %8, ptr noundef nonnull align 8 dereferenceable(16) %11)
  %13 = load ptr, ptr %0, align 8, !tbaa !12
  %14 = icmp eq ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %9
  tail call void @_ZN3rmg8internal12PendingStack4NodeD1Ev(ptr noundef nonnull align 8 dereferenceable(24) %13) #5
  tail call void @_ZdlPvm(ptr noundef nonnull %13, i64 noundef 24) #6
  br label %16

16:                                               ; preds = %15, %9
  store ptr %10, ptr %0, align 8, !tbaa !12
  br label %19

17:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %2, i8 0, i64 16, i1 false)
  call void @_ZN3rmg8internal7PendingC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %2) #5
  %18 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN3rmg8internal7PendingaSEOS1_(ptr noundef nonnull align 8 dereferenceable(16) %8, ptr noundef nonnull align 8 dereferenceable(16) %2) #5
  call void @_ZN3rmg8internal7PendingD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %2) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #5
  br label %19

19:                                               ; preds = %17, %16
  %20 = load i32, ptr %3, align 8, !tbaa !5
  %21 = add i32 %20, -1
  store i32 %21, ptr %3, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %1, %19
  ret void
}

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

declare void @_ZN3rmg8internal7PendingD1Ev(ptr) local_unnamed_addr

declare void @_ZN3rmg8internal12PendingStack4NodeD1Ev(ptr) local_unnamed_addr

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { nobuiltin nounwind "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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { builtin 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, !11, i64 24}
!6 = !{!"_ZTSN3rmg8internal12PendingStackE", !7, i64 0, !10, i64 8, !11, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN3rmg8internal7PendingE", !7, i64 0, !7, i64 8}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"_ZTSN3rmg8internal12PendingStack4NodeE", !7, i64 0, !10, i64 8}


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