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

%struct.TwoStruct = type { %struct.SimpleArray2D, %struct.SimpleArray2D }
%struct.SimpleArray2D = type { ptr, i64, i64 }
%struct.LinearResult = type { ptr, ptr, ptr, i64, i64, i64 }

; Function Attrs: nounwind
declare void @free(ptr noundef) #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @linear_to_simplearray(ptr dead_on_unwind noalias writable sret(%struct.TwoStruct) align 8 %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca %struct.SimpleArray2D, align 8
  %5 = alloca %struct.SimpleArray2D, align 8
  %6 = alloca ptr, align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %4) #4
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.LinearResult, ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.SimpleArray2D, ptr %4, i32 0, i32 0
  store ptr %9, ptr %10, align 8, !tbaa !12
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.LinearResult, ptr %11, i32 0, i32 3
  %13 = load i64, ptr %12, align 8, !tbaa !14
  %14 = getelementptr inbounds %struct.SimpleArray2D, ptr %4, i32 0, i32 1
  store i64 %13, ptr %14, align 8, !tbaa !15
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.LinearResult, ptr %15, i32 0, i32 4
  %17 = load i64, ptr %16, align 8, !tbaa !16
  %18 = getelementptr inbounds %struct.SimpleArray2D, ptr %4, i32 0, i32 2
  store i64 %17, ptr %18, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.LinearResult, ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.LinearResult, ptr %22, i32 0, i32 3
  %24 = load i64, ptr %23, align 8, !tbaa !14
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.LinearResult, ptr %25, i32 0, i32 4
  %27 = load i64, ptr %26, align 8, !tbaa !16
  %28 = call ptr @copy_u16_to_f64(ptr noundef %21, i64 noundef %24, i64 noundef %27)
  store ptr %28, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.SimpleArray2D, ptr %5, i32 0, i32 0
  store ptr %29, ptr %30, align 8, !tbaa !12
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.LinearResult, ptr %31, i32 0, i32 3
  %33 = load i64, ptr %32, align 8, !tbaa !14
  %34 = getelementptr inbounds %struct.SimpleArray2D, ptr %5, i32 0, i32 1
  store i64 %33, ptr %34, align 8, !tbaa !15
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.LinearResult, ptr %35, i32 0, i32 4
  %37 = load i64, ptr %36, align 8, !tbaa !16
  %38 = getelementptr inbounds %struct.SimpleArray2D, ptr %5, i32 0, i32 2
  store i64 %37, ptr %38, align 8, !tbaa !17
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.LinearResult, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !18
  call void @free(ptr noundef %41) #4
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.LinearResult, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !19
  call void @free(ptr noundef %44) #4
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.LinearResult, ptr %45, i32 0, i32 0
  store ptr null, ptr %46, align 8, !tbaa !9
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.LinearResult, ptr %47, i32 0, i32 1
  store ptr null, ptr %48, align 8, !tbaa !18
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.LinearResult, ptr %49, i32 0, i32 2
  store ptr null, ptr %50, align 8, !tbaa !19
  %51 = getelementptr inbounds %struct.TwoStruct, ptr %0, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %51, ptr align 8 %4, i64 24, i1 false), !tbaa.struct !20
  %52 = getelementptr inbounds %struct.TwoStruct, ptr %0, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %52, ptr align 8 %5, i64 24, i1 false), !tbaa.struct !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %4) #4
  ret void
}

; 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) #3

attributes #0 = { nounwind "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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, !6, i64 0}
!10 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 32, !11, i64 40}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"", !6, i64 0, !11, i64 8, !11, i64 16}
!14 = !{!10, !11, i64 24}
!15 = !{!13, !11, i64 8}
!16 = !{!10, !11, i64 32}
!17 = !{!13, !11, i64 16}
!18 = !{!10, !6, i64 8}
!19 = !{!10, !6, i64 16}
!20 = !{i64 0, i64 8, !5, i64 8, i64 8, !21, i64 16, i64 8, !21}
!21 = !{!11, !11, i64 0}


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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @linear_to_simplearray(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.TwoStruct) align 8 %0, ptr nocapture noundef %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr %1, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %1, i64 24
  %5 = load i64, ptr %4, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %1, i64 32
  %7 = load i64, ptr %6, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  %10 = tail call ptr @copy_u16_to_f64(ptr noundef %9, i64 noundef %5, i64 noundef %7)
  %11 = load ptr, ptr %8, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %1, i64 16
  %.sroa.42.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 8
  %.sroa.53.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 16
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 32
  %14 = load <2 x i64>, ptr %4, align 8, !tbaa !14
  tail call void @free(ptr noundef %11) #3
  %15 = load ptr, ptr %12, align 8, !tbaa !15
  tail call void @free(ptr noundef %15) #3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %1, i8 0, i64 24, i1 false)
  store ptr %3, ptr %0, align 8, !tbaa !16
  store i64 %5, ptr %.sroa.42.0..sroa_idx, align 8, !tbaa !14
  store i64 %7, ptr %.sroa.53.0..sroa_idx, align 8, !tbaa !14
  store ptr %10, ptr %13, align 8, !tbaa !16
  store <2 x i64> %14, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !14
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 24}
!12 = !{!6, !10, i64 32}
!13 = !{!6, !7, i64 8}
!14 = !{!10, !10, i64 0}
!15 = !{!6, !7, i64 16}
!16 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,TailCallElimPass