; LLVM IR from mrbid/CSGO_TENSOR_TRIGGER :: GOBOT15/KERAS2C/include (k2c_merge_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_subtract(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %10

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

16:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %39

17:                                               ; preds = %10
  %18 = load ptr, ptr %7, 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 i64, ptr %9, align 8, !tbaa !9
  %22 = getelementptr inbounds float, ptr %20, i64 %21
  %23 = load float, ptr %22, align 4, !tbaa !14
  %24 = load ptr, ptr %8, 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 %9, align 8, !tbaa !9
  %28 = getelementptr inbounds float, ptr %26, i64 %27
  %29 = load float, ptr %28, align 4, !tbaa !14
  %30 = fsub float %23, %29
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.k2c_tensor, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = load i64, ptr %9, align 8, !tbaa !9
  %35 = getelementptr inbounds float, ptr %33, i64 %34
  store float %30, ptr %35, align 4, !tbaa !14
  br label %36

36:                                               ; preds = %17
  %37 = load i64, ptr %9, align 8, !tbaa !9
  %38 = add i64 %37, 1
  store i64 %38, ptr %9, align 8, !tbaa !9
  br label %10, !llvm.loop !16

39:                                               ; preds = %16
  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"}


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

.lr.ph:                                           ; preds = %4
  %7 = load ptr, ptr %2, align 8, !tbaa !11
  %8 = load ptr, ptr %3, align 8, !tbaa !11
  %9 = load ptr, ptr %0, align 8, !tbaa !11
  %min.iters.check = icmp ult i64 %6, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %.08.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %6, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %.08.prol = phi i64 [ %16, %scalar.ph.prol ], [ %.08.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %10 = getelementptr inbounds float, ptr %7, i64 %.08.prol
  %11 = load float, ptr %10, align 4, !tbaa !12
  %12 = getelementptr inbounds float, ptr %8, i64 %.08.prol
  %13 = load float, ptr %12, align 4, !tbaa !12
  %14 = fsub float %11, %13
  %15 = getelementptr inbounds float, ptr %9, i64 %.08.prol
  store float %14, ptr %15, align 4, !tbaa !12
  %16 = add nuw i64 %.08.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 !14

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.08.unr = phi i64 [ %.08.ph, %scalar.ph.preheader ], [ %16, %scalar.ph.prol ]
  %17 = sub i64 %.08.ph, %6
  %18 = icmp ugt i64 %17, -4
  br i1 %18, label %._crit_edge, label %scalar.ph

vector.memcheck:                                  ; preds = %.lr.ph
  %19 = ptrtoint ptr %9 to i64
  %20 = ptrtoint ptr %8 to i64
  %21 = ptrtoint ptr %7 to i64
  %22 = sub i64 %19, %21
  %diff.check = icmp ult i64 %22, 32
  %23 = sub i64 %19, %20
  %diff.check9 = icmp ult i64 %23, 32
  %conflict.rdx = or i1 %diff.check, %diff.check9
  br i1 %conflict.rdx, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %6, -8
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %24 = getelementptr inbounds float, ptr %7, i64 %index
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  %wide.load = load <4 x float>, ptr %24, align 4, !tbaa !12
  %wide.load10 = load <4 x float>, ptr %25, align 4, !tbaa !12
  %26 = getelementptr inbounds float, ptr %8, i64 %index
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  %wide.load11 = load <4 x float>, ptr %26, align 4, !tbaa !12
  %wide.load12 = load <4 x float>, ptr %27, align 4, !tbaa !12
  %28 = fsub <4 x float> %wide.load, %wide.load11
  %29 = fsub <4 x float> %wide.load10, %wide.load12
  %30 = getelementptr inbounds float, ptr %9, i64 %index
  %31 = getelementptr inbounds i8, ptr %30, i64 16
  store <4 x float> %28, ptr %30, align 4, !tbaa !12
  store <4 x float> %29, ptr %31, align 4, !tbaa !12
  %index.next = add nuw i64 %index, 8
  %32 = icmp eq i64 %index.next, %n.vec
  br i1 %32, label %middle.block, label %vector.body, !llvm.loop !16

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %6, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %4
  ret void

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.08 = phi i64 [ %60, %scalar.ph ], [ %.08.unr, %scalar.ph.prol.loopexit ]
  %33 = getelementptr inbounds float, ptr %7, i64 %.08
  %34 = load float, ptr %33, align 4, !tbaa !12
  %35 = getelementptr inbounds float, ptr %8, i64 %.08
  %36 = load float, ptr %35, align 4, !tbaa !12
  %37 = fsub float %34, %36
  %38 = getelementptr inbounds float, ptr %9, i64 %.08
  store float %37, ptr %38, align 4, !tbaa !12
  %39 = add nuw i64 %.08, 1
  %40 = getelementptr inbounds float, ptr %7, i64 %39
  %41 = load float, ptr %40, align 4, !tbaa !12
  %42 = getelementptr inbounds float, ptr %8, i64 %39
  %43 = load float, ptr %42, align 4, !tbaa !12
  %44 = fsub float %41, %43
  %45 = getelementptr inbounds float, ptr %9, i64 %39
  store float %44, ptr %45, align 4, !tbaa !12
  %46 = add nuw i64 %.08, 2
  %47 = getelementptr inbounds float, ptr %7, i64 %46
  %48 = load float, ptr %47, align 4, !tbaa !12
  %49 = getelementptr inbounds float, ptr %8, i64 %46
  %50 = load float, ptr %49, align 4, !tbaa !12
  %51 = fsub float %48, %50
  %52 = getelementptr inbounds float, ptr %9, i64 %46
  store float %51, ptr %52, align 4, !tbaa !12
  %53 = add nuw i64 %.08, 3
  %54 = getelementptr inbounds float, ptr %7, i64 %53
  %55 = load float, ptr %54, align 4, !tbaa !12
  %56 = getelementptr inbounds float, ptr %8, i64 %53
  %57 = load float, ptr %56, align 4, !tbaa !12
  %58 = fsub float %55, %57
  %59 = getelementptr inbounds float, ptr %9, i64 %53
  store float %58, ptr %59, align 4, !tbaa !12
  %60 = add nuw i64 %.08, 4
  %exitcond.not.3 = icmp eq i64 %60, %6
  br i1 %exitcond.not.3, label %._crit_edge, label %scalar.ph, !llvm.loop !20
}

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 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}
!16 = distinct !{!16, !17, !18, !19}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.isvectorized", i32 1}
!19 = !{!"llvm.loop.unroll.runtime.disable"}
!20 = distinct !{!20, !17, !18}


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