; LLVM IR from NVIDIA/TensorRT :: plugin/common/reducedMathPlugin.ll (ZN8nvinfer16plugin6detail11findDivisorEiRjS2_)

; 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
declare dso_local noundef i32 @_ZN8nvinfer16plugin6detail10find_log_2Eib(i32 noundef, i1 noundef zeroext) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN8nvinfer16plugin6detail11findDivisorEiRjS2_(i32 noundef %0, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %3
  br label %38

12:                                               ; preds = %3
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %15, label %18

15:                                               ; preds = %12
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  store i32 0, ptr %16, align 4, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 0, ptr %17, align 4, !tbaa !5
  br label %38

18:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = call noundef i32 @_ZN8nvinfer16plugin6detail10find_log_2Eib(i32 noundef %19, i1 noundef zeroext true)
  %21 = add nsw i32 31, %20
  store i32 %21, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = zext i32 %22 to i64
  %24 = shl i64 1, %23
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = zext i32 %25 to i64
  %27 = add i64 %24, %26
  %28 = sub i64 %27, 1
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = zext i32 %29 to i64
  %31 = udiv i64 %28, %30
  %32 = trunc i64 %31 to i32
  store i32 %32, ptr %8, align 4, !tbaa !5
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !9
  store i32 %33, ptr %34, align 4, !tbaa !5
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = sub i32 %35, 32
  %37 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 %36, ptr %37, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %38

38:                                               ; preds = %18, %15, %11
  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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


; 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 nounwind uwtable
declare dso_local noundef i32 @_ZN8nvinfer16plugin6detail10find_log_2Eib(i32 noundef, i1 noundef zeroext) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN8nvinfer16plugin6detail11findDivisorEiRjS2_(i32 noundef %0, ptr nocapture noundef nonnull writeonly align 4 dereferenceable(4) %1, ptr nocapture noundef nonnull writeonly align 4 dereferenceable(4) %2) local_unnamed_addr #0 {
  switch i32 %0, label %5 [
    i32 0, label %16
    i32 1, label %4
  ]

4:                                                ; preds = %3
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %.sink.split

5:                                                ; preds = %3
  %6 = tail call noundef i32 @_ZN8nvinfer16plugin6detail10find_log_2Eib(i32 noundef %0, i1 noundef zeroext true)
  %7 = add nsw i32 %6, 31
  %8 = zext nneg i32 %7 to i64
  %9 = shl nuw i64 1, %8
  %10 = zext i32 %0 to i64
  %11 = add nsw i64 %10, -1
  %12 = add i64 %11, %9
  %13 = udiv i64 %12, %10
  %14 = trunc i64 %13 to i32
  store i32 %14, ptr %1, align 4, !tbaa !5
  %15 = add i32 %6, -1
  br label %.sink.split

.sink.split:                                      ; preds = %4, %5
  %.sink = phi i32 [ %15, %5 ], [ 0, %4 ]
  store i32 %.sink, ptr %2, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %.sink.split, %3
  ret void
}

attributes #0 = { 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass