; LLVM IR from IOsonata/IOsonata :: src/storage/diskio_impl.ll/ZN6DiskIO8SetCacheEP19 (DiskIO_Cache_Desci)

; 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.DiskIO = type { ptr, i32, i32, i32, ptr }
%struct.__DiskIO_Cache_Desc = type { i32, i32, ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6DiskIO8SetCacheEP19__DiskIO_Cache_Desci(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef %1, i32 noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %14, label %11

11:                                               ; preds = %3
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = icmp sle i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %11, %3
  br label %42

15:                                               ; preds = %11
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = getelementptr inbounds %class.DiskIO, ptr %8, i32 0, i32 3
  store i32 %16, ptr %17, align 8, !tbaa !11
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %class.DiskIO, ptr %8, i32 0, i32 4
  store ptr %18, ptr %19, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %39, %15
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = getelementptr inbounds %class.DiskIO, ptr %8, i32 0, i32 3
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = icmp slt i32 %21, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %42

26:                                               ; preds = %20
  %27 = getelementptr inbounds %class.DiskIO, ptr %8, i32 0, i32 4
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %struct.__DiskIO_Cache_Desc, ptr %28, i64 %30
  %32 = getelementptr inbounds %struct.__DiskIO_Cache_Desc, ptr %31, i32 0, i32 0
  store volatile i32 0, ptr %32, align 4, !tbaa !15
  %33 = getelementptr inbounds %class.DiskIO, ptr %8, i32 0, i32 4
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %struct.__DiskIO_Cache_Desc, ptr %34, i64 %36
  %38 = getelementptr inbounds %struct.__DiskIO_Cache_Desc, ptr %37, i32 0, i32 1
  store i32 -1, ptr %38, align 4, !tbaa !17
  br label %39

39:                                               ; preds = %26
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %7, align 4, !tbaa !9
  br label %20, !llvm.loop !18

42:                                               ; preds = %25, %14
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"_ZTS6DiskIO", !13, i64 8, !10, i64 12, !10, i64 16, !6, i64 24}
!13 = !{!"_ZTS12__DiskIOType", !7, i64 0}
!14 = !{!12, !6, i64 24}
!15 = !{!16, !10, i64 0}
!16 = !{!"_ZTS19__DiskIO_Cache_Desc", !10, i64 0, !10, i64 4, !6, i64 8}
!17 = !{!16, !10, i64 4}
!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"

%struct.__DiskIO_Cache_Desc = type { i32, i32, ptr }

; Function Attrs: mustprogress nofree norecurse nounwind memory(argmem: readwrite, inaccessiblemem: readwrite) uwtable
define dso_local void @_ZN6DiskIO8SetCacheEP19__DiskIO_Cache_Desci(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(32) %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = icmp eq ptr %1, null
  %5 = icmp slt i32 %2, 1
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %.loopexit, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %2, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %1, ptr %8, align 8, !tbaa !12
  %wide.trip.count = zext nneg i32 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %9 = icmp eq i32 %2, 1
  br i1 %9, label %.loopexit.loopexit.unr-lcssa, label %.new

.new:                                             ; preds = %6
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %10

10:                                               ; preds = %10, %.new
  %indvars.iv = phi i64 [ 0, %.new ], [ %indvars.iv.next.1, %10 ]
  %niter = phi i64 [ 0, %.new ], [ %niter.next.1, %10 ]
  %11 = getelementptr inbounds %struct.__DiskIO_Cache_Desc, ptr %1, i64 %indvars.iv
  store volatile i32 0, ptr %11, align 4, !tbaa !13
  %12 = getelementptr inbounds %struct.__DiskIO_Cache_Desc, ptr %1, i64 %indvars.iv, i32 1
  store i32 -1, ptr %12, align 4, !tbaa !15
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %13 = getelementptr inbounds %struct.__DiskIO_Cache_Desc, ptr %1, i64 %indvars.iv.next
  store volatile i32 0, ptr %13, align 4, !tbaa !13
  %14 = getelementptr inbounds %struct.__DiskIO_Cache_Desc, ptr %1, i64 %indvars.iv.next, i32 1
  store i32 -1, ptr %14, align 4, !tbaa !15
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %10, !llvm.loop !16

.loopexit.loopexit.unr-lcssa:                     ; preds = %10, %6
  %indvars.iv.unr = phi i64 [ 0, %6 ], [ %indvars.iv.next.1, %10 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.loopexit.loopexit.epilog-lcssa

.loopexit.loopexit.epilog-lcssa:                  ; preds = %.loopexit.loopexit.unr-lcssa
  %15 = getelementptr inbounds %struct.__DiskIO_Cache_Desc, ptr %1, i64 %indvars.iv.unr
  store volatile i32 0, ptr %15, align 4, !tbaa !13
  %16 = getelementptr inbounds %struct.__DiskIO_Cache_Desc, ptr %1, i64 %indvars.iv.unr, i32 1
  store i32 -1, ptr %16, align 4, !tbaa !15
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.epilog-lcssa, %.loopexit.loopexit.unr-lcssa, %3
  ret void
}

attributes #0 = { mustprogress nofree norecurse nounwind memory(argmem: readwrite, inaccessiblemem: readwrite) 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 = !{!"_ZTS6DiskIO", !7, i64 8, !10, i64 12, !10, i64 16, !11, i64 24}
!7 = !{!"_ZTS12__DiskIOType", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !11, i64 24}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTS19__DiskIO_Cache_Desc", !10, i64 0, !10, i64 4, !11, i64 8}
!15 = !{!14, !10, i64 4}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass