; LLVM IR from PaddlePaddle/Paddle-Lite :: lite/backends/host/math (temporal_shift)

; 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: mustprogress nounwind uwtable
define dso_local void @_ZN6paddle4lite4host4math22temporalshiftNHWC_funcIfEEvPKT_PS4_iiiiiii(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i32 noundef %8) #1 {
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !5
  store i32 %2, ptr %12, align 4, !tbaa !9
  store i32 %3, ptr %13, align 4, !tbaa !9
  store i32 %4, ptr %14, align 4, !tbaa !9
  store i32 %5, ptr %15, align 4, !tbaa !9
  store i32 %6, ptr %16, align 4, !tbaa !9
  store i32 %7, ptr %17, align 4, !tbaa !9
  store i32 %8, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #2
  store i32 0, ptr %19, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #2
  store i32 0, ptr %20, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %82, %9
  %24 = load i32, ptr %20, align 4, !tbaa !9
  %25 = load i32, ptr %12, align 4, !tbaa !9
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #2
  br label %85

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #2
  %29 = load i32, ptr %20, align 4, !tbaa !9
  %30 = load i32, ptr %13, align 4, !tbaa !9
  %31 = srem i32 %29, %30
  %32 = load i32, ptr %14, align 4, !tbaa !9
  %33 = sdiv i32 %31, %32
  store i32 %33, ptr %21, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #2
  %34 = load i32, ptr %20, align 4, !tbaa !9
  %35 = load i32, ptr %16, align 4, !tbaa !9
  %36 = srem i32 %34, %35
  store i32 %36, ptr %22, align 4, !tbaa !9
  %37 = load i32, ptr %22, align 4, !tbaa !9
  %38 = load i32, ptr %17, align 4, !tbaa !9
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %40, label %43

40:                                               ; preds = %28
  %41 = load i32, ptr %21, align 4, !tbaa !9
  %42 = sub nsw i32 %41, 1
  store i32 %42, ptr %19, align 4, !tbaa !9
  br label %53

43:                                               ; preds = %28
  %44 = load i32, ptr %22, align 4, !tbaa !9
  %45 = load i32, ptr %18, align 4, !tbaa !9
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %47, label %50

47:                                               ; preds = %43
  %48 = load i32, ptr %21, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %19, align 4, !tbaa !9
  br label %52

50:                                               ; preds = %43
  %51 = load i32, ptr %21, align 4, !tbaa !9
  store i32 %51, ptr %19, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %50, %47
  br label %53

53:                                               ; preds = %52, %40
  %54 = load i32, ptr %19, align 4, !tbaa !9
  %55 = icmp slt i32 %54, 0
  br i1 %55, label %60, label %56

56:                                               ; preds = %53
  %57 = load i32, ptr %19, align 4, !tbaa !9
  %58 = load i32, ptr %15, align 4, !tbaa !9
  %59 = icmp sge i32 %57, %58
  br i1 %59, label %60, label %65

60:                                               ; preds = %56, %53
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = load i32, ptr %20, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds float, ptr %61, i64 %63
  store float 0.000000e+00, ptr %64, align 4, !tbaa !11
  br label %81

65:                                               ; preds = %56
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = load i32, ptr %20, align 4, !tbaa !9
  %68 = load i32, ptr %19, align 4, !tbaa !9
  %69 = load i32, ptr %21, align 4, !tbaa !9
  %70 = sub nsw i32 %68, %69
  %71 = load i32, ptr %14, align 4, !tbaa !9
  %72 = mul nsw i32 %70, %71
  %73 = add nsw i32 %67, %72
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds float, ptr %66, i64 %74
  %76 = load float, ptr %75, align 4, !tbaa !11
  %77 = load ptr, ptr %11, align 8, !tbaa !5
  %78 = load i32, ptr %20, align 4, !tbaa !9
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds float, ptr %77, i64 %79
  store float %76, ptr %80, align 4, !tbaa !11
  br label %81

81:                                               ; preds = %65, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #2
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %20, align 4, !tbaa !9
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %20, align 4, !tbaa !9
  br label %23, !llvm.loop !13

85:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_ZN6paddle4lite4host4math22temporalshiftNHWC_funcIfEEvPKT_PS4_iiiiiii(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i32 noundef %8) local_unnamed_addr #0 {
  %10 = icmp sgt i32 %2, 0
  br i1 %10, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %9
  %wide.trip.count = zext nneg i32 %2 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %25, %9
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %25
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %25 ]
  %11 = trunc nuw nsw i64 %indvars.iv to i32
  %12 = srem i32 %11, %3
  %13 = sdiv i32 %12, %4
  %14 = srem i32 %11, %6
  %15 = icmp slt i32 %14, %7
  %16 = icmp slt i32 %14, %8
  %17 = zext i1 %16 to i32
  %.0.v = select i1 %15, i32 -1, i32 %17
  %.0 = add nsw i32 %.0.v, %13
  %18 = icmp sgt i32 %.0, -1
  %.not = icmp slt i32 %.0, %5
  %or.cond = and i1 %18, %.not
  br i1 %or.cond, label %19, label %25

19:                                               ; preds = %.lr.ph
  %20 = mul nsw i32 %.0.v, %4
  %21 = add nsw i32 %20, %11
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds float, ptr %0, i64 %22
  %24 = load float, ptr %23, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %.lr.ph, %19
  %.sink = phi float [ %24, %19 ], [ 0.000000e+00, %.lr.ph ]
  %26 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  store float %.sink, ptr %26, align 4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9
}

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


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass