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

@__const.benchmark_edn.in_a = external hidden unnamed_addr constant [200 x i16], align 16
@__const.benchmark_edn.in_b = external hidden unnamed_addr constant [200 x i16], align 16
@c = external hidden global i16, align 2
@d = external hidden global i64, align 8
@e = external hidden global i32, align 4
@a = external hidden global [200 x i16], align 16
@b = external hidden global [200 x i16], align 16
@output = external hidden global [200 x i64], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @vec_mpy1(ptr noundef, ptr noundef, i16 noundef signext) #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
declare dso_local i64 @mac(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @fir(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @fir_no_red_ld(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @latsynth(ptr noundef, ptr noundef, i64 noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @iir1(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @codebook(i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, i16 noundef signext, i16 noundef signext) #0

; Function Attrs: nounwind uwtable
declare dso_local void @jpegdct(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @benchmark_edn() #0 {
  %1 = alloca [200 x i16], align 16
  %2 = alloca [200 x i16], align 16
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 400, ptr %1) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %1, ptr align 16 @__const.benchmark_edn.in_a, i64 400, i1 false)
  call void @llvm.lifetime.start.p0(i64 400, ptr %2) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %2, ptr align 16 @__const.benchmark_edn.in_b, i64 400, i1 false)
  store i16 3, ptr @c, align 2, !tbaa !5
  store i64 43690, ptr @d, align 8, !tbaa !9
  store i32 61166, ptr @e, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !11
  br label %4

4:                                                ; preds = %23, %0
  %5 = load i32, ptr %3, align 4, !tbaa !11
  %6 = icmp slt i32 %5, 200
  br i1 %6, label %8, label %7

7:                                                ; preds = %4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %26

8:                                                ; preds = %4
  %9 = load i32, ptr %3, align 4, !tbaa !11
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [200 x i16], ptr %1, i64 0, i64 %10
  %12 = load i16, ptr %11, align 2, !tbaa !5
  %13 = load i32, ptr %3, align 4, !tbaa !11
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [200 x i16], ptr @a, i64 0, i64 %14
  store i16 %12, ptr %15, align 2, !tbaa !5
  %16 = load i32, ptr %3, align 4, !tbaa !11
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [200 x i16], ptr %2, i64 0, i64 %17
  %19 = load i16, ptr %18, align 2, !tbaa !5
  %20 = load i32, ptr %3, align 4, !tbaa !11
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [200 x i16], ptr @b, i64 0, i64 %21
  store i16 %19, ptr %22, align 2, !tbaa !5
  br label %23

23:                                               ; preds = %8
  %24 = load i32, ptr %3, align 4, !tbaa !11
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %3, align 4, !tbaa !11
  br label %4, !llvm.loop !13

26:                                               ; preds = %7
  %27 = load i16, ptr @c, align 2, !tbaa !5
  call void @vec_mpy1(ptr noundef @a, ptr noundef @b, i16 noundef signext %27)
  %28 = load i16, ptr @c, align 2, !tbaa !5
  %29 = sext i16 %28 to i64
  %30 = call i64 @mac(ptr noundef @a, ptr noundef @b, i64 noundef %29, ptr noundef @output)
  %31 = trunc i64 %30 to i16
  store i16 %31, ptr @c, align 2, !tbaa !5
  call void @fir(ptr noundef @a, ptr noundef @b, ptr noundef @output)
  call void @fir_no_red_ld(ptr noundef @a, ptr noundef @b, ptr noundef @output)
  %32 = load i64, ptr @d, align 8, !tbaa !9
  %33 = call i64 @latsynth(ptr noundef @a, ptr noundef @b, i64 noundef 100, i64 noundef %32)
  store i64 %33, ptr @d, align 8, !tbaa !9
  call void @iir1(ptr noundef @a, ptr noundef @b, ptr noundef getelementptr inbounds ([200 x i64], ptr @output, i64 0, i64 100), ptr noundef @output)
  %34 = load i64, ptr @d, align 8, !tbaa !9
  %35 = load i32, ptr @e, align 4, !tbaa !11
  %36 = sext i32 %35 to i64
  %37 = load i64, ptr @d, align 8, !tbaa !9
  %38 = load i16, ptr @c, align 2, !tbaa !5
  %39 = call i64 @codebook(i64 noundef %34, i64 noundef 1, i64 noundef 17, i64 noundef %36, i64 noundef %37, ptr noundef @a, i16 noundef signext %38, i16 noundef signext 1)
  %40 = trunc i64 %39 to i32
  store i32 %40, ptr @e, align 4, !tbaa !11
  call void @jpegdct(ptr noundef @a, ptr noundef @b)
  call void @llvm.lifetime.end.p0(i64 400, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 400, ptr %1) #3
  ret i32 0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"short", !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 = !{!"int", !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"

@__const.benchmark_edn.in_a = external hidden unnamed_addr constant [200 x i16], align 16
@__const.benchmark_edn.in_b = external hidden unnamed_addr constant [200 x i16], align 16
@c = external hidden local_unnamed_addr global i16, align 2
@d = external hidden local_unnamed_addr global i64, align 8
@e = external hidden local_unnamed_addr global i32, align 4
@a = external hidden global [200 x i16], align 16
@b = external hidden global [200 x i16], align 16
@output = external hidden global [200 x i64], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @vec_mpy1(ptr noundef, ptr noundef, i16 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @mac(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @fir(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @fir_no_red_ld(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @latsynth(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @iir1(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @codebook(i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, i16 noundef signext, i16 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @jpegdct(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @benchmark_edn() local_unnamed_addr #0 {
  store i16 3, ptr @c, align 2, !tbaa !5
  store i64 43690, ptr @d, align 8, !tbaa !9
  store i32 61166, ptr @e, align 4, !tbaa !11
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(400) @a, ptr noundef nonnull align 16 dereferenceable(400) @__const.benchmark_edn.in_a, i64 400, i1 false), !tbaa !5
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(400) @b, ptr noundef nonnull align 16 dereferenceable(400) @__const.benchmark_edn.in_b, i64 400, i1 false), !tbaa !5
  tail call void @vec_mpy1(ptr noundef nonnull @a, ptr noundef nonnull @b, i16 noundef signext 3)
  %1 = load i16, ptr @c, align 2, !tbaa !5
  %2 = sext i16 %1 to i64
  %3 = tail call i64 @mac(ptr noundef nonnull @a, ptr noundef nonnull @b, i64 noundef %2, ptr noundef nonnull @output)
  %4 = trunc i64 %3 to i16
  store i16 %4, ptr @c, align 2, !tbaa !5
  tail call void @fir(ptr noundef nonnull @a, ptr noundef nonnull @b, ptr noundef nonnull @output)
  tail call void @fir_no_red_ld(ptr noundef nonnull @a, ptr noundef nonnull @b, ptr noundef nonnull @output)
  %5 = load i64, ptr @d, align 8, !tbaa !9
  %6 = tail call i64 @latsynth(ptr noundef nonnull @a, ptr noundef nonnull @b, i64 noundef 100, i64 noundef %5)
  store i64 %6, ptr @d, align 8, !tbaa !9
  tail call void @iir1(ptr noundef nonnull @a, ptr noundef nonnull @b, ptr noundef nonnull getelementptr inbounds (i8, ptr @output, i64 800), ptr noundef nonnull @output)
  %7 = load i64, ptr @d, align 8, !tbaa !9
  %8 = load i32, ptr @e, align 4, !tbaa !11
  %9 = sext i32 %8 to i64
  %10 = load i16, ptr @c, align 2, !tbaa !5
  %11 = tail call i64 @codebook(i64 noundef %7, i64 noundef 1, i64 noundef 17, i64 noundef %9, i64 noundef %7, ptr noundef nonnull @a, i16 noundef signext %10, i16 noundef signext 1)
  %12 = trunc i64 %11 to i32
  store i32 %12, ptr @e, align 4, !tbaa !11
  tail call void @jpegdct(ptr noundef nonnull @a, ptr noundef nonnull @b)
  ret i32 0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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 = !{!"short", !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 = !{!"int", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass