; LLVM IR from NVIDIA/tensorflow :: tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/log_sc_99fc3775 (Z13LogScaleApplyP13LogScaleStatePjii)

; 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.LogScaleState = type { i32, i32 }

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z13LogScaleApplyP13LogScaleStatePjii(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.LogScaleState, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !11
  store i32 %16, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %17, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %18 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %18, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %63, %4
  %20 = load i32, ptr %12, align 4, !tbaa !9
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %23, label %66

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds i32, ptr %24, i32 1
  store ptr %25, ptr %6, align 8, !tbaa !5
  %26 = load i32, ptr %24, align 4, !tbaa !9
  store i32 %26, ptr %13, align 4, !tbaa !9
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.LogScaleState, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 4, !tbaa !13
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %52

31:                                               ; preds = %23
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = icmp slt i32 %32, 0
  br i1 %33, label %34, label %39

34:                                               ; preds = %31
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = sub nsw i32 0, %35
  %37 = load i32, ptr %13, align 4, !tbaa !9
  %38 = lshr i32 %37, %36
  store i32 %38, ptr %13, align 4, !tbaa !9
  br label %43

39:                                               ; preds = %31
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = load i32, ptr %13, align 4, !tbaa !9
  %42 = shl i32 %41, %40
  store i32 %42, ptr %13, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %39, %34
  %44 = load i32, ptr %13, align 4, !tbaa !9
  %45 = icmp ugt i32 %44, 1
  br i1 %45, label %46, label %50

46:                                               ; preds = %43
  %47 = load i32, ptr %13, align 4, !tbaa !9
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = call noundef i32 @_ZL3Logjj(i32 noundef %47, i32 noundef %48)
  store i32 %49, ptr %13, align 4, !tbaa !9
  br label %51

50:                                               ; preds = %43
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %50, %46
  br label %52

52:                                               ; preds = %51, %23
  %53 = load i32, ptr %13, align 4, !tbaa !9
  %54 = icmp ult i32 %53, 65535
  br i1 %54, label %55, label %57

55:                                               ; preds = %52
  %56 = load i32, ptr %13, align 4, !tbaa !9
  br label %58

57:                                               ; preds = %52
  br label %58

58:                                               ; preds = %57, %55
  %59 = phi i32 [ %56, %55 ], [ 65535, %57 ]
  %60 = trunc i32 %59 to i16
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = getelementptr inbounds i16, ptr %61, i32 1
  store ptr %62, ptr %10, align 8, !tbaa !5
  store i16 %60, ptr %61, align 2, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  br label %63

63:                                               ; preds = %58
  %64 = load i32, ptr %12, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %12, align 4, !tbaa !9
  br label %19, !llvm.loop !16

66:                                               ; preds = %19
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret ptr %67
}

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

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL3Logjj(i32 noundef, i32 noundef) #0

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

attributes #0 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_ZTS13LogScaleState", !10, i64 0, !10, i64 4}
!13 = !{!12, !10, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !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: mustprogress uwtable
define dso_local noundef ptr @_Z13LogScaleApplyP13LogScaleStatePjii(ptr nocapture noundef readonly %0, ptr noundef returned %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp sgt i32 %2, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %8 = icmp slt i32 %3, 0
  %9 = sub nsw i32 0, %3
  %10 = load i32, ptr %0, align 4, !tbaa !10
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %.lr.ph.split.us.preheader, label %.lr.ph.split

.lr.ph.split.us.preheader:                        ; preds = %.lr.ph
  %12 = zext nneg i32 %2 to i64
  %min.iters.check = icmp ult i32 %2, 8
  br i1 %min.iters.check, label %.lr.ph.split.us.preheader40, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.split.us.preheader
  %n.vec = and i64 %12, 2147483640
  %ind.end = trunc nuw nsw i64 %n.vec to i32
  %13 = shl nuw nsw i64 %n.vec, 2
  %ind.end31 = getelementptr i8, ptr %1, i64 %13
  %14 = shl nuw nsw i64 %n.vec, 1
  %ind.end33 = getelementptr i8, ptr %1, i64 %14
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = shl i64 %index, 2
  %next.gep = getelementptr i8, ptr %1, i64 %offset.idx
  %offset.idx36 = shl i64 %index, 1
  %next.gep37 = getelementptr i8, ptr %1, i64 %offset.idx36
  %15 = getelementptr i8, ptr %next.gep, i64 16
  %wide.load = load <4 x i32>, ptr %next.gep, align 4, !tbaa !11
  %wide.load39 = load <4 x i32>, ptr %15, align 4, !tbaa !11
  %16 = tail call <4 x i32> @llvm.umin.v4i32(<4 x i32> %wide.load, <4 x i32> <i32 65535, i32 65535, i32 65535, i32 65535>)
  %17 = tail call <4 x i32> @llvm.umin.v4i32(<4 x i32> %wide.load39, <4 x i32> <i32 65535, i32 65535, i32 65535, i32 65535>)
  %18 = trunc nuw <4 x i32> %16 to <4 x i16>
  %19 = trunc nuw <4 x i32> %17 to <4 x i16>
  %20 = getelementptr i8, ptr %next.gep37, i64 8
  store <4 x i16> %18, ptr %next.gep37, align 2, !tbaa !12
  store <4 x i16> %19, ptr %20, align 2, !tbaa !12
  %index.next = add nuw i64 %index, 8
  %21 = icmp eq i64 %index.next, %n.vec
  br i1 %21, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %12
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.split.us.preheader40

.lr.ph.split.us.preheader40:                      ; preds = %middle.block, %.lr.ph.split.us.preheader
  %.01926.us.ph = phi i32 [ 0, %.lr.ph.split.us.preheader ], [ %ind.end, %middle.block ]
  %.02025.us.ph = phi ptr [ %1, %.lr.ph.split.us.preheader ], [ %ind.end31, %middle.block ]
  %.02124.us.ph = phi ptr [ %1, %.lr.ph.split.us.preheader ], [ %ind.end33, %middle.block ]
  br label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph.split.us.preheader40, %.lr.ph.split.us
  %.01926.us = phi i32 [ %27, %.lr.ph.split.us ], [ %.01926.us.ph, %.lr.ph.split.us.preheader40 ]
  %.02025.us = phi ptr [ %22, %.lr.ph.split.us ], [ %.02025.us.ph, %.lr.ph.split.us.preheader40 ]
  %.02124.us = phi ptr [ %26, %.lr.ph.split.us ], [ %.02124.us.ph, %.lr.ph.split.us.preheader40 ]
  %22 = getelementptr inbounds i8, ptr %.02025.us, i64 4
  %23 = load i32, ptr %.02025.us, align 4, !tbaa !11
  %24 = tail call i32 @llvm.umin.i32(i32 %23, i32 65535)
  %25 = trunc nuw i32 %24 to i16
  %26 = getelementptr inbounds i8, ptr %.02124.us, i64 2
  store i16 %25, ptr %.02124.us, align 2, !tbaa !12
  %27 = add nuw nsw i32 %.01926.us, 1
  %exitcond28.not = icmp eq i32 %27, %2
  br i1 %exitcond28.not, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !18

.lr.ph.splitthread-pre-split:                     ; preds = %38
  %28 = getelementptr inbounds i8, ptr %.02124, i64 2
  %.pr = load i32, ptr %0, align 4, !tbaa !10
  br label %.lr.ph.split

.lr.ph.split:                                     ; preds = %.lr.ph, %.lr.ph.splitthread-pre-split
  %29 = phi i32 [ %.pr, %.lr.ph.splitthread-pre-split ], [ 1, %.lr.ph ]
  %.01926 = phi i32 [ %41, %.lr.ph.splitthread-pre-split ], [ 0, %.lr.ph ]
  %.02025 = phi ptr [ %30, %.lr.ph.splitthread-pre-split ], [ %1, %.lr.ph ]
  %.02124 = phi ptr [ %28, %.lr.ph.splitthread-pre-split ], [ %1, %.lr.ph ]
  %30 = getelementptr inbounds i8, ptr %.02025, i64 4
  %31 = load i32, ptr %.02025, align 4, !tbaa !11
  %.not = icmp eq i32 %29, 0
  br i1 %.not, label %38, label %32

32:                                               ; preds = %.lr.ph.split
  %33 = lshr i32 %31, %9
  %34 = shl i32 %31, %3
  %.0 = select i1 %8, i32 %33, i32 %34
  %35 = icmp ugt i32 %.0, 1
  br i1 %35, label %36, label %38

36:                                               ; preds = %32
  %37 = tail call noundef i32 @_ZL3Logjj(i32 noundef %.0, i32 noundef %6)
  br label %38

38:                                               ; preds = %32, %36, %.lr.ph.split
  %.1 = phi i32 [ %37, %36 ], [ %31, %.lr.ph.split ], [ 0, %32 ]
  %39 = tail call i32 @llvm.umin.i32(i32 %.1, i32 65535)
  %40 = trunc nuw i32 %39 to i16
  store i16 %40, ptr %.02124, align 2, !tbaa !12
  %41 = add nuw nsw i32 %.01926, 1
  %exitcond.not = icmp eq i32 %41, %2
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph.splitthread-pre-split, !llvm.loop !19

._crit_edge:                                      ; preds = %38, %.lr.ph.split.us, %middle.block, %4
  ret ptr %1
}

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL3Logjj(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i32> @llvm.umin.v4i32(<4 x i32>, <4 x i32>) #1

attributes #0 = { mustprogress 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 speculatable willreturn memory(none) }

!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, !7, i64 4}
!6 = !{!"_ZTS13LogScaleState", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !8, i64 0}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !15, !17, !16}
!19 = distinct !{!19, !15, !20}
!20 = !{!"llvm.loop.unswitch.partial.disable"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass