; LLVM IR from mrbid/CSGO_TENSOR_TRIGGER :: GOBOT15/KERAS2C/include (k2c_recurrent_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

declare void @k2c_affine_matmul(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, i64 noundef, i64 noundef) #1

; 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_simpleRNNcell(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) #2 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i64, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  store ptr %6, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.k2c_tensor, ptr %21, i32 0, i32 3
  %23 = getelementptr inbounds [5 x i64], ptr %22, i64 0, i64 1
  %24 = load i64, ptr %23, align 8, !tbaa !9
  store i64 %24, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.k2c_tensor, ptr %25, i32 0, i32 3
  %27 = getelementptr inbounds [5 x i64], ptr %26, i64 0, i64 0
  %28 = load i64, ptr %27, align 8, !tbaa !9
  store i64 %28, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  store i64 1, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %29 = load ptr, ptr %13, align 8, !tbaa !5
  %30 = getelementptr inbounds float, ptr %29, i64 0
  store ptr %30, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  %31 = load ptr, ptr %13, align 8, !tbaa !5
  %32 = load i64, ptr %15, align 8, !tbaa !9
  %33 = getelementptr inbounds float, ptr %31, i64 %32
  store ptr %33, ptr %19, align 8, !tbaa !5
  %34 = load ptr, ptr %18, align 8, !tbaa !5
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.k2c_tensor, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = load ptr, ptr %12, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.k2c_tensor, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  %42 = load i64, ptr %15, align 8, !tbaa !9
  %43 = load i64, ptr %16, align 8, !tbaa !9
  call void @k2c_affine_matmul(ptr noundef %34, ptr noundef %35, ptr noundef %38, ptr noundef %41, i64 noundef 1, i64 noundef %42, i64 noundef %43)
  %44 = load ptr, ptr %19, align 8, !tbaa !5
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.k2c_tensor, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !11
  %49 = load ptr, ptr %18, align 8, !tbaa !5
  %50 = load i64, ptr %15, align 8, !tbaa !9
  %51 = load i64, ptr %15, align 8, !tbaa !9
  call void @k2c_affine_matmul(ptr noundef %44, ptr noundef %45, ptr noundef %48, ptr noundef %49, i64 noundef 1, i64 noundef %50, i64 noundef %51)
  %52 = load ptr, ptr %14, align 8, !tbaa !5
  %53 = load ptr, ptr %19, align 8, !tbaa !5
  %54 = load i64, ptr %15, align 8, !tbaa !9
  call void %52(ptr noundef %53, i64 noundef %54)
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  store i64 0, ptr %20, align 8, !tbaa !9
  br label %55

55:                                               ; preds = %68, %7
  %56 = load i64, ptr %20, align 8, !tbaa !9
  %57 = load i64, ptr %15, align 8, !tbaa !9
  %58 = icmp ult i64 %56, %57
  br i1 %58, label %60, label %59

59:                                               ; preds = %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  br label %71

60:                                               ; preds = %55
  %61 = load ptr, ptr %19, align 8, !tbaa !5
  %62 = load i64, ptr %20, align 8, !tbaa !9
  %63 = getelementptr inbounds float, ptr %61, i64 %62
  %64 = load float, ptr %63, align 4, !tbaa !13
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = load i64, ptr %20, align 8, !tbaa !9
  %67 = getelementptr inbounds float, ptr %65, i64 %66
  store float %64, ptr %67, align 4, !tbaa !13
  br label %68

68:                                               ; preds = %60
  %69 = load i64, ptr %20, align 8, !tbaa !9
  %70 = add i64 %69, 1
  store i64 %70, ptr %20, align 8, !tbaa !9
  br label %55, !llvm.loop !15

71:                                               ; preds = %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #3 = { 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, !6, i64 0}
!12 = !{!"k2c_tensor", !6, i64 0, !10, i64 8, !10, i64 16, !7, i64 24}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

declare void @k2c_affine_matmul(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @k2c_simpleRNNcell(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4, ptr noundef %5, ptr nocapture noundef readonly %6) local_unnamed_addr #1 {
  %8 = ptrtoint ptr %5 to i64
  %9 = ptrtoint ptr %0 to i64
  %10 = getelementptr inbounds i8, ptr %3, i64 32
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %2, i64 24
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = getelementptr float, ptr %5, i64 %11
  %15 = load ptr, ptr %2, align 8, !tbaa !9
  %16 = load ptr, ptr %4, align 8, !tbaa !9
  tail call void @k2c_affine_matmul(ptr noundef %5, ptr noundef %1, ptr noundef %15, ptr noundef %16, i64 noundef 1, i64 noundef %11, i64 noundef %13) #2
  %17 = load ptr, ptr %3, align 8, !tbaa !9
  tail call void @k2c_affine_matmul(ptr noundef %14, ptr noundef %0, ptr noundef %17, ptr noundef %5, i64 noundef 1, i64 noundef %11, i64 noundef %11) #2
  tail call void %6(ptr noundef %14, i64 noundef %11) #2
  %.not = icmp eq i64 %11, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %7
  %min.iters.check = icmp ult i64 %11, 12
  br i1 %min.iters.check, label %.lr.ph.preheader28, label %vector.memcheck

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

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader28, %.lr.ph.prol
  %.026.prol = phi i64 [ %21, %.lr.ph.prol ], [ %.026.ph, %.lr.ph.preheader28 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader28 ]
  %18 = getelementptr inbounds float, ptr %14, i64 %.026.prol
  %19 = load float, ptr %18, align 4, !tbaa !12
  %20 = getelementptr inbounds float, ptr %0, i64 %.026.prol
  store float %19, ptr %20, align 4, !tbaa !12
  %21 = add nuw i64 %.026.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 %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !14

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader28
  %.026.unr = phi i64 [ %.026.ph, %.lr.ph.preheader28 ], [ %21, %.lr.ph.prol ]
  %22 = sub i64 %.026.ph, %11
  %23 = icmp ugt i64 %22, -4
  br i1 %23, label %._crit_edge, label %.lr.ph

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %24 = shl i64 %11, 2
  %25 = add i64 %24, %8
  %26 = sub i64 %9, %25
  %diff.check = icmp ult i64 %26, 32
  br i1 %diff.check, label %.lr.ph.preheader28, label %vector.ph

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

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

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %11, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader28

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %7
  ret void

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.026 = phi i64 [ %47, %.lr.ph ], [ %.026.unr, %.lr.ph.prol.loopexit ]
  %32 = getelementptr inbounds float, ptr %14, i64 %.026
  %33 = load float, ptr %32, align 4, !tbaa !12
  %34 = getelementptr inbounds float, ptr %0, i64 %.026
  store float %33, ptr %34, align 4, !tbaa !12
  %35 = add nuw i64 %.026, 1
  %36 = getelementptr inbounds float, ptr %14, i64 %35
  %37 = load float, ptr %36, align 4, !tbaa !12
  %38 = getelementptr inbounds float, ptr %0, i64 %35
  store float %37, ptr %38, align 4, !tbaa !12
  %39 = add nuw i64 %.026, 2
  %40 = getelementptr inbounds float, ptr %14, i64 %39
  %41 = load float, ptr %40, align 4, !tbaa !12
  %42 = getelementptr inbounds float, ptr %0, i64 %39
  store float %41, ptr %42, align 4, !tbaa !12
  %43 = add nuw i64 %.026, 3
  %44 = getelementptr inbounds float, ptr %14, i64 %43
  %45 = load float, ptr %44, align 4, !tbaa !12
  %46 = getelementptr inbounds float, ptr %0, i64 %43
  store float %45, ptr %46, align 4, !tbaa !12
  %47 = add nuw i64 %.026, 4
  %exitcond.not.3 = icmp eq i64 %47, %11
  br i1 %exitcond.not.3, label %._crit_edge, label %.lr.ph, !llvm.loop !20
}

attributes #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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"k2c_tensor", !11, i64 0, !6, i64 8, !6, i64 16, !7, i64 24}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !7, 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,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass