; LLVM IR from dmalyuta/FlyARocket_GNC :: la_funcs (madd)

; 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.MATRIX = type { i64, i64, ptr }

; Function Attrs: nounwind uwtable
declare dso_local void @initMatrix(ptr dead_on_unwind noalias writable sret(%struct.MATRIX) align 8, i64 noundef, i64 noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @madd(ptr dead_on_unwind noalias writable sret(%struct.MATRIX) align 8 %0, ptr noundef byval(%struct.MATRIX) align 8 %1, ptr noundef byval(%struct.MATRIX) align 8 %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = getelementptr inbounds %struct.MATRIX, ptr %1, i32 0, i32 0
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.MATRIX, ptr %1, i32 0, i32 1
  %9 = load i64, ptr %8, align 8, !tbaa !11
  call void @initMatrix(ptr dead_on_unwind writable sret(%struct.MATRIX) align 8 %0, i64 noundef %7, i64 noundef %9)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %4, align 4, !tbaa !12
  br label %10

10:                                               ; preds = %58, %3
  %11 = load i32, ptr %4, align 4, !tbaa !12
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds %struct.MATRIX, ptr %1, i32 0, i32 0
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = icmp ult i64 %12, %14
  br i1 %15, label %16, label %61

16:                                               ; preds = %10
  store i32 0, ptr %5, align 4, !tbaa !12
  br label %17

17:                                               ; preds = %54, %16
  %18 = load i32, ptr %5, align 4, !tbaa !12
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds %struct.MATRIX, ptr %1, i32 0, i32 1
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = icmp ult i64 %19, %21
  br i1 %22, label %23, label %57

23:                                               ; preds = %17
  %24 = getelementptr inbounds %struct.MATRIX, ptr %1, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = load i32, ptr %4, align 4, !tbaa !12
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds ptr, ptr %25, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  %30 = load i32, ptr %5, align 4, !tbaa !12
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds float, ptr %29, i64 %31
  %33 = load float, ptr %32, align 4, !tbaa !16
  %34 = getelementptr inbounds %struct.MATRIX, ptr %2, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = load i32, ptr %4, align 4, !tbaa !12
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds ptr, ptr %35, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  %40 = load i32, ptr %5, align 4, !tbaa !12
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds float, ptr %39, i64 %41
  %43 = load float, ptr %42, align 4, !tbaa !16
  %44 = fadd float %33, %43
  %45 = getelementptr inbounds %struct.MATRIX, ptr %0, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !14
  %47 = load i32, ptr %4, align 4, !tbaa !12
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds ptr, ptr %46, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  %51 = load i32, ptr %5, align 4, !tbaa !12
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds float, ptr %50, i64 %52
  store float %44, ptr %53, align 4, !tbaa !16
  br label %54

54:                                               ; preds = %23
  %55 = load i32, ptr %5, align 4, !tbaa !12
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %5, align 4, !tbaa !12
  br label %17, !llvm.loop !18

57:                                               ; preds = %17
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %4, align 4, !tbaa !12
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %4, align 4, !tbaa !12
  br label %10, !llvm.loop !20

61:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  ret void
}

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 }

!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 = !{!"MATRIX", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!6, !10, i64 16}
!15 = !{!10, !10, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"float", !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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

%struct.MATRIX = type { i64, i64, ptr }

; Function Attrs: nounwind uwtable
declare dso_local void @initMatrix(ptr dead_on_unwind noalias writable sret(%struct.MATRIX) align 8, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @madd(ptr dead_on_unwind noalias writable sret(%struct.MATRIX) align 8 %0, ptr nocapture noundef readonly byval(%struct.MATRIX) align 8 %1, ptr nocapture noundef readonly byval(%struct.MATRIX) align 8 %2) local_unnamed_addr #0 {
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !11
  tail call void @initMatrix(ptr dead_on_unwind writable sret(%struct.MATRIX) align 8 %0, i64 noundef %4, i64 noundef %6)
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %._crit_edge15, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %3
  %.not16 = icmp eq i64 %6, 0
  %7 = getelementptr inbounds i8, ptr %1, i64 16
  %8 = load ptr, ptr %7, align 8
  %9 = getelementptr inbounds i8, ptr %2, i64 16
  %10 = load ptr, ptr %9, align 8
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load ptr, ptr %11, align 8
  br i1 %.not16, label %._crit_edge15, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %min.iters.check = icmp ult i64 %6, 8
  %n.vec = and i64 %6, -8
  %cmp.n = icmp eq i64 %6, %n.vec
  %xtraiter = and i64 %6, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv19 = phi i64 [ %indvars.iv.next20, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %13 = getelementptr inbounds ptr, ptr %8, i64 %indvars.iv19
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv19
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = getelementptr inbounds ptr, ptr %12, i64 %indvars.iv19
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.preheader.us
  %19 = ptrtoint ptr %18 to i64
  %20 = ptrtoint ptr %16 to i64
  %21 = ptrtoint ptr %14 to i64
  %22 = sub i64 %19, %21
  %diff.check = icmp ult i64 %22, 32
  %23 = sub i64 %19, %20
  %diff.check26 = icmp ult i64 %23, 32
  %conflict.rdx = or i1 %diff.check, %diff.check26
  br i1 %conflict.rdx, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %vector.memcheck, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %vector.memcheck ]
  %24 = getelementptr inbounds float, ptr %14, i64 %index
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  %wide.load = load <4 x float>, ptr %24, align 4, !tbaa !13
  %wide.load27 = load <4 x float>, ptr %25, align 4, !tbaa !13
  %26 = getelementptr inbounds float, ptr %16, i64 %index
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  %wide.load28 = load <4 x float>, ptr %26, align 4, !tbaa !13
  %wide.load29 = load <4 x float>, ptr %27, align 4, !tbaa !13
  %28 = fadd <4 x float> %wide.load, %wide.load28
  %29 = fadd <4 x float> %wide.load27, %wide.load29
  %30 = getelementptr inbounds float, ptr %18, i64 %index
  %31 = getelementptr inbounds i8, ptr %30, i64 16
  store <4 x float> %28, ptr %30, align 4, !tbaa !13
  store <4 x float> %29, ptr %31, align 4, !tbaa !13
  %index.next = add nuw i64 %index, 8
  %32 = icmp eq i64 %index.next, %n.vec
  br i1 %32, label %middle.block, label %vector.body, !llvm.loop !15

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.preheader.us
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.preheader.us ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %33 = getelementptr inbounds float, ptr %14, i64 %indvars.iv.prol
  %34 = load float, ptr %33, align 4, !tbaa !13
  %35 = getelementptr inbounds float, ptr %16, i64 %indvars.iv.prol
  %36 = load float, ptr %35, align 4, !tbaa !13
  %37 = fadd float %34, %36
  %38 = getelementptr inbounds float, ptr %18, i64 %indvars.iv.prol
  store float %37, ptr %38, align 4, !tbaa !13
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !19

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %39 = sub i64 %indvars.iv.ph, %6
  %40 = icmp ugt i64 %39, -4
  br i1 %40, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %41 = getelementptr inbounds float, ptr %14, i64 %indvars.iv
  %42 = load float, ptr %41, align 4, !tbaa !13
  %43 = getelementptr inbounds float, ptr %16, i64 %indvars.iv
  %44 = load float, ptr %43, align 4, !tbaa !13
  %45 = fadd float %42, %44
  %46 = getelementptr inbounds float, ptr %18, i64 %indvars.iv
  store float %45, ptr %46, align 4, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %47 = getelementptr inbounds float, ptr %14, i64 %indvars.iv.next
  %48 = load float, ptr %47, align 4, !tbaa !13
  %49 = getelementptr inbounds float, ptr %16, i64 %indvars.iv.next
  %50 = load float, ptr %49, align 4, !tbaa !13
  %51 = fadd float %48, %50
  %52 = getelementptr inbounds float, ptr %18, i64 %indvars.iv.next
  store float %51, ptr %52, align 4, !tbaa !13
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %53 = getelementptr inbounds float, ptr %14, i64 %indvars.iv.next.1
  %54 = load float, ptr %53, align 4, !tbaa !13
  %55 = getelementptr inbounds float, ptr %16, i64 %indvars.iv.next.1
  %56 = load float, ptr %55, align 4, !tbaa !13
  %57 = fadd float %54, %56
  %58 = getelementptr inbounds float, ptr %18, i64 %indvars.iv.next.1
  store float %57, ptr %58, align 4, !tbaa !13
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %59 = getelementptr inbounds float, ptr %14, i64 %indvars.iv.next.2
  %60 = load float, ptr %59, align 4, !tbaa !13
  %61 = getelementptr inbounds float, ptr %16, i64 %indvars.iv.next.2
  %62 = load float, ptr %61, align 4, !tbaa !13
  %63 = fadd float %60, %62
  %64 = getelementptr inbounds float, ptr %18, i64 %indvars.iv.next.2
  store float %63, ptr %64, align 4, !tbaa !13
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %6
  br i1 %exitcond.not.3, label %._crit_edge.us, label %scalar.ph, !llvm.loop !21

._crit_edge.us:                                   ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
  %exitcond22.not = icmp eq i64 %indvars.iv.next20, %4
  br i1 %exitcond22.not, label %._crit_edge15, label %.preheader.us, !llvm.loop !22

._crit_edge15:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %3
  ret void
}

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

!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 = !{!"MATRIX", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !8, i64 0}
!15 = distinct !{!15, !16, !17, !18}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!"llvm.loop.isvectorized", i32 1}
!18 = !{!"llvm.loop.unroll.runtime.disable"}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.unroll.disable"}
!21 = distinct !{!21, !16, !17}
!22 = distinct !{!22, !16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass