; LLVM IR from lfarcaro/ARINC653_ARMV7A_Z7000 :: ARINC653_ARMV7A_Z7000.sw/ARINC653_ARMV7A_Z7000/src/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 [2 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

declare i32 @CP15CoreIDGet() #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @MMU_SLTRANSLATIONTABLE_ALLOCATE(ptr noundef %0) #2 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %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 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %8 = call i32 @CP15CoreIDGet()
  store i32 %8, ptr %4, align 4, !tbaa !9
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = zext i32 %9 to i64
  %11 = getelementptr inbounds [2 x %struct._MMU_INFORMATION_TYPE], ptr @CORE_MMU_INFORMATION, i64 0, i64 %10
  store ptr %11, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %30

15:                                               ; preds = %1
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  store ptr %17, ptr %6, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %26, %15
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = getelementptr inbounds i32, ptr %21, i64 256
  %23 = icmp ult ptr %19, %22
  br i1 %23, label %24, label %29

24:                                               ; preds = %18
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %25, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %24
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds i32, ptr %27, i32 1
  store ptr %28, ptr %6, align 8, !tbaa !5
  br label %18, !llvm.loop !11

29:                                               ; preds = %18
  store i8 1, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %70

30:                                               ; preds = %1
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %31, i32 0, i32 5
  %33 = load i32, ptr %32, align 4, !tbaa !13
  %34 = add i32 %33, 1024
  %35 = sub i32 %34, 1
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %36, i32 0, i32 4
  %38 = load i32, ptr %37, align 8, !tbaa !15
  %39 = icmp uge i32 %35, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %30
  store i8 0, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %70

41:                                               ; preds = %30
  %42 = load ptr, ptr %5, 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
  store ptr %44, ptr %6, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %54, %41
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = getelementptr inbounds i32, ptr %49, i64 256
  %51 = icmp ult ptr %46, %50
  br i1 %51, label %52, label %57

52:                                               ; preds = %45
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %53, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %52
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds i32, ptr %55, i32 1
  store ptr %56, ptr %6, align 8, !tbaa !5
  br label %45, !llvm.loop !17

57:                                               ; preds = %45
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %58, i32 0, i32 3
  %60 = load ptr, ptr %59, align 8, !tbaa !16
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %60, ptr %61, align 8, !tbaa !5
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %62, i32 0, i32 3
  %64 = load ptr, ptr %63, align 8, !tbaa !16
  %65 = getelementptr inbounds i32, ptr %64, i64 256
  store ptr %65, ptr %63, align 8, !tbaa !16
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct._MMU_INFORMATION_TYPE, ptr %66, i32 0, i32 5
  %68 = load i32, ptr %67, align 4, !tbaa !13
  %69 = add i32 %68, 1024
  store i32 %69, ptr %67, align 4, !tbaa !13
  store i8 1, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %70

70:                                               ; preds = %57, %40, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %71 = load i8, ptr %2, align 1
  ret i8 %71
}

; 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 = { "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 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 = { 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 [2 x %struct._MMU_INFORMATION_TYPE], align 16

declare i32 @CP15CoreIDGet() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @MMU_SLTRANSLATIONTABLE_ALLOCATE(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = tail call i32 @CP15CoreIDGet() #3
  %3 = zext i32 %2 to i64
  %4 = getelementptr inbounds [2 x %struct._MMU_INFORMATION_TYPE], ptr @CORE_MMU_INFORMATION, i64 0, i64 %3
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %6, label %.preheader.preheader

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

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %4, i64 28
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = add i32 %8, 1023
  %10 = getelementptr inbounds i8, ptr %4, i64 24
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %.not20 = icmp ult i32 %9, %11
  br i1 %.not20, label %12, label %.loopexit

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

.loopexit:                                        ; preds = %.preheader.preheader, %6, %12
  %.018 = phi i8 [ 1, %12 ], [ 0, %6 ], [ 1, %.preheader.preheader ]
  ret i8 %.018
}

; 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 = { "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 = { 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 = { 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 = !{!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