; 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.1 = external hidden unnamed_addr constant [7 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

; Function Attrs: nounwind uwtable
define dso_local void @benchmark_double(ptr dead_on_unwind noalias writable sret(%struct.function_benchmark) align 8 %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca double, 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 double @get_time_us()
  store double %8, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store volatile double 0.000000e+00, 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 = %18, %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 %21

13:                                               ; preds = %9
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = call double @qrng_double(ptr noundef %14)
  %16 = load volatile double, ptr %5, align 8, !tbaa !9
  %17 = fadd double %16, %15
  store volatile double %17, ptr %5, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %13
  %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 %9, !llvm.loop !13

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

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.1 = external hidden unnamed_addr constant [7 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

; Function Attrs: nounwind uwtable
define dso_local void @benchmark_double(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.function_benchmark) align 8 %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca double, align 8
  %4 = tail call double @get_time_us()
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3)
  store volatile double 0.000000e+00, ptr %3, align 8, !tbaa !5
  br label %15

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

15:                                               ; preds = %2, %15
  %.08 = phi i32 [ 0, %2 ], [ %18, %15 ]
  %16 = tail call double @qrng_double(ptr noundef %1) #3
  %.0..0..0..0.5 = load volatile double, ptr %3, align 8, !tbaa !5
  %17 = fadd double %16, %.0..0..0..0.5
  store volatile double %17, ptr %3, align 8, !tbaa !5
  %18 = add nuw nsw i32 %.08, 1
  %exitcond.not = icmp eq i32 %18, 1000000
  br i1 %exitcond.not, label %5, label %15, !llvm.loop !14
}

declare double @qrng_double(ptr noundef) local_unnamed_addr #2

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


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