; LLVM IR from PetarV-/Algorithms :: Data Structures (Circular Doubly-Linked List)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN24CircularDoublyLinkedList7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(16)) #0 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN24CircularDoublyLinkedList14extractMinimumEv(ptr noundef nonnull align 8 dereferenceable(16) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  %9 = call noundef zeroext i1 @_ZN24CircularDoublyLinkedList7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(16) %8)
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  br label %74

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %12 = getelementptr inbounds %class.CircularDoublyLinkedList, ptr %8, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %13, ptr %4, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %class.Node, ptr %14, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = icmp eq ptr %16, %17
  br i1 %18, label %19, label %22

19:                                               ; preds = %11
  %20 = getelementptr inbounds %class.CircularDoublyLinkedList, ptr %8, i32 0, i32 0
  store ptr null, ptr %20, align 8, !tbaa !14
  %21 = getelementptr inbounds %class.CircularDoublyLinkedList, ptr %8, i32 0, i32 1
  store ptr null, ptr %21, align 8, !tbaa !9
  br label %72

22:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %class.Node, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !15
  store ptr %25, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %class.Node, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  store ptr %28, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %class.Node, ptr %30, i32 0, i32 2
  store ptr %29, ptr %31, align 8, !tbaa !11
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %class.Node, ptr %33, i32 0, i32 1
  store ptr %32, ptr %34, align 8, !tbaa !15
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %class.CircularDoublyLinkedList, ptr %8, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  %38 = icmp eq ptr %35, %37
  br i1 %38, label %39, label %42

39:                                               ; preds = %22
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %class.CircularDoublyLinkedList, ptr %8, i32 0, i32 0
  store ptr %40, ptr %41, align 8, !tbaa !14
  br label %42

42:                                               ; preds = %39, %22
  %43 = getelementptr inbounds %class.CircularDoublyLinkedList, ptr %8, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !14
  %45 = getelementptr inbounds %class.CircularDoublyLinkedList, ptr %8, i32 0, i32 1
  store ptr %44, ptr %45, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %46 = getelementptr inbounds %class.CircularDoublyLinkedList, ptr %8, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !14
  %48 = getelementptr inbounds %class.Node, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !11
  store ptr %49, ptr %7, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %67, %42
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %class.CircularDoublyLinkedList, ptr %8, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  %54 = icmp ne ptr %51, %53
  br i1 %54, label %55, label %71

55:                                               ; preds = %50
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %class.Node, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %57, align 8, !tbaa !16
  %59 = getelementptr inbounds %class.CircularDoublyLinkedList, ptr %8, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !9
  %61 = getelementptr inbounds %class.Node, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 8, !tbaa !16
  %63 = icmp slt i32 %58, %62
  br i1 %63, label %64, label %67

64:                                               ; preds = %55
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %class.CircularDoublyLinkedList, ptr %8, i32 0, i32 1
  store ptr %65, ptr %66, align 8, !tbaa !9
  br label %67

67:                                               ; preds = %64, %55
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %class.Node, ptr %68, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !11
  store ptr %70, ptr %7, align 8, !tbaa !5
  br label %50, !llvm.loop !17

71:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %72

72:                                               ; preds = %71, %19
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %73, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %74

74:                                               ; preds = %72, %10
  %75 = load ptr, ptr %2, align 8
  ret ptr %75
}

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 = { 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 = !{!"_ZTS24CircularDoublyLinkedList", !6, i64 0, !6, i64 8}
!11 = !{!12, !6, i64 16}
!12 = !{!"_ZTS4Node", !13, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!"int", !7, i64 0}
!14 = !{!10, !6, i64 0}
!15 = !{!12, !6, i64 8}
!16 = !{!12, !13, i64 0}
!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: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN24CircularDoublyLinkedList7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN24CircularDoublyLinkedList14extractMinimumEv(ptr noundef nonnull align 8 dereferenceable(16) %0) local_unnamed_addr #0 align 2 {
  %2 = tail call noundef zeroext i1 @_ZN24CircularDoublyLinkedList7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  br i1 %2, label %.loopexit, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !10
  %8 = icmp eq ptr %7, %5
  br i1 %8, label %9, label %10

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

10:                                               ; preds = %3
  %11 = getelementptr inbounds i8, ptr %5, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  store ptr %7, ptr %13, align 8, !tbaa !10
  %14 = getelementptr inbounds i8, ptr %7, i64 8
  store ptr %12, ptr %14, align 8, !tbaa !13
  %15 = load ptr, ptr %0, align 8, !tbaa !14
  %16 = icmp eq ptr %5, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %10
  store ptr %7, ptr %0, align 8, !tbaa !14
  br label %18

18:                                               ; preds = %17, %10
  %19 = phi ptr [ %7, %17 ], [ %15, %10 ]
  store ptr %19, ptr %4, align 8, !tbaa !5
  %.0.in20 = getelementptr inbounds i8, ptr %19, i64 16
  %.021 = load ptr, ptr %.0.in20, align 8, !tbaa !10
  %.not22 = icmp eq ptr %.021, %19
  br i1 %.not22, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %18, %25
  %.023 = phi ptr [ %.0, %25 ], [ %.021, %18 ]
  %20 = phi ptr [ %26, %25 ], [ %19, %18 ]
  %21 = load i32, ptr %.023, align 8, !tbaa !15
  %22 = load i32, ptr %20, align 8, !tbaa !15
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %.lr.ph
  store ptr %.023, ptr %4, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %24, %.lr.ph
  %26 = phi ptr [ %.023, %24 ], [ %20, %.lr.ph ]
  %.0.in = getelementptr inbounds i8, ptr %.023, i64 16
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !10
  %.not = icmp eq ptr %.0, %19
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !16

.loopexit:                                        ; preds = %25, %18, %9, %1
  %.017 = phi ptr [ null, %1 ], [ %5, %9 ], [ %5, %18 ], [ %5, %25 ]
  ret ptr %.017
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }

!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 8}
!6 = !{!"_ZTS24CircularDoublyLinkedList", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !7, i64 16}
!11 = !{!"_ZTS4Node", !12, i64 0, !7, i64 8, !7, i64 16}
!12 = !{!"int", !8, i64 0}
!13 = !{!11, !7, i64 8}
!14 = !{!6, !7, i64 0}
!15 = !{!11, !12, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass