; 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::Arithmetic_Codec" = type <{ ptr, ptr, ptr, i32, i32, i32, i32, i32, [4 x i8] }>
%"class.o3dgc::Adaptive_Data_Model" = type <{ ptr, ptr, ptr, i32, i32, 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_19Adaptive_Data_ModelE(ptr noundef nonnull align 8 dereferenceable(44) %0, i32 noundef %1, ptr noundef nonnull align 8 dereferenceable(52) %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
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %10 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %9, i32 0, i32 3
  %11 = load i32, ptr %10, align 8, !tbaa !11
  store i32 %11, ptr %8, align 4, !tbaa !9
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %13, i32 0, i32 7
  %15 = load i32, ptr %14, align 8, !tbaa !13
  %16 = icmp eq i32 %12, %15
  br i1 %16, label %17, label %37

17:                                               ; preds = %3
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr %20, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %9, i32 0, i32 5
  %26 = load i32, ptr %25, align 8, !tbaa !16
  %27 = lshr i32 %26, 15
  %28 = mul i32 %24, %27
  store i32 %28, ptr %7, 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 !11
  %32 = add i32 %31, %29
  store i32 %32, ptr %30, align 8, !tbaa !11
  %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 !16
  %36 = sub i32 %35, %33
  store i32 %36, ptr %34, align 8, !tbaa !16
  br label %67

37:                                               ; preds = %3
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds i32, ptr %40, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %9, i32 0, i32 5
  %46 = load i32, ptr %45, align 8, !tbaa !16
  %47 = lshr i32 %46, 15
  store i32 %47, ptr %45, align 8, !tbaa !16
  %48 = mul i32 %44, %47
  store i32 %48, ptr %7, align 4, !tbaa !9
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %9, i32 0, i32 3
  %51 = load i32, ptr %50, align 8, !tbaa !11
  %52 = add i32 %51, %49
  store i32 %52, ptr %50, align 8, !tbaa !11
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !15
  %56 = load i32, ptr %5, align 4, !tbaa !9
  %57 = add i32 %56, 1
  %58 = zext i32 %57 to i64
  %59 = getelementptr inbounds i32, ptr %55, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !9
  %61 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %9, i32 0, i32 5
  %62 = load i32, ptr %61, align 8, !tbaa !16
  %63 = mul i32 %60, %62
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = sub i32 %63, %64
  %66 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %9, i32 0, i32 5
  store i32 %65, ptr %66, align 8, !tbaa !16
  br label %67

67:                                               ; preds = %37, %17
  %68 = load i32, ptr %8, align 4, !tbaa !9
  %69 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %9, i32 0, i32 3
  %70 = load i32, ptr %69, align 8, !tbaa !11
  %71 = icmp ugt i32 %68, %70
  br i1 %71, label %72, label %73

72:                                               ; preds = %67
  call void @_ZN5o3dgc16Arithmetic_Codec15propagate_carryEv(ptr noundef nonnull align 8 dereferenceable(44) %9)
  br label %73

73:                                               ; preds = %72, %67
  %74 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %9, i32 0, i32 5
  %75 = load i32, ptr %74, align 8, !tbaa !16
  %76 = icmp ult i32 %75, 16777216
  br i1 %76, label %77, label %78

77:                                               ; preds = %73
  call void @_ZN5o3dgc16Arithmetic_Codec19renorm_enc_intervalEv(ptr noundef nonnull align 8 dereferenceable(44) %9)
  br label %78

78:                                               ; preds = %77, %73
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %79, i32 0, i32 1
  %81 = load ptr, ptr %80, align 8, !tbaa !17
  %82 = load i32, ptr %5, align 4, !tbaa !9
  %83 = zext i32 %82 to i64
  %84 = getelementptr inbounds i32, ptr %81, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !9
  %86 = add i32 %85, 1
  store i32 %86, ptr %84, align 4, !tbaa !9
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %87, i32 0, i32 5
  %89 = load i32, ptr %88, align 8, !tbaa !18
  %90 = add i32 %89, -1
  store i32 %90, ptr %88, align 8, !tbaa !18
  %91 = icmp eq i32 %90, 0
  br i1 %91, label %92, label %94

92:                                               ; preds = %78
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN5o3dgc19Adaptive_Data_Model6updateEb(ptr noundef nonnull align 8 dereferenceable(52) %93, i1 noundef zeroext true)
  br label %94

94:                                               ; preds = %92, %78
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5o3dgc19Adaptive_Data_Model6updateEb(ptr noundef nonnull align 8 dereferenceable(52), i1 noundef zeroext) #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 24}
!12 = !{!"_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}
!13 = !{!14, !10, i64 40}
!14 = !{!"_ZTSN5o3dgc19Adaptive_Data_ModelE", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48}
!15 = !{!14, !6, i64 0}
!16 = !{!12, !10, i64 32}
!17 = !{!14, !6, i64 8}
!18 = !{!14, !10, i64 32}


; 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_19Adaptive_Data_ModelE(ptr noundef nonnull align 8 dereferenceable(44) %0, i32 noundef %1, ptr noundef nonnull align 8 dereferenceable(52) %2) local_unnamed_addr #1 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %2, i64 40
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %8 = icmp eq i32 %7, %1
  %9 = load ptr, ptr %2, align 8, !tbaa !13
  %10 = zext i32 %1 to i64
  %11 = getelementptr inbounds i32, ptr %9, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %0, i64 32
  %14 = load i32, ptr %13, align 8, !tbaa !15
  %15 = lshr i32 %14, 15
  br i1 %8, label %16, label %20

16:                                               ; preds = %3
  %17 = mul i32 %15, %12
  %18 = add i32 %17, %5
  store i32 %18, ptr %4, align 8, !tbaa !5
  %19 = sub i32 %14, %17
  br label %29

20:                                               ; preds = %3
  store i32 %15, ptr %13, align 8, !tbaa !15
  %21 = mul i32 %15, %12
  %22 = add i32 %21, %5
  store i32 %22, ptr %4, align 8, !tbaa !5
  %23 = add i32 %1, 1
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds i32, ptr %9, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !14
  %27 = sub i32 %26, %12
  %28 = mul i32 %27, %15
  br label %29

29:                                               ; preds = %20, %16
  %.sink = phi i32 [ %28, %20 ], [ %19, %16 ]
  %30 = phi i32 [ %22, %20 ], [ %18, %16 ]
  store i32 %.sink, ptr %13, align 8, !tbaa !15
  %31 = icmp ugt i32 %5, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %29
  tail call void @_ZN5o3dgc16Arithmetic_Codec15propagate_carryEv(ptr noundef nonnull align 8 dereferenceable(44) %0)
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 32
  %.pre = load i32, ptr %.phi.trans.insert, align 8, !tbaa !15
  br label %33

33:                                               ; preds = %32, %29
  %34 = phi i32 [ %.pre, %32 ], [ %.sink, %29 ]
  %35 = icmp ult i32 %34, 16777216
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  tail call void @_ZN5o3dgc16Arithmetic_Codec19renorm_enc_intervalEv(ptr noundef nonnull align 8 dereferenceable(44) %0)
  br label %37

37:                                               ; preds = %36, %33
  %38 = getelementptr inbounds i8, ptr %2, i64 8
  %39 = load ptr, ptr %38, align 8, !tbaa !16
  %40 = zext i32 %1 to i64
  %41 = getelementptr inbounds i32, ptr %39, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !14
  %43 = add i32 %42, 1
  store i32 %43, ptr %41, align 4, !tbaa !14
  %44 = getelementptr inbounds i8, ptr %2, i64 32
  %45 = load i32, ptr %44, align 8, !tbaa !17
  %46 = add i32 %45, -1
  store i32 %46, ptr %44, align 8, !tbaa !17
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %37
  tail call void @_ZN5o3dgc19Adaptive_Data_Model6updateEb(ptr noundef nonnull align 8 dereferenceable(52) %2, i1 noundef zeroext true)
  br label %49

49:                                               ; preds = %48, %37
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5o3dgc19Adaptive_Data_Model6updateEb(ptr noundef nonnull align 8 dereferenceable(52), i1 noundef zeroext) 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, !10, i64 24}
!6 = !{!"_ZTSN5o3dgc16Arithmetic_CodecE", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !10, i64 40}
!12 = !{!"_ZTSN5o3dgc19Adaptive_Data_ModelE", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48}
!13 = !{!12, !7, i64 0}
!14 = !{!10, !10, i64 0}
!15 = !{!6, !10, i64 32}
!16 = !{!12, !7, i64 8}
!17 = !{!12, !10, i64 32}


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