; LLVM IR from AnneLivia/Competitive-Programming :: Data Structures/Linked List/Circular Linked List (Implemented With Struct)/circula_1223c9af (posPP4Nodei)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z8listSizePP4Node(ptr noundef) #1

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

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %22, label %14

14:                                               ; preds = %10
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call noundef i32 @_Z8listSizePP4Node(ptr noundef %16)
  %18 = icmp sgt i32 %15, %17
  br i1 %18, label %22, label %19

19:                                               ; preds = %14
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = icmp sle i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %19, %14, %10, %2
  store i32 1061109567, ptr %3, align 4
  br label %40

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 1, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  store ptr %25, ptr %7, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %30, %23
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %30, label %36

30:                                               ; preds = %26
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Node, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  store ptr %33, ptr %7, align 8, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %6, align 4, !tbaa !9
  br label %26, !llvm.loop !13

36:                                               ; preds = %26
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.Node, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !15
  store i32 %39, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %40

40:                                               ; preds = %36, %22
  %41 = load i32, ptr %3, align 4
  ret i32 %41
}

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, !6, i64 8}
!12 = !{!"_ZTS4Node", !10, i64 0, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !10, 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 i32 @_Z8listSizePP4Node(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z7get_posPP4Nodei(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %25, label %4

4:                                                ; preds = %2
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %25, label %7

7:                                                ; preds = %4
  %8 = tail call noundef i32 @_Z8listSizePP4Node(ptr noundef nonnull %0)
  %9 = icmp slt i32 %8, %1
  %10 = icmp slt i32 %1, 1
  %or.cond = or i1 %10, %9
  br i1 %or.cond, label %25, label %.preheader

.preheader:                                       ; preds = %7
  %.016 = load ptr, ptr %0, align 8, !tbaa !5
  %11 = icmp ugt i32 %1, 1
  br i1 %11, label %.lr.ph.preheader, label %._crit_edge

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

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

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.018 = phi ptr [ %.016, %.lr.ph.preheader.new ], [ %.0.7, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %15 = getelementptr inbounds i8, ptr %.018, i64 8
  %.0 = load ptr, ptr %15, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %.0, i64 8
  %.0.1 = load ptr, ptr %16, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %.0.1, i64 8
  %.0.2 = load ptr, ptr %17, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %.0.2, i64 8
  %.0.3 = load ptr, ptr %18, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.0.3, i64 8
  %.0.4 = load ptr, ptr %19, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %.0.4, i64 8
  %.0.5 = load ptr, ptr %20, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %.0.5, i64 8
  %.0.6 = load ptr, ptr %21, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %.0.6, i64 8
  %.0.7 = load ptr, ptr %22, 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 %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.0.lcssa22.ph = phi ptr [ poison, %.lr.ph.preheader ], [ %.0.7, %.lr.ph ]
  %.018.unr = phi ptr [ %.016, %.lr.ph.preheader ], [ %.0.7, %.lr.ph ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

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

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %.preheader
  %.0.lcssa = phi ptr [ %.016, %.preheader ], [ %.0.lcssa22.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.0.epil, %.lr.ph.epil ]
  %24 = load i32, ptr %.0.lcssa, align 8, !tbaa !13
  br label %25

25:                                               ; preds = %2, %4, %7, %._crit_edge
  %.013 = phi i32 [ %24, %._crit_edge ], [ 1061109567, %7 ], [ 1061109567, %4 ], [ 1061109567, %2 ]
  ret i32 %.013
}

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, !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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass