; LLVM IR from microsoft/LightAIMD :: src (random)

; 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: nounwind uwtable
declare dso_local double @rand_uniform() #0

; Function Attrs: nounwind uwtable
define dso_local void @rand_standard_normal(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = icmp eq i64 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  br label %73

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %17 = load i64, ptr %4, align 8, !tbaa !9
  %18 = add i64 %17, 1
  %19 = udiv i64 %18, 2
  store i64 %19, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %65, %16
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = load i64, ptr %5, align 8, !tbaa !9
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 2, ptr %8, align 4
  br label %68

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %26 = call double @rand_uniform()
  store double %26, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %27 = call double @rand_uniform()
  store double %27, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %28 = load double, ptr %9, align 8, !tbaa !11
  %29 = call double @log(double noundef %28) #3
  %30 = fmul double -2.000000e+00, %29
  %31 = call double @sqrt(double noundef %30) #3
  store double %31, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %32 = load double, ptr %10, align 8, !tbaa !11
  %33 = fmul double 0x401921FB54442D18, %32
  store double %33, ptr %12, align 8, !tbaa !11
  %34 = load double, ptr %11, align 8, !tbaa !11
  %35 = load double, ptr %12, align 8, !tbaa !11
  %36 = call double @cos(double noundef %35) #3
  %37 = fmul double %34, %36
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = load i64, ptr %6, align 8, !tbaa !9
  %40 = getelementptr inbounds double, ptr %38, i64 %39
  store double %37, ptr %40, align 8, !tbaa !11
  %41 = load i64, ptr %6, align 8, !tbaa !9
  %42 = add i64 %41, 1
  store i64 %42, ptr %6, align 8, !tbaa !9
  %43 = load i64, ptr %6, align 8, !tbaa !9
  %44 = load i64, ptr %4, align 8, !tbaa !9
  %45 = icmp eq i64 %43, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %25
  store i32 1, ptr %8, align 4
  br label %62

47:                                               ; preds = %25
  %48 = load double, ptr %11, align 8, !tbaa !11
  %49 = load double, ptr %12, align 8, !tbaa !11
  %50 = call double @sin(double noundef %49) #3
  %51 = fmul double %48, %50
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = load i64, ptr %6, align 8, !tbaa !9
  %54 = getelementptr inbounds double, ptr %52, i64 %53
  store double %51, ptr %54, align 8, !tbaa !11
  %55 = load i64, ptr %6, align 8, !tbaa !9
  %56 = add i64 %55, 1
  store i64 %56, ptr %6, align 8, !tbaa !9
  %57 = load i64, ptr %6, align 8, !tbaa !9
  %58 = load i64, ptr %4, align 8, !tbaa !9
  %59 = icmp eq i64 %57, %58
  br i1 %59, label %60, label %61

60:                                               ; preds = %47
  store i32 1, ptr %8, align 4
  br label %62

61:                                               ; preds = %47
  store i32 0, ptr %8, align 4
  br label %62

62:                                               ; preds = %61, %60, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %63 = load i32, ptr %8, align 4
  switch i32 %63, label %68 [
    i32 0, label %64
  ]

64:                                               ; preds = %62
  br label %65

65:                                               ; preds = %64
  %66 = load i64, ptr %7, align 8, !tbaa !9
  %67 = add i64 %66, 1
  store i64 %67, ptr %7, align 8, !tbaa !9
  br label %20, !llvm.loop !13

68:                                               ; preds = %62, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %69 = load i32, ptr %8, align 4
  switch i32 %69, label %71 [
    i32 2, label %70
  ]

70:                                               ; preds = %68
  store i32 0, ptr %8, align 4
  br label %71

71:                                               ; preds = %70, %68
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %72 = load i32, ptr %8, align 4
  switch i32 %72, label %74 [
    i32 0, label %73
    i32 1, label %73
  ]

73:                                               ; preds = %71, %71, %15
  ret void

74:                                               ; preds = %71
  unreachable
}

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

; Function Attrs: nounwind
declare double @sqrt(double noundef) #2

; Function Attrs: nounwind
declare double @log(double noundef) #2

; Function Attrs: nounwind
declare double @cos(double noundef) #2

; Function Attrs: nounwind
declare double @sin(double noundef) #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 }

!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 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

; Function Attrs: nounwind uwtable
declare dso_local double @rand_uniform() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @rand_standard_normal(ptr nocapture noundef writeonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i64 %1, 0
  br i1 %3, label %.thread, label %4

4:                                                ; preds = %2
  %5 = add i64 %1, 1
  %6 = lshr i64 %5, 1
  %.not37 = icmp ult i64 %5, 2
  br i1 %.not37, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %4, %18
  %.034 = phi i64 [ %22, %18 ], [ 0, %4 ]
  %.02333 = phi i64 [ %23, %18 ], [ 0, %4 ]
  %7 = tail call double @rand_uniform()
  %8 = tail call double @rand_uniform()
  %9 = tail call double @log(double noundef %7) #2
  %10 = fmul double %9, -2.000000e+00
  %11 = tail call double @sqrt(double noundef %10) #2
  %12 = fmul double %8, 0x401921FB54442D18
  %13 = tail call double @cos(double noundef %12) #2
  %14 = fmul double %11, %13
  %15 = getelementptr inbounds double, ptr %0, i64 %.034
  store double %14, ptr %15, align 8, !tbaa !5
  %16 = or disjoint i64 %.034, 1
  %17 = icmp eq i64 %16, %1
  br i1 %17, label %.thread, label %18

18:                                               ; preds = %.lr.ph
  %19 = tail call double @sin(double noundef %12) #2
  %20 = fmul double %11, %19
  %21 = getelementptr inbounds double, ptr %0, i64 %16
  store double %20, ptr %21, align 8, !tbaa !5
  %22 = add nuw i64 %.034, 2
  %.not = icmp eq i64 %22, %1
  %23 = add nuw nsw i64 %.02333, 1
  %exitcond.not = icmp eq i64 %23, %6
  %or.cond = select i1 %.not, i1 true, i1 %exitcond.not
  br i1 %or.cond, label %.thread, label %.lr.ph, !llvm.loop !9

.thread:                                          ; preds = %18, %.lr.ph, %4, %2
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @log(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { mustprogress nofree nounwind willreturn memory(write) "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 }

!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 = !{!"double", !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,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass