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

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

23:                                               ; preds = %116, %4
  %24 = load i64, ptr %10, align 8, !tbaa !9
  %25 = getelementptr inbounds %class.SparseRandomProjection, ptr %15, i32 0, i32 1
  %26 = load i64, ptr %25, align 8, !tbaa !11
  %27 = icmp ult i64 %24, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %119

29:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store double 0.000000e+00, ptr %11, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  store i64 0, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %107, %29
  %31 = load i64, ptr %12, align 8, !tbaa !9
  %32 = load i64, ptr %8, align 8, !tbaa !9
  %33 = icmp ult i64 %31, %32
  %34 = zext i1 %33 to i32
  %35 = load i64, ptr %13, align 8, !tbaa !9
  %36 = getelementptr inbounds %class.SparseRandomProjection, ptr %15, i32 0, i32 2
  %37 = load i64, ptr %36, align 8, !tbaa !15
  %38 = icmp ult i64 %35, %37
  %39 = zext i1 %38 to i32
  %40 = and i32 %34, %39
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %108

42:                                               ; preds = %30
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load i64, ptr %12, align 8, !tbaa !9
  %45 = getelementptr inbounds i32, ptr %43, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !16
  %47 = getelementptr inbounds %class.SparseRandomProjection, ptr %15, i32 0, i32 4
  %48 = load ptr, ptr %47, align 8, !tbaa !18
  %49 = load i64, ptr %10, align 8, !tbaa !9
  %50 = getelementptr inbounds ptr, ptr %48, i64 %49
  %51 = load ptr, ptr %50, align 8, !tbaa !5
  %52 = load i64, ptr %13, align 8, !tbaa !9
  %53 = getelementptr inbounds i32, ptr %51, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !16
  %55 = icmp eq i32 %46, %54
  br i1 %55, label %56, label %86

56:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = load i64, ptr %12, align 8, !tbaa !9
  %59 = getelementptr inbounds float, ptr %57, i64 %58
  %60 = load float, ptr %59, align 4, !tbaa !19
  store float %60, ptr %14, align 4, !tbaa !19
  %61 = getelementptr inbounds %class.SparseRandomProjection, ptr %15, i32 0, i32 3
  %62 = load ptr, ptr %61, align 8, !tbaa !21
  %63 = load i64, ptr %10, align 8, !tbaa !9
  %64 = getelementptr inbounds ptr, ptr %62, i64 %63
  %65 = load ptr, ptr %64, align 8, !tbaa !5
  %66 = load i64, ptr %13, align 8, !tbaa !9
  %67 = getelementptr inbounds i16, ptr %65, i64 %66
  %68 = load i16, ptr %67, align 2, !tbaa !22
  %69 = sext i16 %68 to i32
  %70 = icmp sge i32 %69, 0
  br i1 %70, label %71, label %76

71:                                               ; preds = %56
  %72 = load float, ptr %14, align 4, !tbaa !19
  %73 = fpext float %72 to double
  %74 = load double, ptr %11, align 8, !tbaa !13
  %75 = fadd double %74, %73
  store double %75, ptr %11, align 8, !tbaa !13
  br label %81

76:                                               ; preds = %56
  %77 = load float, ptr %14, align 4, !tbaa !19
  %78 = fpext float %77 to double
  %79 = load double, ptr %11, align 8, !tbaa !13
  %80 = fsub double %79, %78
  store double %80, ptr %11, align 8, !tbaa !13
  br label %81

81:                                               ; preds = %76, %71
  %82 = load i64, ptr %12, align 8, !tbaa !9
  %83 = add i64 %82, 1
  store i64 %83, ptr %12, align 8, !tbaa !9
  %84 = load i64, ptr %13, align 8, !tbaa !9
  %85 = add i64 %84, 1
  store i64 %85, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %107

86:                                               ; preds = %42
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = load i64, ptr %12, align 8, !tbaa !9
  %89 = getelementptr inbounds i32, ptr %87, i64 %88
  %90 = load i32, ptr %89, align 4, !tbaa !16
  %91 = getelementptr inbounds %class.SparseRandomProjection, ptr %15, i32 0, i32 4
  %92 = load ptr, ptr %91, align 8, !tbaa !18
  %93 = load i64, ptr %10, align 8, !tbaa !9
  %94 = getelementptr inbounds ptr, ptr %92, i64 %93
  %95 = load ptr, ptr %94, align 8, !tbaa !5
  %96 = load i64, ptr %13, align 8, !tbaa !9
  %97 = getelementptr inbounds i32, ptr %95, i64 %96
  %98 = load i32, ptr %97, align 4, !tbaa !16
  %99 = icmp slt i32 %90, %98
  br i1 %99, label %100, label %103

100:                                              ; preds = %86
  %101 = load i64, ptr %12, align 8, !tbaa !9
  %102 = add i64 %101, 1
  store i64 %102, ptr %12, align 8, !tbaa !9
  br label %106

103:                                              ; preds = %86
  %104 = load i64, ptr %13, align 8, !tbaa !9
  %105 = add i64 %104, 1
  store i64 %105, ptr %13, align 8, !tbaa !9
  br label %106

106:                                              ; preds = %103, %100
  br label %107

107:                                              ; preds = %106, %81
  br label %30, !llvm.loop !24

108:                                              ; preds = %30
  %109 = load double, ptr %11, align 8, !tbaa !13
  %110 = fcmp oge double %109, 0.000000e+00
  %111 = zext i1 %110 to i64
  %112 = select i1 %110, i32 0, i32 1
  %113 = load ptr, ptr %9, align 8, !tbaa !5
  %114 = load i64, ptr %10, align 8, !tbaa !9
  %115 = getelementptr inbounds i32, ptr %113, i64 %114
  store i32 %112, ptr %115, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %116

116:                                              ; preds = %108
  %117 = load i64, ptr %10, align 8, !tbaa !9
  %118 = add i64 %117, 1
  store i64 %118, ptr %10, align 8, !tbaa !9
  br label %23, !llvm.loop !26

119:                                              ; preds = %28
  %120 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret ptr %120
}

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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTS22SparseRandomProjection", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !6, i64 32}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!12, !10, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}
!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 @_ZN22SparseRandomProjection13getHashSparseEPiPfm(ptr nocapture noundef nonnull readonly align 8 dereferenceable(40) %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, i64 noundef %3) local_unnamed_addr #1 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = icmp ugt i64 %6, 4611686018427387903
  %8 = shl i64 %6, 2
  %9 = select i1 %7, i64 -1, i64 %8
  %10 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %9) #3
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %._crit_edge40, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %4
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = icmp ne i64 %3, 0
  %14 = icmp ne i64 %12, 0
  %15 = and i1 %13, %14
  %16 = getelementptr inbounds i8, ptr %0, i64 32
  %17 = load ptr, ptr %16, align 8
  %18 = getelementptr inbounds i8, ptr %0, i64 24
  %19 = load ptr, ptr %18, align 8
  br i1 %15, label %.preheader.us, label %.preheader.preheader

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

.preheader.us:                                    ; preds = %.preheader.lr.ph, %._crit_edge.us
  %.039.us = phi i64 [ %53, %._crit_edge.us ], [ 0, %.preheader.lr.ph ]
  %20 = getelementptr inbounds ptr, ptr %17, i64 %.039.us
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = getelementptr inbounds ptr, ptr %19, i64 %.039.us
  br label %23

23:                                               ; preds = %.preheader.us, %46
  %.02938.us = phi i64 [ 0, %.preheader.us ], [ %.1.us, %46 ]
  %.03037.us = phi i64 [ 0, %.preheader.us ], [ %.131.us, %46 ]
  %.03236.us = phi double [ 0.000000e+00, %.preheader.us ], [ %.2.us, %46 ]
  %24 = getelementptr inbounds i32, ptr %1, i64 %.03037.us
  %25 = load i32, ptr %24, align 4, !tbaa !12
  %26 = getelementptr inbounds i32, ptr %21, i64 %.02938.us
  %27 = load i32, ptr %26, align 4, !tbaa !12
  %28 = icmp eq i32 %25, %27
  br i1 %28, label %35, label %29

29:                                               ; preds = %23
  %30 = icmp slt i32 %25, %27
  br i1 %30, label %33, label %31

31:                                               ; preds = %29
  %32 = add nuw i64 %.02938.us, 1
  br label %46

33:                                               ; preds = %29
  %34 = add nuw i64 %.03037.us, 1
  br label %46

35:                                               ; preds = %23
  %36 = getelementptr inbounds float, ptr %2, i64 %.03037.us
  %37 = load float, ptr %36, align 4, !tbaa !15
  %38 = load ptr, ptr %22, align 8, !tbaa !14
  %39 = getelementptr inbounds i16, ptr %38, i64 %.02938.us
  %40 = load i16, ptr %39, align 2, !tbaa !17
  %41 = fpext float %37 to double
  %42 = icmp slt i16 %40, 0
  %43 = fneg double %41
  %.133.p.us = select i1 %42, double %43, double %41
  %.133.us = fadd double %.03236.us, %.133.p.us
  %44 = add nuw i64 %.03037.us, 1
  %45 = add nuw i64 %.02938.us, 1
  br label %46

46:                                               ; preds = %35, %33, %31
  %.2.us = phi double [ %.133.us, %35 ], [ %.03236.us, %33 ], [ %.03236.us, %31 ]
  %.131.us = phi i64 [ %44, %35 ], [ %34, %33 ], [ %.03037.us, %31 ]
  %.1.us = phi i64 [ %45, %35 ], [ %.02938.us, %33 ], [ %32, %31 ]
  %47 = icmp ult i64 %.131.us, %3
  %48 = icmp ult i64 %.1.us, %12
  %49 = and i1 %47, %48
  br i1 %49, label %23, label %._crit_edge.us, !llvm.loop !19

._crit_edge.us:                                   ; preds = %46
  %50 = fcmp ult double %.2.us, 0.000000e+00
  %51 = zext i1 %50 to i32
  %52 = getelementptr inbounds i32, ptr %10, i64 %.039.us
  store i32 %51, ptr %52, align 4, !tbaa !12
  %53 = add nuw i64 %.039.us, 1
  %exitcond.not = icmp eq i64 %53, %6
  br i1 %exitcond.not, label %._crit_edge40, label %.preheader.us, !llvm.loop !21

._crit_edge40:                                    ; preds = %._crit_edge.us, %.preheader.preheader, %4
  ret ptr %10
}

; 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