; LLVM IR from MakeContributions/DSA :: algorithms/CPlusPlus/Linked-Lists (segregate-even-odd-nodes-of-linked-list)

; 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
define dso_local noundef ptr @_Z9segregateP4Node(ptr noundef %0) #1 {
  %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
  store ptr %11, ptr %8, align 8, !tbaa !5
  br label %12

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

15:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %56

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.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 %struct.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 %struct.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 %struct.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 %struct.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
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %52

52:                                               ; preds = %51
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.Node, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !13
  store ptr %55, ptr %8, align 8, !tbaa !5
  br label %12, !llvm.loop !14

56:                                               ; preds = %15
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = icmp eq ptr %57, null
  br i1 %58, label %62, label %59

59:                                               ; preds = %56
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = icmp eq ptr %60, null
  br i1 %61, label %62, label %64

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

64:                                               ; preds = %59
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.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 %struct.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, %62
  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
}

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, !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 @_Z9segregateP4Node(ptr noundef %0) local_unnamed_addr #0 {
  %.not33 = icmp eq ptr %0, null
  br i1 %.not33, label %._crit_edge.thread, label %.lr.ph

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

.lr.ph:                                           ; preds = %1, %12
  %.02538 = phi ptr [ %14, %12 ], [ %0, %1 ]
  %.02637 = phi ptr [ %.1, %12 ], [ null, %1 ]
  %.02736 = phi ptr [ %.128, %12 ], [ null, %1 ]
  %.02935 = phi ptr [ %.130, %12 ], [ null, %1 ]
  %.03134 = phi ptr [ %.132, %12 ], [ null, %1 ]
  %4 = load i32, ptr %.02538, align 8, !tbaa !5
  %5 = and i32 %4, 1
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %9

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

9:                                                ; preds = %.lr.ph
  %10 = icmp eq ptr %.02736, null
  br i1 %10, label %12, label %.sink.split

.sink.split:                                      ; preds = %9, %7
  %.02637.sink = phi ptr [ %.02935, %7 ], [ %.02637, %9 ]
  %.130.ph = phi ptr [ %.02538, %7 ], [ %.02935, %9 ]
  %.1.ph = phi ptr [ %.02637, %7 ], [ %.02538, %9 ]
  %11 = getelementptr inbounds i8, ptr %.02637.sink, i64 8
  store ptr %.02538, ptr %11, align 8, !tbaa !11
  br label %12

12:                                               ; preds = %.sink.split, %9, %7
  %.132 = phi ptr [ %.02538, %7 ], [ %.03134, %9 ], [ %.03134, %.sink.split ]
  %.130 = phi ptr [ %.02538, %7 ], [ %.02935, %9 ], [ %.130.ph, %.sink.split ]
  %.128 = phi ptr [ %.02736, %7 ], [ %.02538, %9 ], [ %.02736, %.sink.split ]
  %.1 = phi ptr [ %.02637, %7 ], [ %.02538, %9 ], [ %.1.ph, %.sink.split ]
  %13 = getelementptr inbounds i8, ptr %.02538, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %.not = icmp eq ptr %14, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

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

._crit_edge.thread:                               ; preds = %1, %._crit_edge, %15
  %.0 = phi ptr [ %.132, %15 ], [ %0, %._crit_edge ], [ null, %1 ]
  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, !7, i64 0}
!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 = !{!6, !10, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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