; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @MMU_SLTRANSLATIONTABLE_ALLOCATE(ptr noundef %0) #1 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = 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
  store ptr @CORE_MMU_INFORMATION, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %25

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

13:                                               ; preds = %21, %10
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds i32, ptr %16, i64 256
  %18 = icmp ult ptr %14, %17
  br i1 %18, label %19, label %24

19:                                               ; preds = %13
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %20, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %19
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds i32, ptr %22, i32 1
  store ptr %23, ptr %5, align 8, !tbaa !5
  br label %13, !llvm.loop !11

24:                                               ; preds = %13
  store i8 1, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %65

25:                                               ; preds = %1
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %26, i32 0, i32 5
  %28 = load i32, ptr %27, align 4, !tbaa !13
  %29 = add i32 %28, 1024
  %30 = sub i32 %29, 1
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %31, i32 0, i32 4
  %33 = load i32, ptr %32, align 8, !tbaa !15
  %34 = icmp uge i32 %30, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %25
  store i8 0, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %65

36:                                               ; preds = %25
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %37, i32 0, i32 3
  %39 = load ptr, ptr %38, align 8, !tbaa !16
  store ptr %39, ptr %5, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %49, %36
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %42, i32 0, i32 3
  %44 = load ptr, ptr %43, align 8, !tbaa !16
  %45 = getelementptr inbounds i32, ptr %44, i64 256
  %46 = icmp ult ptr %41, %45
  br i1 %46, label %47, label %52

47:                                               ; preds = %40
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %48, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %47
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds i32, ptr %50, i32 1
  store ptr %51, ptr %5, align 8, !tbaa !5
  br label %40, !llvm.loop !17

52:                                               ; preds = %40
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %53, i32 0, i32 3
  %55 = load ptr, ptr %54, align 8, !tbaa !16
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %55, ptr %56, align 8, !tbaa !5
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %57, i32 0, i32 3
  %59 = load ptr, ptr %58, align 8, !tbaa !16
  %60 = getelementptr inbounds i32, ptr %59, i64 256
  store ptr %60, ptr %58, align 8, !tbaa !16
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %61, i32 0, i32 5
  %63 = load i32, ptr %62, align 4, !tbaa !13
  %64 = add i32 %63, 1024
  store i32 %64, ptr %62, align 4, !tbaa !13
  store i8 1, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %65

65:                                               ; preds = %52, %35, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %66 = load i8, ptr %2, align 1
  ret i8 %66
}

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

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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 28}
!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 24}
!16 = !{!14, !6, i64 16}
!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: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local zeroext range(i8 0, 2) i8 @MMU_SLTRANSLATIONTABLE_ALLOCATE(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %3, label %.preheader.preheader

.preheader.preheader:                             ; preds = %1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1024) %2, i8 0, i64 1024, i1 false), !tbaa !9
  br label %.loopexit

3:                                                ; preds = %1
  %4 = load i32, ptr getelementptr inbounds (i8, ptr @CORE_MMU_INFORMATION, i64 28), align 4, !tbaa !11
  %5 = add i32 %4, 1023
  %6 = load i32, ptr getelementptr inbounds (i8, ptr @CORE_MMU_INFORMATION, i64 24), align 8, !tbaa !13
  %.not19 = icmp ult i32 %5, %6
  br i1 %.not19, label %7, label %.loopexit

7:                                                ; preds = %3
  %8 = load ptr, ptr getelementptr inbounds (i8, ptr @CORE_MMU_INFORMATION, i64 16), align 16, !tbaa !14
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1024) %8, i8 0, i64 1024, i1 false), !tbaa !9
  store ptr %8, ptr %0, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 1024
  store ptr %9, ptr getelementptr inbounds (i8, ptr @CORE_MMU_INFORMATION, i64 16), align 16, !tbaa !14
  %10 = load i32, ptr getelementptr inbounds (i8, ptr @CORE_MMU_INFORMATION, i64 28), align 4, !tbaa !11
  %11 = add i32 %10, 1024
  store i32 %11, ptr getelementptr inbounds (i8, ptr @CORE_MMU_INFORMATION, i64 28), align 4, !tbaa !11
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader.preheader, %3, %7
  %.017 = phi i8 [ 1, %7 ], [ 0, %3 ], [ 1, %.preheader.preheader ]
  ret i8 %.017
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, 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" }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 28}
!12 = !{!"_MMU_INFORMATION_TYPE", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !10, i64 24, !10, i64 28}
!13 = !{!12, !10, i64 24}
!14 = !{!12, !6, i64 16}


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