; LLVM IR from mrbid/CSGO_TENSOR_TRIGGER :: GOBOT15/KERAS2C/include (k2c_embedding_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: nounwind uwtable
define dso_local void @k2c_embedding(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.k2c_tensor, ptr %11, i32 0, i32 3
  %13 = getelementptr inbounds [5 x i64], ptr %12, i64 0, i64 1
  %14 = load i64, ptr %13, align 8, !tbaa !9
  store i64 %14, 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
  br label %15

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

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

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

23:                                               ; preds = %55, %22
  %24 = load i64, ptr %10, align 8, !tbaa !9
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = icmp ult i64 %24, %25
  br i1 %26, label %28, label %27

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

28:                                               ; preds = %23
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.k2c_tensor, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.k2c_tensor, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !13
  %35 = load i64, ptr %8, align 8, !tbaa !9
  %36 = getelementptr inbounds float, ptr %34, i64 %35
  %37 = load float, ptr %36, align 4, !tbaa !14
  %38 = fptosi float %37 to i32
  %39 = sext i32 %38 to i64
  %40 = load i64, ptr %7, align 8, !tbaa !9
  %41 = mul i64 %39, %40
  %42 = load i64, ptr %10, align 8, !tbaa !9
  %43 = add i64 %41, %42
  %44 = getelementptr inbounds float, ptr %31, i64 %43
  %45 = load float, ptr %44, align 4, !tbaa !14
  %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 %8, align 8, !tbaa !9
  %50 = load i64, ptr %7, align 8, !tbaa !9
  %51 = mul i64 %49, %50
  %52 = load i64, ptr %10, align 8, !tbaa !9
  %53 = add i64 %51, %52
  %54 = getelementptr inbounds float, ptr %48, i64 %53
  store float %45, ptr %54, align 4, !tbaa !14
  br label %55

55:                                               ; preds = %28
  %56 = load i64, ptr %10, align 8, !tbaa !9
  %57 = add i64 %56, 1
  store i64 %57, ptr %10, align 8, !tbaa !9
  br label %23, !llvm.loop !16

58:                                               ; preds = %27
  br label %59

59:                                               ; preds = %58
  %60 = load i64, ptr %8, align 8, !tbaa !9
  %61 = add i64 %60, 1
  store i64 %61, ptr %8, align 8, !tbaa !9
  br label %15, !llvm.loop !18

62:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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_embedding(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %2, i64 32
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 16
  %7 = load i64, ptr %6, align 8, !tbaa !9
  %.not = icmp eq i64 %7, 0
  %.not20 = icmp eq i64 %5, 0
  %or.cond = select i1 %.not, i1 true, i1 %.not20
  br i1 %or.cond, label %._crit_edge19, label %.preheader.lr.ph.split.us

.preheader.lr.ph.split.us:                        ; preds = %3
  %8 = load ptr, ptr %2, align 8, !tbaa !12
  %9 = load ptr, ptr %1, align 8, !tbaa !12
  %10 = load ptr, ptr %0, align 8, !tbaa !12
  %xtraiter = and i64 %5, 1
  %11 = icmp eq i64 %5, 1
  %unroll_iter = and i64 %5, -2
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph.split.us
  %.01518.us = phi i64 [ 0, %.preheader.lr.ph.split.us ], [ %41, %._crit_edge.us ]
  %12 = getelementptr inbounds float, ptr %9, i64 %.01518.us
  %13 = mul i64 %.01518.us, %5
  %14 = getelementptr float, ptr %10, i64 %13
  br i1 %11, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %.017.us = phi i64 [ %32, %.preheader.us.new ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %15 = load float, ptr %12, align 4, !tbaa !13
  %16 = fptosi float %15 to i32
  %17 = sext i32 %16 to i64
  %18 = mul i64 %5, %17
  %19 = getelementptr float, ptr %8, i64 %18
  %20 = getelementptr float, ptr %19, i64 %.017.us
  %21 = load float, ptr %20, align 4, !tbaa !13
  %22 = getelementptr float, ptr %14, i64 %.017.us
  store float %21, ptr %22, align 4, !tbaa !13
  %23 = or disjoint i64 %.017.us, 1
  %24 = load float, ptr %12, align 4, !tbaa !13
  %25 = fptosi float %24 to i32
  %26 = sext i32 %25 to i64
  %27 = mul i64 %5, %26
  %28 = getelementptr float, ptr %8, i64 %27
  %29 = getelementptr float, ptr %28, i64 %23
  %30 = load float, ptr %29, align 4, !tbaa !13
  %31 = getelementptr float, ptr %14, i64 %23
  store float %30, ptr %31, align 4, !tbaa !13
  %32 = add nuw i64 %.017.us, 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_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !15

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %.017.us.unr = phi i64 [ 0, %.preheader.us ], [ %32, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %33 = load float, ptr %12, align 4, !tbaa !13
  %34 = fptosi float %33 to i32
  %35 = sext i32 %34 to i64
  %36 = mul i64 %5, %35
  %37 = getelementptr float, ptr %8, i64 %36
  %38 = getelementptr float, ptr %37, i64 %.017.us.unr
  %39 = load float, ptr %38, align 4, !tbaa !13
  %40 = getelementptr float, ptr %14, i64 %.017.us.unr
  store float %39, ptr %40, align 4, !tbaa !13
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %41 = add nuw i64 %.01518.us, 1
  %exitcond22.not = icmp eq i64 %41, %7
  br i1 %exitcond22.not, label %._crit_edge19, label %.preheader.us, !llvm.loop !17

._crit_edge19:                                    ; preds = %._crit_edge.us, %3
  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, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"k2c_tensor", !11, i64 0, !6, i64 8, !6, i64 16, !7, i64 24}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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