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

; 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, 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 @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, 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 @_Z13addPolynomialP4nodeS0_(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 i32, align 4
  %8 = alloca ptr, align 8
  %9 = 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
  %10 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 16) #6
  invoke void @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(16) %10, i32 noundef 0, i32 noundef 0)
          to label %11 unwind label %51

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

13:                                               ; preds = %82, %11
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %19

16:                                               ; preds = %13
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br label %19

19:                                               ; preds = %16, %13
  %20 = phi i1 [ false, %13 ], [ %18, %16 ]
  br i1 %20, label %21, label %86

21:                                               ; preds = %19
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %class.node, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !9
  %25 = load ptr, ptr %4, 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 = icmp eq i32 %24, %27
  br i1 %28, label %29, label %59

29:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %30 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 16) #6
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %class.node, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !12
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %class.node, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !12
  %37 = add nsw i32 %33, %36
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %class.node, ptr %38, i32 0, i32 0
  %40 = load i32, ptr %39, align 8, !tbaa !9
  invoke void @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(16) %30, i32 noundef %37, i32 noundef %40)
          to label %41 unwind label %55

41:                                               ; preds = %29
  store ptr %30, ptr %9, align 8, !tbaa !5
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %class.node, ptr %43, i32 0, i32 2
  store ptr %42, ptr %44, align 8, !tbaa !13
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %class.node, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  store ptr %47, ptr %3, align 8, !tbaa !5
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %class.node, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  store ptr %50, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %82

51:                                               ; preds = %2
  %52 = landingpad { ptr, i32 }
          cleanup
  %53 = extractvalue { ptr, i32 } %52, 0
  store ptr %53, ptr %6, align 8
  %54 = extractvalue { ptr, i32 } %52, 1
  store i32 %54, ptr %7, align 4
  call void @_ZdlPvm(ptr noundef %10, i64 noundef 16) #7
  br label %104

55:                                               ; preds = %29
  %56 = landingpad { ptr, i32 }
          cleanup
  %57 = extractvalue { ptr, i32 } %56, 0
  store ptr %57, ptr %6, align 8
  %58 = extractvalue { ptr, i32 } %56, 1
  store i32 %58, ptr %7, align 4
  call void @_ZdlPvm(ptr noundef %30, i64 noundef 16) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %104

59:                                               ; preds = %21
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %class.node, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 8, !tbaa !9
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %class.node, ptr %63, i32 0, i32 0
  %65 = load i32, ptr %64, align 8, !tbaa !9
  %66 = icmp sgt i32 %62, %65
  br i1 %66, label %67, label %74

67:                                               ; preds = %59
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds %class.node, ptr %69, i32 0, i32 2
  store ptr %68, ptr %70, align 8, !tbaa !13
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %class.node, ptr %71, i32 0, i32 2
  %73 = load ptr, ptr %72, align 8, !tbaa !13
  store ptr %73, ptr %3, align 8, !tbaa !5
  br label %81

74:                                               ; preds = %59
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = getelementptr inbounds %class.node, ptr %76, i32 0, i32 2
  store ptr %75, ptr %77, align 8, !tbaa !13
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %class.node, ptr %78, i32 0, i32 2
  %80 = load ptr, ptr %79, align 8, !tbaa !13
  store ptr %80, ptr %4, align 8, !tbaa !5
  br label %81

81:                                               ; preds = %74, %67
  br label %82

82:                                               ; preds = %81, %41
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = getelementptr inbounds %class.node, ptr %83, i32 0, i32 2
  %85 = load ptr, ptr %84, align 8, !tbaa !13
  store ptr %85, ptr %8, align 8, !tbaa !5
  br label %13, !llvm.loop !14

86:                                               ; preds = %19
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = icmp ne ptr %87, null
  br i1 %88, label %89, label %93

89:                                               ; preds = %86
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = getelementptr inbounds %class.node, ptr %91, i32 0, i32 2
  store ptr %90, ptr %92, align 8, !tbaa !13
  br label %93

93:                                               ; preds = %89, %86
  %94 = load ptr, ptr %3, align 8, !tbaa !5
  %95 = icmp ne ptr %94, null
  br i1 %95, label %96, label %100

96:                                               ; preds = %93
  %97 = load ptr, ptr %3, align 8, !tbaa !5
  %98 = load ptr, ptr %8, align 8, !tbaa !5
  %99 = getelementptr inbounds %class.node, ptr %98, i32 0, i32 2
  store ptr %97, ptr %99, align 8, !tbaa !13
  br label %100

100:                                              ; preds = %96, %93
  %101 = load ptr, ptr %5, align 8, !tbaa !5
  %102 = getelementptr inbounds %class.node, ptr %101, i32 0, i32 2
  %103 = load ptr, ptr %102, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret ptr %103

104:                                              ; preds = %55, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %105

105:                                              ; preds = %104
  %106 = load ptr, ptr %6, align 8
  %107 = load i32, ptr %7, align 4
  %108 = insertvalue { ptr, i32 } poison, ptr %106, 0
  %109 = insertvalue { ptr, i32 } %108, i32 %107, 1
  resume { ptr, i32 } %109
}

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


; 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 @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z13addPolynomialP4nodeS0_(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 @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(16) %3, i32 noundef 0, i32 noundef 0)
  %4 = icmp ne ptr %0, null
  %5 = icmp ne ptr %1, null
  %6 = and i1 %4, %5
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2, %32
  %.036 = phi ptr [ %.1, %32 ], [ %0, %2 ]
  %.02835 = phi ptr [ %33, %32 ], [ %3, %2 ]
  %.02934 = phi ptr [ %.130, %32 ], [ %1, %2 ]
  %7 = load i32, ptr %.036, align 8, !tbaa !5
  %8 = load i32, ptr %.02934, align 8, !tbaa !5
  %9 = icmp eq i32 %7, %8
  br i1 %9, label %10, label %23

10:                                               ; preds = %.lr.ph
  %11 = tail call noalias noundef nonnull dereferenceable(16) ptr @_Znwm(i64 noundef 16) #3
  %12 = getelementptr inbounds i8, ptr %.036, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %.02934, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = add nsw i32 %15, %13
  %17 = load i32, ptr %.036, align 8, !tbaa !5
  tail call void @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(16) %11, i32 noundef %16, i32 noundef %17)
  %18 = getelementptr inbounds i8, ptr %.02835, i64 8
  store ptr %11, ptr %18, align 8, !tbaa !12
  %19 = getelementptr inbounds i8, ptr %.036, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = getelementptr inbounds i8, ptr %.02934, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !12
  br label %32

23:                                               ; preds = %.lr.ph
  %24 = icmp sgt i32 %7, %8
  %25 = getelementptr inbounds i8, ptr %.02835, i64 8
  br i1 %24, label %26, label %29

26:                                               ; preds = %23
  store ptr %.036, ptr %25, align 8, !tbaa !12
  %27 = getelementptr inbounds i8, ptr %.036, i64 8
  %28 = load ptr, ptr %27, align 8, !tbaa !12
  br label %32

29:                                               ; preds = %23
  store ptr %.02934, ptr %25, align 8, !tbaa !12
  %30 = getelementptr inbounds i8, ptr %.02934, i64 8
  %31 = load ptr, ptr %30, align 8, !tbaa !12
  br label %32

32:                                               ; preds = %26, %29, %10
  %33 = phi ptr [ %11, %10 ], [ %.036, %26 ], [ %.02934, %29 ]
  %.130 = phi ptr [ %22, %10 ], [ %.02934, %26 ], [ %31, %29 ]
  %.1 = phi ptr [ %20, %10 ], [ %28, %26 ], [ %.036, %29 ]
  %34 = icmp ne ptr %.1, null
  %35 = icmp ne ptr %.130, null
  %36 = select i1 %34, i1 %35, i1 false
  br i1 %36, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %32, %2
  %.029.lcssa = phi ptr [ %1, %2 ], [ %.130, %32 ]
  %.028.lcssa = phi ptr [ %3, %2 ], [ %33, %32 ]
  %.0.lcssa = phi ptr [ %0, %2 ], [ %.1, %32 ]
  %.lcssa33 = phi i1 [ %4, %2 ], [ %34, %32 ]
  %.lcssa = phi i1 [ %5, %2 ], [ %35, %32 ]
  br i1 %.lcssa, label %37, label %39

37:                                               ; preds = %._crit_edge
  %38 = getelementptr inbounds i8, ptr %.028.lcssa, i64 8
  store ptr %.029.lcssa, ptr %38, align 8, !tbaa !12
  br label %39

39:                                               ; preds = %37, %._crit_edge
  br i1 %.lcssa33, label %40, label %42

40:                                               ; preds = %39
  %41 = getelementptr inbounds i8, ptr %.028.lcssa, i64 8
  store ptr %.0.lcssa, ptr %41, align 8, !tbaa !12
  br label %42

42:                                               ; preds = %40, %39
  %43 = getelementptr inbounds i8, ptr %3, i64 8
  %44 = load ptr, ptr %43, align 8, !tbaa !12
  ret ptr %44
}

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


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass