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

; 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.1 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [18 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 uwtable
define dso_local noundef i32 @_ZN7libzpaq7Decoder6decodeEi(ptr noundef nonnull align 8 dereferenceable(110672) %0, i32 noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %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 i32 %1, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  %9 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 3
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !17
  %13 = icmp ult i32 %10, %12
  br i1 %13, label %20, label %14

14:                                               ; preds = %2
  %15 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 3
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 2
  %18 = load i32, ptr %17, align 4, !tbaa !18
  %19 = icmp ugt i32 %16, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %14, %2
  call void @_ZN7libzpaq5errorEPKc(ptr noundef @.str.26)
  br label %21

21:                                               ; preds = %20, %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %22 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 1
  %23 = load i32, ptr %22, align 8, !tbaa !17
  %24 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 2
  %25 = load i32, ptr %24, align 4, !tbaa !18
  %26 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 1
  %27 = load i32, ptr %26, align 8, !tbaa !17
  %28 = sub i32 %25, %27
  %29 = zext i32 %28 to i64
  %30 = load i32, ptr %4, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  %32 = mul i64 %29, %31
  %33 = lshr i64 %32, 16
  %34 = trunc i64 %33 to i32
  %35 = add i32 %23, %34
  store i32 %35, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %36 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 3
  %37 = load i32, ptr %36, align 8, !tbaa !11
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = icmp ule i32 %37, %38
  %40 = zext i1 %39 to i32
  store i32 %40, ptr %6, align 4, !tbaa !9
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %46

43:                                               ; preds = %21
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 2
  store i32 %44, ptr %45, align 4, !tbaa !18
  br label %50

46:                                               ; preds = %21
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = add i32 %47, 1
  %49 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 1
  store i32 %48, ptr %49, align 8, !tbaa !17
  br label %50

50:                                               ; preds = %46, %43
  br label %51

51:                                               ; preds = %84, %50
  %52 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 2
  %53 = load i32, ptr %52, align 4, !tbaa !18
  %54 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 1
  %55 = load i32, ptr %54, align 8, !tbaa !17
  %56 = xor i32 %53, %55
  %57 = icmp ult i32 %56, 16777216
  br i1 %57, label %58, label %91

58:                                               ; preds = %51
  %59 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 2
  %60 = load i32, ptr %59, align 4, !tbaa !18
  %61 = shl i32 %60, 8
  %62 = or i32 %61, 255
  %63 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 2
  store i32 %62, ptr %63, align 4, !tbaa !18
  %64 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 1
  %65 = load i32, ptr %64, align 8, !tbaa !17
  %66 = shl i32 %65, 8
  %67 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 1
  store i32 %66, ptr %67, align 8, !tbaa !17
  %68 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 1
  %69 = load i32, ptr %68, align 8, !tbaa !17
  %70 = icmp eq i32 %69, 0
  %71 = zext i1 %70 to i32
  %72 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 1
  %73 = load i32, ptr %72, align 8, !tbaa !17
  %74 = add i32 %73, %71
  store i32 %74, ptr %72, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %75 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !19
  %77 = load ptr, ptr %76, align 8, !tbaa !20
  %78 = getelementptr inbounds ptr, ptr %77, i64 0
  %79 = load ptr, ptr %78, align 8
  %80 = call noundef i32 %79(ptr noundef nonnull align 8 dereferenceable(8) %76)
  store i32 %80, ptr %7, align 4, !tbaa !9
  %81 = load i32, ptr %7, align 4, !tbaa !9
  %82 = icmp slt i32 %81, 0
  br i1 %82, label %83, label %84

83:                                               ; preds = %58
  call void @_ZN7libzpaq5errorEPKc(ptr noundef @.str.1)
  br label %84

84:                                               ; preds = %83, %58
  %85 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 3
  %86 = load i32, ptr %85, align 8, !tbaa !11
  %87 = shl i32 %86, 8
  %88 = load i32, ptr %7, align 4, !tbaa !9
  %89 = or i32 %87, %88
  %90 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %8, i32 0, i32 3
  store i32 %89, ptr %90, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %51, !llvm.loop !22

91:                                               ; preds = %51
  %92 = load i32, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %92
}

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 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 16}
!12 = !{!"_ZTSN7libzpaq7DecoderE", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !13, i64 24, !15, i64 110648}
!13 = !{!"_ZTSN7libzpaq9PredictorE", !10, i64 0, !10, 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, !14, i64 109584, !6, i64 110608, !10, i64 110616}
!14 = !{!"_ZTSN7libzpaq10StateTableE", !7, i64 0}
!15 = !{!"_ZTSN7libzpaq5ArrayIcEE", !6, i64 0, !16, i64 8, !10, i64 16}
!16 = !{!"long", !7, i64 0}
!17 = !{!12, !10, i64 8}
!18 = !{!12, !10, i64 12}
!19 = !{!12, !6, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"vtable pointer", !8, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; 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.1 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [18 x i8], align 1

declare void @_ZN7libzpaq5errorEPKc(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN7libzpaq7Decoder6decodeEi(ptr nocapture noundef nonnull align 8 dereferenceable(110672) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !15
  %7 = icmp ult i32 %4, %6
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  %9 = load i32, ptr %8, align 4
  %10 = icmp ugt i32 %4, %9
  %or.cond = select i1 %7, i1 true, i1 %10
  br i1 %or.cond, label %11, label %12

11:                                               ; preds = %2
  tail call void @_ZN7libzpaq5errorEPKc(ptr noundef nonnull @.str.26)
  %.pre = load i32, ptr %5, align 8, !tbaa !15
  %.pre11 = load i32, ptr %8, align 4, !tbaa !16
  %.pre12 = load i32, ptr %3, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %2, %11
  %13 = phi i32 [ %4, %2 ], [ %.pre12, %11 ]
  %14 = phi i32 [ %9, %2 ], [ %.pre11, %11 ]
  %15 = phi i32 [ %6, %2 ], [ %.pre, %11 ]
  %16 = sub i32 %14, %15
  %17 = zext i32 %16 to i64
  %18 = zext i32 %1 to i64
  %19 = mul nuw i64 %17, %18
  %20 = lshr i64 %19, 16
  %21 = trunc i64 %20 to i32
  %22 = add i32 %15, %21
  %23 = icmp ule i32 %13, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %12
  store i32 %22, ptr %8, align 4, !tbaa !16
  br label %27

25:                                               ; preds = %12
  %26 = add nuw i32 %22, 1
  store i32 %26, ptr %5, align 8, !tbaa !15
  br label %27

27:                                               ; preds = %25, %24
  %28 = phi i32 [ %26, %25 ], [ %15, %24 ]
  %29 = phi i32 [ %14, %25 ], [ %22, %24 ]
  %30 = xor i32 %28, %29
  %31 = icmp ult i32 %30, 16777216
  br i1 %31, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %27, %46
  %32 = phi i32 [ %51, %46 ], [ %28, %27 ]
  %33 = phi i32 [ %50, %46 ], [ %29, %27 ]
  %34 = shl i32 %33, 8
  %35 = or disjoint i32 %34, 255
  store i32 %35, ptr %8, align 4, !tbaa !16
  %36 = shl i32 %32, 8
  %37 = icmp eq i32 %36, 0
  %38 = zext i1 %37 to i32
  %39 = or disjoint i32 %36, %38
  store i32 %39, ptr %5, align 8, !tbaa !15
  %40 = load ptr, ptr %0, align 8, !tbaa !17
  %41 = load ptr, ptr %40, align 8, !tbaa !18
  %42 = load ptr, ptr %41, align 8
  %43 = tail call noundef i32 %42(ptr noundef nonnull align 8 dereferenceable(8) %40)
  %44 = icmp slt i32 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %.lr.ph
  tail call void @_ZN7libzpaq5errorEPKc(ptr noundef nonnull @.str.1)
  br label %46

46:                                               ; preds = %45, %.lr.ph
  %47 = load i32, ptr %3, align 8, !tbaa !5
  %48 = shl i32 %47, 8
  %49 = or i32 %48, %43
  store i32 %49, ptr %3, align 8, !tbaa !5
  %50 = load i32, ptr %8, align 4, !tbaa !16
  %51 = load i32, ptr %5, align 8, !tbaa !15
  %52 = xor i32 %51, %50
  %53 = icmp ult i32 %52, 16777216
  br i1 %53, label %.lr.ph, label %._crit_edge, !llvm.loop !20

._crit_edge:                                      ; preds = %46, %27
  %54 = zext i1 %23 to i32
  ret i32 %54
}

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 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, !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, !10, i64 8}
!16 = !{!6, !10, i64 12}
!17 = !{!6, !7, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"vtable pointer", !9, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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