; 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::Arithmetic_Codec" = type <{ ptr, ptr, ptr, i32, i32, i32, i32, i32, [4 x i8] }>

@.str.5 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [21 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: mustprogress noreturn uwtable
declare hidden void @_ZN5o3dgcL8AC_ErrorEPKc(ptr noundef) #1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5o3dgc16Arithmetic_Codec14read_from_fileEP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(44) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  br label %9

9:                                                ; preds = %23, %2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call i32 @getc(ptr noundef %10)
  store i32 %11, ptr %7, align 4, !tbaa !9
  %12 = icmp eq i32 %11, -1
  br i1 %12, label %13, label %14

13:                                               ; preds = %9
  call void @_ZN5o3dgcL8AC_ErrorEPKc(ptr noundef @.str.5) #5
  unreachable

14:                                               ; preds = %9
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = and i32 %15, 127
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = shl i32 %16, %17
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = or i32 %19, %18
  store i32 %20, ptr %6, align 4, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = add i32 %21, 7
  store i32 %22, ptr %5, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %14
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = and i32 %24, 128
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %9, label %27, !llvm.loop !11

27:                                               ; preds = %23
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %8, i32 0, i32 6
  %30 = load i32, ptr %29, align 4, !tbaa !13
  %31 = icmp ugt i32 %28, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %27
  call void @_ZN5o3dgcL8AC_ErrorEPKc(ptr noundef @.str.6) #5
  unreachable

33:                                               ; preds = %27
  %34 = getelementptr inbounds %"class.o3dgc::Arithmetic_Codec", ptr %8, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = call i64 @fread(ptr noundef %35, i64 noundef 1, i64 noundef %37, ptr noundef %38)
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = icmp ne i64 %39, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %33
  call void @_ZN5o3dgcL8AC_ErrorEPKc(ptr noundef @.str.5) #5
  unreachable

44:                                               ; preds = %33
  call void @_ZN5o3dgc16Arithmetic_Codec13start_decoderEv(ptr noundef nonnull align 8 dereferenceable(44) %8)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

declare i32 @getc(ptr noundef) #3

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { "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 }
attributes #5 = { noreturn }

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 36}
!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, !6, i64 0}


; 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.5 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [21 x i8], align 1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5o3dgc16Arithmetic_Codec14read_from_fileEP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(44) %0, ptr nocapture noundef %1) local_unnamed_addr #1 align 2 {
  br label %3

3:                                                ; preds = %7, %2
  %.010 = phi i32 [ 0, %2 ], [ %10, %7 ]
  %.0 = phi i32 [ 0, %2 ], [ %11, %7 ]
  %4 = tail call i32 @getc(ptr noundef %1)
  %5 = icmp eq i32 %4, -1
  br i1 %5, label %6, label %7

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

7:                                                ; preds = %3
  %8 = and i32 %4, 127
  %9 = shl i32 %8, %.0
  %10 = or i32 %9, %.010
  %11 = add i32 %.0, 7
  %12 = and i32 %4, 128
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %13, label %3, !llvm.loop !5

13:                                               ; preds = %7
  %14 = getelementptr inbounds i8, ptr %0, i64 36
  %15 = load i32, ptr %14, align 4, !tbaa !7
  %16 = icmp ugt i32 %10, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %13
  tail call void @_ZN5o3dgcL8AC_ErrorEPKc(ptr noundef nonnull @.str.6) #3
  unreachable

18:                                               ; preds = %13
  %19 = load ptr, ptr %0, align 8, !tbaa !13
  %20 = zext i32 %10 to i64
  %21 = tail call i64 @fread(ptr noundef %19, i64 noundef 1, i64 noundef %20, ptr noundef %1)
  %.not13 = icmp eq i64 %21, %20
  br i1 %.not13, label %23, label %22

22:                                               ; preds = %18
  tail call void @_ZN5o3dgcL8AC_ErrorEPKc(ptr noundef nonnull @.str.5) #3
  unreachable

23:                                               ; preds = %18
  tail call void @_ZN5o3dgc16Arithmetic_Codec13start_decoderEv(ptr noundef nonnull align 8 dereferenceable(44) %0)
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @getc(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { 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 #2 = { nofree 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 #3 = { noreturn }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !12, i64 36}
!8 = !{!"_ZTSN5o3dgc16Arithmetic_CodecE", !9, i64 0, !9, i64 8, !9, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"int", !10, i64 0}
!13 = !{!8, !9, i64 0}


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