; LLVM IR from datocms/fast_thumbhash :: ext/fast_thumbhash (fast_thumbhash)

; 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: 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.round.f32(float) #1

; Function Attrs: nounwind uwtable
declare dso_local double @thumbhash_to_approximate_aspect_ratio(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @thumb_size(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call double @thumbhash_to_approximate_aspect_ratio(ptr noundef %8)
  store double %9, ptr %7, align 8, !tbaa !10
  %10 = load double, ptr %7, align 8, !tbaa !10
  %11 = fcmp ogt double %10, 1.000000e+00
  br i1 %11, label %12, label %16

12:                                               ; preds = %3
  %13 = load i8, ptr %5, align 1, !tbaa !9
  %14 = zext i8 %13 to i32
  %15 = sitofp i32 %14 to double
  br label %22

16:                                               ; preds = %3
  %17 = load i8, ptr %5, align 1, !tbaa !9
  %18 = zext i8 %17 to i32
  %19 = sitofp i32 %18 to double
  %20 = load double, ptr %7, align 8, !tbaa !10
  %21 = fmul double %19, %20
  br label %22

22:                                               ; preds = %16, %12
  %23 = phi double [ %15, %12 ], [ %21, %16 ]
  %24 = fptrunc double %23 to float
  %25 = call float @llvm.round.f32(float %24)
  %26 = fptoui float %25 to i8
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 0
  store i8 %26, ptr %28, align 1, !tbaa !9
  %29 = load double, ptr %7, align 8, !tbaa !10
  %30 = fcmp ogt double %29, 1.000000e+00
  br i1 %30, label %31, label %37

31:                                               ; preds = %22
  %32 = load i8, ptr %5, align 1, !tbaa !9
  %33 = zext i8 %32 to i32
  %34 = sitofp i32 %33 to double
  %35 = load double, ptr %7, align 8, !tbaa !10
  %36 = fdiv double %34, %35
  br label %41

37:                                               ; preds = %22
  %38 = load i8, ptr %5, align 1, !tbaa !9
  %39 = zext i8 %38 to i32
  %40 = sitofp i32 %39 to double
  br label %41

41:                                               ; preds = %37, %31
  %42 = phi double [ %36, %31 ], [ %40, %37 ]
  %43 = fptrunc double %42 to float
  %44 = call float @llvm.round.f32(float %43)
  %45 = fptoui float %44 to i8
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i64 1
  store i8 %45, ptr %47, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"double", !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"

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

; Function Attrs: nounwind uwtable
declare dso_local double @thumbhash_to_approximate_aspect_ratio(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @thumb_size(ptr noundef %0, i8 noundef zeroext %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %4 = tail call double @thumbhash_to_approximate_aspect_ratio(ptr noundef %0)
  %5 = fcmp ogt double %4, 1.000000e+00
  %6 = uitofp i8 %1 to double
  br i1 %5, label %7, label %9

7:                                                ; preds = %3
  %8 = fdiv double %6, %4
  br label %14

9:                                                ; preds = %3
  %10 = fmul double %4, %6
  %11 = fptrunc double %10 to float
  %12 = tail call float @llvm.round.f32(float %11)
  %13 = fptoui float %12 to i8
  br label %14

14:                                               ; preds = %9, %7
  %.sink = phi i8 [ %1, %7 ], [ %13, %9 ]
  %15 = phi double [ %8, %7 ], [ %6, %9 ]
  store i8 %.sink, ptr %2, align 1
  %16 = fptrunc double %15 to float
  %17 = tail call float @llvm.round.f32(float %16)
  %18 = fptoui float %17 to i8
  %19 = getelementptr inbounds i8, ptr %2, i64 1
  store i8 %18, ptr %19, align 1, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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" }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass