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

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

32:                                               ; preds = %45, %1
  %33 = load i32, ptr %6, align 4, !tbaa !12
  %34 = load i32, ptr %5, align 4, !tbaa !12
  %35 = icmp ult i32 %33, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %48

37:                                               ; preds = %32
  %38 = load i32, ptr %4, align 4, !tbaa !12
  %39 = add i32 %38, 1
  %40 = getelementptr inbounds %class.RCqsmodel, ptr %8, i32 0, i32 7
  %41 = load ptr, ptr %40, align 8, !tbaa !17
  %42 = load i32, ptr %6, align 4, !tbaa !12
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds i32, ptr %41, i64 %43
  store i32 %39, ptr %44, align 4, !tbaa !12
  br label %45

45:                                               ; preds = %37
  %46 = load i32, ptr %6, align 4, !tbaa !12
  %47 = add i32 %46, 1
  store i32 %47, ptr %6, align 4, !tbaa !12
  br label %32, !llvm.loop !18

48:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %49 = load i32, ptr %5, align 4, !tbaa !12
  store i32 %49, ptr %7, align 4, !tbaa !12
  br label %50

50:                                               ; preds = %62, %48
  %51 = load i32, ptr %7, align 4, !tbaa !12
  %52 = load i32, ptr %3, align 4, !tbaa !12
  %53 = icmp ult i32 %51, %52
  br i1 %53, label %55, label %54

54:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %65

55:                                               ; preds = %50
  %56 = load i32, ptr %4, align 4, !tbaa !12
  %57 = getelementptr inbounds %class.RCqsmodel, ptr %8, i32 0, i32 7
  %58 = load ptr, ptr %57, align 8, !tbaa !17
  %59 = load i32, ptr %7, align 4, !tbaa !12
  %60 = zext i32 %59 to i64
  %61 = getelementptr inbounds i32, ptr %58, i64 %60
  store i32 %56, ptr %61, align 4, !tbaa !12
  br label %62

62:                                               ; preds = %55
  %63 = load i32, ptr %7, align 4, !tbaa !12
  %64 = add i32 %63, 1
  store i32 %64, ptr %7, align 4, !tbaa !12
  br label %50, !llvm.loop !20

65:                                               ; preds = %54
  call void @_ZN9RCqsmodel6updateEv(ptr noundef nonnull align 8 dereferenceable(72) %8)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

; 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 void @_ZN9RCqsmodel6updateEv(ptr noundef nonnull align 8 dereferenceable(72)) #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, !11, i64 8}
!10 = !{!"_ZTS7RCmodel", !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !11, i64 28}
!14 = !{!"_ZTS9RCqsmodel", !10, i64 0, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !6, i64 40, !6, i64 48, !11, i64 56, !6, i64 64}
!15 = !{!14, !11, i64 20}
!16 = !{!14, !6, i64 48}
!17 = !{!14, !6, i64 40}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; 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 void @_ZN9RCqsmodel5resetEv(ptr noundef nonnull align 8 dereferenceable(72) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = lshr i32 %3, 4
  %5 = or i32 %4, 2
  %6 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 %5, ptr %6, align 4, !tbaa !10
  %7 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 0, ptr %7, align 4, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  %10 = zext i32 %3 to i64
  %11 = getelementptr inbounds i32, ptr %9, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !15
  %.fr23 = freeze i32 %12
  %13 = udiv i32 %.fr23, %3
  %14 = urem i32 %.fr23, %3
  %15 = urem i32 %.fr23, %3
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %..preheader_crit_edge, label %.lr.ph

..preheader_crit_edge:                            ; preds = %1
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 40
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !16
  br label %.preheader

.lr.ph:                                           ; preds = %1
  %16 = add i32 %13, 1
  %17 = getelementptr inbounds i8, ptr %0, i64 40
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %19 = zext i32 %15 to i64
  %min.iters.check = icmp ult i32 %15, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %19, 4294967288
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %16, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %20 = getelementptr inbounds i32, ptr %18, i64 %index
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  store <4 x i32> %broadcast.splat, ptr %20, align 4, !tbaa !15
  store <4 x i32> %broadcast.splat, ptr %21, align 4, !tbaa !15
  %index.next = add nuw i64 %index, 8
  %22 = icmp eq i64 %index.next, %n.vec
  br i1 %22, label %middle.block, label %vector.body, !llvm.loop !17

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %19
  br i1 %cmp.n, label %.preheader, label %scalar.ph.preheader

.preheader:                                       ; preds = %scalar.ph, %middle.block, %..preheader_crit_edge
  %23 = phi ptr [ %.pre, %..preheader_crit_edge ], [ %18, %middle.block ], [ %18, %scalar.ph ]
  %24 = zext i32 %14 to i64
  %25 = zext i32 %.fr23 to i64
  %26 = add nuw nsw i64 %25, 1
  %27 = urem i64 %25, %10
  %28 = sub nuw nsw i64 %25, %27
  %29 = sub nsw i64 %26, %28
  %umax = tail call i64 @llvm.umax.i64(i64 %29, i64 %10)
  %30 = add i64 %umax, %28
  %31 = sub i64 %30, %25
  %min.iters.check26 = icmp ult i64 %31, 8
  br i1 %min.iters.check26, label %scalar.ph25.preheader, label %vector.ph27

scalar.ph25.preheader:                            ; preds = %middle.block24, %.preheader
  %indvars.iv21.ph = phi i64 [ %24, %.preheader ], [ %ind.end, %middle.block24 ]
  br label %scalar.ph25

vector.ph27:                                      ; preds = %.preheader
  %n.vec29 = and i64 %31, -8
  %ind.end = add i64 %n.vec29, %24
  %broadcast.splatinsert33 = insertelement <4 x i32> poison, i32 %13, i64 0
  %broadcast.splat34 = shufflevector <4 x i32> %broadcast.splatinsert33, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body31

vector.body31:                                    ; preds = %vector.body31, %vector.ph27
  %index32 = phi i64 [ 0, %vector.ph27 ], [ %index.next35, %vector.body31 ]
  %offset.idx = add i64 %index32, %24
  %32 = getelementptr inbounds i32, ptr %23, i64 %offset.idx
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  store <4 x i32> %broadcast.splat34, ptr %32, align 4, !tbaa !15
  store <4 x i32> %broadcast.splat34, ptr %33, align 4, !tbaa !15
  %index.next35 = add nuw i64 %index32, 8
  %34 = icmp eq i64 %index.next35, %n.vec29
  br i1 %34, label %middle.block24, label %vector.body31, !llvm.loop !21

middle.block24:                                   ; preds = %vector.body31
  %cmp.n36 = icmp eq i64 %31, %n.vec29
  br i1 %cmp.n36, label %.loopexit, label %scalar.ph25.preheader

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %35 = getelementptr inbounds i32, ptr %18, i64 %indvars.iv
  store i32 %16, ptr %35, align 4, !tbaa !15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %36 = icmp ult i64 %indvars.iv.next, %19
  br i1 %36, label %scalar.ph, label %.preheader, !llvm.loop !22

.loopexit:                                        ; preds = %scalar.ph25, %middle.block24
  tail call void @_ZN9RCqsmodel6updateEv(ptr noundef nonnull align 8 dereferenceable(72) %0)
  ret void

scalar.ph25:                                      ; preds = %scalar.ph25.preheader, %scalar.ph25
  %indvars.iv21 = phi i64 [ %indvars.iv.next22, %scalar.ph25 ], [ %indvars.iv21.ph, %scalar.ph25.preheader ]
  %37 = getelementptr inbounds i32, ptr %23, i64 %indvars.iv21
  store i32 %13, ptr %37, align 4, !tbaa !15
  %indvars.iv.next22 = add nuw i64 %indvars.iv21, 1
  %38 = icmp ult i64 %indvars.iv.next22, %10
  br i1 %38, label %scalar.ph25, label %.loopexit, !llvm.loop !23
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #1

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


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass