; LLVM IR from devparthgarg/Data-Structures-and-Algorithms :: 11. Linked List/35 Seagregate Even Odd Nodes of LL/35 Segregate Even Odd Nodes of L_228cb8bc (Z16segregateEvenOddRP4Node)

; 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
define dso_local noundef ptr @_Z16segregateEvenOddRP4Node(ptr noundef nonnull align 8 dereferenceable(8) %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %12, ptr %8, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %51, %1
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %55

16:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = getelementptr inbounds %class.Node, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !9
  store i32 %19, ptr %9, align 4, !tbaa !12
  %20 = load i32, ptr %9, align 4, !tbaa !12
  %21 = srem i32 %20, 2
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %37

23:                                               ; preds = %16
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %29

26:                                               ; preds = %23
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %27, ptr %4, align 8, !tbaa !5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %28, ptr %5, align 8, !tbaa !5
  br label %36

29:                                               ; preds = %23
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %class.Node, ptr %31, i32 0, i32 1
  store ptr %30, ptr %32, align 8, !tbaa !13
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %class.Node, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !13
  store ptr %35, ptr %5, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %29, %26
  br label %51

37:                                               ; preds = %16
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %43

40:                                               ; preds = %37
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %41, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %42, ptr %7, align 8, !tbaa !5
  br label %50

43:                                               ; preds = %37
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %class.Node, ptr %45, i32 0, i32 1
  store ptr %44, ptr %46, align 8, !tbaa !13
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %class.Node, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  store ptr %49, ptr %7, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %43, %40
  br label %51

51:                                               ; preds = %50, %36
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %class.Node, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !13
  store ptr %54, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %13, !llvm.loop !14

55:                                               ; preds = %13
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = icmp eq ptr %56, null
  br i1 %57, label %61, label %58

58:                                               ; preds = %55
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = icmp eq ptr %59, null
  br i1 %60, label %61, label %64

61:                                               ; preds = %58, %55
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  store ptr %63, ptr %2, align 8
  store i32 1, ptr %10, align 4
  br label %71

64:                                               ; preds = %58
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %class.Node, ptr %66, i32 0, i32 1
  store ptr %65, ptr %67, align 8, !tbaa !13
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %class.Node, ptr %68, i32 0, i32 1
  store ptr null, ptr %69, align 8, !tbaa !13
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %70, ptr %2, align 8
  store i32 1, ptr %10, align 4
  br label %71

71:                                               ; preds = %64, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %72 = load ptr, ptr %2, align 8
  ret ptr %72
}

; 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, !11, i64 0}
!10 = !{!"_ZTS4Node", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !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 noundef ptr @_Z16segregateEvenOddRP4Node(ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %0) local_unnamed_addr #0 {
  %.02533 = load ptr, ptr %0, align 8, !tbaa !5
  %.not34 = icmp eq ptr %.02533, null
  br i1 %.not34, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %1, %10
  %.02539 = phi ptr [ %.025, %10 ], [ %.02533, %1 ]
  %.02638 = phi ptr [ %.1, %10 ], [ null, %1 ]
  %.02737 = phi ptr [ %.128, %10 ], [ null, %1 ]
  %.02936 = phi ptr [ %.130, %10 ], [ null, %1 ]
  %.03135 = phi ptr [ %.132, %10 ], [ null, %1 ]
  %2 = load i32, ptr %.02539, align 8, !tbaa !9
  %3 = and i32 %2, 1
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %5, label %7

5:                                                ; preds = %.lr.ph
  %6 = icmp eq ptr %.03135, null
  br i1 %6, label %10, label %.sink.split

7:                                                ; preds = %.lr.ph
  %8 = icmp eq ptr %.02737, null
  br i1 %8, label %10, label %.sink.split

.sink.split:                                      ; preds = %7, %5
  %.02638.sink = phi ptr [ %.02936, %5 ], [ %.02638, %7 ]
  %.130.ph = phi ptr [ %.02539, %5 ], [ %.02936, %7 ]
  %.1.ph = phi ptr [ %.02638, %5 ], [ %.02539, %7 ]
  %9 = getelementptr inbounds i8, ptr %.02638.sink, i64 8
  store ptr %.02539, ptr %9, align 8, !tbaa !12
  br label %10

10:                                               ; preds = %.sink.split, %7, %5
  %.132 = phi ptr [ %.02539, %5 ], [ %.03135, %7 ], [ %.03135, %.sink.split ]
  %.130 = phi ptr [ %.02539, %5 ], [ %.02936, %7 ], [ %.130.ph, %.sink.split ]
  %.128 = phi ptr [ %.02737, %5 ], [ %.02539, %7 ], [ %.02737, %.sink.split ]
  %.1 = phi ptr [ %.02638, %5 ], [ %.02539, %7 ], [ %.1.ph, %.sink.split ]
  %11 = getelementptr inbounds i8, ptr %.02539, i64 8
  %.025 = load ptr, ptr %11, align 8, !tbaa !5
  %.not = icmp eq ptr %.025, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %10
  %12 = icmp eq ptr %.132, null
  %13 = icmp eq ptr %.128, null
  %or.cond = select i1 %12, i1 true, i1 %13
  br i1 %or.cond, label %._crit_edge.thread, label %15

._crit_edge.thread:                               ; preds = %1, %._crit_edge
  %14 = load ptr, ptr %0, align 8, !tbaa !5
  br label %18

15:                                               ; preds = %._crit_edge
  %16 = getelementptr inbounds i8, ptr %.130, i64 8
  store ptr %.128, ptr %16, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %.1, i64 8
  store ptr null, ptr %17, align 8, !tbaa !12
  br label %18

18:                                               ; preds = %15, %._crit_edge.thread
  %.0 = phi ptr [ %14, %._crit_edge.thread ], [ %.132, %15 ]
  ret ptr %.0
}

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


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