; LLVM IR from litespeedtech/ls-qpack :: lsqpack (lsqpack_dec_ratio)

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

%struct.lsqpack_dec = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, %struct.lsqpack_ringbuf, %struct.anon.8, [8 x %struct.anon.9], i32, float, %struct.anon.10, %struct.lsqpack_dec_err }
%struct.lsqpack_ringbuf = type { i32, i32, i32, ptr }
%struct.anon.8 = type { ptr, ptr }
%struct.anon.9 = type { ptr, ptr }
%struct.anon.10 = type { i32, %union.anon }
%union.anon = type { %struct.anon.11 }
%struct.anon.11 = type { %struct.lsqpack_dec_int_state, %struct.lsqpack_huff_decode_state, i32, i32, ptr, ptr, ptr, i32, i32, i32, i32, i8, i8 }
%struct.lsqpack_dec_int_state = type { i32, i32, i32, i64 }
%struct.lsqpack_huff_decode_state = type { i32, %struct.lsqpack_decode_status }
%struct.lsqpack_decode_status = type { i8, i8 }
%struct.lsqpack_dec_err = type { i32, i32, i64, i64 }

@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [41 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local float @lsqpack_dec_ratio(ptr noundef %0) #2 {
  %2 = alloca float, align 4
  %3 = alloca ptr, align 8
  %4 = alloca float, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.lsqpack_dec, ptr %6, i32 0, i32 7
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %50

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.lsqpack_dec, ptr %11, i32 0, i32 6
  %13 = load i32, ptr %12, align 8, !tbaa !18
  %14 = uitofp i32 %13 to float
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.lsqpack_dec, ptr %15, i32 0, i32 7
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = uitofp i32 %17 to float
  %19 = fdiv float %14, %18
  store float %19, ptr %4, align 4, !tbaa !19
  br label %20

20:                                               ; preds = %10
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.lsqpack_dec, ptr %21, i32 0, i32 11
  %23 = load ptr, ptr %22, align 8, !tbaa !20
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %46

25:                                               ; preds = %20
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.lsqpack_dec, ptr %26, i32 0, i32 11
  %28 = load ptr, ptr %27, align 8, !tbaa !20
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef @.str.37) #3
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.lsqpack_dec, ptr %30, i32 0, i32 11
  %32 = load ptr, ptr %31, align 8, !tbaa !20
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.lsqpack_dec, ptr %33, i32 0, i32 7
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.lsqpack_dec, ptr %36, i32 0, i32 6
  %38 = load i32, ptr %37, align 8, !tbaa !18
  %39 = load float, ptr %4, align 4, !tbaa !19
  %40 = fpext float %39 to double
  %41 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef @.str.39, i32 noundef %35, i32 noundef %38, double noundef %40) #3
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.lsqpack_dec, ptr %42, i32 0, i32 11
  %44 = load ptr, ptr %43, align 8, !tbaa !20
  %45 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %44, ptr noundef @.str.2) #3
  br label %46

46:                                               ; preds = %25, %20
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  %49 = load float, ptr %4, align 4, !tbaa !19
  store float %49, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %51

50:                                               ; preds = %1
  store float 0.000000e+00, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %51

51:                                               ; preds = %50, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %52 = load float, ptr %2, align 4
  ret float %52
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!10, !11, i64 28}
!10 = !{!"lsqpack_dec", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !6, i64 40, !6, i64 48, !12, i64 56, !13, i64 80, !7, i64 96, !11, i64 224, !14, i64 228, !15, i64 232, !16, i64 328}
!11 = !{!"int", !7, i64 0}
!12 = !{!"lsqpack_ringbuf", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16}
!13 = !{!"", !6, i64 0, !6, i64 8}
!14 = !{!"float", !7, i64 0}
!15 = !{!"", !11, i64 0, !7, i64 8}
!16 = !{!"lsqpack_dec_err", !11, i64 0, !11, i64 4, !17, i64 8, !17, i64 16}
!17 = !{!"long", !7, i64 0}
!18 = !{!10, !11, i64 24}
!19 = !{!14, !14, i64 0}
!20 = !{!10, !6, i64 48}


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

@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [41 x i8], align 1

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

; Function Attrs: nofree nounwind uwtable
define dso_local float @lsqpack_dec_ratio(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 28
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %21, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i32, ptr %5, align 8, !tbaa !17
  %7 = uitofp i32 %6 to float
  %8 = uitofp i32 %3 to float
  %9 = fdiv float %7, %8
  %10 = getelementptr inbounds i8, ptr %0, i64 48
  %11 = load ptr, ptr %10, align 8, !tbaa !18
  %.not14 = icmp eq ptr %11, null
  br i1 %.not14, label %21, label %12

12:                                               ; preds = %4
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %11, ptr noundef nonnull @.str.37) #2
  %14 = load ptr, ptr %10, align 8, !tbaa !18
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = load i32, ptr %5, align 8, !tbaa !17
  %17 = fpext float %9 to double
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef nonnull @.str.39, i32 noundef %15, i32 noundef %16, double noundef %17) #2
  %19 = load ptr, ptr %10, align 8, !tbaa !18
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.2) #2
  br label %21

21:                                               ; preds = %1, %4, %12
  %.0 = phi float [ %9, %12 ], [ %9, %4 ], [ 0.000000e+00, %1 ]
  ret float %.0
}

attributes #0 = { 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 #1 = { 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 #2 = { 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, !7, i64 28}
!6 = !{!"lsqpack_dec", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !10, i64 40, !10, i64 48, !11, i64 56, !12, i64 80, !8, i64 96, !7, i64 224, !13, i64 228, !14, i64 232, !15, i64 328}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"lsqpack_ringbuf", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16}
!12 = !{!"", !10, i64 0, !10, i64 8}
!13 = !{!"float", !8, i64 0}
!14 = !{!"", !7, i64 0, !8, i64 8}
!15 = !{!"lsqpack_dec_err", !7, i64 0, !7, i64 4, !16, i64 8, !16, i64 16}
!16 = !{!"long", !8, i64 0}
!17 = !{!6, !7, i64 24}
!18 = !{!6, !10, i64 48}


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