; LLVM IR from MakeContributions/DSA :: algorithms/CPlusPlus/Linked-Lists/Reorder-List.ll (Z11reorderListP4Node)

; 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 void @_Z11reorderListP4Node(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
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %8, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %9, 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.Node, ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %89

14:                                               ; preds = %1
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %89

17:                                               ; preds = %14
  br label %18

18:                                               ; preds = %28, %17
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %26

21:                                               ; preds = %18
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Node, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = icmp ne ptr %24, null
  br label %26

26:                                               ; preds = %21, %18
  %27 = phi i1 [ false, %18 ], [ %25, %21 ]
  br i1 %27, label %28, label %38

28:                                               ; preds = %26
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %29, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.Node, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.Node, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  store ptr %34, ptr %3, align 8, !tbaa !5
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.Node, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !9
  store ptr %37, ptr %4, align 8, !tbaa !5
  br label %18, !llvm.loop !12

38:                                               ; preds = %26
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Node, ptr %39, i32 0, i32 1
  store ptr null, ptr %40, align 8, !tbaa !9
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %41, ptr %7, align 8, !tbaa !5
  store ptr null, ptr %3, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %45, %38
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %54

45:                                               ; preds = %42
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.Node, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !9
  store ptr %48, ptr %6, align 8, !tbaa !5
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.Node, ptr %50, i32 0, i32 1
  store ptr %49, ptr %51, align 8, !tbaa !9
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %52, ptr %3, align 8, !tbaa !5
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %53, ptr %4, align 8, !tbaa !5
  br label %42, !llvm.loop !14

54:                                               ; preds = %42
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %55, ptr %7, align 8, !tbaa !5
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %56, ptr %6, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %60, %54
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %81

60:                                               ; preds = %57
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %61, ptr %4, align 8, !tbaa !5
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.Node, ptr %62, i32 0, i32 1
  %64 = load ptr, ptr %63, align 8, !tbaa !9
  store ptr %64, ptr %7, align 8, !tbaa !5
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.Node, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !9
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.Node, ptr %68, i32 0, i32 1
  store ptr %67, ptr %69, align 8, !tbaa !9
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.Node, ptr %71, i32 0, i32 1
  store ptr %70, ptr %72, align 8, !tbaa !9
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.Node, ptr %73, i32 0, i32 1
  %75 = load ptr, ptr %74, align 8, !tbaa !9
  store ptr %75, ptr %5, align 8, !tbaa !5
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.Node, ptr %76, i32 0, i32 1
  %78 = load ptr, ptr %77, align 8, !tbaa !9
  %79 = getelementptr inbounds %struct.Node, ptr %78, i32 0, i32 1
  %80 = load ptr, ptr %79, align 8, !tbaa !9
  store ptr %80, ptr %6, align 8, !tbaa !5
  br label %57, !llvm.loop !15

81:                                               ; preds = %57
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = icmp ne ptr %82, null
  br i1 %83, label %84, label %88

84:                                               ; preds = %81
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.Node, ptr %86, i32 0, i32 1
  store ptr %85, ptr %87, align 8, !tbaa !9
  br label %88

88:                                               ; preds = %84, %81
  br label %89

89:                                               ; preds = %88, %14, %1
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void
}

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


; 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 @_Z11reorderListP4Node(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp ne ptr %3, null
  %5 = icmp ne ptr %0, null
  %or.cond = and i1 %5, %4
  br i1 %or.cond, label %.preheader44.preheader, label %26

.preheader44.preheader:                           ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5, !nonnull !11, !noundef !11
  br label %.lr.ph56

.preheader44:                                     ; preds = %.lr.ph56
  %8 = getelementptr inbounds i8, ptr %12, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %.not40 = icmp eq ptr %9, null
  br i1 %.not40, label %.critedge, label %.lr.ph56, !llvm.loop !12

.lr.ph56:                                         ; preds = %.preheader44.preheader, %.preheader44
  %10 = phi ptr [ %9, %.preheader44 ], [ %7, %.preheader44.preheader ]
  %.0344655 = phi ptr [ %14, %.preheader44 ], [ %0, %.preheader44.preheader ]
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %.0344655, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %.critedge, label %.preheader44, !llvm.loop !12

.critedge:                                        ; preds = %.preheader44, %.lr.ph56
  %15 = getelementptr inbounds i8, ptr %.0344655, i64 8
  store ptr null, ptr %15, align 8, !tbaa !5
  %.not4148 = icmp eq ptr %14, null
  br i1 %.not4148, label %.preheader.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %.critedge, %.lr.ph
  %.13550 = phi ptr [ %17, %.lr.ph ], [ %14, %.critedge ]
  %.13749 = phi ptr [ %.13550, %.lr.ph ], [ null, %.critedge ]
  %16 = getelementptr inbounds i8, ptr %.13550, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  store ptr %.13749, ptr %16, align 8, !tbaa !5
  %.not41 = icmp eq ptr %17, null
  br i1 %.not41, label %.preheader.preheader, label %.lr.ph, !llvm.loop !14

.preheader.preheader:                             ; preds = %.lr.ph, %.critedge
  %.052.ph = phi ptr [ null, %.critedge ], [ %.13550, %.lr.ph ]
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %.052 = phi ptr [ %19, %.preheader ], [ %.052.ph, %.preheader.preheader ]
  %.03251 = phi ptr [ %22, %.preheader ], [ %0, %.preheader.preheader ]
  %18 = getelementptr inbounds i8, ptr %.052, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %.03251, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  store ptr %21, ptr %18, align 8, !tbaa !5
  store ptr %.052, ptr %20, align 8, !tbaa !5
  %22 = load ptr, ptr %18, align 8, !tbaa !5
  %.not42 = icmp eq ptr %22, null
  br i1 %.not42, label %23, label %.preheader, !llvm.loop !15

23:                                               ; preds = %.preheader
  %.not43 = icmp eq ptr %19, null
  br i1 %.not43, label %26, label %24

24:                                               ; preds = %23
  %25 = getelementptr inbounds i8, ptr %.052, i64 8
  store ptr %19, ptr %25, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %23, %24, %1
  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, !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 = !{}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


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