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

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

; 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
define dso_local double @analyze_superposition(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca [100 x i64], align 16
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 800, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store double 0.000000e+00, 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 %11

11:                                               ; preds = %60, %1
  %12 = load i32, ptr %5, align 4, !tbaa !11
  %13 = icmp slt i32 %12, 100
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %63

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %16

16:                                               ; preds = %26, %15
  %17 = load i32, ptr %7, align 4, !tbaa !11
  %18 = icmp slt i32 %17, 100
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %29

20:                                               ; preds = %16
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = call i64 @qrng_uint64(ptr noundef %21)
  %23 = load i32, ptr %7, align 4, !tbaa !11
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100 x i64], ptr %3, i64 0, i64 %24
  store i64 %22, ptr %25, align 8, !tbaa !13
  br label %26

26:                                               ; preds = %20
  %27 = load i32, ptr %7, align 4, !tbaa !11
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %7, align 4, !tbaa !11
  br label %16, !llvm.loop !15

29:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store double 0.000000e+00, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 1, ptr %9, align 4, !tbaa !11
  br label %30

30:                                               ; preds = %52, %29
  %31 = load i32, ptr %9, align 4, !tbaa !11
  %32 = icmp slt i32 %31, 100
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  store i32 8, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %55

34:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %35 = load i32, ptr %9, align 4, !tbaa !11
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100 x i64], ptr %3, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !13
  %39 = load i32, ptr %9, align 4, !tbaa !11
  %40 = sub nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100 x i64], ptr %3, i64 0, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !13
  %44 = xor i64 %38, %43
  store i64 %44, ptr %10, align 8, !tbaa !13
  %45 = load i64, ptr %10, align 8, !tbaa !13
  %46 = call i64 @llvm.ctpop.i64(i64 %45)
  %47 = trunc i64 %46 to i32
  %48 = sitofp i32 %47 to double
  %49 = fdiv double %48, 6.400000e+01
  %50 = load double, ptr %8, align 8, !tbaa !9
  %51 = fadd double %50, %49
  store double %51, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %52

52:                                               ; preds = %34
  %53 = load i32, ptr %9, align 4, !tbaa !11
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %9, align 4, !tbaa !11
  br label %30, !llvm.loop !17

55:                                               ; preds = %33
  %56 = load double, ptr %8, align 8, !tbaa !9
  %57 = fdiv double %56, 9.900000e+01
  %58 = load double, ptr %4, align 8, !tbaa !9
  %59 = fadd double %58, %57
  store double %59, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %60

60:                                               ; preds = %55
  %61 = load i32, ptr %5, align 4, !tbaa !11
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %5, align 4, !tbaa !11
  br label %11, !llvm.loop !18

63:                                               ; preds = %14
  %64 = load double, ptr %4, align 8, !tbaa !9
  %65 = fdiv double %64, 1.000000e+02
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 800, ptr %3) #4
  ret double %65
}

declare i64 @qrng_uint64(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.ctpop.i64(i64) #3

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}


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

; 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
define dso_local double @analyze_superposition(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca [100 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 800, ptr nonnull %2) #4
  br label %.preheader18

.preheader18:                                     ; preds = %1, %8
  %.023 = phi double [ 0.000000e+00, %1 ], [ %10, %8 ]
  %.01722 = phi i32 [ 0, %1 ], [ %11, %8 ]
  br label %5

3:                                                ; preds = %8
  %4 = fdiv double %10, 1.000000e+02
  call void @llvm.lifetime.end.p0(i64 800, ptr nonnull %2) #4
  ret double %4

5:                                                ; preds = %.preheader18, %5
  %indvars.iv = phi i64 [ 0, %.preheader18 ], [ %indvars.iv.next, %5 ]
  %6 = tail call i64 @qrng_uint64(ptr noundef %0) #4
  %7 = getelementptr inbounds [100 x i64], ptr %2, i64 0, i64 %indvars.iv
  store i64 %6, ptr %7, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 100
  br i1 %exitcond.not, label %.preheader.preheader, label %5, !llvm.loop !9

.preheader.preheader:                             ; preds = %5
  %.pre = load i64, ptr %2, align 16, !tbaa !5
  br label %.preheader

8:                                                ; preds = %.preheader
  %9 = fdiv double %20, 9.900000e+01
  %10 = fadd double %.023, %9
  %11 = add nuw nsw i32 %.01722, 1
  %exitcond30.not = icmp eq i32 %11, 100
  br i1 %exitcond30.not, label %3, label %.preheader18, !llvm.loop !11

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %12 = phi i64 [ %.pre, %.preheader.preheader ], [ %14, %.preheader ]
  %indvars.iv26 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next27, %.preheader ]
  %.01520 = phi double [ 0.000000e+00, %.preheader.preheader ], [ %20, %.preheader ]
  %13 = getelementptr inbounds [100 x i64], ptr %2, i64 0, i64 %indvars.iv26
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = xor i64 %12, %14
  %16 = tail call range(i64 0, 65) i64 @llvm.ctpop.i64(i64 %15)
  %17 = trunc nuw nsw i64 %16 to i32
  %18 = uitofp nneg i32 %17 to double
  %19 = fmul double %18, 1.562500e-02
  %20 = fadd double %.01520, %19
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %exitcond29.not = icmp eq i64 %indvars.iv.next27, 100
  br i1 %exitcond29.not, label %8, label %.preheader, !llvm.loop !12
}

declare i64 @qrng_uint64(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.ctpop.i64(i64) #3

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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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