; LLVM IR from JessonYue/LeetCodeLearning :: Array/caiweixiong/c (homework_036)

; 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: 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: nounwind uwtable
declare dso_local i32 @getLinkSize(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @findLinkHeadAndComputeSize(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @mergeAndSortLink(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @sortList_2(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca %struct.ListNode, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i8, align 1
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %22

17:                                               ; preds = %1
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ListNode, ptr %18, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = icmp ne ptr %20, null
  br i1 %21, label %24, label %22

22:                                               ; preds = %17, %1
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %23, ptr %2, align 8
  br label %67

24:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = call i32 @getLinkSize(ptr noundef %25)
  store i32 %26, ptr %4, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 1, ptr %5, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store ptr %6, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ListNode, ptr %28, i32 0, i32 1
  store ptr %27, ptr %29, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %61, %24
  %31 = load i32, ptr %5, align 4, !tbaa !12
  %32 = load i32, ptr %4, align 4, !tbaa !12
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %34, label %64

34:                                               ; preds = %30
  store ptr %6, ptr %7, align 8, !tbaa !5
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ListNode, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !9
  store ptr %37, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %38 = load i32, ptr %4, align 4, !tbaa !12
  store i32 %38, ptr %9, align 4, !tbaa !12
  br label %39

39:                                               ; preds = %60, %34
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %61

42:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %43, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #2
  store i8 0, ptr %12, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  store i32 1, ptr %13, align 4, !tbaa !12
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !12
  %46 = call ptr @findLinkHeadAndComputeSize(ptr noundef %44, ptr noundef %11, i32 noundef %45, ptr noundef %9, ptr noundef %13, ptr noundef %12)
  store ptr %46, ptr %8, align 8, !tbaa !5
  %47 = load i8, ptr %12, align 1, !tbaa !13, !range !15, !noundef !16
  %48 = trunc i8 %47 to i1
  br i1 %48, label %49, label %50

49:                                               ; preds = %42
  store i32 5, ptr %14, align 4
  br label %58

50:                                               ; preds = %42
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = load i32, ptr %5, align 4, !tbaa !12
  %56 = load i32, ptr %13, align 4, !tbaa !12
  %57 = call ptr @mergeAndSortLink(ptr noundef %51, ptr noundef %52, ptr noundef %53, ptr noundef %54, i32 noundef %55, i32 noundef %56)
  store ptr %57, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %14, align 4
  br label %58

58:                                               ; preds = %50, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %59 = load i32, ptr %14, align 4
  switch i32 %59, label %69 [
    i32 0, label %60
    i32 5, label %61
  ]

60:                                               ; preds = %58
  br label %39, !llvm.loop !17

61:                                               ; preds = %58, %39
  %62 = load i32, ptr %5, align 4, !tbaa !12
  %63 = shl i32 %62, 1
  store i32 %63, ptr %5, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %30, !llvm.loop !19

64:                                               ; preds = %30
  %65 = getelementptr inbounds %struct.ListNode, ptr %6, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !9
  store ptr %66, ptr %2, align 8
  store i32 1, ptr %14, align 4
  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 16, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %67

67:                                               ; preds = %64, %22
  %68 = load ptr, ptr %2, align 8
  ret ptr %68

69:                                               ; preds = %58
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"ListNode", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @getLinkSize(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @findLinkHeadAndComputeSize(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @mergeAndSortLink(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @sortList_2(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca %struct.ListNode, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %25, label %7

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %.not26 = icmp eq ptr %9, null
  br i1 %.not26, label %25, label %10

10:                                               ; preds = %7
  %11 = tail call i32 @getLinkSize(ptr noundef nonnull %0)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #2
  %12 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %0, ptr %12, align 8, !tbaa !5
  %13 = icmp sgt i32 %11, 1
  br i1 %13, label %.lr.ph36.split, label %._crit_edge

.lr.ph36.split:                                   ; preds = %10, %.loopexit
  %14 = phi ptr [ %.pr, %.loopexit ], [ %0, %10 ]
  %.02334 = phi i32 [ %22, %.loopexit ], [ 1, %10 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #2
  store i32 %11, ptr %3, align 4, !tbaa !11
  %.not2731 = icmp eq ptr %14, null
  br i1 %.not2731, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph36.split, %18
  %.02133 = phi ptr [ %15, %18 ], [ %14, %.lr.ph36.split ]
  %.02232 = phi ptr [ %21, %18 ], [ %2, %.lr.ph36.split ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %5) #2
  store i8 0, ptr %5, align 1, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #2
  store i32 1, ptr %6, align 4, !tbaa !11
  %15 = call ptr @findLinkHeadAndComputeSize(ptr noundef nonnull %.02133, ptr noundef nonnull %4, i32 noundef %.02334, ptr noundef nonnull %3, ptr noundef nonnull %6, ptr noundef nonnull %5)
  %16 = load i8, ptr %5, align 1, !tbaa !12, !range !14, !noundef !15
  %17 = trunc nuw i8 %16 to i1
  br i1 %17, label %.thread, label %18

.thread:                                          ; preds = %.lr.ph
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #2
  br label %.loopexit

18:                                               ; preds = %.lr.ph
  %19 = load ptr, ptr %4, align 8, !tbaa !16
  %20 = load i32, ptr %6, align 4, !tbaa !11
  %21 = call ptr @mergeAndSortLink(ptr noundef %.02232, ptr noundef nonnull %.02133, ptr noundef %19, ptr noundef %15, i32 noundef %.02334, i32 noundef %20)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #2
  %.not27 = icmp eq ptr %15, null
  br i1 %.not27, label %.loopexit, label %.lr.ph

.loopexit:                                        ; preds = %18, %.lr.ph36.split, %.thread
  %22 = shl i32 %.02334, 1
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #2
  %23 = icmp slt i32 %22, %11
  %.pr = load ptr, ptr %12, align 8, !tbaa !5
  br i1 %23, label %.lr.ph36.split, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %.loopexit, %10
  %24 = phi ptr [ %0, %10 ], [ %.pr, %.loopexit ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #2
  br label %25

25:                                               ; preds = %1, %7, %._crit_edge
  %.020 = phi ptr [ %24, %._crit_edge ], [ %0, %7 ], [ null, %1 ]
  ret ptr %.020
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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, !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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"_Bool", !8, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!10, !10, i64 0}
!17 = distinct !{!17, !18, !19}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!"llvm.loop.unswitch.partial.disable"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass