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

; 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_bias_add(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = 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) #2
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %43, %2
  %9 = load i64, ptr %5, align 8, !tbaa !9
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.k2c_tensor, ptr %10, i32 0, i32 2
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = icmp ult i64 %9, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %8
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %49

15:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %39, %15
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.k2c_tensor, ptr %18, i32 0, i32 2
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = icmp ult i64 %17, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %16
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %42

23:                                               ; preds = %16
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.k2c_tensor, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %28 = getelementptr inbounds float, ptr %26, i64 %27
  %29 = load float, ptr %28, align 4, !tbaa !14
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.k2c_tensor, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = load i64, ptr %5, align 8, !tbaa !9
  %34 = load i64, ptr %7, align 8, !tbaa !9
  %35 = add i64 %33, %34
  %36 = getelementptr inbounds float, ptr %32, i64 %35
  %37 = load float, ptr %36, align 4, !tbaa !14
  %38 = fadd float %37, %29
  store float %38, ptr %36, align 4, !tbaa !14
  br label %39

39:                                               ; preds = %23
  %40 = load i64, ptr %7, align 8, !tbaa !9
  %41 = add i64 %40, 1
  store i64 %41, ptr %7, align 8, !tbaa !9
  br label %16, !llvm.loop !16

42:                                               ; preds = %22
  br label %43

43:                                               ; preds = %42
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.k2c_tensor, ptr %44, i32 0, i32 2
  %46 = load i64, ptr %45, align 8, !tbaa !11
  %47 = load i64, ptr %5, align 8, !tbaa !9
  %48 = add i64 %47, %46
  store i64 %48, ptr %5, align 8, !tbaa !9
  br label %8, !llvm.loop !18

49:                                               ; preds = %14
  ret void
}

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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"k2c_tensor", !6, i64 0, !10, i64 8, !10, i64 16, !7, i64 24}
!13 = !{!12, !6, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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_bias_add(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %._crit_edge15, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %2
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %.not16 = icmp eq i64 %6, 0
  br i1 %.not16, label %._crit_edge15, label %.preheader.lr.ph.split.us

.preheader.lr.ph.split.us:                        ; preds = %.preheader.lr.ph
  %7 = load ptr, ptr %1, align 8, !tbaa !11
  %8 = load ptr, ptr %0, align 8, !tbaa !11
  %9 = shl i64 %6, 2
  %scevgep19 = getelementptr i8, ptr %7, i64 %9
  %min.iters.check = icmp ult i64 %6, 8
  %10 = getelementptr i8, ptr %8, i64 %9
  %n.vec = and i64 %6, -8
  %cmp.n = icmp eq i64 %6, %n.vec
  %xtraiter = and i64 %6, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph.split.us
  %indvar = phi i64 [ %indvar.next, %._crit_edge.us ], [ 0, %.preheader.lr.ph.split.us ]
  %.01114.us = phi i64 [ %52, %._crit_edge.us ], [ 0, %.preheader.lr.ph.split.us ]
  %11 = getelementptr float, ptr %8, i64 %.01114.us
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.preheader.us
  %12 = mul i64 %9, %indvar
  %scevgep18 = getelementptr i8, ptr %10, i64 %12
  %scevgep = getelementptr i8, ptr %8, i64 %12
  %bound0 = icmp ult ptr %scevgep, %scevgep19
  %bound1 = icmp ult ptr %7, %scevgep18
  %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 ]
  %13 = getelementptr inbounds float, ptr %7, i64 %index
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  %wide.load = load <4 x float>, ptr %13, align 4, !tbaa !12, !alias.scope !14
  %wide.load20 = load <4 x float>, ptr %14, align 4, !tbaa !12, !alias.scope !14
  %15 = getelementptr float, ptr %11, i64 %index
  %16 = getelementptr i8, ptr %15, i64 16
  %wide.load21 = load <4 x float>, ptr %15, align 4, !tbaa !12, !alias.scope !17, !noalias !14
  %wide.load22 = load <4 x float>, ptr %16, align 4, !tbaa !12, !alias.scope !17, !noalias !14
  %17 = fadd <4 x float> %wide.load, %wide.load21
  %18 = fadd <4 x float> %wide.load20, %wide.load22
  store <4 x float> %17, ptr %15, align 4, !tbaa !12, !alias.scope !17, !noalias !14
  store <4 x float> %18, ptr %16, align 4, !tbaa !12, !alias.scope !17, !noalias !14
  %index.next = add nuw i64 %index, 8
  %19 = icmp eq i64 %index.next, %n.vec
  br i1 %19, label %middle.block, label %vector.body, !llvm.loop !19

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

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

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %.013.us.prol = phi i64 [ %25, %scalar.ph.prol ], [ %.013.us.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %20 = getelementptr inbounds float, ptr %7, i64 %.013.us.prol
  %21 = load float, ptr %20, align 4, !tbaa !12
  %22 = getelementptr float, ptr %11, i64 %.013.us.prol
  %23 = load float, ptr %22, align 4, !tbaa !12
  %24 = fadd float %21, %23
  store float %24, ptr %22, align 4, !tbaa !12
  %25 = add nuw i64 %.013.us.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !23

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.013.us.unr = phi i64 [ %.013.us.ph, %scalar.ph.preheader ], [ %25, %scalar.ph.prol ]
  %26 = sub i64 %.013.us.ph, %6
  %27 = icmp ugt i64 %26, -4
  br i1 %27, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.013.us = phi i64 [ %51, %scalar.ph ], [ %.013.us.unr, %scalar.ph.prol.loopexit ]
  %28 = getelementptr inbounds float, ptr %7, i64 %.013.us
  %29 = load float, ptr %28, align 4, !tbaa !12
  %30 = getelementptr float, ptr %11, i64 %.013.us
  %31 = load float, ptr %30, align 4, !tbaa !12
  %32 = fadd float %29, %31
  store float %32, ptr %30, align 4, !tbaa !12
  %33 = add nuw i64 %.013.us, 1
  %34 = getelementptr inbounds float, ptr %7, i64 %33
  %35 = load float, ptr %34, align 4, !tbaa !12
  %36 = getelementptr float, ptr %11, i64 %33
  %37 = load float, ptr %36, align 4, !tbaa !12
  %38 = fadd float %35, %37
  store float %38, ptr %36, align 4, !tbaa !12
  %39 = add nuw i64 %.013.us, 2
  %40 = getelementptr inbounds float, ptr %7, i64 %39
  %41 = load float, ptr %40, align 4, !tbaa !12
  %42 = getelementptr float, ptr %11, i64 %39
  %43 = load float, ptr %42, align 4, !tbaa !12
  %44 = fadd float %41, %43
  store float %44, ptr %42, align 4, !tbaa !12
  %45 = add nuw i64 %.013.us, 3
  %46 = getelementptr inbounds float, ptr %7, i64 %45
  %47 = load float, ptr %46, align 4, !tbaa !12
  %48 = getelementptr float, ptr %11, i64 %45
  %49 = load float, ptr %48, align 4, !tbaa !12
  %50 = fadd float %47, %49
  store float %50, ptr %48, align 4, !tbaa !12
  %51 = add nuw i64 %.013.us, 4
  %exitcond.not.3 = icmp eq i64 %51, %6
  br i1 %exitcond.not.3, label %._crit_edge.us, label %scalar.ph, !llvm.loop !25

._crit_edge.us:                                   ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %52 = add i64 %6, %.01114.us
  %53 = icmp ult i64 %52, %4
  %indvar.next = add i64 %indvar, 1
  br i1 %53, label %.preheader.us, label %._crit_edge15, !llvm.loop !26

._crit_edge15:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %2
  ret void
}

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

!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 16}
!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 = !{!6, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !8, i64 0}
!14 = !{!15}
!15 = distinct !{!15, !16}
!16 = distinct !{!16, !"LVerDomain"}
!17 = !{!18}
!18 = distinct !{!18, !16}
!19 = distinct !{!19, !20, !21, !22}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!"llvm.loop.isvectorized", i32 1}
!22 = !{!"llvm.loop.unroll.runtime.disable"}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.unroll.disable"}
!25 = distinct !{!25, !20, !21}
!26 = distinct !{!26, !20}


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