; LLVM IR from openxrlab/xrsfm :: 3rdparty/SiftGPU/SiftMatch.ll (ZN11SiftMatchGL10SetMaxSiftEi)

; 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"

%class.SiftMatchGPU = type <{ ptr, i32, i32, ptr, i32, [4 x i8] }>
%class.SiftMatchGL = type { %class.SiftMatchGPU.base, [4 x i8], [2 x %class.GLTexImage], [2 x %class.GLTexImage], %class.GLTexImage, [2 x %class.GLTexImage], ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [2 x i32], [2 x i32], [2 x i32], i32, i32, i32, i32, i32, %"class.std::vector" }
%class.SiftMatchGPU.base = type <{ ptr, i32, i32, ptr, i32 }>
%class.GLTexImage = type <{ ptr, i32, i32, i32, i32, i32, i32, i32, [4 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl" }
%"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl" = type { %"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl_data" }
%"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@_ZN11GlobalParam12_texMaxDimGLE = external global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11SiftMatchGL10SetMaxSiftEi(ptr noundef nonnull align 8 dereferenceable(464) %0, i32 noundef %1) unnamed_addr #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr %3, align 8
  %6 = load i32, ptr %4, align 4, !tbaa !9
  %7 = add nsw i32 %6, 31
  %8 = sdiv i32 %7, 32
  %9 = mul nsw i32 %8, 32
  store i32 %9, ptr %4, align 4, !tbaa !9
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = load i32, ptr @_ZN11GlobalParam12_texMaxDimGLE, align 4, !tbaa !9
  %12 = icmp sgt i32 %10, %11
  br i1 %12, label %13, label %15

13:                                               ; preds = %2
  %14 = load i32, ptr @_ZN11GlobalParam12_texMaxDimGLE, align 4, !tbaa !9
  store i32 %14, ptr %4, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %13, %2
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = getelementptr inbounds %class.SiftMatchGPU, ptr %5, i32 0, i32 4
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = icmp sgt i32 %16, %18
  br i1 %19, label %20, label %35

20:                                               ; preds = %15
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = getelementptr inbounds %class.SiftMatchGPU, ptr %5, i32 0, i32 4
  store i32 %21, ptr %22, align 8, !tbaa !11
  call void @_ZN11SiftMatchGL17AllocateSiftMatchEv(ptr noundef nonnull align 8 dereferenceable(464) %5)
  %23 = getelementptr inbounds %class.SiftMatchGL, ptr %5, i32 0, i32 24
  %24 = getelementptr inbounds [2 x i32], ptr %23, i64 0, i64 1
  store i32 0, ptr %24, align 4, !tbaa !9
  %25 = getelementptr inbounds %class.SiftMatchGL, ptr %5, i32 0, i32 24
  %26 = getelementptr inbounds [2 x i32], ptr %25, i64 0, i64 0
  store i32 0, ptr %26, align 8, !tbaa !9
  %27 = getelementptr inbounds %class.SiftMatchGL, ptr %5, i32 0, i32 23
  %28 = getelementptr inbounds [2 x i32], ptr %27, i64 0, i64 1
  store i32 -1, ptr %28, align 4, !tbaa !9
  %29 = getelementptr inbounds %class.SiftMatchGL, ptr %5, i32 0, i32 23
  %30 = getelementptr inbounds [2 x i32], ptr %29, i64 0, i64 0
  store i32 -1, ptr %30, align 8, !tbaa !9
  %31 = getelementptr inbounds %class.SiftMatchGL, ptr %5, i32 0, i32 22
  %32 = getelementptr inbounds [2 x i32], ptr %31, i64 0, i64 1
  store i32 1, ptr %32, align 4, !tbaa !9
  %33 = getelementptr inbounds %class.SiftMatchGL, ptr %5, i32 0, i32 22
  %34 = getelementptr inbounds [2 x i32], ptr %33, i64 0, i64 0
  store i32 1, ptr %34, align 8, !tbaa !9
  br label %38

35:                                               ; preds = %15
  %36 = load i32, ptr %4, align 4, !tbaa !9
  %37 = getelementptr inbounds %class.SiftMatchGPU, ptr %5, i32 0, i32 4
  store i32 %36, ptr %37, align 8, !tbaa !11
  br label %38

38:                                               ; preds = %35, %20
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11SiftMatchGL17AllocateSiftMatchEv(ptr noundef nonnull align 8 dereferenceable(464)) #0 align 2

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" }

!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 24}
!12 = !{!"_ZTS12SiftMatchGPU", !10, i64 8, !10, i64 12, !6, i64 16, !10, i64 24}


; 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"

@_ZN11GlobalParam12_texMaxDimGLE = external local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11SiftMatchGL10SetMaxSiftEi(ptr noundef nonnull align 8 dereferenceable(464) %0, i32 noundef %1) unnamed_addr #0 align 2 {
  %3 = add nsw i32 %1, 31
  %4 = sdiv i32 %3, 32
  %5 = shl nsw i32 %4, 5
  %6 = load i32, ptr @_ZN11GlobalParam12_texMaxDimGLE, align 4, !tbaa !5
  %spec.select = tail call i32 @llvm.smin.i32(i32 %5, i32 %6)
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = icmp sgt i32 %spec.select, %8
  store i32 %spec.select, ptr %7, align 8, !tbaa !9
  br i1 %9, label %10, label %14

10:                                               ; preds = %2
  tail call void @_ZN11SiftMatchGL17AllocateSiftMatchEv(ptr noundef nonnull align 8 dereferenceable(464) %0)
  %11 = getelementptr inbounds i8, ptr %0, i64 408
  %12 = getelementptr inbounds i8, ptr %0, i64 412
  store i32 0, ptr %12, align 4, !tbaa !5
  store i32 0, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 392
  store <4 x i32> <i32 1, i32 1, i32 -1, i32 -1>, ptr %13, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %2, %10
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11SiftMatchGL17AllocateSiftMatchEv(ptr noundef nonnull align 8 dereferenceable(464)) local_unnamed_addr #0 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 24}
!10 = !{!"_ZTS12SiftMatchGPU", !6, i64 8, !6, i64 12, !11, i64 16, !6, i64 24}
!11 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass