; 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] }>

@.str = external hidden unnamed_addr constant [26 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5o3dgc16Arithmetic_Codec10set_bufferEjPh(ptr noundef nonnull align 8 dereferenceable(44) %0, i32 noundef %1, ptr noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  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
  %7 = load ptr, ptr %4, align 8
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %11, label %10

10:                                               ; preds = %3
  call void @_ZN5o3dgcL8AC_ErrorEPKc(ptr noundef @.str)
  br label %11

11:                                               ; preds = %10, %3
  %12 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %7, i32 0, i32 7
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %11
  call void @_ZN5o3dgcL8AC_ErrorEPKc(ptr noundef @.str.1)
  br label %16

16:                                               ; preds = %15, %11
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %30

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

27:                                               ; preds = %19
  call void @_ZdaPv(ptr noundef %25) #3
  br label %28

28:                                               ; preds = %27, %19
  %29 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %7, i32 0, i32 1
  store ptr null, ptr %29, align 8, !tbaa !15
  br label %53

30:                                               ; preds = %16
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %7, i32 0, i32 6
  %33 = load i32, ptr %32, align 4, !tbaa !13
  %34 = icmp ule i32 %31, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %30
  br label %53

36:                                               ; preds = %30
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %7, i32 0, i32 6
  store i32 %37, ptr %38, align 4, !tbaa !13
  %39 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %7, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = icmp eq ptr %40, null
  br i1 %41, label %43, label %42

42:                                               ; preds = %36
  call void @_ZdaPv(ptr noundef %40) #3
  br label %43

43:                                               ; preds = %42, %36
  %44 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %7, i32 0, i32 6
  %45 = load i32, ptr %44, align 4, !tbaa !13
  %46 = add i32 %45, 16
  %47 = zext i32 %46 to i64
  %48 = call noalias noundef nonnull ptr @_Znam(i64 noundef %47) #4
  %49 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %7, i32 0, i32 1
  store ptr %48, ptr %49, align 8, !tbaa !15
  %50 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %7, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !15
  %52 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %7, i32 0, i32 0
  store ptr %51, ptr %52, align 8, !tbaa !14
  br label %53

53:                                               ; preds = %43, %35, %28
  ret void
}

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

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

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

attributes #0 = { 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 #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 = { 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 = { builtin nounwind }
attributes #4 = { 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 40}
!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 = !{!12, !10, i64 36}
!14 = !{!12, !6, i64 0}
!15 = !{!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 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5o3dgc16Arithmetic_Codec10set_bufferEjPh(ptr nocapture noundef nonnull align 8 dereferenceable(44) %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 align 2 {
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %4, label %5

4:                                                ; preds = %3
  tail call void @_ZN5o3dgcL8AC_ErrorEPKc(ptr noundef nonnull @.str)
  br label %5

5:                                                ; preds = %4, %3
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %.not9 = icmp eq i32 %7, 0
  br i1 %.not9, label %9, label %8

8:                                                ; preds = %5
  tail call void @_ZN5o3dgcL8AC_ErrorEPKc(ptr noundef nonnull @.str.1)
  br label %9

9:                                                ; preds = %8, %5
  %.not10 = icmp eq ptr %2, null
  %10 = getelementptr inbounds i8, ptr %0, i64 36
  br i1 %.not10, label %17, label %11

11:                                               ; preds = %9
  store i32 %1, ptr %10, align 4, !tbaa !11
  store ptr %2, ptr %0, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = icmp eq ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  tail call void @_ZdaPv(ptr noundef nonnull %13) #3
  br label %16

16:                                               ; preds = %15, %11
  store ptr null, ptr %12, align 8, !tbaa !13
  br label %29

17:                                               ; preds = %9
  %18 = load i32, ptr %10, align 4, !tbaa !11
  %.not11 = icmp ult i32 %18, %1
  br i1 %.not11, label %19, label %29

19:                                               ; preds = %17
  store i32 %1, ptr %10, align 4, !tbaa !11
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = icmp eq ptr %21, null
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  tail call void @_ZdaPv(ptr noundef nonnull %21) #3
  %.pre = load i32, ptr %10, align 4, !tbaa !11
  br label %24

24:                                               ; preds = %23, %19
  %25 = phi i32 [ %.pre, %23 ], [ %1, %19 ]
  %26 = add i32 %25, 16
  %27 = zext i32 %26 to i64
  %28 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %27) #4
  store ptr %28, ptr %20, align 8, !tbaa !13
  store ptr %28, ptr %0, align 8, !tbaa !12
  br label %29

29:                                               ; preds = %17, %24, %16
  ret void
}

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

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

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

attributes #0 = { 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 #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 = { 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 = { builtin nounwind }
attributes #4 = { 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 40}
!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 = !{!6, !10, i64 36}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 8}


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