; LLVM IR from tsotchke/quantum_rng :: tests (benchmark_suite)

; 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"

%struct.function_benchmark = type { ptr, double, double, double, double }

@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @tracked_malloc(i64 noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @tracked_free(ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local double @get_time_us() #0

; Function Attrs: nounwind uwtable
define dso_local void @benchmark_bytes_bulk(ptr dead_on_unwind noalias writable sret(%struct.function_benchmark) align 8 %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %8 = call ptr @tracked_malloc(i64 noundef 1048576)
  store ptr %8, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %9 = call double @get_time_us()
  store double %9, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %10

10:                                               ; preds = %18, %2
  %11 = load i32, ptr %6, align 4, !tbaa !11
  %12 = icmp slt i32 %11, 100
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %21

14:                                               ; preds = %10
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call i32 @qrng_bytes(ptr noundef %15, ptr noundef %16, i64 noundef 1048576)
  br label %18

18:                                               ; preds = %14
  %19 = load i32, ptr %6, align 4, !tbaa !11
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %6, align 4, !tbaa !11
  br label %10, !llvm.loop !13

21:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %22 = call double @get_time_us()
  %23 = load double, ptr %5, align 8, !tbaa !9
  %24 = fsub double %22, %23
  store double %24, ptr %7, align 8, !tbaa !9
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  call void @tracked_free(ptr noundef %25, i64 noundef 1048576)
  %26 = getelementptr inbounds %struct.function_benchmark, ptr %0, i32 0, i32 0
  store ptr @.str.2, ptr %26, align 8, !tbaa !15
  %27 = getelementptr inbounds %struct.function_benchmark, ptr %0, i32 0, i32 1
  %28 = load double, ptr %7, align 8, !tbaa !9
  %29 = fdiv double %28, 1.000000e+06
  store double %29, ptr %27, align 8, !tbaa !17
  %30 = getelementptr inbounds %struct.function_benchmark, ptr %0, i32 0, i32 2
  %31 = load double, ptr %7, align 8, !tbaa !9
  %32 = fdiv double %31, 1.000000e+06
  %33 = fdiv double 1.000000e+02, %32
  store double %33, ptr %30, align 8, !tbaa !18
  %34 = getelementptr inbounds %struct.function_benchmark, ptr %0, i32 0, i32 3
  %35 = load double, ptr %7, align 8, !tbaa !9
  %36 = fdiv double %35, 1.000000e+06
  %37 = fdiv double 0x4199000000000000, %36
  store double %37, ptr %34, align 8, !tbaa !19
  %38 = getelementptr inbounds %struct.function_benchmark, ptr %0, i32 0, i32 4
  %39 = load double, ptr %7, align 8, !tbaa !9
  %40 = fdiv double %39, 1.000000e+02
  store double %40, ptr %38, align 8, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  ret void
}

declare i32 @qrng_bytes(ptr noundef, ptr noundef, i64 noundef) #2

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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !6, i64 0}
!16 = !{!"", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!17 = !{!16, !10, i64 8}
!18 = !{!16, !10, i64 16}
!19 = !{!16, !10, i64 24}
!20 = !{!16, !10, i64 32}


; 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"

%struct.function_benchmark = type { ptr, double, double, double, double }

@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @tracked_malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @tracked_free(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local double @get_time_us() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @benchmark_bytes_bulk(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.function_benchmark) align 8 %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @tracked_malloc(i64 noundef 1048576)
  %4 = tail call double @get_time_us()
  br label %16

5:                                                ; preds = %16
  %6 = tail call double @get_time_us()
  %7 = fsub double %6, %4
  tail call void @tracked_free(ptr noundef %3, i64 noundef 1048576)
  store ptr @.str.2, ptr %0, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = fdiv double %7, 1.000000e+06
  store double %9, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = insertelement <2 x double> poison, double %9, i64 0
  %12 = shufflevector <2 x double> %11, <2 x double> poison, <2 x i32> zeroinitializer
  %13 = fdiv <2 x double> <double 1.000000e+02, double 0x4199000000000000>, %12
  store <2 x double> %13, ptr %10, align 8, !tbaa !12
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  %15 = fdiv double %7, 1.000000e+02
  store double %15, ptr %14, align 8, !tbaa !13
  ret void

16:                                               ; preds = %2, %16
  %.09 = phi i32 [ 0, %2 ], [ %18, %16 ]
  %17 = tail call i32 @qrng_bytes(ptr noundef %1, ptr noundef %3, i64 noundef 1048576) #2
  %18 = add nuw nsw i32 %.09, 1
  %exitcond.not = icmp eq i32 %18, 100
  br i1 %exitcond.not, label %5, label %16, !llvm.loop !14
}

declare i32 @qrng_bytes(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #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 = { "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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!10, !10, i64 0}
!13 = !{!6, !10, i64 32}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass