; LLVM IR from ritikbanger/Hacktoberfest2022-DSA :: 10. Linked List/cpp/Linked List Complete.ll (Z13mergeTwoListsP4nodeS0_)

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

%class.node = 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4nodeC2Ei(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) unnamed_addr #2 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #3

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z13mergeTwoListsP4nodeS0_(ptr noundef %0, ptr noundef %1) #4 personality ptr @__gxx_personality_v0 {
  %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
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %11, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %12, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %13 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 16) #6
  invoke void @_ZN4nodeC2Ei(ptr noundef nonnull align 8 dereferenceable(16) %13, i32 noundef -1)
          to label %14 unwind label %39

14:                                               ; preds = %2
  store ptr %13, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %15, ptr %10, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %50, %14
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %22

19:                                               ; preds = %16
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br label %22

22:                                               ; preds = %19, %16
  %23 = phi i1 [ false, %16 ], [ %21, %19 ]
  br i1 %23, label %24, label %54

24:                                               ; preds = %22
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %class.node, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !9
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %class.node, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !9
  %31 = icmp sle i32 %27, %30
  br i1 %31, label %32, label %43

32:                                               ; preds = %24
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = getelementptr inbounds %class.node, ptr %34, i32 0, i32 1
  store ptr %33, ptr %35, align 8, !tbaa !12
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %class.node, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !12
  store ptr %38, ptr %5, align 8, !tbaa !5
  br label %50

39:                                               ; preds = %2
  %40 = landingpad { ptr, i32 }
          cleanup
  %41 = extractvalue { ptr, i32 } %40, 0
  store ptr %41, ptr %8, align 8
  %42 = extractvalue { ptr, i32 } %40, 1
  store i32 %42, ptr %9, align 4
  call void @_ZdlPvm(ptr noundef %13, i64 noundef 16) #7
  call void @llvm.lifetime.end.p0(i64 8, 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
  br label %86

43:                                               ; preds = %24
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = getelementptr inbounds %class.node, ptr %45, i32 0, i32 1
  store ptr %44, ptr %46, align 8, !tbaa !12
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %class.node, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !12
  store ptr %49, ptr %6, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %43, %32
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds %class.node, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !12
  store ptr %53, ptr %10, align 8, !tbaa !5
  br label %16, !llvm.loop !13

54:                                               ; preds = %22
  br label %55

55:                                               ; preds = %58, %54
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %68

58:                                               ; preds = %55
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = getelementptr inbounds %class.node, ptr %60, i32 0, i32 1
  store ptr %59, ptr %61, align 8, !tbaa !12
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %class.node, ptr %62, i32 0, i32 1
  %64 = load ptr, ptr %63, align 8, !tbaa !12
  store ptr %64, ptr %5, align 8, !tbaa !5
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = getelementptr inbounds %class.node, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !12
  store ptr %67, ptr %10, align 8, !tbaa !5
  br label %55, !llvm.loop !15

68:                                               ; preds = %55
  br label %69

69:                                               ; preds = %72, %68
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = icmp ne ptr %70, null
  br i1 %71, label %72, label %82

72:                                               ; preds = %69
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = getelementptr inbounds %class.node, ptr %74, i32 0, i32 1
  store ptr %73, ptr %75, align 8, !tbaa !12
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %class.node, ptr %76, i32 0, i32 1
  %78 = load ptr, ptr %77, align 8, !tbaa !12
  store ptr %78, ptr %6, align 8, !tbaa !5
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = getelementptr inbounds %class.node, ptr %79, i32 0, i32 1
  %81 = load ptr, ptr %80, align 8, !tbaa !12
  store ptr %81, ptr %10, align 8, !tbaa !5
  br label %69, !llvm.loop !16

82:                                               ; preds = %69
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = getelementptr inbounds %class.node, ptr %83, i32 0, i32 1
  %85 = load ptr, ptr %84, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, 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
  ret ptr %85

86:                                               ; preds = %39
  %87 = load ptr, ptr %8, align 8
  %88 = load i32, ptr %9, align 4
  %89 = insertvalue { ptr, i32 } poison, ptr %87, 0
  %90 = insertvalue { ptr, i32 } %89, i32 %88, 1
  resume { ptr, i32 } %90
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nobuiltin 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 #2 = { mustprogress 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 #3 = { nobuiltin 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 #4 = { mustprogress 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 = { builtin allocsize(0) }
attributes #7 = { builtin 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++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS4node", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4nodeC2Ei(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z13mergeTwoListsP4nodeS0_(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 personality ptr @__gxx_personality_v0 {
  %3 = tail call noalias noundef nonnull dereferenceable(16) ptr @_Znwm(i64 noundef 16) #3
  tail call void @_ZN4nodeC2Ei(ptr noundef nonnull align 8 dereferenceable(16) %3, i32 noundef -1)
  %4 = icmp ne ptr %0, null
  %5 = icmp ne ptr %1, null
  %6 = and i1 %4, %5
  br i1 %6, label %.lr.ph, label %.preheader33

.preheader33:                                     ; preds = %16, %2
  %.028.lcssa = phi ptr [ %1, %2 ], [ %.129, %16 ]
  %.025.lcssa = phi ptr [ %0, %2 ], [ %.126, %16 ]
  %.0.lcssa = phi ptr [ %3, %2 ], [ %17, %16 ]
  %.not39 = icmp eq ptr %.025.lcssa, null
  br i1 %.not39, label %.preheader, label %.lr.ph42

.lr.ph:                                           ; preds = %2, %16
  %.036 = phi ptr [ %17, %16 ], [ %3, %2 ]
  %.02535 = phi ptr [ %.126, %16 ], [ %0, %2 ]
  %.02834 = phi ptr [ %.129, %16 ], [ %1, %2 ]
  %7 = load i32, ptr %.02535, align 8, !tbaa !5
  %8 = load i32, ptr %.02834, align 8, !tbaa !5
  %.not32 = icmp sgt i32 %7, %8
  %9 = getelementptr inbounds i8, ptr %.036, i64 8
  br i1 %.not32, label %13, label %10

10:                                               ; preds = %.lr.ph
  store ptr %.02535, ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %.02535, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  br label %16

13:                                               ; preds = %.lr.ph
  store ptr %.02834, ptr %9, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %.02834, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  br label %16

16:                                               ; preds = %13, %10
  %17 = phi ptr [ %.02535, %10 ], [ %.02834, %13 ]
  %.129 = phi ptr [ %.02834, %10 ], [ %15, %13 ]
  %.126 = phi ptr [ %12, %10 ], [ %.02535, %13 ]
  %18 = icmp ne ptr %.126, null
  %19 = icmp ne ptr %.129, null
  %20 = select i1 %18, i1 %19, i1 false
  br i1 %20, label %.lr.ph, label %.preheader33, !llvm.loop !12

.preheader:                                       ; preds = %.lr.ph42, %.preheader33
  %.1.lcssa = phi ptr [ %.0.lcssa, %.preheader33 ], [ %.22740, %.lr.ph42 ]
  %.not3144 = icmp eq ptr %.028.lcssa, null
  br i1 %.not3144, label %._crit_edge, label %.lr.ph47

.lr.ph42:                                         ; preds = %.preheader33, %.lr.ph42
  %.141 = phi ptr [ %.22740, %.lr.ph42 ], [ %.0.lcssa, %.preheader33 ]
  %.22740 = phi ptr [ %23, %.lr.ph42 ], [ %.025.lcssa, %.preheader33 ]
  %21 = getelementptr inbounds i8, ptr %.141, i64 8
  store ptr %.22740, ptr %21, align 8, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %.22740, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %.not = icmp eq ptr %23, null
  br i1 %.not, label %.preheader, label %.lr.ph42, !llvm.loop !14

.lr.ph47:                                         ; preds = %.preheader, %.lr.ph47
  %.246 = phi ptr [ %.23045, %.lr.ph47 ], [ %.1.lcssa, %.preheader ]
  %.23045 = phi ptr [ %26, %.lr.ph47 ], [ %.028.lcssa, %.preheader ]
  %24 = getelementptr inbounds i8, ptr %.246, i64 8
  store ptr %.23045, ptr %24, align 8, !tbaa !11
  %25 = getelementptr inbounds i8, ptr %.23045, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %.not31 = icmp eq ptr %26, null
  br i1 %.not31, label %._crit_edge, label %.lr.ph47, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph47, %.preheader
  %27 = getelementptr inbounds i8, ptr %3, i64 8
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  ret ptr %28
}

attributes #0 = { nobuiltin 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 #1 = { mustprogress 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 = { mustprogress 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 #3 = { builtin 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 = !{!"_ZTS4node", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple 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: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass