; LLVM IR from lfarcaro/ARINC653_ARMV7A_AM335X :: ARINC653_PORT (mmu)

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

@CORE_MMU_INFORMATION = external dso_local global [1 x %struct._MMU_INFORMATION_TYPE], align 16

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @MMU_FLTRANSLATIONTABLE_ALLOCATE(ptr noundef %0) #0 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store ptr @CORE_MMU_INFORMATION, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %42

11:                                               ; preds = %1
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %13, ptr %5, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %38, %11
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds i32, ptr %17, i64 4096
  %19 = icmp ult ptr %15, %18
  br i1 %19, label %20, label %41

20:                                               ; preds = %14
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = and i32 %22, 3
  %24 = icmp eq i32 %23, 1
  br i1 %24, label %25, label %35

25:                                               ; preds = %20
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = and i32 %27, -1024
  %29 = zext i32 %28 to i64
  %30 = inttoptr i64 %29 to ptr
  store ptr %30, ptr %6, align 8, !tbaa !5
  %31 = call zeroext i8 @MMU_SLTRANSLATIONTABLE_ALLOCATE(ptr noundef %6)
  %32 = icmp ne i8 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %25
  store i8 0, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %82

34:                                               ; preds = %25
  br label %37

35:                                               ; preds = %20
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %36, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %35, %34
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds i32, ptr %39, i32 1
  store ptr %40, ptr %5, align 8, !tbaa !5
  br label %14, !llvm.loop !11

41:                                               ; preds = %14
  store i8 1, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %82

42:                                               ; preds = %1
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %43, i32 0, i32 2
  %45 = load i32, ptr %44, align 4, !tbaa !13
  %46 = add i32 %45, 16384
  %47 = sub i32 %46, 1
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 8, !tbaa !15
  %51 = icmp uge i32 %47, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %42
  store i8 0, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %82

53:                                               ; preds = %42
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  store ptr %56, ptr %5, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %66, %53
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !16
  %62 = getelementptr inbounds i32, ptr %61, i64 4096
  %63 = icmp ult ptr %58, %62
  br i1 %63, label %64, label %69

64:                                               ; preds = %57
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %65, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %64
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds i32, ptr %67, i32 1
  store ptr %68, ptr %5, align 8, !tbaa !5
  br label %57, !llvm.loop !17

69:                                               ; preds = %57
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !16
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %72, ptr %73, align 8, !tbaa !5
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !16
  %77 = getelementptr inbounds i32, ptr %76, i64 4096
  store ptr %77, ptr %75, align 8, !tbaa !16
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %78, i32 0, i32 2
  %80 = load i32, ptr %79, align 4, !tbaa !13
  %81 = add i32 %80, 16384
  store i32 %81, ptr %79, align 4, !tbaa !13
  store i8 1, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %82

82:                                               ; preds = %69, %52, %41, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %83 = load i8, ptr %2, align 1
  ret i8 %83
}

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @MMU_SLTRANSLATIONTABLE_ALLOCATE(ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 willreturn memory(argmem: readwrite) }
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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 12}
!14 = !{!"_MMU_INFORMATION_TYPE", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !10, i64 24, !10, i64 28}
!15 = !{!14, !10, i64 8}
!16 = !{!14, !6, i64 0}
!17 = distinct !{!17, !12}


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

@CORE_MMU_INFORMATION = external dso_local local_unnamed_addr global [1 x %struct._MMU_INFORMATION_TYPE], align 16

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @MMU_FLTRANSLATIONTABLE_ALLOCATE(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %19, label %.lr.ph

.lr.ph:                                           ; preds = %1, %14
  %4 = phi ptr [ %15, %14 ], [ %3, %1 ]
  %.023 = phi ptr [ %16, %14 ], [ %3, %1 ]
  %5 = load i32, ptr %.023, align 4, !tbaa !9
  %6 = and i32 %5, 3
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %8, label %13

8:                                                ; preds = %.lr.ph
  %9 = and i32 %5, -1024
  %10 = zext i32 %9 to i64
  %11 = inttoptr i64 %10 to ptr
  store ptr %11, ptr %2, align 8, !tbaa !5
  %12 = call zeroext i8 @MMU_SLTRANSLATIONTABLE_ALLOCATE(ptr noundef nonnull %2)
  %.not22 = icmp eq i8 %12, 0
  br i1 %.not22, label %.loopexit, label %._crit_edge

._crit_edge:                                      ; preds = %8
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  br label %14

13:                                               ; preds = %.lr.ph
  store i32 0, ptr %.023, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %._crit_edge, %13
  %15 = phi ptr [ %.pre, %._crit_edge ], [ %4, %13 ]
  %16 = getelementptr inbounds i8, ptr %.023, i64 4
  %17 = getelementptr inbounds i8, ptr %15, i64 16384
  %18 = icmp ult ptr %16, %17
  br i1 %18, label %.lr.ph, label %.loopexit, !llvm.loop !11

19:                                               ; preds = %1
  %20 = load i32, ptr getelementptr inbounds (i8, ptr @CORE_MMU_INFORMATION, i64 12), align 4, !tbaa !13
  %21 = add i32 %20, 16383
  %22 = load i32, ptr getelementptr inbounds (i8, ptr @CORE_MMU_INFORMATION, i64 8), align 8, !tbaa !15
  %.not21 = icmp ult i32 %21, %22
  br i1 %.not21, label %23, label %.loopexit

23:                                               ; preds = %19
  %24 = load ptr, ptr @CORE_MMU_INFORMATION, align 16, !tbaa !16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(16384) %24, i8 0, i64 16384, i1 false), !tbaa !9
  store ptr %24, ptr %0, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 16384
  store ptr %25, ptr @CORE_MMU_INFORMATION, align 16, !tbaa !16
  %26 = load i32, ptr getelementptr inbounds (i8, ptr @CORE_MMU_INFORMATION, i64 12), align 4, !tbaa !13
  %27 = add i32 %26, 16384
  store i32 %27, ptr getelementptr inbounds (i8, ptr @CORE_MMU_INFORMATION, i64 12), align 4, !tbaa !13
  br label %.loopexit

.loopexit:                                        ; preds = %8, %14, %19, %23
  %.019 = phi i8 [ 1, %23 ], [ 0, %19 ], [ 0, %8 ], [ 1, %14 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  ret i8 %.019
}

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @MMU_SLTRANSLATIONTABLE_ALLOCATE(ptr noundef) local_unnamed_addr #0

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

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 12}
!14 = !{!"_MMU_INFORMATION_TYPE", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !10, i64 24, !10, i64 28}
!15 = !{!14, !10, i64 8}
!16 = !{!14, !6, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass