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

; 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.test_result_t = type { ptr, i32, ptr }

@.str = external hidden unnamed_addr constant [24 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.12 = 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

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

declare void @qrng_free(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 i64 @qrng_uint64(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @test_uint64_distribution(ptr dead_on_unwind noalias writable sret(%struct.test_result_t) align 8 %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca [16 x i64], align 16
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %12 = call i32 @qrng_init(ptr noundef %2, ptr noundef @.str, i64 noundef 23)
  call void @llvm.lifetime.start.p0(i64 128, ptr %3) #4
  call void @llvm.memset.p0.i64(ptr align 16 %3, i8 0, i64 128, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1000000, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %25, %1
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = icmp slt i32 %14, 1000000
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %28

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %18 = load ptr, ptr %2, align 8, !tbaa !9
  %19 = call i64 @qrng_uint64(ptr noundef %18)
  store i64 %19, ptr %6, align 8, !tbaa !11
  %20 = load i64, ptr %6, align 8, !tbaa !11
  %21 = urem i64 %20, 16
  %22 = getelementptr inbounds [16 x i64], ptr %3, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = add i64 %23, 1
  store i64 %24, ptr %22, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %25

25:                                               ; preds = %17
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %5, align 4, !tbaa !5
  br label %13, !llvm.loop !13

28:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store double 6.250000e+04, ptr %7, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store double 0.000000e+00, ptr %8, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %48, %28
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = icmp slt i32 %30, 16
  br i1 %31, label %33, label %32

32:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %51

33:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [16 x i64], ptr %3, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !11
  %38 = uitofp i64 %37 to double
  %39 = load double, ptr %7, align 8, !tbaa !15
  %40 = fsub double %38, %39
  store double %40, ptr %10, align 8, !tbaa !15
  %41 = load double, ptr %10, align 8, !tbaa !15
  %42 = load double, ptr %10, align 8, !tbaa !15
  %43 = fmul double %41, %42
  %44 = load double, ptr %7, align 8, !tbaa !15
  %45 = fdiv double %43, %44
  %46 = load double, ptr %8, align 8, !tbaa !15
  %47 = fadd double %46, %45
  store double %47, ptr %8, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %48

48:                                               ; preds = %33
  %49 = load i32, ptr %9, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %9, align 4, !tbaa !5
  br label %29, !llvm.loop !17

51:                                               ; preds = %32
  %52 = load ptr, ptr %2, align 8, !tbaa !9
  call void @qrng_free(ptr noundef %52)
  %53 = load double, ptr %8, align 8, !tbaa !15
  %54 = fcmp ogt double %53, 3.057800e+01
  br i1 %54, label %55, label %59

55:                                               ; preds = %51
  %56 = getelementptr inbounds %struct.test_result_t, ptr %0, i32 0, i32 0
  store ptr @.str.11, ptr %56, align 8, !tbaa !18
  %57 = getelementptr inbounds %struct.test_result_t, ptr %0, i32 0, i32 1
  store i32 0, ptr %57, align 8, !tbaa !20
  %58 = getelementptr inbounds %struct.test_result_t, ptr %0, i32 0, i32 2
  store ptr @.str.12, ptr %58, align 8, !tbaa !21
  store i32 1, ptr %11, align 4
  br label %63

59:                                               ; preds = %51
  %60 = getelementptr inbounds %struct.test_result_t, ptr %0, i32 0, i32 0
  store ptr @.str.11, ptr %60, align 8, !tbaa !18
  %61 = getelementptr inbounds %struct.test_result_t, ptr %0, i32 0, i32 1
  store i32 1, ptr %61, align 8, !tbaa !20
  %62 = getelementptr inbounds %struct.test_result_t, ptr %0, i32 0, i32 2
  store ptr @.str.3, ptr %62, align 8, !tbaa !21
  store i32 1, ptr %11, align 4
  br label %63

63:                                               ; preds = %59, %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  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

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = distinct !{!17, !14}
!18 = !{!19, !10, i64 0}
!19 = !{!"", !10, i64 0, !6, i64 8, !10, i64 16}
!20 = !{!19, !6, i64 8}
!21 = !{!19, !10, i64 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"

%struct.test_result_t = type { ptr, i32, ptr }

@.str = external hidden unnamed_addr constant [24 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.12 = 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

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

declare void @qrng_free(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

declare i64 @qrng_uint64(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @test_uint64_distribution(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.test_result_t) align 8 %0) local_unnamed_addr #2 {
  %2 = alloca ptr, align 8
  %3 = alloca [16 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %4 = call i32 @qrng_init(ptr noundef nonnull %2, ptr noundef nonnull @.str, i64 noundef 23) #4
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %3) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(128) %3, i8 0, i64 128, i1 false)
  br label %5

5:                                                ; preds = %1, %5
  %.013 = phi i32 [ 0, %1 ], [ %12, %5 ]
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = call i64 @qrng_uint64(ptr noundef %6) #4
  %8 = and i64 %7, 15
  %9 = getelementptr inbounds [16 x i64], ptr %3, i64 0, i64 %8
  %10 = load i64, ptr %9, align 8, !tbaa !9
  %11 = add i64 %10, 1
  store i64 %11, ptr %9, align 8, !tbaa !9
  %12 = add nuw nsw i32 %.013, 1
  %exitcond.not = icmp eq i32 %12, 1000000
  br i1 %exitcond.not, label %.preheader.preheader, label %5, !llvm.loop !11

.preheader.preheader:                             ; preds = %5
  %13 = load i64, ptr %3, align 16, !tbaa !9
  %14 = uitofp i64 %13 to double
  %15 = fadd double %14, -6.250000e+04
  %16 = fmul double %15, %15
  %17 = fdiv double %16, 6.250000e+04
  %18 = getelementptr inbounds i8, ptr %3, i64 8
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = uitofp i64 %19 to double
  %21 = fadd double %20, -6.250000e+04
  %22 = fmul double %21, %21
  %23 = fdiv double %22, 6.250000e+04
  %24 = fadd double %17, %23
  %25 = getelementptr inbounds i8, ptr %3, i64 16
  %26 = load i64, ptr %25, align 16, !tbaa !9
  %27 = uitofp i64 %26 to double
  %28 = fadd double %27, -6.250000e+04
  %29 = fmul double %28, %28
  %30 = fdiv double %29, 6.250000e+04
  %31 = fadd double %24, %30
  %32 = getelementptr inbounds i8, ptr %3, i64 24
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = uitofp i64 %33 to double
  %35 = fadd double %34, -6.250000e+04
  %36 = fmul double %35, %35
  %37 = fdiv double %36, 6.250000e+04
  %38 = fadd double %31, %37
  %39 = getelementptr inbounds i8, ptr %3, i64 32
  %40 = load <2 x i64>, ptr %39, align 16, !tbaa !9
  %41 = uitofp <2 x i64> %40 to <2 x double>
  %42 = fadd <2 x double> %41, <double -6.250000e+04, double -6.250000e+04>
  %43 = fmul <2 x double> %42, %42
  %44 = fdiv <2 x double> %43, <double 6.250000e+04, double 6.250000e+04>
  %45 = extractelement <2 x double> %44, i64 0
  %46 = fadd double %38, %45
  %47 = extractelement <2 x double> %44, i64 1
  %48 = fadd double %46, %47
  %49 = getelementptr inbounds i8, ptr %3, i64 48
  %50 = load <2 x i64>, ptr %49, align 16, !tbaa !9
  %51 = uitofp <2 x i64> %50 to <2 x double>
  %52 = fadd <2 x double> %51, <double -6.250000e+04, double -6.250000e+04>
  %53 = fmul <2 x double> %52, %52
  %54 = fdiv <2 x double> %53, <double 6.250000e+04, double 6.250000e+04>
  %55 = extractelement <2 x double> %54, i64 0
  %56 = fadd double %48, %55
  %57 = extractelement <2 x double> %54, i64 1
  %58 = fadd double %56, %57
  %59 = getelementptr inbounds i8, ptr %3, i64 64
  %60 = load <2 x i64>, ptr %59, align 16, !tbaa !9
  %61 = uitofp <2 x i64> %60 to <2 x double>
  %62 = fadd <2 x double> %61, <double -6.250000e+04, double -6.250000e+04>
  %63 = fmul <2 x double> %62, %62
  %64 = fdiv <2 x double> %63, <double 6.250000e+04, double 6.250000e+04>
  %65 = extractelement <2 x double> %64, i64 0
  %66 = fadd double %58, %65
  %67 = extractelement <2 x double> %64, i64 1
  %68 = fadd double %66, %67
  %69 = getelementptr inbounds i8, ptr %3, i64 80
  %70 = load <2 x i64>, ptr %69, align 16, !tbaa !9
  %71 = uitofp <2 x i64> %70 to <2 x double>
  %72 = fadd <2 x double> %71, <double -6.250000e+04, double -6.250000e+04>
  %73 = fmul <2 x double> %72, %72
  %74 = fdiv <2 x double> %73, <double 6.250000e+04, double 6.250000e+04>
  %75 = extractelement <2 x double> %74, i64 0
  %76 = fadd double %68, %75
  %77 = extractelement <2 x double> %74, i64 1
  %78 = fadd double %76, %77
  %79 = getelementptr inbounds i8, ptr %3, i64 96
  %80 = load <2 x i64>, ptr %79, align 16, !tbaa !9
  %81 = uitofp <2 x i64> %80 to <2 x double>
  %82 = fadd <2 x double> %81, <double -6.250000e+04, double -6.250000e+04>
  %83 = fmul <2 x double> %82, %82
  %84 = fdiv <2 x double> %83, <double 6.250000e+04, double 6.250000e+04>
  %85 = extractelement <2 x double> %84, i64 0
  %86 = fadd double %78, %85
  %87 = extractelement <2 x double> %84, i64 1
  %88 = fadd double %86, %87
  %89 = getelementptr inbounds i8, ptr %3, i64 112
  %90 = load <2 x i64>, ptr %89, align 16, !tbaa !9
  %91 = uitofp <2 x i64> %90 to <2 x double>
  %92 = fadd <2 x double> %91, <double -6.250000e+04, double -6.250000e+04>
  %93 = fmul <2 x double> %92, %92
  %94 = fdiv <2 x double> %93, <double 6.250000e+04, double 6.250000e+04>
  %95 = extractelement <2 x double> %94, i64 0
  %96 = fadd double %88, %95
  %97 = extractelement <2 x double> %94, i64 1
  %98 = fadd double %96, %97
  %99 = load ptr, ptr %2, align 8, !tbaa !5
  call void @qrng_free(ptr noundef %99) #4
  %100 = fcmp ule double %98, 3.057800e+01
  %.sink = zext i1 %100 to i32
  %.str.3.sink = select i1 %100, ptr @.str.3, ptr @.str.12
  store ptr @.str.11, ptr %0, align 8
  %101 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %.sink, ptr %101, align 8
  %102 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %.str.3.sink, ptr %102, align 8
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  ret void
}

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

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: write) }
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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass