; LLVM IR from Aeternum-Veritas/Merry :: merry (merry_nreader)

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

%struct.MerryReader = type { i8, i8, i8, i8, %struct.MerryInstSection, %struct.MerryEAT, %struct.MerrySsT, %struct.MerryST, ptr, [2 x i64], i64, i64, ptr, i64, ptr, i64, ptr, ptr, ptr, ptr, i64, i64 }
%struct.MerryInstSection = type { i64, ptr, i64, i64 }
%struct.MerryEAT = type { ptr, i64, i64 }
%struct.MerrySsT = type { i64, i64, ptr, i8 }
%struct.MerryST = type { ptr, i64 }

; 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: nounwind uwtable
declare dso_local zeroext i8 @merry_reader_read_data_page(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @merry_reader_read_data_sections(ptr noundef %0) #1 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.MerryReader, ptr %7, i32 0, i32 11
  %9 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %9, ptr %4, align 8, !tbaa !16
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.MerryReader, ptr %10, i32 0, i32 11
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = icmp ugt i64 %12, 5
  br i1 %13, label %14, label %15

14:                                               ; preds = %1
  store i64 5, ptr %4, align 8, !tbaa !16
  br label %15

15:                                               ; preds = %14, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store i64 0, ptr %5, align 8, !tbaa !16
  br label %16

16:                                               ; preds = %30, %15
  %17 = load i64, ptr %5, align 8, !tbaa !16
  %18 = load i64, ptr %4, align 8, !tbaa !16
  %19 = icmp ult i64 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 2, ptr %6, align 4
  br label %33

21:                                               ; preds = %16
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load i64, ptr %5, align 8, !tbaa !16
  %24 = mul i64 1048576, %23
  %25 = call zeroext i8 @merry_reader_read_data_page(ptr noundef %22, i64 noundef %24)
  %26 = zext i8 %25 to i32
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %21
  store i8 1, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %33

29:                                               ; preds = %21
  br label %30

30:                                               ; preds = %29
  %31 = load i64, ptr %5, align 8, !tbaa !16
  %32 = add i64 %31, 1
  store i64 %32, ptr %5, align 8, !tbaa !16
  br label %16, !llvm.loop !17

33:                                               ; preds = %28, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  %34 = load i32, ptr %6, align 4
  switch i32 %34, label %36 [
    i32 2, label %35
  ]

35:                                               ; preds = %33
  store i8 0, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %36

36:                                               ; preds = %35, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %37 = load i8, ptr %2, align 1
  ret i8 %37
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !12, i64 144}
!10 = !{!"MerryReader", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !11, i64 8, !13, i64 40, !14, i64 64, !15, i64 96, !6, i64 112, !7, i64 120, !12, i64 136, !12, i64 144, !6, i64 152, !12, i64 160, !6, i64 168, !12, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !12, i64 216, !12, i64 224}
!11 = !{!"MerryInstSection", !12, i64 0, !6, i64 8, !12, i64 16, !12, i64 24}
!12 = !{!"long", !7, i64 0}
!13 = !{!"MerryEAT", !6, i64 0, !12, i64 8, !12, i64 16}
!14 = !{!"MerrySsT", !12, i64 0, !12, i64 8, !6, i64 16, !7, i64 24}
!15 = !{!"MerryST", !6, i64 0, !12, i64 8}
!16 = !{!12, !12, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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: nounwind uwtable
declare dso_local zeroext i8 @merry_reader_read_data_page(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @merry_reader_read_data_sections(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 144
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %spec.store.select = tail call i64 @llvm.umin.i64(i64 %3, i64 5)
  %.not1011.not = icmp eq i64 %3, 0
  br i1 %.not1011.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %4 = tail call zeroext i8 @merry_reader_read_data_page(ptr noundef %0, i64 noundef 0)
  %.not16 = icmp eq i8 %4, 0
  br i1 %.not16, label %.lr.ph18, label %._crit_edge

.lr.ph18:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %.081217 = phi i64 [ %5, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %5 = add nuw nsw i64 %.081217, 1
  %exitcond.not = icmp eq i64 %5, %spec.store.select
  br i1 %exitcond.not, label %._crit_edge.loopexit.loopexit, label %.lr.ph, !llvm.loop !15

.lr.ph:                                           ; preds = %.lr.ph18
  %6 = shl i64 %5, 20
  %7 = tail call zeroext i8 @merry_reader_read_data_page(ptr noundef %0, i64 noundef %6)
  %.not = icmp eq i8 %7, 0
  br i1 %.not, label %.lr.ph18, label %._crit_edge.loopexit.loopexit, !llvm.loop !15

._crit_edge.loopexit.loopexit:                    ; preds = %.lr.ph, %.lr.ph18
  %.not10.le = icmp ult i64 %5, %spec.store.select
  %8 = zext i1 %.not10.le to i8
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %._crit_edge.loopexit.loopexit, %1
  %.not10.lcssa = phi i8 [ 0, %1 ], [ 1, %.lr.ph.preheader ], [ %8, %._crit_edge.loopexit.loopexit ]
  ret i8 %.not10.lcssa
}

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

attributes #0 = { 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, !10, i64 144}
!6 = !{!"MerryReader", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !9, i64 8, !12, i64 40, !13, i64 64, !14, i64 96, !11, i64 112, !7, i64 120, !10, i64 136, !10, i64 144, !11, i64 152, !10, i64 160, !11, i64 168, !10, i64 176, !11, i64 184, !11, i64 192, !11, i64 200, !11, i64 208, !10, i64 216, !10, i64 224}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"MerryInstSection", !10, i64 0, !11, i64 8, !10, i64 16, !10, i64 24}
!10 = !{!"long", !7, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"MerryEAT", !11, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!"MerrySsT", !10, i64 0, !10, i64 8, !11, i64 16, !7, i64 24}
!14 = !{!"MerryST", !11, i64 0, !10, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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