; LLVM IR from amritansh22/Data-Structures-and-Algorithms-in-cpp :: double_circular_linkedlist.ll (Z3delPP4nodei)

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

@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1

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

declare i32 @printf(ptr 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 uwtable
define dso_local void @_Z3delPP4nodei(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %13

11:                                               ; preds = %2
  %12 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %88

13:                                               ; preds = %2
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %52

16:                                               ; preds = %13
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %18, ptr %5, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %27, %16
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.node, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = icmp ne ptr %22, %24
  br i1 %25, label %26, label %31

26:                                               ; preds = %19
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.node, ptr %28, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  store ptr %30, ptr %5, align 8, !tbaa !5
  br label %19, !llvm.loop !13

31:                                               ; preds = %19
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.node, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.node, ptr %36, i32 0, i32 1
  store ptr %35, ptr %37, align 8, !tbaa !11
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  store ptr %39, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.node, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !11
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %43, ptr %44, align 8, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.node, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !11
  %50 = getelementptr inbounds %struct.node, ptr %49, i32 0, i32 2
  store ptr %45, ptr %50, align 8, !tbaa !15
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %51) #4
  br label %87

52:                                               ; preds = %13
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  store ptr %54, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %68, %52
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = load i32, ptr %4, align 4, !tbaa !9
  %58 = icmp slt i32 %56, %57
  br i1 %58, label %59, label %66

59:                                               ; preds = %55
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.node, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !11
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = load ptr, ptr %63, align 8, !tbaa !5
  %65 = icmp ne ptr %62, %64
  br label %66

66:                                               ; preds = %59, %55
  %67 = phi i1 [ false, %55 ], [ %65, %59 ]
  br i1 %67, label %68, label %75

68:                                               ; preds = %66
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %69, ptr %6, align 8, !tbaa !5
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.node, ptr %70, i32 0, i32 1
  %72 = load ptr, ptr %71, align 8, !tbaa !11
  store ptr %72, ptr %5, align 8, !tbaa !5
  %73 = load i32, ptr %7, align 4, !tbaa !9
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %7, align 4, !tbaa !9
  br label %55, !llvm.loop !16

75:                                               ; preds = %66
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.node, ptr %76, i32 0, i32 1
  %78 = load ptr, ptr %77, align 8, !tbaa !11
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.node, ptr %79, i32 0, i32 1
  store ptr %78, ptr %80, align 8, !tbaa !11
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.node, ptr %82, i32 0, i32 1
  %84 = load ptr, ptr %83, align 8, !tbaa !11
  %85 = getelementptr inbounds %struct.node, ptr %84, i32 0, i32 2
  store ptr %81, ptr %85, align 8, !tbaa !15
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %86) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %87

87:                                               ; preds = %75, %31
  br label %88

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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


; 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"

@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3delPP4nodei(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %7

5:                                                ; preds = %2
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %32

7:                                                ; preds = %2
  %8 = icmp eq i32 %1, 0
  br i1 %8, label %.preheader, label %.preheader34

.preheader34:                                     ; preds = %7
  %9 = icmp sgt i32 %1, 1
  br i1 %9, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %.preheader34
  %10 = getelementptr inbounds i8, ptr %3, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %.not44 = icmp eq ptr %11, %3
  br i1 %.not44, label %.critedge, label %.lr.ph47

.preheader:                                       ; preds = %7, %.preheader
  %.027 = phi ptr [ %13, %.preheader ], [ %3, %7 ]
  %12 = getelementptr inbounds i8, ptr %.027, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %.not33 = icmp eq ptr %13, %3
  br i1 %.not33, label %14, label %.preheader, !llvm.loop !12

14:                                               ; preds = %.preheader
  %15 = getelementptr inbounds i8, ptr %.027, i64 8
  %16 = getelementptr inbounds i8, ptr %3, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  store ptr %17, ptr %15, align 8, !tbaa !9
  %18 = load ptr, ptr %0, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  store ptr %20, ptr %0, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  store ptr %.027, ptr %23, align 8, !tbaa !14
  tail call void @free(ptr noundef %18) #3
  br label %32

.lr.ph47:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %24 = phi ptr [ %27, %.lr.ph ], [ %11, %.lr.ph.preheader ]
  %.13546 = phi ptr [ %24, %.lr.ph ], [ %3, %.lr.ph.preheader ]
  %.03745 = phi i32 [ %25, %.lr.ph ], [ 1, %.lr.ph.preheader ]
  %25 = add nuw nsw i32 %.03745, 1
  %exitcond.not = icmp eq i32 %25, %1
  br i1 %exitcond.not, label %.critedge, label %.lr.ph, !llvm.loop !15

.lr.ph:                                           ; preds = %.lr.ph47
  %26 = getelementptr inbounds i8, ptr %24, i64 8
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %.not = icmp eq ptr %27, %3
  br i1 %.not, label %.critedge, label %.lr.ph47, !llvm.loop !15

.critedge:                                        ; preds = %.lr.ph47, %.lr.ph, %.lr.ph.preheader, %.preheader34
  %.1.lcssa = phi ptr [ %3, %.preheader34 ], [ %3, %.lr.ph.preheader ], [ %24, %.lr.ph ], [ %24, %.lr.ph47 ]
  %.026.lcssa = phi ptr [ undef, %.preheader34 ], [ undef, %.lr.ph.preheader ], [ %.13546, %.lr.ph ], [ %.13546, %.lr.ph47 ]
  %28 = getelementptr inbounds i8, ptr %.1.lcssa, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %.026.lcssa, i64 8
  store ptr %29, ptr %30, align 8, !tbaa !9
  %31 = getelementptr inbounds i8, ptr %29, i64 16
  store ptr %.026.lcssa, ptr %31, align 8, !tbaa !14
  tail call void @free(ptr noundef %.1.lcssa) #3
  br label %32

32:                                               ; preds = %14, %.critedge, %5
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

attributes #0 = { nofree 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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }

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


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