; LLVM IR from mrbid/CSGO_TENSOR_TRIGGER :: GOBOT15/KERAS2C/include (k2c_pooling_layers)

; 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.k2c_tensor = type { ptr, i64, i64, [5 x i64] }

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

; 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 void @k2c_global_avg_pooling(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca float, align 4
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.k2c_tensor, ptr %10, i32 0, i32 3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.k2c_tensor, ptr %12, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = sub i64 %14, 1
  %16 = getelementptr inbounds [5 x i64], ptr %11, i64 0, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !12
  store i64 %17, ptr %5, align 8, !tbaa !12
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.k2c_tensor, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.k2c_tensor, ptr %21, i32 0, i32 2
  %23 = load i64, ptr %22, align 8, !tbaa !14
  %24 = mul i64 %23, 4
  call void @llvm.memset.p0.i64(ptr align 4 %20, i8 0, i64 %24, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.k2c_tensor, ptr %25, i32 0, i32 2
  %27 = load i64, ptr %26, align 8, !tbaa !14
  %28 = load i64, ptr %5, align 8, !tbaa !12
  %29 = udiv i64 %27, %28
  %30 = uitofp i64 %29 to float
  %31 = fdiv float 1.000000e+00, %30
  store float %31, ptr %6, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !12
  br label %32

32:                                               ; preds = %66, %2
  %33 = load i64, ptr %7, align 8, !tbaa !12
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.k2c_tensor, ptr %34, i32 0, i32 2
  %36 = load i64, ptr %35, align 8, !tbaa !14
  %37 = icmp ult i64 %33, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %32
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %70

39:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %9, align 8, !tbaa !12
  br label %40

40:                                               ; preds = %62, %39
  %41 = load i64, ptr %9, align 8, !tbaa !12
  %42 = load i64, ptr %5, align 8, !tbaa !12
  %43 = icmp ult i64 %41, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %40
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %65

45:                                               ; preds = %40
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.k2c_tensor, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = load i64, ptr %7, align 8, !tbaa !12
  %50 = load i64, ptr %9, align 8, !tbaa !12
  %51 = add i64 %49, %50
  %52 = getelementptr inbounds float, ptr %48, i64 %51
  %53 = load float, ptr %52, align 4, !tbaa !15
  %54 = load float, ptr %6, align 4, !tbaa !15
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.k2c_tensor, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !13
  %58 = load i64, ptr %9, align 8, !tbaa !12
  %59 = getelementptr inbounds float, ptr %57, i64 %58
  %60 = load float, ptr %59, align 4, !tbaa !15
  %61 = call float @llvm.fmuladd.f32(float %53, float %54, float %60)
  store float %61, ptr %59, align 4, !tbaa !15
  br label %62

62:                                               ; preds = %45
  %63 = load i64, ptr %9, align 8, !tbaa !12
  %64 = add i64 %63, 1
  store i64 %64, ptr %9, align 8, !tbaa !12
  br label %40, !llvm.loop !17

65:                                               ; preds = %44
  br label %66

66:                                               ; preds = %65
  %67 = load i64, ptr %5, align 8, !tbaa !12
  %68 = load i64, ptr %7, align 8, !tbaa !12
  %69 = add i64 %68, %67
  store i64 %69, ptr %7, align 8, !tbaa !12
  br label %32, !llvm.loop !19

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"k2c_tensor", !6, i64 0, !11, i64 8, !11, i64 16, !7, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 0}
!14 = !{!10, !11, i64 16}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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(readwrite, inaccessiblemem: none) uwtable
define dso_local void @k2c_global_avg_pooling(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 24
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = add i64 %5, -1
  %7 = getelementptr inbounds [5 x i64], ptr %3, i64 0, i64 %6
  %8 = load i64, ptr %7, align 8, !tbaa !11
  %9 = load ptr, ptr %0, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load i64, ptr %10, align 8, !tbaa !13
  %12 = shl i64 %11, 2
  tail call void @llvm.memset.p0.i64(ptr align 4 %9, i8 0, i64 %12, i1 false)
  %13 = getelementptr inbounds i8, ptr %1, i64 16
  %14 = load i64, ptr %13, align 8, !tbaa !13
  %15 = udiv i64 %14, %8
  %16 = uitofp i64 %15 to float
  %17 = fdiv float 1.000000e+00, %16
  %.not = icmp eq i64 %14, 0
  br i1 %.not, label %._crit_edge, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %2
  %18 = load ptr, ptr %1, align 8, !tbaa !12
  %19 = load ptr, ptr %0, align 8, !tbaa !12
  %umax = tail call i64 @llvm.umax.i64(i64 %8, i64 1)
  %20 = shl i64 %umax, 2
  %scevgep = getelementptr i8, ptr %19, i64 %20
  %21 = shl i64 %8, 2
  %min.iters.check = icmp ult i64 %8, 8
  %22 = getelementptr i8, ptr %18, i64 %20
  %n.vec = and i64 %umax, -8
  %broadcast.splatinsert = insertelement <4 x float> poison, float %17, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  %cmp.n = icmp eq i64 %8, %n.vec
  %xtraiter = and i64 %umax, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %.loopexit
  %indvar = phi i64 [ 0, %.preheader.lr.ph ], [ %indvar.next, %.loopexit ]
  %.01821 = phi i64 [ 0, %.preheader.lr.ph ], [ %39, %.loopexit ]
  %23 = getelementptr float, ptr %18, i64 %.01821
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.preheader
  %.020.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.preheader ], [ %n.vec, %middle.block ]
  %.neg = or disjoint i64 %.020.ph, 1
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %24 = getelementptr float, ptr %23, i64 %.020.ph
  %25 = load float, ptr %24, align 4, !tbaa !14
  %26 = getelementptr inbounds float, ptr %19, i64 %.020.ph
  %27 = load float, ptr %26, align 4, !tbaa !14
  %28 = tail call float @llvm.fmuladd.f32(float %25, float %17, float %27)
  store float %28, ptr %26, align 4, !tbaa !14
  %29 = or disjoint i64 %.020.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.020.unr = phi i64 [ %.020.ph, %scalar.ph.preheader ], [ %29, %scalar.ph.prol ]
  %30 = icmp eq i64 %umax, %.neg
  br i1 %30, label %.loopexit, label %scalar.ph

vector.memcheck:                                  ; preds = %.preheader
  %31 = mul i64 %21, %indvar
  %scevgep23 = getelementptr i8, ptr %22, i64 %31
  %scevgep22 = getelementptr i8, ptr %18, i64 %31
  %bound0 = icmp ult ptr %19, %scevgep23
  %bound1 = icmp ult ptr %scevgep22, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %vector.memcheck, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %vector.memcheck ]
  %32 = getelementptr float, ptr %23, i64 %index
  %33 = getelementptr i8, ptr %32, i64 16
  %wide.load = load <4 x float>, ptr %32, align 4, !tbaa !14, !alias.scope !16
  %wide.load24 = load <4 x float>, ptr %33, align 4, !tbaa !14, !alias.scope !16
  %34 = getelementptr inbounds float, ptr %19, i64 %index
  %35 = getelementptr inbounds i8, ptr %34, i64 16
  %wide.load25 = load <4 x float>, ptr %34, align 4, !tbaa !14, !alias.scope !19, !noalias !16
  %wide.load26 = load <4 x float>, ptr %35, align 4, !tbaa !14, !alias.scope !19, !noalias !16
  %36 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %wide.load, <4 x float> %broadcast.splat, <4 x float> %wide.load25)
  %37 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %wide.load24, <4 x float> %broadcast.splat, <4 x float> %wide.load26)
  store <4 x float> %36, ptr %34, align 4, !tbaa !14, !alias.scope !19, !noalias !16
  store <4 x float> %37, ptr %35, align 4, !tbaa !14, !alias.scope !19, !noalias !16
  %index.next = add nuw i64 %index, 8
  %38 = icmp eq i64 %index.next, %n.vec
  br i1 %38, label %middle.block, label %vector.body, !llvm.loop !21

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %.loopexit, %2
  ret void

.loopexit:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %39 = add i64 %.01821, %8
  %40 = icmp ult i64 %39, %14
  %indvar.next = add i64 %indvar, 1
  br i1 %40, label %.preheader, label %._crit_edge, !llvm.loop !25

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.020 = phi i64 [ %52, %scalar.ph ], [ %.020.unr, %scalar.ph.prol.loopexit ]
  %41 = getelementptr float, ptr %23, i64 %.020
  %42 = load float, ptr %41, align 4, !tbaa !14
  %43 = getelementptr inbounds float, ptr %19, i64 %.020
  %44 = load float, ptr %43, align 4, !tbaa !14
  %45 = tail call float @llvm.fmuladd.f32(float %42, float %17, float %44)
  store float %45, ptr %43, align 4, !tbaa !14
  %46 = add nuw i64 %.020, 1
  %47 = getelementptr float, ptr %23, i64 %46
  %48 = load float, ptr %47, align 4, !tbaa !14
  %49 = getelementptr inbounds float, ptr %19, i64 %46
  %50 = load float, ptr %49, align 4, !tbaa !14
  %51 = tail call float @llvm.fmuladd.f32(float %48, float %17, float %50)
  store float %51, ptr %49, align 4, !tbaa !14
  %52 = add nuw i64 %.020, 2
  %exitcond.not.1 = icmp eq i64 %8, %52
  br i1 %exitcond.not.1, label %.loopexit, label %scalar.ph, !llvm.loop !26
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x float> @llvm.fmuladd.v4f32(<4 x float>, <4 x float>, <4 x float>) #3

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"k2c_tensor", !7, i64 0, !10, i64 8, !10, i64 16, !8, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !10, i64 16}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !8, i64 0}
!16 = !{!17}
!17 = distinct !{!17, !18}
!18 = distinct !{!18, !"LVerDomain"}
!19 = !{!20}
!20 = distinct !{!20, !18}
!21 = distinct !{!21, !22, !23, !24}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!"llvm.loop.isvectorized", i32 1}
!24 = !{!"llvm.loop.unroll.runtime.disable"}
!25 = distinct !{!25, !22}
!26 = distinct !{!26, !22, !23}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass