; LLVM IR from travisdowns/uarch-bench :: page-info (get_flag_count)

; 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.flag_count = type { i64, i64, i64, i32 }
%struct.page_info_array = type { i64, ptr }
%struct.page_info = type { i64, i8, i8, i8, i8, i8, i8, i64 }

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
define dso_local void @get_flag_count(ptr dead_on_unwind noalias writable sret(%struct.flag_count) align 8 %0, i64 %1, ptr %2, i32 noundef %3) #1 {
  %5 = alloca %struct.page_info_array, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca %struct.page_info, align 8
  %10 = getelementptr inbounds { i64, ptr }, ptr %5, i32 0, i32 0
  store i64 %1, ptr %10, align 8
  %11 = getelementptr inbounds { i64, ptr }, ptr %5, i32 0, i32 1
  store ptr %2, ptr %11, align 8
  store i32 %3, ptr %6, align 4, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %0, i8 0, i64 32, i1 false)
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = icmp slt i32 %12, 0
  br i1 %13, label %17, label %14

14:                                               ; preds = %4
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = icmp sgt i32 %15, 63
  br i1 %16, label %17, label %18

17:                                               ; preds = %14, %4
  br label %61

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = zext i32 %19 to i64
  %21 = shl i64 1, %20
  store i64 %21, ptr %7, align 8, !tbaa !9
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = getelementptr inbounds %struct.flag_count, ptr %0, i32 0, i32 3
  store i32 %22, ptr %23, align 8, !tbaa !11
  %24 = getelementptr inbounds %struct.page_info_array, ptr %5, i32 0, i32 0
  %25 = load i64, ptr %24, align 8, !tbaa !13
  %26 = getelementptr inbounds %struct.flag_count, ptr %0, i32 0, i32 2
  store i64 %25, ptr %26, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %57, %18
  %28 = load i64, ptr %8, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.page_info_array, ptr %5, i32 0, i32 0
  %30 = load i64, ptr %29, align 8, !tbaa !13
  %31 = icmp ult i64 %28, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %60

33:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #4
  %34 = getelementptr inbounds %struct.page_info_array, ptr %5, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !17
  %36 = load i64, ptr %8, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.page_info, ptr %35, i64 %36
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %37, i64 24, i1 false), !tbaa.struct !18
  %38 = getelementptr inbounds %struct.page_info, ptr %9, i32 0, i32 6
  %39 = load i8, ptr %38, align 1, !tbaa !21, !range !23, !noundef !24
  %40 = trunc i8 %39 to i1
  br i1 %40, label %41, label %56

41:                                               ; preds = %33
  %42 = getelementptr inbounds %struct.page_info, ptr %9, i32 0, i32 7
  %43 = load i64, ptr %42, align 8, !tbaa !25
  %44 = load i64, ptr %7, align 8, !tbaa !9
  %45 = and i64 %43, %44
  %46 = load i64, ptr %7, align 8, !tbaa !9
  %47 = icmp eq i64 %45, %46
  %48 = zext i1 %47 to i32
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds %struct.flag_count, ptr %0, i32 0, i32 0
  %51 = load i64, ptr %50, align 8, !tbaa !26
  %52 = add i64 %51, %49
  store i64 %52, ptr %50, align 8, !tbaa !26
  %53 = getelementptr inbounds %struct.flag_count, ptr %0, i32 0, i32 1
  %54 = load i64, ptr %53, align 8, !tbaa !27
  %55 = add i64 %54, 1
  store i64 %55, ptr %53, align 8, !tbaa !27
  br label %56

56:                                               ; preds = %41, %33
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #4
  br label %57

57:                                               ; preds = %56
  %58 = load i64, ptr %8, align 8, !tbaa !9
  %59 = add i64 %58, 1
  store i64 %59, ptr %8, align 8, !tbaa !9
  br label %27, !llvm.loop !28

60:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %61

61:                                               ; preds = %60, %17
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 24}
!12 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !10, i64 0, !15, i64 8}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{!12, !10, i64 16}
!17 = !{!14, !15, i64 8}
!18 = !{i64 0, i64 8, !9, i64 8, i64 1, !19, i64 9, i64 1, !19, i64 10, i64 1, !19, i64 11, i64 1, !19, i64 12, i64 1, !19, i64 13, i64 1, !19, i64 16, i64 8, !9}
!19 = !{!20, !20, i64 0}
!20 = !{!"_Bool", !7, i64 0}
!21 = !{!22, !20, i64 13}
!22 = !{!"", !10, i64 0, !20, i64 8, !20, i64 9, !20, i64 10, !20, i64 11, !20, i64 12, !20, i64 13, !10, i64 16}
!23 = !{i8 0, i8 2}
!24 = !{}
!25 = !{!22, !10, i64 16}
!26 = !{!12, !10, i64 0}
!27 = !{!12, !10, i64 8}
!28 = distinct !{!28, !29}
!29 = !{!"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.flag_count = type { i64, i64, i64, i32 }
%struct.page_info = type { i64, i8, i8, i8, i8, i8, i8, i64 }

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @get_flag_count(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.flag_count) align 8 %0, i64 %1, ptr nocapture readonly %2, i32 noundef %3) local_unnamed_addr #1 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %0, i8 0, i64 32, i1 false)
  %or.cond = icmp ugt i32 %3, 63
  br i1 %or.cond, label %43, label %5

5:                                                ; preds = %4
  %6 = zext nneg i32 %3 to i64
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %3, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %1, ptr %8, align 8, !tbaa !11
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %xtraiter = and i64 %1, 1
  %10 = icmp eq i64 %1, 1
  br i1 %10, label %..loopexit_crit_edge.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %1, -2
  br label %11

11:                                               ; preds = %32, %.lr.ph.new
  %12 = phi i64 [ 0, %.lr.ph.new ], [ %33, %32 ]
  %.015 = phi i64 [ 0, %.lr.ph.new ], [ %35, %32 ]
  %13 = phi i64 [ 0, %.lr.ph.new ], [ %34, %32 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %32 ]
  %14 = getelementptr inbounds %struct.page_info, ptr %2, i64 %.015
  %.sroa.3.0..sroa_idx = getelementptr inbounds i8, ptr %14, i64 13
  %.sroa.3.0.copyload = load i8, ptr %.sroa.3.0..sroa_idx, align 1, !tbaa !12
  %15 = trunc i8 %.sroa.3.0.copyload to i1
  br i1 %15, label %16, label %21

16:                                               ; preds = %11
  %.sroa.42.0..sroa_idx = getelementptr inbounds i8, ptr %14, i64 16
  %.sroa.42.0.copyload = load i64, ptr %.sroa.42.0..sroa_idx, align 8, !tbaa !14
  %17 = lshr i64 %.sroa.42.0.copyload, %6
  %18 = and i64 %17, 1
  %19 = add i64 %18, %13
  %20 = add i64 %12, 1
  br label %21

21:                                               ; preds = %16, %11
  %22 = phi i64 [ %20, %16 ], [ %12, %11 ]
  %23 = phi i64 [ %19, %16 ], [ %13, %11 ]
  %24 = or disjoint i64 %.015, 1
  %25 = getelementptr inbounds %struct.page_info, ptr %2, i64 %24
  %.sroa.3.0..sroa_idx.1 = getelementptr inbounds i8, ptr %25, i64 13
  %.sroa.3.0.copyload.1 = load i8, ptr %.sroa.3.0..sroa_idx.1, align 1, !tbaa !12
  %26 = trunc i8 %.sroa.3.0.copyload.1 to i1
  br i1 %26, label %27, label %32

27:                                               ; preds = %21
  %.sroa.42.0..sroa_idx.1 = getelementptr inbounds i8, ptr %25, i64 16
  %.sroa.42.0.copyload.1 = load i64, ptr %.sroa.42.0..sroa_idx.1, align 8, !tbaa !14
  %28 = lshr i64 %.sroa.42.0.copyload.1, %6
  %29 = and i64 %28, 1
  %30 = add i64 %29, %23
  %31 = add i64 %22, 1
  br label %32

32:                                               ; preds = %27, %21
  %33 = phi i64 [ %31, %27 ], [ %22, %21 ]
  %34 = phi i64 [ %30, %27 ], [ %23, %21 ]
  %35 = add nuw i64 %.015, 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_crit_edge.unr-lcssa, label %11, !llvm.loop !15

..loopexit_crit_edge.unr-lcssa:                   ; preds = %32, %.lr.ph
  %.lcssa25.ph = phi i64 [ poison, %.lr.ph ], [ %33, %32 ]
  %.lcssa24.ph = phi i64 [ poison, %.lr.ph ], [ %34, %32 ]
  %.unr = phi i64 [ 0, %.lr.ph ], [ %33, %32 ]
  %.015.unr = phi i64 [ 0, %.lr.ph ], [ %35, %32 ]
  %.unr26 = phi i64 [ 0, %.lr.ph ], [ %34, %32 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %..loopexit_crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %..loopexit_crit_edge.unr-lcssa
  %36 = getelementptr inbounds %struct.page_info, ptr %2, i64 %.015.unr
  %.sroa.3.0..sroa_idx.epil = getelementptr inbounds i8, ptr %36, i64 13
  %.sroa.3.0.copyload.epil = load i8, ptr %.sroa.3.0..sroa_idx.epil, align 1, !tbaa !12
  %37 = trunc i8 %.sroa.3.0.copyload.epil to i1
  br i1 %37, label %38, label %..loopexit_crit_edge

38:                                               ; preds = %.epil.preheader
  %.sroa.42.0..sroa_idx.epil = getelementptr inbounds i8, ptr %36, i64 16
  %.sroa.42.0.copyload.epil = load i64, ptr %.sroa.42.0..sroa_idx.epil, align 8, !tbaa !14
  %39 = lshr i64 %.sroa.42.0.copyload.epil, %6
  %40 = and i64 %39, 1
  %41 = add i64 %40, %.unr26
  %42 = add i64 %.unr, 1
  br label %..loopexit_crit_edge

..loopexit_crit_edge:                             ; preds = %.epil.preheader, %38, %..loopexit_crit_edge.unr-lcssa
  %.lcssa25 = phi i64 [ %.lcssa25.ph, %..loopexit_crit_edge.unr-lcssa ], [ %42, %38 ], [ %.unr, %.epil.preheader ]
  %.lcssa24 = phi i64 [ %.lcssa24.ph, %..loopexit_crit_edge.unr-lcssa ], [ %41, %38 ], [ %.unr26, %.epil.preheader ]
  store i64 %.lcssa25, ptr %9, align 8, !tbaa !17
  br label %.loopexit

.loopexit:                                        ; preds = %..loopexit_crit_edge, %5
  %.lcssa = phi i64 [ %.lcssa24, %..loopexit_crit_edge ], [ 0, %5 ]
  store i64 %.lcssa, ptr %0, align 8, !tbaa !18
  br label %43

43:                                               ; preds = %.loopexit, %4
  ret void
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { nofree norecurse nosync nounwind memory(argmem: 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 24}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 16}
!12 = !{!13, !13, i64 0}
!13 = !{!"_Bool", !8, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!6, !7, i64 8}
!18 = !{!6, !7, i64 0}


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