; LLVM IR from zchrissirhcz/pixel :: legacy/zcnn (zcnn_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"

@gauss_rand.V1 = external hidden global float, align 4
@gauss_rand.V2 = external hidden global float, align 4
@gauss_rand.S = external hidden global float, align 4
@gauss_rand.phase = external hidden global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local float @gauss_rand(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
  store float %0, ptr %3, align 4, !tbaa !5
  store float %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %8 = load i32, ptr @gauss_rand.phase, align 4, !tbaa !9
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %45

10:                                               ; preds = %2
  br label %11

11:                                               ; preds = %34, %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %12 = call i32 @rand() #4
  %13 = sitofp i32 %12 to float
  %14 = fdiv float %13, 0x41E0000000000000
  store float %14, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %15 = call i32 @rand() #4
  %16 = sitofp i32 %15 to float
  %17 = fdiv float %16, 0x41E0000000000000
  store float %17, ptr %7, align 4, !tbaa !5
  %18 = load float, ptr %6, align 4, !tbaa !5
  %19 = call float @llvm.fmuladd.f32(float 2.000000e+00, float %18, float -1.000000e+00)
  store float %19, ptr @gauss_rand.V1, align 4, !tbaa !5
  %20 = load float, ptr %7, align 4, !tbaa !5
  %21 = call float @llvm.fmuladd.f32(float 2.000000e+00, float %20, float -1.000000e+00)
  store float %21, ptr @gauss_rand.V2, align 4, !tbaa !5
  %22 = load float, ptr @gauss_rand.V1, align 4, !tbaa !5
  %23 = load float, ptr @gauss_rand.V1, align 4, !tbaa !5
  %24 = load float, ptr @gauss_rand.V2, align 4, !tbaa !5
  %25 = load float, ptr @gauss_rand.V2, align 4, !tbaa !5
  %26 = fmul float %24, %25
  %27 = call float @llvm.fmuladd.f32(float %22, float %23, float %26)
  store float %27, ptr @gauss_rand.S, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %28

28:                                               ; preds = %11
  %29 = load float, ptr @gauss_rand.S, align 4, !tbaa !5
  %30 = fcmp oge float %29, 1.000000e+00
  br i1 %30, label %34, label %31

31:                                               ; preds = %28
  %32 = load float, ptr @gauss_rand.S, align 4, !tbaa !5
  %33 = fcmp oeq float %32, 0.000000e+00
  br label %34

34:                                               ; preds = %31, %28
  %35 = phi i1 [ true, %28 ], [ %33, %31 ]
  br i1 %35, label %11, label %36, !llvm.loop !11

36:                                               ; preds = %34
  %37 = load float, ptr @gauss_rand.V1, align 4, !tbaa !5
  %38 = load float, ptr @gauss_rand.S, align 4, !tbaa !5
  %39 = call float @logf(float noundef %38) #4
  %40 = fmul float -2.000000e+00, %39
  %41 = load float, ptr @gauss_rand.S, align 4, !tbaa !5
  %42 = fdiv float %40, %41
  %43 = call float @sqrtf(float noundef %42) #4
  %44 = fmul float %37, %43
  store float %44, ptr %5, align 4, !tbaa !5
  br label %54

45:                                               ; preds = %2
  %46 = load float, ptr @gauss_rand.V2, align 4, !tbaa !5
  %47 = load float, ptr @gauss_rand.S, align 4, !tbaa !5
  %48 = call float @logf(float noundef %47) #4
  %49 = fmul float -2.000000e+00, %48
  %50 = load float, ptr @gauss_rand.S, align 4, !tbaa !5
  %51 = fdiv float %49, %50
  %52 = call float @sqrtf(float noundef %51) #4
  %53 = fmul float %46, %52
  store float %53, ptr %5, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %45, %36
  %55 = load i32, ptr @gauss_rand.phase, align 4, !tbaa !9
  %56 = sub nsw i32 1, %55
  store i32 %56, ptr @gauss_rand.phase, align 4, !tbaa !9
  %57 = load float, ptr %5, align 4, !tbaa !5
  %58 = load float, ptr %4, align 4, !tbaa !5
  %59 = load float, ptr %3, align 4, !tbaa !5
  %60 = call float @llvm.fmuladd.f32(float %57, float %58, float %59)
  store float %60, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret float %60
}

; 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 i32 @rand() #2

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

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

; Function Attrs: nounwind
declare float @sqrtf(float noundef) #2

; Function Attrs: nounwind
declare float @logf(float noundef) #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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@gauss_rand.V1 = external hidden local_unnamed_addr global float, align 4
@gauss_rand.V2 = external hidden local_unnamed_addr global float, align 4
@gauss_rand.S = external hidden local_unnamed_addr global float, align 4
@gauss_rand.phase = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local float @gauss_rand(float noundef %0, float noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @gauss_rand.phase, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %.preheader, label %18

.preheader:                                       ; preds = %2, %.preheader
  %5 = tail call i32 @rand() #4
  %6 = sitofp i32 %5 to float
  %7 = fmul float %6, 0x3E00000000000000
  %8 = tail call i32 @rand() #4
  %9 = sitofp i32 %8 to float
  %10 = fmul float %9, 0x3E00000000000000
  %11 = tail call float @llvm.fmuladd.f32(float %7, float 2.000000e+00, float -1.000000e+00)
  store float %11, ptr @gauss_rand.V1, align 4, !tbaa !9
  %12 = tail call float @llvm.fmuladd.f32(float %10, float 2.000000e+00, float -1.000000e+00)
  store float %12, ptr @gauss_rand.V2, align 4, !tbaa !9
  %13 = fmul float %12, %12
  %14 = tail call float @llvm.fmuladd.f32(float %11, float %11, float %13)
  store float %14, ptr @gauss_rand.S, align 4, !tbaa !9
  %15 = fcmp oge float %14, 1.000000e+00
  %16 = fcmp oeq float %14, 0.000000e+00
  %17 = or i1 %15, %16
  br i1 %17, label %.preheader, label %.loopexit, !llvm.loop !11

18:                                               ; preds = %2
  %19 = load float, ptr @gauss_rand.V2, align 4, !tbaa !9
  %20 = load float, ptr @gauss_rand.S, align 4, !tbaa !9
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %18
  %.sink14 = phi float [ %20, %18 ], [ %14, %.preheader ]
  %.sink = phi float [ %19, %18 ], [ %11, %.preheader ]
  %21 = tail call float @logf(float noundef %.sink14) #4
  %22 = fmul float %21, -2.000000e+00
  %23 = load float, ptr @gauss_rand.S, align 4, !tbaa !9
  %24 = fdiv float %22, %23
  %25 = tail call float @sqrtf(float noundef %24) #4
  %26 = fmul float %.sink, %25
  %27 = load i32, ptr @gauss_rand.phase, align 4, !tbaa !5
  %28 = sub nsw i32 1, %27
  store i32 %28, ptr @gauss_rand.phase, align 4, !tbaa !5
  %29 = tail call float @llvm.fmuladd.f32(float %26, float %1, float %0)
  ret float %29
}

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #1

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @sqrtf(float noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @logf(float noundef) local_unnamed_addr #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 = { 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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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