; LLVM IR from introlab/odas :: src/init (windowing)

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

; Function Attrs: nounwind uwtable
define dso_local ptr @windowing_hann(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = call ptr @window_construct_zero(i32 noundef %5)
  store ptr %6, ptr %3, align 8, !tbaa !9
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %9, label %14

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.window_obj, ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds float, ptr %12, i64 0
  store float 1.000000e+00, ptr %13, align 4, !tbaa !13
  br label %43

14:                                               ; preds = %1
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %39, %14
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = icmp ult i32 %16, %17
  br i1 %18, label %19, label %42

19:                                               ; preds = %15
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = uitofp i32 %20 to float
  %22 = fpext float %21 to double
  %23 = fmul double 0x401921FB54442D18, %22
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sub i32 %24, 1
  %26 = uitofp i32 %25 to float
  %27 = fpext float %26 to double
  %28 = fdiv double %23, %27
  %29 = fptrunc double %28 to float
  %30 = call float @cosf(float noundef %29) #4
  %31 = fsub float 1.000000e+00, %30
  %32 = fmul float 5.000000e-01, %31
  %33 = load ptr, ptr %3, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.window_obj, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds float, ptr %35, i64 %37
  store float %32, ptr %38, align 4, !tbaa !13
  br label %39

39:                                               ; preds = %19
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = add i32 %40, 1
  store i32 %41, ptr %4, align 4, !tbaa !5
  br label %15, !llvm.loop !15

42:                                               ; preds = %15
  br label %43

43:                                               ; preds = %42, %9
  %44 = load ptr, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret ptr %44
}

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

declare ptr @window_construct_zero(i32 noundef) #2

; Function Attrs: nounwind
declare float @cosf(float noundef) #3

; 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 = { "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 = { 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 = !{!"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, !10, i64 8}
!12 = !{!"window_obj", !6, i64 0, !10, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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: nounwind uwtable
define dso_local ptr @windowing_hann(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @window_construct_zero(i32 noundef %0) #3
  switch i32 %0, label %.lr.ph [
    i32 1, label %7
    i32 0, label %.loopexit
  ]

.lr.ph:                                           ; preds = %1
  %3 = add i32 %0, -1
  %4 = uitofp i32 %3 to float
  %5 = fpext float %4 to double
  %6 = getelementptr inbounds i8, ptr %2, i64 8
  %wide.trip.count = zext i32 %0 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %unroll_iter = and i64 %wide.trip.count, 4294967294
  br label %10

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %2, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  store float 1.000000e+00, ptr %9, align 4, !tbaa !11
  br label %.loopexit

10:                                               ; preds = %10, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %10 ]
  %niter = phi i64 [ 0, %.lr.ph ], [ %niter.next.1, %10 ]
  %11 = trunc nuw i64 %indvars.iv to i32
  %12 = uitofp i32 %11 to float
  %13 = fpext float %12 to double
  %14 = fmul double %13, 0x401921FB54442D18
  %15 = fdiv double %14, %5
  %16 = fptrunc double %15 to float
  %17 = tail call float @cosf(float noundef %16) #3
  %18 = fsub float 1.000000e+00, %17
  %19 = fmul float %18, 5.000000e-01
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds float, ptr %20, i64 %indvars.iv
  store float %19, ptr %21, align 4, !tbaa !11
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %22 = trunc nuw i64 %indvars.iv.next to i32
  %23 = uitofp i32 %22 to float
  %24 = fpext float %23 to double
  %25 = fmul double %24, 0x401921FB54442D18
  %26 = fdiv double %25, %5
  %27 = fptrunc double %26 to float
  %28 = tail call float @cosf(float noundef %27) #3
  %29 = fsub float 1.000000e+00, %28
  %30 = fmul float %29, 5.000000e-01
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds float, ptr %31, i64 %indvars.iv.next
  store float %30, ptr %32, align 4, !tbaa !11
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %10, !llvm.loop !13

.loopexit.loopexit.unr-lcssa:                     ; preds = %10
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.loopexit.loopexit.epilog-lcssa

.loopexit.loopexit.epilog-lcssa:                  ; preds = %.loopexit.loopexit.unr-lcssa
  %33 = trunc nuw i64 %indvars.iv.next.1 to i32
  %34 = uitofp i32 %33 to float
  %35 = fpext float %34 to double
  %36 = fmul double %35, 0x401921FB54442D18
  %37 = fdiv double %36, %5
  %38 = fptrunc double %37 to float
  %39 = tail call float @cosf(float noundef %38) #3
  %40 = fsub float 1.000000e+00, %39
  %41 = fmul float %40, 5.000000e-01
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds float, ptr %42, i64 %indvars.iv.next.1
  store float %41, ptr %43, align 4, !tbaa !11
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.epilog-lcssa, %.loopexit.loopexit.unr-lcssa, %1, %7
  ret ptr %2
}

declare ptr @window_construct_zero(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @cosf(float noundef) local_unnamed_addr #2

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 = { "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 nofree nounwind willreturn memory(write) "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, !10, i64 8}
!6 = !{!"window_obj", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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