; 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

declare i64 @qrng_uint64(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local double @measure_decoherence(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca double, align 8
  %4 = alloca [100 x i64], align 16
  %5 = alloca [100 x i64], align 16
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store double 0.000000e+00, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 800, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 800, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %14

14:                                               ; preds = %87, %1
  %15 = load i32, ptr %6, align 4, !tbaa !11
  %16 = icmp slt i32 %15, 100
  br i1 %16, label %18, label %17

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

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

19:                                               ; preds = %29, %18
  %20 = load i32, ptr %8, align 4, !tbaa !11
  %21 = icmp slt i32 %20, 100
  br i1 %21, label %23, label %22

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

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

29:                                               ; preds = %23
  %30 = load i32, ptr %8, align 4, !tbaa !11
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %8, align 4, !tbaa !11
  br label %19, !llvm.loop !15

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

33:                                               ; preds = %40, %32
  %34 = load i32, ptr %9, align 4, !tbaa !11
  %35 = icmp slt i32 %34, 100
  br i1 %35, label %37, label %36

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

37:                                               ; preds = %33
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = call i64 @qrng_uint64(ptr noundef %38)
  br label %40

40:                                               ; preds = %37
  %41 = load i32, ptr %9, align 4, !tbaa !11
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %9, align 4, !tbaa !11
  br label %33, !llvm.loop !17

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

44:                                               ; preds = %54, %43
  %45 = load i32, ptr %10, align 4, !tbaa !11
  %46 = icmp slt i32 %45, 100
  br i1 %46, label %48, label %47

47:                                               ; preds = %44
  store i32 11, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %57

48:                                               ; preds = %44
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = call i64 @qrng_uint64(ptr noundef %49)
  %51 = load i32, ptr %10, align 4, !tbaa !11
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100 x i64], ptr %5, i64 0, i64 %52
  store i64 %50, ptr %53, align 8, !tbaa !13
  br label %54

54:                                               ; preds = %48
  %55 = load i32, ptr %10, align 4, !tbaa !11
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %10, align 4, !tbaa !11
  br label %44, !llvm.loop !18

57:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store double 0.000000e+00, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %58

58:                                               ; preds = %79, %57
  %59 = load i32, ptr %12, align 4, !tbaa !11
  %60 = icmp slt i32 %59, 100
  br i1 %60, label %62, label %61

61:                                               ; preds = %58
  store i32 14, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %82

62:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %63 = load i32, ptr %12, align 4, !tbaa !11
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [100 x i64], ptr %4, i64 0, i64 %64
  %66 = load i64, ptr %65, align 8, !tbaa !13
  %67 = load i32, ptr %12, align 4, !tbaa !11
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [100 x i64], ptr %5, i64 0, i64 %68
  %70 = load i64, ptr %69, align 8, !tbaa !13
  %71 = xor i64 %66, %70
  store i64 %71, ptr %13, align 8, !tbaa !13
  %72 = load i64, ptr %13, align 8, !tbaa !13
  %73 = call i64 @llvm.ctpop.i64(i64 %72)
  %74 = trunc i64 %73 to i32
  %75 = sitofp i32 %74 to double
  %76 = fdiv double %75, 6.400000e+01
  %77 = load double, ptr %11, align 8, !tbaa !9
  %78 = fadd double %77, %76
  store double %78, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %79

79:                                               ; preds = %62
  %80 = load i32, ptr %12, align 4, !tbaa !11
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %12, align 4, !tbaa !11
  br label %58, !llvm.loop !19

82:                                               ; preds = %61
  %83 = load double, ptr %11, align 8, !tbaa !9
  %84 = fdiv double %83, 1.000000e+02
  %85 = load double, ptr %3, align 8, !tbaa !9
  %86 = fadd double %85, %84
  store double %86, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %87

87:                                               ; preds = %82
  %88 = load i32, ptr %6, align 4, !tbaa !11
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %6, align 4, !tbaa !11
  br label %14, !llvm.loop !20

90:                                               ; preds = %17
  %91 = load double, ptr %3, align 8, !tbaa !9
  %92 = fdiv double %91, 1.000000e+02
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 800, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 800, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret double %92
}

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { 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}
!19 = distinct !{!19, !16}
!20 = distinct !{!20, !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

declare i64 @qrng_uint64(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local double @measure_decoherence(ptr noundef %0) local_unnamed_addr #3 {
  %2 = alloca [100 x i64], align 16
  %3 = alloca [100 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 800, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 800, ptr nonnull %3) #4
  br label %.preheader29

.preheader29:                                     ; preds = %1, %13
  %.036 = phi double [ 0.000000e+00, %1 ], [ %15, %13 ]
  %.02635 = phi i32 [ 0, %1 ], [ %16, %13 ]
  br label %6

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

6:                                                ; preds = %.preheader29, %6
  %indvars.iv = phi i64 [ 0, %.preheader29 ], [ %indvars.iv.next, %6 ]
  %7 = tail call i64 @qrng_uint64(ptr noundef %0) #4
  %8 = getelementptr inbounds [100 x i64], ptr %2, i64 0, i64 %indvars.iv
  store i64 %7, ptr %8, 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 %.preheader28, label %6, !llvm.loop !9

.preheader28:                                     ; preds = %6, %.preheader28
  %.02431 = phi i32 [ %10, %.preheader28 ], [ 0, %6 ]
  %9 = tail call i64 @qrng_uint64(ptr noundef %0) #4
  %10 = add nuw nsw i32 %.02431, 1
  %exitcond39.not = icmp eq i32 %10, 100
  br i1 %exitcond39.not, label %.preheader27, label %.preheader28, !llvm.loop !11

.preheader27:                                     ; preds = %.preheader28, %.preheader27
  %indvars.iv40 = phi i64 [ %indvars.iv.next41, %.preheader27 ], [ 0, %.preheader28 ]
  %11 = tail call i64 @qrng_uint64(ptr noundef %0) #4
  %12 = getelementptr inbounds [100 x i64], ptr %3, i64 0, i64 %indvars.iv40
  store i64 %11, ptr %12, align 8, !tbaa !5
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %exitcond43.not = icmp eq i64 %indvars.iv.next41, 100
  br i1 %exitcond43.not, label %.preheader, label %.preheader27, !llvm.loop !12

13:                                               ; preds = %.preheader
  %14 = fdiv double %26, 1.000000e+02
  %15 = fadd double %.036, %14
  %16 = add nuw nsw i32 %.02635, 1
  %exitcond48.not = icmp eq i32 %16, 100
  br i1 %exitcond48.not, label %4, label %.preheader29, !llvm.loop !13

.preheader:                                       ; preds = %.preheader27, %.preheader
  %indvars.iv44 = phi i64 [ %indvars.iv.next45, %.preheader ], [ 0, %.preheader27 ]
  %.02233 = phi double [ %26, %.preheader ], [ 0.000000e+00, %.preheader27 ]
  %17 = getelementptr inbounds [100 x i64], ptr %2, i64 0, i64 %indvars.iv44
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds [100 x i64], ptr %3, i64 0, i64 %indvars.iv44
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = xor i64 %20, %18
  %22 = tail call range(i64 0, 65) i64 @llvm.ctpop.i64(i64 %21)
  %23 = trunc nuw nsw i64 %22 to i32
  %24 = uitofp nneg i32 %23 to double
  %25 = fmul double %24, 1.562500e-02
  %26 = fadd double %.02233, %25
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %exitcond47.not = icmp eq i64 %indvars.iv.next45, 100
  br i1 %exitcond47.not, label %13, label %.preheader, !llvm.loop !14
}

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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { 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}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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