; LLVM IR from fwip/fastqz :: libzpaq.ll (ZN7libzpaq7Decoder7loadbufEv)

; 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.libzpaq::Decoder" = type { ptr, i32, i32, i32, [4 x i8], %"class.libzpaq::Predictor", %"class.libzpaq::Array.4" }
%"class.libzpaq::Predictor" = type <{ i32, i32, [256 x i32], [256 x i32], ptr, [256 x %"struct.libzpaq::Component"], [256 x i32], [1024 x i32], [4096 x i16], [32768 x i16], %"class.libzpaq::StateTable", ptr, i32, [4 x i8] }>
%"struct.libzpaq::Component" = type { i64, i64, i64, i64, i64, %"class.libzpaq::Array", %"class.libzpaq::Array.0", %"class.libzpaq::Array.2" }
%"class.libzpaq::Array" = type <{ ptr, i64, i32, [4 x i8] }>
%"class.libzpaq::Array.0" = type <{ ptr, i64, i32, [4 x i8] }>
%"class.libzpaq::Array.2" = type <{ ptr, i64, i32, [4 x i8] }>
%"class.libzpaq::StateTable" = type { [1024 x i8] }
%"class.libzpaq::Array.4" = type <{ ptr, i64, i32, [4 x i8] }>

@.str.25 = external hidden unnamed_addr constant [24 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

declare void @_ZN7libzpaq5errorEPKc(ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIcEixEm(ptr noundef nonnull align 8 dereferenceable(20), i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7libzpaq7Decoder7loadbufEv(ptr noundef nonnull align 8 dereferenceable(110672) %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  %7 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %6, i32 0, i32 3
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %36

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !16
  br label %11

11:                                               ; preds = %32, %10
  %12 = load i32, ptr %3, align 4, !tbaa !16
  %13 = icmp slt i32 %12, 4
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %35

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %16 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %6, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !17
  %18 = load ptr, ptr %17, align 8, !tbaa !18
  %19 = getelementptr inbounds ptr, ptr %18, i64 0
  %20 = load ptr, ptr %19, align 8
  %21 = call noundef i32 %20(ptr noundef nonnull align 8 dereferenceable(8) %17)
  store i32 %21, ptr %4, align 4, !tbaa !16
  %22 = load i32, ptr %4, align 4, !tbaa !16
  %23 = icmp slt i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %15
  call void @_ZN7libzpaq5errorEPKc(ptr noundef @.str.25)
  br label %25

25:                                               ; preds = %24, %15
  %26 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %6, i32 0, i32 3
  %27 = load i32, ptr %26, align 8, !tbaa !9
  %28 = shl i32 %27, 8
  %29 = load i32, ptr %4, align 4, !tbaa !16
  %30 = or i32 %28, %29
  %31 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %6, i32 0, i32 3
  store i32 %30, ptr %31, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %32

32:                                               ; preds = %25
  %33 = load i32, ptr %3, align 4, !tbaa !16
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %3, align 4, !tbaa !16
  br label %11, !llvm.loop !20

35:                                               ; preds = %14
  br label %36

36:                                               ; preds = %35, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %37 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %6, i32 0, i32 6
  %38 = call noundef i64 @_ZNK7libzpaq5ArrayIcE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20) %37)
  %39 = trunc i64 %38 to i32
  store i32 %39, ptr %5, align 4, !tbaa !16
  %40 = load i32, ptr %5, align 4, !tbaa !16
  %41 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %6, i32 0, i32 3
  %42 = load i32, ptr %41, align 8, !tbaa !9
  %43 = icmp ugt i32 %40, %42
  br i1 %43, label %44, label %47

44:                                               ; preds = %36
  %45 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %6, i32 0, i32 3
  %46 = load i32, ptr %45, align 8, !tbaa !9
  store i32 %46, ptr %5, align 4, !tbaa !16
  br label %47

47:                                               ; preds = %44, %36
  %48 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %6, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  %50 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %6, i32 0, i32 6
  %51 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIcEixEm(ptr noundef nonnull align 8 dereferenceable(20) %50, i64 noundef 0)
  %52 = load i32, ptr %5, align 4, !tbaa !16
  %53 = load ptr, ptr %49, align 8, !tbaa !18
  %54 = getelementptr inbounds ptr, ptr %53, i64 1
  %55 = load ptr, ptr %54, align 8
  %56 = call noundef i32 %55(ptr noundef nonnull align 8 dereferenceable(8) %49, ptr noundef %51, i32 noundef %52)
  %57 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %6, i32 0, i32 2
  store i32 %56, ptr %57, align 4, !tbaa !22
  %58 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %6, i32 0, i32 2
  %59 = load i32, ptr %58, align 4, !tbaa !22
  %60 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %6, i32 0, i32 3
  %61 = load i32, ptr %60, align 8, !tbaa !9
  %62 = sub i32 %61, %59
  store i32 %62, ptr %60, align 8, !tbaa !9
  %63 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %6, i32 0, i32 1
  store i32 0, ptr %63, align 8, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK7libzpaq5ArrayIcE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20)) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #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 = { 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, !11, i64 16}
