; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare ptr @window_construct_zero(i32 noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @windowing_roothann(i32 noundef %0) #3 {
  %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 %44

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

15:                                               ; preds = %40, %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 %43

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 = call float @sqrtf(float noundef %32) #4
  %34 = load ptr, ptr %3, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.window_obj, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds float, ptr %36, i64 %38
  store float %33, ptr %39, align 4, !tbaa !13
  br label %40

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

43:                                               ; preds = %15
  br label %44

44:                                               ; preds = %43, %9
  %45 = 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 %45
}

; Function Attrs: nounwind
declare float @sqrtf(float noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { 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 #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"

declare ptr @window_construct_zero(i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local ptr @windowing_roothann(i32 noundef %0) local_unnamed_addr #2 {
  %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 = tail call float @sqrtf(float noundef %19) #3
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds float, ptr %21, i64 %indvars.iv
  store float %20, ptr %22, align 4, !tbaa !11
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %23 = trunc nuw i64 %indvars.iv.next to i32
  %24 = uitofp i32 %23 to float
  %25 = fpext float %24 to double
  %26 = fmul double %25, 0x401921FB54442D18
  %27 = fdiv double %26, %5
  %28 = fptrunc double %27 to float
  %29 = tail call float @cosf(float noundef %28) #3
  %30 = fsub float 1.000000e+00, %29
  %31 = fmul float %30, 5.000000e-01
  %32 = tail call float @sqrtf(float noundef %31) #3
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds float, ptr %33, i64 %indvars.iv.next
  store float %32, ptr %34, 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
  %35 = trunc nuw i64 %indvars.iv.next.1 to i32
  %36 = uitofp i32 %35 to float
  %37 = fpext float %36 to double
  %38 = fmul double %37, 0x401921FB54442D18
  %39 = fdiv double %38, %5
  %40 = fptrunc double %39 to float
  %41 = tail call float @cosf(float noundef %40) #3
  %42 = fsub float 1.000000e+00, %41
  %43 = fmul float %42, 5.000000e-01
  %44 = tail call float @sqrtf(float noundef %43) #3
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds float, ptr %45, i64 %indvars.iv.next.1
  store float %44, ptr %46, align 4, !tbaa !11
  br label %.loopexit

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

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

attributes #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 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 #2 = { 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 #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