; LLVM IR from DataManagementLab/ScaleStore :: backend/scalestore/utils/ZipfGenerator.ll (ZN10scalestore5utils13ZipfGenerator4randEv)

; 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.scalestore::utils::ZipfGenerator" = type { i64, double, double, double, double }

; 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: nounwind
declare double @pow(double noundef, double noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN10scalestore5utils13ZipfGenerator4randEv(ptr noundef nonnull align 8 dereferenceable(40) %0) #2 align 2 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca i64, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store double 1.000000e+18, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %11 = call noundef i64 @_ZN10scalestore5utils15RandomGenerator10getRandU64Emm(i64 noundef 0, i64 noundef 1000000000000000001)
  store i64 %11, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %12 = load i64, ptr %5, align 8, !tbaa !11
  %13 = uitofp i64 %12 to double
  %14 = load double, ptr %4, align 8, !tbaa !9
  %15 = fdiv double %13, %14
  store double %15, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %16 = load double, ptr %6, align 8, !tbaa !9
  %17 = getelementptr inbounds %"class.scalestore::utils::ZipfGenerator", ptr %10, i32 0, i32 3
  %18 = load double, ptr %17, align 8, !tbaa !13
  %19 = fmul double %16, %18
  store double %19, ptr %7, align 8, !tbaa !9
  %20 = load double, ptr %7, align 8, !tbaa !9
  %21 = fcmp olt double %20, 1.000000e+00
  br i1 %21, label %22, label %23

22:                                               ; preds = %1
  store i64 1, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %50

23:                                               ; preds = %1
  %24 = load double, ptr %7, align 8, !tbaa !9
  %25 = getelementptr inbounds %"class.scalestore::utils::ZipfGenerator", ptr %10, i32 0, i32 1
  %26 = load double, ptr %25, align 8, !tbaa !15
  %27 = call double @pow(double noundef 5.000000e-01, double noundef %26) #4
  %28 = fadd double 1.000000e+00, %27
  %29 = fcmp olt double %24, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %23
  store i64 2, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %50

31:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %32 = getelementptr inbounds %"class.scalestore::utils::ZipfGenerator", ptr %10, i32 0, i32 0
  %33 = load i64, ptr %32, align 8, !tbaa !16
  %34 = uitofp i64 %33 to double
  %35 = getelementptr inbounds %"class.scalestore::utils::ZipfGenerator", ptr %10, i32 0, i32 4
  %36 = load double, ptr %35, align 8, !tbaa !17
  %37 = load double, ptr %6, align 8, !tbaa !9
  %38 = getelementptr inbounds %"class.scalestore::utils::ZipfGenerator", ptr %10, i32 0, i32 4
  %39 = load double, ptr %38, align 8, !tbaa !17
  %40 = fneg double %39
  %41 = call double @llvm.fmuladd.f64(double %36, double %37, double %40)
  %42 = fadd double %41, 1.000000e+00
  %43 = getelementptr inbounds %"class.scalestore::utils::ZipfGenerator", ptr %10, i32 0, i32 2
  %44 = load double, ptr %43, align 8, !tbaa !18
  %45 = call double @pow(double noundef %42, double noundef %44) #4
  %46 = fmul double %34, %45
  %47 = fptosi double %46 to i64
  %48 = add nsw i64 1, %47
  store i64 %48, ptr %9, align 8, !tbaa !11
  %49 = load i64, ptr %9, align 8, !tbaa !11
  store i64 %49, ptr %2, align 8
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %50

50:                                               ; preds = %31, %30, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %51 = load i64, ptr %2, align 8
  ret i64 %51
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN10scalestore5utils15RandomGenerator10getRandU64Emm(i64 noundef, i64 noundef) #2 align 2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 24}
!14 = !{!"_ZTSN10scalestore5utils13ZipfGeneratorE", !12, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!15 = !{!14, !10, i64 8}
!16 = !{!14, !12, i64 0}
!17 = !{!14, !10, i64 32}
!18 = !{!14, !10, i64 16}


; 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 nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i64 -9223372036854775807, -9223372036854775808) i64 @_ZN10scalestore5utils13ZipfGenerator4randEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(40) %0) local_unnamed_addr #1 align 2 {
  %2 = tail call noundef i64 @_ZN10scalestore5utils15RandomGenerator10getRandU64Emm(i64 noundef 0, i64 noundef 1000000000000000001)
  %3 = uitofp i64 %2 to double
  %4 = fdiv double %3, 1.000000e+18
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load double, ptr %5, align 8, !tbaa !5
  %7 = fmul double %6, %4
  %8 = fcmp olt double %7, 1.000000e+00
  br i1 %8, label %28, label %9

9:                                                ; preds = %1
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load double, ptr %10, align 8, !tbaa !11
  %mul = fneg double %11
  %exp2 = tail call double @exp2(double %mul)
  %12 = fadd double %exp2, 1.000000e+00
  %13 = fcmp olt double %7, %12
  br i1 %13, label %28, label %14

14:                                               ; preds = %9
  %15 = load i64, ptr %0, align 8, !tbaa !12
  %16 = uitofp i64 %15 to double
  %17 = getelementptr inbounds i8, ptr %0, i64 32
  %18 = load double, ptr %17, align 8, !tbaa !13
  %19 = fneg double %18
  %20 = tail call double @llvm.fmuladd.f64(double %18, double %4, double %19)
  %21 = fadd double %20, 1.000000e+00
  %22 = getelementptr inbounds i8, ptr %0, i64 16
  %23 = load double, ptr %22, align 8, !tbaa !14
  %24 = tail call double @pow(double noundef %21, double noundef %23) #3
  %25 = fmul double %24, %16
  %26 = fptosi double %25 to i64
  %27 = add nsw i64 %26, 1
  br label %28

28:                                               ; preds = %9, %1, %14
  %.0 = phi i64 [ %27, %14 ], [ 1, %1 ], [ 2, %9 ]
  ret i64 %.0
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN10scalestore5utils15RandomGenerator10getRandU64Emm(i64 noundef, i64 noundef) local_unnamed_addr #1 align 2

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

declare double @exp2(double) local_unnamed_addr

attributes #0 = { 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 #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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, !10, i64 24}
!6 = !{!"_ZTSN10scalestore5utils13ZipfGeneratorE", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !10, i64 32}
!14 = !{!6, !10, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass