; LLVM IR from jgaeddert/liquid-dsp :: src/nco/src/nco.utilities (liquid_unwrap_phase)

; 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 void @liquid_unwrap_phase(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %55, %2
  %7 = load i32, ptr %5, align 4, !tbaa !9
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = icmp ult i32 %7, %8
  br i1 %9, label %10, label %58

10:                                               ; preds = %6
  br label %11

11:                                               ; preds = %25, %10
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = zext i32 %13 to i64
  %15 = getelementptr inbounds float, ptr %12, i64 %14
  %16 = load float, ptr %15, align 4, !tbaa !11
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = sub i32 %18, 1
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds float, ptr %17, i64 %20
  %22 = load float, ptr %21, align 4, !tbaa !11
  %23 = fsub float %16, %22
  %24 = fcmp ogt float %23, 0x400921FB60000000
  br i1 %24, label %25, label %32

25:                                               ; preds = %11
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds float, ptr %26, i64 %28
  %30 = load float, ptr %29, align 4, !tbaa !11
  %31 = fsub float %30, 0x401921FB60000000
  store float %31, ptr %29, align 4, !tbaa !11
  br label %11, !llvm.loop !13

32:                                               ; preds = %11
  br label %33

33:                                               ; preds = %47, %32
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds float, ptr %34, i64 %36
  %38 = load float, ptr %37, align 4, !tbaa !11
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = sub i32 %40, 1
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds float, ptr %39, i64 %42
  %44 = load float, ptr %43, align 4, !tbaa !11
  %45 = fsub float %38, %44
  %46 = fcmp olt float %45, 0xC00921FB60000000
  br i1 %46, label %47, label %54

47:                                               ; preds = %33
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds float, ptr %48, i64 %50
  %52 = load float, ptr %51, align 4, !tbaa !11
  %53 = fadd float %52, 0x401921FB60000000
  store float %53, ptr %51, align 4, !tbaa !11
  br label %33, !llvm.loop !15

54:                                               ; preds = %33
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %5, align 4, !tbaa !9
  %57 = add i32 %56, 1
  store i32 %57, ptr %5, align 4, !tbaa !9
  br label %6, !llvm.loop !16

58:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

; 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

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 }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; 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 norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @liquid_unwrap_phase(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp ugt i32 %1, 1
  br i1 %3, label %.preheader14.preheader, label %._crit_edge20

.preheader14.preheader:                           ; preds = %2
  %wide.trip.count = zext i32 %1 to i64
  %.pre = load float, ptr %0, align 4, !tbaa !5
  %invariant.gep = getelementptr i8, ptr %0, i64 -4
  br label %.preheader14

.preheader14:                                     ; preds = %.preheader14.preheader, %._crit_edge
  %4 = phi float [ %.pre, %.preheader14.preheader ], [ %20, %._crit_edge ]
  %indvars.iv = phi i64 [ 1, %.preheader14.preheader ], [ %indvars.iv.next, %._crit_edge ]
  %5 = getelementptr inbounds float, ptr %0, i64 %indvars.iv
  %gep = getelementptr float, ptr %invariant.gep, i64 %indvars.iv
  %.promoted = load float, ptr %5, align 4, !tbaa !5
  %6 = fsub float %.promoted, %4
  %7 = fcmp ogt float %6, 0x400921FB60000000
  br i1 %7, label %.lr.ph, label %.preheader

..preheader_crit_edge:                            ; preds = %.lr.ph
  store float %13, ptr %5, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %..preheader_crit_edge, %.preheader14
  %8 = phi float [ %13, %..preheader_crit_edge ], [ %.promoted, %.preheader14 ]
  %9 = load float, ptr %gep, align 4, !tbaa !5
  %10 = fsub float %8, %9
  %11 = fcmp olt float %10, 0xC00921FB60000000
  br i1 %11, label %.lr.ph18, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader14, %.lr.ph
  %12 = phi float [ %13, %.lr.ph ], [ %.promoted, %.preheader14 ]
  %13 = fadd float %12, 0xC01921FB60000000
  %14 = fsub float %13, %4
  %15 = fcmp ogt float %14, 0x400921FB60000000
  br i1 %15, label %.lr.ph, label %..preheader_crit_edge, !llvm.loop !9

.lr.ph18:                                         ; preds = %.preheader, %.lr.ph18
  %16 = phi float [ %17, %.lr.ph18 ], [ %8, %.preheader ]
  %17 = fadd float %16, 0x401921FB60000000
  %18 = fsub float %17, %9
  %19 = fcmp olt float %18, 0xC00921FB60000000
  br i1 %19, label %.lr.ph18, label %._crit_edge.loopexit, !llvm.loop !11

._crit_edge.loopexit:                             ; preds = %.lr.ph18
  store float %17, ptr %5, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %20 = phi float [ %8, %.preheader ], [ %17, %._crit_edge.loopexit ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge20, label %.preheader14, !llvm.loop !12

._crit_edge20:                                    ; preds = %._crit_edge, %2
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: 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" }

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass