; LLVM IR from KhawajaAbaid/machine-learning-in-c :: random (random_normal)

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

@random_normal.have_spare = external hidden global i32, align 4
@random_normal.z0 = external hidden global double, align 8
@random_normal.z1 = external hidden global double, align 8

; Function Attrs: nounwind uwtable
define dso_local double @random_normal() #0 {
  %1 = alloca double, align 8
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = load i32, ptr @random_normal.have_spare, align 4, !tbaa !5
  %6 = icmp ne i32 %5, 0
  br i1 %6, label %7, label %9

7:                                                ; preds = %0
  store i32 0, ptr @random_normal.have_spare, align 4, !tbaa !5
  %8 = load double, ptr @random_normal.z1, align 8, !tbaa !9
  store double %8, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %43

9:                                                ; preds = %0
  store i32 1, ptr @random_normal.have_spare, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %14, %9
  %11 = call i64 @random() #3
  %12 = sitofp i64 %11 to double
  %13 = fdiv double %12, 0x41DFFFFFFFC00000
  store double %13, ptr %2, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %10
  %15 = load double, ptr %2, align 8, !tbaa !9
  %16 = fcmp ole double %15, 0x10000000000000
  br i1 %16, label %10, label %17, !llvm.loop !11

17:                                               ; preds = %14
  br label %18

18:                                               ; preds = %22, %17
  %19 = call i64 @random() #3
  %20 = sitofp i64 %19 to double
  %21 = fdiv double %20, 0x41DFFFFFFFC00000
  store double %21, ptr %3, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %18
  %23 = load double, ptr %3, align 8, !tbaa !9
  %24 = fcmp ole double %23, 0x10000000000000
  br i1 %24, label %18, label %25, !llvm.loop !13

25:                                               ; preds = %22
  %26 = load double, ptr %2, align 8, !tbaa !9
  %27 = call double @log(double noundef %26) #3
  %28 = fmul double -2.000000e+00, %27
  %29 = call double @sqrt(double noundef %28) #3
  %30 = load double, ptr %3, align 8, !tbaa !9
  %31 = fmul double 0x401921FB54442D18, %30
  %32 = call double @cos(double noundef %31) #3
  %33 = fmul double %29, %32
  store double %33, ptr @random_normal.z0, align 8, !tbaa !9
  %34 = load double, ptr %2, align 8, !tbaa !9
  %35 = call double @log(double noundef %34) #3
  %36 = fmul double -2.000000e+00, %35
  %37 = call double @sqrt(double noundef %36) #3
  %38 = load double, ptr %3, align 8, !tbaa !9
  %39 = fmul double 0x401921FB54442D18, %38
  %40 = call double @sin(double noundef %39) #3
  %41 = fmul double %37, %40
  store double %41, ptr @random_normal.z1, align 8, !tbaa !9
  %42 = load double, ptr @random_normal.z0, align 8, !tbaa !9
  store double %42, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %43

43:                                               ; preds = %25, %7
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %44 = load double, ptr %1, align 8
  ret double %44
}

; 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 i64 @random() #2

; 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 = !{!"int", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@random_normal.have_spare = external hidden local_unnamed_addr global i32, align 4
@random_normal.z0 = external hidden local_unnamed_addr global double, align 8
@random_normal.z1 = external hidden local_unnamed_addr global double, align 8

; Function Attrs: nounwind uwtable
define dso_local double @random_normal() local_unnamed_addr #0 {
  %1 = load i32, ptr @random_normal.have_spare, align 4, !tbaa !5
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %3, label %2

2:                                                ; preds = %0
  store i32 0, ptr @random_normal.have_spare, align 4, !tbaa !5
  br label %25

3:                                                ; preds = %0
  store i32 1, ptr @random_normal.have_spare, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %4, %3
  %5 = tail call i64 @random() #3
  %6 = sitofp i64 %5 to double
  %7 = fdiv double %6, 0x41DFFFFFFFC00000
  %8 = fcmp ugt double %7, 0x10000000000000
  br i1 %8, label %.preheader, label %4, !llvm.loop !9

.preheader:                                       ; preds = %4, %.preheader
  %9 = tail call i64 @random() #3
  %10 = sitofp i64 %9 to double
  %11 = fdiv double %10, 0x41DFFFFFFFC00000
  %12 = fcmp ugt double %11, 0x10000000000000
  br i1 %12, label %13, label %.preheader, !llvm.loop !11

13:                                               ; preds = %.preheader
  %14 = tail call double @log(double noundef %7) #3
  %15 = fmul double %14, -2.000000e+00
  %16 = tail call double @sqrt(double noundef %15) #3
  %17 = fmul double %11, 0x401921FB54442D18
  %18 = tail call double @cos(double noundef %17) #3
  %19 = fmul double %16, %18
  store double %19, ptr @random_normal.z0, align 8, !tbaa !12
  %20 = tail call double @log(double noundef %7) #3
  %21 = fmul double %20, -2.000000e+00
  %22 = tail call double @sqrt(double noundef %21) #3
  %23 = tail call double @sin(double noundef %17) #3
  %24 = fmul double %22, %23
  store double %24, ptr @random_normal.z1, align 8, !tbaa !12
  br label %25

25:                                               ; preds = %13, %2
  %.0.in = phi ptr [ @random_normal.z1, %2 ], [ @random_normal.z0, %13 ]
  %.0 = load double, ptr %.0.in, align 8, !tbaa !12
  ret double %.0
}

; Function Attrs: nounwind
declare i64 @random() local_unnamed_addr #1

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

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

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

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

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 = { 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 #2 = { 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 #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 = !{!"int", !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 = !{!13, !13, i64 0}
!13 = !{!"double", !7, i64 0}


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