; LLVM IR from seung-lab/fpzip :: fpzip-1.3.0/src/rcqsmodel.ll (ZN9RCqsmodel6decodeERjS0_)

; 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.RCqsmodel = type { %class.RCmodel.base, i32, i32, i32, i32, i32, i32, ptr, ptr, i32, ptr }
%class.RCmodel.base = type <{ ptr, i32 }>

; 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 uwtable
define dso_local noundef i32 @_ZN9RCqsmodel6decodeERjS0_(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2) unnamed_addr #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = getelementptr inbounds %class.RCqsmodel, ptr %11, i32 0, i32 9
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = lshr i32 %13, %15
  store i32 %16, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %17 = getelementptr inbounds %class.RCqsmodel, ptr %11, i32 0, i32 10
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds i32, ptr %18, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !9
  store i32 %22, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %23 = getelementptr inbounds %class.RCqsmodel, ptr %11, i32 0, i32 10
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = add i32 %25, 1
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds i32, ptr %24, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = add i32 %29, 1
  store i32 %30, ptr %9, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %54, %3
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = add i32 %32, 1
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = icmp ult i32 %33, %34
  br i1 %35, label %36, label %55

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = add i32 %37, %38
  %40 = udiv i32 %39, 2
  store i32 %40, ptr %10, align 4, !tbaa !9
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = getelementptr inbounds %class.RCqsmodel, ptr %11, i32 0, i32 8
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds i32, ptr %44, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = icmp ult i32 %42, %48
  br i1 %49, label %50, label %52

50:                                               ; preds = %36
  %51 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %51, ptr %9, align 4, !tbaa !9
  br label %54

52:                                               ; preds = %36
  %53 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %53, ptr %8, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %52, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %31, !llvm.loop !16

55:                                               ; preds = %31
  %56 = getelementptr inbounds %class.RCqsmodel, ptr %11, i32 0, i32 8
  %57 = load ptr, ptr %56, align 8, !tbaa !15
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds i32, ptr %57, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !9
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %61, ptr %62, align 4, !tbaa !9
  %63 = getelementptr inbounds %class.RCqsmodel, ptr %11, i32 0, i32 8
  %64 = load ptr, ptr %63, align 8, !tbaa !15
  %65 = load i32, ptr %8, align 4, !tbaa !9
  %66 = add i32 %65, 1
  %67 = zext i32 %66 to i64
  %68 = getelementptr inbounds i32, ptr %64, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !9
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = load i32, ptr %70, align 4, !tbaa !9
  %72 = sub i32 %69, %71
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %72, ptr %73, align 4, !tbaa !9
  %74 = load i32, ptr %8, align 4, !tbaa !9
  call void @_ZN9RCqsmodel6updateEj(ptr noundef nonnull align 8 dereferenceable(72) %11, i32 noundef %74)
  %75 = load i32, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 %75
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 56}
!12 = !{!"_ZTS9RCqsmodel", !13, i64 0, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40, !6, i64 48, !10, i64 56, !6, i64 64}
!13 = !{!"_ZTS7RCmodel", !10, i64 8}
!14 = !{!12, !6, i64 64}
!15 = !{!12, !6, i64 48}
!16 = distinct !{!16, !17}
!17 = !{!"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
define dso_local noundef i32 @_ZN9RCqsmodel6decodeERjS0_(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr nocapture noundef nonnull align 4 dereferenceable(4) %1, ptr nocapture noundef nonnull writeonly align 4 dereferenceable(4) %2) unnamed_addr #0 align 2 {
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 56
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = lshr i32 %4, %6
  %8 = getelementptr inbounds i8, ptr %0, i64 64
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  %10 = zext i32 %7 to i64
  %11 = getelementptr inbounds i32, ptr %9, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = add i32 %7, 1
  %14 = zext i32 %13 to i64
  %15 = getelementptr inbounds i32, ptr %9, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = add i32 %16, 1
  %18 = add i32 %12, 1
  %19 = icmp ult i32 %18, %17
  %20 = getelementptr inbounds i8, ptr %0, i64 48
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  br i1 %19, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.022 = phi i32 [ %.0., %.lr.ph ], [ %12, %3 ]
  %.01821 = phi i32 [ %..018, %.lr.ph ], [ %17, %3 ]
  %22 = add i32 %.022, %.01821
  %23 = lshr i32 %22, 1
  %24 = zext nneg i32 %23 to i64
  %25 = getelementptr inbounds i32, ptr %21, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp ult i32 %4, %26
  %..018 = select i1 %27, i32 %23, i32 %.01821
  %.0. = select i1 %27, i32 %.022, i32 %23
  %28 = add i32 %.0., 1
  %29 = icmp ult i32 %28, %..018
  br i1 %29, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.0.lcssa = phi i32 [ %12, %3 ], [ %.0., %.lr.ph ]
  %.lcssa = phi i32 [ %18, %3 ], [ %28, %.lr.ph ]
  %30 = zext i32 %.0.lcssa to i64
  %31 = getelementptr inbounds i32, ptr %21, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  store i32 %32, ptr %1, align 4, !tbaa !5
  %33 = zext i32 %.lcssa to i64
  %34 = getelementptr inbounds i32, ptr %21, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = sub i32 %35, %32
  store i32 %36, ptr %2, align 4, !tbaa !5
  tail call void @_ZN9RCqsmodel6updateEj(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %.0.lcssa)
  ret i32 %.0.lcssa
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN9RCqsmodel6updateEj(ptr noundef nonnull align 8 dereferenceable(72), i32 noundef) local_unnamed_addr #0 align 2

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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 56}
!10 = !{!"_ZTS9RCqsmodel", !11, i64 0, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !12, i64 40, !12, i64 48, !6, i64 56, !12, i64 64}
!11 = !{!"_ZTS7RCmodel", !6, i64 8}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !12, i64 64}
!14 = !{!10, !12, i64 48}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass