; LLVM IR from JessonYue/LeetCodeLearning :: Array/wuchao/linkedlist/7-29 合并链表 (MergeSortList)

; 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 void @merge(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %5, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %13

9:                                                ; preds = %3
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %9
  br label %69

13:                                               ; preds = %9, %3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %27

16:                                               ; preds = %13
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ListNode, ptr %18, i32 0, i32 1
  store ptr %17, ptr %19, align 8, !tbaa !9
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ListNode, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ListNode, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  call void @merge(ptr noundef %22, ptr noundef %23, ptr noundef %26)
  br label %69

27:                                               ; preds = %13
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = icmp eq ptr %28, null
  br i1 %29, label %30, label %41

30:                                               ; preds = %27
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ListNode, ptr %32, i32 0, i32 1
  store ptr %31, ptr %33, align 8, !tbaa !9
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ListNode, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ListNode, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  call void @merge(ptr noundef %36, ptr noundef %39, ptr noundef %40)
  br label %69

41:                                               ; preds = %27
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.ListNode, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !12
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ListNode, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 8, !tbaa !12
  %48 = icmp slt i32 %44, %47
  br i1 %48, label %49, label %56

49:                                               ; preds = %41
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ListNode, ptr %51, i32 0, i32 1
  store ptr %50, ptr %52, align 8, !tbaa !9
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.ListNode, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !9
  store ptr %55, ptr %5, align 8, !tbaa !5
  br label %63

56:                                               ; preds = %41
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ListNode, ptr %58, i32 0, i32 1
  store ptr %57, ptr %59, align 8, !tbaa !9
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ListNode, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !9
  store ptr %62, ptr %6, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %56, %49
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.ListNode, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !9
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  call void @merge(ptr noundef %66, ptr noundef %67, ptr noundef %68)
  br label %69

69:                                               ; preds = %63, %30, %16, %12
  ret void
}

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

!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, !6, i64 8}
!10 = !{!"ListNode", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, 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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @merge(ptr nocapture noundef writeonly %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %1, null
  %5 = icmp eq ptr %2, null
  %or.cond32 = and i1 %4, %5
  br i1 %or.cond32, label %tailrecurse._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %tailrecurse.backedge
  %6 = phi i1 [ %13, %tailrecurse.backedge ], [ %5, %3 ]
  %7 = phi i1 [ %12, %tailrecurse.backedge ], [ %4, %3 ]
  %.tr3135 = phi ptr [ %.tr31.be, %tailrecurse.backedge ], [ %2, %3 ]
  %.tr3034 = phi ptr [ %.tr30.be, %tailrecurse.backedge ], [ %1, %3 ]
  %.tr33 = phi ptr [ %.tr.be, %tailrecurse.backedge ], [ %0, %3 ]
  br i1 %7, label %8, label %14

8:                                                ; preds = %.lr.ph
  %9 = getelementptr inbounds i8, ptr %.tr33, i64 8
  store ptr %.tr3135, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %.tr3135, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  br label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %24, %27, %8, %15
  %.tr.be = phi ptr [ %.tr3135, %8 ], [ %.tr3034, %15 ], [ %.tr3034, %24 ], [ %.tr3135, %27 ]
  %.tr30.be = phi ptr [ null, %8 ], [ %18, %15 ], [ %26, %24 ], [ %.tr3034, %27 ]
  %.tr31.be = phi ptr [ %11, %8 ], [ null, %15 ], [ %.tr3135, %24 ], [ %29, %27 ]
  %12 = icmp eq ptr %.tr30.be, null
  %13 = icmp eq ptr %.tr31.be, null
  %or.cond = and i1 %12, %13
  br i1 %or.cond, label %tailrecurse._crit_edge, label %.lr.ph

14:                                               ; preds = %.lr.ph
  br i1 %6, label %15, label %19

15:                                               ; preds = %14
  %16 = getelementptr inbounds i8, ptr %.tr33, i64 8
  store ptr %.tr3034, ptr %16, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %.tr3034, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  br label %tailrecurse.backedge

19:                                               ; preds = %14
  %20 = load i32, ptr %.tr3034, align 8, !tbaa !11
  %21 = load i32, ptr %.tr3135, align 8, !tbaa !11
  %22 = icmp slt i32 %20, %21
  %23 = getelementptr inbounds i8, ptr %.tr33, i64 8
  br i1 %22, label %24, label %27

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

27:                                               ; preds = %19
  store ptr %.tr3135, ptr %23, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %.tr3135, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  br label %tailrecurse.backedge

tailrecurse._crit_edge:                           ; preds = %tailrecurse.backedge, %3
  ret void
}

attributes #0 = { 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 = !{!"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}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass