; LLVM IR from jgaeddert/liquid-dsp :: src/fec/src (interleaver)

; 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.interleaver_s = type { i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local ptr @interleaver_create(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %4 = call noalias ptr @malloc(i64 noundef 16) #6
  store ptr %4, ptr %3, align 8, !tbaa !9
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !9
  %7 = getelementptr inbounds %struct.interleaver_s, ptr %6, i32 0, i32 0
  store i32 %5, ptr %7, align 4, !tbaa !11
  %8 = load ptr, ptr %3, align 8, !tbaa !9
  %9 = getelementptr inbounds %struct.interleaver_s, ptr %8, i32 0, i32 3
  store i32 4, ptr %9, align 4, !tbaa !13
  %10 = load ptr, ptr %3, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.interleaver_s, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = uitofp i32 %12 to float
  %14 = call float @sqrtf(float noundef %13) #5
  %15 = call float @llvm.floor.f32(float %14)
  %16 = fptoui float %15 to i32
  %17 = add i32 1, %16
  %18 = load ptr, ptr %3, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.interleaver_s, ptr %18, i32 0, i32 1
  store i32 %17, ptr %19, align 4, !tbaa !14
  %20 = load ptr, ptr %3, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.interleaver_s, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = load ptr, ptr %3, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.interleaver_s, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !14
  %26 = udiv i32 %22, %25
  %27 = load ptr, ptr %3, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.interleaver_s, ptr %27, i32 0, i32 2
  store i32 %26, ptr %28, align 4, !tbaa !15
  br label %29

29:                                               ; preds = %41, %1
  %30 = load ptr, ptr %3, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.interleaver_s, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 4, !tbaa !11
  %33 = load ptr, ptr %3, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.interleaver_s, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !14
  %36 = load ptr, ptr %3, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.interleaver_s, ptr %36, i32 0, i32 2
  %38 = load i32, ptr %37, align 4, !tbaa !15
  %39 = mul i32 %35, %38
  %40 = icmp uge i32 %32, %39
  br i1 %40, label %41, label %46

41:                                               ; preds = %29
  %42 = load ptr, ptr %3, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.interleaver_s, ptr %42, i32 0, i32 2
  %44 = load i32, ptr %43, align 4, !tbaa !15
  %45 = add i32 %44, 1
  store i32 %45, ptr %43, align 4, !tbaa !15
  br label %29, !llvm.loop !16

46:                                               ; preds = %29
  %47 = load ptr, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret ptr %47
}

; 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: nounwind
declare float @sqrtf(float noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.floor.f32(float) #4

; 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 "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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { 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 = !{!"int", !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 = !{!"interleaver_s", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!13 = !{!12, !6, i64 12}
!14 = !{!12, !6, i64 4}
!15 = !{!12, !6, i64 8}
!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"

; Function Attrs: nofree nounwind memory(write, argmem: none, inaccessiblemem: readwrite) uwtable
define dso_local noalias noundef ptr @interleaver_create(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 12
  store i32 4, ptr %3, align 4, !tbaa !10
  %4 = uitofp i32 %0 to float
  %sqrt = tail call float @llvm.sqrt.f32(float %4)
  %5 = tail call float @llvm.floor.f32(float %sqrt)
  %6 = fptoui float %5 to i32
  %7 = add i32 %6, 1
  %8 = getelementptr inbounds i8, ptr %2, i64 4
  store i32 %7, ptr %8, align 4, !tbaa !11
  %9 = udiv i32 %0, %7
  br label %10

10:                                               ; preds = %10, %1
  %storemerge = phi i32 [ %9, %1 ], [ %12, %10 ]
  %11 = mul i32 %storemerge, %7
  %.not = icmp ugt i32 %11, %0
  %12 = add i32 %storemerge, 1
  br i1 %.not, label %13, label %10, !llvm.loop !12

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %2, i64 8
  store i32 %storemerge, ptr %14, align 4, !tbaa !14
  ret ptr %2
}

; 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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.floor.f32(float) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.sqrt.f32(float) #3

attributes #0 = { nofree nounwind memory(write, argmem: none, 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 0}
!6 = !{!"interleaver_s", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 12}
!11 = !{!6, !7, i64 4}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!6, !7, i64 8}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass