; LLVM IR from div-bargali/Data-Structures-and-Algorithms :: C/Data-Structures/LinkedList (CircularDoublyLinkedList)

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @create(double noundef) #0

; 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: nounwind uwtable
define dso_local ptr @insertAfter(ptr noundef %0, double noundef %1, double noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %14

11:                                               ; preds = %3
  %12 = load double, ptr %6, align 8, !tbaa !9
  %13 = call ptr @create(double noundef %12)
  store ptr %13, ptr %4, align 8, !tbaa !5
  br label %60

14:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %15 = load double, ptr %5, align 8, !tbaa !9
  %16 = call ptr @create(double noundef %15)
  store ptr %16, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %17, ptr %8, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %32, %14
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.list, ptr %19, i32 0, i32 0
  %21 = load double, ptr %20, align 8, !tbaa !11
  %22 = load double, ptr %6, align 8, !tbaa !9
  %23 = fcmp une double %21, %22
  br i1 %23, label %24, label %30

24:                                               ; preds = %18
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.list, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = icmp ne ptr %25, %28
  br label %30

30:                                               ; preds = %24, %18
  %31 = phi i1 [ false, %18 ], [ %29, %24 ]
  br i1 %31, label %32, label %36

32:                                               ; preds = %30
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.list, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  store ptr %35, ptr %8, align 8, !tbaa !5
  br label %18, !llvm.loop !15

36:                                               ; preds = %30
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.list, ptr %37, i32 0, i32 0
  %39 = load double, ptr %38, align 8, !tbaa !11
  %40 = load double, ptr %6, align 8, !tbaa !9
  %41 = fcmp oeq double %39, %40
  br i1 %41, label %42, label %59

42:                                               ; preds = %36
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.list, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.list, ptr %46, i32 0, i32 1
  store ptr %45, ptr %47, align 8, !tbaa !14
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.list, ptr %49, i32 0, i32 2
  store ptr %48, ptr %50, align 8, !tbaa !13
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.list, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !14
  %55 = getelementptr inbounds %struct.list, ptr %54, i32 0, i32 2
  store ptr %51, ptr %55, align 8, !tbaa !13
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.list, ptr %57, i32 0, i32 1
  store ptr %56, ptr %58, align 8, !tbaa !14
  br label %59

59:                                               ; preds = %42, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %60

60:                                               ; preds = %59, %11
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  ret ptr %61
}

attributes #0 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"list", !10, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 16}
!14 = !{!12, !6, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"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: nounwind uwtable
declare dso_local ptr @create(double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @insertAfter(ptr noundef %0, double noundef %1, double noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %5, label %7

5:                                                ; preds = %3
  %6 = tail call ptr @create(double noundef %2)
  br label %24

7:                                                ; preds = %3
  %8 = tail call ptr @create(double noundef %1)
  %9 = load double, ptr %0, align 8, !tbaa !5
  %10 = fcmp une double %9, %2
  br i1 %10, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %7
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %.not27 = icmp eq ptr %12, %0
  br i1 %.not27, label %.critedge, label %.lr.ph29

.lr.ph29:                                         ; preds = %.lr.ph, %.lr.ph29
  %.02228 = phi ptr [ %14, %.lr.ph29 ], [ %0, %.lr.ph ]
  %13 = getelementptr inbounds i8, ptr %.02228, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = fcmp oeq double %15, %2
  %.not = icmp eq ptr %14, %12
  %or.cond = or i1 %16, %.not
  br i1 %or.cond, label %.critedge, label %.lr.ph29, !llvm.loop !13

.critedge:                                        ; preds = %.lr.ph29, %.lr.ph, %7
  %.0.lcssa = phi ptr [ %0, %7 ], [ %0, %.lr.ph ], [ %14, %.lr.ph29 ]
  %.lcssa = phi double [ %9, %7 ], [ %9, %.lr.ph ], [ %15, %.lr.ph29 ]
  %17 = fcmp oeq double %.lcssa, %2
  br i1 %17, label %18, label %24

18:                                               ; preds = %.critedge
  %19 = getelementptr inbounds i8, ptr %.0.lcssa, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = getelementptr inbounds i8, ptr %8, i64 8
  store ptr %20, ptr %21, align 8, !tbaa !12
  %22 = getelementptr inbounds i8, ptr %8, i64 16
  store ptr %.0.lcssa, ptr %22, align 8, !tbaa !11
  %23 = getelementptr inbounds i8, ptr %20, i64 16
  store ptr %8, ptr %23, align 8, !tbaa !11
  store ptr %8, ptr %19, align 8, !tbaa !12
  br label %24

24:                                               ; preds = %.critedge, %18, %5
  %.020 = phi ptr [ %6, %5 ], [ %0, %18 ], [ %0, %.critedge ]
  ret ptr %.020
}

attributes #0 = { 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 = !{!"list", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !10, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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