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

; 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: mustprogress nounwind uwtable
define dso_local void @_ZN24CircularDoublyLinkedList6insertEP4Node(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = call noundef zeroext i1 @_ZN24CircularDoublyLinkedList7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(16) %6)
  br i1 %7, label %8, label %19

8:                                                ; preds = %2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %class.CircularDoublyLinkedList, ptr %6, i32 0, i32 0
  store ptr %9, ptr %10, align 8, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %class.CircularDoublyLinkedList, ptr %6, i32 0, i32 1
  store ptr %11, ptr %12, align 8, !tbaa !11
  %13 = load ptr, 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 1
  store ptr %13, ptr %15, align 8, !tbaa !12
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %class.Node, ptr %17, i32 0, i32 2
  store ptr %16, ptr %18, align 8, !tbaa !15
  br label %50

19:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %20 = getelementptr inbounds %class.CircularDoublyLinkedList, ptr %6, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds %class.Node, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  store ptr %23, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %class.Node, ptr %25, i32 0, i32 2
  store ptr %24, ptr %26, align 8, !tbaa !15
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %class.Node, ptr %28, i32 0, i32 1
  store ptr %27, ptr %29, align 8, !tbaa !12
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %class.CircularDoublyLinkedList, ptr %6, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds %class.Node, ptr %32, i32 0, i32 1
  store ptr %30, ptr %33, align 8, !tbaa !12
  %34 = getelementptr inbounds %class.CircularDoublyLinkedList, ptr %6, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %class.Node, ptr %36, i32 0, i32 2
  store ptr %35, ptr %37, align 8, !tbaa !15
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %class.Node, ptr %38, i32 0, i32 0
  %40 = load i32, ptr %39, align 8, !tbaa !16
  %41 = getelementptr inbounds %class.CircularDoublyLinkedList, ptr %6, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = getelementptr inbounds %class.Node, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !16
  %45 = icmp slt i32 %40, %44
  br i1 %45, label %46, label %49

46:                                               ; preds = %19
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %class.CircularDoublyLinkedList, ptr %6, i32 0, i32 1
  store ptr %47, ptr %48, align 8, !tbaa !11
  br label %49

49:                                               ; preds = %46, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %50

50:                                               ; preds = %49, %8
  ret void
}

; 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

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 0}
!10 = !{!"_ZTS24CircularDoublyLinkedList", !6, i64 0, !6, i64 8}
!11 = !{!10, !6, i64 8}
!12 = !{!13, !6, i64 8}
!13 = !{!"_ZTS4Node", !14, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!"int", !7, i64 0}
!15 = !{!13, !6, i64 16}
!16 = !{!13, !14, i64 0}


; 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 void @_ZN24CircularDoublyLinkedList6insertEP4Node(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %3 = tail call noundef zeroext i1 @_ZN24CircularDoublyLinkedList7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  br i1 %3, label %4, label %8

4:                                                ; preds = %2
  store ptr %1, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %1, ptr %5, align 8, !tbaa !10
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr %1, ptr %6, align 8, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %1, i64 16
  br label %.sink.split

8:                                                ; preds = %2
  %9 = load ptr, ptr %0, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  store ptr %1, ptr %12, align 8, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr %11, ptr %13, align 8, !tbaa !11
  store ptr %1, ptr %10, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %1, i64 16
  store ptr %9, ptr %14, align 8, !tbaa !14
  %15 = load i32, ptr %1, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !10
  %18 = load i32, ptr %17, align 8, !tbaa !15
  %19 = icmp slt i32 %15, %18
  br i1 %19, label %.sink.split, label %20

.sink.split:                                      ; preds = %8, %4
  %.sink = phi ptr [ %7, %4 ], [ %16, %8 ]
  store ptr %1, ptr %.sink, align 8, !tbaa !16
  br label %20

20:                                               ; preds = %.sink.split, %8
  ret void
}

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

!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 = !{!"_ZTS24CircularDoublyLinkedList", !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, !7, i64 8}
!12 = !{!"_ZTS4Node", !13, i64 0, !7, i64 8, !7, i64 16}
!13 = !{!"int", !8, i64 0}
!14 = !{!12, !7, i64 16}
!15 = !{!12, !13, i64 0}
!16 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass