; LLVM IR from begeekmyfriend/leetcode :: 0023_merge_k_sorted_lists (merge_lists)

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

@.str = external hidden unnamed_addr constant [4 x i8], align 1

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

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

11:                                               ; preds = %26, %0
  %12 = load i32, ptr %2, align 4, !tbaa !12
  %13 = icmp slt i32 %12, 3
  br i1 %13, label %14, label %29

14:                                               ; preds = %11
  %15 = call noalias ptr @malloc(i64 noundef 16) #6
  store ptr %15, ptr %4, align 8, !tbaa !11
  %16 = load i32, ptr %2, align 4, !tbaa !12
  %17 = mul nsw i32 %16, 2
  %18 = load ptr, ptr %4, align 8, !tbaa !11
  %19 = getelementptr inbounds %struct.ListNode, ptr %18, i32 0, i32 0
  store i32 %17, ptr %19, align 8, !tbaa !13
  %20 = load ptr, ptr %4, align 8, !tbaa !11
  %21 = getelementptr inbounds %struct.ListNode, ptr %20, i32 0, i32 1
  store ptr null, ptr %21, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !11
  %23 = load ptr, ptr %5, align 8, !tbaa !11
  %24 = getelementptr inbounds %struct.ListNode, ptr %23, i32 0, i32 1
  store ptr %22, ptr %24, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !11
  store ptr %25, ptr %5, align 8, !tbaa !11
  br label %26

26:                                               ; preds = %14
  %27 = load i32, ptr %2, align 4, !tbaa !12
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %2, align 4, !tbaa !12
  br label %11, !llvm.loop !14

29:                                               ; preds = %11
  %30 = getelementptr inbounds %struct.ListNode, ptr %7, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  store ptr %31, ptr %4, align 8, !tbaa !11
  br label %32

32:                                               ; preds = %40, %29
  %33 = load ptr, ptr %4, align 8, !tbaa !11
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %44

35:                                               ; preds = %32
  %36 = load ptr, ptr %4, align 8, !tbaa !11
  %37 = getelementptr inbounds %struct.ListNode, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !13
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %38)
  br label %40

40:                                               ; preds = %35
  %41 = load ptr, ptr %4, align 8, !tbaa !11
  %42 = getelementptr inbounds %struct.ListNode, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  store ptr %43, ptr %4, align 8, !tbaa !11
  br label %32, !llvm.loop !16

44:                                               ; preds = %32
  %45 = call i32 @putchar(i32 noundef 10)
  %46 = getelementptr inbounds %struct.ListNode, ptr %8, i32 0, i32 1
  store ptr null, ptr %46, align 8, !tbaa !5
  store ptr %8, ptr %5, align 8, !tbaa !11
  store i32 0, ptr %2, align 4, !tbaa !12
  br label %47

47:                                               ; preds = %63, %44
  %48 = load i32, ptr %2, align 4, !tbaa !12
  %49 = icmp slt i32 %48, 5
  br i1 %49, label %50, label %66

50:                                               ; preds = %47
  %51 = call noalias ptr @malloc(i64 noundef 16) #6
  store ptr %51, ptr %4, align 8, !tbaa !11
  %52 = load i32, ptr %2, align 4, !tbaa !12
  %53 = mul nsw i32 %52, 2
  %54 = add nsw i32 %53, 1
  %55 = load ptr, ptr %4, align 8, !tbaa !11
  %56 = getelementptr inbounds %struct.ListNode, ptr %55, i32 0, i32 0
  store i32 %54, ptr %56, align 8, !tbaa !13
  %57 = load ptr, ptr %4, align 8, !tbaa !11
  %58 = getelementptr inbounds %struct.ListNode, ptr %57, i32 0, i32 1
  store ptr null, ptr %58, align 8, !tbaa !5
  %59 = load ptr, ptr %4, align 8, !tbaa !11
  %60 = load ptr, ptr %5, align 8, !tbaa !11
  %61 = getelementptr inbounds %struct.ListNode, ptr %60, i32 0, i32 1
  store ptr %59, ptr %61, align 8, !tbaa !5
  %62 = load ptr, ptr %4, align 8, !tbaa !11
  store ptr %62, ptr %5, align 8, !tbaa !11
  br label %63

63:                                               ; preds = %50
  %64 = load i32, ptr %2, align 4, !tbaa !12
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %2, align 4, !tbaa !12
  br label %47, !llvm.loop !17

66:                                               ; preds = %47
  %67 = getelementptr inbounds %struct.ListNode, ptr %8, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  store ptr %68, ptr %4, align 8, !tbaa !11
  br label %69

69:                                               ; preds = %77, %66
  %70 = load ptr, ptr %4, align 8, !tbaa !11
  %71 = icmp ne ptr %70, null
  br i1 %71, label %72, label %81

72:                                               ; preds = %69
  %73 = load ptr, ptr %4, align 8, !tbaa !11
  %74 = getelementptr inbounds %struct.ListNode, ptr %73, i32 0, i32 0
  %75 = load i32, ptr %74, align 8, !tbaa !13
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %75)
  br label %77

77:                                               ; preds = %72
  %78 = load ptr, ptr %4, align 8, !tbaa !11
  %79 = getelementptr inbounds %struct.ListNode, ptr %78, i32 0, i32 1
  %80 = load ptr, ptr %79, align 8, !tbaa !5
  store ptr %80, ptr %4, align 8, !tbaa !11
  br label %69, !llvm.loop !18

81:                                               ; preds = %69
  %82 = call i32 @putchar(i32 noundef 10)
  store i32 2, ptr %3, align 4, !tbaa !12
  %83 = load i32, ptr %3, align 4, !tbaa !12
  %84 = sext i32 %83 to i64
  %85 = mul i64 %84, 8
  %86 = call noalias ptr @malloc(i64 noundef %85) #6
  store ptr %86, ptr %9, align 8, !tbaa !11
  %87 = load ptr, ptr %9, align 8, !tbaa !11
  %88 = getelementptr inbounds ptr, ptr %87, i64 0
  store ptr null, ptr %88, align 8, !tbaa !11
  %89 = load ptr, ptr %9, align 8, !tbaa !11
  %90 = getelementptr inbounds ptr, ptr %89, i64 1
  store ptr null, ptr %90, align 8, !tbaa !11
  %91 = load ptr, ptr %9, align 8, !tbaa !11
  %92 = load i32, ptr %3, align 4, !tbaa !12
  %93 = call ptr @mergeKLists(ptr noundef %91, i32 noundef %92)
  store ptr %93, ptr %6, align 8, !tbaa !11
  %94 = load ptr, ptr %6, align 8, !tbaa !11
  store ptr %94, ptr %4, align 8, !tbaa !11
  br label %95

95:                                               ; preds = %103, %81
  %96 = load ptr, ptr %4, align 8, !tbaa !11
  %97 = icmp ne ptr %96, null
  br i1 %97, label %98, label %107

98:                                               ; preds = %95
  %99 = load ptr, ptr %4, align 8, !tbaa !11
  %100 = getelementptr inbounds %struct.ListNode, ptr %99, i32 0, i32 0
  %101 = load i32, ptr %100, align 8, !tbaa !13
  %102 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %101)
  br label %103

103:                                              ; preds = %98
  %104 = load ptr, ptr %4, align 8, !tbaa !11
  %105 = getelementptr inbounds %struct.ListNode, ptr %104, i32 0, i32 1
  %106 = load ptr, ptr %105, align 8, !tbaa !5
  store ptr %106, ptr %4, align 8, !tbaa !11
  br label %95, !llvm.loop !19

107:                                              ; preds = %95
  %108 = call i32 @putchar(i32 noundef 10)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  ret i32 0
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

declare i32 @printf(ptr noundef, ...) #3

; Function Attrs: inlinehint nounwind uwtable
declare i32 @putchar(i32 noundef) #4

; 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 allocsize(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 #3 = { "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 #4 = { inlinehint 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!10, !10, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}
!18 = distinct !{!18, !15}
!19 = distinct !{!19, !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"

@.str = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
.lr.ph.preheader:
  %0 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #5
  store i32 0, ptr %0, align 8, !tbaa !5
  %1 = getelementptr inbounds i8, ptr %0, i64 8
  %2 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #5
  store i32 2, ptr %2, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %2, ptr %1, align 8, !tbaa !11
  %4 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #5
  store i32 4, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr null, ptr %5, align 8, !tbaa !11
  store ptr %4, ptr %3, align 8, !tbaa !11
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.03039 = phi ptr [ %9, %.lr.ph ], [ %0, %.lr.ph.preheader ]
  %6 = load i32, ptr %.03039, align 8, !tbaa !5
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %6)
  %8 = getelementptr inbounds i8, ptr %.03039, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %.lr.ph45.preheader, label %.lr.ph, !llvm.loop !12

.lr.ph45.preheader:                               ; preds = %.lr.ph
  %10 = tail call i32 @putchar(i32 noundef 10)
  %11 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #5
  store i32 1, ptr %11, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %13 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #5
  store i32 3, ptr %13, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  store ptr %13, ptr %12, align 8, !tbaa !11
  %15 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #5
  store i32 5, ptr %15, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  store ptr %15, ptr %14, align 8, !tbaa !11
  %17 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #5
  store i32 7, ptr %17, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  store ptr %17, ptr %16, align 8, !tbaa !11
  %19 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #5
  store i32 9, ptr %19, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  store ptr null, ptr %20, align 8, !tbaa !11
  store ptr %19, ptr %18, align 8, !tbaa !11
  br label %.lr.ph45

.lr.ph45:                                         ; preds = %.lr.ph45.preheader, %.lr.ph45
  %.13143 = phi ptr [ %24, %.lr.ph45 ], [ %11, %.lr.ph45.preheader ]
  %21 = load i32, ptr %.13143, align 8, !tbaa !5
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %21)
  %23 = getelementptr inbounds i8, ptr %.13143, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %.not34 = icmp eq ptr %24, null
  br i1 %.not34, label %._crit_edge46, label %.lr.ph45, !llvm.loop !14

._crit_edge46:                                    ; preds = %.lr.ph45
  %25 = tail call i32 @putchar(i32 noundef 10)
  %calloc = tail call dereferenceable_or_null(16) ptr @calloc(i64 1, i64 16)
  %26 = tail call ptr @mergeKLists(ptr noundef nonnull %calloc, i32 noundef 2)
  %.not3547 = icmp eq ptr %26, null
  br i1 %.not3547, label %._crit_edge51, label %.lr.ph50

.lr.ph50:                                         ; preds = %._crit_edge46, %.lr.ph50
  %.248 = phi ptr [ %30, %.lr.ph50 ], [ %26, %._crit_edge46 ]
  %27 = load i32, ptr %.248, align 8, !tbaa !5
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %27)
  %29 = getelementptr inbounds i8, ptr %.248, i64 8
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %.not35 = icmp eq ptr %30, null
  br i1 %.not35, label %._crit_edge51, label %.lr.ph50, !llvm.loop !15

._crit_edge51:                                    ; preds = %.lr.ph50, %._crit_edge46
  %31 = tail call i32 @putchar(i32 noundef 10)
  ret i32 0
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: inlinehint nofree nounwind uwtable
declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #4

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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nofree nounwind "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 #3 = { inlinehint nofree 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 #4 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #5 = { nounwind allocsize(0) }

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


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass