; LLVM IR from CactiLab/Sherloc-Cortex-M-CFVD :: Sherloc_runtime/evaluation/src/edn (libedn)

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

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

; 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 i64 @mac(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %11 = load ptr, ptr %8, align 8, !tbaa !5
  %12 = load i64, ptr %11, align 8, !tbaa !9
  store i64 %12, ptr %10, align 8, !tbaa !9
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %45, %4
  %14 = load i64, ptr %9, align 8, !tbaa !9
  %15 = icmp slt i64 %14, 150
  br i1 %15, label %16, label %48

16:                                               ; preds = %13
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load i64, ptr %9, align 8, !tbaa !9
  %19 = getelementptr inbounds i16, ptr %17, i64 %18
  %20 = load i16, ptr %19, align 2, !tbaa !11
  %21 = sext i16 %20 to i32
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load i64, ptr %9, align 8, !tbaa !9
  %24 = getelementptr inbounds i16, ptr %22, i64 %23
  %25 = load i16, ptr %24, align 2, !tbaa !11
  %26 = sext i16 %25 to i32
  %27 = mul nsw i32 %21, %26
  %28 = sext i32 %27 to i64
  %29 = load i64, ptr %10, align 8, !tbaa !9
  %30 = add nsw i64 %29, %28
  store i64 %30, ptr %10, align 8, !tbaa !9
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i64, ptr %9, align 8, !tbaa !9
  %33 = getelementptr inbounds i16, ptr %31, i64 %32
  %34 = load i16, ptr %33, align 2, !tbaa !11
  %35 = sext i16 %34 to i32
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load i64, ptr %9, align 8, !tbaa !9
  %38 = getelementptr inbounds i16, ptr %36, i64 %37
  %39 = load i16, ptr %38, align 2, !tbaa !11
  %40 = sext i16 %39 to i32
  %41 = mul nsw i32 %35, %40
  %42 = sext i32 %41 to i64
  %43 = load i64, ptr %7, align 8, !tbaa !9
  %44 = add nsw i64 %43, %42
  store i64 %44, ptr %7, align 8, !tbaa !9
  br label %45

45:                                               ; preds = %16
  %46 = load i64, ptr %9, align 8, !tbaa !9
  %47 = add nsw i64 %46, 1
  store i64 %47, ptr %9, align 8, !tbaa !9
  br label %13, !llvm.loop !13

48:                                               ; preds = %13
  %49 = load i64, ptr %10, align 8, !tbaa !9
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %49, ptr %50, align 8, !tbaa !9
  %51 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret i64 %51
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local i64 @mac(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i64 noundef %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
vector.ph:
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = insertelement <2 x i64> <i64 poison, i64 0>, i64 %4, i64 0
  %6 = insertelement <2 x i64> <i64 poison, i64 0>, i64 %2, i64 0
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ %5, %vector.ph ], [ %19, %vector.body ]
  %vec.phi23 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %20, %vector.body ]
  %vec.phi24 = phi <2 x i64> [ %6, %vector.ph ], [ %25, %vector.body ]
  %vec.phi25 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %26, %vector.body ]
  %7 = getelementptr inbounds i16, ptr %1, i64 %index
  %8 = getelementptr inbounds i8, ptr %7, i64 4
  %wide.load = load <2 x i16>, ptr %7, align 2, !tbaa !9
  %wide.load26 = load <2 x i16>, ptr %8, align 2, !tbaa !9
  %9 = sext <2 x i16> %wide.load to <2 x i32>
  %10 = sext <2 x i16> %wide.load26 to <2 x i32>
  %11 = getelementptr inbounds i16, ptr %0, i64 %index
  %12 = getelementptr inbounds i8, ptr %11, i64 4
  %wide.load27 = load <2 x i16>, ptr %11, align 2, !tbaa !9
  %wide.load28 = load <2 x i16>, ptr %12, align 2, !tbaa !9
  %13 = sext <2 x i16> %wide.load27 to <2 x i32>
  %14 = sext <2 x i16> %wide.load28 to <2 x i32>
  %15 = mul nsw <2 x i32> %13, %9
  %16 = mul nsw <2 x i32> %14, %10
  %17 = sext <2 x i32> %15 to <2 x i64>
  %18 = sext <2 x i32> %16 to <2 x i64>
  %19 = add <2 x i64> %vec.phi, %17
  %20 = add <2 x i64> %vec.phi23, %18
  %21 = mul nsw <2 x i32> %9, %9
  %22 = mul nsw <2 x i32> %10, %10
  %23 = zext nneg <2 x i32> %21 to <2 x i64>
  %24 = zext nneg <2 x i32> %22 to <2 x i64>
  %25 = add <2 x i64> %vec.phi24, %23
  %26 = add <2 x i64> %vec.phi25, %24
  %index.next = add nuw i64 %index, 4
  %27 = icmp eq i64 %index.next, 148
  br i1 %27, label %.loopexit, label %vector.body, !llvm.loop !11

.loopexit:                                        ; preds = %vector.body
  %bin.rdx29 = add <2 x i64> %26, %25
  %28 = tail call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx29)
  %bin.rdx = add <2 x i64> %20, %19
  %29 = tail call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %30 = getelementptr inbounds i8, ptr %1, i64 296
  %31 = load i16, ptr %30, align 2, !tbaa !9
  %32 = sext i16 %31 to i32
  %33 = getelementptr inbounds i8, ptr %0, i64 296
  %34 = load i16, ptr %33, align 2, !tbaa !9
  %35 = sext i16 %34 to i32
  %36 = mul nsw i32 %35, %32
  %37 = sext i32 %36 to i64
  %38 = add nsw i64 %29, %37
  %39 = mul nsw i32 %32, %32
  %40 = zext nneg i32 %39 to i64
  %41 = add nsw i64 %28, %40
  %42 = getelementptr inbounds i8, ptr %1, i64 298
  %43 = load i16, ptr %42, align 2, !tbaa !9
  %44 = sext i16 %43 to i32
  %45 = getelementptr inbounds i8, ptr %0, i64 298
  %46 = load i16, ptr %45, align 2, !tbaa !9
  %47 = sext i16 %46 to i32
  %48 = mul nsw i32 %47, %44
  %49 = sext i32 %48 to i64
  %50 = add nsw i64 %38, %49
  %51 = mul nsw i32 %44, %44
  %52 = zext nneg i32 %51 to i64
  %53 = add nsw i64 %41, %52
  store i64 %50, ptr %3, align 8, !tbaa !5
  ret i64 %53
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #1

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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 speculatable willreturn memory(none) }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass