; LLVM IR from QiaoLiuHit/LSOTB-TIR :: vlfeat-0.9.19/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 = %74, %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 %77

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 = sitofp i32 %53 to float
  %55 = call float @llvm.fabs.f32(float %54)
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = sitofp i32 %56 to float
  %58 = fdiv float %55, %57
  %59 = fsub float 1.000000e+00, %58
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = icmp sge i32 %60, 0
  br i1 %61, label %62, label %68

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

68:                                               ; preds = %46
  br label %69

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

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

77:                                               ; preds = %41
  %78 = 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 %78
}

; 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 float @llvm.fabs.f32(float) #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) #5
  %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.preheader

.lr.ph.split.preheader:                           ; preds = %.lr.ph
  %20 = shl i32 %0, 1
  %21 = add i32 %20, -1
  %min.iters.check = icmp ult i32 %21, 4
  br i1 %min.iters.check, label %.lr.ph.split.preheader31, label %vector.ph

.lr.ph.split.preheader31:                         ; preds = %vector.body, %.lr.ph.split.preheader
  %.024.ph = phi ptr [ %9, %.lr.ph.split.preheader ], [ %ind.end, %vector.body ]
  %.02123.ph = phi i32 [ %18, %.lr.ph.split.preheader ], [ %ind.end29, %vector.body ]
  br label %.lr.ph.split

vector.ph:                                        ; preds = %.lr.ph.split.preheader
  %22 = and i32 %21, -4
  %n.vec = zext i32 %22 to i64
  %23 = shl nuw nsw i64 %n.vec, 2
  %ind.end = getelementptr i8, ptr %9, i64 %23
  %ind.end29 = add i32 %18, %22
  %.splatinsert = insertelement <4 x i32> poison, i32 %18, i64 0
  %.splat = shufflevector <4 x i32> %.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  %induction = add <4 x i32> %.splat, <i32 0, i32 1, i32 2, i32 3>
  %broadcast.splatinsert = insertelement <4 x float> poison, float %10, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <4 x i32> [ %induction, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %offset.idx = shl i64 %index, 2
  %next.gep = getelementptr i8, ptr %9, i64 %offset.idx
  %24 = sitofp <4 x i32> %vec.ind to <4 x float>
  %25 = tail call <4 x float> @llvm.fabs.v4f32(<4 x float> %24)
  %26 = fdiv <4 x float> %25, %broadcast.splat
  %27 = fsub <4 x float> <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>, %26
  store <4 x float> %27, ptr %next.gep, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %vec.ind.next = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4>
  %28 = icmp eq i64 %index.next, %n.vec
  br i1 %28, label %.lr.ph.split.preheader31, label %vector.body, !llvm.loop !9

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

.lr.ph.split:                                     ; preds = %.lr.ph.split.preheader31, %.lr.ph.split
  %.024 = phi ptr [ %45, %.lr.ph.split ], [ %.024.ph, %.lr.ph.split.preheader31 ]
  %.02123 = phi i32 [ %46, %.lr.ph.split ], [ %.02123.ph, %.lr.ph.split.preheader31 ]
  %41 = sitofp i32 %.02123 to float
  %42 = tail call float @llvm.fabs.f32(float %41)
  %43 = fdiv float %42, %10
  %44 = fsub float 1.000000e+00, %43
  %45 = getelementptr inbounds i8, ptr %.024, i64 4
  store float %44, ptr %.024, align 4, !tbaa !5
  %46 = add nsw i32 %.02123, 1
  %exitcond.not = icmp eq i32 %46, %0
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph.split, !llvm.loop !16

._crit_edge:                                      ; preds = %.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 float @llvm.fabs.f32(float) #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x float> @llvm.fabs.v4f32(<4 x float>) #4

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10, !12, !11}


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