; 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.shared_cores_data_t = type { i16, i16, i32, i32, i64, i64, ptr, i64, i64, i64, i64, %struct.anon, i32, [6 x i8], i8, i8, i8, i32, %struct.spyware_data_t, %struct.memory_shadowing_pages_t }
%struct.anon = type { i64, i64, i64, i64 }
%struct.spyware_data_t = type { i8, [213 x i8] }
%struct.memory_shadowing_pages_t = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.mmap_table_t = type <{ i32, [0 x %struct.mmap_entry_t] }>
%struct.mmap_entry_t = type { i64, i64, i32, i32 }

@shared_cores_data = external global %struct.shared_cores_data_t, align 8

; 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 ptr @allocate_memory(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @AcquireLock(ptr noundef getelementptr inbounds (%struct.shared_cores_data_t, ptr @shared_cores_data, i32 0, i32 2))
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = add i64 %9, 4096
  %11 = sub i64 %10, 1
  %12 = and i64 %11, -4096
  store i64 %12, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store ptr inttoptr (i64 20480 to ptr), ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %13 = load ptr, ptr %4, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.mmap_table_t, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 1, !tbaa !11
  store i32 %15, ptr %5, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %16 = load i32, ptr %5, align 4, !tbaa !11
  store i32 %16, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %17

17:                                               ; preds = %43, %1
  %18 = load i32, ptr %6, align 4, !tbaa !11
  %19 = load i32, ptr %5, align 4, !tbaa !11
  %20 = icmp ult i32 %18, %19
  br i1 %20, label %21, label %46

21:                                               ; preds = %17
  %22 = load ptr, ptr %4, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.mmap_table_t, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %6, align 4, !tbaa !11
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr %23, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.mmap_entry_t, ptr %26, i32 0, i32 2
  %28 = load i32, ptr %27, align 1, !tbaa !13
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %42

30:                                               ; preds = %21
  %31 = load ptr, ptr %4, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.mmap_table_t, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %6, align 4, !tbaa !11
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr %32, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.mmap_entry_t, ptr %35, i32 0, i32 1
  %37 = load i64, ptr %36, align 1, !tbaa !15
  %38 = load i64, ptr %3, align 8, !tbaa !5
  %39 = icmp ugt i64 %37, %38
  br i1 %39, label %40, label %42

40:                                               ; preds = %30
  %41 = load i32, ptr %6, align 4, !tbaa !11
  store i32 %41, ptr %7, align 4, !tbaa !11
  br label %42

42:                                               ; preds = %40, %30, %21
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %6, align 4, !tbaa !11
  %45 = add i32 %44, 1
  store i32 %45, ptr %6, align 4, !tbaa !11
  br label %17, !llvm.loop !16

46:                                               ; preds = %17
  %47 = load ptr, ptr %4, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.mmap_table_t, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %7, align 4, !tbaa !11
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr %48, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.mmap_entry_t, ptr %51, i32 0, i32 0
  %53 = load i64, ptr %52, align 1, !tbaa !18
  %54 = load ptr, ptr %4, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.mmap_table_t, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %7, align 4, !tbaa !11
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr %55, i64 0, i64 %57
  %59 = getelementptr inbounds %struct.mmap_entry_t, ptr %58, i32 0, i32 1
  %60 = load i64, ptr %59, align 1, !tbaa !15
  %61 = add i64 %53, %60
  %62 = load i64, ptr %3, align 8, !tbaa !5
  %63 = sub i64 %61, %62
  %64 = add i64 %63, 4096
  %65 = sub i64 %64, 1
  %66 = and i64 %65, -4096
  %67 = inttoptr i64 %66 to ptr
  store ptr %67, ptr %8, align 8, !tbaa !9
  %68 = load i64, ptr %3, align 8, !tbaa !5
  %69 = load ptr, ptr %4, align 8, !tbaa !9
  %70 = getelementptr inbounds %struct.mmap_table_t, ptr %69, i32 0, i32 1
  %71 = load i32, ptr %7, align 4, !tbaa !11
  %72 = zext i32 %71 to i64
  %73 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr %70, i64 0, i64 %72
  %74 = getelementptr inbounds %struct.mmap_entry_t, ptr %73, i32 0, i32 1
  %75 = load i64, ptr %74, align 1, !tbaa !15
  %76 = sub i64 %75, %68
  store i64 %76, ptr %74, align 1, !tbaa !15
  call void @ReleaseLock(ptr noundef getelementptr inbounds (%struct.shared_cores_data_t, ptr @shared_cores_data, i32 0, i32 2))
  %77 = load ptr, ptr %8, align 8, !tbaa !9
  %78 = icmp ne ptr %77, null
  br i1 %78, label %79, label %84

79:                                               ; preds = %46
  %80 = load ptr, ptr %8, align 8, !tbaa !9
  %81 = load i64, ptr %3, align 8, !tbaa !5
  %82 = trunc i64 %81 to i32
  %83 = call ptr @memset(ptr noundef %80, i8 noundef zeroext 0, i32 noundef %82)
  br label %84

84:                                               ; preds = %79, %46
  %85 = load ptr, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %85
}

declare void @AcquireLock(ptr noundef) #2

declare void @ReleaseLock(ptr noundef) #2

declare ptr @memset(ptr noundef, i8 noundef zeroext, i32 noundef) #2

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 = { "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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 16}
!14 = !{!"", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 20}
!15 = !{!14, !6, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!14, !6, i64 0}


; 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.shared_cores_data_t = type { i16, i16, i32, i32, i64, i64, ptr, i64, i64, i64, i64, %struct.anon, i32, [6 x i8], i8, i8, i8, i32, %struct.spyware_data_t, %struct.memory_shadowing_pages_t }
%struct.anon = type { i64, i64, i64, i64 }
%struct.spyware_data_t = type { i8, [213 x i8] }
%struct.memory_shadowing_pages_t = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.mmap_entry_t = type { i64, i64, i32, i32 }

@shared_cores_data = external global %struct.shared_cores_data_t, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @allocate_memory(i64 noundef %0) local_unnamed_addr #0 {
  tail call void @AcquireLock(ptr noundef nonnull getelementptr inbounds (i8, ptr @shared_cores_data, i64 4)) #2
  %2 = add i64 %0, 4095
  %3 = and i64 %2, -4096
  %4 = load i32, ptr inttoptr (i64 20480 to ptr), align 4096, !tbaa !5
  %.not27 = icmp eq i32 %4, 0
  br i1 %.not27, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %wide.trip.count = zext i32 %4 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %5 = icmp eq i32 %4, 1
  br i1 %5, 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, 4294967294
  br label %.lr.ph

.lr.ph:                                           ; preds = %24, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %24 ]
  %.02325 = phi i32 [ %4, %.lr.ph.preheader.new ], [ %.1.1, %24 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %24 ]
  %6 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr inttoptr (i64 20484 to ptr), i64 0, i64 %indvars.iv
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = icmp eq i32 %8, 1
  br i1 %9, label %10, label %.lr.ph.1

10:                                               ; preds = %.lr.ph
  %11 = getelementptr inbounds i8, ptr %6, i64 8
  %12 = load i64, ptr %11, align 4, !tbaa !12
  %13 = icmp ugt i64 %12, %3
  %14 = trunc nuw i64 %indvars.iv to i32
  %spec.select = select i1 %13, i32 %14, i32 %.02325
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %10, %.lr.ph
  %.1 = phi i32 [ %.02325, %.lr.ph ], [ %spec.select, %10 ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %15 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr inttoptr (i64 20484 to ptr), i64 0, i64 %indvars.iv.next
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %19, label %24

19:                                               ; preds = %.lr.ph.1
  %20 = getelementptr inbounds i8, ptr %15, i64 8
  %21 = load i64, ptr %20, align 4, !tbaa !12
  %22 = icmp ugt i64 %21, %3
  %23 = trunc nuw i64 %indvars.iv.next to i32
  %spec.select.1 = select i1 %22, i32 %23, i32 %.1
  br label %24

24:                                               ; preds = %19, %.lr.ph.1
  %.1.1 = phi i32 [ %.1, %.lr.ph.1 ], [ %spec.select.1, %19 ]
  %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 %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !13

._crit_edge.loopexit.unr-lcssa:                   ; preds = %24, %.lr.ph.preheader
  %.1.lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %.1.1, %24 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %24 ]
  %.02325.unr = phi i32 [ %4, %.lr.ph.preheader ], [ %.1.1, %24 ]
  %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
  %25 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr inttoptr (i64 20484 to ptr), i64 0, i64 %indvars.iv.unr
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = icmp eq i32 %27, 1
  br i1 %28, label %29, label %._crit_edge.loopexit

29:                                               ; preds = %.lr.ph.epil
  %30 = getelementptr inbounds i8, ptr %25, i64 8
  %31 = load i64, ptr %30, align 4, !tbaa !12
  %32 = icmp ugt i64 %31, %3
  %33 = trunc nuw i64 %indvars.iv.unr to i32
  %spec.select.epil = select i1 %32, i32 %33, i32 %.02325.unr
  br label %._crit_edge.loopexit

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

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.023.lcssa = phi i64 [ 0, %1 ], [ %34, %._crit_edge.loopexit ]
  %35 = getelementptr inbounds [0 x %struct.mmap_entry_t], ptr inttoptr (i64 20484 to ptr), i64 0, i64 %.023.lcssa
  %36 = load i64, ptr %35, align 4, !tbaa !15
  %37 = getelementptr inbounds i8, ptr %35, i64 8
  %38 = load i64, ptr %37, align 4, !tbaa !12
  %reass.sub = sub i64 %36, %3
  %39 = add i64 %reass.sub, 4095
  %40 = add i64 %39, %38
  %41 = and i64 %40, -4096
  %42 = inttoptr i64 %41 to ptr
  %43 = sub i64 %38, %3
  store i64 %43, ptr %37, align 4, !tbaa !12
  tail call void @ReleaseLock(ptr noundef nonnull getelementptr inbounds (i8, ptr @shared_cores_data, i64 4)) #2
  %.not = icmp eq i64 %41, 0
  br i1 %.not, label %47, label %44

44:                                               ; preds = %._crit_edge
  %45 = trunc i64 %3 to i32
  %46 = tail call ptr @memset(ptr noundef nonnull %42, i8 noundef zeroext 0, i32 noundef %45) #2
  br label %47

47:                                               ; preds = %44, %._crit_edge
  ret ptr %42
}

declare void @AcquireLock(ptr noundef) local_unnamed_addr #1

declare void @ReleaseLock(ptr noundef) local_unnamed_addr #1

declare ptr @memset(ptr noundef, i8 noundef zeroext, i32 noundef) local_unnamed_addr #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 = { "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 = !{!"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 = !{!10, !11, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!10, !11, i64 0}


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