; LLVM IR from FrancesoM/Bisc8FX :: sdk_projects/bisc8_platform/zynq_fsbl (nor)

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

@FlashReadBaseAddress = external global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @NorAccess(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = urem i32 %12, 4
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %21

15:                                               ; preds = %3
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = and i32 %16, 3
  %18 = sub i32 4, %17
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = add i32 %19, %18
  store i32 %20, ptr %6, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %15, %3
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = lshr i32 %22, 2
  store i32 %23, ptr %11, align 4, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = load i32, ptr @FlashReadBaseAddress, align 4, !tbaa !5
  %26 = add i32 %24, %25
  %27 = zext i32 %26 to i64
  %28 = inttoptr i64 %27 to ptr
  store ptr %28, ptr %9, align 8, !tbaa !9
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = zext i32 %29 to i64
  %31 = inttoptr i64 %30 to ptr
  store ptr %31, ptr %10, align 8, !tbaa !9
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %47, %21
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = load i32, ptr %11, align 4, !tbaa !5
  %35 = icmp ult i32 %33, %34
  br i1 %35, label %36, label %50

36:                                               ; preds = %32
  %37 = load ptr, ptr %9, align 8, !tbaa !9
  %38 = getelementptr inbounds i32, ptr %37, i32 1
  store ptr %38, ptr %9, align 8, !tbaa !9
  %39 = ptrtoint ptr %37 to i32
  %40 = zext i32 %39 to i64
  %41 = call i32 @Xil_In32(i64 noundef %40)
  store i32 %41, ptr %7, align 4, !tbaa !5
  %42 = load ptr, ptr %10, align 8, !tbaa !9
  %43 = getelementptr inbounds i32, ptr %42, i32 1
  store ptr %43, ptr %10, align 8, !tbaa !9
  %44 = ptrtoint ptr %42 to i32
  %45 = zext i32 %44 to i64
  %46 = load i32, ptr %7, align 4, !tbaa !5
  call void @Xil_Out32(i64 noundef %45, i32 noundef %46)
  br label %47

47:                                               ; preds = %36
  %48 = load i32, ptr %8, align 4, !tbaa !5
  %49 = add i32 %48, 1
  store i32 %49, ptr %8, align 4, !tbaa !5
  br label %32, !llvm.loop !11

50:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 0
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @Xil_In32(i64 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @Xil_Out32(i64 noundef, i32 noundef) #2

; 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 = { inlinehint 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@FlashReadBaseAddress = external local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @NorAccess(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.biased = add i32 %2, 3
  %4 = lshr i32 %.biased, 2
  %.not = icmp ult i32 %.biased, 4
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %5 = zext i32 %1 to i64
  %6 = inttoptr i64 %5 to ptr
  %7 = load i32, ptr @FlashReadBaseAddress, align 4, !tbaa !5
  %8 = add i32 %7, %0
  %9 = zext i32 %8 to i64
  %10 = inttoptr i64 %9 to ptr
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.01116 = phi ptr [ %15, %.lr.ph ], [ %6, %.lr.ph.preheader ]
  %.01215 = phi ptr [ %11, %.lr.ph ], [ %10, %.lr.ph.preheader ]
  %.01314 = phi i32 [ %18, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %11 = getelementptr inbounds i8, ptr %.01215, i64 4
  %12 = ptrtoint ptr %.01215 to i64
  %13 = and i64 %12, 4294967295
  %14 = tail call i32 @Xil_In32(i64 noundef %13)
  %15 = getelementptr inbounds i8, ptr %.01116, i64 4
  %16 = ptrtoint ptr %.01116 to i64
  %17 = and i64 %16, 4294967295
  tail call void @Xil_Out32(i64 noundef %17, i32 noundef %14)
  %18 = add nuw nsw i32 %.01314, 1
  %exitcond.not = icmp eq i32 %18, %4
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %3
  ret i32 0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @Xil_In32(i64 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @Xil_Out32(i64 noundef, i32 noundef) local_unnamed_addr #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 = { inlinehint 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass