; LLVM IR from FOSS-UCSC/FOSSALGO :: data-structures/ds-slinklst/cpp/singly_linked_list.ll (Z8editNodeRP4nodeii)

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z8editNodeRP4nodeii(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %1, i32 noundef %2) #1 {
  %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 i32, align 4
  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
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %12, label %18

12:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %14, ptr %7, align 8, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.node, ptr %16, i32 0, i32 0
  store i32 %15, ptr %17, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %42

18:                                               ; preds = %3
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = icmp sgt i32 %19, 1
  br i1 %20, label %21, label %41

21:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  store ptr %23, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %34, %21
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = sub nsw i32 %26, 1
  %28 = icmp slt i32 %25, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %37

30:                                               ; preds = %24
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.node, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  store ptr %33, ptr %8, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %30
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %9, align 4, !tbaa !9
  br label %24, !llvm.loop !14

37:                                               ; preds = %29
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.node, ptr %39, i32 0, i32 0
  store i32 %38, ptr %40, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %41

41:                                               ; preds = %37, %18
  br label %42

42:                                               ; preds = %41, %12
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !10, i64 0}
!12 = !{!"_ZTS4node", !10, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"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 nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z8editNodeRP4nodeii(ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i32 %1, 1
  br i1 %4, label %5, label %7

5:                                                ; preds = %3
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  br label %.sink.split

7:                                                ; preds = %3
  %8 = icmp sgt i32 %1, 1
  br i1 %8, label %.lr.ph.preheader, label %21

.lr.ph.preheader:                                 ; preds = %7
  %.01113 = load ptr, ptr %0, align 8, !tbaa !5
  %9 = add nsw i32 %1, -2
  %10 = add nsw i32 %1, -1
  %xtraiter = and i32 %10, 7
  %11 = icmp ult i32 %9, 7
  br i1 %11, label %.sink.split.loopexit.unr-lcssa, label %.lr.ph.preheader.new

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

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.01115 = phi ptr [ %.01113, %.lr.ph.preheader.new ], [ %.011.7, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %12 = getelementptr inbounds i8, ptr %.01115, i64 8
  %.011 = load ptr, ptr %12, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %.011, i64 8
  %.011.1 = load ptr, ptr %13, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %.011.1, i64 8
  %.011.2 = load ptr, ptr %14, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %.011.2, i64 8
  %.011.3 = load ptr, ptr %15, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %.011.3, i64 8
  %.011.4 = load ptr, ptr %16, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %.011.4, i64 8
  %.011.5 = load ptr, ptr %17, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %.011.5, i64 8
  %.011.6 = load ptr, ptr %18, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.011.6, i64 8
  %.011.7 = load ptr, ptr %19, 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 %.sink.split.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9

.sink.split.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.011.lcssa.ph = phi ptr [ poison, %.lr.ph.preheader ], [ %.011.7, %.lr.ph ]
  %.01115.unr = phi ptr [ %.01113, %.lr.ph.preheader ], [ %.011.7, %.lr.ph ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.sink.split, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.sink.split.loopexit.unr-lcssa, %.lr.ph.epil
  %.01115.epil = phi ptr [ %.011.epil, %.lr.ph.epil ], [ %.01115.unr, %.sink.split.loopexit.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.sink.split.loopexit.unr-lcssa ]
  %20 = getelementptr inbounds i8, ptr %.01115.epil, i64 8
  %.011.epil = load ptr, ptr %20, 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 %.sink.split, label %.lr.ph.epil, !llvm.loop !11

.sink.split:                                      ; preds = %.sink.split.loopexit.unr-lcssa, %.lr.ph.epil, %5
  %.011.lcssa.sink = phi ptr [ %6, %5 ], [ %.011.lcssa.ph, %.sink.split.loopexit.unr-lcssa ], [ %.011.epil, %.lr.ph.epil ]
  store i32 %2, ptr %.011.lcssa.sink, align 8, !tbaa !13
  br label %21

21:                                               ; preds = %.sink.split, %7
  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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTS4node", !15, i64 0, !6, i64 8}
!15 = !{!"int", !7, i64 0}


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