; LLVM IR from ritikbanger/Hacktoberfest2022-DSA :: 10. Linked List/cpp/Linked List Complete.ll (Z13deleteNodeDllRP7nodeDlli)

; 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.nodeDll = type { i32, 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: 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
declare dso_local void @_Z15deleteAtHeadDllRP7nodeDll(ptr noundef nonnull align 8 dereferenceable(8)) #2

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

9:                                                ; preds = %2
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_Z15deleteAtHeadDllRP7nodeDll(ptr noundef nonnull align 8 dereferenceable(8) %10)
  br label %54

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 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %23, %11
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %21

17:                                               ; preds = %14
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = icmp ne i32 %18, %19
  br label %21

21:                                               ; preds = %17, %14
  %22 = phi i1 [ false, %14 ], [ %20, %17 ]
  br i1 %22, label %23, label %29

23:                                               ; preds = %21
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %class.nodeDll, ptr %24, i32 0, i32 2
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  store ptr %26, ptr %5, align 8, !tbaa !5
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %6, align 4, !tbaa !9
  br label %14, !llvm.loop !13

29:                                               ; preds = %21
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %class.nodeDll, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %class.nodeDll, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  %36 = getelementptr inbounds %class.nodeDll, ptr %35, i32 0, i32 2
  store ptr %32, ptr %36, align 8, !tbaa !11
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %class.nodeDll, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %49

41:                                               ; preds = %29
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %class.nodeDll, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %class.nodeDll, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !11
  %48 = getelementptr inbounds %class.nodeDll, ptr %47, i32 0, i32 1
  store ptr %44, ptr %48, align 8, !tbaa !15
  br label %49

49:                                               ; preds = %41, %29
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = icmp eq ptr %50, null
  br i1 %51, label %53, label %52

52:                                               ; preds = %49
  call void @_ZdlPvm(ptr noundef %50, i64 noundef 24) #4
  br label %53

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

54:                                               ; preds = %53, %9
  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 = { 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 16}
!12 = !{!"_ZTS7nodeDll", !10, i64 0, !6, i64 8, !6, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !6, 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"

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z13deleteNodeDllRP7nodeDlli(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = icmp eq i32 %1, 1
  br i1 %3, label %4, label %.preheader

.preheader:                                       ; preds = %2
  %.01316 = load ptr, ptr %0, align 8, !tbaa !5
  %.not19 = icmp eq ptr %.01316, null
  br i1 %.not19, label %._crit_edge, label %.lr.ph

4:                                                ; preds = %2
  tail call void @_Z15deleteAtHeadDllRP7nodeDll(ptr noundef nonnull align 8 dereferenceable(8) %0)
  br label %18

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.01318 = phi ptr [ %.013, %.lr.ph ], [ %.01316, %.preheader ]
  %.017 = phi i32 [ %6, %.lr.ph ], [ 1, %.preheader ]
  %5 = getelementptr inbounds i8, ptr %.01318, i64 16
  %6 = add nuw nsw i32 %.017, 1
  %.013 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = icmp ne ptr %.013, null
  %8 = icmp ne i32 %6, %1
  %9 = select i1 %7, i1 %8, i1 false
  br i1 %9, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.013.lcssa = phi ptr [ null, %.preheader ], [ %.013, %.lr.ph ]
  %10 = getelementptr inbounds i8, ptr %.013.lcssa, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %.013.lcssa, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  store ptr %11, ptr %14, align 8, !tbaa !11
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %17, label %15

15:                                               ; preds = %._crit_edge
  %16 = getelementptr inbounds i8, ptr %11, i64 8
  store ptr %13, ptr %16, align 8, !tbaa !14
  br label %17

17:                                               ; preds = %._crit_edge, %15
  tail call void @_ZdlPvm(ptr noundef nonnull %.013.lcssa, i64 noundef 24) #2
  br label %18

18:                                               ; preds = %17, %4
  ret void
}

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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 16}
!12 = !{!"_ZTS7nodeDll", !13, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 8}


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