; LLVM IR from wmcnamara/crynn :: lib/thirdparty/assimp/contrib/Open3DGC (o3dgcArithmeticCodec)

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

%"class.o3dgc::Adaptive_Bit_Model" = type { i32, i32, i32, i32, i32 }
%"class.o3dgc::Arithmetic_Codec" = type <{ ptr, ptr, ptr, i32, i32, i32, i32, i32, [4 x i8] }>

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5o3dgc16Arithmetic_Codec15propagate_carryEv(ptr noundef nonnull align 8 dereferenceable(44)) #1 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5o3dgc16Arithmetic_Codec19renorm_enc_intervalEv(ptr noundef nonnull align 8 dereferenceable(44)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5o3dgc16Arithmetic_Codec6encodeEjRNS_18Adaptive_Bit_ModelE(ptr noundef nonnull align 8 dereferenceable(44) %0, i32 noundef %1, ptr noundef nonnull align 4 dereferenceable(20) %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = getelementptr inbounds %"class.o3dgc::Adaptive_Bit_Model", ptr %10, i32 0, i32 2
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %9, i32 0, i32 5
  %14 = load i32, ptr %13, align 8, !tbaa !13
  %15 = lshr i32 %14, 13
  %16 = mul i32 %12, %15
  store i32 %16, ptr %7, align 4, !tbaa !9
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %26

19:                                               ; preds = %3
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %9, i32 0, i32 5
  store i32 %20, ptr %21, align 8, !tbaa !13
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %"class.o3dgc::Adaptive_Bit_Model", ptr %22, i32 0, i32 3
  %24 = load i32, ptr %23, align 4, !tbaa !15
  %25 = add i32 %24, 1
  store i32 %25, ptr %23, align 4, !tbaa !15
  br label %43

26:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %27 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %9, i32 0, i32 3
  %28 = load i32, ptr %27, align 8, !tbaa !16
  store i32 %28, ptr %8, align 4, !tbaa !9
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %9, i32 0, i32 3
  %31 = load i32, ptr %30, align 8, !tbaa !16
  %32 = add i32 %31, %29
  store i32 %32, ptr %30, align 8, !tbaa !16
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %9, i32 0, i32 5
  %35 = load i32, ptr %34, align 8, !tbaa !13
  %36 = sub i32 %35, %33
  store i32 %36, ptr %34, align 8, !tbaa !13
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %9, i32 0, i32 3
  %39 = load i32, ptr %38, align 8, !tbaa !16
  %40 = icmp ugt i32 %37, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %26
  call void @_ZN5o3dgc16Arithmetic_Codec15propagate_carryEv(ptr noundef nonnull align 8 dereferenceable(44) %9)
  br label %42

42:                                               ; preds = %41, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %43

43:                                               ; preds = %42, %19
  %44 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %9, i32 0, i32 5
  %45 = load i32, ptr %44, align 8, !tbaa !13
  %46 = icmp ult i32 %45, 16777216
  br i1 %46, label %47, label %48

47:                                               ; preds = %43
  call void @_ZN5o3dgc16Arithmetic_Codec19renorm_enc_intervalEv(ptr noundef nonnull align 8 dereferenceable(44) %9)
  br label %48

48:                                               ; preds = %47, %43
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %"class.o3dgc::Adaptive_Bit_Model", ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !17
  %52 = add i32 %51, -1
  store i32 %52, ptr %50, align 4, !tbaa !17
  %53 = icmp eq i32 %52, 0
  br i1 %53, label %54, label %56

54:                                               ; preds = %48
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN5o3dgc18Adaptive_Bit_Model6updateEv(ptr noundef nonnull align 4 dereferenceable(20) %55)
  br label %56

56:                                               ; preds = %54, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5o3dgc18Adaptive_Bit_Model6updateEv(ptr noundef nonnull align 4 dereferenceable(20)) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress 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 = { mustprogress 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 = { mustprogress 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTSN5o3dgc18Adaptive_Bit_ModelE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16}
!13 = !{!14, !10, i64 32}
!14 = !{!"_ZTSN5o3dgc16Arithmetic_CodecE", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40}
!15 = !{!12, !10, i64 12}
!16 = !{!14, !10, i64 24}
!17 = !{!12, !10, i64 4}


; 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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5o3dgc16Arithmetic_Codec15propagate_carryEv(ptr noundef nonnull align 8 dereferenceable(44)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5o3dgc16Arithmetic_Codec19renorm_enc_intervalEv(ptr noundef nonnull align 8 dereferenceable(44)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5o3dgc16Arithmetic_Codec6encodeEjRNS_18Adaptive_Bit_ModelE(ptr noundef nonnull align 8 dereferenceable(44) %0, i32 noundef %1, ptr noundef nonnull align 4 dereferenceable(20) %2) local_unnamed_addr #1 align 2 {
  %4 = getelementptr inbounds i8, ptr %2, i64 8
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = load i32, ptr %6, align 8, !tbaa !10
  %8 = lshr i32 %7, 13
  %9 = mul i32 %8, %5
  %10 = icmp eq i32 %1, 0
  br i1 %10, label %11, label %15

11:                                               ; preds = %3
  store i32 %9, ptr %6, align 8, !tbaa !10
  %12 = getelementptr inbounds i8, ptr %2, i64 12
  %13 = load i32, ptr %12, align 4, !tbaa !13
  %14 = add i32 %13, 1
  store i32 %14, ptr %12, align 4, !tbaa !13
  br label %22

15:                                               ; preds = %3
  %16 = getelementptr inbounds i8, ptr %0, i64 24
  %17 = load i32, ptr %16, align 8, !tbaa !14
  %18 = add i32 %17, %9
  store i32 %18, ptr %16, align 8, !tbaa !14
  %19 = sub i32 %7, %9
  store i32 %19, ptr %6, align 8, !tbaa !10
  %20 = icmp ugt i32 %17, %18
  br i1 %20, label %21, label %22

21:                                               ; preds = %15
  tail call void @_ZN5o3dgc16Arithmetic_Codec15propagate_carryEv(ptr noundef nonnull align 8 dereferenceable(44) %0)
  %.pr = load i32, ptr %6, align 8, !tbaa !10
  br label %22

22:                                               ; preds = %15, %21, %11
  %23 = phi i32 [ %19, %15 ], [ %.pr, %21 ], [ %9, %11 ]
  %24 = icmp ult i32 %23, 16777216
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  tail call void @_ZN5o3dgc16Arithmetic_Codec19renorm_enc_intervalEv(ptr noundef nonnull align 8 dereferenceable(44) %0)
  br label %26

26:                                               ; preds = %25, %22
  %27 = getelementptr inbounds i8, ptr %2, i64 4
  %28 = load i32, ptr %27, align 4, !tbaa !15
  %29 = add i32 %28, -1
  store i32 %29, ptr %27, align 4, !tbaa !15
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %26
  tail call void @_ZN5o3dgc18Adaptive_Bit_Model6updateEv(ptr noundef nonnull align 4 dereferenceable(20) %2)
  br label %32

32:                                               ; preds = %31, %26
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5o3dgc18Adaptive_Bit_Model6updateEv(ptr noundef nonnull align 4 dereferenceable(20)) local_unnamed_addr #1 align 2

attributes #0 = { inlinehint mustprogress 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 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, !7, i64 8}
!6 = !{!"_ZTSN5o3dgc18Adaptive_Bit_ModelE", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !7, i64 32}
!11 = !{!"_ZTSN5o3dgc16Arithmetic_CodecE", !12, i64 0, !12, i64 8, !12, i64 16, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!6, !7, i64 12}
!14 = !{!11, !7, i64 24}
!15 = !{!6, !7, i64 4}


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