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

@__const.test_quantum_properties.seed = external hidden unnamed_addr constant <{ i8, [31 x i8] }>, align 16
@.str.4 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [29 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

declare i64 @qrng_uint64(ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @test_quantum_properties(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca [10 x i64], align 16
  %4 = alloca [32 x i8], align 16
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 80, ptr %3) #5
  call void @llvm.memset.p0.i64(ptr align 16 %3, i8 0, i64 80, i1 false)
  call void @llvm.lifetime.start.p0(i64 32, ptr %4) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %4, ptr align 16 @__const.test_quantum_properties.seed, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %9

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

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

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %14 = getelementptr inbounds [32 x i8], ptr %4, i64 0, i64 0
  %15 = call i32 @qrng_init(ptr noundef %6, ptr noundef %14, i64 noundef 32)
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = call i64 @qrng_uint64(ptr noundef %16)
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [10 x i64], ptr %3, i64 0, i64 %19
  store i64 %17, ptr %20, align 8, !tbaa !11
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  call void @qrng_free(ptr noundef %21)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %22

22:                                               ; preds = %13
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %5, align 4, !tbaa !9
  br label %9, !llvm.loop !13

25:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %42, %25
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = icmp slt i32 %27, 10
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %26
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [10 x i64], ptr %3, i64 0, i64 %32
  %34 = load i64, ptr %33, align 8, !tbaa !11
  %35 = getelementptr inbounds [10 x i64], ptr %3, i64 0, i64 0
  %36 = load i64, ptr %35, align 16, !tbaa !11
  %37 = icmp eq i64 %34, %36
  br i1 %37, label %38, label %41

38:                                               ; preds = %30
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %7, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %38, %30
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %8, align 4, !tbaa !9
  br label %26, !llvm.loop !15

45:                                               ; preds = %29
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = sub nsw i32 9, %47
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %48)
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = call double @qrng_get_entropy_estimate(ptr noundef %50)
  %52 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, double noundef %51)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 80, ptr %3) #5
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; 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) #4

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

declare void @qrng_free(ptr noundef) #1

declare double @qrng_get_entropy_estimate(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: write) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@__const.test_quantum_properties.seed = external hidden unnamed_addr constant <{ i8, [31 x i8] }>, align 16
@.str.4 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [29 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

declare i64 @qrng_uint64(ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @test_quantum_properties(ptr noundef %0) local_unnamed_addr #3 {
.preheader:
  %1 = alloca [32 x i8], align 16
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %1) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %1, ptr noundef nonnull align 16 dereferenceable(32) @__const.test_quantum_properties.seed, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %3 = call i32 @qrng_init(ptr noundef nonnull %2, ptr noundef nonnull %1, i64 noundef 32) #5
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = call i64 @qrng_uint64(ptr noundef %4) #5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  call void @qrng_free(ptr noundef %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %7 = call i32 @qrng_init(ptr noundef nonnull %2, ptr noundef nonnull %1, i64 noundef 32) #5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = call i64 @qrng_uint64(ptr noundef %8) #5
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  call void @qrng_free(ptr noundef %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %11 = call i32 @qrng_init(ptr noundef nonnull %2, ptr noundef nonnull %1, i64 noundef 32) #5
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = call i64 @qrng_uint64(ptr noundef %12) #5
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  call void @qrng_free(ptr noundef %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %15 = call i32 @qrng_init(ptr noundef nonnull %2, ptr noundef nonnull %1, i64 noundef 32) #5
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = call i64 @qrng_uint64(ptr noundef %16) #5
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  call void @qrng_free(ptr noundef %18) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %19 = call i32 @qrng_init(ptr noundef nonnull %2, ptr noundef nonnull %1, i64 noundef 32) #5
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = call i64 @qrng_uint64(ptr noundef %20) #5
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  call void @qrng_free(ptr noundef %22) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %23 = call i32 @qrng_init(ptr noundef nonnull %2, ptr noundef nonnull %1, i64 noundef 32) #5
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = call i64 @qrng_uint64(ptr noundef %24) #5
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  call void @qrng_free(ptr noundef %26) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %27 = call i32 @qrng_init(ptr noundef nonnull %2, ptr noundef nonnull %1, i64 noundef 32) #5
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = call i64 @qrng_uint64(ptr noundef %28) #5
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  call void @qrng_free(ptr noundef %30) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %31 = call i32 @qrng_init(ptr noundef nonnull %2, ptr noundef nonnull %1, i64 noundef 32) #5
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = call i64 @qrng_uint64(ptr noundef %32) #5
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  call void @qrng_free(ptr noundef %34) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %35 = call i32 @qrng_init(ptr noundef nonnull %2, ptr noundef nonnull %1, i64 noundef 32) #5
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = call i64 @qrng_uint64(ptr noundef %36) #5
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  call void @qrng_free(ptr noundef %38) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %39 = call i32 @qrng_init(ptr noundef nonnull %2, ptr noundef nonnull %1, i64 noundef 32) #5
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = call i64 @qrng_uint64(ptr noundef %40) #5
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  call void @qrng_free(ptr noundef %42) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  %43 = icmp eq i64 %9, %5
  %.neg = sext i1 %43 to i32
  %44 = icmp eq i64 %13, %5
  %.neg15 = sext i1 %44 to i32
  %spec.select.1.neg = add nsw i32 %.neg, %.neg15
  %45 = icmp eq i64 %17, %5
  %.neg16 = sext i1 %45 to i32
  %spec.select.2.neg = add nsw i32 %spec.select.1.neg, %.neg16
  %46 = icmp eq i64 %21, %5
  %.neg17 = sext i1 %46 to i32
  %spec.select.3.neg = add nsw i32 %spec.select.2.neg, %.neg17
  %47 = icmp eq i64 %25, %5
  %.neg18 = sext i1 %47 to i32
  %spec.select.4.neg = add nsw i32 %spec.select.3.neg, %.neg18
  %48 = icmp eq i64 %29, %5
  %.neg19 = sext i1 %48 to i32
  %spec.select.5.neg = add nsw i32 %spec.select.4.neg, %.neg19
  %49 = icmp eq i64 %33, %5
  %.neg20 = sext i1 %49 to i32
  %spec.select.6.neg = add nsw i32 %spec.select.5.neg, %.neg20
  %50 = icmp eq i64 %37, %5
  %.neg21 = sext i1 %50 to i32
  %spec.select.7.neg = add nsw i32 %spec.select.6.neg, %.neg21
  %51 = icmp eq i64 %41, %5
  %.neg22 = sext i1 %51 to i32
  %spec.select.8.neg = add nsw i32 %spec.select.7.neg, %.neg22
  %52 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %53 = add nsw i32 %spec.select.8.neg, 9
  %54 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %53)
  %55 = call double @qrng_get_entropy_estimate(ptr noundef %0) #5
  %56 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, double noundef %55)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %1) #5
  ret void
}

; 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) #4

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

declare void @qrng_free(ptr noundef) local_unnamed_addr #1

declare double @qrng_get_entropy_estimate(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 = { 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 #3 = { 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass