; 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::Static_Bit_Model" = type { 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_16Static_Bit_ModelE(ptr noundef nonnull align 8 dereferenceable(44) %0, i32 noundef %1, ptr noundef nonnull align 4 dereferenceable(4) %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) #3
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = getelementptr inbounds %"class.o3dgc::Static_Bit_Model", ptr %10, i32 0, i32 0
  %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 %22

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
  br label %39

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

37:                                               ; preds = %22
  call void @_ZN5o3dgc16Arithmetic_Codec15propagate_carryEv(ptr noundef nonnull align 8 dereferenceable(44) %9)
  br label %38

38:                                               ; preds = %37, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %39

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

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

44:                                               ; preds = %43, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

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 = { 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 0}
!12 = !{!"_ZTSN5o3dgc16Static_Bit_ModelE", !10, i64 0}
!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 = !{!14, !10, i64 24}


; 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_16Static_Bit_ModelE(ptr noundef nonnull align 8 dereferenceable(44) %0, i32 noundef %1, ptr nocapture noundef nonnull readonly align 4 dereferenceable(4) %2) local_unnamed_addr #1 align 2 {
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load i32, ptr %5, align 8, !tbaa !10
  %7 = lshr i32 %6, 13
  %8 = mul i32 %7, %4
  %9 = icmp eq i32 %1, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %3
  store i32 %8, ptr %5, align 8, !tbaa !10
  br label %18

11:                                               ; preds = %3
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %14 = add i32 %13, %8
  store i32 %14, ptr %12, align 8, !tbaa !13
  %15 = sub i32 %6, %8
  store i32 %15, ptr %5, align 8, !tbaa !10
  %16 = icmp ugt i32 %13, %14
  br i1 %16, label %17, label %18

17:                                               ; preds = %11
  tail call void @_ZN5o3dgc16Arithmetic_Codec15propagate_carryEv(ptr noundef nonnull align 8 dereferenceable(44) %0)
  %.pr = load i32, ptr %5, align 8, !tbaa !10
  br label %18

18:                                               ; preds = %11, %17, %10
  %19 = phi i32 [ %15, %11 ], [ %.pr, %17 ], [ %8, %10 ]
  %20 = icmp ult i32 %19, 16777216
  br i1 %20, label %21, label %22

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

22:                                               ; preds = %21, %18
  ret void
}

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 0}
!6 = !{!"_ZTSN5o3dgc16Static_Bit_ModelE", !7, i64 0}
!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 = !{!11, !7, i64 24}


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