!10 = !{!"_ZTSN7libzpaq7DecoderE", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !12, i64 24, !14, i64 110648}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTSN7libzpaq9PredictorE", !11, i64 0, !11, i64 4, !7, i64 8, !7, i64 1032, !6, i64 2056, !7, i64 2064, !7, i64 30736, !7, i64 31760, !7, i64 35856, !7, i64 44048, !13, i64 109584, !6, i64 110608, !11, i64 110616}
!13 = !{!"_ZTSN7libzpaq10StateTableE", !7, i64 0}
!14 = !{!"_ZTSN7libzpaq5ArrayIcEE", !6, i64 0, !15, i64 8, !11, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!10, !6, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"vtable pointer", !8, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!10, !11, i64 12}
!23 = !{!10, !11, 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.25 = external hidden unnamed_addr constant [24 x i8], align 1

declare void @_ZN7libzpaq5errorEPKc(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIcEixEm(ptr noundef nonnull align 8 dereferenceable(20), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7libzpaq7Decoder7loadbufEv(ptr noundef nonnull align 8 dereferenceable(110672) %0) local_unnamed_addr #2 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %.preheader.preheader, label %.loopexit

.preheader.preheader:                             ; preds = %1
  %5 = load ptr, ptr %0, align 8, !tbaa !15
  %6 = load ptr, ptr %5, align 8, !tbaa !16
  %7 = load ptr, ptr %6, align 8
  %8 = tail call noundef i32 %7(ptr noundef nonnull align 8 dereferenceable(8) %5)
  %9 = icmp slt i32 %8, 0
  br i1 %9, label %10, label %.preheader.1

10:                                               ; preds = %.preheader.preheader
  tail call void @_ZN7libzpaq5errorEPKc(ptr noundef nonnull @.str.25)
  br label %.preheader.1

.preheader.1:                                     ; preds = %10, %.preheader.preheader
  %11 = load i32, ptr %2, align 8, !tbaa !5
  %12 = shl i32 %11, 8
  %13 = or i32 %12, %8
  store i32 %13, ptr %2, align 8, !tbaa !5
  %14 = load ptr, ptr %0, align 8, !tbaa !15
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  %16 = load ptr, ptr %15, align 8
  %17 = tail call noundef i32 %16(ptr noundef nonnull align 8 dereferenceable(8) %14)
  %18 = icmp slt i32 %17, 0
  br i1 %18, label %19, label %.preheader.2

19:                                               ; preds = %.preheader.1
  tail call void @_ZN7libzpaq5errorEPKc(ptr noundef nonnull @.str.25)
  br label %.preheader.2

.preheader.2:                                     ; preds = %19, %.preheader.1
  %20 = load i32, ptr %2, align 8, !tbaa !5
  %21 = shl i32 %20, 8
  %22 = or i32 %21, %17
  store i32 %22, ptr %2, align 8, !tbaa !5
  %23 = load ptr, ptr %0, align 8, !tbaa !15
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = load ptr, ptr %24, align 8
  %26 = tail call noundef i32 %25(ptr noundef nonnull align 8 dereferenceable(8) %23)
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %28, label %.preheader.3

28:                                               ; preds = %.preheader.2
  tail call void @_ZN7libzpaq5errorEPKc(ptr noundef nonnull @.str.25)
  br label %.preheader.3

.preheader.3:                                     ; preds = %28, %.preheader.2
  %29 = load i32, ptr %2, align 8, !tbaa !5
  %30 = shl i32 %29, 8
  %31 = or i32 %30, %26
  store i32 %31, ptr %2, align 8, !tbaa !5
  %32 = load ptr, ptr %0, align 8, !tbaa !15
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  %34 = load ptr, ptr %33, align 8
  %35 = tail call noundef i32 %34(ptr noundef nonnull align 8 dereferenceable(8) %32)
  %36 = icmp slt i32 %35, 0
  br i1 %36, label %37, label %.loopexit.loopexit

37:                                               ; preds = %.preheader.3
  tail call void @_ZN7libzpaq5errorEPKc(ptr noundef nonnull @.str.25)
  br label %.loopexit.loopexit

.loopexit.loopexit:                               ; preds = %37, %.preheader.3
  %38 = load i32, ptr %2, align 8, !tbaa !5
  %39 = shl i32 %38, 8
  %40 = or i32 %39, %35
  store i32 %40, ptr %2, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %1
  %41 = getelementptr inbounds i8, ptr %0, i64 110648
  %42 = tail call noundef i64 @_ZNK7libzpaq5ArrayIcE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20) %41)
  %43 = trunc i64 %42 to i32
  %44 = load i32, ptr %2, align 8, !tbaa !5
  %spec.select = tail call i32 @llvm.umin.i32(i32 %44, i32 %43)
  %45 = load ptr, ptr %0, align 8, !tbaa !15
  %46 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIcEixEm(ptr noundef nonnull align 8 dereferenceable(20) %41, i64 noundef 0)
  %47 = load ptr, ptr %45, align 8, !tbaa !16
  %48 = getelementptr inbounds i8, ptr %47, i64 8
  %49 = load ptr, ptr %48, align 8
  %50 = tail call noundef i32 %49(ptr noundef nonnull align 8 dereferenceable(8) %45, ptr noundef nonnull %46, i32 noundef %spec.select)
  %51 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %50, ptr %51, align 4, !tbaa !18
  %52 = load i32, ptr %2, align 8, !tbaa !5
  %53 = sub i32 %52, %50
  store i32 %53, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 0, ptr %54, align 8, !tbaa !19
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK7libzpaq5ArrayIcE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20)) local_unnamed_addr #1 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #3

attributes #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" }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 16}
!6 = !{!"_ZTSN7libzpaq7DecoderE", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !11, i64 24, !13, i64 110648}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTSN7libzpaq9PredictorE", !10, i64 0, !10, i64 4, !8, i64 8, !8, i64 1032, !7, i64 2056, !8, i64 2064, !8, i64 30736, !8, i64 31760, !8, i64 35856, !8, i64 44048, !12, i64 109584, !7, i64 110608, !10, i64 110616}
!12 = !{!"_ZTSN7libzpaq10StateTableE", !8, i64 0}
!13 = !{!"_ZTSN7libzpaq5ArrayIcEE", !7, i64 0, !14, i64 8, !10, i64 16}
!14 = !{!"long", !8, i64 0}
!15 = !{!6, !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"vtable pointer", !9, i64 0}
!18 = !{!6, !10, i64 12}
!19 = !{!6, !10, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass