; LLVM IR from FrancesoM/Bisc8FX :: sdk_projects/bisc8_platform/ps7_cortexa9_0/standalone_domain/bsp/ps7_cortexa9_0_ (UpdateMPUConfig)

; 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.anon = type { i64, i32 }
%struct.XMpuConfig = type { i32, i64, i64, i32 }

@region_size = external hidden constant [28 x %struct.anon], align 16
@Mpu_Config = external dso_local global [16 x %struct.XMpuConfig], section ".bootdata", 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: 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 i32 @Xil_UpdateMPUConfig(i32 noundef %0, i64 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %12 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %12, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = icmp uge i32 %13, 16
  br i1 %14, label %15, label %16

15:                                               ; preds = %4
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %84

16:                                               ; preds = %4
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = and i32 %17, 1
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %66

20:                                               ; preds = %16
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds [16 x %struct.XMpuConfig], ptr @Mpu_Config, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.XMpuConfig, ptr %23, i32 0, i32 0
  store i32 1, ptr %24, align 16, !tbaa !11
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds [16 x %struct.XMpuConfig], ptr @Mpu_Config, i64 0, i64 %27
  %29 = getelementptr inbounds %struct.XMpuConfig, ptr %28, i32 0, i32 1
  store i64 %25, ptr %29, align 8, !tbaa !13
  %30 = load i32, ptr %10, align 4, !tbaa !5
  %31 = and i32 %30, -2
  store i32 %31, ptr %10, align 4, !tbaa !5
  %32 = load i32, ptr %10, align 4, !tbaa !5
  %33 = lshr i32 %32, 1
  store i32 %33, ptr %10, align 4, !tbaa !5
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %57, %20
  %35 = load i32, ptr %11, align 4, !tbaa !5
  %36 = zext i32 %35 to i64
  %37 = icmp ult i64 %36, 28
  br i1 %37, label %38, label %60

38:                                               ; preds = %34
  %39 = load i32, ptr %10, align 4, !tbaa !5
  %40 = load i32, ptr %11, align 4, !tbaa !5
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds [28 x %struct.anon], ptr @region_size, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.anon, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 8, !tbaa !14
  %45 = icmp ule i32 %39, %44
  br i1 %45, label %46, label %56

46:                                               ; preds = %38
  %47 = load i32, ptr %11, align 4, !tbaa !5
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds [28 x %struct.anon], ptr @region_size, i64 0, i64 %48
  %50 = getelementptr inbounds %struct.anon, ptr %49, i32 0, i32 0
  %51 = load i64, ptr %50, align 16, !tbaa !16
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds [16 x %struct.XMpuConfig], ptr @Mpu_Config, i64 0, i64 %53
  %55 = getelementptr inbounds %struct.XMpuConfig, ptr %54, i32 0, i32 2
  store i64 %51, ptr %55, align 16, !tbaa !17
  br label %60

56:                                               ; preds = %38
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %11, align 4, !tbaa !5
  %59 = add i32 %58, 1
  store i32 %59, ptr %11, align 4, !tbaa !5
  br label %34, !llvm.loop !18

60:                                               ; preds = %46, %34
  %61 = load i32, ptr %8, align 4, !tbaa !5
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = zext i32 %62 to i64
  %64 = getelementptr inbounds [16 x %struct.XMpuConfig], ptr @Mpu_Config, i64 0, i64 %63
  %65 = getelementptr inbounds %struct.XMpuConfig, ptr %64, i32 0, i32 3
  store i32 %61, ptr %65, align 8, !tbaa !20
  br label %83

66:                                               ; preds = %16
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = zext i32 %67 to i64
  %69 = getelementptr inbounds [16 x %struct.XMpuConfig], ptr @Mpu_Config, i64 0, i64 %68
  %70 = getelementptr inbounds %struct.XMpuConfig, ptr %69, i32 0, i32 0
  store i32 0, ptr %70, align 16, !tbaa !11
  %71 = load i32, ptr %5, align 4, !tbaa !5
  %72 = zext i32 %71 to i64
  %73 = getelementptr inbounds [16 x %struct.XMpuConfig], ptr @Mpu_Config, i64 0, i64 %72
  %74 = getelementptr inbounds %struct.XMpuConfig, ptr %73, i32 0, i32 1
  store i64 0, ptr %74, align 8, !tbaa !13
  %75 = load i32, ptr %5, align 4, !tbaa !5
  %76 = zext i32 %75 to i64
  %77 = getelementptr inbounds [16 x %struct.XMpuConfig], ptr @Mpu_Config, i64 0, i64 %76
  %78 = getelementptr inbounds %struct.XMpuConfig, ptr %77, i32 0, i32 2
  store i64 0, ptr %78, align 16, !tbaa !17
  %79 = load i32, ptr %5, align 4, !tbaa !5
  %80 = zext i32 %79 to i64
  %81 = getelementptr inbounds [16 x %struct.XMpuConfig], ptr @Mpu_Config, i64 0, i64 %80
  %82 = getelementptr inbounds %struct.XMpuConfig, ptr %81, i32 0, i32 3
  store i32 0, ptr %82, align 8, !tbaa !20
  br label %83

83:                                               ; preds = %66, %60
  br label %84

84:                                               ; preds = %83, %15
  %85 = load i32, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret i32 %85
}

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


; 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.anon = type { i64, i32 }
%struct.XMpuConfig = type { i32, i64, i64, i32 }

@region_size = external hidden local_unnamed_addr constant [28 x %struct.anon], align 16
@Mpu_Config = external dso_local local_unnamed_addr global [16 x %struct.XMpuConfig], section ".bootdata", align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 2) i32 @Xil_UpdateMPUConfig(i32 noundef %0, i64 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp ugt i32 %0, 15
  br i1 %5, label %73, label %6

6:                                                ; preds = %4
  %7 = and i32 %2, 1
  %.not = icmp eq i32 %7, 0
  %8 = zext nneg i32 %0 to i64
  %9 = getelementptr inbounds [16 x %struct.XMpuConfig], ptr @Mpu_Config, i64 0, i64 %8
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  br i1 %.not, label %72, label %11

11:                                               ; preds = %6
  store i32 1, ptr %9, align 16, !tbaa !5
  store i64 %1, ptr %10, align 8, !tbaa !11
  %12 = lshr i32 %2, 1
  %13 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 8), align 8, !tbaa !12
  %.not24 = icmp ugt i32 %12, %13
  br i1 %.not24, label %14, label %68

14:                                               ; preds = %11
  %15 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 24), align 8, !tbaa !12
  %.not24.1 = icmp ugt i32 %12, %15
  br i1 %.not24.1, label %16, label %68

16:                                               ; preds = %14
  %17 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 40), align 8, !tbaa !12
  %.not24.2 = icmp ugt i32 %12, %17
  br i1 %.not24.2, label %18, label %68

18:                                               ; preds = %16
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 56), align 8, !tbaa !12
  %.not24.3 = icmp ugt i32 %12, %19
  br i1 %.not24.3, label %20, label %68

20:                                               ; preds = %18
  %21 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 72), align 8, !tbaa !12
  %.not24.4 = icmp ugt i32 %12, %21
  br i1 %.not24.4, label %22, label %68

22:                                               ; preds = %20
  %23 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 88), align 8, !tbaa !12
  %.not24.5 = icmp ugt i32 %12, %23
  br i1 %.not24.5, label %24, label %68

24:                                               ; preds = %22
  %25 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 104), align 8, !tbaa !12
  %.not24.6 = icmp ugt i32 %12, %25
  br i1 %.not24.6, label %26, label %68

26:                                               ; preds = %24
  %27 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 120), align 8, !tbaa !12
  %.not24.7 = icmp ugt i32 %12, %27
  br i1 %.not24.7, label %28, label %68

28:                                               ; preds = %26
  %29 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 136), align 8, !tbaa !12
  %.not24.8 = icmp ugt i32 %12, %29
  br i1 %.not24.8, label %30, label %68

30:                                               ; preds = %28
  %31 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 152), align 8, !tbaa !12
  %.not24.9 = icmp ugt i32 %12, %31
  br i1 %.not24.9, label %32, label %68

32:                                               ; preds = %30
  %33 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 168), align 8, !tbaa !12
  %.not24.10 = icmp ugt i32 %12, %33
  br i1 %.not24.10, label %34, label %68

34:                                               ; preds = %32
  %35 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 184), align 8, !tbaa !12
  %.not24.11 = icmp ugt i32 %12, %35
  br i1 %.not24.11, label %36, label %68

36:                                               ; preds = %34
  %37 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 200), align 8, !tbaa !12
  %.not24.12 = icmp ugt i32 %12, %37
  br i1 %.not24.12, label %38, label %68

38:                                               ; preds = %36
  %39 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 216), align 8, !tbaa !12
  %.not24.13 = icmp ugt i32 %12, %39
  br i1 %.not24.13, label %40, label %68

40:                                               ; preds = %38
  %41 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 232), align 8, !tbaa !12
  %.not24.14 = icmp ugt i32 %12, %41
  br i1 %.not24.14, label %42, label %68

42:                                               ; preds = %40
  %43 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 248), align 8, !tbaa !12
  %.not24.15 = icmp ugt i32 %12, %43
  br i1 %.not24.15, label %44, label %68

44:                                               ; preds = %42
  %45 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 264), align 8, !tbaa !12
  %.not24.16 = icmp ugt i32 %12, %45
  br i1 %.not24.16, label %46, label %68

46:                                               ; preds = %44
  %47 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 280), align 8, !tbaa !12
  %.not24.17 = icmp ugt i32 %12, %47
  br i1 %.not24.17, label %48, label %68

48:                                               ; preds = %46
  %49 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 296), align 8, !tbaa !12
  %.not24.18 = icmp ugt i32 %12, %49
  br i1 %.not24.18, label %50, label %68

50:                                               ; preds = %48
  %51 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 312), align 8, !tbaa !12
  %.not24.19 = icmp ugt i32 %12, %51
  br i1 %.not24.19, label %52, label %68

52:                                               ; preds = %50
  %53 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 328), align 8, !tbaa !12
  %.not24.20 = icmp ugt i32 %12, %53
  br i1 %.not24.20, label %54, label %68

54:                                               ; preds = %52
  %55 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 344), align 8, !tbaa !12
  %.not24.21 = icmp ugt i32 %12, %55
  br i1 %.not24.21, label %56, label %68

56:                                               ; preds = %54
  %57 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 360), align 8, !tbaa !12
  %.not24.22 = icmp ugt i32 %12, %57
  br i1 %.not24.22, label %58, label %68

58:                                               ; preds = %56
  %59 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 376), align 8, !tbaa !12
  %.not24.23 = icmp ugt i32 %12, %59
  br i1 %.not24.23, label %60, label %68

60:                                               ; preds = %58
  %61 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 392), align 8, !tbaa !12
  %.not24.24 = icmp ugt i32 %12, %61
  br i1 %.not24.24, label %62, label %68

62:                                               ; preds = %60
  %63 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 408), align 8, !tbaa !12
  %.not24.25 = icmp ugt i32 %12, %63
  br i1 %.not24.25, label %64, label %68

64:                                               ; preds = %62
  %65 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 424), align 8, !tbaa !12
  %.not24.26 = icmp ugt i32 %12, %65
  br i1 %.not24.26, label %66, label %68

66:                                               ; preds = %64
  %67 = load i32, ptr getelementptr inbounds (i8, ptr @region_size, i64 440), align 8, !tbaa !12
  %.not24.27 = icmp ugt i32 %12, %67
  br i1 %.not24.27, label %.loopexit, label %68

68:                                               ; preds = %66, %64, %62, %60, %58, %56, %54, %52, %50, %48, %46, %44, %42, %40, %38, %36, %34, %32, %30, %28, %26, %24, %22, %20, %18, %16, %14, %11
  %.lcssa = phi ptr [ @region_size, %11 ], [ getelementptr inbounds (i8, ptr @region_size, i64 16), %14 ], [ getelementptr inbounds (i8, ptr @region_size, i64 32), %16 ], [ getelementptr inbounds (i8, ptr @region_size, i64 48), %18 ], [ getelementptr inbounds (i8, ptr @region_size, i64 64), %20 ], [ getelementptr inbounds (i8, ptr @region_size, i64 80), %22 ], [ getelementptr inbounds (i8, ptr @region_size, i64 96), %24 ], [ getelementptr inbounds (i8, ptr @region_size, i64 112), %26 ], [ getelementptr inbounds (i8, ptr @region_size, i64 128), %28 ], [ getelementptr inbounds (i8, ptr @region_size, i64 144), %30 ], [ getelementptr inbounds (i8, ptr @region_size, i64 160), %32 ], [ getelementptr inbounds (i8, ptr @region_size, i64 176), %34 ], [ getelementptr inbounds (i8, ptr @region_size, i64 192), %36 ], [ getelementptr inbounds (i8, ptr @region_size, i64 208), %38 ], [ getelementptr inbounds (i8, ptr @region_size, i64 224), %40 ], [ getelementptr inbounds (i8, ptr @region_size, i64 240), %42 ], [ getelementptr inbounds (i8, ptr @region_size, i64 256), %44 ], [ getelementptr inbounds (i8, ptr @region_size, i64 272), %46 ], [ getelementptr inbounds (i8, ptr @region_size, i64 288), %48 ], [ getelementptr inbounds (i8, ptr @region_size, i64 304), %50 ], [ getelementptr inbounds (i8, ptr @region_size, i64 320), %52 ], [ getelementptr inbounds (i8, ptr @region_size, i64 336), %54 ], [ getelementptr inbounds (i8, ptr @region_size, i64 352), %56 ], [ getelementptr inbounds (i8, ptr @region_size, i64 368), %58 ], [ getelementptr inbounds (i8, ptr @region_size, i64 384), %60 ], [ getelementptr inbounds (i8, ptr @region_size, i64 400), %62 ], [ getelementptr inbounds (i8, ptr @region_size, i64 416), %64 ], [ getelementptr inbounds (i8, ptr @region_size, i64 432), %66 ]
  %69 = load i64, ptr %.lcssa, align 16, !tbaa !14
  %70 = getelementptr inbounds i8, ptr %9, i64 16
  store i64 %69, ptr %70, align 16, !tbaa !15
  br label %.loopexit

.loopexit:                                        ; preds = %66, %68
  %71 = getelementptr inbounds i8, ptr %9, i64 24
  store i32 %3, ptr %71, align 8, !tbaa !16
  br label %73

72:                                               ; preds = %6
  store i32 0, ptr %9, align 16, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(20) %10, i8 0, i64 20, i1 false)
  br label %73

73:                                               ; preds = %4, %.loopexit, %72
  %.021 = phi i32 [ 0, %.loopexit ], [ 0, %72 ], [ 1, %4 ]
  ret i32 %.021
}

; 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, argmem: read, 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, !7, i64 0}
!6 = !{!"XMpuConfig", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!13, !7, i64 8}
!13 = !{!"", !10, i64 0, !7, i64 8}
!14 = !{!13, !10, i64 0}
!15 = !{!6, !10, i64 16}
!16 = !{!6, !7, i64 24}


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