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

; 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::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::ZPAQL" = type { ptr, ptr, %"class.libzpaq::Array.0", i32, i32, i32, [4 x i8], %"class.libzpaq::Array.0", %"class.libzpaq::Array", %"class.libzpaq::Array", %"class.libzpaq::Array.4", i32, i32, i32, i32, i32, i32, i32, i32, ptr }
%"class.libzpaq::Array.4" = type <{ ptr, i64, i32, [4 x i8] }>

; 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 nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20), i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7libzpaq5ZPAQL3runEj(ptr noundef nonnull align 8 dereferenceable(192), i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7libzpaq5ZPAQL1HEi(ptr noundef nonnull align 8 dereferenceable(192), i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7libzpaq9Predictor6updateEi(ptr noundef nonnull align 8 dereferenceable(110620) %0, i32 noundef %1) #2 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 = getelementptr inbounds %"class.libzpaq::Predictor", ptr %6, i32 0, i32 11
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %8, i64 5
  %10 = load i32, ptr %4, align 4, !tbaa !9
  call void %9(ptr noundef %6, i32 noundef %10)
  %11 = getelementptr inbounds %"class.libzpaq::Predictor", ptr %6, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !14
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = add nsw i32 %12, %13
  %15 = getelementptr inbounds %"class.libzpaq::Predictor", ptr %6, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = add nsw i32 %16, %14
  store i32 %17, ptr %15, align 8, !tbaa !14
  %18 = getelementptr inbounds %"class.libzpaq::Predictor", ptr %6, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !14
  %20 = icmp sge i32 %19, 256
  br i1 %20, label %21, label %52

21:                                               ; preds = %2
  %22 = getelementptr inbounds %"class.libzpaq::Predictor", ptr %6, i32 0, i32 4
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = getelementptr inbounds %"class.libzpaq::Predictor", ptr %6, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !14
  %26 = sub nsw i32 %25, 256
  call void @_ZN7libzpaq5ZPAQL3runEj(ptr noundef nonnull align 8 dereferenceable(192) %23, i32 noundef %26)
  %27 = getelementptr inbounds %"class.libzpaq::Predictor", ptr %6, i32 0, i32 1
  store i32 1, ptr %27, align 4, !tbaa !16
  %28 = getelementptr inbounds %"class.libzpaq::Predictor", ptr %6, i32 0, i32 0
  store i32 1, ptr %28, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %48, %21
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = getelementptr inbounds %"class.libzpaq::Predictor", ptr %6, i32 0, i32 4
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = getelementptr inbounds %"class.libzpaq::ZPAQL", ptr %32, i32 0, i32 2
  %34 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %33, i64 noundef 6)
  %35 = load i8, ptr %34, align 1, !tbaa !17
  %36 = zext i8 %35 to i32
  %37 = icmp slt i32 %30, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %51

39:                                               ; preds = %29
  %40 = getelementptr inbounds %"class.libzpaq::Predictor", ptr %6, i32 0, i32 4
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = call noundef i32 @_ZN7libzpaq5ZPAQL1HEi(ptr noundef nonnull align 8 dereferenceable(192) %41, i32 noundef %42)
  %44 = getelementptr inbounds %"class.libzpaq::Predictor", ptr %6, i32 0, i32 3
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [256 x i32], ptr %44, i64 0, i64 %46
  store i32 %43, ptr %47, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %39
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %5, align 4, !tbaa !9
  br label %29, !llvm.loop !18

51:                                               ; preds = %38
  br label %84

52:                                               ; preds = %2
  %53 = getelementptr inbounds %"class.libzpaq::Predictor", ptr %6, i32 0, i32 0
  %54 = load i32, ptr %53, align 8, !tbaa !14
  %55 = icmp sge i32 %54, 16
  br i1 %55, label %56, label %70

56:                                               ; preds = %52
  %57 = getelementptr inbounds %"class.libzpaq::Predictor", ptr %6, i32 0, i32 0
  %58 = load i32, ptr %57, align 8, !tbaa !14
  %59 = icmp slt i32 %58, 32
  br i1 %59, label %60, label %70

60:                                               ; preds = %56
  %61 = getelementptr inbounds %"class.libzpaq::Predictor", ptr %6, i32 0, i32 1
  %62 = load i32, ptr %61, align 4, !tbaa !16
  %63 = and i32 %62, 15
  %64 = shl i32 %63, 5
  %65 = load i32, ptr %4, align 4, !tbaa !9
  %66 = shl i32 %65, 4
  %67 = or i32 %64, %66
  %68 = or i32 %67, 1
  %69 = getelementptr inbounds %"class.libzpaq::Predictor", ptr %6, i32 0, i32 1
  store i32 %68, ptr %69, align 4, !tbaa !16
  br label %83

70:                                               ; preds = %56, %52
  %71 = getelementptr inbounds %"class.libzpaq::Predictor", ptr %6, i32 0, i32 1
  %72 = load i32, ptr %71, align 4, !tbaa !16
  %73 = and i32 %72, 496
  %74 = getelementptr inbounds %"class.libzpaq::Predictor", ptr %6, i32 0, i32 1
  %75 = load i32, ptr %74, align 4, !tbaa !16
  %76 = and i32 %75, 15
  %77 = mul nsw i32 %76, 2
  %78 = load i32, ptr %4, align 4, !tbaa !9
  %79 = add nsw i32 %77, %78
  %80 = and i32 %79, 15
  %81 = or i32 %73, %80
  %82 = getelementptr inbounds %"class.libzpaq::Predictor", ptr %6, i32 0, i32 1
  store i32 %81, ptr %82, align 4, !tbaa !16
  br label %83

83:                                               ; preds = %70, %60
  br label %84

84:                                               ; preds = %83, %51
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !6, i64 110608}
!12 = !{!"_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, !13, i64 109584, !6, i64 110608, !10, i64 110616}
!13 = !{!"_ZTSN7libzpaq10StateTableE", !7, i64 0}
!14 = !{!12, !10, i64 0}
!15 = !{!12, !6, i64 2056}
!16 = !{!12, !10, i64 4}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7libzpaq5ZPAQL3runEj(ptr noundef nonnull align 8 dereferenceable(192), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7libzpaq5ZPAQL1HEi(ptr noundef nonnull align 8 dereferenceable(192), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7libzpaq9Predictor6updateEi(ptr noundef nonnull align 8 dereferenceable(110620) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 110608
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 5
  tail call void %5(ptr noundef nonnull %0, i32 noundef %1)
  %6 = load i32, ptr %0, align 8, !tbaa !12
  %reass.add = shl i32 %6, 1
  %7 = add i32 %reass.add, %1
  store i32 %7, ptr %0, align 8, !tbaa !12
  %8 = icmp sgt i32 %7, 255
  br i1 %8, label %9, label %30

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %0, i64 2056
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = add nsw i32 %7, -256
  tail call void @_ZN7libzpaq5ZPAQL3runEj(ptr noundef nonnull align 8 dereferenceable(192) %11, i32 noundef %12)
  %13 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 1, ptr %13, align 4, !tbaa !14
  store i32 1, ptr %0, align 8, !tbaa !12
  %14 = load ptr, ptr %10, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  %16 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %15, i64 noundef 6)
  %17 = load i8, ptr %16, align 1, !tbaa !15
  %.not = icmp eq i8 %17, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %9
  %18 = getelementptr inbounds i8, ptr %0, i64 1032
  br label %19

19:                                               ; preds = %.lr.ph, %19
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %19 ]
  %20 = load ptr, ptr %10, align 8, !tbaa !13
  %21 = trunc nuw nsw i64 %indvars.iv to i32
  %22 = tail call noundef i32 @_ZN7libzpaq5ZPAQL1HEi(ptr noundef nonnull align 8 dereferenceable(192) %20, i32 noundef %21)
  %23 = getelementptr inbounds [256 x i32], ptr %18, i64 0, i64 %indvars.iv
  store i32 %22, ptr %23, align 4, !tbaa !16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %24 = load ptr, ptr %10, align 8, !tbaa !13
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  %26 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %25, i64 noundef 6)
  %27 = load i8, ptr %26, align 1, !tbaa !15
  %28 = zext i8 %27 to i64
  %29 = icmp ult i64 %indvars.iv.next, %28
  br i1 %29, label %19, label %.loopexit, !llvm.loop !17

30:                                               ; preds = %2
  %31 = and i32 %7, -16
  %or.cond = icmp eq i32 %31, 16
  %32 = getelementptr inbounds i8, ptr %0, i64 4
  %33 = load i32, ptr %32, align 4, !tbaa !14
  br i1 %or.cond, label %34, label %40

34:                                               ; preds = %30
  %35 = shl i32 %33, 5
  %36 = and i32 %35, 480
  %37 = shl i32 %1, 4
  %38 = or i32 %37, %36
  %39 = or disjoint i32 %38, 1
  br label %.loopexit.sink.split

40:                                               ; preds = %30
  %41 = and i32 %33, 496
  %42 = shl i32 %33, 1
  %43 = add i32 %42, %1
  %44 = and i32 %43, 15
  %45 = or disjoint i32 %44, %41
  br label %.loopexit.sink.split

.loopexit.sink.split:                             ; preds = %40, %34
  %.sink = phi i32 [ %39, %34 ], [ %45, %40 ]
  store i32 %.sink, ptr %32, align 4, !tbaa !14
  br label %.loopexit

.loopexit:                                        ; preds = %19, %.loopexit.sink.split, %9
  ret void
}

attributes #0 = { 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 #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 110608}
!6 = !{!"_ZTSN7libzpaq9PredictorE", !7, i64 0, !7, i64 4, !8, i64 8, !8, i64 1032, !10, i64 2056, !8, i64 2064, !8, i64 30736, !8, i64 31760, !8, i64 35856, !8, i64 44048, !11, i64 109584, !10, i64 110608, !7, i64 110616}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTSN7libzpaq10StateTableE", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !10, i64 2056}
!14 = !{!6, !7, i64 4}
!15 = !{!8, !8, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass