; LLVM IR from zchrissirhcz/pixel :: src (px_arithm)

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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [30 x i8], align 1
@__FUNCTION__.px_fast_sqrt = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 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

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

; Function Attrs: nounwind uwtable
define dso_local float @px_fast_sqrt(float noundef %0) #1 {
  %2 = alloca float, align 4
  %3 = alloca float, align 4
  %4 = alloca i32, 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
  %8 = load float, ptr %3, align 4, !tbaa !5
  %9 = fcmp olt float %8, 0.000000e+00
  br i1 %9, label %10, label %17

10:                                               ; preds = %1
  br label %11

11:                                               ; preds = %10
  %12 = load ptr, ptr @stderr, align 8, !tbaa !9
  %13 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef @.str, ptr noundef @__FUNCTION__.px_fast_sqrt) #4
  %14 = load ptr, ptr @stderr, align 8, !tbaa !9
  %15 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef @.str.1) #4
  br label %16

16:                                               ; preds = %11
  store float -1.000000e+00, ptr %2, align 4
  br label %53

17:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store float 1.500000e+00, ptr %7, align 4, !tbaa !5
  %18 = load float, ptr %3, align 4, !tbaa !5
  %19 = fmul float %18, 5.000000e-01
  store float %19, ptr %5, align 4, !tbaa !5
  %20 = load float, ptr %3, align 4, !tbaa !5
  store float %20, ptr %6, align 4, !tbaa !5
  %21 = load i32, ptr %6, align 4, !tbaa !11
  store i32 %21, ptr %4, align 4, !tbaa !11
  %22 = load i32, ptr %4, align 4, !tbaa !11
  %23 = ashr i32 %22, 1
  %24 = sub nsw i32 1597463174, %23
  store i32 %24, ptr %4, align 4, !tbaa !11
  %25 = load float, ptr %4, align 4, !tbaa !5
  store float %25, ptr %6, align 4, !tbaa !5
  %26 = load float, ptr %6, align 4, !tbaa !5
  %27 = load float, ptr %5, align 4, !tbaa !5
  %28 = load float, ptr %6, align 4, !tbaa !5
  %29 = fmul float %27, %28
  %30 = load float, ptr %6, align 4, !tbaa !5
  %31 = fneg float %29
  %32 = call float @llvm.fmuladd.f32(float %31, float %30, float 1.500000e+00)
  %33 = fmul float %26, %32
  store float %33, ptr %6, align 4, !tbaa !5
  %34 = load float, ptr %6, align 4, !tbaa !5
  %35 = load float, ptr %5, align 4, !tbaa !5
  %36 = load float, ptr %6, align 4, !tbaa !5
  %37 = fmul float %35, %36
  %38 = load float, ptr %6, align 4, !tbaa !5
  %39 = fneg float %37
  %40 = call float @llvm.fmuladd.f32(float %39, float %38, float 1.500000e+00)
  %41 = fmul float %34, %40
  store float %41, ptr %6, align 4, !tbaa !5
  %42 = load float, ptr %6, align 4, !tbaa !5
  %43 = load float, ptr %5, align 4, !tbaa !5
  %44 = load float, ptr %6, align 4, !tbaa !5
  %45 = fmul float %43, %44
  %46 = load float, ptr %6, align 4, !tbaa !5
  %47 = fneg float %45
  %48 = call float @llvm.fmuladd.f32(float %47, float %46, float 1.500000e+00)
  %49 = fmul float %42, %48
  store float %49, ptr %6, align 4, !tbaa !5
  %50 = load float, ptr %3, align 4, !tbaa !5
  %51 = load float, ptr %6, align 4, !tbaa !5
  %52 = fmul float %50, %51
  store float %52, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %53

53:                                               ; preds = %17, %16
  %54 = load float, ptr %2, align 4
  ret float %54
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [30 x i8], align 1
@__FUNCTION__.px_fast_sqrt = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local float @px_fast_sqrt(float noundef %0) local_unnamed_addr #0 {
  %2 = fcmp olt float %0, 0.000000e+00
  br i1 %2, label %3, label %8

3:                                                ; preds = %1
  %4 = load ptr, ptr @stderr, align 8, !tbaa !5
  %5 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %4, ptr noundef nonnull @.str, ptr noundef nonnull @__FUNCTION__.px_fast_sqrt) #3
  %6 = load ptr, ptr @stderr, align 8, !tbaa !5
  %7 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %6, ptr noundef nonnull @.str.1) #3
  br label %24

8:                                                ; preds = %1
  %9 = bitcast float %0 to i32
  %10 = ashr i32 %9, 1
  %11 = sub nsw i32 1597463174, %10
  %12 = bitcast i32 %11 to float
  %13 = fmul float %0, -5.000000e-01
  %14 = fmul float %13, %12
  %15 = tail call float @llvm.fmuladd.f32(float %14, float %12, float 1.500000e+00)
  %16 = fmul float %15, %12
  %17 = fmul float %13, %16
  %18 = tail call float @llvm.fmuladd.f32(float %17, float %16, float 1.500000e+00)
  %19 = fmul float %16, %18
  %20 = fmul float %13, %19
  %21 = tail call float @llvm.fmuladd.f32(float %20, float %19, float 1.500000e+00)
  %22 = fmul float %19, %21
  %23 = fmul float %22, %0
  br label %24

24:                                               ; preds = %8, %3
  %.0 = phi float [ -1.000000e+00, %3 ], [ %23, %8 ]
  ret float %.0
}

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

attributes #0 = { nofree 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 = { nofree 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 = { cold 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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass