; LLVM IR from Dev-XYS/Algorithms :: Singly-Linked-List(Pointer).ll (Z3deli)

; 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, i32, ptr }

@head = external dso_local global ptr, align 8

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

; 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 noundef zeroext i1 @_Z3deli(i32 noundef %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %8 = load ptr, ptr @head, align 8, !tbaa !9
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  br label %57

11:                                               ; preds = %1
  %12 = load ptr, ptr @head, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.node, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp eq i32 %14, %15
  br i1 %16, label %17, label %26

17:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %18 = load ptr, ptr @head, align 8, !tbaa !9
  store ptr %18, ptr %4, align 8, !tbaa !9
  %19 = load ptr, ptr @head, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.node, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  store ptr %21, ptr @head, align 8, !tbaa !9
  %22 = load ptr, ptr %4, align 8, !tbaa !9
  %23 = icmp eq ptr %22, null
  br i1 %23, label %25, label %24

24:                                               ; preds = %17
  call void @_ZdlPvm(ptr noundef %22, i64 noundef 16) #4
  br label %25

25:                                               ; preds = %24, %17
  store i1 true, ptr %2, align 1
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %57

26:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %27 = load ptr, ptr @head, align 8, !tbaa !9
  store ptr %27, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %28 = load ptr, ptr @head, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.node, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  store ptr %30, ptr %6, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %50, %26
  %32 = load ptr, ptr %6, align 8, !tbaa !9
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %55

34:                                               ; preds = %31
  %35 = load ptr, ptr %6, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.node, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !11
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = icmp eq i32 %37, %38
  br i1 %39, label %40, label %50

40:                                               ; preds = %34
  %41 = load ptr, ptr %6, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.node, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !13
  %44 = load ptr, ptr %5, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.node, ptr %44, i32 0, i32 2
  store ptr %43, ptr %45, align 8, !tbaa !13
  %46 = load ptr, ptr %6, align 8, !tbaa !9
  %47 = icmp eq ptr %46, null
  br i1 %47, label %49, label %48

48:                                               ; preds = %40
  call void @_ZdlPvm(ptr noundef %46, i64 noundef 16) #4
  br label %49

49:                                               ; preds = %48, %40
  store i1 true, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %56

50:                                               ; preds = %34
  %51 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %51, ptr %5, align 8, !tbaa !9
  %52 = load ptr, ptr %6, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.node, ptr %52, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !13
  store ptr %54, ptr %6, align 8, !tbaa !9
  br label %31, !llvm.loop !14

55:                                               ; preds = %31
  store i1 false, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %56

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

57:                                               ; preds = %56, %25, %10
  %58 = load i1, ptr %2, align 1
  ret i1 %58
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4node", !6, i64 0, !6, i64 4, !10, i64 8}
!13 = !{!12, !10, i64 8}
!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"

@head = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z3deli(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @head, align 8, !tbaa !5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %.loopexit, label %4

4:                                                ; preds = %1
  %5 = load i32, ptr %2, align 8, !tbaa !9
  %6 = icmp eq i32 %5, %0
  br i1 %6, label %.loopexit.sink.split, label %.preheader

.preheader:                                       ; preds = %4, %7
  %.010 = phi ptr [ %.0, %7 ], [ %2, %4 ]
  %.0.in = getelementptr inbounds i8, ptr %.010, i64 8
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !12
  %.not.not = icmp eq ptr %.0, null
  br i1 %.not.not, label %.loopexit, label %7

7:                                                ; preds = %.preheader
  %8 = load i32, ptr %.0, align 8, !tbaa !9
  %9 = icmp eq i32 %8, %0
  br i1 %9, label %10, label %.preheader, !llvm.loop !13

10:                                               ; preds = %7
  %.0.in.le = getelementptr inbounds i8, ptr %.010, i64 8
  br label %.loopexit.sink.split

.loopexit.sink.split:                             ; preds = %4, %10
  %.0.lcssa18.sink21 = phi ptr [ %.0, %10 ], [ %2, %4 ]
  %.0.in.le.sink = phi ptr [ %.0.in.le, %10 ], [ @head, %4 ]
  %11 = getelementptr inbounds i8, ptr %.0.lcssa18.sink21, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  store ptr %12, ptr %.0.in.le.sink, align 8, !tbaa !5
  tail call void @_ZdlPvm(ptr noundef nonnull %.0.lcssa18.sink21, i64 noundef 16) #2
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %.loopexit.sink.split, %1
  %.1 = phi i1 [ false, %1 ], [ true, %.loopexit.sink.split ], [ false, %.preheader ]
  ret i1 %.1
}

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


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