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

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

@.str = external hidden unnamed_addr constant [23 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [55 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @benchmark_quantum_rng(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %7 = call i64 @clock() #4
  store i64 %7, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %8

8:                                                ; preds = %17, %1
  %9 = load i32, ptr %5, align 4, !tbaa !11
  %10 = icmp slt i32 %9, 10000000
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %20

12:                                               ; preds = %8
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = call i64 @qrng_uint64(ptr noundef %13)
  %15 = load i64, ptr %4, align 8, !tbaa !9
  %16 = add i64 %15, %14
  store i64 %16, ptr %4, align 8, !tbaa !9
  br label %17

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

20:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %21 = call i64 @clock() #4
  %22 = load i64, ptr %3, align 8, !tbaa !9
  %23 = sub nsw i64 %21, %22
  %24 = sitofp i64 %23 to double
  %25 = fdiv double %24, 1.000000e+06
  store double %25, ptr %6, align 8, !tbaa !15
  %26 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %27 = load double, ptr %6, align 8, !tbaa !15
  %28 = fmul double %27, 1.000000e+06
  %29 = fdiv double 1.000000e+07, %28
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %29)
  %31 = load double, ptr %6, align 8, !tbaa !15
  %32 = fmul double %31, 1.024000e+03
  %33 = fmul double %32, 1.024000e+03
  %34 = fdiv double 8.000000e+07, %33
  %35 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, double noundef %34)
  %36 = load i64, ptr %4, align 8, !tbaa !9
  %37 = icmp eq i64 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %20
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef 10000000)
  br label %40

40:                                               ; preds = %38, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

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

; Function Attrs: nounwind
declare i64 @clock() #2

declare i64 @qrng_uint64(ptr noundef) #3

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

declare i32 @printf(ptr noundef, ...) #3

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 = { 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 #3 = { "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 }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}


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

@.str = external hidden unnamed_addr constant [23 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [55 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @benchmark_quantum_rng(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i64 @clock() #4
  br label %17

3:                                                ; preds = %17
  %4 = tail call i64 @clock() #4
  %5 = sub nsw i64 %4, %2
  %6 = sitofp i64 %5 to double
  %7 = fdiv double %6, 1.000000e+06
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %9 = fmul double %7, 1.000000e+06
  %10 = fdiv double 1.000000e+07, %9
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %10)
  %12 = fmul double %7, 1.024000e+03
  %13 = fmul double %12, 1.024000e+03
  %14 = fdiv double 8.000000e+07, %13
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef %14)
  %16 = icmp eq i64 %19, 0
  br i1 %16, label %21, label %23

17:                                               ; preds = %1, %17
  %.09 = phi i64 [ 0, %1 ], [ %19, %17 ]
  %.078 = phi i32 [ 0, %1 ], [ %20, %17 ]
  %18 = tail call i64 @qrng_uint64(ptr noundef %0) #4
  %19 = add i64 %18, %.09
  %20 = add nuw nsw i32 %.078, 1
  %exitcond.not = icmp eq i32 %20, 10000000
  br i1 %exitcond.not, label %3, label %17, !llvm.loop !5

21:                                               ; preds = %3
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef 10000000)
  br label %23

23:                                               ; preds = %21, %3
  ret void
}

; Function Attrs: nounwind
declare i64 @clock() local_unnamed_addr #1

declare i64 @qrng_uint64(ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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 = { 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 = { "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 = { nofree 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass