; LLVM IR from digital-salon/Digital-Salon :: extern/include/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_Data_Model" = type <{ ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, [4 x i8] }>

@.str.11 = external hidden unnamed_addr constant [31 x i8], align 1

; 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: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #1

; Function Attrs: mustprogress noreturn uwtable
declare hidden void @_ZN5o3dgcL8AC_ErrorEPKc(ptr noundef) #2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5o3dgc19Adaptive_Data_Model12set_alphabetEj(ptr noundef nonnull align 8 dereferenceable(52) %0, i32 noundef %1) #5 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = icmp ult i32 %7, 2
  br i1 %8, label %12, label %9

9:                                                ; preds = %2
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = icmp ugt i32 %10, 2048
  br i1 %11, label %12, label %13

12:                                               ; preds = %9, %2
  call void @_ZN5o3dgcL8AC_ErrorEPKc(ptr noundef @.str.11) #7
  unreachable

13:                                               ; preds = %9
  %14 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 6
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = icmp ne i32 %15, %16
  br i1 %17, label %18, label %95

18:                                               ; preds = %13
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 6
  store i32 %19, ptr %20, align 4, !tbaa !11
  %21 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 6
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = sub i32 %22, 1
  %24 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 7
  store i32 %23, ptr %24, align 8, !tbaa !13
  %25 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = icmp eq ptr %26, null
  br i1 %27, label %29, label %28

28:                                               ; preds = %18
  call void @_ZdaPv(ptr noundef %26) #8
  br label %29

29:                                               ; preds = %28, %18
  %30 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 6
  %31 = load i32, ptr %30, align 4, !tbaa !11
  %32 = icmp ugt i32 %31, 16
  br i1 %32, label %33, label %73

33:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #9
  store i32 3, ptr %5, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %41, %33
  %35 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 6
  %36 = load i32, ptr %35, align 4, !tbaa !11
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = add i32 %37, 2
  %39 = shl i32 1, %38
  %40 = icmp ugt i32 %36, %39
  br i1 %40, label %41, label %44

41:                                               ; preds = %34
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = add i32 %42, 1
  store i32 %43, ptr %5, align 4, !tbaa !9
  br label %34, !llvm.loop !15

44:                                               ; preds = %34
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = shl i32 1, %45
  %47 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 8
  store i32 %46, ptr %47, align 4, !tbaa !17
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = sub i32 15, %48
  %50 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 9
  store i32 %49, ptr %50, align 8, !tbaa !18
  %51 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 6
  %52 = load i32, ptr %51, align 4, !tbaa !11
  %53 = mul i32 2, %52
  %54 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 8
  %55 = load i32, ptr %54, align 4, !tbaa !17
  %56 = add i32 %53, %55
  %57 = add i32 %56, 2
  %58 = zext i32 %57 to i64
  %59 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %58, i64 4)
  %60 = extractvalue { i64, i1 } %59, 1
  %61 = extractvalue { i64, i1 } %59, 0
  %62 = select i1 %60, i64 -1, i64 %61
  %63 = call noalias noundef nonnull ptr @_Znam(i64 noundef %62) #10
  %64 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 0
  store ptr %63, ptr %64, align 8, !tbaa !14
  %65 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !14
  %67 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 6
  %68 = load i32, ptr %67, align 4, !tbaa !11
  %69 = mul i32 2, %68
  %70 = zext i32 %69 to i64
  %71 = getelementptr inbounds i32, ptr %66, i64 %70
  %72 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 2
  store ptr %71, ptr %72, align 8, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #9
  br label %87

73:                                               ; preds = %29
  %74 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 2
  store ptr null, ptr %74, align 8, !tbaa !19
  %75 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 9
  store i32 0, ptr %75, align 8, !tbaa !18
  %76 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 8
  store i32 0, ptr %76, align 4, !tbaa !17
  %77 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 6
  %78 = load i32, ptr %77, align 4, !tbaa !11
  %79 = mul i32 2, %78
  %80 = zext i32 %79 to i64
  %81 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %80, i64 4)
  %82 = extractvalue { i64, i1 } %81, 1
  %83 = extractvalue { i64, i1 } %81, 0
  %84 = select i1 %82, i64 -1, i64 %83
  %85 = call noalias noundef nonnull ptr @_Znam(i64 noundef %84) #10
  %86 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 0
  store ptr %85, ptr %86, align 8, !tbaa !14
  br label %87

87:                                               ; preds = %73, %44
  %88 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 0
  %89 = load ptr, ptr %88, align 8, !tbaa !14
  %90 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 6
  %91 = load i32, ptr %90, align 4, !tbaa !11
  %92 = zext i32 %91 to i64
  %93 = getelementptr inbounds i32, ptr %89, i64 %92
  %94 = getelementptr inbounds %"class.o3dgc::Adaptive_Data_Model", ptr %6, i32 0, i32 1
  store ptr %93, ptr %94, align 8, !tbaa !20
  br label %95

95:                                               ; preds = %87, %13
  call void @_ZN5o3dgc19Adaptive_Data_Model5resetEv(ptr noundef nonnull align 8 dereferenceable(52) %6)
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5o3dgc19Adaptive_Data_Model5resetEv(ptr noundef nonnull align 8 dereferenceable(52)) #6 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nobuiltin 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 #2 = { mustprogress noreturn 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 = { nobuiltin allocsize(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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 #6 = { 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 #7 = { noreturn }
attributes #8 = { builtin nounwind }
attributes #9 = { nounwind }
attributes #10 = { builtin allocsize(0) }

!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 36}
!12 = !{!"_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}
!13 = !{!12, !10, i64 40}
!14 = !{!12, !6, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!12, !10, i64 44}
!18 = !{!12, !10, i64 48}
!19 = !{!12, !6, i64 16}
!20 = !{!12, !6, i64 8}


; 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.11 = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress noreturn uwtable
declare hidden void @_ZN5o3dgcL8AC_ErrorEPKc(ptr noundef) local_unnamed_addr #1

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5o3dgc19Adaptive_Data_Model12set_alphabetEj(ptr noundef nonnull align 8 dereferenceable(52) %0, i32 noundef %1) local_unnamed_addr #3 align 2 {
  %3 = add i32 %1, -2049
  %or.cond = icmp ult i32 %3, -2047
  br i1 %or.cond, label %4, label %5

4:                                                ; preds = %2
  tail call void @_ZN5o3dgcL8AC_ErrorEPKc(ptr noundef nonnull @.str.11) #5
  unreachable

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 36
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not = icmp eq i32 %7, %1
  br i1 %.not, label %47, label %8

8:                                                ; preds = %5
  store i32 %1, ptr %6, align 4, !tbaa !5
  %9 = add nsw i32 %1, -1
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  store i32 %9, ptr %10, align 8, !tbaa !11
  %11 = load ptr, ptr %0, align 8, !tbaa !12
  %12 = icmp eq ptr %11, null
  br i1 %12, label %14, label %13

13:                                               ; preds = %8
  tail call void @_ZdaPv(ptr noundef nonnull %11) #6
  %.pre = load i32, ptr %6, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %13, %8
  %15 = phi i32 [ %.pre, %13 ], [ %1, %8 ]
  %16 = icmp ugt i32 %15, 16
  br i1 %16, label %.preheader, label %35

.preheader:                                       ; preds = %14, %.preheader
  %.0 = phi i32 [ %20, %.preheader ], [ 3, %14 ]
  %17 = add i32 %.0, 2
  %18 = shl nuw i32 1, %17
  %19 = icmp ugt i32 %15, %18
  %20 = add i32 %.0, 1
  br i1 %19, label %.preheader, label %21, !llvm.loop !13

21:                                               ; preds = %.preheader
  %22 = shl nuw i32 1, %.0
  %23 = getelementptr inbounds i8, ptr %0, i64 44
  store i32 %22, ptr %23, align 4, !tbaa !15
  %24 = sub i32 15, %.0
  %25 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %24, ptr %25, align 8, !tbaa !16
  %26 = shl i32 %15, 1
  %27 = add i32 %26, 2
  %28 = add i32 %27, %22
  %29 = zext i32 %28 to i64
  %30 = shl nuw nsw i64 %29, 2
  %31 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %30) #7
  store ptr %31, ptr %0, align 8, !tbaa !12
  %32 = zext i32 %26 to i64
  %33 = getelementptr inbounds i32, ptr %31, i64 %32
  %34 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %33, ptr %34, align 8, !tbaa !17
  br label %42

35:                                               ; preds = %14
  %36 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr null, ptr %36, align 8, !tbaa !17
  %37 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 0, ptr %37, align 8, !tbaa !16
  %38 = getelementptr inbounds i8, ptr %0, i64 44
  store i32 0, ptr %38, align 4, !tbaa !15
  %39 = shl nuw nsw i32 %15, 3
  %40 = zext nneg i32 %39 to i64
  %41 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %40) #7
  store ptr %41, ptr %0, align 8, !tbaa !12
  br label %42

42:                                               ; preds = %35, %21
  %43 = phi ptr [ %41, %35 ], [ %31, %21 ]
  %44 = zext i32 %15 to i64
  %45 = getelementptr inbounds i32, ptr %43, i64 %44
  %46 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %45, ptr %46, align 8, !tbaa !18
  br label %47

47:                                               ; preds = %42, %5
  tail call void @_ZN5o3dgc19Adaptive_Data_Model5resetEv(ptr noundef nonnull align 8 dereferenceable(52) %0)
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5o3dgc19Adaptive_Data_Model5resetEv(ptr noundef nonnull align 8 dereferenceable(52)) local_unnamed_addr #4 align 2

attributes #0 = { nobuiltin 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 = { mustprogress noreturn 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 = { nobuiltin allocsize(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 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 = { 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 #5 = { noreturn }
attributes #6 = { builtin nounwind }
attributes #7 = { builtin allocsize(0) }

!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 36}
!6 = !{!"_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}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 40}
!12 = !{!6, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !10, i64 44}
!16 = !{!6, !10, i64 48}
!17 = !{!6, !7, i64 16}
!18 = !{!6, !7, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass