; LLVM IR from hlzz/libvot :: src/third_party/vlfeat/vl/dsift.ll (vl_dsift_new_kernel)

; 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: nounwind uwtable
define dso_local ptr @_vl_dsift_new_kernel(i32 noundef %0, i32 noundef %1, i32 noundef %2, double noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  %14 = alloca i32, align 4
  %15 = alloca float, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store double %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = mul nsw i32 2, %16
  %18 = sub nsw i32 %17, 1
  store i32 %18, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %19 = load i32, ptr %9, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = mul i64 4, %20
  %22 = call ptr @vl_malloc(i64 noundef %21)
  store ptr %22, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %23 = load ptr, ptr %10, align 8, !tbaa !11
  store ptr %23, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sitofp i32 %24 to float
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = sitofp i32 %26 to float
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = sub nsw i32 %28, 1
  %30 = sitofp i32 %29 to float
  %31 = call float @llvm.fmuladd.f32(float -5.000000e-01, float %30, float %27)
  %32 = fmul float %25, %31
  store float %32, ptr %12, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sitofp i32 %33 to float
  %35 = load double, ptr %8, align 8, !tbaa !9
  %36 = fptrunc double %35 to float
  %37 = fmul float %34, %36
  store float %37, ptr %13, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sub nsw i32 0, %38
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %14, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %73, %4
  %42 = load i32, ptr %14, align 4, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sub nsw i32 %43, 1
  %45 = icmp sle i32 %42, %44
  br i1 %45, label %46, label %76

46:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %47 = load i32, ptr %14, align 4, !tbaa !5
  %48 = sitofp i32 %47 to float
  %49 = load float, ptr %12, align 4, !tbaa !13
  %50 = fsub float %48, %49
  %51 = load float, ptr %13, align 4, !tbaa !13
  %52 = fdiv float %50, %51
  store float %52, ptr %15, align 4, !tbaa !13
  %53 = load i32, ptr %14, align 4, !tbaa !5
  %54 = call i32 @llvm.abs.i32(i32 %53, i1 true)
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = sdiv i32 %54, %55
  %57 = sitofp i32 %56 to float
  %58 = fsub float 1.000000e+00, %57
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = icmp sge i32 %59, 0
  br i1 %60, label %61, label %67

61:                                               ; preds = %46
  %62 = load float, ptr %15, align 4, !tbaa !13
  %63 = fmul float -5.000000e-01, %62
  %64 = load float, ptr %15, align 4, !tbaa !13
  %65 = fmul float %63, %64
  %66 = call float @expf(float noundef %65) #5, !tbaa !5
  br label %68

67:                                               ; preds = %46
  br label %68

68:                                               ; preds = %67, %61
  %69 = phi float [ %66, %61 ], [ 1.000000e+00, %67 ]
  %70 = fmul float %58, %69
  %71 = load ptr, ptr %11, align 8, !tbaa !11
  %72 = getelementptr inbounds float, ptr %71, i32 1
  store ptr %72, ptr %11, align 8, !tbaa !11
  store float %70, ptr %71, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  br label %73

73:                                               ; preds = %68
  %74 = load i32, ptr %14, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %14, align 4, !tbaa !5
  br label %41, !llvm.loop !15

76:                                               ; preds = %41
  %77 = load ptr, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  ret ptr %77
}

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

declare ptr @vl_malloc(i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

; Function Attrs: nounwind
declare float @expf(float noundef) #4

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind "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 #5 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!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"

; Function Attrs: nounwind uwtable
define dso_local ptr @_vl_dsift_new_kernel(i32 noundef %0, i32 noundef %1, i32 noundef %2, double noundef %3) local_unnamed_addr #0 {
  %5 = shl nsw i32 %0, 1
  %6 = add nsw i32 %5, -1
  %7 = sext i32 %6 to i64
  %8 = shl nsw i64 %7, 2
  %9 = tail call ptr @vl_malloc(i64 noundef %8) #4
  %10 = sitofp i32 %0 to float
  %11 = sitofp i32 %2 to float
  %12 = add nsw i32 %1, -1
  %13 = sitofp i32 %12 to float
  %14 = tail call float @llvm.fmuladd.f32(float %13, float -5.000000e-01, float %11)
  %15 = fmul float %14, %10
  %16 = fptrunc double %3 to float
  %17 = fmul float %10, %16
  %18 = sub i32 1, %0
  %.not.not22 = icmp slt i32 %18, %0
  br i1 %.not.not22, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %19 = icmp sgt i32 %2, -1
  br i1 %19, label %.lr.ph.split.us, label %.lr.ph.split.prol

.lr.ph.split.prol:                                ; preds = %.lr.ph
  %20 = tail call i32 @llvm.abs.i32(i32 %18, i1 true)
  %21 = sdiv i32 %20, %0
  %22 = sitofp i32 %21 to float
  %23 = fsub float 1.000000e+00, %22
  %24 = getelementptr inbounds i8, ptr %9, i64 4
  store float %23, ptr %9, align 4, !tbaa !5
  %25 = sub i32 2, %0
  %.mask = and i32 %0, 2147483647
  %26 = icmp eq i32 %.mask, 1
  br i1 %26, label %._crit_edge, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.lr.ph.split.us
  %.024.us = phi ptr [ %38, %.lr.ph.split.us ], [ %9, %.lr.ph ]
  %.02123.us = phi i32 [ %39, %.lr.ph.split.us ], [ %18, %.lr.ph ]
  %27 = tail call i32 @llvm.abs.i32(i32 %.02123.us, i1 true)
  %28 = sdiv i32 %27, %0
  %29 = sitofp i32 %28 to float
  %30 = fsub float 1.000000e+00, %29
  %31 = sitofp i32 %.02123.us to float
  %32 = fsub float %31, %15
  %33 = fdiv float %32, %17
  %34 = fmul float %33, -5.000000e-01
  %35 = fmul float %33, %34
  %36 = tail call float @expf(float noundef %35) #4, !tbaa !9
  %37 = fmul float %30, %36
  %38 = getelementptr inbounds i8, ptr %.024.us, i64 4
  store float %37, ptr %.024.us, align 4, !tbaa !5
  %39 = add nsw i32 %.02123.us, 1
  %exitcond26.not = icmp eq i32 %39, %0
  br i1 %exitcond26.not, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !11

.lr.ph.split:                                     ; preds = %.lr.ph.split.prol, %.lr.ph.split
  %.024 = phi ptr [ %50, %.lr.ph.split ], [ %24, %.lr.ph.split.prol ]
  %.02123 = phi i32 [ %51, %.lr.ph.split ], [ %25, %.lr.ph.split.prol ]
  %40 = tail call i32 @llvm.abs.i32(i32 %.02123, i1 true)
  %41 = sdiv i32 %40, %0
  %42 = sitofp i32 %41 to float
  %43 = fsub float 1.000000e+00, %42
  %44 = getelementptr inbounds i8, ptr %.024, i64 4
  store float %43, ptr %.024, align 4, !tbaa !5
  %45 = add nsw i32 %.02123, 1
  %46 = tail call i32 @llvm.abs.i32(i32 %45, i1 true)
  %47 = sdiv i32 %46, %0
  %48 = sitofp i32 %47 to float
  %49 = fsub float 1.000000e+00, %48
  %50 = getelementptr inbounds i8, ptr %.024, i64 8
  store float %49, ptr %44, align 4, !tbaa !5
  %51 = add nsw i32 %.02123, 2
  %exitcond.not.1 = icmp eq i32 %51, %0
  br i1 %exitcond.not.1, label %._crit_edge, label %.lr.ph.split, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph.split.prol, %.lr.ph.split, %.lr.ph.split.us, %4
  ret ptr %9
}

declare ptr @vl_malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @expf(float noundef) local_unnamed_addr #3

attributes #0 = { 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 #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { mustprogress nofree nounwind willreturn memory(write) "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 #4 = { 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass