; LLVM IR from PeterQLee/sentinel1_denoise_rs :: tests (test_clib)

; 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: nounwind uwtable
define dso_local ptr @copy_u16_to_f64(ptr noundef %0, i64 noundef %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = mul i64 8, %11
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = mul i64 %12, %13
  %15 = call noalias ptr @malloc(i64 noundef %14) #4
  store ptr %15, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %48, %3
  %17 = load i64, ptr %8, align 8, !tbaa !9
  %18 = load i64, ptr %5, align 8, !tbaa !9
  %19 = icmp ult i64 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %51

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %44, %21
  %23 = load i64, ptr %10, align 8, !tbaa !9
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = icmp ult i64 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %47

27:                                               ; preds = %22
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i64, ptr %8, align 8, !tbaa !9
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = mul i64 %29, %30
  %32 = load i64, ptr %10, align 8, !tbaa !9
  %33 = add i64 %31, %32
  %34 = getelementptr inbounds i16, ptr %28, i64 %33
  %35 = load i16, ptr %34, align 2, !tbaa !11
  %36 = uitofp i16 %35 to double
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = load i64, ptr %6, align 8, !tbaa !9
  %40 = mul i64 %38, %39
  %41 = load i64, ptr %10, align 8, !tbaa !9
  %42 = add i64 %40, %41
  %43 = getelementptr inbounds double, ptr %37, i64 %42
  store double %36, ptr %43, align 8, !tbaa !13
  br label %44

44:                                               ; preds = %27
  %45 = load i64, ptr %10, align 8, !tbaa !9
  %46 = add i64 %45, 1
  store i64 %46, ptr %10, align 8, !tbaa !9
  br label %22, !llvm.loop !15

47:                                               ; preds = %26
  br label %48

48:                                               ; preds = %47
  %49 = load i64, ptr %8, align 8, !tbaa !9
  %50 = add i64 %49, 1
  store i64 %50, ptr %8, align 8, !tbaa !9
  br label %16, !llvm.loop !17

51:                                               ; preds = %20
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret ptr %52
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nounwind }
attributes #4 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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 nounwind memory(write, argmem: read, inaccessiblemem: readwrite) uwtable
define dso_local noalias noundef ptr @copy_u16_to_f64(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = shl i64 %1, 3
  %5 = mul i64 %4, %2
  %6 = tail call noalias ptr @malloc(i64 noundef %5) #2
  %.not = icmp eq i64 %1, 0
  %.not21 = icmp eq i64 %2, 0
  %or.cond = or i1 %.not, %.not21
  br i1 %or.cond, label %._crit_edge20, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %3
  %min.iters.check = icmp ult i64 %2, 4
  %n.vec = and i64 %2, -4
  %cmp.n = icmp eq i64 %n.vec, %2
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.01619.us = phi i64 [ %22, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %7 = mul i64 %.01619.us, %2
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %.preheader.us, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.preheader.us ]
  %8 = add i64 %index, %7
  %9 = getelementptr inbounds i16, ptr %0, i64 %8
  %10 = getelementptr inbounds i8, ptr %9, i64 4
  %wide.load = load <2 x i16>, ptr %9, align 2, !tbaa !5
  %wide.load24 = load <2 x i16>, ptr %10, align 2, !tbaa !5
  %11 = uitofp <2 x i16> %wide.load to <2 x double>
  %12 = uitofp <2 x i16> %wide.load24 to <2 x double>
  %13 = getelementptr inbounds double, ptr %6, i64 %8
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  store <2 x double> %11, ptr %13, align 8, !tbaa !9
  store <2 x double> %12, ptr %14, align 8, !tbaa !9
  %index.next = add nuw i64 %index, 4
  %15 = icmp eq i64 %index.next, %n.vec
  br i1 %15, label %middle.block, label %vector.body, !llvm.loop !11

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

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

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.018.us = phi i64 [ %21, %scalar.ph ], [ %.018.us.ph, %scalar.ph.preheader ]
  %16 = add i64 %.018.us, %7
  %17 = getelementptr inbounds i16, ptr %0, i64 %16
  %18 = load i16, ptr %17, align 2, !tbaa !5
  %19 = uitofp i16 %18 to double
  %20 = getelementptr inbounds double, ptr %6, i64 %16
  store double %19, ptr %20, align 8, !tbaa !9
  %21 = add nuw i64 %.018.us, 1
  %exitcond.not = icmp eq i64 %21, %2
  br i1 %exitcond.not, label %._crit_edge.us, label %scalar.ph, !llvm.loop !15

._crit_edge.us:                                   ; preds = %scalar.ph, %middle.block
  %22 = add nuw i64 %.01619.us, 1
  %exitcond23.not = icmp eq i64 %22, %1
  br i1 %exitcond23.not, label %._crit_edge20, label %.preheader.us, !llvm.loop !16

._crit_edge20:                                    ; preds = %._crit_edge.us, %3
  ret ptr %6
}

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

attributes #0 = { nofree nounwind memory(write, argmem: read, inaccessiblemem: 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 = { 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 #2 = { 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !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"}
!15 = distinct !{!15, !12, !14, !13}
!16 = distinct !{!16, !12}


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