; LLVM IR from keroro824/HashingDeepLearning :: SLIDE/srp.ll (ZN22SparseRandomProjection7getHashEPfi)

; 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.SparseRandomProjection = type { i64, i64, i64, ptr, ptr }

; 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 speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #1

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN22SparseRandomProjection7getHashEPfi(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1, i32 noundef %2) #3 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca i64, align 8
  %12 = alloca float, align 4
  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
  %13 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %14 = getelementptr inbounds %class.SparseRandomProjection, ptr %13, i32 0, i32 1
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %15, i64 4)
  %17 = extractvalue { i64, i1 } %16, 1
  %18 = extractvalue { i64, i1 } %16, 0
  %19 = select i1 %17, i64 -1, i64 %18
  %20 = call noalias noundef nonnull ptr @_Znam(i64 noundef %19) #5
  store ptr %20, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !14
  br label %21

21:                                               ; preds = %79, %3
  %22 = load i64, ptr %8, align 8, !tbaa !14
  %23 = getelementptr inbounds %class.SparseRandomProjection, ptr %13, i32 0, i32 1
  %24 = load i64, ptr %23, align 8, !tbaa !11
  %25 = icmp ult i64 %22, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %21
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %82

27:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store double 0.000000e+00, ptr %10, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !14
  br label %28

28:                                               ; preds = %68, %27
  %29 = load i64, ptr %11, align 8, !tbaa !14
  %30 = getelementptr inbounds %class.SparseRandomProjection, ptr %13, i32 0, i32 2
  %31 = load i64, ptr %30, align 8, !tbaa !17
  %32 = icmp ult i64 %29, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %28
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %71

34:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %class.SparseRandomProjection, ptr %13, i32 0, i32 4
  %37 = load ptr, ptr %36, align 8, !tbaa !18
  %38 = load i64, ptr %8, align 8, !tbaa !14
  %39 = getelementptr inbounds ptr, ptr %37, i64 %38
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  %41 = load i64, ptr %11, align 8, !tbaa !14
  %42 = getelementptr inbounds i32, ptr %40, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds float, ptr %35, i64 %44
  %46 = load float, ptr %45, align 4, !tbaa !19
  store float %46, ptr %12, align 4, !tbaa !19
  %47 = getelementptr inbounds %class.SparseRandomProjection, ptr %13, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !21
  %49 = load i64, ptr %8, align 8, !tbaa !14
  %50 = getelementptr inbounds ptr, ptr %48, i64 %49
  %51 = load ptr, ptr %50, align 8, !tbaa !5
  %52 = load i64, ptr %11, align 8, !tbaa !14
  %53 = getelementptr inbounds i16, ptr %51, i64 %52
  %54 = load i16, ptr %53, align 2, !tbaa !22
  %55 = sext i16 %54 to i32
  %56 = icmp sge i32 %55, 0
  br i1 %56, label %57, label %62

57:                                               ; preds = %34
  %58 = load float, ptr %12, align 4, !tbaa !19
  %59 = fpext float %58 to double
  %60 = load double, ptr %10, align 8, !tbaa !15
  %61 = fadd double %60, %59
  store double %61, ptr %10, align 8, !tbaa !15
  br label %67

62:                                               ; preds = %34
  %63 = load float, ptr %12, align 4, !tbaa !19
  %64 = fpext float %63 to double
  %65 = load double, ptr %10, align 8, !tbaa !15
  %66 = fsub double %65, %64
  store double %66, ptr %10, align 8, !tbaa !15
  br label %67

67:                                               ; preds = %62, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %68

68:                                               ; preds = %67
  %69 = load i64, ptr %11, align 8, !tbaa !14
  %70 = add i64 %69, 1
  store i64 %70, ptr %11, align 8, !tbaa !14
  br label %28, !llvm.loop !24

71:                                               ; preds = %33
  %72 = load double, ptr %10, align 8, !tbaa !15
  %73 = fcmp oge double %72, 0.000000e+00
  %74 = zext i1 %73 to i64
  %75 = select i1 %73, i32 0, i32 1
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = load i64, ptr %8, align 8, !tbaa !14
  %78 = getelementptr inbounds i32, ptr %76, i64 %77
  store i32 %75, ptr %78, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %79

79:                                               ; preds = %71
  %80 = load i64, ptr %8, align 8, !tbaa !14
  %81 = add i64 %80, 1
  store i64 %81, ptr %8, align 8, !tbaa !14
  br label %21, !llvm.loop !26

82:                                               ; preds = %26
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret ptr %83
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nobuiltin allocsize(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 #3 = { 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 #4 = { nounwind }
attributes #5 = { builtin allocsize(0) }

!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, !13, i64 8}
!12 = !{!"_ZTS22SparseRandomProjection", !13, i64 0, !13, i64 8, !13, i64 16, !6, i64 24, !6, i64 32}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = !{!12, !13, i64 16}
!18 = !{!12, !6, i64 32}
!19 = !{!20, !20, i64 0}
!20 = !{!"float", !7, i64 0}
!21 = !{!12, !6, i64 24}
!22 = !{!23, !23, i64 0}
!23 = !{!"short", !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = distinct !{!26, !25}


; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noalias noundef nonnull ptr @_ZN22SparseRandomProjection7getHashEPfi(ptr nocapture noundef nonnull readonly align 8 dereferenceable(40) %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = icmp ugt i64 %5, 4611686018427387903
  %7 = shl i64 %5, 2
  %8 = select i1 %6, i64 -1, i64 %7
  %9 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %8) #3
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %._crit_edge22, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %.not23 = icmp eq i64 %11, 0
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  %13 = load ptr, ptr %12, align 8
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  %15 = load ptr, ptr %14, align 8
  br i1 %.not23, label %.preheader.preheader, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %xtraiter = and i64 %11, 1
  %16 = icmp eq i64 %11, 1
  %unroll_iter = and i64 %11, -2
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.preheader:                             ; preds = %.preheader.lr.ph
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 %9, i8 0, i64 %7, i1 false), !tbaa !12
  br label %._crit_edge22

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.021.us = phi i64 [ %56, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %17 = getelementptr inbounds ptr, ptr %13, i64 %.021.us
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = getelementptr inbounds ptr, ptr %15, i64 %.021.us
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  br i1 %16, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %.01720.us = phi i64 [ %42, %.preheader.us.new ], [ 0, %.preheader.us ]
  %.01819.us = phi double [ %.1.us.1, %.preheader.us.new ], [ 0.000000e+00, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %21 = getelementptr inbounds i32, ptr %18, i64 %.01720.us
  %22 = load i32, ptr %21, align 4, !tbaa !12
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds float, ptr %1, i64 %23
  %25 = load float, ptr %24, align 4, !tbaa !15
  %26 = getelementptr inbounds i16, ptr %20, i64 %.01720.us
  %27 = load i16, ptr %26, align 2, !tbaa !17
  %28 = fpext float %25 to double
  %29 = icmp slt i16 %27, 0
  %30 = fneg double %28
  %.1.p.us = select i1 %29, double %30, double %28
  %.1.us = fadd double %.01819.us, %.1.p.us
  %31 = or disjoint i64 %.01720.us, 1
  %32 = getelementptr inbounds i32, ptr %18, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !12
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds float, ptr %1, i64 %34
  %36 = load float, ptr %35, align 4, !tbaa !15
  %37 = getelementptr inbounds i16, ptr %20, i64 %31
  %38 = load i16, ptr %37, align 2, !tbaa !17
  %39 = fpext float %36 to double
  %40 = icmp slt i16 %38, 0
  %41 = fneg double %39
  %.1.p.us.1 = select i1 %40, double %41, double %39
  %.1.us.1 = fadd double %.1.us, %.1.p.us.1
  %42 = add nuw i64 %.01720.us, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !19

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %.1.us.lcssa.ph = phi double [ poison, %.preheader.us ], [ %.1.us.1, %.preheader.us.new ]
  %.01720.us.unr = phi i64 [ 0, %.preheader.us ], [ %42, %.preheader.us.new ]
  %.01819.us.unr = phi double [ 0.000000e+00, %.preheader.us ], [ %.1.us.1, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %43 = getelementptr inbounds i32, ptr %18, i64 %.01720.us.unr
  %44 = load i32, ptr %43, align 4, !tbaa !12
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds float, ptr %1, i64 %45
  %47 = load float, ptr %46, align 4, !tbaa !15
  %48 = getelementptr inbounds i16, ptr %20, i64 %.01720.us.unr
  %49 = load i16, ptr %48, align 2, !tbaa !17
  %50 = fpext float %47 to double
  %51 = icmp slt i16 %49, 0
  %52 = fneg double %50
  %.1.p.us.epil = select i1 %51, double %52, double %50
  %.1.us.epil = fadd double %.01819.us.unr, %.1.p.us.epil
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %.1.us.lcssa = phi double [ %.1.us.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %.1.us.epil, %._crit_edge.us.epilog-lcssa ]
  %53 = fcmp ult double %.1.us.lcssa, 0.000000e+00
  %54 = zext i1 %53 to i32
  %55 = getelementptr inbounds i32, ptr %9, i64 %.021.us
  store i32 %54, ptr %55, align 4, !tbaa !12
  %56 = add nuw i64 %.021.us, 1
  %exitcond25.not = icmp eq i64 %56, %5
  br i1 %exitcond25.not, label %._crit_edge22, label %.preheader.us, !llvm.loop !21

._crit_edge22:                                    ; preds = %._crit_edge.us, %.preheader.preheader, %3
  ret ptr %9
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { nobuiltin allocsize(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 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { builtin allocsize(0) }

!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, !7, i64 8}
!6 = !{!"_ZTS22SparseRandomProjection", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 32}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 16}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!10, !10, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !8, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"short", !8, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass