; LLVM IR from Simple-XX/SimpleKernel :: src/kernel/vmm.ll (ZN3VMM4findEPmmb)

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

@.str = external hidden unnamed_addr constant [30 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN3VMM4findEPmmb(ptr noundef nonnull align 1 dereferenceable(1) %0, ptr noundef %1, i64 noundef %2, i1 noundef zeroext %3) #0 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i8, align 1
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  %14 = zext i1 %3 to i8
  store i8 %14, ptr %9, align 1, !tbaa !11
  %15 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %16, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 3, ptr %11, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %63, %4
  %18 = load i64, ptr %11, align 8, !tbaa !9
  %19 = icmp ugt i64 %18, 0
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  store i32 2, ptr %12, align 4
  br label %66

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = load i64, ptr %11, align 8, !tbaa !9
  %24 = load i64, ptr %8, align 8, !tbaa !9
  %25 = call noundef i64 @_ZN3VMM2PXEmm(i64 noundef %23, i64 noundef %24)
  %26 = getelementptr inbounds i64, ptr %22, i64 %25
  store ptr %26, ptr %13, align 8, !tbaa !5
  %27 = load ptr, ptr %13, align 8, !tbaa !5
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %29 = and i64 %28, 1
  %30 = icmp eq i64 %29, 1
  br i1 %30, label %31, label %36

31:                                               ; preds = %21
  %32 = load ptr, ptr %13, align 8, !tbaa !5
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = call noundef i64 @_ZN3VMM6PTE2PAEm(i64 noundef %33)
  %35 = inttoptr i64 %34 to ptr
  store ptr %35, ptr %10, align 8, !tbaa !5
  br label %59

36:                                               ; preds = %21
  %37 = load i8, ptr %9, align 1, !tbaa !11, !range !13, !noundef !14
  %38 = trunc i8 %37 to i1
  %39 = zext i1 %38 to i32
  %40 = icmp eq i32 %39, 1
  br i1 %40, label %41, label %57

41:                                               ; preds = %36
  %42 = call noundef nonnull align 8 dereferenceable(72) ptr @_ZN3PMM12get_instanceEv()
  %43 = call noundef i64 @_ZN3PMM17alloc_page_kernelEv(ptr noundef nonnull align 8 dereferenceable(72) %42)
  %44 = inttoptr i64 %43 to ptr
  store ptr %44, ptr %10, align 8, !tbaa !5
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  call void @bzero(ptr noundef %45, i32 noundef 4096)
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = icmp eq ptr %46, null
  br i1 %47, label %48, label %50

48:                                               ; preds = %41
  %49 = call i32 (ptr, ...) @err(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 55, ptr noundef @.str.2)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %60

50:                                               ; preds = %41
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  call void @bzero(ptr noundef %51, i32 noundef 4096)
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = ptrtoint ptr %52 to i64
  %54 = call noundef i64 @_ZN3VMM6PA2PTEEm(i64 noundef %53)
  %55 = or i64 %54, 1
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  store i64 %55, ptr %56, align 8, !tbaa !9
  br label %58

57:                                               ; preds = %36
  store ptr null, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %60

58:                                               ; preds = %50
  br label %59

59:                                               ; preds = %58, %31
  store i32 0, ptr %12, align 4
  br label %60

60:                                               ; preds = %59, %57, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  %61 = load i32, ptr %12, align 4
  switch i32 %61, label %66 [
    i32 0, label %62
  ]

62:                                               ; preds = %60
  br label %63

63:                                               ; preds = %62
  %64 = load i64, ptr %11, align 8, !tbaa !9
  %65 = add i64 %64, -1
  store i64 %65, ptr %11, align 8, !tbaa !9
  br label %17, !llvm.loop !15

66:                                               ; preds = %60, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  %67 = load i32, ptr %12, align 4
  switch i32 %67, label %73 [
    i32 2, label %68
  ]

68:                                               ; preds = %66
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = load i64, ptr %8, align 8, !tbaa !9
  %71 = call noundef i64 @_ZN3VMM2PXEmm(i64 noundef 0, i64 noundef %70)
  %72 = getelementptr inbounds i64, ptr %69, i64 %71
  store ptr %72, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %73

73:                                               ; preds = %68, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %74 = load ptr, ptr %5, align 8
  ret ptr %74
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN3VMM2PXEmm(i64 noundef, i64 noundef) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN3VMM6PTE2PAEm(i64 noundef) #2 align 2

declare noundef nonnull align 8 dereferenceable(72) ptr @_ZN3PMM12get_instanceEv() #3

declare noundef i64 @_ZN3PMM17alloc_page_kernelEv(ptr noundef nonnull align 8 dereferenceable(72)) #3

declare void @bzero(ptr noundef, i32 noundef) #3

declare i32 @err(ptr noundef, ...) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN3VMM6PA2PTEEm(i64 noundef) #2 align 2

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

attributes #0 = { mustprogress 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 = { 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 #3 = { "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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@.str = external hidden unnamed_addr constant [30 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN3VMM4findEPmmb(ptr nocapture noundef nonnull readnone align 1 dereferenceable(1) %0, ptr nocapture noundef %1, i64 noundef %2, i1 noundef zeroext %3) local_unnamed_addr #0 align 2 {
  %5 = tail call noundef i64 @_ZN3VMM2PXEmm(i64 noundef 3, i64 noundef %2)
  %6 = getelementptr inbounds i64, ptr %1, i64 %5
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = and i64 %7, 1
  %.not29.us = icmp eq i64 %8, 0
  br i1 %3, label %.split.us.preheader, label %.split.preheader

.split.preheader:                                 ; preds = %4
  br i1 %.not29.us, label %.thread34, label %.split.1

.split.us.preheader:                              ; preds = %4
  br i1 %.not29.us, label %12, label %9

9:                                                ; preds = %.split.us.preheader
  %10 = tail call noundef i64 @_ZN3VMM6PTE2PAEm(i64 noundef %7)
  %11 = inttoptr i64 %10 to ptr
  br label %.split.us.1

12:                                               ; preds = %.split.us.preheader
  %13 = tail call noundef nonnull align 8 dereferenceable(72) ptr @_ZN3PMM12get_instanceEv()
  %14 = tail call noundef i64 @_ZN3PMM17alloc_page_kernelEv(ptr noundef nonnull align 8 dereferenceable(72) %13)
  %15 = inttoptr i64 %14 to ptr
  tail call void @bzero(ptr noundef %15, i32 noundef 4096)
  %16 = icmp eq i64 %14, 0
  br i1 %16, label %.split41.us, label %17

17:                                               ; preds = %12
  tail call void @bzero(ptr noundef nonnull %15, i32 noundef 4096)
  %18 = tail call noundef i64 @_ZN3VMM6PA2PTEEm(i64 noundef %14)
  %19 = or i64 %18, 1
  store i64 %19, ptr %6, align 8, !tbaa !5
  br label %.split.us.1

.split.us.1:                                      ; preds = %17, %9
  %.225.ph.us = phi ptr [ %15, %17 ], [ %11, %9 ]
  %20 = tail call noundef i64 @_ZN3VMM2PXEmm(i64 noundef 2, i64 noundef %2)
  %21 = getelementptr inbounds i64, ptr %.225.ph.us, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = and i64 %22, 1
  %.not29.us.1 = icmp eq i64 %23, 0
  br i1 %.not29.us.1, label %27, label %24

24:                                               ; preds = %.split.us.1
  %25 = tail call noundef i64 @_ZN3VMM6PTE2PAEm(i64 noundef %22)
  %26 = inttoptr i64 %25 to ptr
  br label %.split.us.2

27:                                               ; preds = %.split.us.1
  %28 = tail call noundef nonnull align 8 dereferenceable(72) ptr @_ZN3PMM12get_instanceEv()
  %29 = tail call noundef i64 @_ZN3PMM17alloc_page_kernelEv(ptr noundef nonnull align 8 dereferenceable(72) %28)
  %30 = inttoptr i64 %29 to ptr
  tail call void @bzero(ptr noundef %30, i32 noundef 4096)
  %31 = icmp eq i64 %29, 0
  br i1 %31, label %.split41.us, label %32

32:                                               ; preds = %27
  tail call void @bzero(ptr noundef nonnull %30, i32 noundef 4096)
  %33 = tail call noundef i64 @_ZN3VMM6PA2PTEEm(i64 noundef %29)
  %34 = or i64 %33, 1
  store i64 %34, ptr %21, align 8, !tbaa !5
  br label %.split.us.2

.split.us.2:                                      ; preds = %32, %24
  %.225.ph.us.1 = phi ptr [ %30, %32 ], [ %26, %24 ]
  %35 = tail call noundef i64 @_ZN3VMM2PXEmm(i64 noundef 1, i64 noundef %2)
  %36 = getelementptr inbounds i64, ptr %.225.ph.us.1, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = and i64 %37, 1
  %.not29.us.2 = icmp eq i64 %38, 0
  br i1 %.not29.us.2, label %42, label %39

39:                                               ; preds = %.split.us.2
  %40 = tail call noundef i64 @_ZN3VMM6PTE2PAEm(i64 noundef %37)
  %41 = inttoptr i64 %40 to ptr
  br label %.split43.us

42:                                               ; preds = %.split.us.2
  %43 = tail call noundef nonnull align 8 dereferenceable(72) ptr @_ZN3PMM12get_instanceEv()
  %44 = tail call noundef i64 @_ZN3PMM17alloc_page_kernelEv(ptr noundef nonnull align 8 dereferenceable(72) %43)
  %45 = inttoptr i64 %44 to ptr
  tail call void @bzero(ptr noundef %45, i32 noundef 4096)
  %46 = icmp eq i64 %44, 0
  br i1 %46, label %.split41.us, label %47

47:                                               ; preds = %42
  tail call void @bzero(ptr noundef nonnull %45, i32 noundef 4096)
  %48 = tail call noundef i64 @_ZN3VMM6PA2PTEEm(i64 noundef %44)
  %49 = or i64 %48, 1
  store i64 %49, ptr %36, align 8, !tbaa !5
  br label %.split43.us

.split.1:                                         ; preds = %.split.preheader
  %50 = tail call noundef i64 @_ZN3VMM6PTE2PAEm(i64 noundef %7)
  %51 = inttoptr i64 %50 to ptr
  %52 = tail call noundef i64 @_ZN3VMM2PXEmm(i64 noundef 2, i64 noundef %2)
  %53 = getelementptr inbounds i64, ptr %51, i64 %52
  %54 = load i64, ptr %53, align 8, !tbaa !5
  %55 = and i64 %54, 1
  %.not29.1 = icmp eq i64 %55, 0
  br i1 %.not29.1, label %.thread34, label %.split.2

.split.2:                                         ; preds = %.split.1
  %56 = tail call noundef i64 @_ZN3VMM6PTE2PAEm(i64 noundef %54)
  %57 = inttoptr i64 %56 to ptr
  %58 = tail call noundef i64 @_ZN3VMM2PXEmm(i64 noundef 1, i64 noundef %2)
  %59 = getelementptr inbounds i64, ptr %57, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !5
  %61 = and i64 %60, 1
  %.not29.2 = icmp eq i64 %61, 0
  br i1 %.not29.2, label %.thread34, label %.split43.us.loopexit44

.split43.us.loopexit44:                           ; preds = %.split.2
  %62 = tail call noundef i64 @_ZN3VMM6PTE2PAEm(i64 noundef %60)
  %63 = inttoptr i64 %62 to ptr
  br label %.split43.us

.split41.us:                                      ; preds = %42, %27, %12
  %64 = tail call i32 (ptr, ...) @err(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 55, ptr noundef nonnull @.str.2)
  br label %.thread34

.split43.us:                                      ; preds = %39, %47, %.split43.us.loopexit44
  %.us-phi = phi ptr [ %63, %.split43.us.loopexit44 ], [ %45, %47 ], [ %41, %39 ]
  %65 = tail call noundef i64 @_ZN3VMM2PXEmm(i64 noundef 0, i64 noundef %2)
  %66 = getelementptr inbounds i64, ptr %.us-phi, i64 %65
  br label %.thread34

.thread34:                                        ; preds = %.split.preheader, %.split.1, %.split.2, %.split41.us, %.split43.us
  %.3 = phi ptr [ %66, %.split43.us ], [ null, %.split41.us ], [ null, %.split.2 ], [ null, %.split.1 ], [ null, %.split.preheader ]
  ret ptr %.3
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN3VMM2PXEmm(i64 noundef, i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN3VMM6PTE2PAEm(i64 noundef) local_unnamed_addr #1 align 2

declare noundef nonnull align 8 dereferenceable(72) ptr @_ZN3PMM12get_instanceEv() local_unnamed_addr #2

declare noundef i64 @_ZN3PMM17alloc_page_kernelEv(ptr noundef nonnull align 8 dereferenceable(72)) local_unnamed_addr #2

declare void @bzero(ptr noundef, i32 noundef) local_unnamed_addr #2

declare i32 @err(ptr noundef, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN3VMM6PA2PTEEm(i64 noundef) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress 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 = { 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 #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" }

!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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass