; LLVM IR from HarshCasper/NeoAlgo :: C-Plus-Plus/math/polynomial_addition.ll (Z3sumP10PolynomialS0_)

; 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.Polynomial = 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: 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 @_Z3sumP10PolynomialS0_(ptr noundef %0, ptr noundef %1) #2 {
  %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 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) #3
  %10 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 16) #4
  store ptr %10, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.Polynomial, ptr %11, i32 0, i32 2
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %13, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Polynomial, ptr %14, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  store ptr %16, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %17, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  br label %18

18:                                               ; preds = %102, %2
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %24

21:                                               ; preds = %18
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br label %24

24:                                               ; preds = %21, %18
  %25 = phi i1 [ false, %18 ], [ %23, %21 ]
  br i1 %25, label %26, label %106

26:                                               ; preds = %24
  %27 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 16) #4
  store ptr %27, ptr %9, align 8, !tbaa !5
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Polynomial, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !12
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Polynomial, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !12
  %34 = icmp sgt i32 %30, %33
  br i1 %34, label %35, label %52

35:                                               ; preds = %26
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Polynomial, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !12
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Polynomial, ptr %39, i32 0, i32 1
  store i32 %38, ptr %40, align 4, !tbaa !12
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Polynomial, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !13
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Polynomial, ptr %44, i32 0, i32 0
  store i32 %43, ptr %45, align 8, !tbaa !13
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.Polynomial, ptr %47, i32 0, i32 2
  store ptr %46, ptr %48, align 8, !tbaa !9
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.Polynomial, ptr %49, i32 0, i32 2
  %51 = load ptr, ptr %50, align 8, !tbaa !9
  store ptr %51, ptr %6, align 8, !tbaa !5
  br label %102

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

60:                                               ; preds = %52
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.Polynomial, ptr %61, i32 0, i32 1
  %63 = load i32, ptr %62, align 4, !tbaa !12
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.Polynomial, ptr %64, i32 0, i32 1
  store i32 %63, ptr %65, align 4, !tbaa !12
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.Polynomial, ptr %66, i32 0, i32 0
  %68 = load i32, ptr %67, align 8, !tbaa !13
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.Polynomial, ptr %69, i32 0, i32 0
  store i32 %68, ptr %70, align 8, !tbaa !13
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.Polynomial, ptr %72, i32 0, i32 2
  store ptr %71, ptr %73, align 8, !tbaa !9
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.Polynomial, ptr %74, i32 0, i32 2
  %76 = load ptr, ptr %75, align 8, !tbaa !9
  store ptr %76, ptr %7, align 8, !tbaa !5
  br label %101

77:                                               ; preds = %52
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.Polynomial, ptr %78, i32 0, i32 0
  %80 = load i32, ptr %79, align 8, !tbaa !13
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.Polynomial, ptr %81, i32 0, i32 0
  %83 = load i32, ptr %82, align 8, !tbaa !13
  %84 = add nsw i32 %80, %83
  %85 = load ptr, ptr %9, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.Polynomial, ptr %85, i32 0, i32 0
  store i32 %84, ptr %86, align 8, !tbaa !13
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.Polynomial, ptr %87, i32 0, i32 1
  %89 = load i32, ptr %88, align 4, !tbaa !12
  %90 = load ptr, ptr %9, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.Polynomial, ptr %90, i32 0, i32 1
  store i32 %89, ptr %91, align 4, !tbaa !12
  %92 = load ptr, ptr %9, align 8, !tbaa !5
  %93 = load ptr, ptr %8, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.Polynomial, ptr %93, i32 0, i32 2
  store ptr %92, ptr %94, align 8, !tbaa !9
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.Polynomial, ptr %95, i32 0, i32 2
  %97 = load ptr, ptr %96, align 8, !tbaa !9
  store ptr %97, ptr %6, align 8, !tbaa !5
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.Polynomial, ptr %98, i32 0, i32 2
  %100 = load ptr, ptr %99, align 8, !tbaa !9
  store ptr %100, ptr %7, align 8, !tbaa !5
  br label %101

101:                                              ; preds = %77, %60
  br label %102

102:                                              ; preds = %101, %35
  %103 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %103, ptr %8, align 8, !tbaa !5
  %104 = load ptr, ptr %8, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.Polynomial, ptr %104, i32 0, i32 2
  store ptr null, ptr %105, align 8, !tbaa !9
  br label %18, !llvm.loop !14

106:                                              ; preds = %24
  %107 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret ptr %107
}

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 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 = { nounwind }
attributes #4 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTS10Polynomial", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !11, i64 0}
!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 uwtable
define dso_local noalias noundef nonnull ptr @_Z3sumP10PolynomialS0_(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = tail call noalias noundef nonnull dereferenceable(16) ptr @_Znwm(i64 noundef 16) #2
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = icmp ne ptr %5, null
  %9 = icmp ne ptr %7, null
  %10 = select i1 %8, i1 %9, i1 false
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2, %41
  %.043 = phi ptr [ %.1, %41 ], [ %5, %2 ]
  %.03542 = phi ptr [ %11, %41 ], [ %3, %2 ]
  %.03641 = phi ptr [ %.137, %41 ], [ %7, %2 ]
  %11 = tail call noalias noundef nonnull dereferenceable(16) ptr @_Znwm(i64 noundef 16) #2
  %12 = getelementptr inbounds i8, ptr %.043, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %.03641, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp sgt i32 %13, %15
  br i1 %16, label %17, label %23

17:                                               ; preds = %.lr.ph
  %18 = getelementptr inbounds i8, ptr %11, i64 4
  store i32 %13, ptr %18, align 4, !tbaa !11
  %19 = load i32, ptr %.043, align 8, !tbaa !12
  store i32 %19, ptr %11, align 8, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %.03542, i64 8
  store ptr %11, ptr %20, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %.043, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  br label %41

23:                                               ; preds = %.lr.ph
  %24 = icmp slt i32 %13, %15
  br i1 %24, label %25, label %31

25:                                               ; preds = %23
  %26 = getelementptr inbounds i8, ptr %11, i64 4
  store i32 %15, ptr %26, align 4, !tbaa !11
  %27 = load i32, ptr %.03641, align 8, !tbaa !12
  store i32 %27, ptr %11, align 8, !tbaa !12
  %28 = getelementptr inbounds i8, ptr %.03542, i64 8
  store ptr %11, ptr %28, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %.03641, i64 8
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  br label %41

31:                                               ; preds = %23
  %32 = load i32, ptr %.043, align 8, !tbaa !12
  %33 = load i32, ptr %.03641, align 8, !tbaa !12
  %34 = add nsw i32 %33, %32
  store i32 %34, ptr %11, align 8, !tbaa !12
  %35 = getelementptr inbounds i8, ptr %11, i64 4
  store i32 %13, ptr %35, align 4, !tbaa !11
  %36 = getelementptr inbounds i8, ptr %.03542, i64 8
  store ptr %11, ptr %36, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %.043, i64 8
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %.03641, i64 8
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %25, %31, %17
  %.137 = phi ptr [ %.03641, %17 ], [ %30, %25 ], [ %40, %31 ]
  %.1 = phi ptr [ %22, %17 ], [ %.043, %25 ], [ %38, %31 ]
  %42 = getelementptr inbounds i8, ptr %11, i64 8
  store ptr null, ptr %42, align 8, !tbaa !5
  %43 = icmp ne ptr %.1, null
  %44 = icmp ne ptr %.137, null
  %45 = select i1 %43, i1 %44, i1 false
  br i1 %45, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %41, %2
  ret ptr %3
}

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass