; LLVM IR from codemistic/Data-Structures-and-Algorithms :: CPP/LINKED LIST/CIRCULAR LINKED LIST/circularlinked2.ll (Z10deletenodeRP4nodei)

; 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.node = type { i32, ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z10deletenodeRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  br label %55

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %13, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %class.node, ptr %14, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  store ptr %16, ptr %6, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %23, %11
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %class.node, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !13
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = icmp ne i32 %20, %21
  br i1 %22, label %23, label %28

23:                                               ; preds = %17
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %24, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %class.node, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  store ptr %27, ptr %6, align 8, !tbaa !5
  br label %17, !llvm.loop !14

28:                                               ; preds = %17
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %class.node, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %class.node, ptr %32, i32 0, i32 1
  store ptr %31, ptr %33, align 8, !tbaa !11
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = icmp eq ptr %34, %35
  br i1 %36, label %37, label %40

37:                                               ; preds = %28
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %38, ptr %39, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %37, %28
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = icmp eq ptr %42, %43
  br i1 %44, label %45, label %48

45:                                               ; preds = %40
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %46, ptr %47, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %45, %40
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %class.node, ptr %49, i32 0, i32 1
  store ptr null, ptr %50, align 8, !tbaa !11
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = icmp eq ptr %51, null
  br i1 %52, label %54, label %53

53:                                               ; preds = %48
  call void @_ZN4nodeD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %51) #3
  call void @_ZdlPvm(ptr noundef %51, i64 noundef 16) #4
  br label %54

54:                                               ; preds = %53, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %55

55:                                               ; preds = %54, %10
  ret void
}

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

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

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

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

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


; 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 nounwind uwtable
define dso_local void @_Z10deletenodeRP4nodei(ptr nocapture noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %16, label %.preheader

.preheader:                                       ; preds = %2, %.preheader
  %.018 = phi ptr [ %.0, %.preheader ], [ %3, %2 ]
  %.0.in = getelementptr inbounds i8, ptr %.018, i64 8
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !9
  %5 = load i32, ptr %.0, align 8, !tbaa !12
  %.not = icmp eq i32 %5, %1
  br i1 %.not, label %6, label %.preheader, !llvm.loop !13

6:                                                ; preds = %.preheader
  %.0.in.le = getelementptr inbounds i8, ptr %.018, i64 8
  %7 = getelementptr inbounds i8, ptr %.0, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %8, ptr %.0.in.le, align 8, !tbaa !9
  %9 = icmp eq ptr %.0, %.018
  br i1 %9, label %10, label %._crit_edge

._crit_edge:                                      ; preds = %6
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  br label %11

10:                                               ; preds = %6
  store ptr %.018, ptr %0, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %._crit_edge, %10
  %12 = phi ptr [ %.pre, %._crit_edge ], [ %.018, %10 ]
  %13 = icmp eq ptr %12, %.0
  br i1 %13, label %14, label %15

14:                                               ; preds = %11
  store ptr %.018, ptr %0, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %14, %11
  store ptr null, ptr %7, align 8, !tbaa !9
  tail call void @_ZN4nodeD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %.0) #2
  tail call void @_ZdlPvm(ptr noundef nonnull %.0, i64 noundef 16) #3
  br label %16

16:                                               ; preds = %2, %15
  ret void
}

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

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

attributes #0 = { 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 #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 = { nounwind }
attributes #3 = { 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, !6, i64 8}
!10 = !{!"_ZTS4node", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass