; LLVM IR from suxiaojack/sapDecoder :: src/convert.ll (Z11Float2ShortPsPKfi)

; 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
define dso_local noundef i32 @_Z11Float2ShortPsPKfi(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  store double 3.276800e+04, ptr %11, align 8, !tbaa !11
  br label %15

15:                                               ; preds = %81, %3
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %82

19:                                               ; preds = %15
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = sub nsw i32 %20, %21
  %23 = icmp slt i32 4096, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %19
  br label %29

25:                                               ; preds = %19
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = sub nsw i32 %26, %27
  br label %29

29:                                               ; preds = %25, %24
  %30 = phi i32 [ 4096, %24 ], [ %28, %25 ]
  store i32 %30, ptr %8, align 4, !tbaa !9
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %69, %29
  %32 = load i32, ptr %10, align 4, !tbaa !9
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %35, label %72

35:                                               ; preds = %31
  %36 = load double, ptr %11, align 8, !tbaa !11
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load i32, ptr %10, align 4, !tbaa !9
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = add nsw i32 %38, %39
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds float, ptr %37, i64 %41
  %43 = load float, ptr %42, align 4, !tbaa !13
  %44 = fpext float %43 to double
  %45 = fmul double %36, %44
  store double %45, ptr %12, align 8, !tbaa !11
  %46 = load double, ptr %12, align 8, !tbaa !11
  %47 = fcmp oge double %46, 0.000000e+00
  br i1 %47, label %48, label %55

48:                                               ; preds = %35
  %49 = load double, ptr %12, align 8, !tbaa !11
  %50 = fadd double %49, 5.000000e-01
  store double %50, ptr %12, align 8, !tbaa !11
  %51 = load double, ptr %12, align 8, !tbaa !11
  %52 = fcmp oge double %51, 3.276800e+04
  br i1 %52, label %53, label %54

53:                                               ; preds = %48
  store double 3.276700e+04, ptr %12, align 8, !tbaa !11
  br label %54

54:                                               ; preds = %53, %48
  br label %62

55:                                               ; preds = %35
  %56 = load double, ptr %12, align 8, !tbaa !11
  %57 = fadd double %56, -5.000000e-01
  store double %57, ptr %12, align 8, !tbaa !11
  %58 = load double, ptr %12, align 8, !tbaa !11
  %59 = fcmp ole double %58, -3.276900e+04
  br i1 %59, label %60, label %61

60:                                               ; preds = %55
  store double -3.276800e+04, ptr %12, align 8, !tbaa !11
  br label %61

61:                                               ; preds = %60, %55
  br label %62

62:                                               ; preds = %61, %54
  %63 = load double, ptr %12, align 8, !tbaa !11
  %64 = fptosi double %63 to i16
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = load i32, ptr %10, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds i16, ptr %65, i64 %67
  store i16 %64, ptr %68, align 2, !tbaa !15
  br label %69

69:                                               ; preds = %62
  %70 = load i32, ptr %10, align 4, !tbaa !9
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %10, align 4, !tbaa !9
  br label %31, !llvm.loop !17

72:                                               ; preds = %31
  %73 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %73, ptr %9, align 4, !tbaa !9
  %74 = load i32, ptr %9, align 4, !tbaa !9
  %75 = load i32, ptr %7, align 4, !tbaa !9
  %76 = add nsw i32 %75, %74
  store i32 %76, ptr %7, align 4, !tbaa !9
  %77 = load i32, ptr %9, align 4, !tbaa !9
  %78 = load i32, ptr %8, align 4, !tbaa !9
  %79 = icmp slt i32 %77, %78
  br i1 %79, label %80, label %81

80:                                               ; preds = %72
  br label %82

81:                                               ; preds = %72
  br label %15, !llvm.loop !19

82:                                               ; preds = %80, %15
  %83 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret i32 %83
}

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 = !{!"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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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 nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local noundef i32 @_Z11Float2ShortPsPKfi(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %2, 0
  br i1 %4, label %.lr.ph37, label %._crit_edge38

.lr.ph37:                                         ; preds = %3, %._crit_edge
  %.035 = phi i32 [ %38, %._crit_edge ], [ 0, %3 ]
  %5 = sub nsw i32 %2, %.035
  %6 = tail call i32 @llvm.smin.i32(i32 %5, i32 4096)
  %7 = icmp sgt i32 %5, 0
  br i1 %7, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.lr.ph37
  %8 = sext i32 %.035 to i64
  %smax = tail call i32 @llvm.smax.i32(i32 %6, i32 1)
  %wide.trip.count = zext nneg i32 %smax to i64
  %invariant.gep = getelementptr float, ptr %1, i64 %8
  %min.iters.check = icmp slt i32 %5, 4
  br i1 %min.iters.check, label %.lr.ph.preheader43, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %wide.trip.count, 8188
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %9 = getelementptr float, ptr %invariant.gep, i64 %index
  %wide.load = load <4 x float>, ptr %9, align 4, !tbaa !5
  %10 = fpext <4 x float> %wide.load to <4 x double>
  %11 = fmul <4 x double> %10, <double 3.276800e+04, double 3.276800e+04, double 3.276800e+04, double 3.276800e+04>
  %12 = fcmp ult <4 x double> %11, zeroinitializer
  %13 = fadd <4 x double> %11, <double 5.000000e-01, double 5.000000e-01, double 5.000000e-01, double 5.000000e-01>
  %14 = fcmp oge <4 x double> %13, <double 3.276800e+04, double 3.276800e+04, double 3.276800e+04, double 3.276800e+04>
  %15 = fadd <4 x double> %11, <double -5.000000e-01, double -5.000000e-01, double -5.000000e-01, double -5.000000e-01>
  %16 = fcmp ugt <4 x double> %15, <double -3.276900e+04, double -3.276900e+04, double -3.276900e+04, double -3.276900e+04>
  %17 = xor <4 x i1> %16, <i1 true, i1 true, i1 true, i1 true>
  %18 = select <4 x i1> %12, <4 x i1> %17, <4 x i1> zeroinitializer
  %19 = and <4 x i1> %12, %16
  %.not42 = or <4 x i1> %14, %12
  %predphi = select <4 x i1> %.not42, <4 x double> <double 3.276700e+04, double 3.276700e+04, double 3.276700e+04, double 3.276700e+04>, <4 x double> %13
  %predphi40 = select <4 x i1> %18, <4 x double> <double -3.276800e+04, double -3.276800e+04, double -3.276800e+04, double -3.276800e+04>, <4 x double> %predphi
  %predphi41 = select <4 x i1> %19, <4 x double> %15, <4 x double> %predphi40
  %20 = fptosi <4 x double> %predphi41 to <4 x i16>
  %21 = getelementptr inbounds i16, ptr %0, i64 %index
  store <4 x i16> %20, ptr %21, align 2, !tbaa !9
  %index.next = add nuw i64 %index, 4
  %22 = icmp eq i64 %index.next, %n.vec
  br i1 %22, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader43

.lr.ph.preheader43:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader43, %35
  %indvars.iv = phi i64 [ %indvars.iv.next, %35 ], [ %indvars.iv.ph, %.lr.ph.preheader43 ]
  %gep = getelementptr float, ptr %invariant.gep, i64 %indvars.iv
  %23 = load float, ptr %gep, align 4, !tbaa !5
  %24 = fpext float %23 to double
  %25 = fmul double %24, 3.276800e+04
  %26 = fcmp ult double %25, 0.000000e+00
  br i1 %26, label %31, label %27

27:                                               ; preds = %.lr.ph
  %28 = fadd double %25, 5.000000e-01
  %29 = fcmp ult double %28, 3.276800e+04
  br i1 %29, label %35, label %30

30:                                               ; preds = %27
  br label %35

31:                                               ; preds = %.lr.ph
  %32 = fadd double %25, -5.000000e-01
  %33 = fcmp ugt double %32, -3.276900e+04
  br i1 %33, label %35, label %34

34:                                               ; preds = %31
  br label %35

35:                                               ; preds = %31, %34, %27, %30
  %.027 = phi double [ 3.276700e+04, %30 ], [ %28, %27 ], [ -3.276800e+04, %34 ], [ %32, %31 ]
  %36 = fptosi double %.027 to i16
  %37 = getelementptr inbounds i16, ptr %0, i64 %indvars.iv
  store i16 %36, ptr %37, align 2, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %35, %middle.block, %.lr.ph37
  %38 = add nsw i32 %6, %.035
  %39 = icmp slt i32 %38, %2
  br i1 %39, label %.lr.ph37, label %._crit_edge38

._crit_edge38:                                    ; preds = %._crit_edge, %3
  %.0.lcssa = phi i32 [ 0, %3 ], [ %38, %._crit_edge ]
  ret i32 %.0.lcssa
}

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

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12, !14, !13}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass