; LLVM IR from lichen-community-systems/signaletic :: libsignaletic/tests (test-libsignaletic)

; 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.sig_Allocator = type { ptr, ptr }
%struct.sig_Buffer = type { i64, ptr }

@allocator = external dso_local global %struct.sig_Allocator, align 8
@.str.17 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [48 x i8], align 1

declare void @UnityAssertEqualNumber(i64 noundef, i64 noundef, ptr noundef, i64 noundef, i32 noundef) #0

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

declare ptr @sig_Buffer_new(ptr noundef, i64 noundef) #0

declare void @sig_Buffer_fill(ptr noundef, ptr noundef) #0

declare void @UnityAssertEqualFloatArray(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 noundef, i32 noundef) #0

; 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 float @fillWithIndices(i64 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @test_sig_BufferView() #2 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  store i64 1024, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store i64 256, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 256, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %8 = load i64, ptr %1, align 8, !tbaa !5
  %9 = call ptr @sig_Buffer_new(ptr noundef @allocator, i64 noundef %8)
  store ptr %9, ptr %4, align 8, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !9
  call void @sig_Buffer_fill(ptr noundef %10, ptr noundef @fillWithIndices)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = call ptr @sig_Buffer_new(ptr noundef @allocator, i64 noundef %11)
  store ptr %12, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %31, %0
  %14 = load i64, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.sig_Buffer, ptr %15, i32 0, i32 0
  %17 = load i64, ptr %16, align 8, !tbaa !11
  %18 = icmp ult i64 %14, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %34

20:                                               ; preds = %13
  %21 = load i64, ptr %6, align 8, !tbaa !5
  %22 = uitofp i64 %21 to float
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = uitofp i64 %23 to float
  %25 = fadd float %22, %24
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.sig_Buffer, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = load i64, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds float, ptr %28, i64 %29
  store float %25, ptr %30, align 4, !tbaa !14
  br label %31

31:                                               ; preds = %20
  %32 = load i64, ptr %6, align 8, !tbaa !5
  %33 = add i64 %32, 1
  store i64 %33, ptr %6, align 8, !tbaa !5
  br label %13, !llvm.loop !16

34:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %35 = load ptr, ptr %4, align 8, !tbaa !9
  %36 = load i64, ptr %3, align 8, !tbaa !5
  %37 = load i64, ptr %2, align 8, !tbaa !5
  %38 = call ptr @sig_BufferView_new(ptr noundef @allocator, ptr noundef %35, i64 noundef %36, i64 noundef %37)
  store ptr %38, ptr %7, align 8, !tbaa !9
  %39 = load i64, ptr %2, align 8, !tbaa !5
  %40 = load ptr, ptr %7, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.sig_Buffer, ptr %40, i32 0, i32 0
  %42 = load i64, ptr %41, align 8, !tbaa !11
  call void @UnityAssertEqualNumber(i64 noundef %39, i64 noundef %42, ptr noundef @.str.17, i64 noundef 338, i32 noundef 36)
  %43 = load ptr, ptr %5, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.sig_Buffer, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !13
  %46 = load ptr, ptr %7, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.sig_Buffer, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = load i64, ptr %2, align 8, !tbaa !5
  %50 = trunc i64 %49 to i32
  call void @UnityAssertEqualFloatArray(ptr noundef %45, ptr noundef %48, i32 noundef %50, ptr noundef @.str.18, i64 noundef 344, i32 noundef 1)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

declare ptr @sig_BufferView_new(ptr noundef, ptr noundef, i64 noundef, i64 noundef) #0

attributes #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 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 }

!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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"sig_Buffer", !6, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

%struct.sig_Allocator = type { ptr, ptr }

@allocator = external dso_local global %struct.sig_Allocator, align 8
@.str.17 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [48 x i8], align 1

declare void @UnityAssertEqualNumber(i64 noundef, i64 noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #0

declare ptr @sig_Buffer_new(ptr noundef, i64 noundef) local_unnamed_addr #0

declare void @sig_Buffer_fill(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @UnityAssertEqualFloatArray(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local float @fillWithIndices(i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @test_sig_BufferView() local_unnamed_addr #1 {
  %1 = tail call ptr @sig_Buffer_new(ptr noundef nonnull @allocator, i64 noundef 1024) #2
  tail call void @sig_Buffer_fill(ptr noundef %1, ptr noundef nonnull @fillWithIndices) #2
  %2 = tail call ptr @sig_Buffer_new(ptr noundef nonnull @allocator, i64 noundef 256) #2
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0
  %4 = getelementptr inbounds i8, ptr %2, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !11
  %min.iters.check = icmp ult i64 %3, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %.017.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %3, -4
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <4 x i64> [ <i64 0, i64 1, i64 2, i64 3>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %6 = uitofp <4 x i64> %vec.ind to <4 x float>
  %7 = fadd <4 x float> %6, <float 2.560000e+02, float 2.560000e+02, float 2.560000e+02, float 2.560000e+02>
  %8 = getelementptr inbounds float, ptr %5, i64 %index
  store <4 x float> %7, ptr %8, align 4, !tbaa !12
  %index.next = add nuw i64 %index, 4
  %vec.ind.next = add <4 x i64> %vec.ind, <i64 4, i64 4, i64 4, i64 4>
  %9 = icmp eq i64 %index.next, %n.vec
  br i1 %9, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %3, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %0
  %10 = tail call ptr @sig_BufferView_new(ptr noundef nonnull @allocator, ptr noundef %1, i64 noundef 256, i64 noundef 256) #2
  %11 = load i64, ptr %10, align 8, !tbaa !5
  tail call void @UnityAssertEqualNumber(i64 noundef 256, i64 noundef %11, ptr noundef nonnull @.str.17, i64 noundef 338, i32 noundef 36) #2
  %12 = getelementptr inbounds i8, ptr %2, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %10, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  tail call void @UnityAssertEqualFloatArray(ptr noundef %13, ptr noundef %15, i32 noundef 256, ptr noundef nonnull @.str.18, i64 noundef 344, i32 noundef 1) #2
  ret void

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.017 = phi i64 [ %19, %scalar.ph ], [ %.017.ph, %scalar.ph.preheader ]
  %16 = uitofp i64 %.017 to float
  %17 = fadd float %16, 2.560000e+02
  %18 = getelementptr inbounds float, ptr %5, i64 %.017
  store float %17, ptr %18, align 4, !tbaa !12
  %19 = add nuw i64 %.017, 1
  %exitcond.not = icmp eq i64 %19, %3
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !18
}

declare ptr @sig_BufferView_new(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass