; LLVM IR from tensorflow/tflite-micro :: tensorflow/lite/experimental/microfrontend/lib (window_util)

; 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.WindowConfig = type { i64, i64 }
%struct.WindowState = type { i64, ptr, i64, ptr, i64, ptr, i16 }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [34 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @WindowPopulateState(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca float, align 4
  %9 = alloca i64, align 8
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.WindowConfig, ptr %12, i32 0, i32 0
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = mul i64 %14, %16
  %18 = udiv i64 %17, 1000
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.WindowState, ptr %19, i32 0, i32 0
  store i64 %18, ptr %20, align 8, !tbaa !14
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.WindowConfig, ptr %21, i32 0, i32 1
  %23 = load i64, ptr %22, align 8, !tbaa !17
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = mul i64 %23, %25
  %27 = udiv i64 %26, 1000
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.WindowState, ptr %28, i32 0, i32 2
  store i64 %27, ptr %29, align 8, !tbaa !18
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.WindowState, ptr %30, i32 0, i32 0
  %32 = load i64, ptr %31, align 8, !tbaa !14
  %33 = mul i64 %32, 2
  %34 = call noalias ptr @malloc(i64 noundef %33) #5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.WindowState, ptr %35, i32 0, i32 1
  store ptr %34, ptr %36, align 8, !tbaa !19
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.WindowState, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !19
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %44

41:                                               ; preds = %3
  %42 = load ptr, ptr @stderr, align 8, !tbaa !5
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef @.str) #6
  store i32 0, ptr %4, align 4
  br label %110

44:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.WindowState, ptr %45, i32 0, i32 0
  %47 = load i64, ptr %46, align 8, !tbaa !14
  %48 = uitofp i64 %47 to float
  %49 = fdiv float 0x401921FB60000000, %48
  store float %49, ptr %8, align 4, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  store i64 0, ptr %9, align 8, !tbaa !22
  br label %50

50:                                               ; preds = %73, %44
  %51 = load i64, ptr %9, align 8, !tbaa !22
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.WindowState, ptr %52, i32 0, i32 0
  %54 = load i64, ptr %53, align 8, !tbaa !14
  %55 = icmp ult i64 %51, %54
  br i1 %55, label %56, label %76

56:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %57 = load float, ptr %8, align 4, !tbaa !20
  %58 = load i64, ptr %9, align 8, !tbaa !22
  %59 = uitofp i64 %58 to float
  %60 = fadd float %59, 5.000000e-01
  %61 = fmul float %57, %60
  %62 = call float @cosf(float noundef %61) #6
  %63 = call float @llvm.fmuladd.f32(float -5.000000e-01, float %62, float 5.000000e-01)
  store float %63, ptr %10, align 4, !tbaa !20
  %64 = load float, ptr %10, align 4, !tbaa !20
  %65 = call float @llvm.fmuladd.f32(float %64, float 4.096000e+03, float 5.000000e-01)
  %66 = call float @llvm.floor.f32(float %65)
  %67 = fptosi float %66 to i16
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.WindowState, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !19
  %71 = load i64, ptr %9, align 8, !tbaa !22
  %72 = getelementptr inbounds i16, ptr %70, i64 %71
  store i16 %67, ptr %72, align 2, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %73

73:                                               ; preds = %56
  %74 = load i64, ptr %9, align 8, !tbaa !22
  %75 = add i64 %74, 1
  store i64 %75, ptr %9, align 8, !tbaa !22
  br label %50, !llvm.loop !24

76:                                               ; preds = %50
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.WindowState, ptr %77, i32 0, i32 4
  store i64 0, ptr %78, align 8, !tbaa !26
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.WindowState, ptr %79, i32 0, i32 0
  %81 = load i64, ptr %80, align 8, !tbaa !14
  %82 = mul i64 %81, 2
  %83 = call noalias ptr @malloc(i64 noundef %82) #5
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.WindowState, ptr %84, i32 0, i32 3
  store ptr %83, ptr %85, align 8, !tbaa !27
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.WindowState, ptr %86, i32 0, i32 3
  %88 = load ptr, ptr %87, align 8, !tbaa !27
  %89 = icmp eq ptr %88, null
  br i1 %89, label %90, label %93

90:                                               ; preds = %76
  %91 = load ptr, ptr @stderr, align 8, !tbaa !5
  %92 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %91, ptr noundef @.str.1) #6
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %109

93:                                               ; preds = %76
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.WindowState, ptr %94, i32 0, i32 0
  %96 = load i64, ptr %95, align 8, !tbaa !14
  %97 = mul i64 %96, 2
  %98 = call noalias ptr @malloc(i64 noundef %97) #5
  %99 = load ptr, ptr %6, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.WindowState, ptr %99, i32 0, i32 5
  store ptr %98, ptr %100, align 8, !tbaa !28
  %101 = load ptr, ptr %6, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.WindowState, ptr %101, i32 0, i32 5
  %103 = load ptr, ptr %102, align 8, !tbaa !28
  %104 = icmp eq ptr %103, null
  br i1 %104, label %105, label %108

105:                                              ; preds = %93
  %106 = load ptr, ptr @stderr, align 8, !tbaa !5
  %107 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %106, ptr noundef @.str.2) #6
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %109

108:                                              ; preds = %93
  store i32 1, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %109

109:                                              ; preds = %108, %105, %90
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %110

110:                                              ; preds = %109, %41
  %111 = load i32, ptr %4, align 4
  ret i32 %111
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

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

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

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

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

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 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind allocsize(0) }
attributes #6 = { 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, !13, i64 0}
!12 = !{!"WindowConfig", !13, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"WindowState", !13, i64 0, !6, i64 8, !13, i64 16, !6, i64 24, !13, i64 32, !6, i64 40, !16, i64 48}
!16 = !{!"short", !7, i64 0}
!17 = !{!12, !13, i64 8}
!18 = !{!15, !13, i64 16}
!19 = !{!15, !6, i64 8}
!20 = !{!21, !21, i64 0}
!21 = !{!"float", !7, i64 0}
!22 = !{!13, !13, i64 0}
!23 = !{!16, !16, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!15, !13, i64 32}
!27 = !{!15, !6, i64 24}
!28 = !{!15, !6, i64 40}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [34 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local range(i32 0, 2) i32 @WindowPopulateState(ptr nocapture noundef readonly %0, ptr nocapture noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load i64, ptr %0, align 8, !tbaa !5
  %5 = sext i32 %2 to i64
  %6 = mul i64 %4, %5
  %7 = udiv i64 %6, 1000
  store i64 %7, ptr %1, align 8, !tbaa !10
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !14
  %10 = mul i64 %9, %5
  %11 = udiv i64 %10, 1000
  %12 = getelementptr inbounds i8, ptr %1, i64 16
  store i64 %11, ptr %12, align 8, !tbaa !15
  %13 = shl nuw nsw i64 %7, 1
  %14 = tail call noalias ptr @malloc(i64 noundef %13) #5
  %15 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr %14, ptr %15, align 8, !tbaa !16
  %16 = icmp eq ptr %14, null
  br i1 %16, label %.sink.split, label %17

17:                                               ; preds = %3
  %18 = uitofp nneg i64 %7 to float
  %19 = fdiv float 0x401921FB60000000, %18
  %.not = icmp ult i64 %6, 1000
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %17, %.lr.ph
  %.02526 = phi i64 [ %30, %.lr.ph ], [ 0, %17 ]
  %20 = uitofp i64 %.02526 to float
  %21 = fadd float %20, 5.000000e-01
  %22 = fmul float %19, %21
  %23 = tail call float @cosf(float noundef %22) #6
  %24 = tail call float @llvm.fmuladd.f32(float %23, float -5.000000e-01, float 5.000000e-01)
  %25 = tail call float @llvm.fmuladd.f32(float %24, float 4.096000e+03, float 5.000000e-01)
  %26 = tail call float @llvm.floor.f32(float %25)
  %27 = fptosi float %26 to i16
  %28 = load ptr, ptr %15, align 8, !tbaa !16
  %29 = getelementptr inbounds i16, ptr %28, i64 %.02526
  store i16 %27, ptr %29, align 2, !tbaa !17
  %30 = add nuw i64 %.02526, 1
  %31 = load i64, ptr %1, align 8, !tbaa !10
  %32 = icmp ult i64 %30, %31
  br i1 %32, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !18

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %33 = shl i64 %31, 1
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %17
  %.lcssa = phi i64 [ 0, %17 ], [ %33, %._crit_edge.loopexit ]
  %34 = getelementptr inbounds i8, ptr %1, i64 32
  store i64 0, ptr %34, align 8, !tbaa !20
  %35 = tail call noalias ptr @malloc(i64 noundef %.lcssa) #5
  %36 = getelementptr inbounds i8, ptr %1, i64 24
  store ptr %35, ptr %36, align 8, !tbaa !21
  %37 = icmp eq ptr %35, null
  br i1 %37, label %.sink.split, label %38

38:                                               ; preds = %._crit_edge
  %39 = tail call noalias ptr @malloc(i64 noundef %.lcssa) #5
  %40 = getelementptr inbounds i8, ptr %1, i64 40
  store ptr %39, ptr %40, align 8, !tbaa !22
  %41 = icmp eq ptr %39, null
  br i1 %41, label %.sink.split, label %44

.sink.split:                                      ; preds = %38, %._crit_edge, %3
  %.str.1.sink = phi ptr [ @.str, %3 ], [ @.str.1, %._crit_edge ], [ @.str.2, %38 ]
  %42 = load ptr, ptr @stderr, align 8, !tbaa !23
  %43 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef nonnull %.str.1.sink) #7
  br label %44

44:                                               ; preds = %.sink.split, %38
  %.1 = phi i32 [ 1, %38 ], [ 0, %.sink.split ]
  ret i32 %.1
}

; 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: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

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

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

attributes #0 = { nofree 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 = { 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 = { nofree 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 = { 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 #4 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind allocsize(0) }
attributes #6 = { nounwind }
attributes #7 = { cold 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 = !{!"WindowConfig", !7, i64 0, !7, i64 8}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 0}
!11 = !{!"WindowState", !7, i64 0, !12, i64 8, !7, i64 16, !12, i64 24, !7, i64 32, !12, i64 40, !13, i64 48}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"short", !8, i64 0}
!14 = !{!6, !7, i64 8}
!15 = !{!11, !7, i64 16}
!16 = !{!11, !12, i64 8}
!17 = !{!13, !13, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!11, !7, i64 32}
!21 = !{!11, !12, i64 24}
!22 = !{!11, !12, i64 40}
!23 = !{!12, !12, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass