; LLVM IR from wuzhouhui/leetcode :: 147_insert_sort_list (insertionSortList)

; 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 @insertionSortList(ptr noundef %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
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %15

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.ListNode, ptr %11, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = icmp ne ptr %13, null
  br i1 %14, label %17, label %15

15:                                               ; preds = %10, %1
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %16, ptr %2, align 8
  br label %76

17:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %18, ptr %4, align 8, !tbaa !5
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ListNode, ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  store ptr %21, ptr %3, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ListNode, ptr %22, i32 0, i32 1
  store ptr null, ptr %23, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %67, %39, %17
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %74

27:                                               ; preds = %24
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %28, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ListNode, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  store ptr %31, ptr %3, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ListNode, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !12
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ListNode, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !12
  %38 = icmp sle i32 %34, %37
  br i1 %38, label %39, label %44

39:                                               ; preds = %27
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ListNode, ptr %41, i32 0, i32 1
  store ptr %40, ptr %42, align 8, !tbaa !9
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %43, ptr %4, align 8, !tbaa !5
  br label %24, !llvm.loop !13

44:                                               ; preds = %27
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %45, ptr %5, align 8, !tbaa !5
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.ListNode, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !9
  store ptr %48, ptr %7, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %62, %44
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %60

52:                                               ; preds = %49
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.ListNode, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !12
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ListNode, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %57, align 8, !tbaa !12
  %59 = icmp slt i32 %55, %58
  br label %60

60:                                               ; preds = %52, %49
  %61 = phi i1 [ false, %49 ], [ %59, %52 ]
  br i1 %61, label %62, label %67

62:                                               ; preds = %60
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %63, ptr %5, align 8, !tbaa !5
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.ListNode, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !9
  store ptr %66, ptr %7, align 8, !tbaa !5
  br label %49, !llvm.loop !15

67:                                               ; preds = %60
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.ListNode, ptr %69, i32 0, i32 1
  store ptr %68, ptr %70, align 8, !tbaa !9
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.ListNode, ptr %72, i32 0, i32 1
  store ptr %71, ptr %73, align 8, !tbaa !9
  br label %24, !llvm.loop !13

74:                                               ; preds = %24
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %75, ptr %2, align 8
  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
  br label %76

76:                                               ; preds = %74, %15
  %77 = load ptr, ptr %2, align 8
  ret ptr %77
}

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


; 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 noundef ptr @insertionSortList(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit, label %2

2:                                                ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not33 = icmp eq ptr %4, null
  br i1 %.not33, label %.loopexit, label %5

5:                                                ; preds = %2
  store ptr null, ptr %3, align 8, !tbaa !5
  %.pre = load i32, ptr %0, align 8, !tbaa !11
  br label %.lr.ph

.lr.ph:                                           ; preds = %5, %.outer
  %6 = phi i32 [ %.pre, %5 ], [ %10, %.outer ]
  %.029.ph43 = phi ptr [ %0, %5 ], [ %.03040, %.outer ]
  %.030.ph42 = phi ptr [ %4, %5 ], [ %9, %.outer ]
  br label %7

7:                                                ; preds = %.lr.ph, %.critedge
  %.03040 = phi ptr [ %.030.ph42, %.lr.ph ], [ %9, %.critedge ]
  %8 = getelementptr inbounds i8, ptr %.03040, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = load i32, ptr %.03040, align 8, !tbaa !11
  %.not35 = icmp sgt i32 %10, %6
  br i1 %.not35, label %.preheader, label %.outer

.outer:                                           ; preds = %7
  store ptr %.029.ph43, ptr %8, align 8, !tbaa !5
  %.not3439 = icmp eq ptr %9, null
  br i1 %.not3439, label %.loopexit, label %.lr.ph, !llvm.loop !12

.preheader:                                       ; preds = %7, %11
  %.028 = phi ptr [ %.0, %11 ], [ %.029.ph43, %7 ]
  %.0.in = getelementptr inbounds i8, ptr %.028, i64 8
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !5
  %.not36 = icmp eq ptr %.0, null
  br i1 %.not36, label %.critedge, label %11

11:                                               ; preds = %.preheader
  %12 = load i32, ptr %.0, align 8, !tbaa !11
  %13 = icmp slt i32 %12, %10
  br i1 %13, label %.preheader, label %.critedge, !llvm.loop !14

.critedge:                                        ; preds = %.preheader, %11
  %.0.in.le = getelementptr inbounds i8, ptr %.028, i64 8
  store ptr %.0, ptr %8, align 8, !tbaa !5
  store ptr %.03040, ptr %.0.in.le, align 8, !tbaa !5
  %.not34 = icmp eq ptr %9, null
  br i1 %.not34, label %.loopexit, label %7, !llvm.loop !12

.loopexit:                                        ; preds = %.outer, %.critedge, %1, %2
  %.027 = phi ptr [ %0, %2 ], [ null, %1 ], [ %.029.ph43, %.critedge ], [ %.03040, %.outer ]
  ret ptr %.027
}

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}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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