; LLVM IR from begeekmyfriend/leetcode :: 0086_partition_list (partition_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.ListNode = type { i32, ptr }

; Function Attrs: nounwind uwtable
define dso_local ptr @partition(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca %struct.ListNode, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store ptr %5, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ListNode, ptr %5, i32 0, i32 1
  store ptr %10, ptr %11, align 8, !tbaa !11
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %12, ptr %7, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %25, %2
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %29

16:                                               ; preds = %13
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ListNode, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !13
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = icmp sge i32 %19, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %16
  br label %29

23:                                               ; preds = %16
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %24, ptr %6, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %23
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ListNode, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  store ptr %28, ptr %7, align 8, !tbaa !5
  br label %13, !llvm.loop !14

29:                                               ; preds = %22, %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ListNode, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  store ptr %32, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %33, ptr %9, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %66, %29
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %67

37:                                               ; preds = %34
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ListNode, ptr %38, i32 0, i32 0
  %40 = load i32, ptr %39, align 8, !tbaa !13
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %43, label %61

43:                                               ; preds = %37
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ListNode, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ListNode, ptr %47, i32 0, i32 1
  store ptr %46, ptr %48, align 8, !tbaa !11
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ListNode, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !11
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.ListNode, ptr %52, i32 0, i32 1
  store ptr %51, ptr %53, align 8, !tbaa !11
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.ListNode, ptr %55, i32 0, i32 1
  store ptr %54, ptr %56, align 8, !tbaa !11
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %57, ptr %6, align 8, !tbaa !5
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ListNode, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !11
  store ptr %60, ptr %8, align 8, !tbaa !5
  br label %66

61:                                               ; preds = %37
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %62, ptr %9, align 8, !tbaa !5
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ListNode, ptr %63, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !11
  store ptr %65, ptr %8, align 8, !tbaa !5
  br label %66

66:                                               ; preds = %61, %43
  br label %34, !llvm.loop !16

67:                                               ; preds = %34
  %68 = getelementptr inbounds %struct.ListNode, ptr %5, i32 0, i32 1
  %69 = load ptr, ptr %68, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  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 16, ptr %5) #2
  ret ptr %69
}

; 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"ListNode", !10, i64 0, !6, i64 8}
!13 = !{!12, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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"

%struct.ListNode = type { i32, ptr }

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: write) uwtable
define dso_local ptr @partition(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.ListNode, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #3
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %2
  %.sink = phi ptr [ %0, %2 ], [ %7, %.lr.ph ]
  %.02429 = phi ptr [ %3, %2 ], [ %.sink, %.lr.ph ]
  %.not = icmp ne ptr %.sink, null
  tail call void @llvm.assume(i1 %.not)
  %5 = load i32, ptr %.sink, align 8, !tbaa !11
  %.not26 = icmp slt i32 %5, %1
  %6 = getelementptr inbounds i8, ptr %.sink, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  br i1 %.not26, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph
  %.not2736 = icmp eq ptr %7, null
  br i1 %.not2736, label %._crit_edge42, label %.lr.ph41

.lr.ph41:                                         ; preds = %._crit_edge, %16
  %.02139 = phi ptr [ %.021, %16 ], [ %7, %._crit_edge ]
  %.038 = phi ptr [ %.1, %16 ], [ %.sink, %._crit_edge ]
  %.12537 = phi ptr [ %.2, %16 ], [ %.02429, %._crit_edge ]
  %8 = load i32, ptr %.02139, align 8, !tbaa !11
  %9 = icmp slt i32 %8, %1
  %10 = getelementptr inbounds i8, ptr %.02139, i64 8
  br i1 %9, label %11, label %16

11:                                               ; preds = %.lr.ph41
  %12 = load ptr, ptr %10, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %.038, i64 8
  store ptr %12, ptr %13, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %.12537, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %15, ptr %10, align 8, !tbaa !5
  store ptr %.02139, ptr %14, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %.lr.ph41, %11
  %.2 = phi ptr [ %.02139, %11 ], [ %.12537, %.lr.ph41 ]
  %.122.in = phi ptr [ %13, %11 ], [ %10, %.lr.ph41 ]
  %.1 = phi ptr [ %.038, %11 ], [ %.02139, %.lr.ph41 ]
  %.021 = load ptr, ptr %.122.in, align 8, !tbaa !5
  %.not27 = icmp eq ptr %.021, null
  br i1 %.not27, label %._crit_edge42.loopexit, label %.lr.ph41, !llvm.loop !12

._crit_edge42.loopexit:                           ; preds = %16
  %.pre = load ptr, ptr %4, align 8, !tbaa !5
  br label %._crit_edge42

._crit_edge42:                                    ; preds = %._crit_edge42.loopexit, %._crit_edge
  %17 = phi ptr [ %.pre, %._crit_edge42.loopexit ], [ %0, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #3
  ret ptr %17
}

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)
declare void @llvm.assume(i1 noundef) #2

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: write) 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }
attributes #3 = { 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, !10, i64 8}
!6 = !{!"ListNode", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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