; LLVM IR from codemistic/Data-Structures-and-Algorithms :: CPP/LINKED LIST/SOME LEET CODE QUESTIONS/leetcode92.ll (Z17reverseonlyknodesP4nodeii)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z17reverselinkedlistP4nodeS0_(ptr noundef, ptr 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: mustprogress nounwind uwtable
define dso_local noundef ptr @_Z17reverseonlyknodesP4nodeii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %15, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %16, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store ptr null, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = sub nsw i32 %17, %18
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %25, %3
  %22 = load i32, ptr %12, align 4, !tbaa !9
  %23 = load i32, ptr %11, align 4, !tbaa !9
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %25, label %34

25:                                               ; preds = %21
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %class.node, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  store ptr %28, ptr %10, align 8, !tbaa !5
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds %class.node, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  store ptr %31, ptr %9, align 8, !tbaa !5
  %32 = load i32, ptr %12, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %12, align 4, !tbaa !9
  br label %21, !llvm.loop !13

34:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  store i32 1, ptr %13, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %39, %34
  %36 = load i32, ptr %13, align 4, !tbaa !9
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %39, label %46

39:                                               ; preds = %35
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %40, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %class.node, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !11
  store ptr %43, ptr %7, align 8, !tbaa !5
  %44 = load i32, ptr %13, align 4, !tbaa !9
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %13, align 4, !tbaa !9
  br label %35, !llvm.loop !15

46:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = call noundef ptr @_Z17reverselinkedlistP4nodeS0_(ptr noundef %47, ptr noundef %48)
  store ptr %49, ptr %14, align 8, !tbaa !5
  %50 = load ptr, ptr %14, align 8, !tbaa !5
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %class.node, ptr %51, i32 0, i32 1
  store ptr %50, ptr %52, align 8, !tbaa !11
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds %class.node, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !11
  %56 = load ptr, ptr %14, align 8, !tbaa !5
  %57 = getelementptr inbounds %class.node, ptr %56, i32 0, i32 1
  store ptr %55, ptr %57, align 8, !tbaa !11
  %58 = load ptr, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret ptr %58
}

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


; 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 ptr @_Z17reverselinkedlistP4nodeS0_(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_Z17reverseonlyknodesP4nodeii(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not24 = icmp slt i32 %2, %1
  br i1 %.not24, label %.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %4 = add i32 %2, 1
  %5 = sub i32 %4, %1
  %6 = sub i32 %2, %1
  %xtraiter = and i32 %5, 7
  %7 = icmp ult i32 %6, 7
  br i1 %7, label %.preheader.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %5, -8
  br label %.lr.ph

.preheader.loopexit.unr-lcssa:                    ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa36.ph = phi ptr [ poison, %.lr.ph.preheader ], [ %29, %.lr.ph ]
  %.02325.unr = phi ptr [ %0, %.lr.ph.preheader ], [ %29, %.lr.ph ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.preheader.loopexit.unr-lcssa, %.lr.ph.epil
  %.02325.epil = phi ptr [ %9, %.lr.ph.epil ], [ %.02325.unr, %.preheader.loopexit.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.preheader.loopexit.unr-lcssa ]
  %8 = getelementptr inbounds i8, ptr %.02325.epil, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.preheader, label %.lr.ph.epil, !llvm.loop !11

.preheader:                                       ; preds = %.preheader.loopexit.unr-lcssa, %.lr.ph.epil, %3
  %.023.lcssa = phi ptr [ %0, %3 ], [ %.lcssa36.ph, %.preheader.loopexit.unr-lcssa ], [ %9, %.lr.ph.epil ]
  %10 = icmp sgt i32 %1, 1
  br i1 %10, label %.lr.ph29.preheader, label %._crit_edge

.lr.ph29.preheader:                               ; preds = %.preheader
  %11 = add nsw i32 %1, -1
  %12 = add nsw i32 %1, -2
  %xtraiter38 = and i32 %11, 7
  %13 = icmp ult i32 %12, 7
  br i1 %13, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph29.preheader.new

.lr.ph29.preheader.new:                           ; preds = %.lr.ph29.preheader
  %unroll_iter43 = and i32 %11, -8
  br label %.lr.ph29

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.02325 = phi ptr [ %0, %.lr.ph.preheader.new ], [ %29, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %14 = getelementptr inbounds i8, ptr %.02325, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 8
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 8
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %niter.next.7 = add i32 %niter, 8
  %niter.ncmp.7 = icmp eq i32 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %.preheader.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !13

.lr.ph29:                                         ; preds = %.lr.ph29, %.lr.ph29.preheader.new
  %.028 = phi ptr [ %0, %.lr.ph29.preheader.new ], [ %45, %.lr.ph29 ]
  %niter44 = phi i32 [ 0, %.lr.ph29.preheader.new ], [ %niter44.next.7, %.lr.ph29 ]
  %30 = getelementptr inbounds i8, ptr %.028, i64 8
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i64 8
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 8
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 8
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 8
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 8
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 8
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i64 8
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %niter44.next.7 = add i32 %niter44, 8
  %niter44.ncmp.7 = icmp eq i32 %niter44.next.7, %unroll_iter43
  br i1 %niter44.ncmp.7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph29, !llvm.loop !15

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph29, %.lr.ph29.preheader
  %.028.lcssa.ph = phi ptr [ poison, %.lr.ph29.preheader ], [ %43, %.lr.ph29 ]
  %.lcssa.ph = phi ptr [ poison, %.lr.ph29.preheader ], [ %45, %.lr.ph29 ]
  %.028.unr = phi ptr [ %0, %.lr.ph29.preheader ], [ %45, %.lr.ph29 ]
  %lcmp.mod40.not = icmp eq i32 %xtraiter38, 0
  br i1 %lcmp.mod40.not, label %._crit_edge, label %.lr.ph29.epil

.lr.ph29.epil:                                    ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph29.epil
  %.028.epil = phi ptr [ %47, %.lr.ph29.epil ], [ %.028.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter39 = phi i32 [ %epil.iter39.next, %.lr.ph29.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %46 = getelementptr inbounds i8, ptr %.028.epil, i64 8
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %epil.iter39.next = add i32 %epil.iter39, 1
  %epil.iter39.cmp.not = icmp eq i32 %epil.iter39.next, %xtraiter38
  br i1 %epil.iter39.cmp.not, label %._crit_edge, label %.lr.ph29.epil, !llvm.loop !16

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph29.epil, %.preheader
  %.022.lcssa = phi ptr [ null, %.preheader ], [ %.028.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.028.epil, %.lr.ph29.epil ]
  %.0.lcssa = phi ptr [ %0, %.preheader ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %47, %.lr.ph29.epil ]
  %48 = tail call noundef ptr @_Z17reverselinkedlistP4nodeS0_(ptr noundef %.0.lcssa, ptr noundef %.023.lcssa)
  %49 = getelementptr inbounds i8, ptr %.022.lcssa, i64 8
  store ptr %48, ptr %49, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %.023.lcssa, i64 8
  %51 = load ptr, ptr %50, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %48, i64 8
  store ptr %51, ptr %52, align 8, !tbaa !5
  ret ptr %48
}

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


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