; LLVM IR from HarshCasper/NeoAlgo :: C-Plus-Plus/cp/Rotate_doubly_linked_list_by_given_node.ll (Z13rotate_from_nPP4Nodei)

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z13rotate_from_nPP4Nodei(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  br label %65

12:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %14, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %24, %12
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %22

19:                                               ; preds = %15
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br label %22

22:                                               ; preds = %19, %15
  %23 = phi i1 [ false, %15 ], [ %21, %19 ]
  br i1 %23, label %24, label %30

24:                                               ; preds = %22
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Node, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  store ptr %27, ptr %5, align 8, !tbaa !5
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %6, align 4, !tbaa !9
  br label %15, !llvm.loop !13

30:                                               ; preds = %22
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %34

33:                                               ; preds = %30
  store i32 1, ptr %7, align 4
  br label %63

34:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %35, ptr %8, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %41, %34
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.Node, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %45

41:                                               ; preds = %36
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.Node, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !11
  store ptr %44, ptr %5, align 8, !tbaa !5
  br label %36, !llvm.loop !15

45:                                               ; preds = %36
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Node, ptr %48, i32 0, i32 2
  store ptr %47, ptr %49, align 8, !tbaa !11
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Node, ptr %52, i32 0, i32 1
  store ptr %50, ptr %53, align 8, !tbaa !16
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Node, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !11
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %56, ptr %57, align 8, !tbaa !5
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.Node, ptr %59, i32 0, i32 1
  store ptr null, ptr %60, align 8, !tbaa !16
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.Node, ptr %61, i32 0, i32 2
  store ptr null, ptr %62, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  store i32 0, ptr %7, align 4
  br label %63

63:                                               ; preds = %45, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  %64 = load i32, ptr %7, align 4
  switch i32 %64, label %66 [
    i32 0, label %65
    i32 1, label %65
  ]

65:                                               ; preds = %63, %63, %11
  ret void

66:                                               ; preds = %63
  unreachable
}

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


; 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 nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z13rotate_from_nPP4Nodei(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %1, 0
  br i1 %3, label %22, label %.preheader21

.preheader21:                                     ; preds = %2
  %.022 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = icmp sgt i32 %1, 1
  %5 = icmp ne ptr %.022, null
  %6 = select i1 %4, i1 %5, i1 false
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader21, %.lr.ph
  %.024 = phi ptr [ %.0, %.lr.ph ], [ %.022, %.preheader21 ]
  %.01823 = phi i32 [ %8, %.lr.ph ], [ 1, %.preheader21 ]
  %7 = getelementptr inbounds i8, ptr %.024, i64 16
  %8 = add nuw nsw i32 %.01823, 1
  %.0 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = icmp slt i32 %8, %1
  %10 = icmp ne ptr %.0, null
  %11 = select i1 %9, i1 %10, i1 false
  br i1 %11, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.preheader21
  %.0.lcssa = phi ptr [ %.022, %.preheader21 ], [ %.0, %.lr.ph ]
  %12 = icmp eq ptr %.0.lcssa, null
  br i1 %12, label %22, label %.preheader

.preheader:                                       ; preds = %._crit_edge, %.preheader
  %.1 = phi ptr [ %14, %.preheader ], [ %.0.lcssa, %._crit_edge ]
  %13 = getelementptr inbounds i8, ptr %.1, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %.not = icmp eq ptr %14, null
  br i1 %.not, label %15, label %.preheader, !llvm.loop !13

15:                                               ; preds = %.preheader
  %16 = getelementptr inbounds i8, ptr %.1, i64 16
  store ptr %.022, ptr %16, align 8, !tbaa !11
  %17 = load ptr, ptr %0, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  store ptr %.1, ptr %18, align 8, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %.0.lcssa, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  store ptr %20, ptr %0, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 8
  store ptr null, ptr %21, align 8, !tbaa !14
  store ptr null, ptr %19, align 8, !tbaa !11
  br label %22

22:                                               ; preds = %15, %._crit_edge, %2
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 16}
!12 = !{!"_ZTS4Node", !7, i64 0, !6, i64 8, !6, i64 16}
!13 = distinct !{!13, !10}
!14 = !{!12, !6, i64 8}


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