; LLVM IR from HarshCasper/NeoAlgo :: C/math (polynomial_multiplication)

; 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: nounwind allocsize(0)
declare noalias ptr @malloc(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: nounwind uwtable
define dso_local ptr @product(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) #4
  %10 = call noalias ptr @malloc(i64 noundef 16) #5
  store ptr %10, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %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) #4
  %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) #4
  %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) #4
  br label %18

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

21:                                               ; preds = %18
  br label %22

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

25:                                               ; preds = %22
  %26 = call noalias ptr @malloc(i64 noundef 16) #5
  store ptr %26, ptr %9, align 8, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Polynomial, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !12
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.Polynomial, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !12
  %33 = mul nsw i32 %29, %32
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.Polynomial, ptr %34, i32 0, i32 0
  store i32 %33, ptr %35, align 8, !tbaa !12
  %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 !13
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Polynomial, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !13
  %42 = add nsw i32 %38, %41
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.Polynomial, ptr %43, i32 0, i32 1
  store i32 %42, ptr %44, align 4, !tbaa !13
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.Polynomial, ptr %46, i32 0, i32 2
  store ptr %45, ptr %47, align 8, !tbaa !9
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %48, ptr %8, align 8, !tbaa !5
  %49 = load ptr, ptr %7, 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 %7, align 8, !tbaa !5
  br label %22, !llvm.loop !14

52:                                               ; preds = %22
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.Polynomial, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !9
  store ptr %55, ptr %6, align 8, !tbaa !5
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.Polynomial, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %57, align 8, !tbaa !9
  store ptr %58, ptr %7, align 8, !tbaa !5
  br label %18, !llvm.loop !16

59:                                               ; preds = %18
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Polynomial, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !9
  store ptr %62, ptr %6, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %106, %59
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = icmp ne ptr %64, null
  br i1 %65, label %66, label %110

66:                                               ; preds = %63
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %67, ptr %7, align 8, !tbaa !5
  br label %68

68:                                               ; preds = %102, %66
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.Polynomial, ptr %69, i32 0, i32 2
  %71 = load ptr, ptr %70, align 8, !tbaa !9
  %72 = icmp ne ptr %71, null
  br i1 %72, label %73, label %106

73:                                               ; preds = %68
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.Polynomial, ptr %74, i32 0, i32 1
  %76 = load i32, ptr %75, align 4, !tbaa !13
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.Polynomial, ptr %77, i32 0, i32 2
  %79 = load ptr, ptr %78, align 8, !tbaa !9
  %80 = getelementptr inbounds %struct.Polynomial, ptr %79, i32 0, i32 1
  %81 = load i32, ptr %80, align 4, !tbaa !13
  %82 = icmp eq i32 %76, %81
  br i1 %82, label %83, label %102

83:                                               ; preds = %73
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.Polynomial, ptr %84, i32 0, i32 2
  %86 = load ptr, ptr %85, align 8, !tbaa !9
  store ptr %86, ptr %8, align 8, !tbaa !5
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.Polynomial, ptr %87, i32 0, i32 2
  %89 = load ptr, ptr %88, align 8, !tbaa !9
  %90 = getelementptr inbounds %struct.Polynomial, ptr %89, i32 0, i32 0
  %91 = load i32, ptr %90, align 8, !tbaa !12
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.Polynomial, ptr %92, i32 0, i32 0
  %94 = load i32, ptr %93, align 8, !tbaa !12
  %95 = add nsw i32 %94, %91
  store i32 %95, ptr %93, align 8, !tbaa !12
  %96 = load ptr, ptr %8, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.Polynomial, ptr %96, i32 0, i32 2
  %98 = load ptr, ptr %97, align 8, !tbaa !9
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.Polynomial, ptr %99, i32 0, i32 2
  store ptr %98, ptr %100, align 8, !tbaa !9
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %101) #4
  br label %102

102:                                              ; preds = %83, %73
  %103 = load ptr, ptr %7, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.Polynomial, ptr %103, i32 0, i32 2
  %105 = load ptr, ptr %104, align 8, !tbaa !9
  store ptr %105, ptr %7, align 8, !tbaa !5
  br label %68, !llvm.loop !17

106:                                              ; preds = %68
  %107 = load ptr, ptr %6, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.Polynomial, ptr %107, i32 0, i32 2
  %109 = load ptr, ptr %108, align 8, !tbaa !9
  store ptr %109, ptr %6, align 8, !tbaa !5
  br label %63, !llvm.loop !18

110:                                              ; preds = %63
  %111 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret ptr %111
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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

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

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @product(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #3
  %.0.in50 = getelementptr inbounds i8, ptr %0, i64 8
  %.051 = load ptr, ptr %.0.in50, align 8, !tbaa !5
  %.not52 = icmp eq ptr %.051, null
  br i1 %.not52, label %.preheader.preheader, label %.preheader43.lr.ph

.preheader43.lr.ph:                               ; preds = %2
  %.135.in45 = getelementptr inbounds i8, ptr %1, i64 8
  %4 = load ptr, ptr %.135.in45, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %.preheader.preheader, label %.preheader43

.loopexit44:                                      ; preds = %7, %.preheader43
  %.133.lcssa = phi ptr [ %.03253, %.preheader43 ], [ %8, %7 ]
  %.0.in = getelementptr inbounds i8, ptr %.054, i64 8
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %.preheader42, label %.preheader43thread-pre-split, !llvm.loop !11

.preheader43thread-pre-split:                     ; preds = %.loopexit44
  %.13546.pr = load ptr, ptr %.135.in45, align 8, !tbaa !5
  br label %.preheader43

.preheader43:                                     ; preds = %.preheader43.lr.ph, %.preheader43thread-pre-split
  %.13546 = phi ptr [ %.13546.pr, %.preheader43thread-pre-split ], [ %4, %.preheader43.lr.ph ]
  %.054 = phi ptr [ %.0, %.preheader43thread-pre-split ], [ %.051, %.preheader43.lr.ph ]
  %.03253 = phi ptr [ %.133.lcssa, %.preheader43thread-pre-split ], [ %3, %.preheader43.lr.ph ]
  %.not3947 = icmp eq ptr %.13546, null
  br i1 %.not3947, label %.loopexit44, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader43
  %6 = getelementptr inbounds i8, ptr %.054, i64 4
  br label %7

.preheader42:                                     ; preds = %.loopexit44
  %.1.in57.phi.trans.insert = getelementptr inbounds i8, ptr %3, i64 8
  %.158.pre = load ptr, ptr %.1.in57.phi.trans.insert, align 8, !tbaa !5
  %.not3759 = icmp eq ptr %.158.pre, null
  br i1 %.not3759, label %._crit_edge, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader43.lr.ph, %2, %.preheader42
  %.160.ph = phi ptr [ undef, %.preheader43.lr.ph ], [ undef, %2 ], [ %.158.pre, %.preheader42 ]
  br label %.preheader

7:                                                ; preds = %.lr.ph, %7
  %.13549 = phi ptr [ %.13546, %.lr.ph ], [ %.135, %7 ]
  %.13348 = phi ptr [ %.03253, %.lr.ph ], [ %8, %7 ]
  %8 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #3
  %9 = load i32, ptr %.054, align 8, !tbaa !14
  %10 = load i32, ptr %.13549, align 8, !tbaa !14
  %11 = mul nsw i32 %10, %9
  store i32 %11, ptr %8, align 8, !tbaa !14
  %12 = load i32, ptr %6, align 4, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %.13549, i64 4
  %14 = load i32, ptr %13, align 4, !tbaa !15
  %15 = add nsw i32 %14, %12
  %16 = getelementptr inbounds i8, ptr %8, i64 4
  store i32 %15, ptr %16, align 4, !tbaa !15
  %17 = getelementptr inbounds i8, ptr %.13348, i64 8
  store ptr %8, ptr %17, align 8, !tbaa !5
  %.135.in = getelementptr inbounds i8, ptr %.13549, i64 8
  %.135 = load ptr, ptr %.135.in, align 8, !tbaa !5
  %.not39 = icmp eq ptr %.135, null
  br i1 %.not39, label %.loopexit44, label %7, !llvm.loop !16

.loopexit:                                        ; preds = %34
  %.1.pre = load ptr, ptr %18, align 8, !tbaa !5
  %.not37 = icmp eq ptr %.1.pre, null
  br i1 %.not37, label %._crit_edge, label %.preheader, !llvm.loop !17

.preheader:                                       ; preds = %.preheader.preheader, %.loopexit
  %.160 = phi ptr [ %.1.pre, %.loopexit ], [ %.160.ph, %.preheader.preheader ]
  %18 = getelementptr inbounds i8, ptr %.160, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %.not3855 = icmp eq ptr %19, null
  br i1 %.not3855, label %._crit_edge, label %.lr.ph56

.lr.ph56:                                         ; preds = %.preheader
  %20 = getelementptr inbounds i8, ptr %.160, i64 4
  br label %21

21:                                               ; preds = %.lr.ph56, %34
  %22 = phi ptr [ %19, %.lr.ph56 ], [ %37, %34 ]
  %23 = phi ptr [ %18, %.lr.ph56 ], [ %36, %34 ]
  %24 = load i32, ptr %20, align 4, !tbaa !15
  %25 = getelementptr inbounds i8, ptr %22, i64 4
  %26 = load i32, ptr %25, align 4, !tbaa !15
  %27 = icmp eq i32 %24, %26
  br i1 %27, label %28, label %34

28:                                               ; preds = %21
  %29 = load i32, ptr %22, align 8, !tbaa !14
  %30 = load i32, ptr %.160, align 8, !tbaa !14
  %31 = add nsw i32 %30, %29
  store i32 %31, ptr %.160, align 8, !tbaa !14
  %32 = getelementptr inbounds i8, ptr %22, i64 8
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  store ptr %33, ptr %23, align 8, !tbaa !5
  tail call void @free(ptr noundef nonnull %22) #4
  %.pre = load ptr, ptr %23, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %28, %21
  %35 = phi ptr [ %.pre, %28 ], [ %22, %21 ]
  %36 = getelementptr inbounds i8, ptr %35, i64 8
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %.not38 = icmp eq ptr %37, null
  br i1 %.not38, label %.loopexit, label %21, !llvm.loop !18

._crit_edge:                                      ; preds = %.loopexit, %.preheader, %.preheader42
  ret ptr %3
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

attributes #0 = { 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 #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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #3 = { nounwind allocsize(0) }
attributes #4 = { 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 = !{!"Polynomial", !7, i64 0, !7, i64 4, !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 = distinct !{!11, !12, !13}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.unswitch.partial.disable"}
!14 = !{!6, !7, i64 0}
!15 = !{!6, !7, i64 4}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12}
!18 = distinct !{!18, !12}


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