; 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.benchmark_result = type { double, double, double, double, double }

@__const.main.seed = external hidden unnamed_addr constant <{ i8, [31 x i8] }>, align 16
@.str.17 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [23 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

declare i64 @qrng_uint64(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @run_benchmark_suite(ptr dead_on_unwind noalias writable sret(%struct.benchmark_result) align 8, ptr noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

; Function Attrs: nounwind uwtable
declare dso_local void @print_benchmark_comparison(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca [32 x i8], align 16
  %4 = alloca %struct.benchmark_result, align 8
  %5 = alloca %struct.benchmark_result, align 8
  %6 = alloca %struct.benchmark_result, align 8
  %7 = alloca i32, align 4
  %8 = alloca %struct.benchmark_result, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %3) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %3, ptr align 16 @__const.main.seed, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 40, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 40, ptr %5) #4
  %9 = call i32 (ptr, ...) @printf(ptr noundef @.str.17)
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str.18)
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str.19)
  %12 = call i32 (ptr, ...) @printf(ptr noundef @.str.20)
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str.21, i32 noundef 4, i32 noundef 2, i32 noundef 1)
  %14 = call i32 (ptr, ...) @printf(ptr noundef @.str.22, ptr noundef @.str.23)
  %15 = call ptr @qrng_version()
  %16 = call i32 (ptr, ...) @printf(ptr noundef @.str.24, ptr noundef %15)
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.25)
  %18 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 0
  %19 = call i32 @qrng_init(ptr noundef %2, ptr noundef %18, i64 noundef 32)
  call void @llvm.lifetime.start.p0(i64 40, ptr %6) #4
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  call void @run_benchmark_suite(ptr dead_on_unwind writable sret(%struct.benchmark_result) align 8 %6, ptr noundef %20)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %6, i64 40, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 40, ptr %6) #4
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  call void @qrng_free(ptr noundef %21)
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.26)
  %23 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 0
  %24 = call i32 @qrng_init(ptr noundef %2, ptr noundef %23, i64 noundef 32)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !12
  br label %25

25:                                               ; preds = %32, %0
  %26 = load i32, ptr %7, align 4, !tbaa !12
  %27 = icmp slt i32 %26, 1000
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %35

29:                                               ; preds = %25
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = call i64 @qrng_uint64(ptr noundef %30)
  br label %32

32:                                               ; preds = %29
  %33 = load i32, ptr %7, align 4, !tbaa !12
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %7, align 4, !tbaa !12
  br label %25, !llvm.loop !14

35:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 40, ptr %8) #4
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  call void @run_benchmark_suite(ptr dead_on_unwind writable sret(%struct.benchmark_result) align 8 %8, ptr noundef %36)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %8, i64 40, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 40, ptr %8) #4
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  call void @qrng_free(ptr noundef %37)
  call void @print_benchmark_comparison(ptr noundef @.str.27, ptr noundef %4, ptr noundef %5)
  call void @llvm.lifetime.end.p0(i64 40, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  ret i32 0
}

declare ptr @qrng_version() #1

declare i32 @qrng_init(ptr noundef, ptr noundef, i64 noundef) #1

declare void @qrng_free(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 nounwind willreturn memory(argmem: readwrite) }
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 = !{i64 0, i64 8, !10, i64 8, i64 8, !10, i64 16, i64 8, !10, i64 24, i64 8, !10, i64 32, i64 8, !10}
!10 = !{!11, !11, i64 0}
!11 = !{!"double", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; 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.benchmark_result = type { double, double, double, double, double }

@__const.main.seed = external hidden unnamed_addr constant <{ i8, [31 x i8] }>, align 16
@.str.17 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [23 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

declare i64 @qrng_uint64(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @run_benchmark_suite(ptr dead_on_unwind noalias writable sret(%struct.benchmark_result) align 8, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

; Function Attrs: nounwind uwtable
declare dso_local void @print_benchmark_comparison(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca ptr, align 8
  %2 = alloca [32 x i8], align 16
  %3 = alloca %struct.benchmark_result, align 8
  %4 = alloca %struct.benchmark_result, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %2, ptr noundef nonnull align 16 dereferenceable(32) @__const.main.seed, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %4) #5
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.17)
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.18)
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.19)
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.20)
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.21, i32 noundef 4, i32 noundef 2, i32 noundef 1)
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.22, ptr noundef nonnull @.str.23)
  %11 = tail call ptr @qrng_version() #5
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.24, ptr noundef %11)
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.25)
  %14 = call i32 @qrng_init(ptr noundef nonnull %1, ptr noundef nonnull %2, i64 noundef 32) #5
  %15 = load ptr, ptr %1, align 8, !tbaa !5
  call void @run_benchmark_suite(ptr dead_on_unwind nonnull writable sret(%struct.benchmark_result) align 8 %3, ptr noundef %15)
  %16 = load ptr, ptr %1, align 8, !tbaa !5
  call void @qrng_free(ptr noundef %16) #5
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.26)
  %18 = call i32 @qrng_init(ptr noundef nonnull %1, ptr noundef nonnull %2, i64 noundef 32) #5
  br label %22

19:                                               ; preds = %22
  %20 = load ptr, ptr %1, align 8, !tbaa !5
  call void @run_benchmark_suite(ptr dead_on_unwind nonnull writable sret(%struct.benchmark_result) align 8 %4, ptr noundef %20)
  %21 = load ptr, ptr %1, align 8, !tbaa !5
  call void @qrng_free(ptr noundef %21) #5
  call void @print_benchmark_comparison(ptr noundef nonnull @.str.27, ptr noundef nonnull %3, ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  ret i32 0

22:                                               ; preds = %0, %22
  %.02 = phi i32 [ 0, %0 ], [ %25, %22 ]
  %23 = load ptr, ptr %1, align 8, !tbaa !5
  %24 = call i64 @qrng_uint64(ptr noundef %23) #5
  %25 = add nuw nsw i32 %.02, 1
  %exitcond.not = icmp eq i32 %25, 1000
  br i1 %exitcond.not, label %19, label %22, !llvm.loop !9
}

declare ptr @qrng_version() local_unnamed_addr #1

declare i32 @qrng_init(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare void @qrng_free(ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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