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

; 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 i64 @k2c_sub2idx(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %43, %3
  %13 = load i64, ptr %9, align 8, !tbaa !9
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = icmp ult i64 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %46

17:                                               ; preds = %12
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = load i64, ptr %9, align 8, !tbaa !9
  %20 = getelementptr inbounds i64, ptr %18, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !9
  store i64 %21, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %22 = load i64, ptr %6, align 8, !tbaa !9
  %23 = sub i64 %22, 1
  store i64 %23, ptr %11, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %36, %17
  %25 = load i64, ptr %11, align 8, !tbaa !9
  %26 = load i64, ptr %9, align 8, !tbaa !9
  %27 = icmp ugt i64 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %39

29:                                               ; preds = %24
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i64, ptr %11, align 8, !tbaa !9
  %32 = getelementptr inbounds i64, ptr %30, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = load i64, ptr %8, align 8, !tbaa !9
  %35 = mul i64 %34, %33
  store i64 %35, ptr %8, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %29
  %37 = load i64, ptr %11, align 8, !tbaa !9
  %38 = add i64 %37, -1
  store i64 %38, ptr %11, align 8, !tbaa !9
  br label %24, !llvm.loop !11

39:                                               ; preds = %28
  %40 = load i64, ptr %8, align 8, !tbaa !9
  %41 = load i64, ptr %7, align 8, !tbaa !9
  %42 = add i64 %41, %40
  store i64 %42, ptr %7, align 8, !tbaa !9
  br label %43

43:                                               ; preds = %39
  %44 = load i64, ptr %9, align 8, !tbaa !9
  %45 = add i64 %44, 1
  store i64 %45, ptr %9, align 8, !tbaa !9
  br label %12, !llvm.loop !13

46:                                               ; preds = %16
  %47 = load i64, ptr %7, align 8, !tbaa !9
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i64 %47
}

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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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(argmem: read) uwtable
define dso_local i64 @k2c_sub2idx(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i64 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %._crit_edge25, label %.lr.ph24

.lr.ph24:                                         ; preds = %3
  %.018 = add i64 %2, -1
  %xtraiter = and i64 %2, 1
  %4 = icmp eq i64 %.018, 0
  br i1 %4, label %._crit_edge25.loopexit.unr-lcssa, label %.lr.ph24.new

.lr.ph24.new:                                     ; preds = %.lr.ph24
  %unroll_iter = and i64 %2, -2
  br label %13

._crit_edge25.loopexit.unr-lcssa:                 ; preds = %._crit_edge.1, %.lr.ph24
  %.lcssa30.ph = phi i64 [ poison, %.lr.ph24 ], [ %26, %._crit_edge.1 ]
  %.01422.unr = phi i64 [ 0, %.lr.ph24 ], [ %27, %._crit_edge.1 ]
  %.01621.unr = phi i64 [ 0, %.lr.ph24 ], [ %26, %._crit_edge.1 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge25, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge25.loopexit.unr-lcssa
  %5 = getelementptr inbounds i64, ptr %0, i64 %.01422.unr
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = icmp ugt i64 %.018, %.01422.unr
  br i1 %7, label %.lr.ph.epil, label %._crit_edge.epil

.lr.ph.epil:                                      ; preds = %.epil.preheader, %.lr.ph.epil
  %.020.epil = phi i64 [ %.0.epil, %.lr.ph.epil ], [ %.018, %.epil.preheader ]
  %.01519.epil = phi i64 [ %10, %.lr.ph.epil ], [ %6, %.epil.preheader ]
  %8 = getelementptr inbounds i64, ptr %1, i64 %.020.epil
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = mul i64 %9, %.01519.epil
  %.0.epil = add i64 %.020.epil, -1
  %11 = icmp ugt i64 %.0.epil, %.01422.unr
  br i1 %11, label %.lr.ph.epil, label %._crit_edge.epil, !llvm.loop !9

._crit_edge.epil:                                 ; preds = %.lr.ph.epil, %.epil.preheader
  %.015.lcssa.epil = phi i64 [ %6, %.epil.preheader ], [ %10, %.lr.ph.epil ]
  %12 = add i64 %.015.lcssa.epil, %.01621.unr
  br label %._crit_edge25

._crit_edge25:                                    ; preds = %._crit_edge.epil, %._crit_edge25.loopexit.unr-lcssa, %3
  %.016.lcssa = phi i64 [ 0, %3 ], [ %.lcssa30.ph, %._crit_edge25.loopexit.unr-lcssa ], [ %12, %._crit_edge.epil ]
  ret i64 %.016.lcssa

13:                                               ; preds = %._crit_edge.1, %.lr.ph24.new
  %.01422 = phi i64 [ 0, %.lr.ph24.new ], [ %27, %._crit_edge.1 ]
  %.01621 = phi i64 [ 0, %.lr.ph24.new ], [ %26, %._crit_edge.1 ]
  %niter = phi i64 [ 0, %.lr.ph24.new ], [ %niter.next.1, %._crit_edge.1 ]
  %14 = getelementptr inbounds i64, ptr %0, i64 %.01422
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = icmp ugt i64 %.018, %.01422
  br i1 %16, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %13
  %.015.lcssa = phi i64 [ %15, %13 ], [ %30, %.lr.ph ]
  %17 = add i64 %.015.lcssa, %.01621
  %18 = or disjoint i64 %.01422, 1
  %19 = getelementptr inbounds i64, ptr %0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = icmp ugt i64 %.018, %18
  br i1 %21, label %.lr.ph.1, label %._crit_edge.1

.lr.ph.1:                                         ; preds = %._crit_edge, %.lr.ph.1
  %.020.1 = phi i64 [ %.0.1, %.lr.ph.1 ], [ %.018, %._crit_edge ]
  %.01519.1 = phi i64 [ %24, %.lr.ph.1 ], [ %20, %._crit_edge ]
  %22 = getelementptr inbounds i64, ptr %1, i64 %.020.1
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = mul i64 %23, %.01519.1
  %.0.1 = add i64 %.020.1, -1
  %25 = icmp ugt i64 %.0.1, %18
  br i1 %25, label %.lr.ph.1, label %._crit_edge.1, !llvm.loop !9

._crit_edge.1:                                    ; preds = %.lr.ph.1, %._crit_edge
  %.015.lcssa.1 = phi i64 [ %20, %._crit_edge ], [ %24, %.lr.ph.1 ]
  %26 = add i64 %.015.lcssa.1, %17
  %27 = add nuw i64 %.01422, 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 %._crit_edge25.loopexit.unr-lcssa, label %13, !llvm.loop !11

.lr.ph:                                           ; preds = %13, %.lr.ph
  %.020 = phi i64 [ %.0, %.lr.ph ], [ %.018, %13 ]
  %.01519 = phi i64 [ %30, %.lr.ph ], [ %15, %13 ]
  %28 = getelementptr inbounds i64, ptr %1, i64 %.020
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = mul i64 %29, %.01519
  %.0 = add i64 %.020, -1
  %31 = icmp ugt i64 %.0, %.01422
  br i1 %31, label %.lr.ph, label %._crit_edge, !llvm.loop !9
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: read) 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, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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