; LLVM IR from sbu-fsl/kernel-ml :: src/math (math)

; 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 float @fast_sqrt_f(float noundef) #0

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

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

; Function Attrs: nounwind uwtable
declare dso_local float @power(float noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local float @ln(float noundef) #0

; Function Attrs: nounwind uwtable
define dso_local float @normal_random(float noundef %0, float noundef %1) #0 {
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca i32, align 4
  store float %0, ptr %4, align 4, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  br label %10

10:                                               ; preds = %44, %2
  br label %11

11:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %12 = call i32 @kml_random()
  %13 = sitofp i32 %12 to float
  %14 = fdiv float %13, 0x41E0000000000000
  store float %14, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %15 = call i32 @kml_random()
  %16 = sitofp i32 %15 to float
  %17 = fdiv float %16, 0x41E0000000000000
  store float %17, ptr %8, align 4, !tbaa !5
  %18 = load float, ptr %7, align 4, !tbaa !5
  %19 = call float @llvm.fmuladd.f32(float %18, float 2.000000e+00, float -1.000000e+00)
  store float %19, ptr %7, align 4, !tbaa !5
  %20 = load float, ptr %8, align 4, !tbaa !5
  %21 = call float @llvm.fmuladd.f32(float %20, float 2.000000e+00, float -1.000000e+00)
  store float %21, ptr %8, align 4, !tbaa !5
  %22 = load float, ptr %7, align 4, !tbaa !5
  %23 = call float @power(float noundef %22, i32 noundef 2)
  %24 = load float, ptr %8, align 4, !tbaa !5
  %25 = call float @power(float noundef %24, i32 noundef 2)
  %26 = fadd float %23, %25
  store float %26, ptr %6, align 4, !tbaa !5
  %27 = load float, ptr %6, align 4, !tbaa !5
  %28 = fcmp olt float %27, 1.000000e+00
  br i1 %28, label %29, label %41

29:                                               ; preds = %11
  %30 = load float, ptr %7, align 4, !tbaa !5
  %31 = load float, ptr %6, align 4, !tbaa !5
  %32 = call float @ln(float noundef %31)
  %33 = fmul float -2.000000e+00, %32
  %34 = load float, ptr %6, align 4, !tbaa !5
  %35 = fdiv float %33, %34
  %36 = call float @fast_sqrt_f(float noundef %35)
  %37 = fmul float %30, %36
  %38 = load float, ptr %5, align 4, !tbaa !5
  %39 = load float, ptr %4, align 4, !tbaa !5
  %40 = call float @llvm.fmuladd.f32(float %37, float %38, float %39)
  store float %40, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %42

41:                                               ; preds = %11
  store i32 0, ptr %9, align 4
  br label %42

42:                                               ; preds = %41, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  %43 = load i32, ptr %9, align 4
  switch i32 %43, label %45 [
    i32 0, label %44
  ]

44:                                               ; preds = %42
  br label %10

45:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %46 = load float, ptr %3, align 4
  ret float %46
}

declare i32 @kml_random() #3

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { "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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; 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 float @fast_sqrt_f(float noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

; Function Attrs: nounwind uwtable
declare dso_local float @power(float noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local float @ln(float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local float @normal_random(float noundef %0, float noundef %1) local_unnamed_addr #0 {
  br label %3

3:                                                ; preds = %3, %2
  %4 = tail call i32 @kml_random() #3
  %5 = sitofp i32 %4 to float
  %6 = fmul float %5, 0x3E00000000000000
  %7 = tail call i32 @kml_random() #3
  %8 = sitofp i32 %7 to float
  %9 = fmul float %8, 0x3E00000000000000
  %10 = tail call float @llvm.fmuladd.f32(float %6, float 2.000000e+00, float -1.000000e+00)
  %11 = tail call float @llvm.fmuladd.f32(float %9, float 2.000000e+00, float -1.000000e+00)
  %12 = tail call float @power(float noundef %10, i32 noundef 2)
  %13 = tail call float @power(float noundef %11, i32 noundef 2)
  %14 = fadd float %12, %13
  %15 = fcmp uge float %14, 1.000000e+00
  br i1 %15, label %3, label %16

16:                                               ; preds = %3
  %17 = tail call float @ln(float noundef %14)
  %18 = fmul float %17, -2.000000e+00
  %19 = fdiv float %18, %14
  %20 = tail call float @fast_sqrt_f(float noundef %19)
  %21 = fmul float %10, %20
  %22 = tail call float @llvm.fmuladd.f32(float %21, float %1, float %0)
  ret float %22
}

declare i32 @kml_random() 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { 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)"}


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