; 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.3 = external hidden unnamed_addr constant [12 x i8], align 1

; 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 uwtable
declare dso_local double @get_time_us() #1

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

; Function Attrs: nounwind uwtable
define dso_local void @benchmark_bytes_small(ptr dead_on_unwind noalias writable sret(%struct.function_benchmark) align 8 %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca [64 x i8], align 16
  %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 64, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %8 = call double @get_time_us()
  store double %8, 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 %9

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

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

13:                                               ; preds = %9
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds [64 x i8], ptr %4, i64 0, i64 0
  %16 = call i32 @qrng_bytes(ptr noundef %14, ptr noundef %15, i64 noundef 64)
  br label %17

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

20:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %21 = call double @get_time_us()
  %22 = load double, ptr %5, align 8, !tbaa !9
  %23 = fsub double %21, %22
  store double %23, ptr %7, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.function_benchmark, ptr %0, i32 0, i32 0
  store ptr @.str.3, ptr %24, align 8, !tbaa !15
  %25 = getelementptr inbounds %struct.function_benchmark, ptr %0, i32 0, i32 1
  %26 = load double, ptr %7, align 8, !tbaa !9
  %27 = fdiv double %26, 1.000000e+06
  store double %27, ptr %25, align 8, !tbaa !17
  %28 = getelementptr inbounds %struct.function_benchmark, ptr %0, i32 0, i32 2
  %29 = load double, ptr %7, align 8, !tbaa !9
  %30 = fdiv double %29, 1.000000e+06
  %31 = fdiv double 1.000000e+06, %30
  store double %31, ptr %28, align 8, !tbaa !18
  %32 = getelementptr inbounds %struct.function_benchmark, ptr %0, i32 0, i32 3
  %33 = load double, ptr %7, align 8, !tbaa !9
  %34 = fdiv double %33, 1.000000e+06
  %35 = fdiv double 6.400000e+07, %34
  store double %35, ptr %32, align 8, !tbaa !19
  %36 = getelementptr inbounds %struct.function_benchmark, ptr %0, i32 0, i32 4
  %37 = load double, ptr %7, align 8, !tbaa !9
  %38 = fdiv double %37, 1.000000e+06
  store double %38, ptr %36, 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 64, ptr %4) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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.3 = external hidden unnamed_addr constant [12 x i8], align 1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @benchmark_bytes_small(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.function_benchmark) align 8 %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca [64 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %3) #3
  %4 = tail call double @get_time_us()
  br label %15

5:                                                ; preds = %15
  %6 = call double @get_time_us()
  %7 = fsub double %6, %4
  store ptr @.str.3, 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+06, double 6.400000e+07>, %12
  store <2 x double> %13, ptr %10, align 8, !tbaa !12
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  store double %9, ptr %14, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #3
  ret void

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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, !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