; LLVM IR from gognl/VMBR :: victim/src/boot (mmap)

; 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.mmap_table_t = type <{ i32, [0 x %struct.mmap_entry_t] }>
%struct.mmap_entry_t = type { i64, i64, i32, 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: nounwind uwtable
define dso_local i64 @get_bottom_allocation() #1 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  store ptr inttoptr (i64 20480 to ptr), ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.mmap_table_t, ptr %5, i32 0, i32 0
  %7 = load i32, ptr %6, align 1, !tbaa !9
  store i32 %7, ptr %2, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %8 = load i32, ptr %2, align 4, !tbaa !9
  store i32 %8, ptr %4, align 4, !tbaa !9
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %26, %0
  %10 = load i32, ptr %3, align 4, !tbaa !9
  %11 = load i32, ptr %2, align 4, !tbaa !9
  %12 = sub i32 %11, 1
  %13 = icmp ult i32 %10, %12
  br i1 %13, label %14, label %29

14:                                               ; preds = %9
  %15 = load ptr, ptr %1, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.mmap_table_t, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr %16, i64 0, i64 %18
  %20 = getelementptr inbounds %struct.mmap_entry_t, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 1, !tbaa !11
  %22 = icmp eq i32 %21, 1
  br i1 %22, label %23, label %25

23:                                               ; preds = %14
  %24 = load i32, ptr %3, align 4, !tbaa !9
  store i32 %24, ptr %4, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %23, %14
  br label %26

26:                                               ; preds = %25
  %27 = load i32, ptr %3, align 4, !tbaa !9
  %28 = add i32 %27, 1
  store i32 %28, ptr %3, align 4, !tbaa !9
  br label %9, !llvm.loop !14

29:                                               ; preds = %9
  %30 = load ptr, ptr %1, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.mmap_table_t, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr %31, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.mmap_entry_t, ptr %34, i32 0, i32 0
  %36 = load i64, ptr %35, align 1, !tbaa !16
  %37 = load ptr, ptr %1, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.mmap_table_t, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %4, align 4, !tbaa !9
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr %38, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.mmap_entry_t, ptr %41, i32 0, i32 1
  %43 = load i64, ptr %42, align 1, !tbaa !17
  %44 = add i64 %36, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret i64 %44
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"", !13, i64 0, !13, i64 8, !10, i64 16, !10, i64 20}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!12, !13, i64 0}
!17 = !{!12, !13, i64 8}


; 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.mmap_entry_t = type { i64, i64, i32, i32 }

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local i64 @get_bottom_allocation() local_unnamed_addr #0 {
  %1 = load i32, ptr inttoptr (i64 20480 to ptr), align 4096, !tbaa !5
  %2 = add i32 %1, -1
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %wide.trip.count = zext i32 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %3 = icmp ult i32 %2, 4
  br i1 %3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 4294967292
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %.013 = phi i32 [ %1, %.lr.ph.preheader.new ], [ %spec.select.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %4 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr inttoptr (i64 20484 to ptr), i64 0, i64 %indvars.iv, i32 2
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %6 = icmp eq i32 %5, 1
  %7 = trunc nuw i64 %indvars.iv to i32
  %spec.select = select i1 %6, i32 %7, i32 %.013
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %8 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr inttoptr (i64 20484 to ptr), i64 0, i64 %indvars.iv.next, i32 2
  %9 = load i32, ptr %8, align 4, !tbaa !9
  %10 = icmp eq i32 %9, 1
  %11 = trunc nuw i64 %indvars.iv.next to i32
  %spec.select.1 = select i1 %10, i32 %11, i32 %spec.select
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %12 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr inttoptr (i64 20484 to ptr), i64 0, i64 %indvars.iv.next.1, i32 2
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = icmp eq i32 %13, 1
  %15 = trunc nuw i64 %indvars.iv.next.1 to i32
  %spec.select.2 = select i1 %14, i32 %15, i32 %spec.select.1
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %16 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr inttoptr (i64 20484 to ptr), i64 0, i64 %indvars.iv.next.2, i32 2
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = icmp eq i32 %17, 1
  %19 = trunc nuw i64 %indvars.iv.next.2 to i32
  %spec.select.3 = select i1 %18, i32 %19, i32 %spec.select.2
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !12

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %spec.select.lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %spec.select.3, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %.013.unr = phi i32 [ %1, %.lr.ph.preheader ], [ %spec.select.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.013.epil = phi i32 [ %spec.select.epil, %.lr.ph.epil ], [ %.013.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %20 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr inttoptr (i64 20484 to ptr), i64 0, i64 %indvars.iv.epil, i32 2
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = icmp eq i32 %21, 1
  %23 = trunc nuw i64 %indvars.iv.epil to i32
  %spec.select.epil = select i1 %22, i32 %23, i32 %.013.epil
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.loopexit, label %.lr.ph.epil, !llvm.loop !14

._crit_edge.loopexit:                             ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa
  %spec.select.lcssa = phi i32 [ %spec.select.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %spec.select.epil, %.lr.ph.epil ]
  %24 = zext i32 %spec.select.lcssa to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %.0.lcssa = phi i64 [ 1, %0 ], [ %24, %._crit_edge.loopexit ]
  %25 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr inttoptr (i64 20484 to ptr), i64 0, i64 %.0.lcssa
  %26 = load i64, ptr %25, align 4, !tbaa !16
  %27 = getelementptr inbounds i8, ptr %25, i64 8
  %28 = load i64, ptr %27, align 4, !tbaa !17
  %29 = add i64 %28, %26
  ret i64 %29
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 20}
!11 = !{!"long long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}
!16 = !{!10, !11, i64 0}
!17 = !{!10, !11, i64 8}


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