; LLVM IR from bhrigukansra/algorithms-in-C-Cplusplus-Java-Python-JavaScript :: Data Structures/Linked List/C++/SLList.ll (ZN6SLList11delete_nodeEi)

; 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.SLList = type { ptr, ptr }
%class.SLLNode = type { i32, ptr }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6SLList11delete_nodeEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  %9 = getelementptr inbounds %class.SLList, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %103

12:                                               ; preds = %2
  %13 = getelementptr inbounds %class.SLList, ptr %8, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = getelementptr inbounds %class.SLList, ptr %8, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = icmp eq ptr %14, %16
  br i1 %17, label %18, label %33

18:                                               ; preds = %12
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = getelementptr inbounds %class.SLList, ptr %8, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = getelementptr inbounds %class.SLLNode, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !14
  %24 = icmp eq i32 %19, %23
  br i1 %24, label %25, label %33

25:                                               ; preds = %18
  %26 = getelementptr inbounds %class.SLList, ptr %8, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = icmp eq ptr %27, null
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  call void @_ZdlPvm(ptr noundef %27, i64 noundef 16) #3
  br label %30

30:                                               ; preds = %29, %25
  %31 = getelementptr inbounds %class.SLList, ptr %8, i32 0, i32 1
  store ptr null, ptr %31, align 8, !tbaa !13
  %32 = getelementptr inbounds %class.SLList, ptr %8, i32 0, i32 0
  store ptr null, ptr %32, align 8, !tbaa !11
  br label %102

33:                                               ; preds = %18, %12
  %34 = load i32, ptr %4, align 4, !tbaa !9
  %35 = getelementptr inbounds %class.SLList, ptr %8, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  %37 = getelementptr inbounds %class.SLLNode, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !14
  %39 = icmp eq i32 %34, %38
  br i1 %39, label %40, label %52

40:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %41 = getelementptr inbounds %class.SLList, ptr %8, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  store ptr %42, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %class.SLList, ptr %8, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !11
  %45 = getelementptr inbounds %class.SLLNode, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !16
  %47 = getelementptr inbounds %class.SLList, ptr %8, i32 0, i32 0
  store ptr %46, ptr %47, align 8, !tbaa !11
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = icmp eq ptr %48, null
  br i1 %49, label %51, label %50

50:                                               ; preds = %40
  call void @_ZdlPvm(ptr noundef %48, i64 noundef 16) #3
  br label %51

51:                                               ; preds = %50, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %101

52:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %53 = getelementptr inbounds %class.SLList, ptr %8, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !11
  store ptr %54, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %class.SLList, ptr %8, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !11
  %57 = getelementptr inbounds %class.SLLNode, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !16
  store ptr %58, ptr %7, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %72, %52
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %69

62:                                               ; preds = %59
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %class.SLLNode, ptr %63, i32 0, i32 0
  %65 = load i32, ptr %64, align 8, !tbaa !14
  %66 = load i32, ptr %4, align 4, !tbaa !9
  %67 = icmp eq i32 %65, %66
  %68 = xor i1 %67, true
  br label %69

69:                                               ; preds = %62, %59
  %70 = phi i1 [ false, %59 ], [ %68, %62 ]
  br i1 %70, label %71, label %79

71:                                               ; preds = %69
  br label %72

72:                                               ; preds = %71
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = getelementptr inbounds %class.SLLNode, ptr %73, i32 0, i32 1
  %75 = load ptr, ptr %74, align 8, !tbaa !16
  store ptr %75, ptr %6, align 8, !tbaa !5
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = getelementptr inbounds %class.SLLNode, ptr %76, i32 0, i32 1
  %78 = load ptr, ptr %77, align 8, !tbaa !16
  store ptr %78, ptr %7, align 8, !tbaa !5
  br label %59, !llvm.loop !17

79:                                               ; preds = %69
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = icmp ne ptr %80, null
  br i1 %81, label %82, label %100

82:                                               ; preds = %79
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = getelementptr inbounds %class.SLLNode, ptr %83, i32 0, i32 1
  %85 = load ptr, ptr %84, align 8, !tbaa !16
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds %class.SLLNode, ptr %86, i32 0, i32 1
  store ptr %85, ptr %87, align 8, !tbaa !16
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = getelementptr inbounds %class.SLList, ptr %8, i32 0, i32 1
  %90 = load ptr, ptr %89, align 8, !tbaa !13
  %91 = icmp eq ptr %88, %90
  br i1 %91, label %92, label %95

92:                                               ; preds = %82
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = getelementptr inbounds %class.SLList, ptr %8, i32 0, i32 1
  store ptr %93, ptr %94, align 8, !tbaa !13
  br label %95

95:                                               ; preds = %92, %82
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %97 = icmp eq ptr %96, null
  br i1 %97, label %99, label %98

98:                                               ; preds = %95
  call void @_ZdlPvm(ptr noundef %96, i64 noundef 16) #3
  br label %99

99:                                               ; preds = %98, %95
  br label %100

100:                                              ; preds = %99, %79
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %101

101:                                              ; preds = %100, %51
  br label %102

102:                                              ; preds = %101, %30
  br label %103

103:                                              ; preds = %102, %2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #3 = { builtin nounwind }
attributes #4 = { 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 0}
!12 = !{!"_ZTS6SLList", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = !{!15, !10, i64 0}
!15 = !{!"_ZTS7SLLNode", !10, i64 0, !6, i64 8}
!16 = !{!15, !6, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"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: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6SLList11delete_nodeEi(ptr nocapture noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %.critedge19, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !10
  %7 = icmp eq ptr %3, %6
  %.pre = load i32, ptr %3, align 8, !tbaa !11
  %8 = icmp eq i32 %.pre, %1
  %or.cond = select i1 %7, i1 %8, i1 false
  br i1 %or.cond, label %9, label %10

9:                                                ; preds = %4
  tail call void @_ZdlPvm(ptr noundef nonnull %3, i64 noundef 16) #3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %0, i8 0, i64 16, i1 false)
  br label %.critedge19

10:                                               ; preds = %4
  %11 = icmp eq i32 %.pre, %1
  %12 = getelementptr inbounds i8, ptr %3, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  br i1 %11, label %14, label %.preheader

.preheader:                                       ; preds = %10
  %.not1724 = icmp eq ptr %13, null
  br i1 %.not1724, label %.critedge19, label %.lr.ph

14:                                               ; preds = %10
  store ptr %13, ptr %0, align 8, !tbaa !5
  tail call void @_ZdlPvm(ptr noundef nonnull %3, i64 noundef 16) #3
  br label %.critedge19

.lr.ph:                                           ; preds = %.preheader, %16
  %.026 = phi ptr [ %.0, %16 ], [ %13, %.preheader ]
  %.01425 = phi ptr [ %18, %16 ], [ %3, %.preheader ]
  %15 = load i32, ptr %.026, align 8, !tbaa !11
  %.not18 = icmp eq i32 %15, %1
  br i1 %.not18, label %.critedge, label %16

16:                                               ; preds = %.lr.ph
  %17 = getelementptr inbounds i8, ptr %.01425, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %.0.in = getelementptr inbounds i8, ptr %.026, i64 8
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !14
  %.not17 = icmp eq ptr %.0, null
  br i1 %.not17, label %.critedge19, label %.lr.ph, !llvm.loop !15

.critedge:                                        ; preds = %.lr.ph
  %19 = getelementptr inbounds i8, ptr %.026, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %.01425, i64 8
  store ptr %20, ptr %21, align 8, !tbaa !14
  %22 = icmp eq ptr %.026, %6
  br i1 %22, label %23, label %24

23:                                               ; preds = %.critedge
  store ptr %.01425, ptr %5, align 8, !tbaa !10
  br label %24

24:                                               ; preds = %.critedge, %23
  tail call void @_ZdlPvm(ptr noundef nonnull %.026, i64 noundef 16) #3
  br label %.critedge19

.critedge19:                                      ; preds = %16, %.preheader, %24, %9, %14, %2
  ret void
}

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

attributes #0 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 0}
!6 = !{!"_ZTS6SLList", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS7SLLNode", !13, i64 0, !7, i64 8}
!13 = !{!"int", !8, i64 0}
!14 = !{!12, !7, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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